Advertisement
Guest User

offlineshop_config.cpp

a guest
Sep 8th, 2017
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.97 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <sstream>
  3. #include "utils.h"
  4. #include "log.h"
  5. #include "dev_log.h"
  6. #include "config.h"
  7. #include "offlineshop_config.h"
  8.  
  9. enum
  10. {
  11. GOLD_MAX = 2000000000,
  12. ITEM_MAX_COUNT = 200,
  13. };
  14.  
  15. using namespace std;
  16.  
  17. BYTE g_bOfflineShopSaveTime = 5;
  18.  
  19. // Offline Shop Need Money
  20. bool g_bNeedMoney = false;
  21. DWORD g_dwNeedMoney = 0;
  22. int g_iTotalOfflineShopCount = 1000;
  23. // End Of Offline Shop Need Money
  24.  
  25. // Offline Shop Need Item
  26. bool g_bNeedItem = false;
  27. int g_iItemVnum = 0;
  28. BYTE g_bItemCount = 0;
  29. // End Of Offline Shop Need Item
  30.  
  31. bool g_bOfflineShopMapAllowLimit = false;
  32. static set<int> s_set_offlineshop_map_allows;
  33.  
  34. bool g_bEnableRespawnOfflineShop = true;
  35. BYTE g_bOfflineShopSocketMax = 4;
  36.  
  37. bool offlineshop_map_allow_find(int mapIndex)
  38. {
  39. if (g_bAuthServer)
  40. return false;
  41.  
  42. if (s_set_offlineshop_map_allows.find(mapIndex) == s_set_offlineshop_map_allows.end())
  43. return false;
  44.  
  45. return true;
  46. }
  47.  
  48. void offlineshop_map_allow_add(int mapIndex)
  49. {
  50. if (offlineshop_map_allow_find(mapIndex))
  51. {
  52. fprintf(stderr, "Multiple map allow detected!");
  53. exit(1);
  54. }
  55.  
  56. fprintf(stdout, "OFFLINESHOP_MAP_ALLOW: %d\n", mapIndex);
  57. s_set_offlineshop_map_allows.insert(mapIndex);
  58. }
  59.  
  60. void offlineshop_config_init()
  61. {
  62. if (!g_bAuthServer)
  63. {
  64. FILE * file;
  65.  
  66. char buf[256], token_string[256], value_string[256];
  67.  
  68. if (!(file = fopen("OFFLINE_SHOP_CONFIG", "r")))
  69. {
  70. fprintf(stderr, "Can not open [OFFLINE_SHOP_CONFIG]\n");
  71. exit(1);
  72. }
  73.  
  74. while (fgets(buf, 256, file))
  75. {
  76. parse_token(buf, token_string, value_string);
  77.  
  78. TOKEN("OFFLINE_SHOP_SAVE_TIME")
  79. {
  80. g_bOfflineShopSaveTime = MINMAX(1, g_bOfflineShopSaveTime, 10);
  81. str_to_number(g_bOfflineShopSaveTime, value_string);
  82. sys_log(0, "OFFLINE_SHOP_SAVE_TIME: %d", g_bOfflineShopSaveTime);
  83. }
  84.  
  85. TOKEN("OFFLINE_SHOP_NEED_MONEY")
  86. {
  87. char arg1[256];
  88. char arg2[256];
  89. two_arguments(value_string, arg1, sizeof(arg1), arg2, sizeof(arg2));
  90.  
  91. if (!*arg1 || !*arg2)
  92. {
  93. fprintf(stderr, "OFFLINE_SHOP_NEED_MONEY syntax: offline_shop_need_money <disable or enable> <money>");
  94. exit(1);
  95. }
  96. else if (!isnhdigit(*arg2))
  97. {
  98. fprintf(stderr, "Second argument must be integer!");
  99. exit(1);
  100. }
  101.  
  102. if (!strcmp(arg1, "enable"))
  103. g_bNeedMoney = true;
  104. else if (!strcmp(arg1, "disable"))
  105. g_bNeedMoney = false;
  106. else if (isnhdigit(*arg1))
  107. str_to_number(g_bNeedMoney, arg1);
  108.  
  109. // Check overflow and configure the money.
  110. g_dwNeedMoney = MINMAX(1, g_dwNeedMoney, GOLD_MAX);
  111.  
  112. str_to_number(g_dwNeedMoney, arg2);
  113. sys_log(0, "OFFLINE_SHOP_NEED_MONEY: %s - Money %u", g_bNeedMoney ? "Enabled" : "Disabled", g_dwNeedMoney);
  114. }
  115.  
  116. TOKEN("OFFLINE_SHOP_TOTAL_COUNT")
  117. {
  118. str_to_number(g_iTotalOfflineShopCount, value_string);
  119. sys_log(0, "OFFLINE_SHOP_TOTAL_COUNT: %d", g_iTotalOfflineShopCount);
  120. }
  121.  
  122. TOKEN("OFFLINE_SHOP_NEED_ITEM")
  123. {
  124. char arg1[256];
  125. char arg2[256];
  126. char arg3[256];
  127. three_arguments(value_string, arg1, sizeof(arg1), arg2, sizeof(arg2), arg3, sizeof(arg3));
  128.  
  129. if (!*arg1 || !*arg2 || !*arg3)
  130. {
  131. fprintf(stderr, "OFFLINE_SHOP_NEED_ITEM syntax: offline_shop_need_item <enable or disable> <item_vnum> <item_count>");
  132. exit(1);
  133. }
  134. else if (!isnhdigit(*arg2) || !isnhdigit(*arg3))
  135. {
  136. fprintf(stderr, "Second argument and third argument must be integer!");
  137. exit(1);
  138. }
  139.  
  140. if (!strcmp(arg1, "enable"))
  141. g_bNeedItem = true;
  142. else if (!strcmp(arg1, "disable"))
  143. g_bNeedItem = false;
  144. else if (isnhdigit(*arg1))
  145. str_to_number(g_bNeedItem, arg1);
  146.  
  147.  
  148. // Item count can be maximum 200.
  149. g_bItemCount = MINMAX(1, g_bItemCount, ITEM_MAX_COUNT);
  150.  
  151. str_to_number(g_iItemVnum, arg2);
  152. str_to_number(g_bItemCount, arg3);
  153. sys_log(0, "OFFLINE_SHOP_NEED_ITEM: %s %d %d", g_bNeedItem ? "Enabled" : "Disabled", g_iItemVnum, g_bItemCount);
  154. }
  155.  
  156. TOKEN("OFFLINE_SHOP_MAP_ALLOW_LIMIT")
  157. {
  158. char arg1[256];
  159. one_argument(value_string, arg1, sizeof(arg1));
  160.  
  161. if (!*arg1)
  162. {
  163. fprintf(stderr, "OFFLINE_SHOP_MAP_ALLOW_LIMIT syntax: offline_shop_map_allow_limit <enable or disable> or < 0 or 1 >");
  164. exit(1);
  165. }
  166.  
  167. if (!strcmp(arg1, "enable"))
  168. g_bOfflineShopMapAllowLimit = true;
  169. else if(!strcmp(arg1, "disable"))
  170. g_bOfflineShopMapAllowLimit = false;
  171. else if(isnhdigit(*arg1))
  172. str_to_number(g_bOfflineShopMapAllowLimit, arg1);
  173. }
  174.  
  175. TOKEN("OFFLINE_SHOP_MAP_ALLOW")
  176. {
  177. if (!g_bOfflineShopMapAllowLimit)
  178. {
  179. fprintf(stderr, "OFFLINE_SHOP_MAP_ALLOW_LIMIT must be enable for this option!");
  180. exit(1);
  181. }
  182.  
  183. char * p = value_string;
  184. string stNum;
  185.  
  186. for(; *p; p++)
  187. {
  188. if (isnhspace(*p))
  189. {
  190. if (stNum.length())
  191. {
  192. int index = 0;
  193. str_to_number(index, stNum.c_str());
  194. offlineshop_map_allow_add(index);
  195. stNum.clear();
  196. }
  197. }
  198. else
  199. stNum += *p;
  200. }
  201.  
  202. if (stNum.length())
  203. {
  204. int index = 0;
  205. str_to_number(index, stNum.c_str());
  206. offlineshop_map_allow_add(index);
  207. }
  208.  
  209. continue;
  210. }
  211.  
  212. TOKEN("OFFLINE_SHOP_RESPAWN")
  213. {
  214. char arg1[256];
  215. one_argument(value_string, arg1, sizeof(arg1));
  216.  
  217. if (!*arg1)
  218. {
  219. fprintf(stderr, "OFFLINE_SHOP_RESPAWN syntax : offline_shop_respawn: <string or integer>");
  220. exit(1);
  221. }
  222.  
  223. if (!strcmp(arg1, "enable"))
  224. g_bEnableRespawnOfflineShop = true;
  225. else if (!strcmp(arg1, "disable"))
  226. g_bEnableRespawnOfflineShop = false;
  227. else if (isnhdigit(*arg1))
  228. str_to_number(g_bEnableRespawnOfflineShop, value_string);
  229. }
  230.  
  231. TOKEN("OFFLINE_SHOP_SOCKET_MAX")
  232. {
  233. str_to_number(g_bOfflineShopSocketMax, value_string);
  234. g_bOfflineShopSocketMax = MINMAX(3, g_bOfflineShopSocketMax, 6);
  235. fprintf(stderr, "OFFLINE_SHOP_SOCKET_MAX: %d", g_bOfflineShopSocketMax);
  236. }
  237. }
  238. }
  239. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement