[6982] Implemented gmlevel-based command security
[getmangos.git] / src / game / ScriptCalls.cpp
blobd258ea19950d96153fd9440753d4ecf7886020b5
1 /*
2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef WIN32
20 #include <dlfcn.h>
21 #endif
23 #include "Platform/Define.h"
24 #include "ScriptCalls.h"
25 #include "World.h"
27 ScriptsSet Script=NULL;
29 void UnloadScriptingModule()
31 if(Script)
33 //todo: some check if some func from script library is called right now
34 Script->ScriptsFree();
35 MANGOS_CLOSE_LIBRARY(Script->hScriptsLib);
36 delete Script;
37 Script = NULL;
41 bool LoadScriptingModule(char const* libName)
43 ScriptsSet testScript=new _ScriptSet;
45 std::string name = strlen(libName) ? libName : MANGOS_SCRIPT_NAME;
46 name += MANGOS_SCRIPT_EXT;
48 testScript->hScriptsLib=MANGOS_LOAD_LIBRARY(name.c_str());
50 if(!testScript->hScriptsLib )
52 printf("Error loading Scripts Library %s !\n",name.c_str());
53 delete testScript;
54 return false;
57 if( !(testScript->ScriptsInit =(scriptCallScriptsInit )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"ScriptsInit" ))
58 ||!(testScript->ScriptsFree =(scriptCallScriptsFree )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"ScriptsFree" ))
59 ||!(testScript->ScriptsVersion =(scriptCallScriptsVersion )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"ScriptsVersion" ))
60 ||!(testScript->GossipHello =(scriptCallGossipHello )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"GossipHello" ))
61 ||!(testScript->GOChooseReward =(scriptCallGOChooseReward )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"GOChooseReward" ))
62 ||!(testScript->QuestAccept =(scriptCallQuestAccept )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"QuestAccept" ))
63 ||!(testScript->GossipSelect =(scriptCallGossipSelect )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"GossipSelect" ))
64 ||!(testScript->GossipSelectWithCode=(scriptCallGossipSelectWithCode)MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"GossipSelectWithCode"))
65 ||!(testScript->QuestSelect =(scriptCallQuestSelect )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"QuestSelect" ))
66 ||!(testScript->QuestComplete =(scriptCallQuestComplete )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"QuestComplete" ))
67 ||!(testScript->NPCDialogStatus =(scriptCallNPCDialogStatus )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"NPCDialogStatus" ))
68 ||!(testScript->GODialogStatus =(scriptCallGODialogStatus )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"GODialogStatus" ))
69 ||!(testScript->ChooseReward =(scriptCallChooseReward )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"ChooseReward" ))
70 ||!(testScript->ItemHello =(scriptCallItemHello )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"ItemHello" ))
71 ||!(testScript->GOHello =(scriptCallGOHello )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"GOHello" ))
72 ||!(testScript->scriptAreaTrigger =(scriptCallAreaTrigger )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"AreaTrigger" ))
73 ||!(testScript->ItemQuestAccept =(scriptCallItemQuestAccept )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"ItemQuestAccept" ))
74 ||!(testScript->GOQuestAccept =(scriptCallGOQuestAccept )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"GOQuestAccept" ))
75 ||!(testScript->ReceiveEmote =(scriptCallReceiveEmote )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"ReceiveEmote" ))
76 ||!(testScript->ItemUse =(scriptCallItemUse )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"ItemUse" ))
77 ||!(testScript->GetAI =(scriptCallGetAI )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"GetAI" ))
78 ||!(testScript->CreateInstanceData =(scriptCallCreateInstanceData )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"CreateInstanceData" ))
81 printf("Error loading Scripts Library %s !\n Library missing required functions.",name.c_str());
82 MANGOS_CLOSE_LIBRARY(testScript->hScriptsLib);
83 delete testScript;
84 return false;
87 printf("Scripts Library %s was successfully loaded.\n",name.c_str());
89 //heh we are still there :P we have a valid library
90 //we reload script
91 UnloadScriptingModule();
93 Script=testScript;
94 Script->ScriptsInit(objmgr.GetScriptNames());
96 sWorld.SetScriptsVersion(Script->ScriptsVersion());
98 return true;