Advertisement
deyan4you

Untitled

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