Guest User

Untitled

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