diff options
author | shennetsind <ind@henn.et> | 2013-08-04 12:19:25 -0300 |
---|---|---|
committer | shennetsind <ind@henn.et> | 2013-08-08 15:07:40 -0300 |
commit | 6b9f58446c46877ecfc5fe40847636145acf5af8 (patch) | |
tree | 81b71aa95a47e611a5415528cf72efefe0d552b1 /src/map | |
parent | defac0ef9714121a872ab48c3f6c4ddd177ae509 (diff) | |
download | hercules-6b9f58446c46877ecfc5fe40847636145acf5af8.tar.gz hercules-6b9f58446c46877ecfc5fe40847636145acf5af8.tar.bz2 hercules-6b9f58446c46877ecfc5fe40847636145acf5af8.tar.xz hercules-6b9f58446c46877ecfc5fe40847636145acf5af8.zip |
HPM Update
- Custom Packet Support
- Custom Data Struct Support (currently append-able to map_session_data and socket_data)
- Char Server Support
- Login Server Support
http://hercules.ws/board/topic/1934-hercules-plugin-manager-update/
Documentation will soon be updated in http://hercules.ws/wiki/HPM
Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/HPMmap.c | 89 | ||||
-rw-r--r-- | src/map/HPMmap.h | 18 | ||||
-rw-r--r-- | src/map/Makefile.in | 4 | ||||
-rw-r--r-- | src/map/chrif.c | 14 | ||||
-rw-r--r-- | src/map/clif.c | 9 | ||||
-rw-r--r-- | src/map/map.c | 5 | ||||
-rw-r--r-- | src/map/pc.h | 3 | ||||
-rw-r--r-- | src/map/pc_groups.c | 1 | ||||
-rw-r--r-- | src/map/unit.c | 11 |
9 files changed, 150 insertions, 4 deletions
diff --git a/src/map/HPMmap.c b/src/map/HPMmap.c new file mode 100644 index 000000000..17d72bc98 --- /dev/null +++ b/src/map/HPMmap.c @@ -0,0 +1,89 @@ +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file + +#include "../common/cbasetypes.h" +#include "../common/malloc.h" +#include "../common/showmsg.h" +#include "../common/HPM.h" + +#include "HPMmap.h" +#include "pc.h" +#include "map.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> + + +void HPM_map_addToMSD(struct map_session_data *sd, void *data, unsigned int id, unsigned int type, bool autofree) { + struct HPluginData *HPData; + unsigned int i; + + for(i = 0; i < sd->hdatac; i++) { + if( sd->hdata[i]->pluginID == id && sd->hdata[i]->type == type ) { + ShowError("HPMi->addToMSD:%s: error! attempting to insert duplicate struct of type %u on '%s'\n",HPM->pid2name(id),type,sd->status.name); + return; + } + } + + CREATE(HPData, struct HPluginData, 1); + + HPData->pluginID = id; + HPData->type = type; + HPData->flag.free = autofree ? 1 : 0; + HPData->data = data; + + RECREATE(sd->hdata,struct HPluginData *,++sd->hdatac); + sd->hdata[sd->hdatac - 1] = HPData; +} +void *HPM_map_getFromMSD(struct map_session_data *sd, unsigned int id, unsigned int type) { + unsigned int i; + + for(i = 0; i < sd->hdatac; i++) { + if( sd->hdata[i]->pluginID == id && sd->hdata[i]->type == type ) { + break; + } + } + + if( i != sd->hdatac ) + return sd->hdata[i]->data; + + return NULL; +} +void HPM_map_removeFromMSD(struct map_session_data *sd, unsigned int id, unsigned int type) { + unsigned int i; + + for(i = 0; i < sd->hdatac; i++) { + if( sd->hdata[i]->pluginID == id && sd->hdata[i]->type == type ) { + break; + } + } + + if( i != sd->hdatac ) { + unsigned int cursor; + + aFree(sd->hdata[i]->data); + aFree(sd->hdata[i]); + sd->hdata[i] = NULL; + + for(i = 0, cursor = 0; i < sd->hdatac; i++) { + if( sd->hdata[i] == NULL ) + continue; + if( i != cursor ) + sd->hdata[cursor] = sd->hdata[i]; + cursor++; + } + + sd->hdatac = cursor; + } + +} +void HPM_map_plugin_load_sub(struct hplugin *plugin) { + plugin->hpi->addCommand = HPM->import_symbol("addCommand"); + plugin->hpi->addScript = HPM->import_symbol("addScript"); + /* */ + plugin->hpi->addToMSD = HPM->import_symbol("addToMSD"); + plugin->hpi->getFromMSD = HPM->import_symbol("getFromMSD"); + plugin->hpi->removeFromMSD = HPM->import_symbol("removeFromMSD"); +} diff --git a/src/map/HPMmap.h b/src/map/HPMmap.h new file mode 100644 index 000000000..a6cac4ace --- /dev/null +++ b/src/map/HPMmap.h @@ -0,0 +1,18 @@ +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file + +#ifndef _HPM_MAP_ +#define _HPM_MAP_ + +#include "../common/cbasetypes.h" + +struct hplugin; +struct map_session_data; + +void HPM_map_addToMSD(struct map_session_data *sd, void *data, unsigned int id, unsigned int type, bool autofree); +void *HPM_map_getFromMSD(struct map_session_data *sd, unsigned int id, unsigned int type); +void HPM_map_removeFromMSD(struct map_session_data *sd, unsigned int id, unsigned int type); + +void HPM_map_plugin_load_sub(struct hplugin *plugin); + +#endif /* _HPM_MAP_ */ diff --git a/src/map/Makefile.in b/src/map/Makefile.in index 70c0cd900..588d19eae 100644 --- a/src/map/Makefile.in +++ b/src/map/Makefile.in @@ -17,7 +17,7 @@ MAP_OBJ = map.o chrif.o clif.o pc.o status.o npc.o \ storage.o skill.o atcommand.o battle.o battleground.o \ intif.o trade.o party.o vending.o guild.o pet.o \ log.o mail.o date.o unit.o homunculus.o mercenary.o quest.o instance.o \ - buyingstore.o searchstore.o duel.o pc_groups.o elemental.o irc-bot.o + buyingstore.o searchstore.o duel.o pc_groups.o elemental.o irc-bot.o HPMmap.o MAP_SQL_OBJ = $(MAP_OBJ:%=obj_sql/%) \ obj_sql/mapreg_sql.o MAP_H = map.h chrif.h clif.h pc.h status.h npc.h \ @@ -27,7 +27,7 @@ MAP_H = map.h chrif.h clif.h pc.h status.h npc.h \ log.h mail.h date.h unit.h homunculus.h mercenary.h quest.h instance.h mapreg.h \ buyingstore.h searchstore.h duel.h pc_groups.h \ ../config/core.h ../config/renewal.h ../config/secure.h ../config/const.h \ - ../config/classes/general.h elemental.h packets.h packets_struct.h irc-bot.h + ../config/classes/general.h elemental.h packets.h packets_struct.h irc-bot.h HPMmap.h HAVE_MYSQL=@HAVE_MYSQL@ ifeq ($(HAVE_MYSQL),yes) diff --git a/src/map/chrif.c b/src/map/chrif.c index d44ccf721..6b0397b56 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -10,6 +10,7 @@ #include "../common/showmsg.h" #include "../common/strlib.h" #include "../common/ers.h" +#include "../common/HPM.h" #include "map.h" #include "battle.h" @@ -1396,7 +1397,7 @@ void chrif_skillid2idx(int fd) { * *------------------------------------------*/ int chrif_parse(int fd) { - int packet_len, cmd; + int packet_len, cmd, r; // only process data from the char-server if ( fd != char_fd ) { @@ -1421,9 +1422,18 @@ int chrif_parse(int fd) { } while ( RFIFOREST(fd) >= 2 ) { + + if( HPM->packetsc[hpChrif_Parse] ) { + if( (r = HPM->parse_packets(fd,hpChrif_Parse)) ) { + if( r == 1 ) continue; + if( r == 2 ) return 0; + } + } + cmd = RFIFOW(fd,0); + if (cmd < 0x2af8 || cmd >= 0x2af8 + ARRAYLENGTH(packet_len_table) || packet_len_table[cmd-0x2af8] == 0) { - int r = intif->parse(fd); // Passed on to the intif + r = intif->parse(fd); // Passed on to the intif if (r == 1) continue; // Treated in intif if (r == 2) return 0; // Didn't have enough data (len==-1) diff --git a/src/map/clif.c b/src/map/clif.c index 44df5b607..7171a48be 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -14,6 +14,7 @@ #include "../common/utils.h" #include "../common/ers.h" #include "../common/conf.h" +#include "../common/HPM.h" #include "map.h" #include "chrif.h" @@ -17621,6 +17622,14 @@ int clif_parse(int fd) { if (RFIFOREST(fd) < 2) return 0; + + if( HPM->packetsc[hpClif_Parse] ) { + int r; + if( (r = HPM->parse_packets(fd,hpClif_Parse)) ) { + if( r == 1 ) continue; + if( r == 2 ) return 0; + } + } if( sd ) parse_cmd_func = sd->parse_cmd_func; diff --git a/src/map/map.c b/src/map/map.c index 713577495..5753fbc1d 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -51,6 +51,7 @@ #include "log.h" #include "mail.h" #include "irc-bot.h" +#include "HPMmap.h" #include <stdio.h> #include <stdlib.h> @@ -5172,6 +5173,9 @@ void map_hp_symbols(void) { /* specific */ HPM->share(atcommand->create,"addCommand"); HPM->share(script->addScript,"addScript"); + HPM->share(HPM_map_addToMSD,"addToMSD"); + HPM->share(HPM_map_getFromMSD,"getFromMSD"); + HPM->share(HPM_map_removeFromMSD,"removeFromMSD"); /* vars */ HPM->share(map,"map"); } @@ -5379,6 +5383,7 @@ int do_init(int argc, char *argv[]) iTimer->add_timer_func_list(map_removemobs_timer, "map_removemobs_timer"); iTimer->add_timer_interval(iTimer->gettick()+1000, map_freeblock_timer, 0, 0, 60*1000); + HPM->load_sub = HPM_map_plugin_load_sub; HPM->symbol_defaults_sub = map_hp_symbols; HPM->config_read(); HPM->event(HPET_INIT); diff --git a/src/map/pc.h b/src/map/pc.h index 1f1538e1f..c2e834d1c 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -507,6 +507,9 @@ struct map_session_data { unsigned char delayed_damage;//ref. counter bugreport:7307 [Ind/Hercules] + struct HPluginData **hdata; + unsigned int hdatac; + // temporary debugging of bug #3504 const char* delunit_prevfile; int delunit_prevline; diff --git a/src/map/pc_groups.c b/src/map/pc_groups.c index 9ca0fd17a..be02b5f15 100644 --- a/src/map/pc_groups.c +++ b/src/map/pc_groups.c @@ -2,6 +2,7 @@ // See the LICENSE file // Portions Copyright (c) Athena Dev Teams +#include "../common/cbasetypes.h" #include "../common/conf.h" #include "../common/db.h" #include "../common/malloc.h" diff --git a/src/map/unit.c b/src/map/unit.c index 9becb128e..41d661169 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -8,6 +8,7 @@ #include "../common/db.h" #include "../common/malloc.h" #include "../common/random.h" +#include "../common/HPM.h" #include "map.h" #include "path.h" @@ -2330,6 +2331,7 @@ int unit_free(struct block_list *bl, clr_type clrtype) { struct map_session_data *sd = (struct map_session_data*)bl; int i; + unsigned int k; if( iStatus->isdead(bl) ) pc->setrestartvalue(sd,2); @@ -2397,6 +2399,15 @@ int unit_free(struct block_list *bl, clr_type clrtype) aFree(sd->queues); sd->queues = NULL; } + + for( k = 0; k < sd->hdatac; k++ ) { + if( sd->hdata[k]->flag.free ) { + aFree(sd->hdata[k]->data); + aFree(sd->hdata[k]); + } + } + if( sd->hdata ) + aFree(sd->hdata); break; } case BL_PET: |