Advertisement
Guest User

Untitled

a guest
Feb 14th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 43.52 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <sstream>
  3. #ifndef __WIN32__
  4. #include <ifaddrs.h>
  5. #endif
  6.  
  7. #include "constants.h"
  8. #include "utils.h"
  9. #include "log.h"
  10. #include "desc.h"
  11. #include "desc_manager.h"
  12. #include "item_manager.h"
  13. #include "p2p.h"
  14. #include "char.h"
  15. #include "ip_ban.h"
  16. #include "war_map.h"
  17. #include "locale_service.h"
  18. #include "config.h"
  19. #include "dev_log.h"
  20. #include "db.h"
  21. #include "skill_power.h"
  22. #include "check_server.h"
  23.  
  24. using std::string;
  25.  
  26. BYTE g_bChannel = 0;
  27. WORD mother_port = 50080;
  28. int passes_per_sec = 25;
  29. WORD db_port = 0;
  30. WORD p2p_port = 50900;
  31. char db_addr[ADDRESS_MAX_LEN + 1];
  32. int save_event_second_cycle = passes_per_sec * 120; // 3şĐ
  33. int ping_event_second_cycle = passes_per_sec * 60;
  34. bool g_bNoMoreClient = false;
  35. bool g_bNoRegen = false;
  36. bool g_bNoPasspod = false;
  37. // #ifdef ENABLE_NEWSTUFF
  38. bool g_bEmpireShopPriceTripleDisable = false;
  39. bool g_bShoutAddonEnable = false;
  40. bool g_bGlobalShoutEnable = false;
  41. bool g_bDisablePrismNeed = false;
  42. bool g_bDisableEmotionMask = false;
  43. BYTE g_bItemCountLimit = 200;
  44. DWORD g_dwItemBonusChangeTime = 60;
  45. bool g_bAllMountAttack = false;
  46. bool g_bEnableBootaryCheck = false;
  47. bool g_bGMHostCheck = false;
  48. bool g_bGuildInviteLimit = false;
  49. bool g_bGuildInfiniteMembers = false;
  50. bool g_bChinaIntoxicationCheck = false;
  51. bool g_bEnableSpeedHackCrash = false;
  52. int g_iStatusPointGetLevelLimit = 90;
  53. int g_iStatusPointSetMaxValue = 90;
  54. int g_iShoutLimitLevel = 15;
  55. // int g_iShoutLimitTime = 15;
  56. int g_iDbLogLevel = LOG_LEVEL_MAX;
  57. int g_iSysLogLevel = LOG_LEVEL_MAX;
  58. int g_aiItemDestroyTime[ITEM_DESTROY_TIME_MAX] = {300, 150, 300}; // autoitem, dropgold, dropitem
  59. bool g_bDisableEmpireLanguageCheck = false;
  60. DWORD g_dwSkillBookNextReadMin = 28800;
  61. DWORD g_dwSkillBookNextReadMax = 43200;
  62. // #endif
  63.  
  64. // TRAFFIC_PROFILER
  65. bool g_bTrafficProfileOn = false;
  66. DWORD g_dwTrafficProfileFlushCycle = 3600;
  67. // END_OF_TRAFFIC_PROFILER
  68.  
  69. int test_server = 0;
  70. int speed_server = 0;
  71. #ifdef __AUCTION__
  72. int auction_server = 0;
  73. #endif
  74. bool distribution_test_server = false;
  75. bool china_event_server = false;
  76. bool guild_mark_server = true;
  77. BYTE guild_mark_min_level = 3;
  78. bool no_wander = false;
  79. int g_iUserLimit = 32768;
  80.  
  81. char g_szPublicIP[16] = "0";
  82. char g_szInternalIP[16] = "0";
  83. bool g_bSkillDisable = false;
  84. int g_iFullUserCount = 1200;
  85. int g_iBusyUserCount = 650;
  86. //Canada
  87. //int g_iFullUserCount = 600;
  88. //int g_iBusyUserCount = 350;
  89. //Brazil
  90. //int g_iFullUserCount = 650;
  91. //int g_iBusyUserCount = 450;
  92. bool g_bEmpireWhisper = true;
  93. BYTE g_bAuthServer = false;
  94.  
  95. bool g_bCheckClientVersion = true;
  96. string g_stClientVersion = "1215955205";
  97.  
  98. BYTE g_bBilling = false;
  99.  
  100. string g_stAuthMasterIP;
  101. WORD g_wAuthMasterPort = 0;
  102.  
  103. static std::set<DWORD> s_set_dwFileCRC;
  104. static std::set<DWORD> s_set_dwProcessCRC;
  105.  
  106. string g_stHostname = "";
  107. string g_table_postfix = "";
  108.  
  109. string g_stQuestDir = "./quest";
  110. //string g_stQuestObjectDir = "./quest/object";
  111. string g_stDefaultQuestObjectDir = "./quest/object";
  112. std::set<string> g_setQuestObjectDir;
  113.  
  114. std::vector<std::string> g_stAdminPageIP;
  115. std::string g_stAdminPagePassword = "SHOWMETHEMONEY";
  116.  
  117. string g_stBlockDate = "30000705";
  118.  
  119. extern string g_stLocale;
  120.  
  121. char teen_addr[ADDRESS_MAX_LEN + 1] = {0};
  122. WORD teen_port = 0;
  123.  
  124. int SPEEDHACK_LIMIT_COUNT = 50;
  125. int SPEEDHACK_LIMIT_BONUS = 80;
  126. int g_iSyncHackLimitCount = 10;
  127.  
  128. //˝Ăľß = VIEW_RANGE + VIEW_BONUS_RANGE
  129. //VIEW_BONUSE_RANGE : Ŭ¶óŔĚľđĆ®żÍ ˝Ăľß Ăł¸®żˇĽ­łĘą« µü ¶łľîÁú°ćżě ą®Á¦°ˇ ąß»ýÇŇĽöŔÖľî 500CMŔÇ ż©şĐŔ» Ç×»óÁŘ´Ů.
  130. int VIEW_RANGE = 5000;
  131. int VIEW_BONUS_RANGE = 500;
  132.  
  133. int g_server_id = 0;
  134. string g_strWebMallURL = "www.metin2.de";
  135.  
  136. unsigned int g_uiSpamBlockDuration = 60 * 15; // ±âş» 15şĐ
  137. unsigned int g_uiSpamBlockScore = 100; // ±âş» 100Áˇ
  138. unsigned int g_uiSpamReloadCycle = 60 * 10; // ±âş» 10şĐ
  139.  
  140. bool g_bCheckMultiHack = true;
  141.  
  142. int g_iSpamBlockMaxLevel = 10;
  143.  
  144. void LoadStateUserCount();
  145. void LoadValidCRCList();
  146. bool LoadClientVersion();
  147. bool g_protectNormalPlayer = false; // ąüąýŔÚ°ˇ "ĆňČ­¸đµĺ" ŔÎ ŔĎąÝŔŻŔú¸¦ °ř°ÝÇĎÁö ¸řÇÔ
  148. bool g_noticeBattleZone = false; // Á߸łÁö´ëżˇ ŔÔŔĺÇĎ¸é ľČł»¸ŢĽĽÁö¸¦ ľË·ÁÁÜ
  149.  
  150. bool isHackShieldEnable = false;
  151. int HackShield_FirstCheckWaitTime = passes_per_sec * 30;
  152. int HackShield_CheckCycleTime = passes_per_sec * 180;
  153.  
  154. bool bXTrapEnabled = false;
  155.  
  156. int gPlayerMaxLevel = 99;
  157. int gShutdownAge = 0;
  158. int gShutdownEnable = 0;
  159.  
  160. /*
  161. * NOTE : ÇŮ ĂĽĹ© On/Off. CheckInÇҶ§ false·Î ĽöÁ¤ÇßŔ¸¸é ąÝµĺ˝Ă Č®ŔÎÇĎ°í °íĂÄłőŔ»°Í!
  162. * ŔĚ°É·Î »ý±ćĽöŔÖ´Â ¶ËŔş ĂĄŔÓľČÁü ~ ity ~
  163. */
  164. bool gHackCheckEnable = false;
  165.  
  166. bool g_BlockCharCreation = false;
  167.  
  168.  
  169. //OPENID
  170. int openid_server = 0;
  171. char openid_host[256];
  172. char openid_uri[256];
  173.  
  174. bool is_string_true(const char * string)
  175. {
  176. bool result = 0;
  177. if (isnhdigit(*string))
  178. {
  179. str_to_number(result, string);
  180. return result > 0 ? true : false;
  181. }
  182. else if (LOWER(*string) == 't')
  183. return true;
  184. else
  185. return false;
  186. }
  187.  
  188. static std::set<int> s_set_map_allows;
  189.  
  190. bool map_allow_find(int index)
  191. {
  192. if (g_bAuthServer)
  193. return false;
  194.  
  195. if (s_set_map_allows.find(index) == s_set_map_allows.end())
  196. return false;
  197.  
  198. return true;
  199. }
  200.  
  201. void map_allow_log()
  202. {
  203. std::set<int>::iterator i;
  204.  
  205. for (i = s_set_map_allows.begin(); i != s_set_map_allows.end(); ++i)
  206. sys_log(0, "MAP_ALLOW: %d", *i);
  207. }
  208.  
  209. void map_allow_add(int index)
  210. {
  211. if (map_allow_find(index) == true)
  212. {
  213. fprintf(stdout, "!!! FATAL ERROR !!! multiple MAP_ALLOW setting!!\n");
  214. exit(1);
  215. }
  216.  
  217. fprintf(stdout, "MAP ALLOW %d\n", index);
  218. s_set_map_allows.insert(index);
  219. }
  220.  
  221. void map_allow_copy(long * pl, int size)
  222. {
  223. int iCount = 0;
  224. std::set<int>::iterator it = s_set_map_allows.begin();
  225.  
  226. while (it != s_set_map_allows.end())
  227. {
  228. int i = *(it++);
  229. *(pl++) = i;
  230.  
  231. if (++iCount > size)
  232. break;
  233. }
  234. }
  235.  
  236. static void FN_add_adminpageIP(char *line)
  237. {
  238. char *last;
  239. const char *delim = " \t\r\n";
  240. char *v = strtok_r(line, delim, &last);
  241.  
  242. while (v)
  243. {
  244. g_stAdminPageIP.push_back(v);
  245. v = strtok_r(NULL, delim, &last);
  246. }
  247. }
  248.  
  249. static void FN_log_adminpage()
  250. {
  251. itertype(g_stAdminPageIP) iter = g_stAdminPageIP.begin();
  252.  
  253. while (iter != g_stAdminPageIP.end())
  254. {
  255. dev_log(LOG_DEB0, "ADMIN_PAGE_IP = %s", (*iter).c_str());
  256. ++iter;
  257. }
  258.  
  259. dev_log(LOG_DEB0, "ADMIN_PAGE_PASSWORD = %s", g_stAdminPagePassword.c_str());
  260. }
  261.  
  262. #define ENABLE_AUTODETECT_INTERNAL_IP
  263. bool GetIPInfo()
  264. {
  265. #ifndef __WIN32__
  266. struct ifaddrs* ifaddrp = NULL;
  267.  
  268. if (0 != getifaddrs(&ifaddrp))
  269. return false;
  270.  
  271. for( struct ifaddrs* ifap=ifaddrp ; NULL != ifap ; ifap = ifap->ifa_next )
  272. {
  273. struct sockaddr_in * sai = (struct sockaddr_in *) ifap->ifa_addr;
  274.  
  275. if (!ifap->ifa_netmask || // ignore if no netmask
  276. sai->sin_addr.s_addr == 0 || // ignore if address is 0.0.0.0
  277. sai->sin_addr.s_addr == 16777343) // ignore if address is 127.0.0.1
  278. continue;
  279. #else
  280. WSADATA wsa_data;
  281. char host_name[100];
  282. HOSTENT* host_ent;
  283. int n = 0;
  284.  
  285. if (WSAStartup(0x0101, &wsa_data)) {
  286. return false;
  287. }
  288.  
  289. gethostname(host_name, sizeof(host_name));
  290. host_ent = gethostbyname(host_name);
  291. if (host_ent == NULL) {
  292. return false;
  293. }
  294. for ( ; host_ent->h_addr_list[n] != NULL; ++n) {
  295. struct sockaddr_in addr;
  296. struct sockaddr_in* sai = &addr;
  297. memcpy(&sai->sin_addr.s_addr, host_ent->h_addr_list[n], host_ent->h_length);
  298. #endif
  299.  
  300. char * netip = inet_ntoa(sai->sin_addr);
  301.  
  302. if (!strncmp(netip, "192.168", 7)) // ignore if address is starting with 192
  303. {
  304. strlcpy(g_szInternalIP, netip, sizeof(g_szInternalIP));
  305. #ifndef __WIN32__
  306. fprintf(stderr, "INTERNAL_IP: %s interface %s\n", netip, ifap->ifa_name);
  307. #else
  308. fprintf(stderr, "INTERNAL_IP: %s\n", netip);
  309. #endif
  310. }
  311. else if (!strncmp(netip, "10.", 3))
  312. {
  313. strlcpy(g_szInternalIP, netip, sizeof(g_szInternalIP));
  314. #ifndef __WIN32__
  315. fprintf(stderr, "INTERNAL_IP: %s interface %s\n", netip, ifap->ifa_name);
  316. #else
  317. fprintf(stderr, "INTERNAL_IP: %s\n", netip);
  318. #endif
  319. }
  320. else if (g_szPublicIP[0] == '0')
  321. {
  322. strlcpy(g_szPublicIP, netip, sizeof(g_szPublicIP));
  323. #ifndef __WIN32__
  324. fprintf(stderr, "PUBLIC_IP: %s interface %s\n", netip, ifap->ifa_name);
  325. #else
  326. fprintf(stderr, "PUBLIC_IP: %s\n", netip);
  327. #endif
  328. }
  329. }
  330.  
  331. #ifndef __WIN32__
  332. freeifaddrs( ifaddrp );
  333. #else
  334. WSACleanup();
  335. #endif
  336.  
  337. if (g_szPublicIP[0] != '0')
  338. return true;
  339. else
  340. {
  341. #ifdef ENABLE_AUTODETECT_INTERNAL_IP
  342. if (g_szInternalIP[0] == '0')
  343. return false;
  344. else
  345. strlcpy(g_szPublicIP, g_szInternalIP, sizeof(g_szPublicIP));
  346. return true;
  347. #else
  348. return false;
  349. #endif
  350. }
  351. }
  352.  
  353. static bool __LoadConnectConfigFile(const char* configName)
  354. {
  355. char buf[256];
  356. char token_string[256];
  357. char value_string[256];
  358.  
  359. char db_host[2][64], db_user[2][64], db_pwd[2][64], db_db[2][64];
  360. // ... ľĆ... db_port´Â ŔĚąĚ ŔִµĄ... ł×ŔĚąÖ ľîÂîÇŘľßÇÔ...
  361. int mysql_db_port[2];
  362.  
  363. for (int n = 0; n < 2; ++n)
  364. {
  365. *db_host[n] = '\0';
  366. *db_user[n] = '\0';
  367. *db_pwd[n]= '\0';
  368. *db_db[n]= '\0';
  369. mysql_db_port[n] = 0;
  370. }
  371.  
  372. char log_host[64], log_user[64], log_pwd[64], log_db[64];
  373. int log_port = 0;
  374.  
  375. *log_host = '\0';
  376. *log_user = '\0';
  377. *log_pwd = '\0';
  378. *log_db = '\0';
  379.  
  380.  
  381. // DBżˇĽ­ ·ÎÄÉŔĎÁ¤ş¸¸¦ ĽĽĆĂÇϱâŔ§ÇŘĽ­´Â ´Ů¸Ą ĽĽĆĂ°Şş¸´Ů Ľ±ÇŕµÇľîĽ­
  382. // DBÁ¤ş¸¸¸ ŔĐľîżÍ ·ÎÄÉŔĎ ĽĽĆĂŔ» ÇŃČÄ ´Ů¸Ą ĽĽĆĂŔ» Ŕűżë˝ĂÄŃľßÇŃ´Ů.
  383. // ŔĚŔŻ´Â ·ÎÄÉŔĎ°ü·ĂµČ ĂʱâČ­ ·çĆľŔĚ °÷°÷żˇ Á¸ŔçÇϱ⠶§ą®.
  384.  
  385. bool isCommonSQL = false;
  386. bool isPlayerSQL = false;
  387.  
  388. FILE* fpOnlyForDB;
  389.  
  390. if (!(fpOnlyForDB = fopen(configName, "r")))
  391. {
  392. fprintf(stderr, "Can not open [%s]\n", configName);
  393. exit(1);
  394. }
  395.  
  396. while (fgets(buf, 256, fpOnlyForDB))
  397. {
  398. parse_token(buf, token_string, value_string);
  399.  
  400. TOKEN("hostname")
  401. {
  402. g_stHostname = value_string;
  403. fprintf(stdout, "HOSTNAME: %s\n", g_stHostname.c_str());
  404. continue;
  405. }
  406.  
  407. TOKEN("channel")
  408. {
  409. str_to_number(g_bChannel, value_string);
  410. continue;
  411. }
  412.  
  413. TOKEN("player_sql")
  414. {
  415. const char * line = two_arguments(value_string, db_host[0], sizeof(db_host[0]), db_user[0], sizeof(db_user[0]));
  416. line = two_arguments(line, db_pwd[0], sizeof(db_pwd[0]), db_db[0], sizeof(db_db[0]));
  417.  
  418. if ('\0' != line[0])
  419. {
  420. char buf[256];
  421. one_argument(line, buf, sizeof(buf));
  422. str_to_number(mysql_db_port[0], buf);
  423. }
  424.  
  425. if (!*db_host[0] || !*db_user[0] || !*db_pwd[0] || !*db_db[0])
  426. {
  427. fprintf(stderr, "PLAYER_SQL syntax: logsql <host user password db>\n");
  428. exit(1);
  429. }
  430.  
  431. char buf[1024];
  432. snprintf(buf, sizeof(buf), "PLAYER_SQL: %s %s %s %s %d", db_host[0], db_user[0], db_pwd[0], db_db[0], mysql_db_port[0]);
  433. isPlayerSQL = true;
  434. continue;
  435. }
  436.  
  437. TOKEN("common_sql")
  438. {
  439. const char * line = two_arguments(value_string, db_host[1], sizeof(db_host[1]), db_user[1], sizeof(db_user[1]));
  440. line = two_arguments(line, db_pwd[1], sizeof(db_pwd[1]), db_db[1], sizeof(db_db[1]));
  441.  
  442. if ('\0' != line[0])
  443. {
  444. char buf[256];
  445. one_argument(line, buf, sizeof(buf));
  446. str_to_number(mysql_db_port[1], buf);
  447. }
  448.  
  449. if (!*db_host[1] || !*db_user[1] || !*db_pwd[1] || !*db_db[1])
  450. {
  451. fprintf(stderr, "COMMON_SQL syntax: logsql <host user password db>\n");
  452. exit(1);
  453. }
  454.  
  455. char buf[1024];
  456. snprintf(buf, sizeof(buf), "COMMON_SQL: %s %s %s %s %d", db_host[1], db_user[1], db_pwd[1], db_db[1], mysql_db_port[1]);
  457. isCommonSQL = true;
  458. continue;
  459. }
  460.  
  461. TOKEN("log_sql")
  462. {
  463. const char * line = two_arguments(value_string, log_host, sizeof(log_host), log_user, sizeof(log_user));
  464. line = two_arguments(line, log_pwd, sizeof(log_pwd), log_db, sizeof(log_db));
  465.  
  466. if ('\0' != line[0])
  467. {
  468. char buf[256];
  469. one_argument(line, buf, sizeof(buf));
  470. str_to_number(log_port, buf);
  471. }
  472.  
  473. if (!*log_host || !*log_user || !*log_pwd || !*log_db)
  474. {
  475. fprintf(stderr, "LOG_SQL syntax: logsql <host user password db>\n");
  476. exit(1);
  477. }
  478.  
  479. char buf[1024];
  480. snprintf(buf, sizeof(buf), "LOG_SQL: %s %s %s %s %d", log_host, log_user, log_pwd, log_db, log_port);
  481. continue;
  482. }
  483. }
  484.  
  485. //Ăł¸®°ˇ łˇłµŔ¸´Ď ĆÄŔĎŔ» ´ÝŔÚ.
  486. fclose(fpOnlyForDB);
  487.  
  488. // CONFIG_SQL_INFO_ERROR
  489. if (!isCommonSQL)
  490. {
  491. puts("LOAD_COMMON_SQL_INFO_FAILURE:");
  492. puts("");
  493. puts("CONFIG:");
  494. puts("------------------------------------------------");
  495. puts("COMMON_SQL: HOST USER PASSWORD DATABASE");
  496. puts("");
  497. exit(1);
  498. }
  499.  
  500. if (!isPlayerSQL)
  501. {
  502. puts("LOAD_PLAYER_SQL_INFO_FAILURE:");
  503. puts("");
  504. puts("CONFIG:");
  505. puts("------------------------------------------------");
  506. puts("PLAYER_SQL: HOST USER PASSWORD DATABASE");
  507. puts("");
  508. exit(1);
  509. }
  510.  
  511. // Common DB °ˇ Locale Á¤ş¸¸¦ °ˇÁö°í Ŕֱ⠶§ą®żˇ °ˇŔĺ ¸ŐŔú Á˘ĽÓÇŘľß ÇŃ´Ů.
  512. AccountDB::instance().Connect(db_host[1], mysql_db_port[1], db_user[1], db_pwd[1], db_db[1]);
  513.  
  514. if (false == AccountDB::instance().IsConnected())
  515. {
  516. fprintf(stderr, "cannot start server while no common sql connected\n");
  517. exit(1);
  518. }
  519.  
  520. fprintf(stdout, "CommonSQL connected\n");
  521.  
  522. // ·ÎÄÉŔĎ Á¤ş¸¸¦ °ˇÁ®żŔŔÚ
  523. // <°ć°í> Äő¸®ą®żˇ Ŕý´ë Á¶°Çą®(WHERE) ´ŢÁö ¸¶ĽĽżä. (´Ů¸Ą ÁöżŞżˇĽ­ ą®Á¦°ˇ »ý±ćĽö ŔÖ˝Ŕ´Ď´Ů)
  524. {
  525. char szQuery[512];
  526. snprintf(szQuery, sizeof(szQuery), "SELECT mKey, mValue FROM locale");
  527.  
  528. std::auto_ptr<SQLMsg> pMsg(AccountDB::instance().DirectQuery(szQuery));
  529.  
  530. if (pMsg->Get()->uiNumRows == 0)
  531. {
  532. fprintf(stderr, "COMMON_SQL: DirectQuery failed : %s\n", szQuery);
  533. exit(1);
  534. }
  535.  
  536. MYSQL_ROW row;
  537.  
  538. while (NULL != (row = mysql_fetch_row(pMsg->Get()->pSQLResult)))
  539. {
  540. // ·ÎÄÉŔĎ ĽĽĆĂ
  541. if (strcasecmp(row[0], "LOCALE") == 0)
  542. {
  543. if (LocaleService_Init(row[1]) == false)
  544. {
  545. fprintf(stderr, "COMMON_SQL: invalid locale key %s\n", row[1]);
  546. exit(1);
  547. }
  548. }
  549. }
  550. }
  551.  
  552. // ·ÎÄÉŔĎ Á¤ş¸¸¦ COMMON SQLżˇ ĽĽĆĂÇŘÁŘ´Ů.
  553. // Âü°í·Î g_stLocale Á¤ş¸´Â LocaleService_Init() ł»şÎżˇĽ­ ĽĽĆõȴŮ.
  554. fprintf(stdout, "Setting DB to locale %s\n", g_stLocale.c_str());
  555.  
  556. AccountDB::instance().SetLocale(g_stLocale);
  557.  
  558. AccountDB::instance().ConnectAsync(db_host[1], mysql_db_port[1], db_user[1], db_pwd[1], db_db[1], g_stLocale.c_str());
  559.  
  560. // Player DB Á˘ĽÓ
  561. DBManager::instance().Connect(db_host[0], mysql_db_port[0], db_user[0], db_pwd[0], db_db[0]);
  562.  
  563. if (!DBManager::instance().IsConnected())
  564. {
  565. fprintf(stderr, "PlayerSQL.ConnectError\n");
  566. exit(1);
  567. }
  568.  
  569. fprintf(stdout, "PlayerSQL connected\n");
  570.  
  571. if (false == g_bAuthServer) // ŔÎÁő Ľ­ąö°ˇ ľĆ´Ň °ćżě
  572. {
  573. // Log DB Á˘ĽÓ
  574. LogManager::instance().Connect(log_host, log_port, log_user, log_pwd, log_db);
  575.  
  576. if (!LogManager::instance().IsConnected())
  577. {
  578. fprintf(stderr, "LogSQL.ConnectError\n");
  579. exit(1);
  580. }
  581.  
  582. fprintf(stdout, "LogSQL connected\n");
  583.  
  584. LogManager::instance().BootLog(g_stHostname.c_str(), g_bChannel);
  585. }
  586.  
  587. // SKILL_POWER_BY_LEVEL
  588. // ˝şĆ®¸µ şń±łŔÇ ą®Á¦·Î ŔÎÇŘĽ­ AccountDB::instance().SetLocale(g_stLocale) ČÄşÎĹÍ ÇŃ´Ů.
  589. // ą°·Đ ±ął»´Â ş°·Î ą®Á¦°ˇ ľČµČ´Ů(Çؿܰˇ ą®Á¦)
  590. {
  591. char szQuery[256];
  592. snprintf(szQuery, sizeof(szQuery), "SELECT mValue FROM locale WHERE mKey='SKILL_POWER_BY_LEVEL'");
  593. std::auto_ptr<SQLMsg> pMsg(AccountDB::instance().DirectQuery(szQuery));
  594.  
  595. if (pMsg->Get()->uiNumRows == 0)
  596. {
  597. fprintf(stderr, "[SKILL_PERCENT] Query failed: %s", szQuery);
  598. exit(1);
  599. }
  600.  
  601. MYSQL_ROW row;
  602.  
  603. row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  604.  
  605. const char * p = row[0];
  606. int cnt = 0;
  607. char num[128];
  608. int aiBaseSkillPowerByLevelTable[SKILL_MAX_LEVEL+1];
  609.  
  610. fprintf(stdout, "SKILL_POWER_BY_LEVEL %s\n", p);
  611. while (*p != '\0' && cnt < (SKILL_MAX_LEVEL + 1))
  612. {
  613. p = one_argument(p, num, sizeof(num));
  614. aiBaseSkillPowerByLevelTable[cnt++] = atoi(num);
  615.  
  616. //fprintf(stdout, "%d %d\n", cnt - 1, aiBaseSkillPowerByLevelTable[cnt - 1]);
  617. if (*p == '\0')
  618. {
  619. if (cnt != (SKILL_MAX_LEVEL + 1))
  620. {
  621. fprintf(stderr, "[SKILL_PERCENT] locale table has not enough skill information! (count: %d query: %s)", cnt, szQuery);
  622. exit(1);
  623. }
  624.  
  625. fprintf(stdout, "SKILL_POWER_BY_LEVEL: Done! (count %d)\n", cnt);
  626. break;
  627. }
  628. }
  629.  
  630. // ÁľÁ·ş° ˝şĹł ĽĽĆĂ
  631. for (int job = 0; job < JOB_MAX_NUM * 2; ++job)
  632. {
  633. snprintf(szQuery, sizeof(szQuery), "SELECT mValue from locale where mKey='SKILL_POWER_BY_LEVEL_TYPE%d' ORDER BY CAST(mValue AS unsigned)", job);
  634. std::auto_ptr<SQLMsg> pMsg(AccountDB::instance().DirectQuery(szQuery));
  635.  
  636. // ĽĽĆĂŔĚ ľČµÇľîŔÖŔ¸¸é ±âş»Ĺ×ŔĚşíŔ» »çżëÇŃ´Ů.
  637. if (pMsg->Get()->uiNumRows == 0)
  638. {
  639. CTableBySkill::instance().SetSkillPowerByLevelFromType(job, aiBaseSkillPowerByLevelTable);
  640. continue;
  641. }
  642.  
  643. row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  644. cnt = 0;
  645. p = row[0];
  646. int aiSkillTable[SKILL_MAX_LEVEL + 1];
  647.  
  648. fprintf(stdout, "SKILL_POWER_BY_JOB %d %s\n", job, p);
  649. while (*p != '\0' && cnt < (SKILL_MAX_LEVEL + 1))
  650. {
  651. p = one_argument(p, num, sizeof(num));
  652. aiSkillTable[cnt++] = atoi(num);
  653.  
  654. //fprintf(stdout, "%d %d\n", cnt - 1, aiBaseSkillPowerByLevelTable[cnt - 1]);
  655. if (*p == '\0')
  656. {
  657. if (cnt != (SKILL_MAX_LEVEL + 1))
  658. {
  659. fprintf(stderr, "[SKILL_PERCENT] locale table has not enough skill information! (count: %d query: %s)", cnt, szQuery);
  660. exit(1);
  661. }
  662.  
  663. fprintf(stdout, "SKILL_POWER_BY_JOB: Done! (job: %d count: %d)\n", job, cnt);
  664. break;
  665. }
  666. }
  667.  
  668. CTableBySkill::instance().SetSkillPowerByLevelFromType(job, aiSkillTable);
  669. }
  670. }
  671. // END_SKILL_POWER_BY_LEVEL
  672.  
  673. // LOG_KEEP_DAYS_EXTEND
  674. log_set_expiration_days(2);
  675. // END_OF_LOG_KEEP_DAYS_EXTEND
  676. return true;
  677. }
  678.  
  679. static bool __LoadDefaultConfigFile(const char* configName)
  680. {
  681. FILE *fp;
  682.  
  683. char buf[256];
  684. char token_string[256];
  685. char value_string[256];
  686.  
  687. if (!(fp = fopen(configName, "r")))
  688. return false;
  689.  
  690. while (fgets(buf, 256, fp))
  691. {
  692. parse_token(buf, token_string, value_string);
  693.  
  694. TOKEN("port")
  695. {
  696. str_to_number(mother_port, value_string);
  697. continue;
  698. }
  699.  
  700. TOKEN("p2p_port")
  701. {
  702. str_to_number(p2p_port, value_string);
  703. continue;
  704. }
  705.  
  706. TOKEN("map_allow")
  707. {
  708. char * p = value_string;
  709. string stNum;
  710.  
  711. for (; *p; p++)
  712. {
  713. if (isnhspace(*p))
  714. {
  715. if (stNum.length())
  716. {
  717. int index = 0;
  718. str_to_number(index, stNum.c_str());
  719. map_allow_add(index);
  720. stNum.clear();
  721. }
  722. }
  723. else
  724. stNum += *p;
  725. }
  726.  
  727. if (stNum.length())
  728. {
  729. int index = 0;
  730. str_to_number(index, stNum.c_str());
  731. map_allow_add(index);
  732. }
  733.  
  734. continue;
  735. }
  736.  
  737. TOKEN("auth_server")
  738. {
  739. char szIP[32];
  740. char szPort[32];
  741.  
  742. two_arguments(value_string, szIP, sizeof(szIP), szPort, sizeof(szPort));
  743.  
  744. if (!*szIP || (!*szPort && strcasecmp(szIP, "master")))
  745. {
  746. fprintf(stderr, "AUTH_SERVER: syntax error: <ip|master> <port>\n");
  747. exit(1);
  748. }
  749.  
  750. g_bAuthServer = true;
  751.  
  752. LoadBanIP("BANIP");
  753.  
  754. if (!strcasecmp(szIP, "master"))
  755. fprintf(stdout, "AUTH_SERVER: I am the master\n");
  756. else
  757. {
  758. g_stAuthMasterIP = szIP;
  759. str_to_number(g_wAuthMasterPort, szPort);
  760.  
  761. fprintf(stdout, "AUTH_SERVER: master %s %u\n", g_stAuthMasterIP.c_str(), g_wAuthMasterPort);
  762. }
  763. continue;
  764. }
  765.  
  766. TOKEN("teen_addr")
  767. {
  768. strlcpy(teen_addr, value_string, sizeof(teen_addr));
  769.  
  770. for (int n =0; n < ADDRESS_MAX_LEN; ++n)
  771. {
  772. if (teen_addr[n] == ' ')
  773. teen_addr[n] = '\0';
  774. }
  775.  
  776. continue;
  777. }
  778.  
  779. TOKEN("teen_port")
  780. {
  781. str_to_number(teen_port, value_string);
  782. }
  783.  
  784. }
  785.  
  786. fclose(fp);
  787. return true;
  788. }
  789.  
  790. static bool __LoadGeneralConfigFile(const char* configName)
  791. {
  792. FILE *fp;
  793.  
  794. char buf[256];
  795. char token_string[256];
  796. char value_string[256];
  797.  
  798. if (!(fp = fopen(configName, "r")))
  799. return false;
  800.  
  801. while (fgets(buf, 256, fp))
  802. {
  803. parse_token(buf, token_string, value_string);
  804.  
  805. //OPENID
  806. TOKEN("WEB_AUTH")
  807. {
  808. two_arguments(value_string, openid_host, sizeof(openid_host), openid_uri, sizeof(openid_uri));
  809.  
  810. if (!*openid_host || !*openid_uri)
  811. {
  812. fprintf(stderr, "WEB_AUTH syntax error (ex: WEB_AUTH <host(metin2.co.kr) uri(/kyw/gameauth.php)>\n");
  813. exit(1);
  814. }
  815.  
  816. char buf[1024];
  817. openid_server = 1;
  818. snprintf(buf, sizeof(buf), "WEB_AUTH: %s %s", openid_host, openid_uri);
  819. continue;
  820. }
  821.  
  822. // DB_ONLY_BEGIN
  823. TOKEN("BLOCK_LOGIN")
  824. {
  825. g_stBlockDate = value_string;
  826. }
  827.  
  828. TOKEN("adminpage_ip")
  829. {
  830. FN_add_adminpageIP(value_string);
  831. }
  832.  
  833. TOKEN("adminpage_ip1")
  834. {
  835. FN_add_adminpageIP(value_string);
  836. }
  837.  
  838. TOKEN("adminpage_ip2")
  839. {
  840. FN_add_adminpageIP(value_string);
  841. }
  842.  
  843. TOKEN("adminpage_ip3")
  844. {
  845. FN_add_adminpageIP(value_string);
  846. }
  847.  
  848. TOKEN("adminpage_password")
  849. {
  850. g_stAdminPagePassword = value_string;
  851. }
  852. // DB_ONLY_END
  853.  
  854. // CONNECTION_BEGIN
  855. TOKEN("db_port")
  856. {
  857. str_to_number(db_port, value_string);
  858. continue;
  859. }
  860.  
  861. TOKEN("db_addr")
  862. {
  863. strlcpy(db_addr, value_string, sizeof(db_addr));
  864.  
  865. for (int n =0; n < ADDRESS_MAX_LEN; ++n)
  866. {
  867. if (db_addr[n] == ' ')
  868. db_addr[n] = '\0';
  869. }
  870.  
  871. continue;
  872. }
  873. // CONNECTION_END
  874.  
  875. TOKEN("empire_whisper")
  876. {
  877. bool b_value = 0;
  878. str_to_number(b_value, value_string);
  879. g_bEmpireWhisper = !!b_value;
  880. continue;
  881. }
  882.  
  883. TOKEN("mark_server")
  884. {
  885. guild_mark_server = is_string_true(value_string);
  886. continue;
  887. }
  888.  
  889. TOKEN("mark_min_level")
  890. {
  891. str_to_number(guild_mark_min_level, value_string);
  892. guild_mark_min_level = MINMAX(0, guild_mark_min_level, GUILD_MAX_LEVEL);
  893. continue;
  894. }
  895.  
  896. TOKEN("log_keep_days")
  897. {
  898. int i = 0;
  899. str_to_number(i, value_string);
  900. log_set_expiration_days(MINMAX(1, i, 90));
  901. continue;
  902. }
  903.  
  904. TOKEN("passes_per_sec")
  905. {
  906. str_to_number(passes_per_sec, value_string);
  907. continue;
  908. }
  909.  
  910. TOKEN("save_event_second_cycle")
  911. {
  912. int cycle = 0;
  913. str_to_number(cycle, value_string);
  914. save_event_second_cycle = cycle * passes_per_sec;
  915. continue;
  916. }
  917.  
  918. TOKEN("ping_event_second_cycle")
  919. {
  920. int cycle = 0;
  921. str_to_number(cycle, value_string);
  922. ping_event_second_cycle = cycle * passes_per_sec;
  923. continue;
  924. }
  925.  
  926. TOKEN("table_postfix")
  927. {
  928. g_table_postfix = value_string;
  929. continue;
  930. }
  931.  
  932. TOKEN("test_server")
  933. {
  934. printf("-----------------------------------------------\n");
  935. printf("TEST_SERVER\n");
  936. printf("-----------------------------------------------\n");
  937. str_to_number(test_server, value_string);
  938. continue;
  939. }
  940.  
  941. TOKEN("speed_server")
  942. {
  943. printf("-----------------------------------------------\n");
  944. printf("SPEED_SERVER\n");
  945. printf("-----------------------------------------------\n");
  946. str_to_number(speed_server, value_string);
  947. continue;
  948. }
  949.  
  950. #ifdef __AUCTION__
  951. TOKEN("auction_server")
  952. {
  953. printf("-----------------------------------------------\n");
  954. printf("AUCTION_SERVER\n");
  955. printf("-----------------------------------------------\n");
  956. str_to_number(auction_server, value_string);
  957. continue;
  958. }
  959. #endif
  960. TOKEN("distribution_test_server")
  961. {
  962. str_to_number(distribution_test_server, value_string);
  963. continue;
  964. }
  965.  
  966. TOKEN("china_event_server")
  967. {
  968. str_to_number(china_event_server, value_string);
  969. continue;
  970. }
  971. TOKEN("shutdowned")
  972. {
  973. g_bNoMoreClient = true;
  974. continue;
  975. }
  976.  
  977. TOKEN("no_regen")
  978. {
  979. g_bNoRegen = true;
  980. continue;
  981. }
  982.  
  983. #ifdef ENABLE_NEWSTUFF
  984. TOKEN("item_count_limit")
  985. {
  986. str_to_number(g_bItemCountLimit, value_string);
  987. fprintf(stdout, "ITEM_COUNT_LIMIT: %d\n", g_bItemCountLimit);
  988. continue;
  989. }
  990.  
  991. TOKEN("disable_shop_price_3x")
  992. {
  993. g_bEmpireShopPriceTripleDisable = true;
  994. fprintf(stdout, "EMPIRE_SHOP_PRICE_3x: DISABLED\n");
  995. continue;
  996. }
  997.  
  998. TOKEN("shop_price_3x_tax") //alternative
  999. {
  1000. int flag = 0;
  1001. str_to_number(flag, value_string);
  1002. g_bEmpireShopPriceTripleDisable = !flag;
  1003. fprintf(stdout, "SHOP_PRICE_3X_TAX: %s\n", (!g_bEmpireShopPriceTripleDisable)?"ENABLED":"DISABLED");
  1004. continue;
  1005. }
  1006.  
  1007. //unused
  1008. TOKEN("enable_shout_addon")
  1009. {
  1010. g_bShoutAddonEnable = true;
  1011. continue;
  1012. }
  1013.  
  1014. //unused
  1015. TOKEN("enable_all_mount_attack")
  1016. {
  1017. g_bAllMountAttack = true;
  1018. continue;
  1019. }
  1020.  
  1021. TOKEN("disable_change_attr_time")
  1022. {
  1023. g_dwItemBonusChangeTime = 0;
  1024. fprintf(stdout, "CHANGE_ATTR_TIME_LIMIT: DISABLED\n");
  1025. continue;
  1026. }
  1027.  
  1028. TOKEN("change_attr_time_limit") //alternative
  1029. {
  1030. DWORD flag = 0;
  1031. str_to_number(flag, value_string);
  1032. g_dwItemBonusChangeTime = flag;
  1033. fprintf(stdout, "CHANGE_ATTR_TIME_LIMIT: %u\n", g_dwItemBonusChangeTime);
  1034. continue;
  1035. }
  1036.  
  1037. TOKEN("disable_prism_item")
  1038. {
  1039. g_bDisablePrismNeed = true;
  1040. fprintf(stdout, "PRISM_ITEM_REQUIREMENT: DISABLED\n");
  1041. continue;
  1042. }
  1043.  
  1044. TOKEN("prism_item_require") //alternative
  1045. {
  1046. int flag = 0;
  1047. str_to_number(flag, value_string);
  1048. g_bDisablePrismNeed = !flag;
  1049. fprintf(stdout, "PRISM_ITEM_REQUIRE: %s\n", (!g_bDisablePrismNeed)?"ENABLED":"DISABLED");
  1050. continue;
  1051. }
  1052.  
  1053. TOKEN("enable_global_shout")
  1054. {
  1055. g_bGlobalShoutEnable = true;
  1056. fprintf(stdout, "GLOBAL_SHOUT: ENABLED\n");
  1057. continue;
  1058. }
  1059.  
  1060. TOKEN("global_shout") //alternative
  1061. {
  1062. int flag = 0;
  1063. str_to_number(flag, value_string);
  1064. g_bGlobalShoutEnable = !!flag;
  1065. fprintf(stdout, "GLOBAL_SHOUT: %s\n", (g_bGlobalShoutEnable)?"ENABLED":"DISABLED");
  1066. continue;
  1067. }
  1068.  
  1069. TOKEN("disable_emotion_mask")
  1070. {
  1071. g_bDisableEmotionMask = true;
  1072. fprintf(stdout, "EMOTION_MASK_REQUIREMENT: DISABLED\n");
  1073. continue;
  1074. }
  1075.  
  1076. TOKEN("emotion_mask_require") //alternative
  1077. {
  1078. int flag = 0;
  1079. str_to_number(flag, value_string);
  1080. g_bDisableEmotionMask = !flag;
  1081. fprintf(stdout, "EMOTION_MASK_REQUIRE: %s\n", (g_bDisableEmotionMask)?"ENABLED":"DISABLED");
  1082. continue;
  1083. }
  1084.  
  1085. TOKEN("enable_bootary_check")
  1086. {
  1087. g_bEnableBootaryCheck = true;
  1088. fprintf(stdout, "ENABLE_BOOTARY_CHECK: ENABLED\n");
  1089. continue;
  1090. }
  1091.  
  1092. TOKEN("bootary_check") //alternative
  1093. {
  1094. int flag = 0;
  1095. str_to_number(flag, value_string);
  1096. g_bEnableBootaryCheck = !!flag;
  1097. fprintf(stdout, "BOOTARY_CHECK: %s\n", (g_bEnableBootaryCheck)?"ENABLED":"DISABLED");
  1098. continue;
  1099. }
  1100.  
  1101. TOKEN("status_point_get_level_limit")
  1102. {
  1103. int flag = 0;
  1104. str_to_number(flag, value_string);
  1105. if (flag <= 0) continue;
  1106.  
  1107. g_iStatusPointGetLevelLimit = MINMAX(0, flag, PLAYER_MAX_LEVEL_CONST);
  1108. fprintf(stdout, "STATUS_POINT_GET_LEVEL_LIMIT: %d\n", g_iStatusPointGetLevelLimit);
  1109. continue;
  1110. }
  1111.  
  1112. TOKEN("status_point_set_max_value")
  1113. {
  1114. int flag = 0;
  1115. str_to_number(flag, value_string);
  1116. if (flag <= 0) continue;
  1117.  
  1118. g_iStatusPointSetMaxValue = flag;
  1119. fprintf(stdout, "STATUS_POINT_SET_MAX_VALUE: %d\n", g_iStatusPointSetMaxValue);
  1120. continue;
  1121. }
  1122.  
  1123. TOKEN("shout_limit_level")
  1124. {
  1125. int flag = 0;
  1126. str_to_number(flag, value_string);
  1127. if (flag <= 0) continue;
  1128.  
  1129. g_iShoutLimitLevel = flag;
  1130. fprintf(stdout, "SHOUT_LIMIT_LEVEL: %d\n", g_iShoutLimitLevel);
  1131. continue;
  1132. }
  1133.  
  1134. TOKEN("db_log_level")
  1135. {
  1136. int flag = 0;
  1137. str_to_number(flag, value_string);
  1138.  
  1139. g_iDbLogLevel = flag;
  1140. fprintf(stdout, "DB_LOG_LEVEL: %d\n", g_iDbLogLevel);
  1141. continue;
  1142. }
  1143.  
  1144. TOKEN("sys_log_level")
  1145. {
  1146. int flag = 0;
  1147. str_to_number(flag, value_string);
  1148.  
  1149. g_iSysLogLevel = flag;
  1150. fprintf(stdout, "SYS_LOG_LEVEL: %d\n", g_iSysLogLevel);
  1151. continue;
  1152. }
  1153.  
  1154. TOKEN("item_destroy_time_autogive")
  1155. {
  1156. int flag = 0;
  1157. str_to_number(flag, value_string);
  1158.  
  1159. g_aiItemDestroyTime[ITEM_DESTROY_TIME_AUTOGIVE] = flag;
  1160. fprintf(stdout, "ITEM_DESTROY_TIME_AUTOGIVE: %d\n", g_aiItemDestroyTime[ITEM_DESTROY_TIME_AUTOGIVE]);
  1161. continue;
  1162. }
  1163.  
  1164. TOKEN("item_destroy_time_dropgold")
  1165. {
  1166. int flag = 0;
  1167. str_to_number(flag, value_string);
  1168.  
  1169. g_aiItemDestroyTime[ITEM_DESTROY_TIME_DROPGOLD] = flag;
  1170. fprintf(stdout, "ITEM_DESTROY_TIME_DROPGOLD: %d\n", g_aiItemDestroyTime[ITEM_DESTROY_TIME_DROPGOLD]);
  1171. continue;
  1172. }
  1173.  
  1174. TOKEN("item_destroy_time_dropitem")
  1175. {
  1176. int flag = 0;
  1177. str_to_number(flag, value_string);
  1178.  
  1179. g_aiItemDestroyTime[ITEM_DESTROY_TIME_DROPITEM] = flag;
  1180. fprintf(stdout, "ITEM_DESTROY_TIME_DROPITEM: %d\n", g_aiItemDestroyTime[ITEM_DESTROY_TIME_DROPITEM]);
  1181. continue;
  1182. }
  1183.  
  1184. // TOKEN("shout_limit_time")
  1185. // {
  1186. // int flag = 0;
  1187. // str_to_number(flag, value_string);
  1188. // if (flag <= 0) continue;
  1189.  
  1190. // g_iShoutLimitTime = flag;
  1191. // fprintf(stdout, "SHOUT_LIMIT_TIME: %d\n", g_iShoutLimitTime);
  1192. // continue;
  1193. // }
  1194.  
  1195. TOKEN("check_version_server")
  1196. {
  1197. int flag = 0;
  1198.  
  1199. str_to_number(flag, value_string);
  1200. g_bCheckClientVersion = !!flag;
  1201. fprintf(stdout, "CHECK_VERSION_SERVER: %d\n", g_bCheckClientVersion);
  1202. continue;
  1203. }
  1204.  
  1205. TOKEN("check_version_value")
  1206. {
  1207. g_stClientVersion = value_string;
  1208. fprintf(stdout, "CHECK_VERSION_VALUE: %s\n", g_stClientVersion.c_str());
  1209. continue;
  1210. }
  1211.  
  1212. TOKEN("enable_hack_check")
  1213. {
  1214. DWORD flag = 0;
  1215. str_to_number(flag, value_string);
  1216.  
  1217. gHackCheckEnable = !!flag;
  1218. fprintf(stdout, "ENABLE_HACK_CHECK: %d\n", gHackCheckEnable);
  1219. continue;
  1220. }
  1221.  
  1222. TOKEN("gm_host_check")
  1223. {
  1224. DWORD flag = 0;
  1225. str_to_number(flag, value_string);
  1226.  
  1227. g_bGMHostCheck = !!flag;
  1228. fprintf(stdout, "GM_HOST_CHECK: %d\n", g_bGMHostCheck);
  1229. continue;
  1230. }
  1231.  
  1232. TOKEN("guild_invite_limit")
  1233. {
  1234. DWORD flag = 0;
  1235. str_to_number(flag, value_string);
  1236.  
  1237. g_bGuildInviteLimit = !!flag;
  1238. fprintf(stdout, "GUILD_INVITE_LIMIT: %d\n", g_bGuildInviteLimit);
  1239. continue;
  1240. }
  1241.  
  1242. TOKEN("guild_infinite_members")
  1243. {
  1244. DWORD flag = 0;
  1245. str_to_number(flag, value_string);
  1246.  
  1247. g_bGuildInfiniteMembers = !!flag;
  1248. fprintf(stdout, "GUILD_INFINITE_MEMBERS: %d\n", g_bGuildInfiniteMembers);
  1249. continue;
  1250. }
  1251.  
  1252. TOKEN("empire_language_check")
  1253. {
  1254. int flag = 0;
  1255. str_to_number(flag, value_string);
  1256. g_bDisableEmpireLanguageCheck = !flag;
  1257. fprintf(stdout, "EMPIRE_LANGUAGE_CHECK: %s\n", (g_bDisableEmpireLanguageCheck)?"DISABLED":"ENABLED");
  1258. continue;
  1259. }
  1260.  
  1261. TOKEN("skillbook_nextread_min")
  1262. {
  1263. DWORD flag = 0;
  1264. str_to_number(flag, value_string);
  1265. g_dwSkillBookNextReadMin = flag;
  1266. fprintf(stdout, "SKILLBOOK_NEXTREAD_MIN: %u\n", g_dwSkillBookNextReadMin);
  1267. continue;
  1268. }
  1269.  
  1270. TOKEN("skillbook_nextread_max")
  1271. {
  1272. DWORD flag = 0;
  1273. str_to_number(flag, value_string);
  1274. g_dwSkillBookNextReadMax = flag;
  1275. fprintf(stdout, "SKILLBOOK_NEXTREAD_MAX: %u\n", g_dwSkillBookNextReadMax);
  1276. continue;
  1277. }
  1278. #endif
  1279.  
  1280. TOKEN("traffic_profile")
  1281. {
  1282. g_bTrafficProfileOn = true;
  1283. continue;
  1284. }
  1285.  
  1286. TOKEN("no_wander")
  1287. {
  1288. no_wander = true;
  1289. continue;
  1290. }
  1291.  
  1292. TOKEN("user_limit")
  1293. {
  1294. str_to_number(g_iUserLimit, value_string);
  1295. continue;
  1296. }
  1297.  
  1298. TOKEN("skill_disable")
  1299. {
  1300. str_to_number(g_bSkillDisable, value_string);
  1301. continue;
  1302. }
  1303.  
  1304. TOKEN("billing")
  1305. {
  1306. g_bBilling = true;
  1307. }
  1308.  
  1309. TOKEN("quest_dir")
  1310. {
  1311. sys_log(0, "QUEST_DIR SETTING : %s", value_string);
  1312. g_stQuestDir = value_string;
  1313. }
  1314.  
  1315. TOKEN("quest_object_dir")
  1316. {
  1317. //g_stQuestObjectDir = value_string;
  1318. std::istringstream is(value_string);
  1319. sys_log(0, "QUEST_OBJECT_DIR SETTING : %s", value_string);
  1320. string dir;
  1321. while (!is.eof())
  1322. {
  1323. is >> dir;
  1324. if (is.fail())
  1325. break;
  1326. g_setQuestObjectDir.insert(dir);
  1327. sys_log(0, "QUEST_OBJECT_DIR INSERT : %s", dir .c_str());
  1328. }
  1329. }
  1330.  
  1331. TOKEN("synchack_limit_count")
  1332. {
  1333. str_to_number(g_iSyncHackLimitCount, value_string);
  1334. }
  1335.  
  1336. TOKEN("speedhack_limit_count")
  1337. {
  1338. str_to_number(SPEEDHACK_LIMIT_COUNT, value_string);
  1339. }
  1340.  
  1341. TOKEN("speedhack_limit_bonus")
  1342. {
  1343. str_to_number(SPEEDHACK_LIMIT_BONUS, value_string);
  1344. }
  1345.  
  1346. TOKEN("server_id")
  1347. {
  1348. str_to_number(g_server_id, value_string);
  1349. }
  1350.  
  1351. TOKEN("mall_url")
  1352. {
  1353. g_strWebMallURL = value_string;
  1354. }
  1355.  
  1356. TOKEN("bind_ip")
  1357. {
  1358. strlcpy(g_szPublicIP, value_string, sizeof(g_szPublicIP));
  1359. }
  1360.  
  1361. TOKEN("view_range")
  1362. {
  1363. str_to_number(VIEW_RANGE, value_string);
  1364. }
  1365.  
  1366. TOKEN("spam_block_duration")
  1367. {
  1368. str_to_number(g_uiSpamBlockDuration, value_string);
  1369. }
  1370.  
  1371. TOKEN("spam_block_score")
  1372. {
  1373. str_to_number(g_uiSpamBlockScore, value_string);
  1374. g_uiSpamBlockScore = MAX(1, g_uiSpamBlockScore);
  1375. }
  1376.  
  1377. TOKEN("spam_block_reload_cycle")
  1378. {
  1379. str_to_number(g_uiSpamReloadCycle, value_string);
  1380. g_uiSpamReloadCycle = MAX(60, g_uiSpamReloadCycle); // ĂÖĽŇ 1şĐ
  1381. }
  1382.  
  1383. TOKEN("check_multihack")
  1384. {
  1385. str_to_number(g_bCheckMultiHack, value_string);
  1386. }
  1387.  
  1388. TOKEN("spam_block_max_level")
  1389. {
  1390. str_to_number(g_iSpamBlockMaxLevel, value_string);
  1391. }
  1392. TOKEN("protect_normal_player")
  1393. {
  1394. str_to_number(g_protectNormalPlayer, value_string);
  1395. }
  1396. TOKEN("notice_battle_zone")
  1397. {
  1398. str_to_number(g_noticeBattleZone, value_string);
  1399. }
  1400.  
  1401. TOKEN("hackshield_enable")
  1402. {
  1403. int flag = 0;
  1404.  
  1405. str_to_number(flag, value_string);
  1406.  
  1407. if (1 == flag)
  1408. {
  1409. isHackShieldEnable = true;
  1410. }
  1411. }
  1412.  
  1413. TOKEN("hackshield_first_check_time")
  1414. {
  1415. int secs = 30;
  1416. str_to_number(secs, value_string);
  1417.  
  1418. HackShield_FirstCheckWaitTime = passes_per_sec * secs;
  1419. }
  1420.  
  1421. TOKEN("hackshield_check_cycle_time")
  1422. {
  1423. int secs = 180;
  1424. str_to_number(secs, value_string);
  1425.  
  1426. HackShield_CheckCycleTime = passes_per_sec * secs;
  1427. }
  1428.  
  1429. TOKEN("xtrap_enable")
  1430. {
  1431. int flag = 0;
  1432. str_to_number(flag, value_string);
  1433.  
  1434. if (1 == flag )
  1435. {
  1436. bXTrapEnabled = true;
  1437. }
  1438. }
  1439.  
  1440. TOKEN("pk_protect_level")
  1441. {
  1442. str_to_number(PK_PROTECT_LEVEL, value_string);
  1443. fprintf(stderr, "PK_PROTECT_LEVEL: %d", PK_PROTECT_LEVEL);
  1444. }
  1445.  
  1446. TOKEN("max_level")
  1447. {
  1448. str_to_number(gPlayerMaxLevel, value_string);
  1449.  
  1450. gPlayerMaxLevel = MINMAX(1, gPlayerMaxLevel, PLAYER_MAX_LEVEL_CONST);
  1451.  
  1452. fprintf(stderr, "PLAYER_MAX_LEVEL: %d\n", gPlayerMaxLevel);
  1453. }
  1454.  
  1455. TOKEN("shutdown_age")
  1456. {
  1457. str_to_number(gShutdownAge, value_string);
  1458. fprintf(stderr, "SHUTDOWN_AGE: %d\n", gShutdownAge);
  1459.  
  1460. }
  1461.  
  1462. TOKEN("shutdown_enable")
  1463. {
  1464. str_to_number(gShutdownEnable, value_string);
  1465. fprintf(stderr, "SHUTDOWN_ENABLE: %d\n", gShutdownEnable);
  1466. }
  1467.  
  1468. TOKEN("block_char_creation")
  1469. {
  1470. int tmp = 0;
  1471.  
  1472. str_to_number(tmp, value_string);
  1473.  
  1474. if (0 == tmp)
  1475. g_BlockCharCreation = false;
  1476. else
  1477. g_BlockCharCreation = true;
  1478.  
  1479. continue;
  1480. }
  1481.  
  1482. TOKEN("server_key")
  1483. {
  1484. CCheckServer::Instance().AddServerKey(value_string);
  1485. continue;
  1486. }
  1487.  
  1488. }
  1489. fclose(fp);
  1490. return true;
  1491. }
  1492.  
  1493. #define ENABLE_CMD_PLAYER
  1494. static bool __LoadDefaultCMDFile(const char* cmdName)
  1495. {
  1496. FILE *fp;
  1497. char buf[256];
  1498.  
  1499. if ((fp = fopen(cmdName, "r")))
  1500. {
  1501. while (fgets(buf, 256, fp))
  1502. {
  1503. char cmd[32], levelname[32];
  1504. int level;
  1505.  
  1506. two_arguments(buf, cmd, sizeof(cmd), levelname, sizeof(levelname));
  1507.  
  1508. if (!*cmd || !*levelname)
  1509. {
  1510. #ifdef ENABLE_CMD_PLAYER
  1511. fprintf(stderr, "CMD syntax error: <cmd> <PLAYER | LOW_WIZARD | WIZARD | HIGH_WIZARD | GOD | IMPLEMENTOR | DISABLE>\n");
  1512. #else
  1513. fprintf(stderr, "CMD syntax error: <cmd> <LOW_WIZARD | WIZARD | HIGH_WIZARD | GOD | IMPLEMENTOR | DISABLE>\n");
  1514. #endif
  1515. exit(1);
  1516. }
  1517.  
  1518. if (!strcasecmp(levelname, "LOW_WIZARD"))
  1519. level = GM_LOW_WIZARD;
  1520. else if (!strcasecmp(levelname, "WIZARD"))
  1521. level = GM_WIZARD;
  1522. else if (!strcasecmp(levelname, "HIGH_WIZARD"))
  1523. level = GM_HIGH_WIZARD;
  1524. else if (!strcasecmp(levelname, "GOD"))
  1525. level = GM_GOD;
  1526. else if (!strcasecmp(levelname, "IMPLEMENTOR"))
  1527. level = GM_IMPLEMENTOR;
  1528. #ifdef ENABLE_CMD_PLAYER
  1529. else if (!strcasecmp(levelname, "PLAYER"))
  1530. level = GM_PLAYER;
  1531. #endif
  1532. else if (!strcasecmp(levelname, "DISABLE"))
  1533. level = GM_DISABLE;
  1534. else
  1535. {
  1536. #ifdef ENABLE_CMD_PLAYER
  1537. fprintf(stderr, "CMD syntax error: <cmd> <PLAYER | LOW_WIZARD | WIZARD | HIGH_WIZARD | GOD | IMPLEMENTOR | DISABLE>\n");
  1538. #else
  1539. fprintf(stderr, "CMD syntax error: <cmd> <LOW_WIZARD | WIZARD | HIGH_WIZARD | GOD | IMPLEMENTOR | DISABLE>\n");
  1540. #endif
  1541. exit(1);
  1542. }
  1543.  
  1544. if (test_server)
  1545. fprintf(stdout, "CMD_REWRITE: [%s] [%s:%d]\n", cmd, levelname, level);
  1546. interpreter_set_privilege(cmd, level);
  1547. }
  1548.  
  1549. fclose(fp);
  1550. return true;
  1551. }
  1552. return false;
  1553. }
  1554.  
  1555. #define ENABLE_EXPTABLE_FROMDB
  1556. #ifdef ENABLE_EXPTABLE_FROMDB
  1557. static bool __LoadExpTableFromDB(void)
  1558. {
  1559. std::auto_ptr<SQLMsg> pMsg(AccountDB::instance().DirectQuery("SELECT level, exp FROM exp_table"));
  1560. if (pMsg->Get()->uiNumRows == 0)
  1561. return false;
  1562.  
  1563. static DWORD new_exp_table[PLAYER_MAX_LEVEL_CONST+1];
  1564. if (exp_table != NULL)
  1565. memcpy(new_exp_table, exp_table, (PLAYER_MAX_LEVEL_CONST+1)*sizeof(DWORD));
  1566.  
  1567. MYSQL_ROW row = NULL;
  1568. while ((row = mysql_fetch_row(pMsg->Get()->pSQLResult)))
  1569. {
  1570. DWORD level = 0;
  1571. DWORD exp = 0;
  1572. str_to_number(level, row[0]);
  1573. str_to_number(exp, row[1]);
  1574. if (level > PLAYER_MAX_LEVEL_CONST)
  1575. continue;
  1576. new_exp_table[level] = exp;
  1577. // printf("new_exp_table[%u] = %u;\n", level, exp);
  1578. }
  1579. exp_table = new_exp_table;
  1580. return true;
  1581. }
  1582. #endif
  1583.  
  1584. // #define ENABLE_GENERAL_CMD
  1585. // #define ENABLE_GENERAL_CONFIG
  1586. void config_init(const string& st_localeServiceName)
  1587. {
  1588. // LOCALE_SERVICE
  1589. string st_configFileName;
  1590.  
  1591. st_configFileName.reserve(32);
  1592. st_configFileName = "CONFIG";
  1593.  
  1594. if (!st_localeServiceName.empty())
  1595. {
  1596. st_configFileName += ".";
  1597. st_configFileName += st_localeServiceName;
  1598. }
  1599. // END_OF_LOCALE_SERVICE
  1600.  
  1601. // public ip°ˇ ľřľîµµ BIND_IPÇĎ¸é °ÔŔÓ µąľĆ°ˇ´ÂµĄżˇ´Â ľĆą«·± ÁöŔĺŔĚ ľř±â ¶§ą®żˇ
  1602. // ÁÖĽ®Ăł¸® ÇÔ.
  1603. if (!GetIPInfo())
  1604. {
  1605. // fprintf(stderr, "Can not get public ip address\n");
  1606. // exit(1);
  1607. }
  1608.  
  1609. // default config load (REQUIRED)
  1610. if (!__LoadConnectConfigFile(st_configFileName.c_str()) ||
  1611. !__LoadDefaultConfigFile(st_configFileName.c_str()) ||
  1612. !__LoadGeneralConfigFile(st_configFileName.c_str())
  1613. )
  1614. {
  1615. fprintf(stderr, "Can not open [%s]\n", st_configFileName.c_str());
  1616. exit(1);
  1617. }
  1618. #ifdef ENABLE_GENERAL_CONFIG
  1619. // general config - locale based
  1620. {
  1621. char szFileName[256];
  1622. snprintf(szFileName, sizeof(szFileName), "%s/conf/GENERAL_%s", LocaleService_GetBasePath().c_str(), st_configFileName.c_str());
  1623. if (__LoadGeneralConfigFile(szFileName))
  1624. fprintf(stderr, "GENERAL CONFIG LOAD OK [%s]\n", szFileName);
  1625. }
  1626. // general config - locale n channel based
  1627. {
  1628. char szFileName[256];
  1629. snprintf(szFileName, sizeof(szFileName), "%s/conf/GENERAL_%s_CHANNEL_%d", LocaleService_GetBasePath().c_str(), st_configFileName.c_str(), g_bChannel);
  1630. if (__LoadGeneralConfigFile(szFileName))
  1631. fprintf(stderr, "GENERAL CONFIG LOAD OK [%s]\n", szFileName);
  1632. }
  1633. // general config - locale n channel n hostname based
  1634. {
  1635. char szFileName[256];
  1636. snprintf(szFileName, sizeof(szFileName), "%s/conf/GENERAL_%s_CHANNEL_%d_HOSTNAME_%s", LocaleService_GetBasePath().c_str(), st_configFileName.c_str(), g_bChannel, g_stHostname.c_str());
  1637. if (__LoadGeneralConfigFile(szFileName))
  1638. fprintf(stderr, "GENERAL CONFIG LOAD OK [%s]\n", szFileName);
  1639. }
  1640. #endif
  1641.  
  1642. if (g_setQuestObjectDir.empty())
  1643. g_setQuestObjectDir.insert(g_stDefaultQuestObjectDir);
  1644.  
  1645. if (0 == db_port)
  1646. {
  1647. fprintf(stderr, "DB_PORT not configured\n");
  1648. exit(1);
  1649. }
  1650.  
  1651. if (0 == g_bChannel)
  1652. {
  1653. fprintf(stderr, "CHANNEL not configured\n");
  1654. exit(1);
  1655. }
  1656.  
  1657. if (g_stHostname.empty())
  1658. {
  1659. fprintf(stderr, "HOSTNAME must be configured.\n");
  1660. exit(1);
  1661. }
  1662.  
  1663. // LOCALE_SERVICE
  1664. LocaleService_LoadLocaleStringFile();
  1665. LocaleService_TransferDefaultSetting();
  1666. LocaleService_LoadEmpireTextConvertTables();
  1667. // END_OF_LOCALE_SERVICE
  1668.  
  1669. #ifdef ENABLE_EXPTABLE_FROMDB
  1670. if (!__LoadExpTableFromDB())
  1671. {
  1672. // do as you please to manage this
  1673. fprintf(stderr, "Failed to Load ExpTable from DB so exit\n");
  1674. // exit(1);
  1675. }
  1676. #endif
  1677.  
  1678. std::string st_cmdFileName("CMD");
  1679. __LoadDefaultCMDFile(st_cmdFileName.c_str());
  1680. #ifdef ENABLE_GENERAL_CMD
  1681. // general cmd - locale based
  1682. {
  1683. char szFileName[256];
  1684. snprintf(szFileName, sizeof(szFileName), "%s/conf/GENERAL_%s", LocaleService_GetBasePath().c_str(), st_cmdFileName.c_str());
  1685. if (__LoadDefaultCMDFile(szFileName))
  1686. fprintf(stdout, "GENERAL CMD LOAD OK [%s]\n", szFileName);
  1687. }
  1688. // general cmd - locale n channel based
  1689. {
  1690. char szFileName[256];
  1691. snprintf(szFileName, sizeof(szFileName), "%s/conf/GENERAL_%s_CHANNEL_%d", LocaleService_GetBasePath().c_str(), st_cmdFileName.c_str(), g_bChannel);
  1692. if (__LoadDefaultCMDFile(szFileName))
  1693. fprintf(stdout, "GENERAL CMD LOAD OK [%s]\n", szFileName);
  1694. }
  1695. // general cmd - locale n channel n hostname based
  1696. {
  1697. char szFileName[256];
  1698. snprintf(szFileName, sizeof(szFileName), "%s/conf/GENERAL_%s_CHANNEL_%d_HOSTNAME_%s", LocaleService_GetBasePath().c_str(), st_cmdFileName.c_str(), g_bChannel, g_stHostname.c_str());
  1699. if (__LoadDefaultCMDFile(szFileName))
  1700. fprintf(stdout, "GENERAL CMD LOAD OK [%s]\n", szFileName);
  1701. }
  1702. #endif
  1703.  
  1704. if(!gHackCheckEnable) // Hack ĂĽĹ©°ˇ şńČ°ĽşČ­ŔÎ °ćżě
  1705. {
  1706. assert(test_server); // Ĺ×˝şĆ® Ľ­ąö°ˇ ľĆ´Ď¶ó¸é assert
  1707. }
  1708.  
  1709. LoadValidCRCList();
  1710. LoadStateUserCount();
  1711.  
  1712. CWarMapManager::instance().LoadWarMapInfo(NULL);
  1713.  
  1714. FN_log_adminpage();
  1715. if (g_szPublicIP[0] == '0')
  1716. {
  1717. fprintf(stderr, "Can not get public ip address\n");
  1718. exit(1);
  1719. }
  1720. }
  1721.  
  1722. const char* get_table_postfix()
  1723. {
  1724. return g_table_postfix.c_str();
  1725. }
  1726.  
  1727. void LoadValidCRCList()
  1728. {
  1729. s_set_dwProcessCRC.clear();
  1730. s_set_dwFileCRC.clear();
  1731.  
  1732. FILE * fp;
  1733. char buf[256];
  1734.  
  1735. if ((fp = fopen("CRC", "r")))
  1736. {
  1737. while (fgets(buf, 256, fp))
  1738. {
  1739. if (!*buf)
  1740. continue;
  1741.  
  1742. DWORD dwValidClientProcessCRC;
  1743. DWORD dwValidClientFileCRC;
  1744.  
  1745. sscanf(buf, " %u %u ", &dwValidClientProcessCRC, &dwValidClientFileCRC);
  1746.  
  1747. s_set_dwProcessCRC.insert(dwValidClientProcessCRC);
  1748. s_set_dwFileCRC.insert(dwValidClientFileCRC);
  1749.  
  1750. fprintf(stderr, "CLIENT_CRC: %u %u\n", dwValidClientProcessCRC, dwValidClientFileCRC);
  1751. }
  1752.  
  1753. fclose(fp);
  1754. }
  1755. }
  1756.  
  1757. bool LoadClientVersion()
  1758. {
  1759. FILE * fp = fopen("VERSION", "r");
  1760.  
  1761. if (!fp)
  1762. return false;
  1763.  
  1764. char buf[256];
  1765. fgets(buf, 256, fp);
  1766.  
  1767. char * p = strchr(buf, '\n');
  1768. if (p) *p = '\0';
  1769.  
  1770. fprintf(stderr, "VERSION: \"%s\"\n", buf);
  1771.  
  1772. g_stClientVersion = buf;
  1773. fclose(fp);
  1774. return true;
  1775. }
  1776.  
  1777. void CheckClientVersion()
  1778. {
  1779. const DESC_MANAGER::DESC_SET & set = DESC_MANAGER::instance().GetClientSet();
  1780. DESC_MANAGER::DESC_SET::const_iterator it = set.begin();
  1781.  
  1782. while (it != set.end())
  1783. {
  1784. LPDESC d = *(it++);
  1785.  
  1786. if (!d->GetCharacter())
  1787. continue;
  1788.  
  1789. if (0 != g_stClientVersion.compare(d->GetClientVersion())) // @fixme103 (version > date)
  1790. {
  1791. d->GetCharacter()->ChatPacket(CHAT_TYPE_NOTICE, LC_TEXT("Ŭ¶óŔĚľđĆ® ąöŔüŔĚ Ć˛·Á ·Î±×ľĆżô µË´Ď´Ů. Á¤»óŔűŔ¸·Î ĆĐġ ČÄ Á˘ĽÓÇĎĽĽżä."));
  1792. d->DelayedDisconnect(10);
  1793. }
  1794. }
  1795. }
  1796.  
  1797. void LoadStateUserCount()
  1798. {
  1799. FILE * fp = fopen("state_user_count", "r");
  1800.  
  1801. if (!fp)
  1802. return;
  1803.  
  1804. fscanf(fp, " %d %d ", &g_iFullUserCount, &g_iBusyUserCount);
  1805.  
  1806. fclose(fp);
  1807. }
  1808.  
  1809. bool IsValidProcessCRC(DWORD dwCRC)
  1810. {
  1811. return s_set_dwProcessCRC.find(dwCRC) != s_set_dwProcessCRC.end();
  1812. }
  1813.  
  1814. bool IsValidFileCRC(DWORD dwCRC)
  1815. {
  1816. return s_set_dwFileCRC.find(dwCRC) != s_set_dwFileCRC.end();
  1817. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement