/src/map/HPMmap.c

https://gitlab.com/evol/hercules · C · 201 lines · 142 code · 22 blank · 37 comment · 7 complexity · 2c331ff39034174bc1b3fc8a878792fb MD5 · raw file

  1. /**
  2. * This file is part of Hercules.
  3. * http://herc.ws - http://github.com/HerculesWS/Hercules
  4. *
  5. * Copyright (C) 2013-2015 Hercules Dev Team
  6. *
  7. * Hercules is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #define HERCULES_CORE
  21. #include "HPMmap.h"
  22. #include "common/HPM.h"
  23. #include "common/cbasetypes.h"
  24. #include "common/HPMi.h"
  25. #include "common/conf.h"
  26. #include "common/console.h"
  27. #include "common/core.h"
  28. #include "common/db.h"
  29. #include "common/des.h"
  30. #include "common/ers.h"
  31. #include "common/memmgr.h"
  32. #include "common/mapindex.h"
  33. #include "common/mmo.h"
  34. #include "common/nullpo.h"
  35. #include "common/showmsg.h"
  36. #include "common/socket.h"
  37. #include "common/spinlock.h"
  38. #include "common/sql.h"
  39. #include "common/strlib.h"
  40. #include "common/sysinfo.h"
  41. #include "common/timer.h"
  42. #include "common/utils.h"
  43. #include "map/atcommand.h"
  44. #include "map/battle.h"
  45. #include "map/battleground.h"
  46. #include "map/buyingstore.h"
  47. #include "map/channel.h"
  48. #include "map/chat.h"
  49. #include "map/chrif.h"
  50. #include "map/clif.h"
  51. #include "map/date.h"
  52. #include "map/duel.h"
  53. #include "map/elemental.h"
  54. #include "map/guild.h"
  55. #include "map/homunculus.h"
  56. #include "map/instance.h"
  57. #include "map/intif.h"
  58. #include "map/irc-bot.h"
  59. #include "map/itemdb.h"
  60. #include "map/log.h"
  61. #include "map/mail.h"
  62. #include "map/map.h"
  63. #include "map/mapreg.h"
  64. #include "map/mercenary.h"
  65. #include "map/mob.h"
  66. #include "map/npc.h"
  67. #include "map/packets_struct.h"
  68. #include "map/party.h"
  69. #include "map/path.h"
  70. #include "map/pc.h"
  71. #include "map/pc_groups.h"
  72. #include "map/pet.h"
  73. #include "map/quest.h"
  74. #include "map/script.h"
  75. #include "map/searchstore.h"
  76. #include "map/skill.h"
  77. #include "map/status.h"
  78. #include "map/storage.h"
  79. #include "map/trade.h"
  80. #include "map/unit.h"
  81. #include "map/vending.h"
  82. // HPMDataCheck comes after all the other includes
  83. #include "common/HPMDataCheck.h"
  84. #include <stdio.h>
  85. #include <stdlib.h>
  86. struct HPM_atcommand_list {
  87. //tracking currently not enabled
  88. // - requires modifying how plugins calls atcommand creation
  89. // - needs load/unload during runtime support
  90. //unsigned int pID;/* plugin id */
  91. char name[ATCOMMAND_LENGTH];
  92. AtCommandFunc func;
  93. };
  94. struct HPM_atcommand_list *atcommand_list = NULL;
  95. unsigned int atcommand_list_items = 0;
  96. /**
  97. * HPM plugin data store validator sub-handler (map-server)
  98. *
  99. * @see HPM_interface::data_store_validate
  100. */
  101. bool HPM_map_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **storeptr, bool initialize)
  102. {
  103. switch (type) {
  104. case HPDT_MSD:
  105. case HPDT_NPCD:
  106. case HPDT_MAP:
  107. case HPDT_PARTY:
  108. case HPDT_GUILD:
  109. case HPDT_INSTANCE:
  110. case HPDT_MOBDB:
  111. case HPDT_MOBDATA:
  112. case HPDT_ITEMDATA:
  113. case HPDT_BGDATA:
  114. case HPDT_AUTOTRADE_VEND:
  115. // Initialized by the caller.
  116. return true;
  117. default:
  118. break;
  119. }
  120. return false;
  121. }
  122. void HPM_map_plugin_load_sub(struct hplugin *plugin) {
  123. plugin->hpi->sql_handle = map->mysql_handle;
  124. plugin->hpi->addCommand = atcommand->create;
  125. plugin->hpi->addScript = script->addScript;
  126. plugin->hpi->addPCGPermission = HPM_map_add_group_permission;
  127. }
  128. bool HPM_map_add_atcommand(char *name, AtCommandFunc func) {
  129. unsigned int i = 0;
  130. for(i = 0; i < atcommand_list_items; i++) {
  131. if( !strcmpi(atcommand_list[i].name,name) ) {
  132. ShowDebug("HPM_map_add_atcommand: duplicate command '%s', skipping...\n", name);
  133. return false;
  134. }
  135. }
  136. i = atcommand_list_items;
  137. RECREATE(atcommand_list, struct HPM_atcommand_list , ++atcommand_list_items);
  138. safestrncpy(atcommand_list[i].name, name, sizeof(atcommand_list[i].name));
  139. atcommand_list[i].func = func;
  140. return true;
  141. }
  142. void HPM_map_atcommands(void) {
  143. unsigned int i;
  144. for(i = 0; i < atcommand_list_items; i++) {
  145. atcommand->add(atcommand_list[i].name,atcommand_list[i].func,true);
  146. }
  147. }
  148. /**
  149. * Adds a new group permission to the HPM-provided list
  150. **/
  151. void HPM_map_add_group_permission(unsigned int pluginID, char *name, unsigned int *mask) {
  152. unsigned char index = pcg->HPMpermissions_count;
  153. RECREATE(pcg->HPMpermissions, struct pc_groups_new_permission, ++pcg->HPMpermissions_count);
  154. pcg->HPMpermissions[index].pID = pluginID;
  155. pcg->HPMpermissions[index].name = aStrdup(name);
  156. pcg->HPMpermissions[index].mask = mask;
  157. }
  158. void HPM_map_do_init(void) {
  159. HPM->load_sub = HPM_map_plugin_load_sub;
  160. HPM->data_store_validate_sub = HPM_map_data_store_validate;
  161. HPM->datacheck_init(HPMDataCheck, HPMDataCheckLen, HPMDataCheckVer);
  162. HPM_shared_symbols(SERVER_TYPE_MAP);
  163. }
  164. void HPM_map_do_final(void) {
  165. if (atcommand_list)
  166. aFree(atcommand_list);
  167. /**
  168. * why is pcg->HPM being cleared here? because PCG's do_final is not final,
  169. * is used on reload, and would thus cause plugin-provided permissions to go away
  170. **/
  171. if (pcg->HPMpermissions) {
  172. unsigned char i;
  173. for (i = 0; i < pcg->HPMpermissions_count; i++) {
  174. aFree(pcg->HPMpermissions[i].name);
  175. }
  176. aFree(pcg->HPMpermissions);
  177. }
  178. HPM->datacheck_final();
  179. }