1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
// See the LICENSE file
#define HERCULES_CORE
#include "HPMmap.h"
#include "common/HPM.h"
#include "common/cbasetypes.h"
#include "common/HPMi.h"
#include "common/conf.h"
#include "common/console.h"
#include "common/core.h"
#include "common/db.h"
#include "common/des.h"
#include "common/ers.h"
#include "common/malloc.h"
#include "common/mapindex.h"
#include "common/mmo.h"
#include "common/nullpo.h"
#include "common/showmsg.h"
#include "common/socket.h"
#include "common/spinlock.h"
#include "common/sql.h"
#include "common/strlib.h"
#include "common/sysinfo.h"
#include "common/timer.h"
#include "common/utils.h"
#include "map/atcommand.h"
#include "map/battle.h"
#include "map/battleground.h"
#include "map/buyingstore.h"
#include "map/channel.h"
#include "map/chat.h"
#include "map/chrif.h"
#include "map/clif.h"
#include "map/date.h"
#include "map/duel.h"
#include "map/elemental.h"
#include "map/guild.h"
#include "map/homunculus.h"
#include "map/instance.h"
#include "map/intif.h"
#include "map/irc-bot.h"
#include "map/itemdb.h"
#include "map/log.h"
#include "map/mail.h"
#include "map/map.h"
#include "map/mapreg.h"
#include "map/mercenary.h"
#include "map/mob.h"
#include "map/npc.h"
#include "map/packets_struct.h"
#include "map/party.h"
#include "map/path.h"
#include "map/pc.h"
#include "map/pc_groups.h"
#include "map/pet.h"
#include "map/quest.h"
#include "map/script.h"
#include "map/searchstore.h"
#include "map/skill.h"
#include "map/status.h"
#include "map/storage.h"
#include "map/trade.h"
#include "map/unit.h"
#include "map/vending.h"
// HPMDataCheck comes after all the other includes
#include "common/HPMDataCheck.h"
#include <stdio.h>
#include <stdlib.h>
struct HPM_atcommand_list {
//tracking currently not enabled
// - requires modifying how plugins calls atcommand creation
// - needs load/unload during runtime support
//unsigned int pID;/* plugin id */
char name[ATCOMMAND_LENGTH];
AtCommandFunc func;
};
struct HPM_atcommand_list *atcommand_list = NULL;
unsigned int atcommand_list_items = 0;
bool HPM_map_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr) {
/* record address */
switch( type ) {
case HPDT_MSD:
ret->HPDataSRCPtr = (void**)(&((struct map_session_data *)ptr)->hdata);
ret->hdatac = &((struct map_session_data *)ptr)->hdatac;
break;
case HPDT_NPCD:
ret->HPDataSRCPtr = (void**)(&((struct npc_data *)ptr)->hdata);
ret->hdatac = &((struct npc_data *)ptr)->hdatac;
break;
case HPDT_MAP:
ret->HPDataSRCPtr = (void**)(&((struct map_data *)ptr)->hdata);
ret->hdatac = &((struct map_data *)ptr)->hdatac;
break;
case HPDT_PARTY:
ret->HPDataSRCPtr = (void**)(&((struct party_data *)ptr)->hdata);
ret->hdatac = &((struct party_data *)ptr)->hdatac;
break;
case HPDT_GUILD:
ret->HPDataSRCPtr = (void**)(&((struct guild *)ptr)->hdata);
ret->hdatac = &((struct guild *)ptr)->hdatac;
break;
case HPDT_INSTANCE:
ret->HPDataSRCPtr = (void**)(&((struct instance_data *)ptr)->hdata);
ret->hdatac = &((struct instance_data *)ptr)->hdatac;
break;
case HPDT_MOBDB:
ret->HPDataSRCPtr = (void**)(&((struct mob_db *)ptr)->hdata);
ret->hdatac = &((struct mob_db *)ptr)->hdatac;
break;
case HPDT_MOBDATA:
ret->HPDataSRCPtr = (void**)(&((struct mob_data *)ptr)->hdata);
ret->hdatac = &((struct mob_data *)ptr)->hdatac;
break;
case HPDT_ITEMDATA:
ret->HPDataSRCPtr = (void**)(&((struct item_data *)ptr)->hdata);
ret->hdatac = &((struct item_data *)ptr)->hdatac;
break;
case HPDT_BGDATA:
ret->HPDataSRCPtr = (void**)(&((struct battleground_data *)ptr)->hdata);
ret->hdatac = &((struct battleground_data *)ptr)->hdatac;
break;
case HPDT_AUTOTRADE_VEND:
ret->HPDataSRCPtr = (void**)(&((struct autotrade_vending *)ptr)->hdata);
ret->hdatac = &((struct autotrade_vending *)ptr)->hdatac;
break;
default:
return false;
}
return true;
}
void HPM_map_plugin_load_sub(struct hplugin *plugin) {
plugin->hpi->sql_handle = map->mysql_handle;
plugin->hpi->addCommand = atcommand->create;
plugin->hpi->addScript = script->addScript;
plugin->hpi->addPCGPermission = HPM_map_add_group_permission;
}
bool HPM_map_add_atcommand(char *name, AtCommandFunc func) {
unsigned int i = 0;
for(i = 0; i < atcommand_list_items; i++) {
if( !strcmpi(atcommand_list[i].name,name) ) {
ShowDebug("HPM_map_add_atcommand: duplicate command '%s', skipping...\n", name);
return false;
}
}
i = atcommand_list_items;
RECREATE(atcommand_list, struct HPM_atcommand_list , ++atcommand_list_items);
safestrncpy(atcommand_list[i].name, name, sizeof(atcommand_list[i].name));
atcommand_list[i].func = func;
return true;
}
void HPM_map_atcommands(void) {
unsigned int i;
for(i = 0; i < atcommand_list_items; i++) {
atcommand->add(atcommand_list[i].name,atcommand_list[i].func,true);
}
}
/**
* Adds a new group permission to the HPM-provided list
**/
void HPM_map_add_group_permission(unsigned int pluginID, char *name, unsigned int *mask) {
unsigned char index = pcg->HPMpermissions_count;
RECREATE(pcg->HPMpermissions, struct pc_groups_new_permission, ++pcg->HPMpermissions_count);
pcg->HPMpermissions[index].pID = pluginID;
pcg->HPMpermissions[index].name = aStrdup(name);
pcg->HPMpermissions[index].mask = mask;
}
void HPM_map_do_init(void) {
HPM->load_sub = HPM_map_plugin_load_sub;
HPM->grabHPDataSub = HPM_map_grabHPData;
HPM->datacheck_init(HPMDataCheck, HPMDataCheckLen, HPMDataCheckVer);
HPM_shared_symbols(SERVER_TYPE_MAP);
}
void HPM_map_do_final(void) {
if (atcommand_list)
aFree(atcommand_list);
/**
* why is pcg->HPM being cleared here? because PCG's do_final is not final,
* is used on reload, and would thus cause plugin-provided permissions to go away
**/
if (pcg->HPMpermissions) {
unsigned char i;
for (i = 0; i < pcg->HPMpermissions_count; i++) {
aFree(pcg->HPMpermissions[i].name);
}
aFree(pcg->HPMpermissions);
}
HPM->datacheck_final();
}
|