Skip to content

Commit

Permalink
[10945] Restore check scripting lib API at load.
Browse files Browse the repository at this point in the history
Also report result of script library load/reload to chat/console.
  • Loading branch information
VladimirMangos committed Jan 1, 2011
1 parent 6d5def4 commit e125a5e
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 14 deletions.
5 changes: 4 additions & 1 deletion sql/mangos.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ CREATE TABLE `db_version` (
`version` varchar(120) default NULL,
`creature_ai_version` varchar(120) default NULL,
`cache_id` int(10) default '0',
`required_10932_01_mangos_game_event_creature_data` bit(1) default NULL
`required_10945_01_mangos_mangos_string` bit(1) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Used DB version notes';

--
Expand Down Expand Up @@ -3796,6 +3796,9 @@ INSERT INTO `mangos_string` VALUES
(1163,'Achievement %u doesn\'t exist.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(1164,'Achievement criteria %u doesn\'t exist.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(1165,'Spell %u not have auras.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(1166,'Scripting library not found or not accessable.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(1167,'Scripting library has wrong list functions (outdated?).',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(1168,'Scripting library reloaded.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(1200,'You try to view cinemitic %u but it doesn\'t exist.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(1201,'You try to view movie %u but it doesn\'t exist.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
/*!40000 ALTER TABLE `mangos_string` ENABLE KEYS */;
Expand Down
8 changes: 8 additions & 0 deletions sql/updates/10945_01_mangos_mangos_string.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ALTER TABLE db_version CHANGE COLUMN required_10932_01_mangos_game_event_creature_data required_10945_01_mangos_mangos_string bit;

DELETE FROM mangos_string WHERE entry IN (1166,1167,1168);

INSERT INTO mangos_string VALUES
(1166,'Scripting library not found or not accessable.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(1167,'Scripting library has wrong list functions (outdated?).',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(1168,'Scripting library reloaded.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
2 changes: 2 additions & 0 deletions sql/updates/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ pkgdata_DATA = \
10906_01_mangos_spell_proc_event.sql \
10906_02_mangos_spell_bonus_data.sql \
10932_01_mangos_game_event_creature_data.sql \
10945_01_mangos_mangos_string.sql \
README

## Additional files to include when running 'make dist'
Expand Down Expand Up @@ -258,4 +259,5 @@ EXTRA_DIST = \
10906_01_mangos_spell_proc_event.sql \
10906_02_mangos_spell_bonus_data.sql \
10932_01_mangos_game_event_creature_data.sql \
10945_01_mangos_mangos_string.sql \
README
7 changes: 5 additions & 2 deletions src/game/Language.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ enum MangosStrings
// Room for more level 2 376-399 not used

// level 3 chat
LANG_SCRIPTS_RELOADED = 400,
LANG_SCRIPTS_RELOADED_ANNOUNCE = 400,
LANG_YOU_CHANGE_SECURITY = 401,
LANG_YOURS_SECURITY_CHANGED = 402,
LANG_YOURS_SECURITY_IS_LOW = 403,
Expand Down Expand Up @@ -885,7 +885,10 @@ enum MangosStrings
LANG_ACHIEVEMENT_NOT_EXIST = 1163,
LANG_ACHIEVEMENT_CRITERIA_NOT_EXIST = 1164,
LANG_SPELL_NO_HAVE_AURAS = 1165,
// Room for more level 3 1166-1199 not used
LANG_SCRIPTS_NOT_FOUND = 1166,
LANG_SCRIPTS_WRONG_API = 1167,
LANG_SCRIPTS_RELOADED_OK = 1168,
// Room for more level 3 1169-1199 not used

// Debug commands
LANG_CINEMATIC_NOT_EXIST = 1200,
Expand Down
16 changes: 13 additions & 3 deletions src/game/Level3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -938,10 +938,20 @@ bool ChatHandler::HandleLoadScriptsCommand(char* args)
if (!*args)
return false;

if (!sScriptMgr.LoadScriptLibrary(args))
return true;
switch(sScriptMgr.LoadScriptLibrary(args))
{
case SCRIPT_LOAR_OK:
sWorld.SendWorldText(LANG_SCRIPTS_RELOADED_ANNOUNCE);
SendSysMessage(LANG_SCRIPTS_RELOADED_OK);
break;
case SCRIPT_LOAR_ERR_NOT_FOUND:
SendSysMessage(LANG_SCRIPTS_NOT_FOUND);
break;
case SCRIPT_LOAR_ERR_WRONG_API:
SendSysMessage(LANG_SCRIPTS_WRONG_API);
break;
}

sWorld.SendWorldText(LANG_SCRIPTS_RELOADED);
return true;
}

Expand Down
17 changes: 14 additions & 3 deletions src/game/ScriptMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ bool ScriptMgr::OnAuraDummy(Aura const* pAura, bool apply)
return m_pOnAuraDummy != NULL && m_pOnAuraDummy(pAura, apply);
}

bool ScriptMgr::LoadScriptLibrary(const char* libName)
ScriptLoadResult ScriptMgr::LoadScriptLibrary(const char* libName)
{
UnloadScriptLibrary();

Expand All @@ -1042,7 +1042,7 @@ bool ScriptMgr::LoadScriptLibrary(const char* libName)
m_hScriptLib = MANGOS_LOAD_LIBRARY(name.c_str());

if (!m_hScriptLib)
return false;
return SCRIPT_LOAR_ERR_NOT_FOUND;

GetScriptHookPtr(m_pOnInitScriptLibrary, "InitScriptLibrary");
GetScriptHookPtr(m_pOnFreeScriptLibrary, "FreeScriptLibrary");
Expand Down Expand Up @@ -1073,13 +1073,24 @@ bool ScriptMgr::LoadScriptLibrary(const char* libName)
GetScriptHookPtr(m_pOnEffectDummyItem, "EffectDummyItem");
GetScriptHookPtr(m_pOnAuraDummy, "AuraDummy");

if (!m_pOnInitScriptLibrary || !m_pOnFreeScriptLibrary || !m_pGetScriptLibraryVersion ||
!m_pGetCreatureAI || !m_pCreateInstanceData ||
!m_pOnGossipHello || !m_pOnGOGossipHello || !m_pOnGossipSelect ||
!m_pOnGOGossipSelect || !m_pOnGossipSelectWithCode || !m_pOnGOGossipSelectWithCode ||
!m_pOnQuestAccept || !m_pOnGOQuestAccept || !m_pOnItemQuestAccept ||
!m_pOnQuestRewarded || !m_pOnGOQuestRewarded || !m_pGetNPCDialogStatus ||
!m_pGetGODialogStatus || !m_pOnGOUse || !m_pOnItemUse ||
!m_pOnAreaTrigger || !m_pOnProcessEvent || !m_pOnEffectDummyCreature ||
!m_pOnEffectDummyGO || !m_pOnEffectDummyItem || !m_pOnAuraDummy)
return SCRIPT_LOAR_ERR_WRONG_API;

if (m_pOnInitScriptLibrary)
m_pOnInitScriptLibrary();

if (m_pGetScriptLibraryVersion)
sWorld.SetScriptsVersion(m_pGetScriptLibraryVersion());

return true;
return SCRIPT_LOAR_OK;
}

void ScriptMgr::UnloadScriptLibrary()
Expand Down
9 changes: 8 additions & 1 deletion src/game/ScriptMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,13 @@ extern ScriptMapMap sEventScripts;
extern ScriptMapMap sGossipScripts;
extern ScriptMapMap sCreatureMovementScripts;

enum ScriptLoadResult
{
SCRIPT_LOAR_OK,
SCRIPT_LOAR_ERR_NOT_FOUND,
SCRIPT_LOAR_ERR_WRONG_API
};

class ScriptMgr
{
public:
Expand All @@ -330,7 +337,7 @@ class ScriptMgr
const char* GetScriptName(uint32 id) const { return id < m_scriptNames.size() ? m_scriptNames[id].c_str() : ""; }
uint32 GetScriptId(const char *name) const;

bool LoadScriptLibrary(const char* libName);
ScriptLoadResult LoadScriptLibrary(const char* libName);
void UnloadScriptLibrary();

CreatureAI* GetCreatureAI(Creature* pCreature);
Expand Down
15 changes: 13 additions & 2 deletions src/game/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1249,8 +1249,19 @@ void World::SetInitialWorldSettings()
sLog.outString( "Loading CreatureEventAI Scripts...");
sEventAIMgr.LoadCreatureEventAI_Scripts();

sLog.outString( "Initializing Scripts..." );
sScriptMgr.LoadScriptLibrary(MANGOS_SCRIPT_NAME);
sLog.outString("Initializing Scripts...");
switch(sScriptMgr.LoadScriptLibrary(MANGOS_SCRIPT_NAME))
{
case SCRIPT_LOAR_OK:
sLog.outString("Scripting library loaded.");
break;
case SCRIPT_LOAR_ERR_NOT_FOUND:
sLog.outError("Scripting library not found or not accessable.");
break;
case SCRIPT_LOAR_ERR_WRONG_API:
sLog.outError("Scripting library has wrong list functions (outdated?).");
break;
}

///- Initialize game time and timers
sLog.outString( "DEBUG:: Initialize game time and timers" );
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "10944"
#define REVISION_NR "10945"
#endif // __REVISION_NR_H__
2 changes: 1 addition & 1 deletion src/shared/revision_sql.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef __REVISION_SQL_H__
#define __REVISION_SQL_H__
#define REVISION_DB_CHARACTERS "required_10862_01_characters_mail"
#define REVISION_DB_MANGOS "required_10932_01_mangos_game_event_creature_data"
#define REVISION_DB_MANGOS "required_10945_01_mangos_mangos_string"
#define REVISION_DB_REALMD "required_10008_01_realmd_realmd_db_version"
#endif // __REVISION_SQL_H__

0 comments on commit e125a5e

Please sign in to comment.