diff options
-rw-r--r-- | src/common/HPMi.h | 24 | ||||
-rw-r--r-- | src/map/atcommand.h | 1 | ||||
-rw-r--r-- | src/map/script.h | 1 | ||||
-rw-r--r-- | src/plugins/db2sql.c | 2 | ||||
-rw-r--r-- | src/plugins/sample.c | 32 |
5 files changed, 44 insertions, 16 deletions
diff --git a/src/common/HPMi.h b/src/common/HPMi.h index 7637dc832..2cd1075c4 100644 --- a/src/common/HPMi.h +++ b/src/common/HPMi.h @@ -105,6 +105,30 @@ enum HPluginDataTypes { #define getFromNPCD(ptr,index) (HPMi->getFromHPData(HPDT_NPCD,HPMi->pid,(ptr),(index))) #define removeFromNPCD(ptr,index) (HPMi->removeFromHPData(HPDT_NPCD,HPMi->pid,(ptr),(index))) +/* HPMi->addCommand */ +#define addAtcommand(cname,funcname) \ + if ( HPMi->addCommand != NULL ) { \ + HPMi->addCommand(cname,atcommand_ ## funcname); \ + } else { \ + ShowWarning("HPM (%s):addAtcommand(\"%s\",%s) failed, addCommand sub is NULL!\n",pinfo.name,cname,# funcname);\ + } +/* HPMi->addScript */ +#define addScriptCommand(cname,scinfo,funcname) \ + if ( HPMi->addScript != NULL ) { \ + HPMi->addScript(cname,scinfo,buildin_ ## funcname); \ + } else { \ + ShowWarning("HPM (%s):addScriptCommand(\"%s\",\"%s\",%s) failed, addScript sub is NULL!\n",pinfo.name,cname,scinfo,# funcname);\ + } +/* HPMi->addCPCommand */ +#define addCPCommand(cname,funcname) \ + if ( HPMi->addCPCommand != NULL ) { \ + HPMi->addCPCommand(cname,console_parse_ ## funcname); \ + } else { \ + ShowWarning("HPM (%s):addCPCommand(\"%s\",%s) failed, addCPCommand sub is NULL!\n",pinfo.name,cname,# funcname);\ + } +/* HPMi->addPacket */ +#define addPacket(cmd,len,receive,point) HPMi->addPacket(cmd,len,receive,point,HPMi->pid) + /* Hercules Plugin Mananger Include Interface */ HPExport struct HPMi_interface { /* */ diff --git a/src/map/atcommand.h b/src/map/atcommand.h index 6b5a52fcb..d01f00d8e 100644 --- a/src/map/atcommand.h +++ b/src/map/atcommand.h @@ -122,6 +122,5 @@ void atcommand_defaults(void); /* stay here */ #define ACMD(x) static bool atcommand_ ## x (const int fd, struct map_session_data* sd, const char* command, const char* message, struct AtCommandInfo *info) -#define ACMD_A(x) atcommand_ ## x #endif /* _ATCOMMAND_H_ */ diff --git a/src/map/script.h b/src/map/script.h index 32426e988..e0e5f9ea9 100644 --- a/src/map/script.h +++ b/src/map/script.h @@ -145,7 +145,6 @@ struct eri; #define is_string_variable(name) ( (name)[strlen(name) - 1] == '$' ) #define BUILDIN(x) bool buildin_ ## x (struct script_state* st) -#define BUILDIN_A(x) buildin_ ## x #define script_fetch(st, n, t) do { \ if( script_hasdata((st),(n)) ) \ diff --git a/src/plugins/db2sql.c b/src/plugins/db2sql.c index 3c3981bdd..9161e0263 100644 --- a/src/plugins/db2sql.c +++ b/src/plugins/db2sql.c @@ -196,7 +196,7 @@ HPExport void server_preinit (void) { addArg("--db2sql",false,db2sql_arg,NULL); } HPExport void plugin_init (void) { - HPMi->addCPCommand("server:tools:db2sql",CPCMD_A(db2sql)); + addCPCommand("server:tools:db2sql",db2sql); } HPExport void server_online (void) { if( torun ) diff --git a/src/plugins/sample.c b/src/plugins/sample.c index cffd39992..552194e43 100644 --- a/src/plugins/sample.c +++ b/src/plugins/sample.c @@ -36,6 +36,7 @@ struct sample_data_struct { struct point lastMSGPosition; unsigned int someNumber; }; + /* sample packet implementation */ /* cmd 0xf3 - it is a client-server existent id, for clif_parse_GlobalMessage */ /* in this sample we do nothing and simply redirect */ @@ -138,26 +139,31 @@ HPExport void plugin_init (void) { ShowInfo ("I'm being run from the '%s' filename\n", server_name); - if( HPMi->addCommand != NULL ) {//link our '@sample' command - HPMi->addCommand("sample",ACMD_A(sample)); - } - - if( HPMi->addScript != NULL ) {//link our 'sample' script command - HPMi->addScript("sample","i",BUILDIN_A(sample)); - } + /* addAtcommand("command-key",command-function) tells map server to call ACMD(sample) when "sample" command is used */ + /* - it will print a warning when used on a non-map-server plugin */ + addAtcommand("sample",sample);//link our '@sample' command - if( HPMi->addCPCommand != NULL ) {//link our 'sample' console command - HPMi->addCPCommand("this:is:a:sample",CPCMD_A(sample)); - } + /* addScriptCommand("script-command-name","script-command-params-info",script-function) tells map server to call BUILDIN(sample) for the "sample(i)" command */ + /* - it will print a warning when used on a non-map-server plugin */ + addScriptCommand("sample","i",sample); - if( HPMi->addPacket != NULL ) {//link our 'sample' packet to map-server - HPMi->addPacket(0xf3,-1,sample_packet0f3,hpClif_Parse,HPMi->pid); - } + /* addCPCommand("console-command-name",command-function) tells server to call CPCMD(sample) for the 'this is a sample <optional-args>' console call */ + /* in "console-command-name" usage of ':' indicates a category, for example 'this:is:a:sample' translates to 'this is a sample', + * therefore 'this -> is -> a -> sample', it can be used to aggregate multiple commands under the same category or to append commands to existing categories + * categories inherit the special keyword 'help' which prints the subsequent commands, e.g. 'server help' prints all categories and commands under 'server' + * therefore 'this help' would inform about 'is (category) -> a (category) -> sample (command)'*/ + addCPCommand("this:is:a:sample",sample); + /* addPacket(packetID,packetLength,packetFunction,packetIncomingPoint) */ + /* adds packetID of packetLength (-1 for dynamic length where length is defined in the packet { packetID (2 Byte) , packetLength (2 Byte) , ... }) + * to trigger packetFunction in the packetIncomingPoint section ( available points listed in enum HPluginPacketHookingPoints within src/common/HPMi.h ) */ + addPacket(0xf3,-1,sample_packet0f3,hpClif_Parse); + /* in this sample we add a PreHook to pc->dropitem */ /* to identify whether the item being dropped is on amount higher than 1 */ /* if so, it stores the amount on a variable (my_pc_dropitem_storage) and changes the amount to 1 */ addHookPre("pc->dropitem",my_pc_dropitem_pre); + /* in this sample we add a PostHook to pc->dropitem */ /* if the original pc->dropitem was successful and the amount stored on my_pc_dropitem_storage is higher than 1, */ /* our posthook will display a message to the user about the cap */ |