Advertisement
Guest User

Untitled

a guest
Mar 28th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 26.70 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.  
  23. using std::string;
  24.  
  25. BYTE    g_bChannel = 0;
  26. WORD    mother_port = 50080;
  27. int     passes_per_sec = 25;
  28. WORD    db_port = 0;
  29. WORD    p2p_port = 50900;
  30. char    db_addr[ADDRESS_MAX_LEN + 1];
  31. int     save_event_second_cycle = passes_per_sec * 120;
  32. int     ping_event_second_cycle = passes_per_sec * 60;
  33. bool    g_bNoMoreClient = false;
  34. bool    g_bNoRegen = false;
  35. bool    g_bNoPasspod = false;
  36.  
  37. bool        g_bTrafficProfileOn = false;
  38. DWORD       g_dwTrafficProfileFlushCycle = 3600;
  39.  
  40. int         test_server = 0;
  41. int         speed_server = 0;
  42. #ifdef __AUCTION__
  43. int         auction_server = 0;
  44. #endif
  45. bool        distribution_test_server = false;
  46. bool        china_event_server = false;
  47. bool        guild_mark_server = true;
  48. BYTE        guild_mark_min_level = 3;
  49. bool        no_wander = false;
  50. int     g_iUserLimit = 32768;
  51.  
  52. char        g_szPublicIP[16] = "0";
  53. char        g_szInternalIP[16] = "0";
  54. bool        g_bSkillDisable = false;
  55. int         g_iFullUserCount = 1500;
  56. int         g_iBusyUserCount = 650;
  57.  
  58. bool        g_bEmpireWhisper = true;
  59. BYTE        g_bAuthServer = false;
  60.  
  61. bool        g_bCheckClientVersion = true;
  62. string  g_stClientVersion = "1215955205";
  63.  
  64. BYTE        g_bBilling = false;
  65.  
  66. string  g_stAuthMasterIP;
  67. WORD        g_wAuthMasterPort = 0;
  68.  
  69. static std::set<DWORD> s_set_dwFileCRC;
  70. static std::set<DWORD> s_set_dwProcessCRC;
  71.  
  72. string g_stHostname = "";
  73. string g_table_postfix = "";
  74.  
  75. string g_stQuestDir = "./quest";
  76. string g_stDefaultQuestObjectDir = "./quest/object";
  77. std::set<string> g_setQuestObjectDir;
  78.  
  79. std::vector<std::string>    g_stAdminPageIP;
  80. std::string g_stAdminPagePassword = "SHOWMETHEMONEY";
  81.  
  82. string g_stBlockDate = "30000705";
  83.  
  84. extern string g_stLocale;
  85.  
  86. char    teen_addr[ADDRESS_MAX_LEN + 1] = {0};
  87. WORD    teen_port   = 0;
  88.  
  89. int SPEEDHACK_LIMIT_COUNT   = 50;
  90. int SPEEDHACK_LIMIT_BONUS   = 80;
  91. int g_iSyncHackLimitCount = 10;
  92.  
  93. int VIEW_RANGE = 5000;
  94. int VIEW_BONUS_RANGE = 500;
  95.  
  96. int g_server_id = 0;
  97. string g_strWebMallURL = "www.metin2.de";
  98.  
  99. unsigned int g_uiSpamBlockDuration = 60 * 15;
  100. unsigned int g_uiSpamBlockScore = 100;
  101. unsigned int g_uiSpamReloadCycle = 60 * 10;
  102.  
  103. bool        g_bCheckMultiHack = true;
  104.  
  105. int         g_iSpamBlockMaxLevel = 10;
  106.  
  107. void        LoadStateUserCount();
  108. void        LoadValidCRCList();
  109. bool        LoadClientVersion();
  110. bool            g_protectNormalPlayer   = false;
  111. bool            g_noticeBattleZone      = false;
  112.  
  113. bool        isHackShieldEnable = false;
  114. int         HackShield_FirstCheckWaitTime = passes_per_sec * 30;
  115. int         HackShield_CheckCycleTime = passes_per_sec * 180;
  116.  
  117. bool        bXTrapEnabled = false;
  118.  
  119. int gPlayerMaxLevel = 99;
  120. int MaxLoncaSkor = 100;
  121. int LoncaAcilisKacKisiAlsin = 32;
  122. int LoncaLevelAtlarsaKacKisiAlmaArtsin = 2;
  123. int YesilMorpot = 0;
  124. int KirmiziMavipot = 0;
  125. int NesneMarket = 0;
  126. bool g_BlockCharCreation = false;
  127.  
  128. int     openid_server = 0;
  129. char    openid_host[256];
  130. char    openid_uri[256];
  131.  
  132. bool is_string_true(const char * string)
  133. {
  134.     bool    result = 0;
  135.     if (isnhdigit(*string))
  136.     {
  137.         str_to_number(result, string);
  138.         return result > 0 ? true : false;
  139.     }
  140.     else if (LOWER(*string) == 't')
  141.         return true;
  142.     else
  143.         return false;
  144. }
  145.  
  146. static std::set<int> s_set_map_allows;
  147.  
  148. bool map_allow_find(int index)
  149. {
  150.     if (g_bAuthServer)
  151.         return false;
  152.  
  153.     if (s_set_map_allows.find(index) == s_set_map_allows.end())
  154.         return false;
  155.  
  156.     return true;
  157. }
  158.  
  159. void map_allow_log()
  160. {
  161.     std::set<int>::iterator i;
  162.  
  163.     for (i = s_set_map_allows.begin(); i != s_set_map_allows.end(); ++i)
  164.         sys_log(0, "MAP_ALLOW: %d", *i);
  165. }
  166.  
  167. void map_allow_add(int index)
  168. {
  169.     if (map_allow_find(index) == true)
  170.     {
  171.         fprintf(stdout, "!!! FATAL ERROR !!! multiple MAP_ALLOW setting!!\n");
  172.         exit(1);
  173.     }
  174.  
  175.     s_set_map_allows.insert(index);
  176. }
  177.  
  178. void map_allow_copy(long * pl, int size)
  179. {
  180.     int iCount = 0;
  181.     std::set<int>::iterator it = s_set_map_allows.begin();
  182.  
  183.     while (it != s_set_map_allows.end())
  184.     {
  185.         int i = *(it++);
  186.         *(pl++) = i;
  187.  
  188.         if (++iCount > size)
  189.             break;
  190.     }
  191. }
  192.  
  193. static void FN_add_adminpageIP(char *line)
  194. {
  195.     char    *last;
  196.     const char *delim = " \t\r\n";
  197.     char *v = strtok_r(line, delim, &last);
  198.  
  199.     while (v)
  200.     {
  201.         g_stAdminPageIP.push_back(v);
  202.         v = strtok_r(NULL, delim, &last);
  203.     }
  204. }
  205.  
  206. static void FN_log_adminpage()
  207. {
  208.     itertype(g_stAdminPageIP) iter = g_stAdminPageIP.begin();
  209.  
  210.     while (iter != g_stAdminPageIP.end())
  211.     {
  212.         dev_log(LOG_DEB0, "ADMIN_PAGE_IP = %s", (*iter).c_str());
  213.         ++iter;
  214.     }
  215.  
  216.     dev_log(LOG_DEB0, "ADMIN_PAGE_PASSWORD = %s", g_stAdminPagePassword.c_str());
  217. }
  218.  
  219.  
  220. bool GetIPInfo()
  221. {
  222.     struct ifaddrs* ifaddrp = NULL;
  223.     if (0 != getifaddrs(&ifaddrp)) return false;
  224.     for( struct ifaddrs* ifap=ifaddrp ; NULL != ifap ; ifap = ifap->ifa_next )
  225.     {
  226.         struct sockaddr_in * sai = (struct sockaddr_in *) ifap->ifa_addr;
  227.         if (!ifap->ifa_netmask || sai->sin_addr.s_addr == 0 || sai->sin_addr.s_addr == 16777343) continue;
  228.         char * netip = inet_ntoa(sai->sin_addr);
  229.         if (g_szPublicIP[0] != '0')
  230.         {
  231.             strlcpy(g_szInternalIP, netip, sizeof(g_szInternalIP));
  232.             fprintf(stderr, "INTERNAL_IP: %s interface %s\n", netip, ifap->ifa_name);
  233.         } else if (g_szPublicIP[0] == '0') {
  234.             strlcpy(g_szPublicIP, netip, sizeof(g_szPublicIP));
  235.             fprintf(stderr, "PUBLIC_IP: %s interface %s\n", netip, ifap->ifa_name);
  236.         }
  237.     }
  238. }
  239.  
  240. void config_init(const string& st_localeServiceName)
  241. {
  242.     FILE    *fp;
  243.  
  244.     char    buf[256];
  245.     char    token_string[256];
  246.     char    value_string[256];
  247.  
  248.     string  st_configFileName;
  249.  
  250.     st_configFileName.reserve(32);
  251.     st_configFileName = "CONFIG";
  252.  
  253.     if (!st_localeServiceName.empty())
  254.     {
  255.         st_configFileName += ".";
  256.         st_configFileName += st_localeServiceName;
  257.     }
  258.    
  259.     if (!(fp = fopen(st_configFileName.c_str(), "r")))
  260.     {
  261.         fprintf(stderr, "Can not open [%s]\n", st_configFileName.c_str());
  262.         exit(1);
  263.     }
  264.  
  265.     if (!GetIPInfo())
  266.     {
  267.         fprintf(stderr, "Can not get public ip address\n");
  268.         exit(1);
  269.     }
  270.  
  271.     char db_host[2][64], db_user[2][64], db_pwd[2][64], db_db[2][64];
  272.     int mysql_db_port[2];
  273.  
  274.     for (int n = 0; n < 2; ++n)
  275.     {
  276.         *db_host[n] = '\0';
  277.         *db_user[n] = '\0';
  278.         *db_pwd[n]= '\0';
  279.         *db_db[n]= '\0';
  280.         mysql_db_port[n] = 0;
  281.     }
  282.  
  283.     char log_host[64], log_user[64], log_pwd[64], log_db[64];
  284.     int log_port = 0;
  285.  
  286.     *log_host = '\0';
  287.     *log_user = '\0';
  288.     *log_pwd = '\0';
  289.     *log_db = '\0';
  290.  
  291.     bool isCommonSQL = false;  
  292.     bool isPlayerSQL = false;
  293.  
  294.     FILE* fpOnlyForDB;
  295.  
  296.     if (!(fpOnlyForDB = fopen(st_configFileName.c_str(), "r")))
  297.     {
  298.         fprintf(stderr, "Can not open [%s]\n", st_configFileName.c_str());
  299.         exit(1);
  300.     }
  301.  
  302.     while (fgets(buf, 256, fpOnlyForDB))
  303.     {
  304.         parse_token(buf, token_string, value_string);
  305.  
  306.         TOKEN("BLOCK_LOGIN")
  307.         {
  308.             g_stBlockDate = value_string;
  309.         }
  310.  
  311.         TOKEN("adminpage_ip")
  312.         {
  313.             FN_add_adminpageIP(value_string);
  314.             //g_stAdminPageIP[0] = value_string;
  315.         }
  316.  
  317.         TOKEN("adminpage_ip1")
  318.         {
  319.             FN_add_adminpageIP(value_string);
  320.             //g_stAdminPageIP[0] = value_string;
  321.         }
  322.  
  323.         TOKEN("adminpage_ip2")
  324.         {
  325.             FN_add_adminpageIP(value_string);
  326.             //g_stAdminPageIP[1] = value_string;
  327.         }
  328.  
  329.         TOKEN("adminpage_ip3")
  330.         {
  331.             FN_add_adminpageIP(value_string);
  332.             //g_stAdminPageIP[2] = value_string;
  333.         }
  334.  
  335.         TOKEN("adminpage_password")
  336.         {
  337.             g_stAdminPagePassword = value_string;
  338.         }
  339.  
  340.         TOKEN("hostname")
  341.         {
  342.             g_stHostname = value_string;
  343.             //fprintf(stdout, "HOSTNAME: %s\n", g_stHostname.c_str());
  344.             continue;
  345.         }
  346.  
  347.         TOKEN("channel")
  348.         {
  349.             str_to_number(g_bChannel, value_string);
  350.             continue;
  351.         }
  352.  
  353.         TOKEN("player_sql")
  354.         {
  355.             const char * line = two_arguments(value_string, db_host[0], sizeof(db_host[0]), db_user[0], sizeof(db_user[0]));
  356.             line = two_arguments(line, db_pwd[0], sizeof(db_pwd[0]), db_db[0], sizeof(db_db[0]));
  357.  
  358.             if (NULL != line[0])
  359.             {
  360.                 char buf[256];
  361.                 one_argument(line, buf, sizeof(buf));
  362.                 str_to_number(mysql_db_port[0], buf);
  363.             }
  364.  
  365.             if (!*db_host[0] || !*db_user[0] || !*db_pwd[0] || !*db_db[0])
  366.             {
  367.                 fprintf(stderr, "PLAYER_SQL syntax: logsql <host user password db>\n");
  368.                 exit(1);
  369.             }
  370.  
  371.             char buf[1024];
  372.             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]);
  373.             isPlayerSQL = true;
  374.             continue;
  375.         }
  376.  
  377.         TOKEN("common_sql")
  378.         {
  379.             const char * line = two_arguments(value_string, db_host[1], sizeof(db_host[1]), db_user[1], sizeof(db_user[1]));
  380.             line = two_arguments(line, db_pwd[1], sizeof(db_pwd[1]), db_db[1], sizeof(db_db[1]));
  381.  
  382.             if (NULL != line[0])
  383.             {
  384.                 char buf[256];
  385.                 one_argument(line, buf, sizeof(buf));
  386.                 str_to_number(mysql_db_port[1], buf);
  387.             }
  388.  
  389.             if (!*db_host[1] || !*db_user[1] || !*db_pwd[1] || !*db_db[1])
  390.             {
  391.                 fprintf(stderr, "COMMON_SQL syntax: logsql <host user password db>\n");
  392.                 exit(1);
  393.             }
  394.  
  395.             char buf[1024];
  396.             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]);
  397.             isCommonSQL = true;
  398.             continue;
  399.         }
  400.  
  401.         TOKEN("log_sql")
  402.         {
  403.             const char * line = two_arguments(value_string, log_host, sizeof(log_host), log_user, sizeof(log_user));
  404.             line = two_arguments(line, log_pwd, sizeof(log_pwd), log_db, sizeof(log_db));
  405.  
  406.             if (NULL != line[0])
  407.             {
  408.                 char buf[256];
  409.                 one_argument(line, buf, sizeof(buf));
  410.                 str_to_number(log_port, buf);
  411.             }
  412.  
  413.             if (!*log_host || !*log_user || !*log_pwd || !*log_db)
  414.             {
  415.                 fprintf(stderr, "LOG_SQL syntax: logsql <host user password db>\n");
  416.                 exit(1);
  417.             }
  418.  
  419.             char buf[1024];
  420.             snprintf(buf, sizeof(buf), "LOG_SQL: %s %s %s %s %d", log_host, log_user, log_pwd, log_db, log_port);
  421.             continue;
  422.         }
  423.  
  424.        
  425.         //OPENID       
  426.         TOKEN("WEB_AUTH")
  427.         {
  428.             const char * line = two_arguments(value_string, openid_host, sizeof(openid_host), openid_uri, sizeof(openid_uri));
  429.  
  430.             if (!*openid_host || !*openid_uri)
  431.             {
  432.                 fprintf(stderr, "WEB_AUTH syntax error (ex: WEB_AUTH <host(metin2.co.kr) uri(/kyw/gameauth.php)>\n");
  433.                 exit(1);
  434.             }
  435.  
  436.             char buf[1024];
  437.             openid_server = 1;
  438.             snprintf(buf, sizeof(buf), "WEB_AUTH: %s %s", openid_host, openid_uri);
  439.             continue;
  440.         }
  441.     }
  442.  
  443.     fclose(fpOnlyForDB);
  444.  
  445.     if (!isCommonSQL)
  446.     {
  447.         puts("LOAD_COMMON_SQL_INFO_FAILURE:");
  448.         puts("");
  449.         puts("CONFIG:");
  450.         puts("------------------------------------------------");
  451.         puts("COMMON_SQL: HOST USER PASSWORD DATABASE");
  452.         puts("");
  453.         exit(1);
  454.     }
  455.  
  456.     if (!isPlayerSQL)
  457.     {
  458.         puts("LOAD_PLAYER_SQL_INFO_FAILURE:");
  459.         puts("");
  460.         puts("CONFIG:");
  461.         puts("------------------------------------------------");
  462.         puts("PLAYER_SQL: HOST USER PASSWORD DATABASE");
  463.         puts("");
  464.         exit(1);
  465.     }
  466.  
  467.     AccountDB::instance().Connect(db_host[1], mysql_db_port[1], db_user[1], db_pwd[1], db_db[1]);
  468.  
  469.     if (false == AccountDB::instance().IsConnected())
  470.     {
  471.         fprintf(stderr, "cannot start server while no common sql connected\n");
  472.         exit(1);
  473.     }
  474.  
  475.     {
  476.         char szQuery[512];
  477.         snprintf(szQuery, sizeof(szQuery), "SELECT mKey, mValue FROM locale");
  478.  
  479.         std::auto_ptr<SQLMsg> pMsg(AccountDB::instance().DirectQuery(szQuery));
  480.  
  481.         if (pMsg->Get()->uiNumRows == 0)
  482.         {
  483.             fprintf(stderr, "COMMON_SQL: DirectQuery failed : %s\n", szQuery);
  484.             exit(1);
  485.         }
  486.  
  487.         MYSQL_ROW row;
  488.  
  489.         while (NULL != (row = mysql_fetch_row(pMsg->Get()->pSQLResult)))
  490.         {
  491.             if (strcasecmp(row[0], "LOCALE") == 0)
  492.             {
  493.                 if (LocaleService_Init(row[1]) == false)
  494.                 {
  495.                     fprintf(stderr, "COMMON_SQL: invalid locale key %s\n", row[1]);
  496.                     exit(1);
  497.                 }
  498.             }
  499.         }
  500.     }
  501.  
  502.     AccountDB::instance().SetLocale(g_stLocale);
  503.  
  504.     AccountDB::instance().ConnectAsync(db_host[1], mysql_db_port[1], db_user[1], db_pwd[1], db_db[1], g_stLocale.c_str());
  505.  
  506.     DBManager::instance().Connect(db_host[0], mysql_db_port[0], db_user[0], db_pwd[0], db_db[0]);
  507.  
  508.     if (!DBManager::instance().IsConnected())
  509.     {
  510.         fprintf(stderr, "PlayerSQL.ConnectError\n");
  511.         exit(1);
  512.     }
  513.  
  514.     if (false == g_bAuthServer)
  515.     {
  516.         LogManager::instance().Connect(log_host, log_port, log_user, log_pwd, log_db);
  517.  
  518.         if (!LogManager::instance().IsConnected())
  519.         {
  520.             fprintf(stderr, "LogSQL.ConnectError\n");
  521.             exit(1);
  522.         }
  523.  
  524.         LogManager::instance().BootLog(g_stHostname.c_str(), g_bChannel);
  525.     }
  526.  
  527.     {
  528.         char szQuery[256];
  529.         snprintf(szQuery, sizeof(szQuery), "SELECT mValue FROM locale WHERE mKey='SKILL_POWER_BY_LEVEL'");
  530.         std::auto_ptr<SQLMsg> pMsg(AccountDB::instance().DirectQuery(szQuery));
  531.  
  532.         if (pMsg->Get()->uiNumRows == 0)
  533.         {
  534.             fprintf(stderr, "[SKILL_PERCENT] Query failed: %s", szQuery);
  535.             exit(1);
  536.         }
  537.  
  538.         MYSQL_ROW row;
  539.  
  540.         row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  541.  
  542.         const char * p = row[0];
  543.         int cnt = 0;
  544.         char num[128];
  545.         int aiBaseSkillPowerByLevelTable[SKILL_MAX_LEVEL+1];
  546.  
  547.         while (*p != '\0' && cnt < (SKILL_MAX_LEVEL + 1))
  548.         {
  549.             p = one_argument(p, num, sizeof(num));
  550.             aiBaseSkillPowerByLevelTable[cnt++] = atoi(num);
  551.  
  552.             if (*p == '\0')
  553.             {
  554.                 if (cnt != (SKILL_MAX_LEVEL + 1))
  555.                 {
  556.                     fprintf(stderr, "[SKILL_PERCENT] locale table has not enough skill information! (count: %d query: %s)", cnt, szQuery);
  557.                     exit(1);
  558.                 }
  559.  
  560.                 fprintf(stdout, "SKILL_POWER_BY_LEVEL: Done! (count %d)\n", cnt);
  561.                 break;
  562.             }
  563.         }
  564.  
  565.         for (int job = 0; job < JOB_MAX_NUM * 2; ++job)
  566.         {
  567.             snprintf(szQuery, sizeof(szQuery), "SELECT mValue from locale where mKey='SKILL_POWER_BY_LEVEL_TYPE%d' ORDER BY CAST(mValue AS unsigned)", job);
  568.             std::auto_ptr<SQLMsg> pMsg(AccountDB::instance().DirectQuery(szQuery));
  569.  
  570.             if (pMsg->Get()->uiNumRows == 0)
  571.             {
  572.                 CTableBySkill::instance().SetSkillPowerByLevelFromType(job, aiBaseSkillPowerByLevelTable);
  573.                 continue;
  574.             }
  575.  
  576.             row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  577.             cnt = 0;
  578.             p = row[0];
  579.             int aiSkillTable[SKILL_MAX_LEVEL + 1];
  580.  
  581.             while (*p != '\0' && cnt < (SKILL_MAX_LEVEL + 1))
  582.             {          
  583.                 p = one_argument(p, num, sizeof(num));
  584.                 aiSkillTable[cnt++] = atoi(num);
  585.  
  586.                 if (*p == '\0')
  587.                 {
  588.                     if (cnt != (SKILL_MAX_LEVEL + 1))
  589.                     {
  590.                         fprintf(stderr, "[SKILL_PERCENT] locale table has not enough skill information! (count: %d query: %s)", cnt, szQuery);
  591.                         exit(1);
  592.                     }
  593.  
  594.                     fprintf(stdout, "SKILL_POWER_BY_JOB: Done! (job: %d count: %d)\n", job, cnt);
  595.                     break;
  596.                 }
  597.             }
  598.  
  599.             CTableBySkill::instance().SetSkillPowerByLevelFromType(job, aiSkillTable);
  600.         }      
  601.     }
  602.  
  603.     log_set_expiration_days(2);
  604.  
  605.     while (fgets(buf, 256, fp))
  606.     {
  607.         parse_token(buf, token_string, value_string);
  608.  
  609.         TOKEN("empire_whisper")
  610.         {
  611.             bool b_value = 0;
  612.             str_to_number(b_value, value_string);
  613.             g_bEmpireWhisper = !!b_value;
  614.             continue;
  615.         }
  616.  
  617.         TOKEN("mark_server")
  618.         {
  619.             guild_mark_server = is_string_true(value_string);
  620.             continue;
  621.         }
  622.  
  623.         TOKEN("mark_min_level")
  624.         {
  625.             str_to_number(guild_mark_min_level, value_string);
  626.             guild_mark_min_level = MINMAX(0, guild_mark_min_level, GUILD_MAX_LEVEL);
  627.             continue;
  628.         }
  629.  
  630.         TOKEN("port")
  631.         {
  632.             str_to_number(mother_port, value_string);
  633.             continue;
  634.         }
  635.  
  636.         TOKEN("log_keep_days")
  637.         {
  638.             int i = 0;
  639.             str_to_number(i, value_string);
  640.             log_set_expiration_days(MINMAX(1, i, 90));
  641.             continue;
  642.         }
  643.  
  644.         TOKEN("passes_per_sec")
  645.         {
  646.             str_to_number(passes_per_sec, value_string);
  647.             continue;
  648.         }
  649.  
  650.         TOKEN("p2p_port")
  651.         {
  652.             str_to_number(p2p_port, value_string);
  653.             continue;
  654.         }
  655.  
  656.         TOKEN("db_port")
  657.         {
  658.             str_to_number(db_port, value_string);
  659.             continue;
  660.         }
  661.  
  662.         TOKEN("db_addr")
  663.         {
  664.             strlcpy(db_addr, value_string, sizeof(db_addr));
  665.  
  666.             for (int n =0; n < ADDRESS_MAX_LEN; ++n)
  667.             {
  668.                 if (db_addr[n] == ' ')
  669.                     db_addr[n] = '\0';
  670.             }
  671.  
  672.             continue;
  673.         }
  674.  
  675.         TOKEN("save_event_second_cycle")
  676.         {
  677.             int cycle = 0;
  678.             str_to_number(cycle, value_string);
  679.             save_event_second_cycle = cycle * passes_per_sec;
  680.             continue;
  681.         }
  682.  
  683.         TOKEN("ping_event_second_cycle")
  684.         {
  685.             int cycle = 0;
  686.             str_to_number(cycle, value_string);
  687.             ping_event_second_cycle = cycle * passes_per_sec;
  688.             continue;
  689.         }
  690.  
  691.         TOKEN("table_postfix")
  692.         {
  693.             g_table_postfix = value_string;
  694.             continue;
  695.         }
  696.  
  697.         TOKEN("test_server")
  698.         {
  699.             printf("-----------------------------------------------\n");
  700.             printf("Mattius Game Core : 46789 \n");
  701.             printf("-----------------------------------------------\n");
  702.             str_to_number(test_server, value_string);
  703.             continue;
  704.         }
  705.  
  706.         TOKEN("speed_server")
  707.         {
  708.             printf("-----------------------------------------------\n");
  709.             printf("Mattius Game Core : 46789 \n");
  710.             printf("-----------------------------------------------\n");
  711.             str_to_number(speed_server, value_string);
  712.             continue;
  713.         }
  714. #ifdef __AUCTION__
  715.         TOKEN("auction_server")
  716.         {
  717.             printf("-----------------------------------------------\n");
  718.             printf("Mattius Game Core : 46789 \n");
  719.             printf("-----------------------------------------------\n");
  720.             str_to_number(auction_server, value_string);
  721.             continue;
  722.         }
  723. #endif
  724.         TOKEN("distribution_test_server")
  725.         {
  726.             str_to_number(distribution_test_server, value_string);
  727.             continue;
  728.         }
  729.  
  730.         TOKEN("china_event_server")
  731.         {
  732.             str_to_number(china_event_server, value_string);
  733.             continue;
  734.         }
  735.  
  736.         TOKEN("shutdowned")
  737.         {
  738.             g_bNoMoreClient = true;
  739.             continue;
  740.         }
  741.  
  742.         TOKEN("no_regen")
  743.         {
  744.             g_bNoRegen = true;
  745.             continue;
  746.         }
  747.  
  748.         TOKEN("traffic_profile")
  749.         {
  750.             g_bTrafficProfileOn = true;
  751.             continue;
  752.         }
  753.  
  754.  
  755.         TOKEN("map_allow")
  756.         {
  757.             char * p = value_string;
  758.             string stNum;
  759.  
  760.             for (; *p; p++)
  761.             {  
  762.                 if (isnhspace(*p))
  763.                 {
  764.                     if (stNum.length())
  765.                     {
  766.                         int index = 0;
  767.                         str_to_number(index, stNum.c_str());
  768.                         map_allow_add(index);
  769.                         stNum.clear();
  770.                     }
  771.                 }
  772.                 else
  773.                     stNum += *p;
  774.             }
  775.  
  776.             if (stNum.length())
  777.             {
  778.                 int index = 0;
  779.                 str_to_number(index, stNum.c_str());
  780.                 map_allow_add(index);
  781.             }
  782.  
  783.             continue;
  784.         }
  785.  
  786.         TOKEN("no_wander")
  787.         {
  788.             no_wander = true;
  789.             continue;
  790.         }
  791.  
  792.         TOKEN("user_limit")
  793.         {
  794.             str_to_number(g_iUserLimit, value_string);
  795.             continue;
  796.         }
  797.  
  798.         TOKEN("skill_disable")
  799.         {
  800.             str_to_number(g_bSkillDisable, value_string);
  801.             continue;
  802.         }
  803.  
  804.         TOKEN("auth_server")
  805.         {
  806.             char szIP[32];
  807.             char szPort[32];
  808.  
  809.             two_arguments(value_string, szIP, sizeof(szIP), szPort, sizeof(szPort));
  810.  
  811.             if (!*szIP || (!*szPort && strcasecmp(szIP, "master")))
  812.             {
  813.                 fprintf(stderr, "AUTH_SERVER: syntax error: <ip|master> <port>\n");
  814.                 exit(1);
  815.             }
  816.  
  817.             g_bAuthServer = true;
  818.  
  819.             LoadBanIP("BANIP");
  820.  
  821.             if (!strcasecmp(szIP, "master"))
  822.                 fprintf(stdout, "AUTH_SERVER: I am the master\n");
  823.             else
  824.             {
  825.                 g_stAuthMasterIP = szIP;
  826.                 str_to_number(g_wAuthMasterPort, szPort);
  827.  
  828.                 fprintf(stdout, "AUTH_SERVER: master %s %u\n", g_stAuthMasterIP.c_str(), g_wAuthMasterPort);
  829.             }
  830.             continue;
  831.         }
  832.  
  833.         TOKEN("billing")
  834.         {
  835.             g_bBilling = true;
  836.         }
  837.  
  838.         TOKEN("quest_dir")
  839.         {
  840.             sys_log(0, "QUEST_DIR SETTING : %s", value_string);
  841.             g_stQuestDir = value_string;
  842.         }
  843.  
  844.         TOKEN("quest_object_dir")
  845.         {
  846.             std::istringstream is(value_string);
  847.             sys_log(0, "QUEST_OBJECT_DIR SETTING : %s", value_string);
  848.             string dir;
  849.             while (!is.eof())
  850.             {
  851.                 is >> dir;
  852.                 if (is.fail())
  853.                     break;
  854.                 g_setQuestObjectDir.insert(dir);
  855.                 sys_log(0, "QUEST_OBJECT_DIR INSERT : %s", dir .c_str());
  856.             }
  857.         }
  858.  
  859.         TOKEN("teen_addr")
  860.         {
  861.             strlcpy(teen_addr, value_string, sizeof(teen_addr));
  862.  
  863.             for (int n =0; n < ADDRESS_MAX_LEN; ++n)
  864.             {
  865.                 if (teen_addr[n] == ' ')
  866.                     teen_addr[n] = '\0';
  867.             }
  868.  
  869.             continue;
  870.         }
  871.  
  872.         TOKEN("teen_port")
  873.         {
  874.             str_to_number(teen_port, value_string);
  875.         }
  876.  
  877.         TOKEN("synchack_limit_count")
  878.         {
  879.             str_to_number(g_iSyncHackLimitCount, value_string);
  880.         }
  881.  
  882.         TOKEN("speedhack_limit_count")
  883.         {
  884.             str_to_number(SPEEDHACK_LIMIT_COUNT, value_string);
  885.         }
  886.  
  887.         TOKEN("speedhack_limit_bonus")
  888.         {
  889.             str_to_number(SPEEDHACK_LIMIT_BONUS, value_string);
  890.         }
  891.  
  892.         TOKEN("server_id")
  893.         {
  894.             str_to_number(g_server_id, value_string);
  895.         }
  896.  
  897.         TOKEN("mall_url")
  898.         {
  899.             g_strWebMallURL = value_string;
  900.         }
  901.  
  902.         TOKEN("bind_ip")
  903.         {
  904.             strlcpy(g_szPublicIP, value_string, sizeof(g_szPublicIP));
  905.         }
  906.  
  907.         TOKEN("view_range")
  908.         {
  909.             str_to_number(VIEW_RANGE, value_string);
  910.         }
  911.  
  912.         TOKEN("spam_block_duration")
  913.         {
  914.             str_to_number(g_uiSpamBlockDuration, value_string);
  915.         }
  916.  
  917.         TOKEN("spam_block_score")
  918.         {
  919.             str_to_number(g_uiSpamBlockScore, value_string);
  920.             g_uiSpamBlockScore = MAX(1, g_uiSpamBlockScore);
  921.         }
  922.  
  923.         TOKEN("spam_block_reload_cycle")
  924.         {
  925.             str_to_number(g_uiSpamReloadCycle, value_string);
  926.             g_uiSpamReloadCycle = MAX(60, g_uiSpamReloadCycle);
  927.         }
  928.  
  929.         TOKEN("check_multihack")
  930.         {
  931.             str_to_number(g_bCheckMultiHack, value_string);
  932.         }
  933.  
  934.         TOKEN("spam_block_max_level")
  935.         {
  936.             str_to_number(g_iSpamBlockMaxLevel, value_string);
  937.         }
  938.         TOKEN("protect_normal_player")
  939.         {
  940.             str_to_number(g_protectNormalPlayer, value_string);
  941.         }
  942.         TOKEN("notice_battle_zone")
  943.         {
  944.             str_to_number(g_noticeBattleZone, value_string);
  945.         }
  946.  
  947.         TOKEN("hackshield_enable")
  948.         {
  949.             int flag = 0;
  950.  
  951.             str_to_number(flag, value_string);
  952.  
  953.             if (1 == flag)
  954.             {
  955.                 isHackShieldEnable = true;
  956.             }
  957.         }
  958.  
  959.         TOKEN("hackshield_first_check_time")
  960.         {
  961.             int secs = 30;
  962.             str_to_number(secs, value_string);
  963.  
  964.             HackShield_FirstCheckWaitTime = passes_per_sec * secs;
  965.         }
  966.  
  967.         TOKEN("hackshield_check_cycle_time")
  968.         {
  969.             int secs = 180;
  970.             str_to_number(secs, value_string);
  971.  
  972.             HackShield_CheckCycleTime = passes_per_sec * secs;
  973.         }
  974.  
  975.         TOKEN("xtrap_enable")
  976.         {
  977.             int flag = 0;
  978.             str_to_number(flag, value_string);
  979.  
  980.             if (1 == flag )
  981.             {
  982.                 bXTrapEnabled = true;
  983.             }
  984.         }
  985.  
  986.         TOKEN("pk_protect_level")
  987.         {
  988.             str_to_number(PK_PROTECT_LEVEL, value_string);
  989.             fprintf(stderr, "PK_PROTECT_LEVEL: %d", PK_PROTECT_LEVEL);
  990.         }
  991.  
  992.         TOKEN("max_level")
  993.         {
  994.             str_to_number(gPlayerMaxLevel, value_string);
  995.  
  996.             gPlayerMaxLevel = MINMAX(1, gPlayerMaxLevel, PLAYER_MAX_LEVEL_CONST);
  997.  
  998.             fprintf(stderr, "PLAYER_MAX_LEVEL: %d\n", gPlayerMaxLevel);
  999.         }
  1000.  
  1001.         TOKEN("YESILMORPOTSINIRSIZ")        
  1002.         {
  1003.             str_to_number(YesilMorpot, value_string);
  1004.             continue;
  1005.         }
  1006.        
  1007.         TOKEN("KIRMIZIMAVIPOTSINIRSIZ")
  1008.         {
  1009.             str_to_number(KirmiziMavipot, value_string);
  1010.             continue;
  1011.         }
  1012.        
  1013.         TOKEN("NESNE_MARKET")
  1014.         {
  1015.             str_to_number(NesneMarket, value_string);
  1016.             continue;
  1017.         }
  1018.        
  1019.         TOKEN("LONCA_SKOR")
  1020.         {
  1021.             str_to_number(MaxLoncaSkor, value_string);
  1022.             continue;
  1023.         }
  1024.        
  1025.         TOKEN("LONCA_1LEVEL_ALINABILEN_UYE")
  1026.         {
  1027.             str_to_number(LoncaAcilisKacKisiAlsin, value_string);
  1028.             continue;
  1029.         }
  1030.        
  1031.         TOKEN("LONCA_LEVEL_ARTAN_UYE")
  1032.         {
  1033.             str_to_number(LoncaLevelAtlarsaKacKisiAlmaArtsin, value_string);
  1034.             continue;
  1035.         }
  1036.        
  1037.         TOKEN("block_char_creation")
  1038.         {
  1039.             int tmp = 0;
  1040.  
  1041.             str_to_number(tmp, value_string);
  1042.  
  1043.             if (0 == tmp)
  1044.                 g_BlockCharCreation = false;
  1045.             else
  1046.                 g_BlockCharCreation = true;
  1047.  
  1048.             continue;
  1049.         }
  1050.     }
  1051.  
  1052.     if (g_setQuestObjectDir.empty())
  1053.         g_setQuestObjectDir.insert(g_stDefaultQuestObjectDir);
  1054.  
  1055.     if (0 == db_port)
  1056.     {
  1057.         fprintf(stderr, "DB_PORT not configured\n");
  1058.         exit(1);
  1059.     }
  1060.  
  1061.     if (0 == g_bChannel)
  1062.     {
  1063.         fprintf(stderr, "CHANNEL not configured\n");
  1064.         exit(1);
  1065.     }
  1066.  
  1067.     if (g_stHostname.empty())
  1068.     {
  1069.         fprintf(stderr, "HOSTNAME must be configured.\n");
  1070.         exit(1);
  1071.     }
  1072.  
  1073.     LocaleService_LoadLocaleStringFile();
  1074.     LocaleService_TransferDefaultSetting();
  1075.     LocaleService_LoadEmpireTextConvertTables();
  1076.  
  1077.     fclose(fp);
  1078.  
  1079.     if ((fp = fopen("CMD", "r")))
  1080.     {
  1081.         while (fgets(buf, 256, fp))
  1082.         {
  1083.             char cmd[32], levelname[32];
  1084.             int level;
  1085.  
  1086.             two_arguments(buf, cmd, sizeof(cmd), levelname, sizeof(levelname));
  1087.  
  1088.             if (!*cmd || !*levelname)
  1089.             {
  1090.                 fprintf(stderr, "CMD syntax error: <cmd> <DISABLE | LOW_WIZARD | WIZARD | HIGH_WIZARD | GOD>\n");
  1091.                 exit(1);
  1092.             }
  1093.  
  1094.             if (!strcasecmp(levelname, "LOW_WIZARD"))
  1095.                 level = GM_LOW_WIZARD;
  1096.             else if (!strcasecmp(levelname, "WIZARD"))
  1097.                 level = GM_WIZARD;
  1098.             else if (!strcasecmp(levelname, "HIGH_WIZARD"))
  1099.                 level = GM_HIGH_WIZARD;
  1100.             else if (!strcasecmp(levelname, "GOD"))
  1101.                 level = GM_GOD;
  1102.             else if (!strcasecmp(levelname, "IMPLEMENTOR"))
  1103.                 level = GM_IMPLEMENTOR;
  1104.             else if (!strcasecmp(levelname, "DISABLE"))
  1105.                 level = GM_IMPLEMENTOR + 1;
  1106.             else
  1107.             {
  1108.                 fprintf(stderr, "CMD syntax error: <cmd> <DISABLE | LOW_WIZARD | WIZARD | HIGH_WIZARD | GOD>\n");
  1109.                 exit(1);
  1110.             }
  1111.  
  1112.             interpreter_set_privilege(cmd, level);
  1113.         }
  1114.  
  1115.         fclose(fp);
  1116.     }
  1117.  
  1118.     LoadValidCRCList();
  1119.     LoadStateUserCount();
  1120.  
  1121.     CWarMapManager::instance().LoadWarMapInfo(NULL);
  1122.  
  1123.     FN_log_adminpage();
  1124. }
  1125.  
  1126. const char* get_table_postfix()
  1127. {
  1128.     return g_table_postfix.c_str();
  1129. }
  1130.  
  1131. void LoadValidCRCList()
  1132. {
  1133.     s_set_dwProcessCRC.clear();
  1134.     s_set_dwFileCRC.clear();
  1135.  
  1136.     FILE * fp;
  1137.     char buf[256];
  1138.  
  1139.     if ((fp = fopen("CRC", "r")))
  1140.     {
  1141.         while (fgets(buf, 256, fp))
  1142.         {
  1143.             if (!*buf)
  1144.                 continue;
  1145.  
  1146.             DWORD dwValidClientProcessCRC;
  1147.             DWORD dwValidClientFileCRC;
  1148.  
  1149.             sscanf(buf, " %u %u ", &dwValidClientProcessCRC, &dwValidClientFileCRC);
  1150.  
  1151.             s_set_dwProcessCRC.insert(dwValidClientProcessCRC);
  1152.             s_set_dwFileCRC.insert(dwValidClientFileCRC);
  1153.  
  1154.             fprintf(stderr, "CLIENT_CRC: %u %u\n", dwValidClientProcessCRC, dwValidClientFileCRC);
  1155.         }
  1156.  
  1157.         fclose(fp);
  1158.     }
  1159. }
  1160.  
  1161. bool LoadClientVersion()
  1162. {
  1163.     FILE * fp = fopen("VERSION", "r");
  1164.  
  1165.     if (!fp)
  1166.         return false;
  1167.  
  1168.     char buf[256];
  1169.     fgets(buf, 256, fp);
  1170.  
  1171.     char * p = strchr(buf, '\n');
  1172.     if (p) *p = '\0';
  1173.  
  1174.     fprintf(stderr, "VERSION: \"%s\"\n", buf);
  1175.  
  1176.     g_stClientVersion = buf;
  1177.     fclose(fp);
  1178.     return true;
  1179. }
  1180.  
  1181. void CheckClientVersion()
  1182. {
  1183.     if (LC_IsEurope())
  1184.     {
  1185.         g_bCheckClientVersion = true;
  1186.     }
  1187.     else
  1188.     {
  1189.         g_bCheckClientVersion = false;
  1190.     }
  1191.  
  1192.     const DESC_MANAGER::DESC_SET & set = DESC_MANAGER::instance().GetClientSet();
  1193.     DESC_MANAGER::DESC_SET::const_iterator it = set.begin();
  1194.  
  1195.     while (it != set.end())
  1196.     {
  1197.         LPDESC d = *(it++);
  1198.  
  1199.         if (!d->GetCharacter())
  1200.             continue;
  1201.  
  1202.  
  1203.         int version = atoi(g_stClientVersion.c_str());
  1204.         int date    = atoi(d->GetClientVersion() );
  1205.  
  1206.         if (version != date)
  1207.         {
  1208.             d->GetCharacter()->ChatPacket(CHAT_TYPE_NOTICE, LC_TEXT("클라이언트 버전이 틀려 로그아웃 됩니다. 정상적으로 패치 후 접속하세요."));
  1209.             d->DelayedDisconnect(10);
  1210.         }
  1211.     }
  1212. }
  1213.  
  1214. void LoadStateUserCount()
  1215. {
  1216.     FILE * fp = fopen("state_user_count", "r");
  1217.  
  1218.     if (!fp)
  1219.         return;
  1220.  
  1221.     if (!LC_IsHongKong())
  1222.         fscanf(fp, " %d %d ", &g_iFullUserCount, &g_iBusyUserCount);
  1223.  
  1224.     fclose(fp);
  1225. }
  1226.  
  1227. bool IsValidProcessCRC(DWORD dwCRC)
  1228. {
  1229.     return s_set_dwProcessCRC.find(dwCRC) != s_set_dwProcessCRC.end();
  1230. }
  1231.  
  1232. bool IsValidFileCRC(DWORD dwCRC)
  1233. {
  1234.     return s_set_dwFileCRC.find(dwCRC) != s_set_dwFileCRC.end();
  1235. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement