From 10f0d5962d0933cd396854d7798e31500976e5fc Mon Sep 17 00:00:00 2001 From: false_genesis Date: Mon, 18 Feb 2008 22:15:28 +0000 Subject: [PATCH] * changed GetName script to support types: guid,player,item,unit with guid/entry depeding on type * restructured event scripts, some organisation --- bin/scripts/__core_chatAI.def | 15 --- bin/scripts/__core_eventstubs.def | 96 +++++++++++++++++++ bin/scripts/__core_internal.def | 11 --- bin/scripts/{ => deprecated}/_enterworld.def | 0 bin/scripts/{ => deprecated}/_leaveworld.def | 0 .../{ => deprecated}/_nopermission.def | 0 bin/scripts/{ => deprecated}/_onwhisper.def | 0 .../{ => deprecated}/opcode_who_forplayer.def | 0 bin/scripts/{ => optional}/bbExample.def | 0 .../{ => optional}/chatAI_HelloWorld.def | 0 bin/scripts/optional/dump_playercache.def | 21 ++++ .../{ => optional}/example_scriptHook.def | 0 bin/scripts/uptime.def | 34 ++++--- src/Client/DefScriptInterface.cpp | 60 +++++++----- src/Client/World/WorldSession.cpp | 10 ++ 15 files changed, 180 insertions(+), 67 deletions(-) create mode 100644 bin/scripts/__core_eventstubs.def rename bin/scripts/{ => deprecated}/_enterworld.def (100%) rename bin/scripts/{ => deprecated}/_leaveworld.def (100%) rename bin/scripts/{ => deprecated}/_nopermission.def (100%) rename bin/scripts/{ => deprecated}/_onwhisper.def (100%) rename bin/scripts/{ => deprecated}/opcode_who_forplayer.def (100%) rename bin/scripts/{ => optional}/bbExample.def (100%) rename bin/scripts/{ => optional}/chatAI_HelloWorld.def (100%) create mode 100644 bin/scripts/optional/dump_playercache.def rename bin/scripts/{ => optional}/example_scriptHook.def (100%) diff --git a/bin/scripts/__core_chatAI.def b/bin/scripts/__core_chatAI.def index ae4ad9a..9984c7b 100644 --- a/bin/scripts/__core_chatAI.def +++ b/bin/scripts/__core_chatAI.def @@ -1,18 +1,3 @@ -// ------------------------------------------- -#script=_onchatmessage -// purpose: do something if specific chat messages are recieved. -// args: -// @def: chat message text -// @0: message type id (check ChatMsg enum in src/Client/SharedDefines.h) -// @1: language id (also defined in SharedDefines.h), alternatively look up bin/data/scp/language.scp -// @2: GUID of the player or creature this msg came from -// @3: channel name. empty string if the chat message was not sent in a channel (for example say, yell or whisper) -//-------------------------------------------- - -processchatai,{${@0}},{${@1}},{${@2}},{${@3}} ${@def} - - - // ----------------------------------- #script=FlushChatAI diff --git a/bin/scripts/__core_eventstubs.def b/bin/scripts/__core_eventstubs.def new file mode 100644 index 0000000..db1754a --- /dev/null +++ b/bin/scripts/__core_eventstubs.def @@ -0,0 +1,96 @@ + +// ----==== CHAT MESSAGES ====---- +// ------------------------------------------- +#script=_onchatmessage +// purpose: do something if specific chat messages are recieved. +// args: +// @def: chat message text +// @0: message type id (check ChatMsg enum in src/Client/SharedDefines.h) +// @1: language id (also defined in SharedDefines.h), alternatively look up bin/data/scp/language.scp +// @2: GUID of the player or creature this msg came from +// @3: channel name. empty string if the chat message was not sent in a channel (for example say, yell or whisper) +//-------------------------------------------- +processchatai,{${@0}},{${@1}},{${@2}},{${@3}} ${@def} // this is required for the ChatAI script to work + +// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + + +// ----==== TELEPORTATION ====---- + +#script=_onteleport +// @def: [far teleport=true, else false] +// @0: [far teleport: map ID, else teleported GUID] +// @1: X position +// @2: Y position +// @3: Z position +// @4: Orientation + +//- script content here... + + +// ----==== GUI RELATED ====---- + +#script=_onguiclose +// no args. gets called when the GUI is closed. +if ?{GetVar #EXITONGUICLOSE} + exit +endif + + +// ----==== OBJECT HANDLING ====---- + +#script=_onobjectcreate +// @def: GUID of created object +// @0 TypeID of created object +// The object can be accessed with GetName, GetEntry, GetObjectType, GetObjectValue, GetRace, GetClass, ... via the guid + +//- script content here... + + + +#script=_onobjectdelete +// @def: GUID of deleted object +// @0: [out of range object deletion=true, else false] +// The object can be accessed with the object handling functions listed above. +// It will be deleted right after handling this script. + +//- script content here... + + + + +// ----==== ENTERING/LEAVING WORLD ====---- + +#script=_leaveworld +// no args. gets called when the world is left. + +//- script content here... + + +#script=_enterworld +// no args. called when the world is entered +log * World entered! +say [${@version_short}] login successful. +emote 126 // = TEXTEMOTE_READY +joinchannel General +joinchannel Trade +joinchannel LookingForGroup +castspell 836 // LoginEffect + + + +// ----==== IN-GAME SCRIPT COMMANDS ====---- + +#script=_nopermission +// this script gets executed if a player tries to give pseuwow a command but is not allowed to +// Arguments: +// ========== +// @0 : name of the player who wanted to execute a command +// @1 : permission level of this user +// @2 : permission level needed to execute the script +// @3 : name of the script that should get executed + +SAY Forget it, ${@0}, you have only permission ${@1} but need ${@2} to run the script '${@3}' +LOG Player '${@0}' (p:${@1}) wanted to execute '${@3}' (p:${@2}) +EMOTE 66 // say NO! + diff --git a/bin/scripts/__core_internal.def b/bin/scripts/__core_internal.def index 8e49cfb..8149060 100644 --- a/bin/scripts/__core_internal.def +++ b/bin/scripts/__core_internal.def @@ -103,16 +103,6 @@ LOG * Assigning permissions for internal functions... setscriptpermission,emote 0 // ... set more permissions here ... -//------------------------------------------------- -#script=register_onguiclose_exit -//------------------------------------------------- -if ?{not ?{ScriptHasLine,_onguiclose #tag:hook:${@myname}}} - appenddef,_onguiclose #tag:hook:${@myname} - appenddef,_onguiclose if ?\{GetVar #EXITONGUICLOSE\} - appenddef,_onguiclose exit - appenddef,_onguiclose endif -endif - // this dummy script does nothing actually but since its loaded last in this file it causes the config // script to be run before all .def files are loaded @@ -124,6 +114,5 @@ endif if ?{not ${#config::DONE}} config endif -register_onguiclose_exit #/onload diff --git a/bin/scripts/_enterworld.def b/bin/scripts/deprecated/_enterworld.def similarity index 100% rename from bin/scripts/_enterworld.def rename to bin/scripts/deprecated/_enterworld.def diff --git a/bin/scripts/_leaveworld.def b/bin/scripts/deprecated/_leaveworld.def similarity index 100% rename from bin/scripts/_leaveworld.def rename to bin/scripts/deprecated/_leaveworld.def diff --git a/bin/scripts/_nopermission.def b/bin/scripts/deprecated/_nopermission.def similarity index 100% rename from bin/scripts/_nopermission.def rename to bin/scripts/deprecated/_nopermission.def diff --git a/bin/scripts/_onwhisper.def b/bin/scripts/deprecated/_onwhisper.def similarity index 100% rename from bin/scripts/_onwhisper.def rename to bin/scripts/deprecated/_onwhisper.def diff --git a/bin/scripts/opcode_who_forplayer.def b/bin/scripts/deprecated/opcode_who_forplayer.def similarity index 100% rename from bin/scripts/opcode_who_forplayer.def rename to bin/scripts/deprecated/opcode_who_forplayer.def diff --git a/bin/scripts/bbExample.def b/bin/scripts/optional/bbExample.def similarity index 100% rename from bin/scripts/bbExample.def rename to bin/scripts/optional/bbExample.def diff --git a/bin/scripts/chatAI_HelloWorld.def b/bin/scripts/optional/chatAI_HelloWorld.def similarity index 100% rename from bin/scripts/chatAI_HelloWorld.def rename to bin/scripts/optional/chatAI_HelloWorld.def diff --git a/bin/scripts/optional/dump_playercache.def b/bin/scripts/optional/dump_playercache.def new file mode 100644 index 0000000..17dd87f --- /dev/null +++ b/bin/scripts/optional/dump_playercache.def @@ -0,0 +1,21 @@ +#script=dumppcache +fopen,fh,rb ./cache/playernames.cache +freadbb,fh bb +set,size ?{bbread,bb uint32} +log PlayerNameCache: ${size} entries. +set,i 0 +loop + if ?{bigger_eq,${i} ${size}} + exitloop + endif + set,guid ?{bbread,bb uint64} + set,len ?{bbread,bb uint8} + set,name ?{bbread,bb,${len} strnz} + log PlayerNameCache[${i}]: ${guid} = ${name} (${len}) + add,i 1 +endloop + +#script=dummy +#onload +dumppcache +#/onload diff --git a/bin/scripts/example_scriptHook.def b/bin/scripts/optional/example_scriptHook.def similarity index 100% rename from bin/scripts/example_scriptHook.def rename to bin/scripts/optional/example_scriptHook.def diff --git a/bin/scripts/uptime.def b/bin/scripts/uptime.def index 5d85bc3..9771ae1 100644 --- a/bin/scripts/uptime.def +++ b/bin/scripts/uptime.def @@ -1,20 +1,13 @@ -#permission=0 - +#script=getuptime // purpose: pseuwow uptime counter -// args: none -// usage: - load the script to register the uptime counter -// - call the script to say the uptime formatted in hours, mins & secs +// args: @def: "say", "yell", "chan,General", etc. any command that accepts a string in @def and does something with it. + // returns: uptime formatted as 0h 0m 0s -#onload - if ?{not ?{isset #uptime}} - set,#uptime 0 - endif - removeevent event_{${@myname}} - addevent,event_{${@myname}},1000 add,#uptime 1 -#endonload - -set,s ${#uptime} +set,s ${@clock} +div,s 1000 +set,s ?{toint ${s}} +set,secs ${s} set,h ${s} div,h 3600 @@ -27,14 +20,19 @@ toint,m ${m} mod,s 60 toint,s ${s} set,str ${h}h ${m}m ${s}s -out UPTIME: ${#uptime} secs = ${str} +out UPTIME: ${secs} secs = ${str} -if ${@inworld} - say UPTIME: ${h} hours, ${m} minutes, ${s} seconds +if ?{strlen ${@def}} + ${@def} UPTIME: ${h} hours, ${m} minutes, ${s} seconds endif unset h unset m unset s +unset secs -return ${str} \ No newline at end of file +return ${str} + +#script=uptime +#permission=0 +return ?{getuptime say} \ No newline at end of file diff --git a/src/Client/DefScriptInterface.cpp b/src/Client/DefScriptInterface.cpp index 8179fb8..2869910 100644 --- a/src/Client/DefScriptInterface.cpp +++ b/src/Client/DefScriptInterface.cpp @@ -442,32 +442,46 @@ DefReturnResult DefScriptPackage::SCGetName(CmdSet& Set) logerror("Invalid Script call: SCGetName: WorldSession not valid"); DEF_RETURN_ERROR; } - DefReturnResult r; - uint64 guid=DefScriptTools::toNumber(Set.defaultarg); - r.ret="Unknown Entity"; - Object *o = ws->objmgr.GetObj(guid); - if(o) + uint64 id = DefScriptTools::toUint64(Set.defaultarg); + std::string source = DefScriptTools::stringToLower(Set.arg[0]); + + // "guid" type can be everything - item, player, unit, gameobject... whatever has this guid. + if(source.empty() || source == "guid") { - if(o->GetTypeId()==TYPEID_ITEM || o->GetTypeId()==TYPEID_CONTAINER) - { - ItemProto *proto=((PseuInstance*)parentMethod)->GetWSession()->objmgr.GetItemProto(o->GetEntry()); - r.ret=proto->Name[0]; // and whats with Name[1] - Name[3]? - } - else if(o->GetTypeId()==TYPEID_UNIT || o->GetTypeId()==TYPEID_PLAYER || o->GetTypeId()==TYPEID_GAMEOBJECT || o->GetTypeId()==TYPEID_CORPSE) - { - r.ret=((WorldObject*)o)->GetName(); - } - // TODO: add support for gameobjects etc. - } - else - { - // if no object with that guid is near, it might exist in the cache, check it and use that if present - if(ws->plrNameCache.IsKnown(guid)) - r.ret = ws->plrNameCache.GetName(guid); + Object *o = ws->objmgr.GetObj(id); + if(o) + return o->GetName(); else - logerror("SCGetName: Object "I64FMT" not known",guid); + { + // fallback if that guid is player guid, its maybe stored, so check that + if(IS_PLAYER_GUID(id)) + { + if(ws->plrNameCache.IsKnown(id)) + return ws->plrNameCache.GetName(id); + } + } } - return r; + else if(source == "player") + { + if(ws->plrNameCache.IsKnown(id)) + return ws->plrNameCache.GetName(id); + else + return ""; + + } + else if(source == "item") + { + ItemProto *iproto = ws->objmgr.GetItemProto((uint32)id); + return iproto ? iproto->Name : ""; + } + else if(source == "unit") + { + CreatureTemplate *ct = ws->objmgr.GetCreatureTemplate((uint32)id); + return ct ? ct->name : ""; + } + // TODO: add gameobject, dynamicobject + + return ""; } DefReturnResult DefScriptPackage::SCGetEntry(CmdSet& Set) diff --git a/src/Client/World/WorldSession.cpp b/src/Client/World/WorldSession.cpp index 3b8cb04..2a37f53 100644 --- a/src/Client/World/WorldSession.cpp +++ b/src/Client/World/WorldSession.cpp @@ -847,6 +847,11 @@ void WorldSession::_HandleTelePortAckOpcode(WorldPacket& recvPacket) { CmdSet Set; Set.defaultarg = "false"; // teleported to other map = false + Set.arg[0] = toString(guid); + Set.arg[1] = toString(x); + Set.arg[2] = toString(y); + Set.arg[3] = toString(z); + Set.arg[4] = toString(o); GetInstance()->GetScripts()->RunScriptIfExists("_onteleport"); } } @@ -881,6 +886,11 @@ void WorldSession::_HandleNewWorldOpcode(WorldPacket& recvPacket) { CmdSet Set; Set.defaultarg = "true"; // teleported to other map = false + Set.arg[0] = toString(mapid); + Set.arg[1] = toString(x); + Set.arg[2] = toString(y); + Set.arg[3] = toString(z); + Set.arg[4] = toString(o); GetInstance()->GetScripts()->RunScriptIfExists("_onteleport"); } }