SHARE
TWEET

Untitled

a guest Feb 21st, 2020 106 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include "stdafx.h"
  3. #include "../../common/CommonDefines.h"
  4.  
  5. #include "../../common/billing.h"
  6. #include "../../common/building.h"
  7. #include "../../common/VnumHelper.h"
  8. #include "../../libgame/include/grid.h"
  9.  
  10. #include "ClientManager.h"
  11.  
  12. #include "Main.h"
  13. #include "Config.h"
  14. #include "DBManager.h"
  15. #include "QID.h"
  16. #include "GuildManager.h"
  17. #include "PrivManager.h"
  18. #include "MoneyLog.h"
  19. #include "ItemAwardManager.h"
  20. #include "Marriage.h"
  21. #include "Monarch.h"
  22. #include "BlockCountry.h"
  23. #include "ItemIDRangeManager.h"
  24. #include "Cache.h"
  25. #include <sstream>
  26. #ifdef __AUCTION__
  27. #include "AuctionManager.h"
  28. #endif
  29. extern int g_iPlayerCacheFlushSeconds;
  30. extern int g_iItemCacheFlushSeconds;
  31. extern int g_test_server;
  32. extern int g_log;
  33. extern std::string g_stLocale;
  34. extern std::string g_stLocaleNameColumn;
  35. bool CreateItemTableFromRes(MYSQL_RES * res, std::vector<TPlayerItem> * pVec, DWORD dwPID);
  36.  
  37. DWORD g_dwUsageMax = 0;
  38. DWORD g_dwUsageAvg = 0;
  39.  
  40. CPacketInfo g_query_info;
  41. CPacketInfo g_item_info;
  42.  
  43. int g_item_count = 0;
  44. int g_query_count[2];
  45. #ifdef ENABLE_PROTO_FROM_DB
  46. bool g_bMirror2DB = false;
  47. #endif
  48.  
  49. CClientManager::CClientManager() :
  50.     m_pkAuthPeer(NULL),
  51.     m_iPlayerIDStart(0),
  52.     m_iPlayerDeleteLevelLimit(0),
  53.     m_iPlayerDeleteLevelLimitLower(0),
  54.     m_bChinaEventServer(false),
  55.     m_iShopTableSize(0),
  56.     m_pShopTable(NULL),
  57.     m_iRefineTableSize(0),
  58.     m_pRefineTable(NULL),
  59.     m_bShutdowned(FALSE),
  60.     m_iCacheFlushCount(0),
  61.     m_iCacheFlushCountLimit(200)
  62. {
  63.     m_itemRange.dwMin = 0;
  64.     m_itemRange.dwMax = 0;
  65.     m_itemRange.dwUsableItemIDMin = 0;
  66.  
  67.     memset(g_query_count, 0, sizeof(g_query_count));
  68. #ifdef ENABLE_PROTO_FROM_DB
  69.     bIsProtoReadFromDB = false;
  70. #endif
  71. }
  72.  
  73. CClientManager::~CClientManager()
  74. {
  75.     Destroy();
  76. }
  77.  
  78. void CClientManager::SetPlayerIDStart(int iIDStart)
  79. {
  80.     m_iPlayerIDStart = iIDStart;
  81. }
  82.  
  83. void CClientManager::GetPeerP2PHostNames(std::string& peerHostNames)
  84. {
  85.     std::ostringstream oss(std::ostringstream::out);
  86.  
  87.     for (itertype(m_peerList) it = m_peerList.begin(); it != m_peerList.end(); ++it)
  88.     {
  89.         CPeer * peer = *it;
  90.         oss << peer->GetHost() << " " << peer->GetP2PPort() << " channel : " << (int)(peer->GetChannel()) << "\n";
  91.     }
  92.  
  93.     peerHostNames += oss.str();
  94. }
  95.  
  96. void CClientManager::Destroy()
  97. {
  98.     m_mChannelStatus.clear();
  99.     for (itertype(m_peerList) i = m_peerList.begin(); i != m_peerList.end(); ++i)
  100.         (*i)->Destroy();
  101.  
  102.     m_peerList.clear();
  103.  
  104.     if (m_fdAccept > 0)
  105.     {
  106.         socket_close(m_fdAccept);
  107.         m_fdAccept = -1;
  108.     }
  109. }
  110.  
  111. #define ENABLE_DEFAULT_PRIV
  112. #ifdef ENABLE_DEFAULT_PRIV
  113. static bool bCleanOldPriv = true;
  114. static bool __InitializeDefaultPriv()
  115. {
  116.     if (bCleanOldPriv)
  117.     {
  118.         std::auto_ptr<SQLMsg> pCleanStuff(CDBManager::instance().DirectQuery("DELETE FROM priv_settings WHERE value <= 0 OR duration <= NOW();", SQL_COMMON));
  119.         printf("DEFAULT_PRIV_EMPIRE: removed %u expired priv settings.\n", pCleanStuff->Get()->uiAffectedRows);
  120.     }
  121.     std::auto_ptr<SQLMsg> pMsg(CDBManager::instance().DirectQuery("SELECT priv_type, id, type, value, UNIX_TIMESTAMP(duration) FROM priv_settings", SQL_COMMON));
  122.     if (pMsg->Get()->uiNumRows == 0)
  123.         return false;
  124.     MYSQL_ROW row = NULL;
  125.     while ((row = mysql_fetch_row(pMsg->Get()->pSQLResult)))
  126.     {
  127.         if (!strcmp(row[0], "EMPIRE"))
  128.         {
  129.             // init
  130.             BYTE empire = 0;
  131.             BYTE type = 1;
  132.             int value = 0;
  133.             time_t duration_sec = 0;
  134.             // set
  135.             str_to_number(empire, row[1]);
  136.             str_to_number(type, row[2]);
  137.             str_to_number(value, row[3]);
  138.             str_to_number(duration_sec, row[4]);
  139.             // recalibrate time
  140.             time_t now_time_sec = CClientManager::instance().GetCurrentTime();
  141.             if (now_time_sec>duration_sec)
  142.                 duration_sec = 0;
  143.             else
  144.                 duration_sec -= now_time_sec;
  145.             // send priv
  146.             printf("DEFAULT_PRIV_EMPIRE: set empire(%u), type(%u), value(%d), duration(%u)\n", empire, type, value, duration_sec);
  147.             CPrivManager::instance().AddEmpirePriv(empire, type, value, duration_sec);
  148.         }
  149.         else if (!strcmp(row[0], "GUILD"))
  150.         {
  151.             // init
  152.             DWORD guild_id = 0;
  153.             BYTE type = 1;
  154.             int value = 0;
  155.             time_t duration_sec = 0;
  156.             // set
  157.             str_to_number(guild_id, row[1]);
  158.             str_to_number(type, row[2]);
  159.             str_to_number(value, row[3]);
  160.             str_to_number(duration_sec, row[4]);
  161.             // recalibrate time
  162.             time_t now_time_sec = CClientManager::instance().GetCurrentTime();
  163.             if (now_time_sec>duration_sec)
  164.                 duration_sec = 0;
  165.             else
  166.                 duration_sec -= now_time_sec;
  167.             // send priv
  168.             if (guild_id)
  169.             {
  170.                 printf("DEFAULT_PRIV_GUILD: set guild_id(%u), type(%u), value(%d), duration(%u)\n", guild_id, type, value, duration_sec);
  171.                 CPrivManager::instance().AddGuildPriv(guild_id, type, value, duration_sec);
  172.             }
  173.         }
  174.         else if (!strcmp(row[0], "PLAYER"))
  175.         {
  176.             // init
  177.             DWORD pid = 0;
  178.             BYTE type = 1;
  179.             int value = 0;
  180.             // set
  181.             str_to_number(pid, row[1]);
  182.             str_to_number(type, row[2]);
  183.             str_to_number(value, row[3]);
  184.             // send priv
  185.             if (pid)
  186.             {
  187.                 printf("DEFAULT_PRIV_PLAYER: set pid(%u), type(%u), value(%d)\n", pid, type, value);
  188.                 CPrivManager::instance().AddCharPriv(pid, type, value);
  189.             }
  190.         }
  191.     }
  192.     return true;
  193. }
  194.  
  195. static bool __UpdateDefaultPriv(const char* priv_type, DWORD id, BYTE type, int value, time_t duration_sec)
  196. {
  197.     char szQuery[1024];
  198.     snprintf(szQuery, 1024,
  199.         "REPLACE INTO priv_settings SET priv_type='%s', id=%u, type=%u, value=%d, duration=DATE_ADD(NOW(), INTERVAL %u SECOND);",
  200.         priv_type, id, type, value, duration_sec
  201.     );
  202.     std::auto_ptr<SQLMsg> pMsg(CDBManager::instance().DirectQuery(szQuery, SQL_COMMON));
  203.     return pMsg->Get()->uiAffectedRows;
  204. }
  205. #endif
  206.  
  207. bool CClientManager::Initialize()
  208. {
  209.     int tmpValue;
  210.  
  211.     //BOOT_LOCALIZATION
  212.     if (!InitializeLocalization())
  213.     {
  214.         fprintf(stderr, "Failed Localization Infomation so exit\n");
  215.         return false;
  216.     }
  217. #ifdef ENABLE_DEFAULT_PRIV
  218.     if (!__InitializeDefaultPriv())
  219.     {
  220.         fprintf(stderr, "Failed Default Priv Setting so exit\n");
  221.         // return false;
  222.     }
  223. #endif
  224.     //END_BOOT_LOCALIZATION
  225.     //ITEM_UNIQUE_ID
  226.  
  227.     if (!InitializeNowItemID())
  228.     {
  229.         fprintf(stderr, " Item range Initialize Failed. Exit DBCache Server\n");
  230.         return false;
  231.     }
  232.     //END_ITEM_UNIQUE_ID
  233.  
  234. #ifdef ENABLE_PROTO_FROM_DB
  235.     int iTemp;
  236.     if (CConfig::instance().GetValue("PROTO_FROM_DB", &iTemp))
  237.     {
  238.         bIsProtoReadFromDB = !!iTemp;
  239.         fprintf(stdout, "PROTO_FROM_DB: %s\n", (bIsProtoReadFromDB)?"Enabled":"Disabled");
  240.     }
  241.     if (!bIsProtoReadFromDB && CConfig::instance().GetValue("MIRROR2DB", &iTemp))
  242.     {
  243.         g_bMirror2DB = !!iTemp;
  244.         fprintf(stdout, "MIRROR2DB: %s\n", (g_bMirror2DB)?"Enabled":"Disabled");
  245.     }
  246. #endif
  247.     if (!InitializeTables())
  248.     {
  249.         sys_err("Table Initialize FAILED");
  250.         return false;
  251.     }
  252.  
  253.     CGuildManager::instance().BootReserveWar();
  254.  
  255.     if (!CConfig::instance().GetValue("BIND_PORT", &tmpValue))
  256.         tmpValue = 5300;
  257.  
  258.     char szBindIP[128];
  259.  
  260.     if (!CConfig::instance().GetValue("BIND_IP", szBindIP, 128))
  261.         strlcpy(szBindIP, "0", sizeof(szBindIP));
  262.  
  263.     m_fdAccept = socket_tcp_bind(szBindIP, tmpValue);
  264.  
  265.     if (m_fdAccept < 0)
  266.     {
  267.         perror("socket");
  268.         return false;
  269.     }
  270.  
  271.     sys_log(0, "ACCEPT_HANDLE: %u", m_fdAccept);
  272.     fdwatch_add_fd(m_fdWatcher, m_fdAccept, NULL, FDW_READ, false);
  273.  
  274.     if (!CConfig::instance().GetValue("BACKUP_LIMIT_SEC", &tmpValue))
  275.         tmpValue = 600;
  276.  
  277.     m_looping = true;
  278.  
  279.     if (!CConfig::instance().GetValue("PLAYER_DELETE_LEVEL_LIMIT", &m_iPlayerDeleteLevelLimit))
  280.     {
  281.         sys_err("conf.txt: Cannot find PLAYER_DELETE_LEVEL_LIMIT, use default level %d", PLAYER_MAX_LEVEL_CONST + 1);
  282.         m_iPlayerDeleteLevelLimit = PLAYER_MAX_LEVEL_CONST + 1;
  283.     }
  284.  
  285.     if (!CConfig::instance().GetValue("PLAYER_DELETE_LEVEL_LIMIT_LOWER", &m_iPlayerDeleteLevelLimitLower))
  286.     {
  287.         m_iPlayerDeleteLevelLimitLower = 0;
  288.     }
  289.  
  290.     sys_log(0, "PLAYER_DELETE_LEVEL_LIMIT set to %d", m_iPlayerDeleteLevelLimit);
  291.     sys_log(0, "PLAYER_DELETE_LEVEL_LIMIT_LOWER set to %d", m_iPlayerDeleteLevelLimitLower);
  292.  
  293.     m_bChinaEventServer = false;
  294.  
  295.     int iChinaEventServer = 0;
  296.  
  297.     if (CConfig::instance().GetValue("CHINA_EVENT_SERVER", &iChinaEventServer))
  298.         m_bChinaEventServer = (iChinaEventServer);
  299.  
  300.     sys_log(0, "CHINA_EVENT_SERVER %s", CClientManager::instance().IsChinaEventServer()?"true":"false");
  301.  
  302.  
  303.     LoadEventFlag();
  304.  
  305.     // database character-setŔ» °­Á¦·Î ¸ÂĂă
  306.     if (g_stLocale == "big5" || g_stLocale == "sjis")
  307.         CDBManager::instance().QueryLocaleSet();
  308.  
  309.     return true;
  310. }
  311.  
  312. void CClientManager::MainLoop()
  313. {
  314.     SQLMsg * tmp;
  315.  
  316.     sys_log(0, "ClientManager pointer is %p", this);
  317.  
  318.     // ¸ŢŔηçÇÁ
  319.     while (!m_bShutdowned)
  320.     {
  321.         while ((tmp = CDBManager::instance().PopResult()))
  322.         {
  323.             AnalyzeQueryResult(tmp);
  324.             delete tmp;
  325.         }
  326.  
  327.         if (!Process())
  328.             break;
  329.  
  330.         log_rotate();
  331.     }
  332.  
  333.     //
  334.     // ¸ŢŔηçÇÁ Áľ·áĂł¸®
  335.     //
  336.     sys_log(0, "MainLoop exited, Starting cache flushing");
  337.  
  338.     signal_timer_disable();
  339.  
  340.     itertype(m_map_playerCache) it = m_map_playerCache.begin();
  341.  
  342.     //ÇĂ·ąŔĚľî Ĺ×ŔĚşí Äł˝¬ ÇĂ·Ż˝¬
  343.     while (it != m_map_playerCache.end())
  344.     {
  345.         CPlayerTableCache * c = (it++)->second;
  346.  
  347.         c->Flush();
  348.         delete c;
  349.     }
  350.     m_map_playerCache.clear();
  351.  
  352.  
  353.     itertype(m_map_itemCache) it2 = m_map_itemCache.begin();
  354.     //ľĆŔĚĹŰ ÇĂ·Ż˝¬
  355.     while (it2 != m_map_itemCache.end())
  356.     {
  357.         CItemCache * c = (it2++)->second;
  358.  
  359.         c->Flush();
  360.         delete c;
  361.     }
  362.     m_map_itemCache.clear();
  363.  
  364.     // MYSHOP_PRICE_LIST
  365.     //
  366.     // °łŔλóÁˇ ľĆŔĚĹŰ °ˇ°Ý ¸®˝şĆ® Flush
  367.     //
  368.     for (itertype(m_mapItemPriceListCache) itPriceList = m_mapItemPriceListCache.begin(); itPriceList != m_mapItemPriceListCache.end(); ++itPriceList)
  369.     {
  370.         CItemPriceListTableCache* pCache = itPriceList->second;
  371.         pCache->Flush();
  372.         delete pCache;
  373.     }
  374.  
  375.     m_mapItemPriceListCache.clear();
  376.     // END_OF_MYSHOP_PRICE_LIST
  377. }
  378.  
  379. void CClientManager::Quit()
  380. {
  381.     m_bShutdowned = TRUE;
  382. }
  383.  
  384. void CClientManager::QUERY_BOOT(CPeer* peer, TPacketGDBoot * p)
  385. {
  386.     const BYTE bPacketVersion = 6; // BOOT ĆĐŶŔĚ ąŮ˛đ¶§¸¶´Ů ąřČŁ¸¦ żĂ¸®µµ·Ď ÇŃ´Ů.
  387.  
  388.     std::vector<tAdminInfo> vAdmin;
  389.     std::vector<std::string> vHost;
  390.  
  391.     __GetHostInfo(vHost);
  392.     __GetAdminInfo(p->szIP, vAdmin);
  393.  
  394.     sys_log(0, "QUERY_BOOT : AdminInfo (Request ServerIp %s) ", p->szIP);
  395.  
  396.     DWORD dwPacketSize =
  397.         sizeof(DWORD) +
  398.         sizeof(BYTE) +
  399.         sizeof(WORD) + sizeof(WORD) + sizeof(TMobTable) * m_vec_mobTable.size() +
  400.         sizeof(WORD) + sizeof(WORD) + sizeof(TItemTable) * m_vec_itemTable.size() +
  401.         sizeof(WORD) + sizeof(WORD) + sizeof(TShopTable) * m_iShopTableSize +
  402.         sizeof(WORD) + sizeof(WORD) + sizeof(TSkillTable) * m_vec_skillTable.size() +
  403.         sizeof(WORD) + sizeof(WORD) + sizeof(TRefineTable) * m_iRefineTableSize +
  404.         sizeof(WORD) + sizeof(WORD) + sizeof(TItemAttrTable) * m_vec_itemAttrTable.size() +
  405.         sizeof(WORD) + sizeof(WORD) + sizeof(TItemAttrTable) * m_vec_itemRareTable.size() +
  406.         sizeof(WORD) + sizeof(WORD) + sizeof(TBanwordTable) * m_vec_banwordTable.size() +
  407.         sizeof(WORD) + sizeof(WORD) + sizeof(building::TLand) * m_vec_kLandTable.size() +
  408.         sizeof(WORD) + sizeof(WORD) + sizeof(building::TObjectProto) * m_vec_kObjectProto.size() +
  409.         sizeof(WORD) + sizeof(WORD) + sizeof(building::TObject) * m_map_pkObjectTable.size() +
  410. #ifdef __AUCTION__
  411.         sizeof(WORD) + sizeof(WORD) + sizeof(TPlayerItem) * AuctionManager::instance().GetAuctionItemSize() +
  412.         sizeof(WORD) + sizeof(WORD) + sizeof(TAuctionItemInfo) * AuctionManager::instance().GetAuctionSize() +
  413.         sizeof(WORD) + sizeof(WORD) + sizeof(TSaleItemInfo) * AuctionManager::instance().GetSaleSize() +
  414.         sizeof(WORD) + sizeof(WORD) + sizeof(TWishItemInfo) * AuctionManager::instance().GetWishSize() +
  415.         sizeof(WORD) + sizeof(WORD) + (sizeof(DWORD) + sizeof(DWORD) + sizeof(int)) * AuctionManager::instance().GetMyBidSize() +
  416. #endif
  417.         sizeof(time_t) +
  418.         sizeof(WORD) + sizeof(WORD) + sizeof(TItemIDRangeTable)*2 +
  419.         //ADMIN_MANAGER
  420.         sizeof(WORD) + sizeof(WORD) + 16 * vHost.size() +
  421.         sizeof(WORD) + sizeof(WORD) +  sizeof(tAdminInfo) *  vAdmin.size() +
  422.         //END_ADMIN_MANAGER
  423.         sizeof(WORD) + sizeof(WORD) + sizeof(TMonarchInfo) +
  424.         sizeof(WORD) + sizeof(WORD) + sizeof(MonarchCandidacy)* CMonarch::instance().MonarchCandidacySize() +
  425.         sizeof(WORD);
  426.  
  427.     peer->EncodeHeader(HEADER_DG_BOOT, 0, dwPacketSize);
  428.     peer->Encode(&dwPacketSize, sizeof(DWORD));
  429.     peer->Encode(&bPacketVersion, sizeof(BYTE));
  430.  
  431.     sys_log(0, "BOOT: PACKET: %d", dwPacketSize);
  432.     sys_log(0, "BOOT: VERSION: %d", bPacketVersion);
  433.  
  434.     sys_log(0, "sizeof(TMobTable) = %d", sizeof(TMobTable));
  435.     sys_log(0, "sizeof(TItemTable) = %d", sizeof(TItemTable));
  436.     sys_log(0, "sizeof(TShopTable) = %d", sizeof(TShopTable));
  437.     sys_log(0, "sizeof(TSkillTable) = %d", sizeof(TSkillTable));
  438.     sys_log(0, "sizeof(TRefineTable) = %d", sizeof(TRefineTable));
  439.     sys_log(0, "sizeof(TItemAttrTable) = %d", sizeof(TItemAttrTable));
  440.     sys_log(0, "sizeof(TItemRareTable) = %d", sizeof(TItemAttrTable));
  441.     sys_log(0, "sizeof(TBanwordTable) = %d", sizeof(TBanwordTable));
  442.     sys_log(0, "sizeof(TLand) = %d", sizeof(building::TLand));
  443.     sys_log(0, "sizeof(TObjectProto) = %d", sizeof(building::TObjectProto));
  444.     sys_log(0, "sizeof(TObject) = %d", sizeof(building::TObject));
  445.     //ADMIN_MANAGER
  446.     sys_log(0, "sizeof(tAdminInfo) = %d * %d ", sizeof(tAdminInfo) * vAdmin.size());
  447.     //END_ADMIN_MANAGER
  448.     sys_log(0, "sizeof(TMonarchInfo) = %d * %d", sizeof(TMonarchInfo));
  449.  
  450.     peer->EncodeWORD(sizeof(TMobTable));
  451.     peer->EncodeWORD(m_vec_mobTable.size());
  452.     peer->Encode(&m_vec_mobTable[0], sizeof(TMobTable) * m_vec_mobTable.size());
  453.  
  454.     peer->EncodeWORD(sizeof(TItemTable));
  455.     peer->EncodeWORD(m_vec_itemTable.size());
  456.     peer->Encode(&m_vec_itemTable[0], sizeof(TItemTable) * m_vec_itemTable.size());
  457.  
  458.     peer->EncodeWORD(sizeof(TShopTable));
  459.     peer->EncodeWORD(m_iShopTableSize);
  460.     peer->Encode(m_pShopTable, sizeof(TShopTable) * m_iShopTableSize);
  461.  
  462.     peer->EncodeWORD(sizeof(TSkillTable));
  463.     peer->EncodeWORD(m_vec_skillTable.size());
  464.     peer->Encode(&m_vec_skillTable[0], sizeof(TSkillTable) * m_vec_skillTable.size());
  465.  
  466.     peer->EncodeWORD(sizeof(TRefineTable));
  467.     peer->EncodeWORD(m_iRefineTableSize);
  468.     peer->Encode(m_pRefineTable, sizeof(TRefineTable) * m_iRefineTableSize);
  469.  
  470.     peer->EncodeWORD(sizeof(TItemAttrTable));
  471.     peer->EncodeWORD(m_vec_itemAttrTable.size());
  472.     peer->Encode(&m_vec_itemAttrTable[0], sizeof(TItemAttrTable) * m_vec_itemAttrTable.size());
  473.  
  474.     peer->EncodeWORD(sizeof(TItemAttrTable));
  475.     peer->EncodeWORD(m_vec_itemRareTable.size());
  476.     peer->Encode(&m_vec_itemRareTable[0], sizeof(TItemAttrTable) * m_vec_itemRareTable.size());
  477.  
  478.     peer->EncodeWORD(sizeof(TBanwordTable));
  479.     peer->EncodeWORD(m_vec_banwordTable.size());
  480.     peer->Encode(&m_vec_banwordTable[0], sizeof(TBanwordTable) * m_vec_banwordTable.size());
  481.  
  482.     peer->EncodeWORD(sizeof(building::TLand));
  483.     peer->EncodeWORD(m_vec_kLandTable.size());
  484.     peer->Encode(&m_vec_kLandTable[0], sizeof(building::TLand) * m_vec_kLandTable.size());
  485.  
  486.     peer->EncodeWORD(sizeof(building::TObjectProto));
  487.     peer->EncodeWORD(m_vec_kObjectProto.size());
  488.     peer->Encode(&m_vec_kObjectProto[0], sizeof(building::TObjectProto) * m_vec_kObjectProto.size());
  489.  
  490.     peer->EncodeWORD(sizeof(building::TObject));
  491.     peer->EncodeWORD(m_map_pkObjectTable.size());
  492.  
  493.     itertype(m_map_pkObjectTable) it = m_map_pkObjectTable.begin();
  494.  
  495.     while (it != m_map_pkObjectTable.end())
  496.         peer->Encode((it++)->second, sizeof(building::TObject));
  497.  
  498.     // Auction Boot
  499. #ifdef __AUCTION__
  500.     AuctionManager::instance().Boot (peer);
  501. #endif
  502.     time_t now = time(0);
  503.     peer->Encode(&now, sizeof(time_t));
  504.  
  505.     TItemIDRangeTable itemRange = CItemIDRangeManager::instance().GetRange();
  506.     TItemIDRangeTable itemRangeSpare = CItemIDRangeManager::instance().GetRange();
  507.  
  508.     peer->EncodeWORD(sizeof(TItemIDRangeTable));
  509.     peer->EncodeWORD(1);
  510.     peer->Encode(&itemRange, sizeof(TItemIDRangeTable));
  511.     peer->Encode(&itemRangeSpare, sizeof(TItemIDRangeTable));
  512.  
  513.     peer->SetItemIDRange(itemRange);
  514.     peer->SetSpareItemIDRange(itemRangeSpare);
  515.  
  516.     //ADMIN_MANAGER
  517.     peer->EncodeWORD(16);
  518.     peer->EncodeWORD(vHost.size());
  519.  
  520.     for (size_t n = 0; n < vHost.size(); ++n)
  521.     {
  522.         peer->Encode(vHost[n].c_str(), 16);
  523.         sys_log(0, "GMHosts %s", vHost[n].c_str());
  524.     }
  525.  
  526.     peer->EncodeWORD(sizeof(tAdminInfo));
  527.     peer->EncodeWORD(vAdmin.size());
  528.  
  529.     for (size_t n = 0; n < vAdmin.size(); ++n)
  530.     {
  531.         peer->Encode(&vAdmin[n], sizeof(tAdminInfo));
  532.         sys_log(0, "Admin name %s ConntactIP %s", vAdmin[n].m_szName, vAdmin[n].m_szContactIP);
  533.     }
  534.     //END_ADMIN_MANAGER
  535.  
  536.     //MONARCH
  537.     peer->EncodeWORD(sizeof(TMonarchInfo));
  538.     peer->EncodeWORD(1);
  539.     peer->Encode(CMonarch::instance().GetMonarch(), sizeof(TMonarchInfo));
  540.  
  541.     CMonarch::VEC_MONARCHCANDIDACY & rVecMonarchCandidacy = CMonarch::instance().GetVecMonarchCandidacy();
  542.  
  543.     size_t num_monarch_candidacy = CMonarch::instance().MonarchCandidacySize();
  544.     peer->EncodeWORD(sizeof(MonarchCandidacy));
  545.     peer->EncodeWORD(num_monarch_candidacy);
  546.     if (num_monarch_candidacy != 0) {
  547.         peer->Encode(&rVecMonarchCandidacy[0], sizeof(MonarchCandidacy) * num_monarch_candidacy);
  548.     }
  549.     //END_MONARCE
  550.  
  551.     if (g_test_server)
  552.         sys_log(0, "MONARCHCandidacy Size %d", CMonarch::instance().MonarchCandidacySize());
  553.  
  554.     peer->EncodeWORD(0xffff);
  555. #ifdef __ENABLE_NEW_OFFLINESHOP__
  556.     SendOfflineshopTable(peer);
  557. #endif
  558.  
  559. }
  560.  
  561. void CClientManager::SendPartyOnSetup(CPeer* pkPeer)
  562. {
  563.     TPartyMap & pm = m_map_pkChannelParty[pkPeer->GetChannel()];
  564.  
  565.     for (itertype(pm) it_party = pm.begin(); it_party != pm.end(); ++it_party)
  566.     {
  567.         sys_log(0, "PARTY SendPartyOnSetup Party [%u]", it_party->first);
  568.         pkPeer->EncodeHeader(HEADER_DG_PARTY_CREATE, 0, sizeof(TPacketPartyCreate));
  569.         pkPeer->Encode(&it_party->first, sizeof(DWORD));
  570.  
  571.         for (itertype(it_party->second) it_member = it_party->second.begin(); it_member != it_party->second.end(); ++it_member)
  572.         {
  573.             sys_log(0, "PARTY SendPartyOnSetup Party [%u] Member [%u]", it_party->first, it_member->first);
  574.             pkPeer->EncodeHeader(HEADER_DG_PARTY_ADD, 0, sizeof(TPacketPartyAdd));
  575.             pkPeer->Encode(&it_party->first, sizeof(DWORD));
  576.             pkPeer->Encode(&it_member->first, sizeof(DWORD));
  577.             pkPeer->Encode(&it_member->second.bRole, sizeof(BYTE));
  578.  
  579.             pkPeer->EncodeHeader(HEADER_DG_PARTY_SET_MEMBER_LEVEL, 0, sizeof(TPacketPartySetMemberLevel));
  580.             pkPeer->Encode(&it_party->first, sizeof(DWORD));
  581.             pkPeer->Encode(&it_member->first, sizeof(DWORD));
  582.             pkPeer->Encode(&it_member->second.bLevel, sizeof(BYTE));
  583.         }
  584.     }
  585. }
  586.  
  587. void CClientManager::QUERY_PLAYER_COUNT(CPeer * pkPeer, TPlayerCountPacket * pPacket)
  588. {
  589.     pkPeer->SetUserCount(pPacket->dwCount);
  590. }
  591.  
  592. void CClientManager::QUERY_QUEST_SAVE(CPeer * pkPeer, TQuestTable * pTable, DWORD dwLen)
  593. {
  594.     if (0 != (dwLen % sizeof(TQuestTable)))
  595.     {
  596.         sys_err("invalid packet size %d, sizeof(TQuestTable) == %d", dwLen, sizeof(TQuestTable));
  597.         return;
  598.     }
  599.  
  600.     int iSize = dwLen / sizeof(TQuestTable);
  601.  
  602.     char szQuery[1024];
  603.  
  604.     for (int i = 0; i < iSize; ++i, ++pTable)
  605.     {
  606.         if (pTable->lValue == 0)
  607.         {
  608.             snprintf(szQuery, sizeof(szQuery),
  609.                     "DELETE FROM quest%s WHERE dwPID=%d AND szName='%s' AND szState='%s'",
  610.                     GetTablePostfix(), pTable->dwPID, pTable->szName, pTable->szState);
  611.         }
  612.         else
  613.         {
  614.             snprintf(szQuery, sizeof(szQuery),
  615.                     "REPLACE INTO quest%s (dwPID, szName, szState, lValue) VALUES(%d, '%s', '%s', %ld)",
  616.                     GetTablePostfix(), pTable->dwPID, pTable->szName, pTable->szState, pTable->lValue);
  617.         }
  618.  
  619.         CDBManager::instance().ReturnQuery(szQuery, QID_QUEST_SAVE, pkPeer->GetHandle(), NULL);
  620.     }
  621. }
  622.  
  623. void CClientManager::QUERY_SAFEBOX_LOAD(CPeer * pkPeer, DWORD dwHandle, TSafeboxLoadPacket * packet, bool bMall)
  624. {
  625.     ClientHandleInfo * pi = new ClientHandleInfo(dwHandle);
  626.     strlcpy(pi->safebox_password, packet->szPassword, sizeof(pi->safebox_password));
  627.     pi->account_id = packet->dwID;
  628.     pi->account_index = 0;
  629.     pi->ip[0] = bMall ? 1 : 0;
  630.     strlcpy(pi->login, packet->szLogin, sizeof(pi->login));
  631.  
  632.     char szQuery[QUERY_MAX_LEN];
  633.     snprintf(szQuery, sizeof(szQuery),
  634.             "SELECT account_id, size, password FROM safebox%s WHERE account_id=%u",
  635.             GetTablePostfix(), packet->dwID);
  636.  
  637.     if (g_log)
  638.         sys_log(0, "HEADER_GD_SAFEBOX_LOAD (handle: %d account.id %u is_mall %d)", dwHandle, packet->dwID, bMall ? 1 : 0);
  639.  
  640.     CDBManager::instance().ReturnQuery(szQuery, QID_SAFEBOX_LOAD, pkPeer->GetHandle(), pi);
  641. }
  642.  
  643. void CClientManager::RESULT_SAFEBOX_LOAD(CPeer * pkPeer, SQLMsg * msg)
  644. {
  645.     CQueryInfo * qi = (CQueryInfo *) msg->pvUserData;
  646.     ClientHandleInfo * pi = (ClientHandleInfo *) qi->pvData;
  647.     DWORD dwHandle = pi->dwHandle;
  648.  
  649.     if (pi->account_index == 0)
  650.     {
  651.         char szSafeboxPassword[SAFEBOX_PASSWORD_MAX_LEN + 1];
  652.         strlcpy(szSafeboxPassword, pi->safebox_password, sizeof(szSafeboxPassword));
  653.  
  654.         TSafeboxTable * pSafebox = new TSafeboxTable;
  655.         memset(pSafebox, 0, sizeof(TSafeboxTable));
  656.  
  657.         SQLResult * res = msg->Get();
  658.  
  659.         if (res->uiNumRows == 0)
  660.         {
  661.             if (strcmp("000000", szSafeboxPassword))
  662.             {
  663.                 pkPeer->EncodeHeader(HEADER_DG_SAFEBOX_WRONG_PASSWORD, dwHandle, 0);
  664.                 delete pi;
  665.                 return;
  666.             }
  667.         }
  668.         else
  669.         {
  670.             MYSQL_ROW row = mysql_fetch_row(res->pSQLResult);
  671.  
  672.             // şńąĐąřČŁ°ˇ Ʋ¸®¸é..
  673.             if (((!row[2] || !*row[2]) && strcmp("000000", szSafeboxPassword)) ||
  674.                 ((row[2] && *row[2]) && strcmp(row[2], szSafeboxPassword)))
  675.             {
  676.                 pkPeer->EncodeHeader(HEADER_DG_SAFEBOX_WRONG_PASSWORD, dwHandle, 0);
  677.                 delete pi;
  678.                 return;
  679.             }
  680.  
  681.             if (!row[0])
  682.                 pSafebox->dwID = 0;
  683.             else
  684.                 str_to_number(pSafebox->dwID, row[0]);
  685.  
  686.             if (!row[1])
  687.                 pSafebox->bSize = 0;
  688.             else
  689.                 str_to_number(pSafebox->bSize, row[1]);
  690.             /*
  691.                if (!row[3])
  692.                pSafebox->dwGold = 0;
  693.                else
  694.                pSafebox->dwGold = atoi(row[3]);
  695.                */
  696.             if (pi->ip[0] == 1)
  697.             {
  698.                 pSafebox->bSize = 1;
  699.                 sys_log(0, "MALL id[%d] size[%d]", pSafebox->dwID, pSafebox->bSize);
  700.             }
  701.             else
  702.                 sys_log(0, "SAFEBOX id[%d] size[%d]", pSafebox->dwID, pSafebox->bSize);
  703.         }
  704.  
  705.         if (0 == pSafebox->dwID)
  706.             pSafebox->dwID = pi->account_id;
  707.  
  708.         pi->pSafebox = pSafebox;
  709.  
  710.         char szQuery[512];
  711.         snprintf(szQuery, sizeof(szQuery),
  712.                 "SELECT id, window+0, pos, count, vnum, "
  713. #ifdef __ITEM_SOCKET5__
  714.                 "socket0, socket1, socket2, socket3, socket4, socket5, "
  715. #else
  716.                 "socket0, socket1, socket2, "
  717. #endif
  718.                 "attrtype0, attrvalue0, "
  719.                 "attrtype1, attrvalue1, "
  720.                 "attrtype2, attrvalue2, "
  721.                 "attrtype3, attrvalue3, "
  722.                 "attrtype4, attrvalue4, "
  723.                 "attrtype5, attrvalue5, "
  724.                 "attrtype6, attrvalue6 "
  725.                 "FROM item%s WHERE owner_id=%d AND window='%s'",
  726.                 GetTablePostfix(), pi->account_id, pi->ip[0] == 0 ? "SAFEBOX" : "MALL");
  727.  
  728.         pi->account_index = 1;
  729.  
  730.         CDBManager::instance().ReturnQuery(szQuery, QID_SAFEBOX_LOAD, pkPeer->GetHandle(), pi);
  731.     }
  732.     else
  733.     {
  734.  
  735.         if (!pi->pSafebox)
  736.         {
  737.             sys_err("null safebox pointer!");
  738.             delete pi;
  739.             return;
  740.         }
  741.  
  742.  
  743.         // Äő¸®żˇ żˇ·Ż°ˇ ŔÖľúŔ¸ąÇ·Î ŔŔ´äÇŇ °ćżě â°í°ˇ şńľîŔÖ´Â °Í Ăł·ł
  744.         // ş¸Ṟ́⠶§ą®żˇ â°í°ˇ ľĆľę ľČż­¸®´Â°Ô łŞŔ˝
  745.         if (!msg->Get()->pSQLResult)
  746.         {
  747.             sys_err("null safebox result");
  748.             delete pi;
  749.             return;
  750.         }
  751.  
  752.         static std::vector<TPlayerItem> s_items;
  753.         CreateItemTableFromRes(msg->Get()->pSQLResult, &s_items, pi->account_id);
  754.  
  755.         std::set<TItemAward *> * pSet = ItemAwardManager::instance().GetByLogin(pi->login);
  756.  
  757.         if (pSet && !m_vec_itemTable.empty())
  758.         {
  759.  
  760.             CGrid grid(5, MAX(1, pi->pSafebox->bSize) * 9);
  761.             bool bEscape = false;
  762.  
  763.             for (DWORD i = 0; i < s_items.size(); ++i)
  764.             {
  765.                 TPlayerItem & r = s_items[i];
  766.  
  767.                 itertype(m_map_itemTableByVnum) it = m_map_itemTableByVnum.find(r.vnum);
  768.  
  769.                 if (it == m_map_itemTableByVnum.end())
  770.                 {
  771.                     bEscape = true;
  772.                     sys_err("invalid item vnum %u in safebox: login %s", r.vnum, pi->login);
  773.                     break;
  774.                 }
  775.  
  776.                 grid.Put(r.pos, 1, it->second->bSize);
  777.             }
  778.  
  779.             if (!bEscape)
  780.             {
  781.                 std::vector<std::pair<DWORD, DWORD> > vec_dwFinishedAwardID;
  782.  
  783.                 typeof(pSet->begin()) it = pSet->begin();
  784.  
  785.                 char szQuery[512];
  786.  
  787.                 while (it != pSet->end())
  788.                 {
  789.                     TItemAward * pItemAward = *(it++);
  790.                     const DWORD& dwItemVnum = pItemAward->dwVnum;
  791.  
  792.                     if (pItemAward->bTaken)
  793.                         continue;
  794.  
  795.                     if (pi->ip[0] == 0 && pItemAward->bMall)
  796.                         continue;
  797.  
  798.                     if (pi->ip[0] == 1 && !pItemAward->bMall)
  799.                         continue;
  800.  
  801.                     itertype(m_map_itemTableByVnum) it = m_map_itemTableByVnum.find(pItemAward->dwVnum);
  802.  
  803.                     if (it == m_map_itemTableByVnum.end())
  804.                     {
  805.                         sys_err("invalid item vnum %u in item_award: login %s", pItemAward->dwVnum, pi->login);
  806.                         continue;
  807.                     }
  808.  
  809.                     TItemTable * pItemTable = it->second;
  810.  
  811.                     int iPos;
  812.  
  813.                     if ((iPos = grid.FindBlank(1, it->second->bSize)) == -1)
  814.                         break;
  815.  
  816.                     TPlayerItem item;
  817.                     memset(&item, 0, sizeof(TPlayerItem));
  818.  
  819.                     DWORD dwSocket2 = 0;
  820.  
  821.                     if (pItemTable->bType == ITEM_UNIQUE)
  822.                     {
  823.                         if (pItemAward->dwSocket2 != 0)
  824.                             dwSocket2 = pItemAward->dwSocket2;
  825.                         else
  826.                             dwSocket2 = pItemTable->alValues[0];
  827.                     }
  828.                     else if ((dwItemVnum == 50300 || dwItemVnum == 70037) && pItemAward->dwSocket0 == 0)
  829.                     {
  830.                         DWORD dwSkillIdx;
  831.                         DWORD dwSkillVnum;
  832.  
  833.                         do
  834.                         {
  835.                             dwSkillIdx = number(0, m_vec_skillTable.size()-1);
  836.  
  837.                             dwSkillVnum = m_vec_skillTable[dwSkillIdx].dwVnum;
  838.  
  839.                             break;
  840.                         } while (1);
  841.  
  842.                         pItemAward->dwSocket0 = dwSkillVnum;
  843.                     }
  844.                     else
  845.                     {
  846.                         switch (dwItemVnum)
  847.                         {
  848.                             case 72723: case 72724: case 72725: case 72726:
  849.                             case 72727: case 72728: case 72729: case 72730:
  850.                             // ą«˝Ăą«˝ĂÇĎÁö¸¸ ŔĚŔüżˇ ÇĎ´ř °É °íġ±â´Â ą«Ľ·°í...
  851.                             // ±×·ˇĽ­ ±×łÉ Çϵĺ ÄÚµů. Ľ±ą° »óŔÚżë ŔÚµżą°ľŕ ľĆŔĚĹ۵é.
  852.                             case 76004: case 76005: case 76021: case 76022:
  853.                             case 79012: case 79013:
  854.                                 if (pItemAward->dwSocket2 == 0)
  855.                                 {
  856.                                     dwSocket2 = pItemTable->alValues[0];
  857.                                 }
  858.                                 else
  859.                                 {
  860.                                     dwSocket2 = pItemAward->dwSocket2;
  861.                                 }
  862.                                 break;
  863.                         }
  864.                     }
  865.  
  866.                     if (GetItemID () > m_itemRange.dwMax)
  867.                     {
  868.                         sys_err("UNIQUE ID OVERFLOW!!");
  869.                         break;
  870.                     }
  871.  
  872.                     {
  873.                         itertype(m_map_itemTableByVnum) it = m_map_itemTableByVnum.find (dwItemVnum);
  874.                         if (it == m_map_itemTableByVnum.end())
  875.                         {
  876.                             sys_err ("Invalid item(vnum : %d). It is not in m_map_itemTableByVnum.", dwItemVnum);
  877.                             continue;
  878.                         }
  879.                         TItemTable* item_table = it->second;
  880.                         if (item_table == NULL)
  881.                         {
  882.                             sys_err ("Invalid item_table (vnum : %d). It's value is NULL in m_map_itemTableByVnum.", dwItemVnum);
  883.                             continue;
  884.                         }
  885.                         if (0 == pItemAward->dwSocket0)
  886.                         {
  887.                             for (int i = 0; i < ITEM_LIMIT_MAX_NUM; i++)
  888.                             {
  889.                                 if (LIMIT_REAL_TIME == item_table->aLimits[i].bType)
  890.                                 {
  891.                                     if (0 == item_table->aLimits[i].lValue)
  892.                                         pItemAward->dwSocket0 = time(0) + 60 * 60 * 24 * 7;
  893.                                     else
  894.                                         pItemAward->dwSocket0 = time(0) + item_table->aLimits[i].lValue;
  895.  
  896.                                     break;
  897.                                 }
  898.                                 else if (LIMIT_REAL_TIME_START_FIRST_USE == item_table->aLimits[i].bType || LIMIT_TIMER_BASED_ON_WEAR == item_table->aLimits[i].bType)
  899.                                 {
  900.                                     if (0 == item_table->aLimits[i].lValue)
  901.                                         pItemAward->dwSocket0 = 60 * 60 * 24 * 7;
  902.                                     else
  903.                                         pItemAward->dwSocket0 = item_table->aLimits[i].lValue;
  904.  
  905.                                     break;
  906.                                 }
  907.                             }
  908.                         }
  909.  
  910.                         snprintf(szQuery, sizeof(szQuery),
  911.                                 "INSERT INTO item%s (id, owner_id, window, pos, vnum, count, socket0, socket1, socket2) "
  912.                                 "VALUES(%u, %u, '%s', %d, %u, %u, %u, %u, %u)",
  913.                                 GetTablePostfix(),
  914.                                 GainItemID(),
  915.                                 pi->account_id,
  916.                                 pi->ip[0] == 0 ? "SAFEBOX" : "MALL",
  917.                                 iPos,
  918.                                 pItemAward->dwVnum, pItemAward->dwCount, pItemAward->dwSocket0, pItemAward->dwSocket1, dwSocket2);
  919.                     }
  920.  
  921.                     std::auto_ptr<SQLMsg> pmsg(CDBManager::instance().DirectQuery(szQuery));
  922.                     SQLResult * pRes = pmsg->Get();
  923.                     sys_log(0, "SAFEBOX Query : [%s]", szQuery);
  924.  
  925.                     if (pRes->uiAffectedRows == 0 || pRes->uiInsertID == 0 || pRes->uiAffectedRows == (uint32_t)-1)
  926.                         break;
  927.  
  928.                     item.id = pmsg->Get()->uiInsertID;
  929.                     item.window = pi->ip[0] == 0 ? SAFEBOX : MALL,
  930.                     item.pos = iPos;
  931.                     item.count = pItemAward->dwCount;
  932.                     item.vnum = pItemAward->dwVnum;
  933.                     item.alSockets[0] = pItemAward->dwSocket0;
  934.                     item.alSockets[1] = pItemAward->dwSocket1;
  935.                     item.alSockets[2] = dwSocket2;
  936.                     s_items.push_back(item);
  937.  
  938.                     vec_dwFinishedAwardID.push_back(std::make_pair(pItemAward->dwID, item.id));
  939.                     grid.Put(iPos, 1, it->second->bSize);
  940.                 }
  941.  
  942.                 for (DWORD i = 0; i < vec_dwFinishedAwardID.size(); ++i)
  943.                     ItemAwardManager::instance().Taken(vec_dwFinishedAwardID[i].first, vec_dwFinishedAwardID[i].second);
  944.             }
  945.         }
  946.  
  947.         pi->pSafebox->wItemCount = s_items.size();
  948.  
  949.         pkPeer->EncodeHeader(pi->ip[0] == 0 ? HEADER_DG_SAFEBOX_LOAD : HEADER_DG_MALL_LOAD, dwHandle, sizeof(TSafeboxTable) + sizeof(TPlayerItem) * s_items.size());
  950.  
  951.         pkPeer->Encode(pi->pSafebox, sizeof(TSafeboxTable));
  952.  
  953.         if (!s_items.empty())
  954.             pkPeer->Encode(&s_items[0], sizeof(TPlayerItem) * s_items.size());
  955.  
  956.         delete pi;
  957.     }
  958. }
  959.  
  960. void CClientManager::QUERY_SAFEBOX_CHANGE_SIZE(CPeer * pkPeer, DWORD dwHandle, TSafeboxChangeSizePacket * p)
  961. {
  962.     ClientHandleInfo * pi = new ClientHandleInfo(dwHandle);
  963.     pi->account_index = p->bSize;   // account_index¸¦ »çŔĚÁî·Î Ŕӽ÷Π»çżë
  964.  
  965.     char szQuery[QUERY_MAX_LEN];
  966.  
  967.     if (p->bSize == 1)
  968.         snprintf(szQuery, sizeof(szQuery), "INSERT INTO safebox%s (account_id, size) VALUES(%u, %u)", GetTablePostfix(), p->dwID, p->bSize);
  969.     else
  970.         snprintf(szQuery, sizeof(szQuery), "UPDATE safebox%s SET size=%u WHERE account_id=%u", GetTablePostfix(), p->bSize, p->dwID);
  971.  
  972.     CDBManager::instance().ReturnQuery(szQuery, QID_SAFEBOX_CHANGE_SIZE, pkPeer->GetHandle(), pi);
  973. }
  974.  
  975. void CClientManager::RESULT_SAFEBOX_CHANGE_SIZE(CPeer * pkPeer, SQLMsg * msg)
  976. {
  977.     CQueryInfo * qi = (CQueryInfo *) msg->pvUserData;
  978.     ClientHandleInfo * p = (ClientHandleInfo *) qi->pvData;
  979.     DWORD dwHandle = p->dwHandle;
  980.     BYTE bSize = p->account_index;
  981.  
  982.     delete p;
  983.  
  984.     if (msg->Get()->uiNumRows > 0)
  985.     {
  986.         pkPeer->EncodeHeader(HEADER_DG_SAFEBOX_CHANGE_SIZE, dwHandle, sizeof(BYTE));
  987.         pkPeer->EncodeBYTE(bSize);
  988.     }
  989. }
  990.  
  991. void CClientManager::QUERY_SAFEBOX_CHANGE_PASSWORD(CPeer * pkPeer, DWORD dwHandle, TSafeboxChangePasswordPacket * p)
  992. {
  993.     ClientHandleInfo * pi = new ClientHandleInfo(dwHandle);
  994.     strlcpy(pi->safebox_password, p->szNewPassword, sizeof(pi->safebox_password));
  995.     strlcpy(pi->login, p->szOldPassword, sizeof(pi->login));
  996.     pi->account_id = p->dwID;
  997.  
  998.     char szQuery[QUERY_MAX_LEN];
  999.     snprintf(szQuery, sizeof(szQuery), "SELECT password FROM safebox%s WHERE account_id=%u", GetTablePostfix(), p->dwID);
  1000.  
  1001.     CDBManager::instance().ReturnQuery(szQuery, QID_SAFEBOX_CHANGE_PASSWORD, pkPeer->GetHandle(), pi);
  1002. }
  1003.  
  1004. void CClientManager::RESULT_SAFEBOX_CHANGE_PASSWORD(CPeer * pkPeer, SQLMsg * msg)
  1005. {
  1006.     CQueryInfo * qi = (CQueryInfo *) msg->pvUserData;
  1007.     ClientHandleInfo * p = (ClientHandleInfo *) qi->pvData;
  1008.     DWORD dwHandle = p->dwHandle;
  1009.  
  1010.     if (msg->Get()->uiNumRows > 0)
  1011.     {
  1012.         MYSQL_ROW row = mysql_fetch_row(msg->Get()->pSQLResult);
  1013.  
  1014.         if ((row[0] && *row[0] && !strcasecmp(row[0], p->login)) || ((!row[0] || !*row[0]) && !strcmp("000000", p->login)))
  1015.         {
  1016.             char szQuery[QUERY_MAX_LEN];
  1017.             char escape_pwd[64];
  1018.             CDBManager::instance().EscapeString(escape_pwd, p->safebox_password, strlen(p->safebox_password));
  1019.  
  1020.             snprintf(szQuery, sizeof(szQuery), "UPDATE safebox%s SET password='%s' WHERE account_id=%u", GetTablePostfix(), escape_pwd, p->account_id);
  1021.  
  1022.             CDBManager::instance().ReturnQuery(szQuery, QID_SAFEBOX_CHANGE_PASSWORD_SECOND, pkPeer->GetHandle(), p);
  1023.             return;
  1024.         }
  1025.     }
  1026.  
  1027.     delete p;
  1028.  
  1029.     // Wrong old password
  1030.     pkPeer->EncodeHeader(HEADER_DG_SAFEBOX_CHANGE_PASSWORD_ANSWER, dwHandle, sizeof(BYTE));
  1031.     pkPeer->EncodeBYTE(0);
  1032. }
  1033.  
  1034. void CClientManager::RESULT_SAFEBOX_CHANGE_PASSWORD_SECOND(CPeer * pkPeer, SQLMsg * msg)
  1035. {
  1036.     CQueryInfo * qi = (CQueryInfo *) msg->pvUserData;
  1037.     ClientHandleInfo * p = (ClientHandleInfo *) qi->pvData;
  1038.     DWORD dwHandle = p->dwHandle;
  1039.     delete p;
  1040.  
  1041.     pkPeer->EncodeHeader(HEADER_DG_SAFEBOX_CHANGE_PASSWORD_ANSWER, dwHandle, sizeof(BYTE));
  1042.     pkPeer->EncodeBYTE(1);
  1043. }
  1044.  
  1045. // MYSHOP_PRICE_LIST
  1046. void CClientManager::RESULT_PRICELIST_LOAD(CPeer* peer, SQLMsg* pMsg)
  1047. {
  1048.     TItemPricelistReqInfo* pReqInfo = (TItemPricelistReqInfo*)static_cast<CQueryInfo*>(pMsg->pvUserData)->pvData;
  1049.  
  1050.     //
  1051.     // DB żˇĽ­ ·ÎµĺÇŃ Á¤ş¸¸¦ Cache żˇ ŔúŔĺ
  1052.     //
  1053.  
  1054.     TItemPriceListTable table;
  1055.     table.dwOwnerID = pReqInfo->second;
  1056.     table.byCount = 0;
  1057.  
  1058.     MYSQL_ROW row;
  1059.  
  1060.     while ((row = mysql_fetch_row(pMsg->Get()->pSQLResult)))
  1061.     {
  1062.         str_to_number(table.aPriceInfo[table.byCount].dwVnum, row[0]);
  1063.         str_to_number(table.aPriceInfo[table.byCount].dwPrice, row[1]);
  1064.         table.byCount++;
  1065.     }
  1066.  
  1067.     PutItemPriceListCache(&table);
  1068.  
  1069.     //
  1070.     // ·ÎµĺÇŃ µĄŔĚĹ͸¦ Game server żˇ ŔüĽŰ
  1071.     //
  1072.  
  1073.     TPacketMyshopPricelistHeader header;
  1074.  
  1075.     header.dwOwnerID = pReqInfo->second;
  1076.     header.byCount = table.byCount;
  1077.  
  1078.     size_t sizePriceListSize = sizeof(TItemPriceInfo) * header.byCount;
  1079.  
  1080.     peer->EncodeHeader(HEADER_DG_MYSHOP_PRICELIST_RES, pReqInfo->first, sizeof(header) + sizePriceListSize);
  1081.     peer->Encode(&header, sizeof(header));
  1082.     peer->Encode(table.aPriceInfo, sizePriceListSize);
  1083.  
  1084.     sys_log(0, "Load MyShopPricelist handle[%d] pid[%d] count[%d]", pReqInfo->first, pReqInfo->second, header.byCount);
  1085.  
  1086.     delete pReqInfo;
  1087. }
  1088.  
  1089. void CClientManager::RESULT_PRICELIST_LOAD_FOR_UPDATE(SQLMsg* pMsg)
  1090. {
  1091.     TItemPriceListTable* pUpdateTable = (TItemPriceListTable*)static_cast<CQueryInfo*>(pMsg->pvUserData)->pvData;
  1092.  
  1093.     //
  1094.     // DB żˇĽ­ ·ÎµĺÇŃ Á¤ş¸¸¦ Cache żˇ ŔúŔĺ
  1095.     //
  1096.  
  1097.     TItemPriceListTable table;
  1098.     table.dwOwnerID = pUpdateTable->dwOwnerID;
  1099.     table.byCount = 0;
  1100.  
  1101.     MYSQL_ROW row;
  1102.  
  1103.     while ((row = mysql_fetch_row(pMsg->Get()->pSQLResult)))
  1104.     {
  1105.         str_to_number(table.aPriceInfo[table.byCount].dwVnum, row[0]);
  1106.         str_to_number(table.aPriceInfo[table.byCount].dwPrice, row[1]);
  1107.         table.byCount++;
  1108.     }
  1109.  
  1110.     PutItemPriceListCache(&table);
  1111.  
  1112.     // Update cache
  1113.     GetItemPriceListCache(pUpdateTable->dwOwnerID)->UpdateList(pUpdateTable);
  1114.  
  1115.     delete pUpdateTable;
  1116. }
  1117. // END_OF_MYSHOP_PRICE_LIST
  1118.  
  1119. void CClientManager::QUERY_SAFEBOX_SAVE(CPeer * pkPeer, TSafeboxTable * pTable)
  1120. {
  1121.     char szQuery[QUERY_MAX_LEN];
  1122.  
  1123.     snprintf(szQuery, sizeof(szQuery),
  1124.             "UPDATE safebox%s SET gold='%u' WHERE account_id=%u",
  1125.             GetTablePostfix(), pTable->dwGold, pTable->dwID);
  1126.  
  1127.     CDBManager::instance().ReturnQuery(szQuery, QID_SAFEBOX_SAVE, pkPeer->GetHandle(), NULL);
  1128. }
  1129.  
  1130. void CClientManager::QUERY_EMPIRE_SELECT(CPeer * pkPeer, DWORD dwHandle, TEmpireSelectPacket * p)
  1131. {
  1132.     char szQuery[QUERY_MAX_LEN];
  1133.  
  1134.     snprintf(szQuery, sizeof(szQuery), "UPDATE player_index%s SET empire=%u WHERE id=%u", GetTablePostfix(), p->bEmpire, p->dwAccountID);
  1135.     delete CDBManager::instance().DirectQuery(szQuery);
  1136.  
  1137.     sys_log(0, "EmpireSelect: %s", szQuery);
  1138.     {
  1139. #ifdef ENABLE_PLAYER_PER_ACCOUNT5
  1140.         snprintf(szQuery, sizeof(szQuery),
  1141.                 "SELECT pid1, pid2, pid3, pid4, pid5 FROM player_index%s WHERE id=%u", GetTablePostfix(), p->dwAccountID);
  1142. #else
  1143.         snprintf(szQuery, sizeof(szQuery),
  1144.                 "SELECT pid1, pid2, pid3, pid4 FROM player_index%s WHERE id=%u", GetTablePostfix(), p->dwAccountID);
  1145. #endif
  1146.  
  1147.         std::auto_ptr<SQLMsg> pmsg(CDBManager::instance().DirectQuery(szQuery));
  1148.  
  1149.         SQLResult * pRes = pmsg->Get();
  1150.  
  1151.         if (pRes->uiNumRows)
  1152.         {
  1153.             sys_log(0, "EMPIRE %lu", pRes->uiNumRows);
  1154.  
  1155.             MYSQL_ROW row = mysql_fetch_row(pRes->pSQLResult);
  1156.             DWORD pids[3];
  1157.  
  1158.             UINT g_start_map[4] =
  1159.             {
  1160.                 0,  // reserved
  1161.                 1,  // ˝ĹĽö±ą
  1162.                 21, // õÁ¶±ą
  1163.                 41  // Ářłë±ą
  1164.             };
  1165.  
  1166.             // FIXME share with game
  1167.             DWORD g_start_position[4][2]=
  1168.             {
  1169.                 {      0,      0 },
  1170.                 { 469300, 964200 }, // ˝ĹĽö±ą
  1171.                 {  55700, 157900 }, // õÁ¶±ą
  1172.                 { 969600, 278400 }  // Ářłë±ą
  1173.             };
  1174.  
  1175.             for (int i = 0; i < 3; ++i)
  1176.             {
  1177.                 str_to_number(pids[i], row[i]);
  1178.                 sys_log(0, "EMPIRE PIDS[%d]", pids[i]);
  1179.  
  1180.                 if (pids[i])
  1181.                 {
  1182.                     sys_log(0, "EMPIRE move to pid[%d] to villiage of %u, map_index %d",
  1183.                             pids[i], p->bEmpire, g_start_map[p->bEmpire]);
  1184.  
  1185.                     snprintf(szQuery, sizeof(szQuery), "UPDATE player%s SET map_index=%u,x=%u,y=%u WHERE id=%u",
  1186.                             GetTablePostfix(),
  1187.                             g_start_map[p->bEmpire],
  1188.                             g_start_position[p->bEmpire][0],
  1189.                             g_start_position[p->bEmpire][1],
  1190.                             pids[i]);
  1191.  
  1192.                     std::auto_ptr<SQLMsg> pmsg2(CDBManager::instance().DirectQuery(szQuery));
  1193.                 }
  1194.             }
  1195.         }
  1196.     }
  1197.  
  1198.     pkPeer->EncodeHeader(HEADER_DG_EMPIRE_SELECT, dwHandle, sizeof(BYTE));
  1199.     pkPeer->EncodeBYTE(p->bEmpire);
  1200. }
  1201.  
  1202. void CClientManager::QUERY_SETUP(CPeer * peer, DWORD dwHandle, const char * c_pData)
  1203. {
  1204.     TPacketGDSetup * p = (TPacketGDSetup *) c_pData;
  1205.     c_pData += sizeof(TPacketGDSetup);
  1206.  
  1207.     if (p->bAuthServer)
  1208.     {
  1209.         sys_log(0, "AUTH_PEER ptr %p", peer);
  1210.  
  1211.         m_pkAuthPeer = peer;
  1212.         SendAllLoginToBilling();
  1213.         return;
  1214.     }
  1215.  
  1216.     peer->SetPublicIP(p->szPublicIP);
  1217.     peer->SetChannel(p->bChannel);
  1218.     peer->SetListenPort(p->wListenPort);
  1219.     peer->SetP2PPort(p->wP2PPort);
  1220.     peer->SetMaps(p->alMaps);
  1221.  
  1222.     //
  1223.     // ľî¶˛ ¸ĘŔĚ ľî¶˛ Ľ­ąöżˇ ŔÖ´ÂÁö ş¸ł»±â
  1224.     //
  1225.     TMapLocation kMapLocations;
  1226.  
  1227.     strlcpy(kMapLocations.szHost, peer->GetPublicIP(), sizeof(kMapLocations.szHost));
  1228.     kMapLocations.wPort = peer->GetListenPort();
  1229.     thecore_memcpy(kMapLocations.alMaps, peer->GetMaps(), sizeof(kMapLocations.alMaps));
  1230.  
  1231.     BYTE bMapCount;
  1232.  
  1233.     std::vector<TMapLocation> vec_kMapLocations;
  1234.  
  1235.     if (peer->GetChannel() == 1)
  1236.     {
  1237.         for (itertype(m_peerList) i = m_peerList.begin(); i != m_peerList.end(); ++i)
  1238.         {
  1239.             CPeer * tmp = *i;
  1240.  
  1241.             if (tmp == peer)
  1242.                 continue;
  1243.  
  1244.             if (!tmp->GetChannel())
  1245.                 continue;
  1246.  
  1247.             if (tmp->GetChannel() == GUILD_WARP_WAR_CHANNEL || tmp->GetChannel() == peer->GetChannel())
  1248.             {
  1249.                 TMapLocation kMapLocation2;
  1250.                 strlcpy(kMapLocation2.szHost, tmp->GetPublicIP(), sizeof(kMapLocation2.szHost));
  1251.                 kMapLocation2.wPort = tmp->GetListenPort();
  1252.                 thecore_memcpy(kMapLocation2.alMaps, tmp->GetMaps(), sizeof(kMapLocation2.alMaps));
  1253.                 vec_kMapLocations.push_back(kMapLocation2);
  1254.  
  1255.                 tmp->EncodeHeader(HEADER_DG_MAP_LOCATIONS, 0, sizeof(BYTE) + sizeof(TMapLocation));
  1256.                 bMapCount = 1;
  1257.                 tmp->EncodeBYTE(bMapCount);
  1258.                 tmp->Encode(&kMapLocations, sizeof(TMapLocation));
  1259.             }
  1260.         }
  1261.     }
  1262.     else if (peer->GetChannel() == GUILD_WARP_WAR_CHANNEL)
  1263.     {
  1264.         for (itertype(m_peerList) i = m_peerList.begin(); i != m_peerList.end(); ++i)
  1265.         {
  1266.             CPeer * tmp = *i;
  1267.  
  1268.             if (tmp == peer)
  1269.                 continue;
  1270.  
  1271.             if (!tmp->GetChannel())
  1272.                 continue;
  1273.  
  1274.             if (tmp->GetChannel() == 1 || tmp->GetChannel() == peer->GetChannel())
  1275.             {
  1276.                 TMapLocation kMapLocation2;
  1277.                 strlcpy(kMapLocation2.szHost, tmp->GetPublicIP(), sizeof(kMapLocation2.szHost));
  1278.                 kMapLocation2.wPort = tmp->GetListenPort();
  1279.                 thecore_memcpy(kMapLocation2.alMaps, tmp->GetMaps(), sizeof(kMapLocation2.alMaps));
  1280.                 vec_kMapLocations.push_back(kMapLocation2);
  1281.             }
  1282.  
  1283.             tmp->EncodeHeader(HEADER_DG_MAP_LOCATIONS, 0, sizeof(BYTE) + sizeof(TMapLocation));
  1284.             bMapCount = 1;
  1285.             tmp->EncodeBYTE(bMapCount);
  1286.             tmp->Encode(&kMapLocations, sizeof(TMapLocation));
  1287.         }
  1288.     }
  1289.     else
  1290.     {
  1291.         for (itertype(m_peerList) i = m_peerList.begin(); i != m_peerList.end(); ++i)
  1292.         {
  1293.             CPeer * tmp = *i;
  1294.  
  1295.             if (tmp == peer)
  1296.                 continue;
  1297.  
  1298.             if (!tmp->GetChannel())
  1299.                 continue;
  1300.  
  1301.             if (tmp->GetChannel() == GUILD_WARP_WAR_CHANNEL || tmp->GetChannel() == peer->GetChannel())
  1302.             {
  1303.                 TMapLocation kMapLocation2;
  1304.  
  1305.                 strlcpy(kMapLocation2.szHost, tmp->GetPublicIP(), sizeof(kMapLocation2.szHost));
  1306.                 kMapLocation2.wPort = tmp->GetListenPort();
  1307.                 thecore_memcpy(kMapLocation2.alMaps, tmp->GetMaps(), sizeof(kMapLocation2.alMaps));
  1308.  
  1309.                 vec_kMapLocations.push_back(kMapLocation2);
  1310.             }
  1311.  
  1312.             if (tmp->GetChannel() == peer->GetChannel())
  1313.             {
  1314.                 tmp->EncodeHeader(HEADER_DG_MAP_LOCATIONS, 0, sizeof(BYTE) + sizeof(TMapLocation));
  1315.                 bMapCount = 1;
  1316.                 tmp->EncodeBYTE(bMapCount);
  1317.                 tmp->Encode(&kMapLocations, sizeof(TMapLocation));
  1318.             }
  1319.         }
  1320.     }
  1321.  
  1322.     vec_kMapLocations.push_back(kMapLocations);
  1323.  
  1324.     peer->EncodeHeader(HEADER_DG_MAP_LOCATIONS, 0, sizeof(BYTE) + sizeof(TMapLocation) * vec_kMapLocations.size());
  1325.     bMapCount = vec_kMapLocations.size();
  1326.     peer->EncodeBYTE(bMapCount);
  1327.     peer->Encode(&vec_kMapLocations[0], sizeof(TMapLocation) * vec_kMapLocations.size());
  1328.  
  1329.     //
  1330.     // ĽÂľ÷ : Á˘ĽÓÇŃ ÇǾ ´Ů¸Ą ÇÇľîµéŔĚ Á˘ĽÓÇĎ°Ô ¸¸µç´Ů. (P2P ÄÁłŘĽÇ »ýĽş)
  1331.     //
  1332.     sys_log(0, "SETUP: channel %u listen %u p2p %u count %u", peer->GetChannel(), p->wListenPort, p->wP2PPort, bMapCount);
  1333.  
  1334.     TPacketDGP2P p2pSetupPacket;
  1335.     p2pSetupPacket.wPort = peer->GetP2PPort();
  1336.     p2pSetupPacket.bChannel = peer->GetChannel();
  1337.     strlcpy(p2pSetupPacket.szHost, peer->GetPublicIP(), sizeof(p2pSetupPacket.szHost));
  1338.  
  1339.     for (itertype(m_peerList) i = m_peerList.begin(); i != m_peerList.end();++i)
  1340.     {
  1341.         CPeer * tmp = *i;
  1342.  
  1343.         if (tmp == peer)
  1344.             continue;
  1345.  
  1346.         // äłÎŔĚ 0Ŕ̶ó¸é ľĆÁ÷ SETUP ĆĐŶŔĚ żŔÁö ľĘŔş ÇÇľî ¶Ç´Â auth¶ó°í °ŁÁÖÇŇ Ľö ŔÖŔ˝
  1347.         if (0 == tmp->GetChannel())
  1348.             continue;
  1349.  
  1350.         tmp->EncodeHeader(HEADER_DG_P2P, 0, sizeof(TPacketDGP2P));
  1351.         tmp->Encode(&p2pSetupPacket, sizeof(TPacketDGP2P));
  1352.     }
  1353.  
  1354.     //
  1355.     // ·Î±×ŔÎ ą× şô¸µÁ¤ş¸ ş¸ł»±â
  1356.     //
  1357.     TPacketLoginOnSetup * pck = (TPacketLoginOnSetup *) c_pData;;
  1358.     std::vector<TPacketBillingRepair> vec_repair;
  1359.  
  1360.     for (DWORD c = 0; c < p->dwLoginCount; ++c, ++pck)
  1361.     {
  1362.         CLoginData * pkLD = new CLoginData;
  1363.  
  1364.         pkLD->SetKey(pck->dwLoginKey);
  1365.         pkLD->SetClientKey(pck->adwClientKey);
  1366.         pkLD->SetIP(pck->szHost);
  1367.  
  1368.         TAccountTable & r = pkLD->GetAccountRef();
  1369.  
  1370.         r.id = pck->dwID;
  1371.         trim_and_lower(pck->szLogin, r.login, sizeof(r.login));
  1372.         strlcpy(r.social_id, pck->szSocialID, sizeof(r.social_id));
  1373.         strlcpy(r.passwd, "TEMP", sizeof(r.passwd));
  1374.  
  1375.         InsertLoginData(pkLD);
  1376.  
  1377.         if (InsertLogonAccount(pck->szLogin, peer->GetHandle(), pck->szHost))
  1378.         {
  1379.             sys_log(0, "SETUP: login %u %s login_key %u host %s", pck->dwID, pck->szLogin, pck->dwLoginKey, pck->szHost);
  1380.             pkLD->SetPlay(true);
  1381.  
  1382.             if (m_pkAuthPeer)
  1383.             {
  1384.                 TPacketBillingRepair pck_repair;
  1385.                 pck_repair.dwLoginKey = pkLD->GetKey();
  1386.                 strlcpy(pck_repair.szLogin, pck->szLogin, sizeof(pck_repair.szLogin));
  1387.                 strlcpy(pck_repair.szHost, pck->szHost, sizeof(pck_repair.szHost));
  1388.                 vec_repair.push_back(pck_repair);
  1389.             }
  1390.         }
  1391.         else
  1392.             sys_log(0, "SETUP: login_fail %u %s login_key %u", pck->dwID, pck->szLogin, pck->dwLoginKey);
  1393.     }
  1394.  
  1395.     if (m_pkAuthPeer && !vec_repair.empty())
  1396.     {
  1397.         sys_log(0, "REPAIR size %d", vec_repair.size());
  1398.  
  1399.         m_pkAuthPeer->EncodeHeader(HEADER_DG_BILLING_REPAIR, 0, sizeof(DWORD) + sizeof(TPacketBillingRepair) * vec_repair.size());
  1400.         m_pkAuthPeer->EncodeDWORD(vec_repair.size());
  1401.         m_pkAuthPeer->Encode(&vec_repair[0], sizeof(TPacketBillingRepair) * vec_repair.size());
  1402.     }
  1403.  
  1404.     SendPartyOnSetup(peer);
  1405.     CGuildManager::instance().OnSetup(peer);
  1406.     CPrivManager::instance().SendPrivOnSetup(peer);
  1407.     SendEventFlagsOnSetup(peer);
  1408.     marriage::CManager::instance().OnSetup(peer);
  1409. }
  1410.  
  1411. #ifdef __SKILL_COLOR_SYSTEM__
  1412. void CClientManager::QUERY_SKILL_COLOR_SAVE(const char* c_pData)
  1413. {
  1414.     PutSkillColorCache((TSkillColor*)c_pData);
  1415. }
  1416. #endif
  1417.  
  1418. void CClientManager::QUERY_ITEM_FLUSH(CPeer * pkPeer, const char * c_pData)
  1419. {
  1420.     DWORD dwID = *(DWORD *) c_pData;
  1421.  
  1422.     if (g_log)
  1423.         sys_log(0, "HEADER_GD_ITEM_FLUSH: %u", dwID);
  1424.  
  1425.     CItemCache * c = GetItemCache(dwID);
  1426.  
  1427.     if (c)
  1428.         c->Flush();
  1429. }
  1430.  
  1431. void CClientManager::QUERY_ITEM_SAVE(CPeer * pkPeer, const char * c_pData)
  1432. {
  1433.     TPlayerItem * p = (TPlayerItem *) c_pData;
  1434.  
  1435.     // â°í¸é Äł˝¬ÇĎÁö ľĘ°í, Äł˝¬żˇ ŔÖ´ř °Íµµ »©ąö·Áľß ÇŃ´Ů.
  1436.     // auctionŔş ŔĚ ·çĆ®¸¦ ŸÁö ľĘľĆľß ÇŃ´Ů. EnrollInAuctionŔ» ŸľßÇŃ´Ů.
  1437.  
  1438.     if (p->window == SAFEBOX || p->window == MALL)
  1439.     {
  1440.         CItemCache * c = GetItemCache(p->id);
  1441.  
  1442.         if (c)
  1443.         {
  1444.             TItemCacheSetPtrMap::iterator it = m_map_pkItemCacheSetPtr.find(c->Get()->owner);
  1445.  
  1446.             if (it != m_map_pkItemCacheSetPtr.end())
  1447.             {
  1448.                 if (g_test_server)
  1449.                     sys_log(0, "ITEM_CACHE: safebox owner %u id %u", c->Get()->owner, c->Get()->id);
  1450.  
  1451.                 it->second->erase(c);
  1452.             }
  1453.  
  1454.             m_map_itemCache.erase(p->id);
  1455.  
  1456.             delete c;
  1457.         }
  1458.         char szQuery[512];
  1459.  
  1460.         snprintf(szQuery, sizeof(szQuery),
  1461.             "REPLACE INTO item%s (id, owner_id, window, pos, count, vnum, socket0, socket1, socket2, "
  1462.             "attrtype0, attrvalue0, "
  1463.             "attrtype1, attrvalue1, "
  1464.             "attrtype2, attrvalue2, "
  1465.             "attrtype3, attrvalue3, "
  1466.             "attrtype4, attrvalue4, "
  1467.             "attrtype5, attrvalue5, "
  1468.             "attrtype6, attrvalue6) "
  1469.             "VALUES(%u, %u, %d, %d, %u, %u, %ld, %ld, %ld, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d)",
  1470.             GetTablePostfix(),
  1471.             p->id,
  1472.             p->owner,
  1473.             p->window,
  1474.             p->pos,
  1475.             p->count,
  1476.             p->vnum,
  1477.             p->alSockets[0],
  1478.             p->alSockets[1],
  1479.             p->alSockets[2],
  1480.             p->aAttr[0].bType, p->aAttr[0].sValue,
  1481.             p->aAttr[1].bType, p->aAttr[1].sValue,
  1482.             p->aAttr[2].bType, p->aAttr[2].sValue,
  1483.             p->aAttr[3].bType, p->aAttr[3].sValue,
  1484.             p->aAttr[4].bType, p->aAttr[4].sValue,
  1485.             p->aAttr[5].bType, p->aAttr[5].sValue,
  1486.             p->aAttr[6].bType, p->aAttr[6].sValue);
  1487.  
  1488.         CDBManager::instance().ReturnQuery(szQuery, QID_ITEM_SAVE, pkPeer->GetHandle(), NULL);
  1489.     }
  1490. #ifdef __AUCTION__
  1491.     else if (p->window == AUCTION)
  1492.     {
  1493.         sys_err("invalid window. how can you enter this route?");
  1494.         return ;
  1495.     }
  1496. #endif
  1497.     else
  1498.     {
  1499.         if (g_test_server)
  1500.             sys_log(0, "QUERY_ITEM_SAVE => PutItemCache() owner %d id %d vnum %d ", p->owner, p->id, p->vnum);
  1501.  
  1502.         PutItemCache(p);
  1503.     }
  1504. }
  1505.  
  1506. CClientManager::TItemCacheSet * CClientManager::GetItemCacheSet(DWORD pid)
  1507. {
  1508.     TItemCacheSetPtrMap::iterator it = m_map_pkItemCacheSetPtr.find(pid);
  1509.  
  1510.     if (it == m_map_pkItemCacheSetPtr.end())
  1511.         return NULL;
  1512.  
  1513.     return it->second;
  1514. }
  1515.  
  1516. void CClientManager::CreateItemCacheSet(DWORD pid)
  1517. {
  1518.     if (m_map_pkItemCacheSetPtr.find(pid) != m_map_pkItemCacheSetPtr.end())
  1519.         return;
  1520.  
  1521.     TItemCacheSet * pSet = new TItemCacheSet;
  1522.     m_map_pkItemCacheSetPtr.insert(TItemCacheSetPtrMap::value_type(pid, pSet));
  1523.  
  1524.     if (g_log)
  1525.         sys_log(0, "ITEM_CACHE: new cache %u", pid);
  1526. }
  1527.  
  1528. void CClientManager::FlushItemCacheSet(DWORD pid)
  1529. {
  1530.     TItemCacheSetPtrMap::iterator it = m_map_pkItemCacheSetPtr.find(pid);
  1531.  
  1532.     if (it == m_map_pkItemCacheSetPtr.end())
  1533.     {
  1534.         sys_log(0, "FLUSH_ITEMCACHESET : No ItemCacheSet pid(%d)", pid);
  1535.         return;
  1536.     }
  1537.  
  1538.     TItemCacheSet * pSet = it->second;
  1539.     TItemCacheSet::iterator it_set = pSet->begin();
  1540.  
  1541.     while (it_set != pSet->end())
  1542.     {
  1543.         CItemCache * c = *it_set++;
  1544.         c->Flush();
  1545.  
  1546.         m_map_itemCache.erase(c->Get()->id);
  1547.         delete c;
  1548.     }
  1549.  
  1550.     pSet->clear();
  1551.     delete pSet;
  1552.  
  1553.     m_map_pkItemCacheSetPtr.erase(it);
  1554.  
  1555.     if (g_log)
  1556.         sys_log(0, "FLUSH_ITEMCACHESET : Deleted pid(%d)", pid);
  1557. }
  1558.  
  1559. CItemCache * CClientManager::GetItemCache(DWORD id)
  1560. {
  1561.     TItemCacheMap::iterator it = m_map_itemCache.find(id);
  1562.  
  1563.     if (it == m_map_itemCache.end())
  1564.         return NULL;
  1565.  
  1566.     return it->second;
  1567. }
  1568.  
  1569. void CClientManager::PutItemCache(TPlayerItem * pNew, bool bSkipQuery)
  1570. {
  1571.     CItemCache * c;
  1572.  
  1573.     c = GetItemCache(pNew->id);
  1574.  
  1575.     // ľĆŔĚĹŰ »ő·Î »ýĽş
  1576.     if (!c)
  1577.     {
  1578.         if (g_log)
  1579.             sys_log(0, "ITEM_CACHE: PutItemCache ==> New CItemCache id%d vnum%d new owner%d", pNew->id, pNew->vnum, pNew->owner);
  1580.  
  1581.         c = new CItemCache;
  1582.         m_map_itemCache.insert(TItemCacheMap::value_type(pNew->id, c));
  1583.     }
  1584.     // ŔÖŔ»˝Ă
  1585.     else
  1586.     {
  1587.         if (g_log)
  1588.             sys_log(0, "ITEM_CACHE: PutItemCache ==> Have Cache");
  1589.         // ĽŇŔŻŔÚ°ˇ Ʋ¸®¸é
  1590.         if (pNew->owner != c->Get()->owner)
  1591.         {
  1592.             // ŔĚąĚ ŔĚ ľĆŔĚĹŰŔ» °ˇÁö°í ŔÖľú´ř ŔŻŔú·Î şÎĹÍ ľĆŔĚĹŰŔ» »čÁ¦ÇŃ´Ů.
  1593.             TItemCacheSetPtrMap::iterator it = m_map_pkItemCacheSetPtr.find(c->Get()->owner);
  1594.  
  1595.             if (it != m_map_pkItemCacheSetPtr.end())
  1596.             {
  1597.                 if (g_log)
  1598.                 sys_log(0, "ITEM_CACHE: delete owner %u id %u new owner %u", c->Get()->owner, c->Get()->id, pNew->owner);
  1599.                 it->second->erase(c);
  1600.             }
  1601.         }
  1602.     }
  1603.  
  1604.     // »ő·Îżî Á¤ş¸ ľ÷µĄŔĚĆ®
  1605.     c->Put(pNew, bSkipQuery);
  1606.  
  1607.     TItemCacheSetPtrMap::iterator it = m_map_pkItemCacheSetPtr.find(c->Get()->owner);
  1608.  
  1609.     if (it != m_map_pkItemCacheSetPtr.end())
  1610.     {
  1611.         if (g_log)
  1612.             sys_log(0, "ITEM_CACHE: save %u id %u", c->Get()->owner, c->Get()->id);
  1613.         else
  1614.             sys_log(1, "ITEM_CACHE: save %u id %u", c->Get()->owner, c->Get()->id);
  1615.         it->second->insert(c);
  1616.     }
  1617.     else
  1618.     {
  1619.         // ÇöŔç ĽŇŔŻŔÚ°ˇ ľřŔ¸ąÇ·Î ąŮ·Î ŔúŔĺÇŘľß ´ŮŔ˝ Á˘ĽÓŔĚ żĂ ¶§ SQLżˇ Äő¸®ÇĎż©
  1620.         // ąŢŔ» Ľö ŔÖŔ¸ąÇ·Î ąŮ·Î ŔúŔĺÇŃ´Ů.
  1621.         if (g_log)
  1622.             sys_log(0, "ITEM_CACHE: direct save %u id %u", c->Get()->owner, c->Get()->id);
  1623.         else
  1624.             sys_log(1, "ITEM_CACHE: direct save %u id %u", c->Get()->owner, c->Get()->id);
  1625.  
  1626.         c->OnFlush();
  1627.     }
  1628. }
  1629.  
  1630. bool CClientManager::DeleteItemCache(DWORD dwID)
  1631. {
  1632.     CItemCache * c = GetItemCache(dwID);
  1633.  
  1634.     if (!c)
  1635.         return false;
  1636.  
  1637.     c->Delete();
  1638.     return true;
  1639. }
  1640.  
  1641. // MYSHOP_PRICE_LIST
  1642. CItemPriceListTableCache* CClientManager::GetItemPriceListCache(DWORD dwID)
  1643. {
  1644.     TItemPriceListCacheMap::iterator it = m_mapItemPriceListCache.find(dwID);
  1645.  
  1646.     if (it == m_mapItemPriceListCache.end())
  1647.         return NULL;
  1648.  
  1649.     return it->second;
  1650. }
  1651.  
  1652. void CClientManager::PutItemPriceListCache(const TItemPriceListTable* pItemPriceList)
  1653. {
  1654.     CItemPriceListTableCache* pCache = GetItemPriceListCache(pItemPriceList->dwOwnerID);
  1655.  
  1656.     if (!pCache)
  1657.     {
  1658.         pCache = new CItemPriceListTableCache;
  1659.         m_mapItemPriceListCache.insert(TItemPriceListCacheMap::value_type(pItemPriceList->dwOwnerID, pCache));
  1660.     }
  1661.  
  1662.     pCache->Put(const_cast<TItemPriceListTable*>(pItemPriceList), true);
  1663. }
  1664.  
  1665. void CClientManager::UpdatePlayerCache()
  1666. {
  1667.     TPlayerTableCacheMap::iterator it = m_map_playerCache.begin();
  1668.  
  1669.     while (it != m_map_playerCache.end())
  1670.     {
  1671.         CPlayerTableCache * c = (it++)->second;
  1672.  
  1673.         if (c->CheckTimeout())
  1674.         {
  1675.             if (g_log)
  1676.                 sys_log(0, "UPDATE : UpdatePlayerCache() ==> FlushPlayerCache %d %s ", c->Get(false)->id, c->Get(false)->name);
  1677.  
  1678.             c->Flush();
  1679.  
  1680.             // Item Cacheµµ ľ÷µĄŔĚĆ®
  1681.             UpdateItemCacheSet(c->Get()->id);
  1682.         }
  1683.         else if (c->CheckFlushTimeout())
  1684.             c->Flush();
  1685.     }
  1686. }
  1687. // END_OF_MYSHOP_PRICE_LIST
  1688.  
  1689. #ifdef __SKILL_COLOR_SYSTEM__
  1690. CSKillColorCache* CClientManager::GetSkillColorCache(DWORD id)
  1691. {
  1692.     TSkillColorCacheMap::iterator it = m_map_SkillColorCache.find(id);
  1693.  
  1694.     if (it == m_map_SkillColorCache.end())
  1695.         return NULL;
  1696.  
  1697.     return it->second;
  1698. }
  1699.  
  1700. void CClientManager::PutSkillColorCache(const TSkillColor* pNew)
  1701. {
  1702.     CSKillColorCache* pCache = GetSkillColorCache(pNew->player_id);
  1703.  
  1704.     if (!pCache)
  1705.     {
  1706.         pCache = new CSKillColorCache;
  1707.         m_map_SkillColorCache.insert(TSkillColorCacheMap::value_type(pNew->player_id, pCache));
  1708.     }
  1709.  
  1710.     pCache->Put(const_cast<TSkillColor*>(pNew), false);
  1711. }
  1712.  
  1713. void CClientManager::UpdateSkillColorCache()
  1714. {
  1715.     TSkillColorCacheMap::iterator it = m_map_SkillColorCache.begin();
  1716.  
  1717.     while (it != m_map_SkillColorCache.end())
  1718.     {
  1719.         CSKillColorCache* pCache = it->second;
  1720.  
  1721.         if (pCache->CheckFlushTimeout())
  1722.         {
  1723.             pCache->Flush();
  1724.             m_map_SkillColorCache.erase(it++);
  1725.         }
  1726.         else
  1727.             ++it;
  1728.     }
  1729. }
  1730. #endif
  1731.  
  1732. void CClientManager::SetCacheFlushCountLimit(int iLimit)
  1733. {
  1734.     m_iCacheFlushCountLimit = MAX(10, iLimit);
  1735.     sys_log(0, "CACHE_FLUSH_LIMIT_PER_SECOND: %d", m_iCacheFlushCountLimit);
  1736. }
  1737.  
  1738. void CClientManager::UpdateItemCache()
  1739. {
  1740.     if (m_iCacheFlushCount >= m_iCacheFlushCountLimit)
  1741.         return;
  1742.  
  1743.     TItemCacheMap::iterator it = m_map_itemCache.begin();
  1744.  
  1745.     while (it != m_map_itemCache.end())
  1746.     {
  1747.         CItemCache * c = (it++)->second;
  1748.  
  1749.         // ľĆŔĚĹŰŔş Flush¸¸ ÇŃ´Ů.
  1750.         if (c->CheckFlushTimeout())
  1751.         {
  1752.             if (g_test_server)
  1753.                 sys_log(0, "UpdateItemCache ==> Flush() vnum %d id owner %d", c->Get()->vnum, c->Get()->id, c->Get()->owner);
  1754.  
  1755.             c->Flush();
  1756.  
  1757.             if (++m_iCacheFlushCount >= m_iCacheFlushCountLimit)
  1758.                 break;
  1759.         }
  1760.     }
  1761. }
  1762.  
  1763. void CClientManager::UpdateItemPriceListCache()
  1764. {
  1765.     TItemPriceListCacheMap::iterator it = m_mapItemPriceListCache.begin();
  1766.  
  1767.     while (it != m_mapItemPriceListCache.end())
  1768.     {
  1769.         CItemPriceListTableCache* pCache = it->second;
  1770.  
  1771.         if (pCache->CheckFlushTimeout())
  1772.         {
  1773.             pCache->Flush();
  1774.             m_mapItemPriceListCache.erase(it++);
  1775.         }
  1776.         else
  1777.             ++it;
  1778.     }
  1779. }
  1780.  
  1781. void CClientManager::QUERY_ITEM_DESTROY(CPeer * pkPeer, const char * c_pData)
  1782. {
  1783.     DWORD dwID = *(DWORD *) c_pData;
  1784.     c_pData += sizeof(DWORD);
  1785.  
  1786.     DWORD dwPID = *(DWORD *) c_pData;
  1787.  
  1788.     if (!DeleteItemCache(dwID))
  1789.     {
  1790.         char szQuery[64];
  1791.         snprintf(szQuery, sizeof(szQuery), "DELETE FROM item%s WHERE id=%u", GetTablePostfix(), dwID);
  1792.  
  1793.         if (g_log)
  1794.             sys_log(0, "HEADER_GD_ITEM_DESTROY: PID %u ID %u", dwPID, dwID);
  1795.  
  1796.         if (dwPID == 0) // ľĆą«µµ °ˇÁř »ç¶÷ŔĚ ľřľú´Ů¸é, şńµż±â Äő¸®
  1797.             CDBManager::instance().AsyncQuery(szQuery);
  1798.         else
  1799.             CDBManager::instance().ReturnQuery(szQuery, QID_ITEM_DESTROY, pkPeer->GetHandle(), NULL);
  1800.     }
  1801. }
  1802.  
  1803. void CClientManager::QUERY_FLUSH_CACHE(CPeer * pkPeer, const char * c_pData)
  1804. {
  1805.     DWORD dwPID = *(DWORD *) c_pData;
  1806.  
  1807.     CPlayerTableCache * pkCache = GetPlayerCache(dwPID);
  1808.  
  1809.     if (!pkCache)
  1810.         return;
  1811.  
  1812.     sys_log(0, "FLUSH_CACHE: %u", dwPID);
  1813.  
  1814.     pkCache->Flush();
  1815.     FlushItemCacheSet(dwPID);
  1816.  
  1817.     m_map_playerCache.erase(dwPID);
  1818.     delete pkCache;
  1819. }
  1820.  
  1821. void CClientManager::QUERY_SMS(CPeer * pkPeer, TPacketGDSMS * pack)
  1822. {
  1823.     char szQuery[QUERY_MAX_LEN];
  1824.  
  1825.     char szMsg[256+1];
  1826.     //unsigned long len = CDBManager::instance().EscapeString(szMsg, pack->szMsg, strlen(pack->szMsg), SQL_ACCOUNT);
  1827.     unsigned long len = CDBManager::instance().EscapeString(szMsg, pack->szMsg, strlen(pack->szMsg));
  1828.     szMsg[len] = '\0';
  1829.  
  1830.     snprintf(szQuery, sizeof(szQuery),
  1831.             "INSERT INTO sms_pool (server, sender, receiver, mobile, msg) VALUES(%d, '%s', '%s', '%s', '%s')",
  1832.             (m_iPlayerIDStart + 2) / 3, pack->szFrom, pack->szTo, pack->szMobile, szMsg);
  1833.  
  1834.     CDBManager::instance().AsyncQuery(szQuery);
  1835. }
  1836.  
  1837. void CClientManager::QUERY_RELOAD_PROTO()
  1838. {
  1839.     if (!InitializeTables())
  1840.     {
  1841.         sys_err("QUERY_RELOAD_PROTO: cannot load tables");
  1842.         return;
  1843.     }
  1844.  
  1845.     for (TPeerList::iterator i = m_peerList.begin(); i != m_peerList.end(); ++i)
  1846.     {
  1847.         CPeer * tmp = *i;
  1848.  
  1849.         if (!tmp->GetChannel())
  1850.             continue;
  1851.  
  1852.         tmp->EncodeHeader(HEADER_DG_RELOAD_PROTO, 0,
  1853.                 sizeof(WORD) + sizeof(TSkillTable) * m_vec_skillTable.size() +
  1854.                 sizeof(WORD) + sizeof(TBanwordTable) * m_vec_banwordTable.size() +
  1855.                 sizeof(WORD) + sizeof(TItemTable) * m_vec_itemTable.size() +
  1856.                 sizeof(WORD) + sizeof(TMobTable) * m_vec_mobTable.size());
  1857.  
  1858.         tmp->EncodeWORD(m_vec_skillTable.size());
  1859.         tmp->Encode(&m_vec_skillTable[0], sizeof(TSkillTable) * m_vec_skillTable.size());
  1860.  
  1861.         tmp->EncodeWORD(m_vec_banwordTable.size());
  1862.         tmp->Encode(&m_vec_banwordTable[0], sizeof(TBanwordTable) * m_vec_banwordTable.size());
  1863.  
  1864.         tmp->EncodeWORD(m_vec_itemTable.size());
  1865.         tmp->Encode(&m_vec_itemTable[0], sizeof(TItemTable) * m_vec_itemTable.size());
  1866.  
  1867.         tmp->EncodeWORD(m_vec_mobTable.size());
  1868.         tmp->Encode(&m_vec_mobTable[0], sizeof(TMobTable) * m_vec_mobTable.size());
  1869.     }
  1870. }
  1871.  
  1872. // ADD_GUILD_PRIV_TIME
  1873. /**
  1874.  * @version 05/06/08 Bang2ni - ÁöĽÓ˝Ă°Ł Ăß°ˇ
  1875.  */
  1876. void CClientManager::AddGuildPriv(TPacketGiveGuildPriv* p)
  1877. {
  1878.     CPrivManager::instance().AddGuildPriv(p->guild_id, p->type, p->value, p->duration_sec);
  1879. #ifdef ENABLE_DEFAULT_PRIV
  1880.     __UpdateDefaultPriv("GUILD", p->guild_id, p->type, p->value, p->duration_sec);
  1881. #endif
  1882. }
  1883.  
  1884. void CClientManager::AddEmpirePriv(TPacketGiveEmpirePriv* p)
  1885. {
  1886.     CPrivManager::instance().AddEmpirePriv(p->empire, p->type, p->value, p->duration_sec);
  1887. #ifdef ENABLE_DEFAULT_PRIV
  1888.     __UpdateDefaultPriv("EMPIRE", p->empire, p->type, p->value, p->duration_sec);
  1889. #endif
  1890. }
  1891. // END_OF_ADD_GUILD_PRIV_TIME
  1892.  
  1893. void CClientManager::AddCharacterPriv(TPacketGiveCharacterPriv* p)
  1894. {
  1895.     CPrivManager::instance().AddCharPriv(p->pid, p->type, p->value);
  1896. #ifdef ENABLE_DEFAULT_PRIV
  1897.     __UpdateDefaultPriv("PLAYER", p->pid, p->type, p->value, 0);
  1898. #endif
  1899. }
  1900.  
  1901. void CClientManager::MoneyLog(TPacketMoneyLog* p)
  1902. {
  1903.     CMoneyLog::instance().AddLog(p->type, p->vnum, p->gold);
  1904. }
  1905.  
  1906. CLoginData * CClientManager::GetLoginData(DWORD dwKey)
  1907. {
  1908.     TLoginDataByLoginKey::iterator it = m_map_pkLoginData.find(dwKey);
  1909.  
  1910.     if (it == m_map_pkLoginData.end())
  1911.         return NULL;
  1912.  
  1913.     return it->second;
  1914. }
  1915.  
  1916. CLoginData * CClientManager::GetLoginDataByLogin(const char * c_pszLogin)
  1917. {
  1918.     char szLogin[LOGIN_MAX_LEN + 1];
  1919.     trim_and_lower(c_pszLogin, szLogin, sizeof(szLogin));
  1920.  
  1921.     TLoginDataByLogin::iterator it = m_map_pkLoginDataByLogin.find(szLogin);
  1922.  
  1923.     if (it == m_map_pkLoginDataByLogin.end())
  1924.         return NULL;
  1925.  
  1926.     return it->second;
  1927. }
  1928.  
  1929. CLoginData * CClientManager::GetLoginDataByAID(DWORD dwAID)
  1930. {
  1931.     TLoginDataByAID::iterator it = m_map_pkLoginDataByAID.find(dwAID);
  1932.  
  1933.     if (it == m_map_pkLoginDataByAID.end())
  1934.         return NULL;
  1935.  
  1936.     return it->second;
  1937. }
  1938.  
  1939. void CClientManager::InsertLoginData(CLoginData * pkLD)
  1940. {
  1941.     char szLogin[LOGIN_MAX_LEN + 1];
  1942.     trim_and_lower(pkLD->GetAccountRef().login, szLogin, sizeof(szLogin));
  1943.  
  1944.     m_map_pkLoginData.insert(std::make_pair(pkLD->GetKey(), pkLD));
  1945.     m_map_pkLoginDataByLogin.insert(std::make_pair(szLogin, pkLD));
  1946.     m_map_pkLoginDataByAID.insert(std::make_pair(pkLD->GetAccountRef().id, pkLD));
  1947. }
  1948.  
  1949. void CClientManager::DeleteLoginData(CLoginData * pkLD)
  1950. {
  1951.     m_map_pkLoginData.erase(pkLD->GetKey());
  1952.     m_map_pkLoginDataByLogin.erase(pkLD->GetAccountRef().login);
  1953.     m_map_pkLoginDataByAID.erase(pkLD->GetAccountRef().id);
  1954.  
  1955.     if (m_map_kLogonAccount.find(pkLD->GetAccountRef().login) == m_map_kLogonAccount.end())
  1956.         delete pkLD;
  1957.     else
  1958.         pkLD->SetDeleted(true);
  1959. }
  1960.  
  1961. void CClientManager::QUERY_AUTH_LOGIN(CPeer * pkPeer, DWORD dwHandle, TPacketGDAuthLogin * p)
  1962. {
  1963.     if (g_test_server)
  1964.         sys_log(0, "QUERY_AUTH_LOGIN %d %d %s", p->dwID, p->dwLoginKey, p->szLogin);
  1965.     CLoginData * pkLD = GetLoginDataByLogin(p->szLogin);
  1966.  
  1967.     if (pkLD)
  1968.     {
  1969.         DeleteLoginData(pkLD);
  1970.     }
  1971.  
  1972.     BYTE bResult;
  1973.  
  1974.     if (GetLoginData(p->dwLoginKey))
  1975.     {
  1976.         sys_err("LoginData already exist key %u login %s", p->dwLoginKey, p->szLogin);
  1977.         bResult = 0;
  1978.  
  1979.         pkPeer->EncodeHeader(HEADER_DG_AUTH_LOGIN, dwHandle, sizeof(BYTE));
  1980.         pkPeer->EncodeBYTE(bResult);
  1981.     }
  1982.     else
  1983.     {
  1984.         CLoginData * pkLD = new CLoginData;
  1985.  
  1986.         pkLD->SetKey(p->dwLoginKey);
  1987.         pkLD->SetClientKey(p->adwClientKey);
  1988.         pkLD->SetBillType(p->bBillType);
  1989.         pkLD->SetBillID(p->dwBillID);
  1990.         pkLD->SetPremium(p->iPremiumTimes);
  1991.  
  1992.         TAccountTable & r = pkLD->GetAccountRef();
  1993.  
  1994.         r.id = p->dwID;
  1995.         trim_and_lower(p->szLogin, r.login, sizeof(r.login));
  1996.         strlcpy(r.social_id, p->szSocialID, sizeof(r.social_id));
  1997.         strlcpy(r.passwd, "TEMP", sizeof(r.passwd));
  1998.  
  1999.         sys_log(0, "AUTH_LOGIN id(%u) login(%s) social_id(%s) login_key(%u), client_key(%u %u %u %u)",
  2000.                 p->dwID, p->szLogin, p->szSocialID, p->dwLoginKey,
  2001.                 p->adwClientKey[0], p->adwClientKey[1], p->adwClientKey[2], p->adwClientKey[3]);
  2002.  
  2003.         bResult = 1;
  2004.  
  2005.         InsertLoginData(pkLD);
  2006.  
  2007.         pkPeer->EncodeHeader(HEADER_DG_AUTH_LOGIN, dwHandle, sizeof(BYTE));
  2008.         pkPeer->EncodeBYTE(bResult);
  2009.     }
  2010. }
  2011.  
  2012. void CClientManager::BillingExpire(TPacketBillingExpire * p)
  2013. {
  2014.     char key[LOGIN_MAX_LEN + 1];
  2015.     trim_and_lower(p->szLogin, key, sizeof(key));
  2016.  
  2017.     switch (p->bBillType)
  2018.     {
  2019.         case BILLING_IP_TIME:
  2020.         case BILLING_IP_DAY:
  2021.             {
  2022.                 DWORD dwIPID = 0;
  2023.                 str_to_number(dwIPID, p->szLogin);
  2024.  
  2025.                 TLogonAccountMap::iterator it = m_map_kLogonAccount.begin();
  2026.  
  2027.                 while (it != m_map_kLogonAccount.end())
  2028.                 {
  2029.                     CLoginData * pkLD = (it++)->second;
  2030.  
  2031.                     if (pkLD->GetBillID() == dwIPID)
  2032.                     {
  2033.                         CPeer * pkPeer = GetPeer(pkLD->GetConnectedPeerHandle());
  2034.  
  2035.                         if (pkPeer)
  2036.                         {
  2037.                             strlcpy(p->szLogin, pkLD->GetAccountRef().login, sizeof(p->szLogin));
  2038.                             pkPeer->EncodeHeader(HEADER_DG_BILLING_EXPIRE, 0, sizeof(TPacketBillingExpire));
  2039.                             pkPeer->Encode(p, sizeof(TPacketBillingExpire));
  2040.                         }
  2041.                     }
  2042.                 }
  2043.             }
  2044.             break;
  2045.  
  2046.         case BILLING_TIME:
  2047.         case BILLING_DAY:
  2048.             {
  2049.                 TLogonAccountMap::iterator it = m_map_kLogonAccount.find(key);
  2050.  
  2051.                 if (it != m_map_kLogonAccount.end())
  2052.                 {
  2053.                     CLoginData * pkLD = it->second;
  2054.  
  2055.                     CPeer * pkPeer = GetPeer(pkLD->GetConnectedPeerHandle());
  2056.  
  2057.                     if (pkPeer)
  2058.                     {
  2059.                         pkPeer->EncodeHeader(HEADER_DG_BILLING_EXPIRE, 0, sizeof(TPacketBillingExpire));
  2060.                         pkPeer->Encode(p, sizeof(TPacketBillingExpire));
  2061.                     }
  2062.                 }
  2063.             }
  2064.             break;
  2065.     }
  2066. }
  2067.  
  2068. void CClientManager::BillingCheck(const char * data)
  2069. {
  2070.     if (!m_pkAuthPeer)
  2071.         return;
  2072.  
  2073.     time_t curTime = GetCurrentTime();
  2074.  
  2075.     DWORD dwCount = *(DWORD *) data;
  2076.     data += sizeof(DWORD);
  2077.  
  2078.     std::vector<DWORD> vec;
  2079.  
  2080.     sys_log(0, "BillingCheck: size %u", dwCount);
  2081.  
  2082.     for (DWORD i = 0; i < dwCount; ++i)
  2083.     {
  2084.         DWORD dwKey = *(DWORD *) data;
  2085.         data += sizeof(DWORD);
  2086.  
  2087.         sys_log(0, "BillingCheck: %u", dwKey);
  2088.  
  2089.         TLoginDataByLoginKey::iterator it = m_map_pkLoginData.find(dwKey);
  2090.  
  2091.         if (it == m_map_pkLoginData.end())
  2092.         {
  2093.             sys_log(0, "BillingCheck: key not exist: %u", dwKey);
  2094.             vec.push_back(dwKey);
  2095.         }
  2096.         else
  2097.         {
  2098.             CLoginData * pkLD = it->second;
  2099.  
  2100.             if (!pkLD->IsPlay() && curTime - pkLD->GetLastPlayTime() > 180)
  2101.             {
  2102.                 sys_log(0, "BillingCheck: not login: %u", dwKey);
  2103.                 vec.push_back(dwKey);
  2104.             }
  2105.         }
  2106.     }
  2107.  
  2108.     m_pkAuthPeer->EncodeHeader(HEADER_DG_BILLING_CHECK, 0, sizeof(DWORD) + sizeof(DWORD) * vec.size());
  2109.     m_pkAuthPeer->EncodeDWORD(vec.size());
  2110.  
  2111.     if (!vec.empty())
  2112.         m_pkAuthPeer->Encode(&vec[0], sizeof(DWORD) * vec.size());
  2113. }
  2114.  
  2115. void CClientManager::GuildDepositMoney(TPacketGDGuildMoney* p)
  2116. {
  2117.     CGuildManager::instance().DepositMoney(p->dwGuild, p->iGold);
  2118. }
  2119.  
  2120. void CClientManager::GuildWithdrawMoney(CPeer* peer, TPacketGDGuildMoney* p)
  2121. {
  2122.     CGuildManager::instance().WithdrawMoney(peer, p->dwGuild, p->iGold);
  2123. }
  2124.  
  2125. void CClientManager::GuildWithdrawMoneyGiveReply(TPacketGDGuildMoneyWithdrawGiveReply* p)
  2126. {
  2127.     CGuildManager::instance().WithdrawMoneyReply(p->dwGuild, p->bGiveSuccess, p->iChangeGold);
  2128. }
  2129.  
  2130. void CClientManager::GuildWarBet(TPacketGDGuildWarBet * p)
  2131. {
  2132.     CGuildManager::instance().Bet(p->dwWarID, p->szLogin, p->dwGold, p->dwGuild);
  2133. }
  2134.  
  2135. void CClientManager::SendAllLoginToBilling()
  2136. {
  2137.     if (!m_pkAuthPeer)
  2138.         return;
  2139.  
  2140.     std::vector<TPacketBillingRepair> vec;
  2141.     TPacketBillingRepair p;
  2142.  
  2143.     TLogonAccountMap::iterator it = m_map_kLogonAccount.begin();
  2144.  
  2145.     while (it != m_map_kLogonAccount.end())
  2146.     {
  2147.         CLoginData * pkLD = (it++)->second;
  2148.  
  2149.         p.dwLoginKey = pkLD->GetKey();
  2150.         strlcpy(p.szLogin, pkLD->GetAccountRef().login, sizeof(p.szLogin));
  2151.         strlcpy(p.szHost, pkLD->GetIP(), sizeof(p.szHost));
  2152.         sys_log(0, "SendAllLoginToBilling %s %s", pkLD->GetAccountRef().login, pkLD->GetIP());
  2153.         vec.push_back(p);
  2154.     }
  2155.  
  2156.     if (!vec.empty())
  2157.     {
  2158.         m_pkAuthPeer->EncodeHeader(HEADER_DG_BILLING_REPAIR, 0, sizeof(DWORD) + sizeof(TPacketBillingRepair) * vec.size());
  2159.         m_pkAuthPeer->EncodeDWORD(vec.size());
  2160.         m_pkAuthPeer->Encode(&vec[0], sizeof(TPacketBillingRepair) * vec.size());
  2161.     }
  2162. }
  2163.  
  2164. void CClientManager::SendLoginToBilling(CLoginData * pkLD, bool bLogin)
  2165. {
  2166.     if (!m_pkAuthPeer)
  2167.         return;
  2168.  
  2169.     TPacketBillingLogin p;
  2170.  
  2171.     p.dwLoginKey = pkLD->GetKey();
  2172.     p.bLogin = bLogin ? 1 : 0;
  2173.  
  2174.     DWORD dwCount = 1;
  2175.     m_pkAuthPeer->EncodeHeader(HEADER_DG_BILLING_LOGIN, 0, sizeof(DWORD) + sizeof(TPacketBillingLogin));
  2176.     m_pkAuthPeer->EncodeDWORD(dwCount);
  2177.     m_pkAuthPeer->Encode(&p, sizeof(TPacketBillingLogin));
  2178. }
  2179.  
  2180. void CClientManager::CreateObject(TPacketGDCreateObject * p)
  2181. {
  2182.     using namespace building;
  2183.  
  2184.     char szQuery[512];
  2185.  
  2186.     snprintf(szQuery, sizeof(szQuery),
  2187.             "INSERT INTO object%s (land_id, vnum, map_index, x, y, x_rot, y_rot, z_rot) VALUES(%u, %u, %d, %d, %d, %f, %f, %f)",
  2188.             GetTablePostfix(), p->dwLandID, p->dwVnum, p->lMapIndex, p->x, p->y, p->xRot, p->yRot, p->zRot);
  2189.  
  2190.     std::auto_ptr<SQLMsg> pmsg(CDBManager::instance().DirectQuery(szQuery));
  2191.  
  2192.     if (pmsg->Get()->uiInsertID == 0)
  2193.     {
  2194.         sys_err("cannot insert object");
  2195.         return;
  2196.     }
  2197.  
  2198.     TObject * pkObj = new TObject;
  2199.  
  2200.     memset(pkObj, 0, sizeof(TObject));
  2201.  
  2202.     pkObj->dwID = pmsg->Get()->uiInsertID;
  2203.     pkObj->dwVnum = p->dwVnum;
  2204.     pkObj->dwLandID = p->dwLandID;
  2205.     pkObj->lMapIndex = p->lMapIndex;
  2206.     pkObj->x = p->x;
  2207.     pkObj->y = p->y;
  2208.     pkObj->xRot = p->xRot;
  2209.     pkObj->yRot = p->yRot;
  2210.     pkObj->zRot = p->zRot;
  2211.     pkObj->lLife = 0;
  2212.  
  2213.     ForwardPacket(HEADER_DG_CREATE_OBJECT, pkObj, sizeof(TObject));
  2214.  
  2215.     m_map_pkObjectTable.insert(std::make_pair(pkObj->dwID, pkObj));
  2216. }
  2217.  
  2218. void CClientManager::DeleteObject(DWORD dwID)
  2219. {
  2220.     char szQuery[128];
  2221.  
  2222.     snprintf(szQuery, sizeof(szQuery), "DELETE FROM object%s WHERE id=%u", GetTablePostfix(), dwID);
  2223.  
  2224.     std::auto_ptr<SQLMsg> pmsg(CDBManager::instance().DirectQuery(szQuery));
  2225.  
  2226.     if (pmsg->Get()->uiAffectedRows == 0 || pmsg->Get()->uiAffectedRows == (uint32_t)-1)
  2227.     {
  2228.         sys_err("no object by id %u", dwID);
  2229.         return;
  2230.     }
  2231.  
  2232.     itertype(m_map_pkObjectTable) it = m_map_pkObjectTable.find(dwID);
  2233.  
  2234.     if (it != m_map_pkObjectTable.end())
  2235.     {
  2236.         delete it->second;
  2237.         m_map_pkObjectTable.erase(it);
  2238.     }
  2239.  
  2240.     ForwardPacket(HEADER_DG_DELETE_OBJECT, &dwID, sizeof(DWORD));
  2241. }
  2242.  
  2243. void CClientManager::UpdateLand(DWORD * pdw)
  2244. {
  2245.     DWORD dwID = pdw[0];
  2246.     DWORD dwGuild = pdw[1];
  2247.  
  2248.     building::TLand * p = &m_vec_kLandTable[0];
  2249.  
  2250.     DWORD i;
  2251.  
  2252.     for (i = 0; i < m_vec_kLandTable.size(); ++i, ++p)
  2253.     {
  2254.         if (p->dwID == dwID)
  2255.         {
  2256.             char buf[256];
  2257.             snprintf(buf, sizeof(buf), "UPDATE land%s SET guild_id=%u WHERE id=%u", GetTablePostfix(), dwGuild, dwID);
  2258.             CDBManager::instance().AsyncQuery(buf);
  2259.  
  2260.             p->dwGuildID = dwGuild;
  2261.             break;
  2262.         }
  2263.     }
  2264.  
  2265.     if (i < m_vec_kLandTable.size())
  2266.         ForwardPacket(HEADER_DG_UPDATE_LAND, p, sizeof(building::TLand));
  2267. }
  2268.  
  2269. void CClientManager::VCard(TPacketGDVCard * p)
  2270. {
  2271.     sys_log(0, "VCARD: %u %s %s %s %s",
  2272.             p->dwID, p->szSellCharacter, p->szSellAccount, p->szBuyCharacter, p->szBuyAccount);
  2273.  
  2274.     m_queue_vcard.push(*p);
  2275. }
  2276.  
  2277. void CClientManager::VCardProcess()
  2278. {
  2279.     if (!m_pkAuthPeer)
  2280.         return;
  2281.  
  2282.     while (!m_queue_vcard.empty())
  2283.     {
  2284.         m_pkAuthPeer->EncodeHeader(HEADER_DG_VCARD, 0, sizeof(TPacketGDVCard));
  2285.         m_pkAuthPeer->Encode(&m_queue_vcard.front(), sizeof(TPacketGDVCard));
  2286.  
  2287.         m_queue_vcard.pop();
  2288.     }
  2289. }
  2290.  
  2291. // BLOCK_CHAT
  2292. void CClientManager::BlockChat(TPacketBlockChat* p)
  2293. {
  2294.     char szQuery[256];
  2295.  
  2296.     if (g_stLocale == "sjis")
  2297.         snprintf(szQuery, sizeof(szQuery), "SELECT id FROM player%s WHERE name = '%s' collate sjis_japanese_ci", GetTablePostfix(), p->szName);
  2298.     else
  2299.         snprintf(szQuery, sizeof(szQuery), "SELECT id FROM player%s WHERE name = '%s'", GetTablePostfix(), p->szName);
  2300.     std::auto_ptr<SQLMsg> pmsg(CDBManager::instance().DirectQuery(szQuery));
  2301.     SQLResult * pRes = pmsg->Get();
  2302.  
  2303.     if (pRes->uiNumRows)
  2304.     {
  2305.         MYSQL_ROW row = mysql_fetch_row(pRes->pSQLResult);
  2306.         DWORD pid = strtoul(row[0], NULL, 10);
  2307.  
  2308.         TPacketGDAddAffect pa;
  2309.         pa.dwPID = pid;
  2310.         pa.elem.dwType = 223;
  2311.         pa.elem.bApplyOn = 0;
  2312.         pa.elem.lApplyValue = 0;
  2313.         pa.elem.dwFlag = 0;
  2314.         pa.elem.lDuration = p->lDuration;
  2315.         pa.elem.lSPCost = 0;
  2316.         QUERY_ADD_AFFECT(NULL, &pa);
  2317.     }
  2318.     else
  2319.     {
  2320.         // cannot find user with that name
  2321.     }
  2322. }
  2323. // END_OF_BLOCK_CHAT
  2324.  
  2325. void CClientManager::MarriageAdd(TPacketMarriageAdd * p)
  2326. {
  2327.     sys_log(0, "MarriageAdd %u %u %s %s", p->dwPID1, p->dwPID2, p->szName1, p->szName2);
  2328.     marriage::CManager::instance().Add(p->dwPID1, p->dwPID2, p->szName1, p->szName2);
  2329. }
  2330.  
  2331. void CClientManager::MarriageUpdate(TPacketMarriageUpdate * p)
  2332. {
  2333.     sys_log(0, "MarriageUpdate PID:%u %u LP:%d ST:%d", p->dwPID1, p->dwPID2, p->iLovePoint, p->byMarried);
  2334.     marriage::CManager::instance().Update(p->dwPID1, p->dwPID2, p->iLovePoint, p->byMarried);
  2335. }
  2336.  
  2337. void CClientManager::MarriageRemove(TPacketMarriageRemove * p)
  2338. {
  2339.     sys_log(0, "MarriageRemove %u %u", p->dwPID1, p->dwPID2);
  2340.     marriage::CManager::instance().Remove(p->dwPID1, p->dwPID2);
  2341. }
  2342.  
  2343. void CClientManager::WeddingRequest(TPacketWeddingRequest * p)
  2344. {
  2345.     sys_log(0, "WeddingRequest %u %u", p->dwPID1, p->dwPID2);
  2346.     ForwardPacket(HEADER_DG_WEDDING_REQUEST, p, sizeof(TPacketWeddingRequest));
  2347.     //marriage::CManager::instance().RegisterWedding(p->dwPID1, p->szName1, p->dwPID2, p->szName2);
  2348. }
  2349.  
  2350. void CClientManager::WeddingReady(TPacketWeddingReady * p)
  2351. {
  2352.     sys_log(0, "WeddingReady %u %u", p->dwPID1, p->dwPID2);
  2353.     ForwardPacket(HEADER_DG_WEDDING_READY, p, sizeof(TPacketWeddingReady));
  2354.     marriage::CManager::instance().ReadyWedding(p->dwMapIndex, p->dwPID1, p->dwPID2);
  2355. }
  2356.  
  2357. void CClientManager::WeddingEnd(TPacketWeddingEnd * p)
  2358. {
  2359.     sys_log(0, "WeddingEnd %u %u", p->dwPID1, p->dwPID2);
  2360.     marriage::CManager::instance().EndWedding(p->dwPID1, p->dwPID2);
  2361. }
  2362.  
  2363. //
  2364. // Äł˝Ăżˇ °ˇ°ÝÁ¤ş¸°ˇ ŔÖŔ¸¸é Äł˝Ă¸¦ ľ÷µĄŔĚĆ® ÇĎ°í Äł˝Ăżˇ °ˇ°ÝÁ¤ş¸°ˇ ľř´Ů¸é
  2365. // żěĽ± ±âÁ¸ŔÇ µĄŔĚĹ͸¦ ·ÎµĺÇŃ µÚżˇ ±âÁ¸ŔÇ Á¤ş¸·Î Äł˝Ă¸¦ ¸¸µé°í »ő·Î ąŢŔş °ˇ°ÝÁ¤ş¸¸¦ ľ÷µĄŔĚĆ® ÇŃ´Ů.
  2366. //
  2367. void CClientManager::MyshopPricelistUpdate(const TItemPriceListTable* pPacket) // @fixme403 (TPacketMyshopPricelistHeader to TItemPriceListTable)
  2368. {
  2369.     if (pPacket->byCount > SHOP_PRICELIST_MAX_NUM)
  2370.     {
  2371.         sys_err("count overflow!");
  2372.         return;
  2373.     }
  2374.  
  2375.     CItemPriceListTableCache* pCache = GetItemPriceListCache(pPacket->dwOwnerID);
  2376.  
  2377.     if (pCache)
  2378.     {
  2379.         TItemPriceListTable table;
  2380.  
  2381.         table.dwOwnerID = pPacket->dwOwnerID;
  2382.         table.byCount = pPacket->byCount;
  2383.  
  2384.         thecore_memcpy(table.aPriceInfo, pPacket->aPriceInfo, sizeof(TItemPriceInfo) * pPacket->byCount);
  2385.  
  2386.         pCache->UpdateList(&table);
  2387.     }
  2388.     else
  2389.     {
  2390.         TItemPriceListTable* pUpdateTable = new TItemPriceListTable;
  2391.  
  2392.         pUpdateTable->dwOwnerID = pPacket->dwOwnerID;
  2393.         pUpdateTable->byCount = pPacket->byCount;
  2394.  
  2395.         thecore_memcpy(pUpdateTable->aPriceInfo, pPacket->aPriceInfo, sizeof(TItemPriceInfo) * pPacket->byCount);
  2396.  
  2397.         char szQuery[QUERY_MAX_LEN];
  2398.         snprintf(szQuery, sizeof(szQuery), "SELECT item_vnum, price FROM myshop_pricelist%s WHERE owner_id=%u", GetTablePostfix(), pPacket->dwOwnerID);
  2399.         CDBManager::instance().ReturnQuery(szQuery, QID_ITEMPRICE_LOAD_FOR_UPDATE, 0, pUpdateTable);
  2400.     }
  2401. }
  2402.  
  2403. // MYSHOP_PRICE_LIST
  2404. // Äł˝ĂµČ °ˇ°ÝÁ¤ş¸°ˇ ŔÖŔ¸¸é Äł˝Ă¸¦ ŔĐľî ąŮ·Î ŔüĽŰÇĎ°í Äł˝Ăżˇ Á¤ş¸°ˇ ľřŔ¸¸é DB żˇ Äő¸®¸¦ ÇŃ´Ů.
  2405. //
  2406. void CClientManager::MyshopPricelistRequest(CPeer* peer, DWORD dwHandle, DWORD dwPlayerID)
  2407. {
  2408.     if (CItemPriceListTableCache* pCache = GetItemPriceListCache(dwPlayerID))
  2409.     {
  2410.         sys_log(0, "Cache MyShopPricelist handle[%d] pid[%d]", dwHandle, dwPlayerID);
  2411.  
  2412.         TItemPriceListTable* pTable = pCache->Get(false);
  2413.  
  2414.         TPacketMyshopPricelistHeader header =
  2415.         {
  2416.             pTable->dwOwnerID,
  2417.             pTable->byCount
  2418.         };
  2419.  
  2420.         size_t sizePriceListSize = sizeof(TItemPriceInfo) * pTable->byCount;
  2421.  
  2422.         peer->EncodeHeader(HEADER_DG_MYSHOP_PRICELIST_RES, dwHandle, sizeof(header) + sizePriceListSize);
  2423.         peer->Encode(&header, sizeof(header));
  2424.         peer->Encode(pTable->aPriceInfo, sizePriceListSize);
  2425.  
  2426.     }
  2427.     else
  2428.     {
  2429.         sys_log(0, "Query MyShopPricelist handle[%d] pid[%d]", dwHandle, dwPlayerID);
  2430.  
  2431.         char szQuery[QUERY_MAX_LEN];
  2432.         snprintf(szQuery, sizeof(szQuery), "SELECT item_vnum, price FROM myshop_pricelist%s WHERE owner_id=%u", GetTablePostfix(), dwPlayerID);
  2433.         CDBManager::instance().ReturnQuery(szQuery, QID_ITEMPRICE_LOAD, peer->GetHandle(), new TItemPricelistReqInfo(dwHandle, dwPlayerID));
  2434.     }
  2435. }
  2436. // END_OF_MYSHOP_PRICE_LIST
  2437.  
  2438. void CPacketInfo::Add(int header)
  2439. {
  2440.     itertype(m_map_info) it = m_map_info.find(header);
  2441.  
  2442.     if (it == m_map_info.end())
  2443.         m_map_info.insert(std::map<int, int>::value_type(header, 1));
  2444.     else
  2445.         ++it->second;
  2446. }
  2447.  
  2448. void CPacketInfo::Reset()
  2449. {
  2450.     m_map_info.clear();
  2451. }
  2452.  
  2453. void CClientManager::ProcessPackets(CPeer * peer)
  2454. {
  2455.     BYTE        header;
  2456.     DWORD       dwHandle;
  2457.     DWORD       dwLength;
  2458.     const char * data = NULL;
  2459.     int         i = 0;
  2460.     int         iCount = 0;
  2461.  
  2462.     while (peer->PeekPacket(i, header, dwHandle, dwLength, &data))
  2463.     {
  2464.         // DISABLE_DB_HEADER_LOG
  2465.         // sys_log(0, "header %d %p size %d", header, this, dwLength);
  2466.         // END_OF_DISABLE_DB_HEADER_LOG
  2467.         m_bLastHeader = header;
  2468.         ++iCount;
  2469.  
  2470. #ifdef _TEST
  2471.         if (header != 10)
  2472.             sys_log(0, " ProcessPacket Header [%d] Handle[%d] Length[%d] iCount[%d]", header, dwHandle, dwLength, iCount);
  2473. #endif
  2474.         if (g_test_server)
  2475.         {
  2476.             if (header != 10)
  2477.                 sys_log(0, " ProcessPacket Header [%d] Handle[%d] Length[%d] iCount[%d]", header, dwHandle, dwLength, iCount);
  2478.         }
  2479.  
  2480.  
  2481.         // test log by mhh
  2482.         {
  2483.             if (HEADER_GD_BLOCK_COUNTRY_IP == header)
  2484.                 sys_log(0, "recved : HEADER_GD_BLOCK_COUNTRY_IP");
  2485.         }
  2486.  
  2487.         switch (header)
  2488.         {
  2489.             case HEADER_GD_BOOT:
  2490.                 QUERY_BOOT(peer, (TPacketGDBoot *) data);
  2491.                 break;
  2492.  
  2493.             case HEADER_GD_HAMMER_OF_TOR:
  2494.                 break;
  2495.  
  2496.             case HEADER_GD_LOGIN_BY_KEY:
  2497.                 QUERY_LOGIN_BY_KEY(peer, dwHandle, (TPacketGDLoginByKey *) data);
  2498.                 break;
  2499.  
  2500.             case HEADER_GD_LOGOUT:
  2501.                 //sys_log(0, "HEADER_GD_LOGOUT (handle: %d length: %d)", dwHandle, dwLength);
  2502.                 QUERY_LOGOUT(peer, dwHandle, data);
  2503.                 break;
  2504.  
  2505.             case HEADER_GD_PLAYER_LOAD:
  2506.                 sys_log(1, "HEADER_GD_PLAYER_LOAD (handle: %d length: %d)", dwHandle, dwLength);
  2507.                 QUERY_PLAYER_LOAD(peer, dwHandle, (TPlayerLoadPacket *) data);
  2508. #ifdef __SKILL_COLOR_SYSTEM__
  2509.                 QUERY_SKILL_COLOR_LOAD(peer, dwHandle, (TPlayerLoadPacket*)data);
  2510. #endif
  2511.                 break;
  2512.  
  2513.             case HEADER_GD_PLAYER_SAVE:
  2514.                 sys_log(1, "HEADER_GD_PLAYER_SAVE (handle: %d length: %d)", dwHandle, dwLength);
  2515.                 QUERY_PLAYER_SAVE(peer, dwHandle, (TPlayerTable *) data);
  2516.                 break;
  2517.  
  2518.             case HEADER_GD_PLAYER_CREATE:
  2519.                 sys_log(0, "HEADER_GD_PLAYER_CREATE (handle: %d length: %d)", dwHandle, dwLength);
  2520.                 __QUERY_PLAYER_CREATE(peer, dwHandle, (TPlayerCreatePacket *) data);
  2521.                 sys_log(0, "END");
  2522.                 break;
  2523.  
  2524.             case HEADER_GD_PLAYER_DELETE:
  2525.                 sys_log(1, "HEADER_GD_PLAYER_DELETE (handle: %d length: %d)", dwHandle, dwLength);
  2526.                 __QUERY_PLAYER_DELETE(peer, dwHandle, (TPlayerDeletePacket *) data);
  2527.                 break;
  2528.  
  2529.             case HEADER_GD_PLAYER_COUNT:
  2530.                 QUERY_PLAYER_COUNT(peer, (TPlayerCountPacket *) data);
  2531.                 break;
  2532.  
  2533.             case HEADER_GD_QUEST_SAVE:
  2534.                 sys_log(1, "HEADER_GD_QUEST_SAVE (handle: %d length: %d)", dwHandle, dwLength);
  2535.                 QUERY_QUEST_SAVE(peer, (TQuestTable *) data, dwLength);
  2536.                 break;
  2537.  
  2538.             case HEADER_GD_SAFEBOX_LOAD:
  2539.                 QUERY_SAFEBOX_LOAD(peer, dwHandle, (TSafeboxLoadPacket *) data, 0);
  2540.                 break;
  2541.  
  2542.             case HEADER_GD_SAFEBOX_SAVE:
  2543.                 sys_log(1, "HEADER_GD_SAFEBOX_SAVE (handle: %d length: %d)", dwHandle, dwLength);
  2544.                 QUERY_SAFEBOX_SAVE(peer, (TSafeboxTable *) data);
  2545.                 break;
  2546.  
  2547.             case HEADER_GD_SAFEBOX_CHANGE_SIZE:
  2548.                 QUERY_SAFEBOX_CHANGE_SIZE(peer, dwHandle, (TSafeboxChangeSizePacket *) data);
  2549.                 break;
  2550.  
  2551.             case HEADER_GD_SAFEBOX_CHANGE_PASSWORD:
  2552.                 QUERY_SAFEBOX_CHANGE_PASSWORD(peer, dwHandle, (TSafeboxChangePasswordPacket *) data);
  2553.                 break;
  2554.  
  2555.             case HEADER_GD_MALL_LOAD:
  2556.                 QUERY_SAFEBOX_LOAD(peer, dwHandle, (TSafeboxLoadPacket *) data, 1);
  2557.                 break;
  2558.  
  2559.             case HEADER_GD_EMPIRE_SELECT:
  2560.                 QUERY_EMPIRE_SELECT(peer, dwHandle, (TEmpireSelectPacket *) data);
  2561.                 break;
  2562.  
  2563.             case HEADER_GD_SETUP:
  2564.                 QUERY_SETUP(peer, dwHandle, data);
  2565.                 break;
  2566.  
  2567.             case HEADER_GD_GUILD_CREATE:
  2568.                 GuildCreate(peer, *(DWORD *) data);
  2569.                 break;
  2570.  
  2571.             case HEADER_GD_GUILD_SKILL_UPDATE:
  2572.                 GuildSkillUpdate(peer, (TPacketGuildSkillUpdate *) data);
  2573.                 break;
  2574.  
  2575.             case HEADER_GD_GUILD_EXP_UPDATE:
  2576.                 GuildExpUpdate(peer, (TPacketGuildExpUpdate *) data);
  2577.                 break;
  2578.  
  2579.             case HEADER_GD_GUILD_ADD_MEMBER:
  2580.                 GuildAddMember(peer, (TPacketGDGuildAddMember*) data);
  2581.                 break;
  2582.  
  2583.             case HEADER_GD_GUILD_REMOVE_MEMBER:
  2584.                 GuildRemoveMember(peer, (TPacketGuild*) data);
  2585.                 break;
  2586.  
  2587.             case HEADER_GD_GUILD_CHANGE_GRADE:
  2588.                 GuildChangeGrade(peer, (TPacketGuild*) data);
  2589.                 break;
  2590.  
  2591.             case HEADER_GD_GUILD_CHANGE_MEMBER_DATA:
  2592.                 GuildChangeMemberData(peer, (TPacketGuildChangeMemberData*) data);
  2593.                 break;
  2594.  
  2595.             case HEADER_GD_GUILD_DISBAND:
  2596.                 GuildDisband(peer, (TPacketGuild*) data);
  2597.                 break;
  2598.  
  2599.             case HEADER_GD_GUILD_WAR:
  2600.                 GuildWar(peer, (TPacketGuildWar*) data);
  2601.                 break;
  2602.  
  2603.             case HEADER_GD_GUILD_WAR_SCORE:
  2604.                 GuildWarScore(peer, (TPacketGuildWarScore*) data);
  2605.                 break;
  2606.  
  2607.             case HEADER_GD_GUILD_CHANGE_LADDER_POINT:
  2608.                 GuildChangeLadderPoint((TPacketGuildLadderPoint*) data);
  2609.                 break;
  2610.  
  2611.             case HEADER_GD_GUILD_USE_SKILL:
  2612.                 GuildUseSkill((TPacketGuildUseSkill*) data);
  2613.                 break;
  2614.  
  2615.             case HEADER_GD_FLUSH_CACHE:
  2616.                 QUERY_FLUSH_CACHE(peer, data);
  2617.                 break;
  2618.  
  2619.             case HEADER_GD_ITEM_SAVE:
  2620.                 QUERY_ITEM_SAVE(peer, data);
  2621.                 break;
  2622.  
  2623.             case HEADER_GD_ITEM_DESTROY:
  2624.                 QUERY_ITEM_DESTROY(peer, data);
  2625.                 break;
  2626.  
  2627.             case HEADER_GD_ITEM_FLUSH:
  2628.                 QUERY_ITEM_FLUSH(peer, data);
  2629.                 break;
  2630.  
  2631.             case HEADER_GD_ADD_AFFECT:
  2632.                 sys_log(1, "HEADER_GD_ADD_AFFECT");
  2633.                 QUERY_ADD_AFFECT(peer, (TPacketGDAddAffect *) data);
  2634.                 break;
  2635.  
  2636.             case HEADER_GD_REMOVE_AFFECT:
  2637.                 sys_log(1, "HEADER_GD_REMOVE_AFFECT");
  2638.                 QUERY_REMOVE_AFFECT(peer, (TPacketGDRemoveAffect *) data);
  2639.                 break;
  2640.  
  2641.             case HEADER_GD_HIGHSCORE_REGISTER:
  2642.                 QUERY_HIGHSCORE_REGISTER(peer, (TPacketGDHighscore *) data);
  2643.                 break;
  2644.  
  2645.             case HEADER_GD_PARTY_CREATE:
  2646.                 QUERY_PARTY_CREATE(peer, (TPacketPartyCreate*) data);
  2647.                 break;
  2648.  
  2649.             case HEADER_GD_PARTY_DELETE:
  2650.                 QUERY_PARTY_DELETE(peer, (TPacketPartyDelete*) data);
  2651.                 break;
  2652.  
  2653.             case HEADER_GD_PARTY_ADD:
  2654.                 QUERY_PARTY_ADD(peer, (TPacketPartyAdd*) data);
  2655.                 break;
  2656.  
  2657.             case HEADER_GD_PARTY_REMOVE:
  2658.                 QUERY_PARTY_REMOVE(peer, (TPacketPartyRemove*) data);
  2659.                 break;
  2660.  
  2661.             case HEADER_GD_PARTY_STATE_CHANGE:
  2662.                 QUERY_PARTY_STATE_CHANGE(peer, (TPacketPartyStateChange*) data);
  2663.                 break;
  2664.  
  2665.             case HEADER_GD_PARTY_SET_MEMBER_LEVEL:
  2666.                 QUERY_PARTY_SET_MEMBER_LEVEL(peer, (TPacketPartySetMemberLevel*) data);
  2667.                 break;
  2668.  
  2669.             case HEADER_GD_RELOAD_PROTO:
  2670.                 QUERY_RELOAD_PROTO();
  2671.                 break;
  2672.  
  2673.             case HEADER_GD_CHANGE_NAME:
  2674.                 QUERY_CHANGE_NAME(peer, dwHandle, (TPacketGDChangeName *) data);
  2675.                 break;
  2676.  
  2677.             case HEADER_GD_SMS:
  2678.                 QUERY_SMS(peer, (TPacketGDSMS *) data);
  2679.                 break;
  2680.  
  2681.             case HEADER_GD_AUTH_LOGIN:
  2682.                 QUERY_AUTH_LOGIN(peer, dwHandle, (TPacketGDAuthLogin *) data);
  2683.                 break;
  2684.  
  2685.             case HEADER_GD_REQUEST_GUILD_PRIV:
  2686.                 AddGuildPriv((TPacketGiveGuildPriv*)data);
  2687.                 break;
  2688.  
  2689.             case HEADER_GD_REQUEST_EMPIRE_PRIV:
  2690.                 AddEmpirePriv((TPacketGiveEmpirePriv*)data);
  2691.                 break;
  2692.  
  2693.             case HEADER_GD_REQUEST_CHARACTER_PRIV:
  2694.                 AddCharacterPriv((TPacketGiveCharacterPriv*) data);
  2695.                 break;
  2696.  
  2697.             case HEADER_GD_MONEY_LOG:
  2698.                 MoneyLog((TPacketMoneyLog*)data);
  2699.                 break;
  2700.  
  2701.             case HEADER_GD_GUILD_DEPOSIT_MONEY:
  2702.                 GuildDepositMoney((TPacketGDGuildMoney*)data);
  2703.                 break;
  2704.  
  2705.             case HEADER_GD_GUILD_WITHDRAW_MONEY:
  2706.                 GuildWithdrawMoney(peer, (TPacketGDGuildMoney*)data);
  2707.                 break;
  2708.  
  2709.             case HEADER_GD_GUILD_WITHDRAW_MONEY_GIVE_REPLY:
  2710.                 GuildWithdrawMoneyGiveReply((TPacketGDGuildMoneyWithdrawGiveReply*)data);
  2711.                 break;
  2712.  
  2713.             case HEADER_GD_GUILD_WAR_BET:
  2714.                 GuildWarBet((TPacketGDGuildWarBet *) data);
  2715.                 break;
  2716.  
  2717.             case HEADER_GD_SET_EVENT_FLAG:
  2718.                 SetEventFlag((TPacketSetEventFlag*) data);
  2719.                 break;
  2720.  
  2721.             case HEADER_GD_BILLING_EXPIRE:
  2722.                 BillingExpire((TPacketBillingExpire *) data);
  2723.                 break;
  2724.  
  2725.             case HEADER_GD_BILLING_CHECK:
  2726.                 BillingCheck(data);
  2727.                 break;
  2728.  
  2729.             case HEADER_GD_CREATE_OBJECT:
  2730.                 CreateObject((TPacketGDCreateObject *) data);
  2731.                 break;
  2732.  
  2733.             case HEADER_GD_DELETE_OBJECT:
  2734.                 DeleteObject(*(DWORD *) data);
  2735.                 break;
  2736.  
  2737.             case HEADER_GD_UPDATE_LAND:
  2738.                 UpdateLand((DWORD *) data);
  2739.                 break;
  2740.  
  2741.             case HEADER_GD_VCARD:
  2742.                 VCard((TPacketGDVCard *) data);
  2743.                 break;
  2744.  
  2745.             case HEADER_GD_MARRIAGE_ADD:
  2746.                 MarriageAdd((TPacketMarriageAdd *) data);
  2747.                 break;
  2748.  
  2749.             case HEADER_GD_MARRIAGE_UPDATE:
  2750.                 MarriageUpdate((TPacketMarriageUpdate *) data);
  2751.                 break;
  2752.  
  2753.             case HEADER_GD_MARRIAGE_REMOVE:
  2754.                 MarriageRemove((TPacketMarriageRemove *) data);
  2755.                 break;
  2756.  
  2757.             case HEADER_GD_WEDDING_REQUEST:
  2758.                 WeddingRequest((TPacketWeddingRequest *) data);
  2759.                 break;
  2760.  
  2761.             case HEADER_GD_WEDDING_READY:
  2762.                 WeddingReady((TPacketWeddingReady *) data);
  2763.                 break;
  2764.  
  2765.             case HEADER_GD_WEDDING_END:
  2766.                 WeddingEnd((TPacketWeddingEnd *) data);
  2767.                 break;
  2768.  
  2769.                 // BLOCK_CHAT
  2770.             case HEADER_GD_BLOCK_CHAT:
  2771.                 BlockChat((TPacketBlockChat *) data);
  2772.                 break;
  2773.                 // END_OF_BLOCK_CHAT
  2774.  
  2775.                 // MYSHOP_PRICE_LIST
  2776.             case HEADER_GD_MYSHOP_PRICELIST_UPDATE:
  2777.                 MyshopPricelistUpdate((TItemPriceListTable*)data); // @fixme403 (TPacketMyshopPricelistHeader to TItemPriceListTable)
  2778.                 break;
  2779.  
  2780.             case HEADER_GD_MYSHOP_PRICELIST_REQ:
  2781.                 MyshopPricelistRequest(peer, dwHandle, *(DWORD*)data);
  2782.                 break;
  2783.                 // END_OF_MYSHOP_PRICE_LIST
  2784.  
  2785.                 //RELOAD_ADMIN
  2786.             case HEADER_GD_RELOAD_ADMIN:
  2787.                 ReloadAdmin(peer, (TPacketReloadAdmin*)data);
  2788.                 break;
  2789.                 //END_RELOAD_ADMIN
  2790.  
  2791.             case HEADER_GD_BREAK_MARRIAGE:
  2792.                 BreakMarriage(peer, data);
  2793.                 break;
  2794.  
  2795.             //MOANRCH
  2796.             case HEADER_GD_ELECT_MONARCH:
  2797.                 Election(peer, dwHandle, data);
  2798.                 break;
  2799.  
  2800.             case HEADER_GD_CANDIDACY:
  2801.                 Candidacy(peer, dwHandle, data);
  2802.                 break;
  2803.  
  2804.             case HEADER_GD_ADD_MONARCH_MONEY:
  2805.                 AddMonarchMoney(peer, dwHandle, data);
  2806.                 break;
  2807.  
  2808.             case HEADER_GD_DEC_MONARCH_MONEY:
  2809.                 DecMonarchMoney(peer, dwHandle, data);
  2810.                 break;
  2811.  
  2812.             case HEADER_GD_TAKE_MONARCH_MONEY:
  2813.                 TakeMonarchMoney(peer, dwHandle, data);
  2814.                 break;
  2815.  
  2816.             case HEADER_GD_COME_TO_VOTE:
  2817.                 ComeToVote(peer, dwHandle, data);
  2818.                 break;
  2819.  
  2820.             case HEADER_GD_RMCANDIDACY:     //< ČÄş¸ Á¦°Ĺ (żîżµŔÚ)
  2821.                 RMCandidacy(peer, dwHandle, data);
  2822.                 break;
  2823.  
  2824.             case HEADER_GD_SETMONARCH:      ///<±şÁÖĽłÁ¤ (żîżµŔÚ)
  2825.                 SetMonarch(peer, dwHandle, data);
  2826.                 break;
  2827.  
  2828.             case HEADER_GD_RMMONARCH:       ///<±şÁÖ»čÁ¦
  2829.                 RMMonarch(peer, dwHandle, data);
  2830.                 break;
  2831.             //END_MONARCH
  2832.  
  2833.             case HEADER_GD_CHANGE_MONARCH_LORD :
  2834.                 ChangeMonarchLord(peer, dwHandle, (TPacketChangeMonarchLord*)data);
  2835.                 break;
  2836.  
  2837.             case HEADER_GD_BLOCK_COUNTRY_IP:
  2838.                 sys_log(0, "HEADER_GD_BLOCK_COUNTRY_IP received");
  2839.                 CBlockCountry::instance().SendBlockedCountryIp(peer);
  2840.                 CBlockCountry::instance().SendBlockException(peer);
  2841.                 break;
  2842.  
  2843.             case HEADER_GD_BLOCK_EXCEPTION:
  2844.                 sys_log(0, "HEADER_GD_BLOCK_EXCEPTION received");
  2845.                 BlockException((TPacketBlockException*) data);
  2846.                 break;
  2847.  
  2848.             case HEADER_GD_REQ_SPARE_ITEM_ID_RANGE :
  2849.                 SendSpareItemIDRange(peer);
  2850.                 break;
  2851.  
  2852.             case HEADER_GD_REQ_CHANGE_GUILD_MASTER :
  2853.                 GuildChangeMaster((TPacketChangeGuildMaster*) data);
  2854.                 break;
  2855.  
  2856.             case HEADER_GD_UPDATE_HORSE_NAME :
  2857.                 UpdateHorseName((TPacketUpdateHorseName*) data, peer);
  2858.                 break;
  2859.  
  2860.             case HEADER_GD_REQ_HORSE_NAME :
  2861.                 AckHorseName(*(DWORD*)data, peer);
  2862.                 break;
  2863.  
  2864.             case HEADER_GD_DC:
  2865.                 DeleteLoginKey((TPacketDC*) data);
  2866.                 break;
  2867.  
  2868.             case HEADER_GD_VALID_LOGOUT:
  2869.                 ResetLastPlayerID((TPacketNeedLoginLogInfo*)data);
  2870.                 break;
  2871.  
  2872.             case HEADER_GD_REQUEST_CHARGE_CASH:
  2873.                 ChargeCash((TRequestChargeCash*)data);
  2874.                 break;
  2875.  
  2876.             //delete gift notify icon
  2877.  
  2878.             case HEADER_GD_DELETE_AWARDID:
  2879.                 DeleteAwardId((TPacketDeleteAwardID*) data);
  2880.                 break;
  2881.  
  2882.             case HEADER_GD_UPDATE_CHANNELSTATUS:
  2883.                 UpdateChannelStatus((SChannelStatus*) data);
  2884.                 break;
  2885.             case HEADER_GD_REQUEST_CHANNELSTATUS:
  2886.                 RequestChannelStatus(peer, dwHandle);
  2887.                 break;
  2888. #ifdef __AUCTION__
  2889.             case HEADER_GD_COMMAND_AUCTION:
  2890.             {
  2891.                 TPacketGDCommnadAuction* auction_data = (TPacketGDCommnadAuction*)data;
  2892.  
  2893.                 switch (auction_data->get_cmd())
  2894.                 {
  2895.                 case AUCTION_ENR_AUC:
  2896.                     EnrollInAuction (peer, dwHandle, (AuctionEnrollProductInfo*)data);
  2897.                     break;
  2898.                 case AUCTION_ENR_SALE:
  2899.                     EnrollInSale (peer, dwHandle, (AuctionEnrollSaleInfo*)data);
  2900.                     break;
  2901.                 case AUCTION_ENR_WISH:
  2902.                     EnrollInWish (peer, dwHandle, (AuctionEnrollWishInfo*)data);
  2903.                     break;
  2904.                 case AUCTION_BID:
  2905.                     AuctionBid (peer, dwHandle, (AuctionBidInfo*)data);
  2906.                     break;
  2907.                 case AUCTION_IMME_PUR:
  2908.                     AuctionImpur (peer, dwHandle, (AuctionImpurInfo*)data);
  2909.                     break;
  2910.                 case AUCTION_GET_AUC:
  2911.                     AuctionGetAuctionedItem (peer, dwHandle, auction_data->get_item());
  2912.                     break;
  2913.                 case AUCTION_BUY_SOLD:
  2914.                     AuctionBuySoldItem (peer, dwHandle, auction_data->get_item());
  2915.                     break;
  2916.                 case AUCTION_CANCEL_AUC:
  2917.                     AuctionCancelAuction (peer, dwHandle, auction_data->get_item());
  2918.                     break;
  2919.                 case AUCTION_CANCEL_WISH:
  2920.                     AuctionCancelWish (peer, dwHandle, auction_data->get_item());
  2921.                     break;
  2922.                 case AUCTION_CANCEL_SALE:
  2923.                     AuctionCancelSale (peer, dwHandle, auction_data->get_item());
  2924.                     break;
  2925.                 case AUCTION_DELETE_AUCTION_ITEM:
  2926.                     AuctionDeleteAuctionItem (peer, dwHandle, auction_data->get_item());
  2927.                     break;
  2928.                 case AUCTION_DELETE_SALE_ITEM:
  2929.                     AuctionDeleteSaleItem (peer, dwHandle, auction_data->get_item());
  2930.                     break;
  2931.                 case AUCTION_REBID:
  2932.                     AuctionReBid (peer, dwHandle, (AuctionBidInfo*)data);
  2933.                     break;
  2934. //              case AUCTION_BID_CANCEL:
  2935. //                  AuctionBidCancel (peer, dwHandle, data->get_item());
  2936.                 default :
  2937.                     break;
  2938.                 }
  2939.             }
  2940.             break;
  2941. #endif
  2942. #ifdef __ENABLE_NEW_OFFLINESHOP__
  2943.             case HEADER_GD_NEW_OFFLINESHOP:
  2944.                 RecvOfflineShopPacket(peer, data);
  2945.                 break;
  2946. #endif
  2947.  
  2948. #ifdef __SKILL_COLOR_SYSTEM__
  2949.             case HEADER_GD_SKILL_COLOR_SAVE:
  2950.                 QUERY_SKILL_COLOR_SAVE(data);
  2951.                 break;
  2952. #endif
  2953.  
  2954.             default:
  2955.                 sys_err("Unknown header (header: %d handle: %d length: %d)", header, dwHandle, dwLength);
  2956.                 break;
  2957.         }
  2958.     }
  2959.  
  2960.     peer->RecvEnd(i);
  2961. }
  2962.  
  2963. void CClientManager::AddPeer(socket_t fd)
  2964. {
  2965.     CPeer * pPeer = new CPeer;
  2966.  
  2967.     if (pPeer->Accept(fd))
  2968.         m_peerList.push_front(pPeer);
  2969.     else
  2970.         delete pPeer;
  2971. }
  2972.  
  2973. void CClientManager::RemovePeer(CPeer * pPeer)
  2974. {
  2975.     if (m_pkAuthPeer == pPeer)
  2976.     {
  2977.         m_pkAuthPeer = NULL;
  2978.     }
  2979.     else
  2980.     {
  2981.         TLogonAccountMap::iterator it = m_map_kLogonAccount.begin();
  2982.  
  2983.         while (it != m_map_kLogonAccount.end())
  2984.         {
  2985.             CLoginData * pkLD = it->second;
  2986.  
  2987.             if (pkLD->GetConnectedPeerHandle() == pPeer->GetHandle())
  2988.             {
  2989.                 if (pkLD->IsPlay())
  2990.                 {
  2991.                     pkLD->SetPlay(false);
  2992.                     SendLoginToBilling(pkLD, false);
  2993.                 }
  2994.  
  2995.                 if (pkLD->IsDeleted())
  2996.                 {
  2997.                     sys_log(0, "DELETING LoginData");
  2998.                     delete pkLD;
  2999.                 }
  3000.  
  3001.                 m_map_kLogonAccount.erase(it++);
  3002.             }
  3003.             else
  3004.                 ++it;
  3005.         }
  3006.     }
  3007.  
  3008.     m_peerList.remove(pPeer);
  3009.     delete pPeer;
  3010. }
  3011.  
  3012. CPeer * CClientManager::GetPeer(IDENT ident)
  3013. {
  3014.     for (itertype(m_peerList) i = m_peerList.begin(); i != m_peerList.end();++i)
  3015.     {
  3016.         CPeer * tmp = *i;
  3017.  
  3018.         if (tmp->GetHandle() == ident)
  3019.             return tmp;
  3020.     }
  3021.  
  3022.     return NULL;
  3023. }
  3024.  
  3025. CPeer * CClientManager::GetAnyPeer()
  3026. {
  3027.     if (m_peerList.empty())
  3028.         return NULL;
  3029.  
  3030.     return m_peerList.front();
  3031. }
  3032.  
  3033. // DB ¸Ĺ´ĎŔú·Î şÎĹÍ ąŢŔş °á°ú¸¦ Ăł¸®ÇŃ´Ů.
  3034. //
  3035. // @version 05/06/10 Bang2ni - °ˇ°ÝÁ¤ş¸ °ü·Ă Äő¸®(QID_ITEMPRICE_XXX) Ăß°ˇ
  3036. int CClientManager::AnalyzeQueryResult(SQLMsg * msg)
  3037. {
  3038.     CQueryInfo * qi = (CQueryInfo *) msg->pvUserData;
  3039.     CPeer * peer = GetPeer(qi->dwIdent);
  3040.  
  3041. #ifdef _TEST
  3042.     if (qi->iType != QID_ITEM_AWARD_LOAD)
  3043.     sys_log(0, "AnalyzeQueryResult %d", qi->iType);
  3044. #endif
  3045.     switch (qi->iType)
  3046.     {
  3047.         case QID_ITEM_AWARD_LOAD:
  3048.             ItemAwardManager::instance().Load(msg);
  3049.             delete qi;
  3050.             return true;
  3051.  
  3052.         case QID_GUILD_RANKING:
  3053.             CGuildManager::instance().ResultRanking(msg->Get()->pSQLResult);
  3054.             break;
  3055.  
  3056.             // MYSHOP_PRICE_LIST
  3057.         case QID_ITEMPRICE_LOAD_FOR_UPDATE:
  3058.             RESULT_PRICELIST_LOAD_FOR_UPDATE(msg);
  3059.             break;
  3060.             // END_OF_MYSHOP_PRICE_LIST
  3061.     }
  3062.  
  3063.     if (!peer)
  3064.     {
  3065. #ifdef __ENABLE_NEW_OFFLINESHOP__
  3066.         switch (qi->iType)
  3067.         {
  3068.         case QID_OFFLINESHOP_ADD_ITEM:
  3069.         case QID_OFFLINESHOP_EDIT_ITEM:
  3070.         case QID_OFFLINESHOP_DELETE_SHOP:
  3071.         case QID_OFFLINESHOP_DELETE_SHOP_ITEM:
  3072.         case QID_OFFLINESHOP_REMOVE_ITEM:
  3073.         case QID_OFFLINESHOP_UPDATE_SOLD_ITEM:
  3074.         case QID_OFFLINESHOP_CREATE_SHOP:
  3075.         case QID_OFFLINESHOP_CREATE_SHOP_ADD_ITEM:
  3076.         case QID_OFFLINESHOP_SHOP_CHANGE_NAME:
  3077.         case QID_OFFLINESHOP_SHOP_UPDATE_DURATION:
  3078.         case QID_OFFLINESHOP_SAFEBOX_DELETE_ITEM:
  3079.         case QID_OFFLINESHOP_SAFEBOX_ADD_ITEM:
  3080.         case QID_OFFLINESHOP_SAFEBOX_UPDATE_VALUTES:
  3081.         case QID_OFFLINESHOP_SAFEBOX_INSERT_VALUTES:
  3082.         case QID_OFFLINESHOP_SAFEBOX_UPDATE_VALUTES_ADDING:
  3083.         case QID_OFFLINESHOP_OFFER_ADD:
  3084.         case QID_OFFLINESHOP_OFFER_UPDATE_NOTIFIED:
  3085.         case QID_OFFLINESHOP_OFFER_UPDATE_ACCEPTED:
  3086.         case QID_OFFLINESHOP_OFFER_DELETE_BY_SHOP:
  3087.         case QID_OFFLINESHOP_AUCTION_INSERT:
  3088.         case QID_OFFLINESHOP_AUCTION_INSERT_OFFER:
  3089.         case QID_OFFLINESHOP_AUCTION_DELETE:
  3090.         case QID_OFFLINESHOP_AUCTION_DELETE_OFFERS:
  3091.         case QID_OFFLINESHOP_AUCTION_UPDATE_DURATION:
  3092.             OfflineShopResultQuery(peer, msg, qi);
  3093.             break;
  3094.  
  3095.         default:
  3096.             sys_err("CClientManager::AnalyzeQueryResult: peer not exist anymore. (ident: %d)", qi->dwIdent);
  3097.             break;
  3098.         }
  3099. #endif
  3100.         delete qi;
  3101.         return true;
  3102.     }
  3103.  
  3104.     switch (qi->iType)
  3105.     {
  3106.         case QID_PLAYER:
  3107.         case QID_ITEM:
  3108.         case QID_QUEST:
  3109.         case QID_AFFECT:
  3110. #ifdef __SKILL_COLOR_SYSTEM__
  3111.         case QID_SKILL_COLOR:
  3112. #endif
  3113.             RESULT_COMPOSITE_PLAYER(peer, msg, qi->iType);
  3114.             break;
  3115.  
  3116.         case QID_LOGIN:
  3117.             RESULT_LOGIN(peer, msg);
  3118.             break;
  3119.  
  3120.         case QID_SAFEBOX_LOAD:
  3121.             sys_log(0, "QUERY_RESULT: HEADER_GD_SAFEBOX_LOAD");
  3122.             RESULT_SAFEBOX_LOAD(peer, msg);
  3123.             break;
  3124.  
  3125.         case QID_SAFEBOX_CHANGE_SIZE:
  3126.             sys_log(0, "QUERY_RESULT: HEADER_GD_SAFEBOX_CHANGE_SIZE");
  3127.             RESULT_SAFEBOX_CHANGE_SIZE(peer, msg);
  3128.             break;
  3129.  
  3130.         case QID_SAFEBOX_CHANGE_PASSWORD:
  3131.             sys_log(0, "QUERY_RESULT: HEADER_GD_SAFEBOX_CHANGE_PASSWORD %p", msg);
  3132.             RESULT_SAFEBOX_CHANGE_PASSWORD(peer, msg);
  3133.             break;
  3134.  
  3135.         case QID_SAFEBOX_CHANGE_PASSWORD_SECOND:
  3136.             sys_log(0, "QUERY_RESULT: HEADER_GD_SAFEBOX_CHANGE_PASSWORD %p", msg);
  3137.             RESULT_SAFEBOX_CHANGE_PASSWORD_SECOND(peer, msg);
  3138.             break;
  3139.  
  3140.         case QID_HIGHSCORE_REGISTER:
  3141.             sys_log(0, "QUERY_RESULT: HEADER_GD_HIGHSCORE_REGISTER %p", msg);
  3142.             RESULT_HIGHSCORE_REGISTER(peer, msg);
  3143.             break;
  3144.  
  3145.         case QID_SAFEBOX_SAVE:
  3146.         case QID_ITEM_SAVE:
  3147.         case QID_ITEM_DESTROY:
  3148.         case QID_QUEST_SAVE:
  3149.         case QID_PLAYER_SAVE:
  3150.         case QID_ITEM_AWARD_TAKEN:
  3151. #ifdef __SKILL_COLOR_SYSTEM__
  3152.         case QID_SKILL_COLOR_SAVE:
  3153. #endif
  3154.             break;
  3155.  
  3156.             // PLAYER_INDEX_CREATE_BUG_FIX
  3157.         case QID_PLAYER_INDEX_CREATE:
  3158.             RESULT_PLAYER_INDEX_CREATE(peer, msg);
  3159.             break;
  3160.             // END_PLAYER_INDEX_CREATE_BUG_FIX
  3161.  
  3162.         case QID_PLAYER_DELETE:
  3163.             __RESULT_PLAYER_DELETE(peer, msg);
  3164.             break;
  3165.  
  3166.         case QID_LOGIN_BY_KEY:
  3167.             RESULT_LOGIN_BY_KEY(peer, msg);
  3168.             break;
  3169.  
  3170.             // MYSHOP_PRICE_LIST
  3171.         case QID_ITEMPRICE_LOAD:
  3172.             RESULT_PRICELIST_LOAD(peer, msg);
  3173.             break;
  3174.             // END_OF_MYSHOP_PRICE_LIST
  3175.  
  3176. #ifdef __ENABLE_NEW_OFFLINESHOP__
  3177.         case QID_OFFLINESHOP_ADD_ITEM:
  3178.         case QID_OFFLINESHOP_EDIT_ITEM:
  3179.         case QID_OFFLINESHOP_DELETE_SHOP:
  3180.         case QID_OFFLINESHOP_DELETE_SHOP_ITEM:
  3181.         case QID_OFFLINESHOP_CREATE_SHOP:
  3182.         case QID_OFFLINESHOP_CREATE_SHOP_ADD_ITEM:
  3183.         case QID_OFFLINESHOP_SHOP_CHANGE_NAME:
  3184.         case QID_OFFLINESHOP_SAFEBOX_DELETE_ITEM:
  3185.         case QID_OFFLINESHOP_SAFEBOX_ADD_ITEM:
  3186.         case QID_OFFLINESHOP_REMOVE_ITEM:
  3187.         case QID_OFFLINESHOP_SAFEBOX_UPDATE_VALUTES:
  3188.         case QID_OFFLINESHOP_SAFEBOX_INSERT_VALUTES:
  3189.         case QID_OFFLINESHOP_SAFEBOX_UPDATE_VALUTES_ADDING:
  3190.         case QID_OFFLINESHOP_OFFER_ADD:
  3191.         case QID_OFFLINESHOP_OFFER_UPDATE_NOTIFIED:
  3192.         case QID_OFFLINESHOP_OFFER_UPDATE_ACCEPTED:
  3193.         case QID_OFFLINESHOP_OFFER_DELETE_BY_SHOP:
  3194.         case QID_OFFLINESHOP_AUCTION_INSERT:
  3195.         case QID_OFFLINESHOP_AUCTION_INSERT_OFFER:
  3196.         case QID_OFFLINESHOP_AUCTION_DELETE:
  3197.         case QID_OFFLINESHOP_AUCTION_DELETE_OFFERS:
  3198.         case QID_OFFLINESHOP_AUCTION_UPDATE_DURATION:
  3199.             OfflineShopResultQuery(peer, msg, qi);
  3200.             break;
  3201. #endif
  3202.  
  3203.         default:
  3204.             sys_log(0, "CClientManager::AnalyzeQueryResult unknown query result type: %d, str: %s", qi->iType, msg->stQuery.c_str());
  3205.             break;
  3206.     }
  3207.  
  3208.     delete qi;
  3209.     return true;
  3210. }
  3211.  
  3212. void UsageLog()
  3213. {
  3214.     FILE* fp = NULL;
  3215.  
  3216.     time_t      ct;
  3217.     char        *time_s;
  3218.     struct tm   lt;
  3219.  
  3220.     int         avg = g_dwUsageAvg / 3600; // 60 ĂĘ * 60 şĐ
  3221.  
  3222.     fp = fopen("usage.txt", "a+");
  3223.  
  3224.     if (!fp)
  3225.         return;
  3226.  
  3227.     ct = time(0);
  3228.     lt = *localtime(&ct);
  3229.     time_s = asctime(&lt);
  3230.  
  3231.     time_s[strlen(time_s) - 1] = '\0';
  3232.  
  3233.     fprintf(fp, "| %4d %-15.15s | %5d | %5u |", lt.tm_year + 1900, time_s + 4, avg, g_dwUsageMax);
  3234.  
  3235.     fprintf(fp, "\n");
  3236.     fclose(fp);
  3237.  
  3238.     g_dwUsageMax = g_dwUsageAvg = 0;
  3239. }
  3240.  
  3241. //#define ENABLE_ITEMAWARD_REFRESH
  3242. int CClientManager::Process()
  3243. {
  3244.     int pulses;
  3245.  
  3246.     if (!(pulses = thecore_idle()))
  3247.         return 0;
  3248.  
  3249.     while (pulses--)
  3250.     {
  3251.         ++thecore_heart->pulse;
  3252.  
  3253.         /*
  3254.         //30şĐ¸¶´Ů şŻ°ć
  3255.         if (((thecore_pulse() % (60 * 30 * 10)) == 0))
  3256.         {
  3257.             g_iPlayerCacheFlushSeconds = MAX(60, rand() % 180);
  3258.             g_iItemCacheFlushSeconds = MAX(60, rand() % 180);
  3259.             sys_log(0, "[SAVE_TIME]Change saving time item %d player %d", g_iPlayerCacheFlushSeconds, g_iItemCacheFlushSeconds);
  3260.         }
  3261.         */
  3262.  
  3263.         if (!(thecore_heart->pulse % thecore_heart->passes_per_sec))
  3264.         {
  3265.             if (g_test_server)
  3266.             {
  3267.  
  3268.                 if (!(thecore_heart->pulse % thecore_heart->passes_per_sec * 10))
  3269.  
  3270.                 {
  3271.                     pt_log("[%9d] return %d/%d/%d/%d async %d/%d/%d/%d",
  3272.                             thecore_heart->pulse,
  3273.                             CDBManager::instance().CountReturnQuery(SQL_PLAYER),
  3274.                             CDBManager::instance().CountReturnResult(SQL_PLAYER),
  3275.                             CDBManager::instance().CountReturnQueryFinished(SQL_PLAYER),
  3276.                             CDBManager::instance().CountReturnCopiedQuery(SQL_PLAYER),
  3277.                             CDBManager::instance().CountAsyncQuery(SQL_PLAYER),
  3278.                             CDBManager::instance().CountAsyncResult(SQL_PLAYER),
  3279.                             CDBManager::instance().CountAsyncQueryFinished(SQL_PLAYER),
  3280.                             CDBManager::instance().CountAsyncCopiedQuery(SQL_PLAYER));
  3281.  
  3282.                     if ((thecore_heart->pulse % 50) == 0)
  3283.                         sys_log(0, "[%9d] return %d/%d/%d async %d/%d/%d",
  3284.                                 thecore_heart->pulse,
  3285.                                 CDBManager::instance().CountReturnQuery(SQL_PLAYER),
  3286.                                 CDBManager::instance().CountReturnResult(SQL_PLAYER),
  3287.                                 CDBManager::instance().CountReturnQueryFinished(SQL_PLAYER),
  3288.                                 CDBManager::instance().CountAsyncQuery(SQL_PLAYER),
  3289.                                 CDBManager::instance().CountAsyncResult(SQL_PLAYER),
  3290.                                 CDBManager::instance().CountAsyncQueryFinished(SQL_PLAYER));
  3291.                 }
  3292.             }
  3293.             else
  3294.             {
  3295.                 pt_log("[%9d] return %d/%d/%d/%d async %d/%d/%d%/%d",
  3296.                         thecore_heart->pulse,
  3297.                         CDBManager::instance().CountReturnQuery(SQL_PLAYER),
  3298.                         CDBManager::instance().CountReturnResult(SQL_PLAYER),
  3299.                         CDBManager::instance().CountReturnQueryFinished(SQL_PLAYER),
  3300.                         CDBManager::instance().CountReturnCopiedQuery(SQL_PLAYER),
  3301.                         CDBManager::instance().CountAsyncQuery(SQL_PLAYER),
  3302.                         CDBManager::instance().CountAsyncResult(SQL_PLAYER),
  3303.                         CDBManager::instance().CountAsyncQueryFinished(SQL_PLAYER),
  3304.                         CDBManager::instance().CountAsyncCopiedQuery(SQL_PLAYER));
  3305.  
  3306.                         if ((thecore_heart->pulse % 50) == 0)
  3307.                         sys_log(0, "[%9d] return %d/%d/%d async %d/%d/%d",
  3308.                             thecore_heart->pulse,
  3309.                             CDBManager::instance().CountReturnQuery(SQL_PLAYER),
  3310.                             CDBManager::instance().CountReturnResult(SQL_PLAYER),
  3311.                             CDBManager::instance().CountReturnQueryFinished(SQL_PLAYER),
  3312.                             CDBManager::instance().CountAsyncQuery(SQL_PLAYER),
  3313.                             CDBManager::instance().CountAsyncResult(SQL_PLAYER),
  3314.                             CDBManager::instance().CountAsyncQueryFinished(SQL_PLAYER));
  3315.                         }
  3316.  
  3317.             CDBManager::instance().ResetCounter();
  3318.  
  3319.             DWORD dwCount = CClientManager::instance().GetUserCount();
  3320.  
  3321.             g_dwUsageAvg += dwCount;
  3322.             g_dwUsageMax = MAX(g_dwUsageMax, dwCount);
  3323.  
  3324.             memset(&thecore_profiler[0], 0, sizeof(thecore_profiler));
  3325.  
  3326.             if (!(thecore_heart->pulse % (thecore_heart->passes_per_sec * 3600)))
  3327.                 UsageLog();
  3328.  
  3329.             m_iCacheFlushCount = 0;
  3330.  
  3331. #ifdef __SKILL_COLOR_SYSTEM__
  3332.             // Skill color fush
  3333.             UpdateSkillColorCache();
  3334. #endif
  3335.  
  3336.             UpdatePlayerCache();
  3337.             UpdateItemCache();
  3338.             UpdateLogoutPlayer();
  3339.  
  3340.             // MYSHOP_PRICE_LIST
  3341.             UpdateItemPriceListCache();
  3342.             // END_OF_MYSHOP_PRICE_LIST
  3343.  
  3344.             CGuildManager::instance().Update();
  3345.             CPrivManager::instance().Update();
  3346.             marriage::CManager::instance().Update();
  3347.         }
  3348. #ifdef ENABLE_ITEMAWARD_REFRESH
  3349.         if (!(thecore_heart->pulse % (thecore_heart->passes_per_sec * 5)))
  3350.         {
  3351.             ItemAwardManager::instance().RequestLoad();
  3352.         }
  3353. #endif
  3354.         if (!(thecore_heart->pulse % (thecore_heart->passes_per_sec * 10)))
  3355.         {
  3356.             /*
  3357.             char buf[4096 + 1];
  3358.             int len
  3359.             itertype(g_query_info.m_map_info) it;
  3360.  
  3361.             /////////////////////////////////////////////////////////////////
  3362.             buf[0] = '\0';
  3363.             len = 0;
  3364.  
  3365.             it = g_query_info.m_map_info.begin();
  3366.  
  3367.             int count = 0;
  3368.  
  3369.             while (it != g_query_info.m_map_info.end())
  3370.             {
  3371.                 len += snprintf(buf + len, sizeof(buf) - len, "%2d %3d\n", it->first, it->second);
  3372.                 count += it->second;
  3373.                 it++;
  3374.             }
  3375.  
  3376.             pt_log("QUERY:\n%s-------------------- MAX : %d\n", buf, count);
  3377.             g_query_info.Reset();
  3378.             */
  3379.             pt_log("QUERY: MAIN[%d] ASYNC[%d]", g_query_count[0], g_query_count[1]);
  3380.             g_query_count[0] = 0;
  3381.             g_query_count[1] = 0;
  3382.             /////////////////////////////////////////////////////////////////
  3383.  
  3384.             /////////////////////////////////////////////////////////////////
  3385.             /*
  3386.             buf[0] = '\0';
  3387.             len = 0;
  3388.  
  3389.             it = g_item_info.m_map_info.begin();
  3390.  
  3391.             count = 0;
  3392.             while (it != g_item_info.m_map_info.end())
  3393.             {
  3394.                 len += snprintf(buf + len, sizeof(buf) - len, "%5d %3d\n", it->first, it->second);
  3395.                 count += it->second;
  3396.                 it++;
  3397.             }
  3398.  
  3399.             pt_log("ITEM:\n%s-------------------- MAX : %d\n", buf, count);
  3400.             g_item_info.Reset();
  3401.             */
  3402.             pt_log("ITEM:%d\n", g_item_count);
  3403.             g_item_count = 0;
  3404.             /////////////////////////////////////////////////////////////////
  3405.         }
  3406.  
  3407.         if (!(thecore_heart->pulse % (thecore_heart->passes_per_sec * 60))) // 60ĂĘżˇ ÇŃąř
  3408.         {
  3409.             // ŔŻ´ĎĹ© ľĆŔĚĹŰŔ» Ŕ§ÇŃ ˝Ă°ŁŔ» ş¸ł˝´Ů.
  3410.             CClientManager::instance().SendTime();
  3411.  
  3412.             // ÇöŔç ż¬°áµČ peerŔÇ host ą× port¸¦ Ăâ·ÂÇŃ´Ů.
  3413.             std::string st;
  3414.             CClientManager::instance().GetPeerP2PHostNames(st);
  3415.             sys_log(0, "Current Peer host names...\n%s", st.c_str());
  3416.         }
  3417.  
  3418.         if (!(thecore_heart->pulse % (thecore_heart->passes_per_sec * 3600)))   // ÇѽðŁżˇ ÇŃąř
  3419.         {
  3420.             CMoneyLog::instance().Save();
  3421.         }
  3422.     }
  3423.  
  3424.     int num_events = fdwatch(m_fdWatcher, 0);
  3425.     int idx;
  3426.     CPeer * peer;
  3427.  
  3428.     for (idx = 0; idx < num_events; ++idx) // ŔÎDz
  3429.     {
  3430.         peer = (CPeer *) fdwatch_get_client_data(m_fdWatcher, idx);
  3431.  
  3432.         if (!peer)
  3433.         {
  3434.             if (fdwatch_check_event(m_fdWatcher, m_fdAccept, idx) == FDW_READ)
  3435.             {
  3436.                 AddPeer(m_fdAccept);
  3437.                 fdwatch_clear_event(m_fdWatcher, m_fdAccept, idx);
  3438.             }
  3439.             else
  3440.             {
  3441.                 sys_log(0, "FDWATCH: peer null in event: ident %d", fdwatch_get_ident(m_fdWatcher, idx)); // @warme012
  3442.             }
  3443.  
  3444.             continue;
  3445.         }
  3446.  
  3447.         switch (fdwatch_check_event(m_fdWatcher, peer->GetFd(), idx))
  3448.         {
  3449.             case FDW_READ:
  3450.                 if (peer->Recv() < 0)
  3451.                 {
  3452.                     sys_err("Recv failed");
  3453.                     RemovePeer(peer);
  3454.                 }
  3455.                 else
  3456.                 {
  3457.                     if (peer == m_pkAuthPeer)
  3458.                         if (g_log)
  3459.                             sys_log(0, "AUTH_PEER_READ: size %d", peer->GetRecvLength());
  3460.  
  3461.                     ProcessPackets(peer);
  3462.                 }
  3463.                 break;
  3464.  
  3465.             case FDW_WRITE:
  3466.                 if (peer == m_pkAuthPeer)
  3467.                     if (g_log)
  3468.                         sys_log(0, "AUTH_PEER_WRITE: size %d", peer->GetSendLength());
  3469.  
  3470.                 if (peer->Send() < 0)
  3471.                 {
  3472.                     sys_err("Send failed");
  3473.                     RemovePeer(peer);
  3474.                 }
  3475.  
  3476.                 break;
  3477.  
  3478.             case FDW_EOF:
  3479.                 RemovePeer(peer);
  3480.                 break;
  3481.  
  3482.             default:
  3483.                 sys_err("fdwatch_check_fd returned unknown result");
  3484.                 RemovePeer(peer);
  3485.                 break;
  3486.         }
  3487.     }
  3488.  
  3489. #ifdef __WIN32__
  3490.     if (_kbhit()) {
  3491.         int c = _getch();
  3492.         switch (c) {
  3493.             case 0x1b: // Esc
  3494.                 return 0; // shutdown
  3495.                 break;
  3496.             default:
  3497.                 break;
  3498.         }
  3499.     }
  3500. #endif
  3501.  
  3502.     VCardProcess();
  3503.     return 1;
  3504. }
  3505.  
  3506. DWORD CClientManager::GetUserCount()
  3507. {
  3508.     // ´ÜĽřČ÷ ·Î±×ŔÎ Ä«żîĆ®¸¦ Ľľ´Ů.. --;
  3509.     return m_map_kLogonAccount.size();
  3510. }
  3511.  
  3512. void CClientManager::SendAllGuildSkillRechargePacket()
  3513. {
  3514.     ForwardPacket(HEADER_DG_GUILD_SKILL_RECHARGE, NULL, 0);
  3515. }
  3516.  
  3517. void CClientManager::SendTime()
  3518. {
  3519.     time_t now = GetCurrentTime();
  3520.     ForwardPacket(HEADER_DG_TIME, &now, sizeof(time_t));
  3521. }
  3522.  
  3523. void CClientManager::ForwardPacket(BYTE header, const void* data, int size, BYTE bChannel, CPeer* except)
  3524. {
  3525.     for (itertype(m_peerList) it = m_peerList.begin(); it != m_peerList.end(); ++it)
  3526.     {
  3527.         CPeer * peer = *it;
  3528.  
  3529.         if (peer == except)
  3530.             continue;
  3531.  
  3532.         if (!peer->GetChannel())
  3533.             continue;
  3534.  
  3535.         if (bChannel && peer->GetChannel() != bChannel)
  3536.             continue;
  3537.  
  3538.         peer->EncodeHeader(header, 0, size);
  3539.  
  3540.         if (size > 0 && data)
  3541.             peer->Encode(data, size);
  3542.     }
  3543. }
  3544.  
  3545. void CClientManager::SendNotice(const char * c_pszFormat, ...)
  3546. {
  3547.     char szBuf[255+1];
  3548.     va_list args;
  3549.  
  3550.     va_start(args, c_pszFormat);
  3551.     int len = vsnprintf(szBuf, sizeof(szBuf), c_pszFormat, args);
  3552.     va_end(args);
  3553.     szBuf[len] = '\0';
  3554.  
  3555.     ForwardPacket(HEADER_DG_NOTICE, szBuf, len + 1);
  3556. }
  3557.  
  3558. time_t CClientManager::GetCurrentTime()
  3559. {
  3560.     return time(0);
  3561. }
  3562.  
  3563. // ITEM_UNIQUE_ID
  3564. bool CClientManager::InitializeNowItemID()
  3565. {
  3566.     DWORD dwMin, dwMax;
  3567.  
  3568.     //ľĆŔĚĹŰ ID¸¦ ĂʱâČ­ ÇŃ´Ů.
  3569.     if (!CConfig::instance().GetTwoValue("ITEM_ID_RANGE", &dwMin, &dwMax))
  3570.     {
  3571.         sys_err("conf.txt: Cannot find ITEM_ID_RANGE [start_item_id] [end_item_id]");
  3572.         return false;
  3573.     }
  3574.  
  3575.     sys_log(0, "ItemRange From File %u ~ %u ", dwMin, dwMax);
  3576.  
  3577.     if (CItemIDRangeManager::instance().BuildRange(dwMin, dwMax, m_itemRange) == false)
  3578.     {
  3579.         sys_err("Can not build ITEM_ID_RANGE");
  3580.         return false;
  3581.     }
  3582.  
  3583.     sys_log(0, " Init Success Start %u End %u Now %u\n", m_itemRange.dwMin, m_itemRange.dwMax, m_itemRange.dwUsableItemIDMin);
  3584.  
  3585.     return true;
  3586. }
  3587.  
  3588. DWORD CClientManager::GainItemID()
  3589. {
  3590.     return m_itemRange.dwUsableItemIDMin++;
  3591. }
  3592.  
  3593. DWORD CClientManager::GetItemID()
  3594. {
  3595.     return m_itemRange.dwUsableItemIDMin;
  3596. }
  3597. // ITEM_UNIQUE_ID_END
  3598. //BOOT_LOCALIZATION
  3599.  
  3600. bool CClientManager::InitializeLocalization()
  3601. {
  3602.     char szQuery[512];
  3603.     snprintf(szQuery, sizeof(szQuery), "SELECT mValue, mKey FROM locale");
  3604.     SQLMsg * pMsg = CDBManager::instance().DirectQuery(szQuery, SQL_COMMON);
  3605.  
  3606.     if (pMsg->Get()->uiNumRows == 0)
  3607.     {
  3608.         sys_err("InitializeLocalization() ==> DirectQuery failed(%s)", szQuery);
  3609.         delete pMsg;
  3610.         return false;
  3611.     }
  3612.  
  3613.     sys_log(0, "InitializeLocalization() - LoadLocaleTable(count:%d)", pMsg->Get()->uiNumRows);
  3614.  
  3615.     m_vec_Locale.clear();
  3616.  
  3617.     MYSQL_ROW row = NULL;
  3618.  
  3619.     for (int n = 0; (row = mysql_fetch_row(pMsg->Get()->pSQLResult)) != NULL; ++n)
  3620.     {
  3621.         int col = 0;
  3622.         tLocale locale;
  3623.  
  3624.         strlcpy(locale.szValue, row[col++], sizeof(locale.szValue));
  3625.         strlcpy(locale.szKey, row[col++], sizeof(locale.szKey));
  3626.  
  3627.         //DB_NAME_COLUMN Setting
  3628.         if (strcmp(locale.szKey, "LOCALE") == 0)
  3629.         {
  3630.             if (strcmp(locale.szValue, "cibn") == 0)
  3631.             {
  3632.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3633.  
  3634.                 if (g_stLocale != locale.szValue)
  3635.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "gb2312");
  3636.  
  3637.                 g_stLocale = "gb2312";
  3638.                 g_stLocaleNameColumn = "gb2312name";
  3639.             }
  3640.             else if (strcmp(locale.szValue, "ymir") == 0)
  3641.             {
  3642.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3643.  
  3644.                 if (g_stLocale != locale.szValue)
  3645.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "euckr");
  3646.  
  3647.                 g_stLocale = "euckr";
  3648.                 g_stLocaleNameColumn = "name";
  3649.             }
  3650.             else if (strcmp(locale.szValue, "japan") == 0)
  3651.             {
  3652.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3653.  
  3654.                 if (g_stLocale != locale.szValue)
  3655.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "sjis");
  3656.  
  3657.                 g_stLocale = "sjis";
  3658.                 g_stLocaleNameColumn = "locale_name";
  3659.             }
  3660.             else if (strcmp(locale.szValue, "english") == 0)
  3661.             {
  3662.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3663.  
  3664.                 if (g_stLocale != locale.szValue)
  3665.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "euckr");
  3666.  
  3667.                 g_stLocale = "";
  3668.                 g_stLocaleNameColumn = "locale_name";
  3669.             }
  3670.             else if (strcmp(locale.szValue, "germany") == 0)
  3671.             {
  3672.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3673.  
  3674.                 if (g_stLocale != locale.szValue)
  3675.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "euckr");
  3676.  
  3677.                 g_stLocale = "latin1";
  3678.                 g_stLocaleNameColumn = "locale_name";
  3679.             }
  3680.             else if (strcmp(locale.szValue, "france") == 0)
  3681.             {
  3682.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3683.  
  3684.                 if (g_stLocale != locale.szValue)
  3685.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "euckr");
  3686.  
  3687.                 g_stLocale = "latin1";
  3688.                 g_stLocaleNameColumn = "locale_name";
  3689.             }
  3690.             else if (strcmp(locale.szValue, "italy") == 0)
  3691.             {
  3692.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3693.  
  3694.                 if (g_stLocale != locale.szValue)
  3695.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "euckr");
  3696.  
  3697.                 g_stLocale = "latin1";
  3698.                 g_stLocaleNameColumn = "locale_name";
  3699.             }
  3700.             else if (strcmp(locale.szValue, "spain") == 0)
  3701.             {
  3702.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3703.  
  3704.                 if (g_stLocale != locale.szValue)
  3705.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "euckr");
  3706.  
  3707.                 g_stLocale = "latin1";
  3708.                 g_stLocaleNameColumn = "locale_name";
  3709.             }
  3710.             else if (strcmp(locale.szValue, "uk") == 0)
  3711.             {
  3712.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3713.  
  3714.                 if (g_stLocale != locale.szValue)
  3715.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "euckr");
  3716.  
  3717.                 g_stLocale = "latin1";
  3718.                 g_stLocaleNameColumn = "locale_name";
  3719.             }
  3720.             else if (strcmp(locale.szValue, "turkey") == 0)
  3721.             {
  3722.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3723.  
  3724.                 if (g_stLocale != locale.szValue)
  3725.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "euckr");
  3726.  
  3727.                 g_stLocale = "latin5";
  3728.                 g_stLocaleNameColumn = "locale_name";
  3729.             }
  3730.             else if (strcmp(locale.szValue, "poland") == 0)
  3731.             {
  3732.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3733.  
  3734.                 if (g_stLocale != locale.szValue)
  3735.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "euckr");
  3736.  
  3737.                 g_stLocale = "latin2";
  3738.                 g_stLocaleNameColumn = "locale_name";
  3739.             }
  3740.             else if (strcmp(locale.szValue, "portugal") == 0)
  3741.             {
  3742.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3743.  
  3744.                 if (g_stLocale != locale.szValue)
  3745.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "euckr");
  3746.  
  3747.                 g_stLocale = "latin1";
  3748.                 g_stLocaleNameColumn = "locale_name";
  3749.             }
  3750.             else if (strcmp(locale.szValue, "hongkong") == 0)
  3751.             {
  3752.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3753.  
  3754.                 if (g_stLocale != locale.szValue)
  3755.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "big5");
  3756.  
  3757.                 g_stLocale = "big5";
  3758.                 g_stLocaleNameColumn = "locale_name";
  3759.             }
  3760.             else if (strcmp(locale.szValue, "newcibn") == 0)
  3761.             {
  3762.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3763.  
  3764.                 if (g_stLocale != locale.szValue)
  3765.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "gb2312");
  3766.  
  3767.                 g_stLocale = "gb2312";
  3768.                 g_stLocaleNameColumn = "gb2312name";
  3769.             }
  3770.             else if (strcmp(locale.szValue, "korea") == 0)
  3771.             {
  3772.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3773.  
  3774.                 if (g_stLocale != locale.szValue)
  3775.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "euckr");
  3776.  
  3777.                 g_stLocale = "euckr";
  3778.                 g_stLocaleNameColumn = "name";
  3779.             }
  3780.             else if (strcmp(locale.szValue, "canada") == 0)
  3781.             {
  3782.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3783.  
  3784.                 if (g_stLocale != locale.szValue)
  3785.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "latin1");
  3786.  
  3787.                 g_stLocale = "latin1";
  3788.                 g_stLocaleNameColumn = "gb2312name";
  3789.             }
  3790.             else if (strcmp(locale.szValue, "brazil") == 0)
  3791.             {
  3792.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3793.  
  3794.                 if (g_stLocale != locale.szValue)
  3795.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "latin1");
  3796.  
  3797.                 g_stLocale = "latin1";
  3798.                 g_stLocaleNameColumn = "locale_name";
  3799.             }
  3800.             else if (strcmp(locale.szValue, "greek") == 0)
  3801.             {
  3802.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3803.  
  3804.                 if (g_stLocale != locale.szValue)
  3805.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "latin1");
  3806.  
  3807.                 g_stLocale = "greek";
  3808.                 g_stLocaleNameColumn = "locale_name";
  3809.             }
  3810.             else if (strcmp(locale.szValue, "russia") == 0)
  3811.             {
  3812.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3813.  
  3814.                 if (g_stLocale != locale.szValue)
  3815.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "latin1");
  3816.  
  3817.                 g_stLocale = "cp1251";
  3818.                 g_stLocaleNameColumn = "locale_name";
  3819.             }
  3820.             else if (strcmp(locale.szValue, "denmark") == 0)
  3821.             {
  3822.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3823.  
  3824.                 if (g_stLocale != locale.szValue)
  3825.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "latin1");
  3826.  
  3827.                 g_stLocale = "latin1";
  3828.                 g_stLocaleNameColumn = "locale_name";
  3829.             }
  3830.             else if (strcmp(locale.szValue, "bulgaria") == 0)
  3831.             {
  3832.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3833.  
  3834.                 if (g_stLocale != locale.szValue)
  3835.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "latin1");
  3836.  
  3837.                 g_stLocale = "cp1251";
  3838.                 g_stLocaleNameColumn = "locale_name";
  3839.             }
  3840.             else if (strcmp(locale.szValue, "croatia") == 0)
  3841.             {
  3842.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3843.  
  3844.                 if (g_stLocale != locale.szValue)
  3845.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "latin1");
  3846.  
  3847.                 g_stLocale = "cp1251";
  3848.                 g_stLocaleNameColumn = "locale_name";
  3849.             }
  3850.             else if (strcmp(locale.szValue, "mexico") == 0)
  3851.             {
  3852.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3853.  
  3854.                 if (g_stLocale != locale.szValue)
  3855.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "euckr");
  3856.  
  3857.                 g_stLocale = "latin1";
  3858.                 g_stLocaleNameColumn = "locale_name";
  3859.             }
  3860.             else if (strcmp(locale.szValue, "arabia") == 0)
  3861.             {
  3862.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3863.  
  3864.                 if (g_stLocale != locale.szValue)
  3865.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "euckr");
  3866.  
  3867.                 g_stLocale = "cp1256";
  3868.                 g_stLocaleNameColumn = "locale_name";
  3869.             }
  3870.             else if (strcmp(locale.szValue, "czech") == 0)
  3871.             {
  3872.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3873.  
  3874.                 if (g_stLocale != locale.szValue)
  3875.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "euckr");
  3876.  
  3877.                 g_stLocale = "latin2";
  3878.                 g_stLocaleNameColumn = "locale_name";
  3879.             }
  3880.             else if (strcmp(locale.szValue, "hungary") == 0)
  3881.             {
  3882.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3883.  
  3884.                 if (g_stLocale != locale.szValue)
  3885.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "euckr");
  3886.  
  3887.                 g_stLocale = "latin2";
  3888.                 g_stLocaleNameColumn = "locale_name";
  3889.             }
  3890.             else if (strcmp(locale.szValue, "romania") == 0)
  3891.             {
  3892.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3893.  
  3894.                 if (g_stLocale != locale.szValue)
  3895.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "euckr");
  3896.  
  3897.                 g_stLocale = "latin2";
  3898.                 g_stLocaleNameColumn = "locale_name";
  3899.             }
  3900.             else if (strcmp(locale.szValue, "netherlands") == 0)
  3901.             {
  3902.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3903.  
  3904.                 if (g_stLocale != locale.szValue)
  3905.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "euckr");
  3906.  
  3907.                 g_stLocale = "latin1";
  3908.                 g_stLocaleNameColumn = "locale_name";
  3909.             }
  3910.             else if (strcmp(locale.szValue, "singapore") == 0)
  3911.             {
  3912.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3913.  
  3914.                 if (g_stLocale != locale.szValue)
  3915.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "latin1");
  3916.  
  3917.                 g_stLocale = "latin1";
  3918.                 g_stLocaleNameColumn = "locale_name";
  3919.             }
  3920.             else if (strcmp(locale.szValue, "vietnam") == 0)
  3921.             {
  3922.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3923.  
  3924.                 if (g_stLocale != locale.szValue)
  3925.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "latin1");
  3926.  
  3927.                 g_stLocale = "latin1";
  3928.                 g_stLocaleNameColumn = "locale_name";
  3929.             }
  3930.             else if (strcmp(locale.szValue, "thailand") == 0)
  3931.             {
  3932.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3933.  
  3934.                 if (g_stLocale != locale.szValue)
  3935.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "latin1");
  3936.  
  3937.                 g_stLocale = "latin1";
  3938.                 g_stLocaleNameColumn = "locale_name";
  3939.             }
  3940.             else if (strcmp(locale.szValue, "usa") == 0)
  3941.             {
  3942.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3943.  
  3944.                 if (g_stLocale != locale.szValue)
  3945.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "latin1");
  3946.  
  3947.                 g_stLocale = "latin1";
  3948.                 g_stLocaleNameColumn = "locale_name";
  3949.             }
  3950.             else if (strcmp(locale.szValue, "we_korea") == 0)
  3951.             {
  3952.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3953.  
  3954.                 if (g_stLocale != locale.szValue)
  3955.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "euckr");
  3956.  
  3957.                 g_stLocale = "euckr";
  3958.                 g_stLocaleNameColumn = "name";
  3959.             }
  3960.             else if (strcmp(locale.szValue, "taiwan") == 0)
  3961.             {
  3962.                 sys_log(0, "locale[LOCALE] = %s", locale.szValue);
  3963.  
  3964.                 if (g_stLocale != locale.szValue)
  3965.                     sys_log(0, "Changed g_stLocale %s to %s", g_stLocale.c_str(), "big5");
  3966.                 g_stLocale = "big5";
  3967.                 g_stLocaleNameColumn = "locale_name";
  3968.             }
  3969.             else
  3970.             {
  3971.                 sys_err("locale[LOCALE] = UNKNOWN(%s)", locale.szValue);
  3972.                 exit(0);
  3973.             }
  3974.             // @warme007
  3975.             // sys_log(0,"before call SetLocale: %s",g_stLocale.c_str());
  3976.             // CDBManager::instance().SetLocale(g_stLocale.c_str());
  3977.             // sys_log(0,"Called SetLocale");
  3978.         }
  3979.         else if (strcmp(locale.szKey, "DB_NAME_COLUMN") == 0)
  3980.         {
  3981.             sys_log(0, "locale[DB_NAME_COLUMN] = %s", locale.szValue);
  3982.             g_stLocaleNameColumn = locale.szValue;
  3983.         }
  3984.         else
  3985.         {
  3986.             sys_log(0, "locale[UNKNOWN_KEY(%s)] = %s", locale.szKey, locale.szValue);
  3987.         }
  3988.         m_vec_Locale.push_back(locale);
  3989.     }
  3990.  
  3991.     delete pMsg;
  3992.  
  3993.     return true;
  3994. }
  3995. //END_BOOT_LOCALIZATION
  3996. //ADMIN_MANAGER
  3997.  
  3998. bool CClientManager::__GetAdminInfo(const char *szIP, std::vector<tAdminInfo> & rAdminVec)
  3999. {
  4000.     //szIP == NULL ŔĎ°ćżě  ¸đµçĽ­ąöżˇ żîżµŔÚ ±ÇÇŃŔ» °®´Â´Ů.
  4001.     char szQuery[512];
  4002.     snprintf(szQuery, sizeof(szQuery),
  4003.             "SELECT mID,mAccount,mName,mContactIP,mServerIP,mAuthority FROM gmlist WHERE mServerIP='ALL' or mServerIP='%s'",
  4004.             szIP ? szIP : "ALL");
  4005.  
  4006.     SQLMsg * pMsg = CDBManager::instance().DirectQuery(szQuery, SQL_COMMON);
  4007.  
  4008.     if (pMsg->Get()->uiNumRows == 0)
  4009.     {
  4010.         // sys_err("__GetAdminInfo() ==> DirectQuery failed(%s)", szQuery); // @warme013
  4011.         delete pMsg;
  4012.         return false;
  4013.     }
  4014.  
  4015.     MYSQL_ROW row;
  4016.     rAdminVec.reserve(pMsg->Get()->uiNumRows);
  4017.  
  4018.     while ((row = mysql_fetch_row(pMsg->Get()->pSQLResult)))
  4019.     {
  4020.         int idx = 0;
  4021.         tAdminInfo Info;
  4022.  
  4023.         str_to_number(Info.m_ID, row[idx++]);
  4024.         trim_and_lower(row[idx++], Info.m_szAccount, sizeof(Info.m_szAccount));
  4025.         strlcpy(Info.m_szName, row[idx++], sizeof(Info.m_szName));
  4026.         strlcpy(Info.m_szContactIP, row[idx++], sizeof(Info.m_szContactIP));
  4027.         strlcpy(Info.m_szServerIP, row[idx++], sizeof(Info.m_szServerIP));
  4028.         std::string stAuth = row[idx++];
  4029.  
  4030.         if (!stAuth.compare("IMPLEMENTOR"))
  4031.             Info.m_Authority = GM_IMPLEMENTOR;
  4032.         else if (!stAuth.compare("GOD"))
  4033.             Info.m_Authority = GM_GOD;
  4034.         else if (!stAuth.compare("HIGH_WIZARD"))
  4035.             Info.m_Authority = GM_HIGH_WIZARD;
  4036.         else if (!stAuth.compare("LOW_WIZARD"))
  4037.             Info.m_Authority = GM_LOW_WIZARD;
  4038.         else if (!stAuth.compare("WIZARD"))
  4039.             Info.m_Authority = GM_WIZARD;
  4040.         else
  4041.             continue;
  4042.  
  4043.         rAdminVec.push_back(Info);
  4044.  
  4045.         sys_log(0, "GM: PID %u Login %s Character %s ContactIP %s ServerIP %s Authority %d[%s]",
  4046.                 Info.m_ID, Info.m_szAccount, Info.m_szName, Info.m_szContactIP, Info.m_szServerIP, Info.m_Authority, stAuth.c_str());
  4047.     }
  4048.  
  4049.     delete pMsg;
  4050.  
  4051.     return true;
  4052. }
  4053.  
  4054. bool CClientManager::__GetHostInfo(std::vector<std::string> & rIPVec)
  4055. {
  4056.     char szQuery[512];
  4057.     snprintf(szQuery, sizeof(szQuery), "SELECT mIP FROM gmhost");
  4058.     SQLMsg * pMsg = CDBManager::instance().DirectQuery(szQuery, SQL_COMMON);
  4059.  
  4060.     if (pMsg->Get()->uiNumRows == 0)
  4061.     {
  4062.         // sys_err("__GetHostInfo() ==> DirectQuery failed(%s)", szQuery); // @warme013
  4063.         delete pMsg;
  4064.         return false;
  4065.     }
  4066.  
  4067.     rIPVec.reserve(pMsg->Get()->uiNumRows);
  4068.  
  4069.     MYSQL_ROW row;
  4070.  
  4071.     while ((row = mysql_fetch_row(pMsg->Get()->pSQLResult)))
  4072.     {
  4073.         if (row[0] && *row[0])
  4074.         {
  4075.             rIPVec.push_back(row[0]);
  4076.             sys_log(0, "GMHOST: %s", row[0]);
  4077.         }
  4078.     }
  4079.  
  4080.     delete pMsg;
  4081.     return true;
  4082. }
  4083. //END_ADMIN_MANAGER
  4084.  
  4085. void CClientManager::ReloadAdmin(CPeer*, TPacketReloadAdmin* p)
  4086. {
  4087.     std::vector<tAdminInfo> vAdmin;
  4088.     std::vector<std::string> vHost;
  4089.  
  4090.     __GetHostInfo(vHost);
  4091.     __GetAdminInfo(p->szIP, vAdmin);
  4092.  
  4093.     DWORD dwPacketSize = sizeof(WORD) + sizeof (WORD) + sizeof(tAdminInfo) * vAdmin.size() +
  4094.           sizeof(WORD) + sizeof(WORD) + 16 * vHost.size();
  4095.  
  4096.     for (itertype(m_peerList) it = m_peerList.begin(); it != m_peerList.end(); ++it)
  4097.     {
  4098.         CPeer * peer = *it;
  4099.  
  4100.         if (!peer->GetChannel())
  4101.             continue;
  4102.  
  4103.         peer->EncodeHeader(HEADER_DG_RELOAD_ADMIN, 0, dwPacketSize);
  4104.  
  4105.         peer->EncodeWORD(16);
  4106.         peer->EncodeWORD(vHost.size());
  4107.  
  4108.         for (size_t n = 0; n < vHost.size(); ++n)
  4109.             peer->Encode(vHost[n].c_str(), 16);
  4110.  
  4111.         peer->EncodeWORD(sizeof(tAdminInfo));
  4112.         peer->EncodeWORD(vAdmin.size());
  4113.  
  4114.         for (size_t n = 0; n < vAdmin.size(); ++n)
  4115.             peer->Encode(&vAdmin[n], sizeof(tAdminInfo));
  4116.     }
  4117.  
  4118.     sys_log(0, "ReloadAdmin End %s", p->szIP);
  4119. }
  4120.  
  4121. //BREAK_MARRIAGE
  4122. void CClientManager::BreakMarriage(CPeer * peer, const char * data)
  4123. {
  4124.     DWORD pid1, pid2;
  4125.  
  4126.     pid1 = *(int *) data;
  4127.     data += sizeof(int);
  4128.  
  4129.     pid2 = *(int *) data;
  4130.     data += sizeof(int);
  4131.  
  4132.     sys_log(0, "Breaking off a marriage engagement! pid %d and pid %d", pid1, pid2);
  4133.     marriage::CManager::instance().Remove(pid1, pid2);
  4134. }
  4135. //END_BREAK_MARIIAGE
  4136.  
  4137. void CClientManager::UpdateItemCacheSet(DWORD pid)
  4138. {
  4139.     itertype(m_map_pkItemCacheSetPtr) it = m_map_pkItemCacheSetPtr.find(pid);
  4140.  
  4141.     if (it == m_map_pkItemCacheSetPtr.end())
  4142.     {
  4143.         if (g_test_server)
  4144.             sys_log(0, "UPDATE_ITEMCACHESET : UpdateItemCacheSet ==> No ItemCacheSet pid(%d)", pid);
  4145.         return;
  4146.     }
  4147.  
  4148.     TItemCacheSet * pSet = it->second;
  4149.     TItemCacheSet::iterator it_set = pSet->begin();
  4150.  
  4151.     while (it_set != pSet->end())
  4152.     {
  4153.         CItemCache * c = *it_set++;
  4154.         c->Flush();
  4155.     }
  4156.  
  4157.     if (g_log)
  4158.         sys_log(0, "UPDATE_ITEMCACHESET : UpdateItemCachsSet pid(%d)", pid);
  4159. }
  4160.  
  4161. void CClientManager::Election(CPeer * peer, DWORD dwHandle, const char* data)
  4162. {
  4163.     DWORD idx;
  4164.     DWORD selectingpid;
  4165.  
  4166.     idx = *(DWORD *) data;
  4167.     data += sizeof(DWORD);
  4168.  
  4169.     selectingpid = *(DWORD *) data;
  4170.     data += sizeof(DWORD);
  4171.  
  4172.     int Success = 0;
  4173.  
  4174.     if (!(Success = CMonarch::instance().VoteMonarch(selectingpid, idx)))
  4175.     {
  4176.         if (g_test_server)
  4177.         sys_log(0, "[MONARCH_VOTE] Failed %d %d", idx, selectingpid);
  4178.         peer->EncodeHeader(HEADER_DG_ELECT_MONARCH, dwHandle, sizeof(int));
  4179.         peer->Encode(&Success, sizeof(int));
  4180.         return;
  4181.     }
  4182.     else
  4183.     {
  4184.         if (g_test_server)
  4185.         sys_log(0, "[MONARCH_VOTE] Success %d %d", idx, selectingpid);
  4186.         peer->EncodeHeader(HEADER_DG_ELECT_MONARCH, dwHandle, sizeof(int));
  4187.         peer->Encode(&Success, sizeof(int));
  4188.         return;
  4189.     }
  4190.  
  4191. }
  4192. void CClientManager::Candidacy(CPeer *  peer, DWORD dwHandle, const char* data)
  4193. {
  4194.     DWORD pid;
  4195.  
  4196.     pid = *(DWORD *) data;
  4197.     data += sizeof(DWORD);
  4198.  
  4199.     if (!CMonarch::instance().AddCandidacy(pid, data))
  4200.     {
  4201.         if (g_test_server)
  4202.             sys_log(0, "[MONARCH_CANDIDACY] Failed %d %s", pid, data);
  4203.  
  4204.         peer->EncodeHeader(HEADER_DG_CANDIDACY, dwHandle, sizeof(int) + 32);
  4205.         peer->Encode(0, sizeof(int));
  4206.         peer->Encode(data, 32);
  4207.         return;
  4208.     }
  4209.     else
  4210.     {
  4211.         if (g_test_server)
  4212.             sys_log(0, "[MONARCH_CANDIDACY] Success %d %s", pid, data);
  4213.  
  4214.         for (itertype(m_peerList) it = m_peerList.begin(); it != m_peerList.end(); ++it)
  4215.         {
  4216.             CPeer * p = *it;
  4217.  
  4218.             if (!p->GetChannel())
  4219.                 continue;
  4220.  
  4221.             if (0 && p->GetChannel() != 0)
  4222.                 continue;
  4223.  
  4224.             if (p == peer)
  4225.             {
  4226.                 p->EncodeHeader(HEADER_DG_CANDIDACY, dwHandle, sizeof(int) + 32);
  4227.                 p->Encode(&pid, sizeof(int));
  4228.                 p->Encode(data, 32);
  4229.             }
  4230.             else
  4231.             {
  4232.                 p->EncodeHeader(HEADER_DG_CANDIDACY, 0, sizeof(int) + 32);
  4233.                 p->Encode(&pid, sizeof(int));
  4234.                 p->Encode(data, 32);
  4235.             }
  4236.         }
  4237.     }
  4238. }
  4239.  
  4240. void CClientManager::AddMonarchMoney(CPeer * peer, DWORD dwHandle, const char * data)
  4241. {
  4242.     int Empire = *(int *) data;
  4243.     data += sizeof(int);
  4244.  
  4245.     int Money = *(int *) data;
  4246.     data += sizeof(int);
  4247.  
  4248.     if (g_test_server)
  4249.         sys_log(0, "[MONARCH] Add money Empire(%d) Money(%d)", Empire, Money);
  4250.  
  4251.     CMonarch::instance().AddMoney(Empire, Money);
  4252.  
  4253.     for (itertype(m_peerList) it = m_peerList.begin(); it != m_peerList.end(); ++it)
  4254.     {
  4255.         CPeer * p = *it;
  4256.  
  4257.         if (!p->GetChannel())
  4258.             continue;
  4259.  
  4260.         if (p == peer)
  4261.         {
  4262.             p->EncodeHeader(HEADER_DG_ADD_MONARCH_MONEY, dwHandle, sizeof(int) + sizeof(int));
  4263.             p->Encode(&Empire, sizeof(int));
  4264.             p->Encode(&Money, sizeof(int));
  4265.         }
  4266.         else
  4267.         {
  4268.             p->EncodeHeader(HEADER_DG_ADD_MONARCH_MONEY, 0, sizeof(int) + sizeof(int));
  4269.             p->Encode(&Empire, sizeof(int));
  4270.             p->Encode(&Money, sizeof(int));
  4271.         }
  4272.  
  4273.     }
  4274. }
  4275. void CClientManager::DecMonarchMoney(CPeer * peer, DWORD dwHandle, const char * data)
  4276. {
  4277.     int Empire = *(int *) data;
  4278.     data += sizeof(int);
  4279.  
  4280.     int Money = *(int *) data;
  4281.     data += sizeof(int);
  4282.  
  4283.     if (g_test_server)
  4284.         sys_log(0, "[MONARCH] Dec money Empire(%d) Money(%d)", Empire, Money);
  4285.  
  4286.     CMonarch::instance().DecMoney(Empire, Money);
  4287.  
  4288.     for (itertype(m_peerList) it = m_peerList.begin(); it != m_peerList.end(); ++it)
  4289.     {
  4290.         CPeer * p = *it;
  4291.  
  4292.         if (!p->GetChannel())
  4293.             continue;
  4294.  
  4295.         if (p == peer)
  4296.         {
  4297.             p->EncodeHeader(HEADER_DG_DEC_MONARCH_MONEY, dwHandle, sizeof(int) + sizeof(int));
  4298.             p->Encode(&Empire, sizeof(int));
  4299.             p->Encode(&Money, sizeof(int));
  4300.         }
  4301.         else
  4302.         {
  4303.             p->EncodeHeader(HEADER_DG_DEC_MONARCH_MONEY, 0, sizeof(int) + sizeof(int));
  4304.             p->Encode(&Empire, sizeof(int));
  4305.             p->Encode(&Money, sizeof(int));
  4306.         }
  4307.     }
  4308. }
  4309.  
  4310. void CClientManager::TakeMonarchMoney(CPeer * peer, DWORD dwHandle, const char * data)
  4311. {
  4312.     int Empire = *(int *) data;
  4313.     data += sizeof(int);
  4314.  
  4315.     DWORD pid = *(DWORD *) data;
  4316.     data += sizeof(int);
  4317.  
  4318.     int Money = *(int *) data;
  4319.     data += sizeof(int);
  4320.  
  4321.     if (g_test_server)
  4322.         sys_log(0, "[MONARCH] Take money Empire(%d) Money(%d)", Empire, Money);
  4323.  
  4324.     if (CMonarch::instance().TakeMoney(Empire, pid, Money) == true)
  4325.     {
  4326.         peer->EncodeHeader(HEADER_DG_TAKE_MONARCH_MONEY, dwHandle, sizeof(int) + sizeof(int));
  4327.         peer->Encode(&Empire, sizeof(int));
  4328.         peer->Encode(&Money, sizeof(int));
  4329.     }
  4330.     else
  4331.     {
  4332.         Money = 0;
  4333.         peer->EncodeHeader(HEADER_DG_TAKE_MONARCH_MONEY, dwHandle, sizeof(int) + sizeof(int));
  4334.         peer->Encode(&Empire, sizeof(int));
  4335.         peer->Encode(&Money, sizeof(int));
  4336.     }
  4337. }
  4338.  
  4339. void CClientManager::ComeToVote(CPeer * peer, DWORD dwHandle, const char * data)
  4340. {
  4341.     CMonarch::instance().ElectMonarch();
  4342. }
  4343.  
  4344. void CClientManager::RMCandidacy(CPeer * peer, DWORD dwHandle, const char * data)
  4345. {
  4346.     char szName[32];
  4347.  
  4348.     strlcpy(szName, data, sizeof(szName));
  4349.     sys_log(0, "[MONARCH_GM] Remove candidacy name(%s)", szName);
  4350.  
  4351.     int iRet = CMonarch::instance().DelCandidacy(szName) ? 1 : 0;
  4352.  
  4353.     if (1 == iRet)
  4354.     {
  4355.         for (itertype(m_peerList) it = m_peerList.begin(); it != m_peerList.end(); ++it)
  4356.         {
  4357.             CPeer * p = *it;
  4358.  
  4359.             if (!p->GetChannel())
  4360.                 continue;
  4361.  
  4362.             if (p == peer)
  4363.             {
  4364.                 p->EncodeHeader(HEADER_DG_RMCANDIDACY, dwHandle, sizeof(int) + sizeof(szName));
  4365.                 p->Encode(&iRet, sizeof(int));
  4366.                 p->Encode(szName, sizeof(szName));
  4367.             }
  4368.             else
  4369.             {
  4370.                 p->EncodeHeader(HEADER_DG_RMCANDIDACY, dwHandle, sizeof(int) + sizeof(szName));
  4371.                 p->Encode(&iRet, sizeof(int));
  4372.                 p->Encode(szName, sizeof(szName));
  4373.             }
  4374.         }
  4375.     }
  4376.     else
  4377.     {
  4378.         CPeer * p = peer;
  4379.         p->EncodeHeader(HEADER_DG_RMCANDIDACY, dwHandle, sizeof(int) + sizeof(szName));
  4380.         p->Encode(&iRet, sizeof(int));
  4381.         p->Encode(szName, sizeof(szName));
  4382.     }
  4383. }
  4384.  
  4385. void CClientManager::SetMonarch(CPeer * peer, DWORD dwHandle, const char * data)
  4386. {
  4387.     char szName[32];
  4388.  
  4389.     strlcpy(szName, data, sizeof(szName));
  4390.  
  4391.     if (g_test_server)
  4392.         sys_log(0, "[MONARCH_GM] Set Monarch name(%s)", szName);
  4393.  
  4394.     int iRet = CMonarch::instance().SetMonarch(szName) ? 1 : 0;
  4395.  
  4396.     if (1 == iRet)
  4397.     {
  4398.         for (itertype(m_peerList) it = m_peerList.begin(); it != m_peerList.end(); ++it)
  4399.         {
  4400.             CPeer * p = *it;
  4401.  
  4402.             if (!p->GetChannel())
  4403.                 continue;
  4404.  
  4405.             if (p == peer)
  4406.             {
  4407.                 p->EncodeHeader(HEADER_DG_RMCANDIDACY, dwHandle, sizeof(int) + sizeof(szName));
  4408.                 p->Encode(&iRet, sizeof(int));
  4409.                 p->Encode(szName, sizeof(szName));
  4410.             }
  4411.             else
  4412.             {
  4413.                 p->EncodeHeader(HEADER_DG_RMCANDIDACY, dwHandle, sizeof(int) + sizeof(szName));
  4414.                 p->Encode(&iRet, sizeof(int));
  4415.                 p->Encode(szName, sizeof(szName));
  4416.             }
  4417.         }
  4418.     }
  4419.     else
  4420.     {
  4421.         CPeer * p = peer;
  4422.         p->EncodeHeader(HEADER_DG_RMCANDIDACY, dwHandle, sizeof(int) + sizeof(szName));
  4423.         p->Encode(&iRet, sizeof(int));
  4424.         p->Encode(szName, sizeof(szName));
  4425.     }
  4426. }
  4427.  
  4428. void CClientManager::RMMonarch(CPeer * peer, DWORD dwHandle, const char * data)
  4429. {
  4430.     char szName[32];
  4431.  
  4432.     strlcpy(szName, data, sizeof(szName));
  4433.  
  4434.     if (g_test_server)
  4435.         sys_log(0, "[MONARCH_GM] Remove Monarch name(%s)", szName);
  4436.  
  4437.     CMonarch::instance().DelMonarch(szName);
  4438.  
  4439.     int iRet = CMonarch::instance().DelMonarch(szName) ? 1 : 0;
  4440.  
  4441.     if (1 == iRet)
  4442.     {
  4443.         for (itertype(m_peerList) it = m_peerList.begin(); it != m_peerList.end(); ++it)
  4444.         {
  4445.             CPeer * p = *it;
  4446.  
  4447.             if (!p->GetChannel())
  4448.                 continue;
  4449.  
  4450.             if (p == peer)
  4451.             {
  4452.                 p->EncodeHeader(HEADER_DG_RMMONARCH, dwHandle, sizeof(int) + sizeof(szName));
  4453.                 p->Encode(&iRet, sizeof(int));
  4454.                 p->Encode(szName, sizeof(szName));
  4455.             }
  4456.             else
  4457.             {
  4458.                 p->EncodeHeader(HEADER_DG_RMMONARCH, dwHandle, sizeof(int) + sizeof(szName));
  4459.                 p->Encode(&iRet, sizeof(int));
  4460.                 p->Encode(szName, sizeof(szName));
  4461.             }
  4462.         }
  4463.     }
  4464.     else
  4465.     {
  4466.         CPeer * p = peer;
  4467.         p->EncodeHeader(HEADER_DG_RMCANDIDACY, dwHandle, sizeof(int) + sizeof(szName));
  4468.         p->Encode(&iRet, sizeof(int));
  4469.         p->Encode(szName, sizeof(szName));
  4470.     }
  4471. }
  4472.  
  4473. void CClientManager::ChangeMonarchLord(CPeer * peer, DWORD dwHandle, TPacketChangeMonarchLord* info)
  4474. {
  4475.     char szQuery[1024];
  4476.     snprintf(szQuery, sizeof(szQuery),
  4477.             "SELECT a.name, NOW() FROM player%s AS a, player_index%s AS b WHERE (a.account_id=b.id AND a.id=%u AND b.empire=%u) AND "
  4478. #ifdef ENABLE_PLAYER_PER_ACCOUNT5
  4479.             "(b.pid1=%u OR b.pid2=%u OR b.pid3=%u OR b.pid4=%u OR b.pid5=%u)",
  4480. #else
  4481.             "(b.pid1=%u OR b.pid2=%u OR b.pid3=%u OR b.pid4=%u)",
  4482. #endif
  4483.             GetTablePostfix(), GetTablePostfix(), info->dwPID, info->bEmpire,
  4484. #ifdef ENABLE_PLAYER_PER_ACCOUNT5
  4485.             info->dwPID, info->dwPID, info->dwPID, info->dwPID, info->dwPID);
  4486. #else
  4487.             info->dwPID, info->dwPID, info->dwPID, info->dwPID);
  4488. #endif
  4489.  
  4490.     SQLMsg * pMsg = CDBManager::instance().DirectQuery(szQuery, SQL_PLAYER);
  4491.  
  4492.     if (pMsg->Get()->uiNumRows != 0)
  4493.     {
  4494.         TPacketChangeMonarchLordACK ack;
  4495.         ack.bEmpire = info->bEmpire;
  4496.         ack.dwPID = info->dwPID;
  4497.  
  4498.         MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  4499.         strlcpy(ack.szName, row[0], sizeof(ack.szName));
  4500.         strlcpy(ack.szDate, row[1], sizeof(ack.szDate));
  4501.  
  4502.         snprintf(szQuery, sizeof(szQuery), "UPDATE monarch SET pid=%u, windate=NOW() WHERE empire=%d", ack.dwPID, ack.bEmpire);
  4503.         SQLMsg* pMsg2 = CDBManager::instance().DirectQuery(szQuery, SQL_PLAYER);
  4504.  
  4505.         if (pMsg2->Get()->uiAffectedRows > 0)
  4506.         {
  4507.             CMonarch::instance().LoadMonarch();
  4508.  
  4509.             TMonarchInfo* newInfo = CMonarch::instance().GetMonarch();
  4510.  
  4511.             for (itertype(m_peerList) it = m_peerList.begin(); it != m_peerList.end(); it++)
  4512.             {
  4513.                 CPeer* client = *it;
  4514.  
  4515.                 client->EncodeHeader(HEADER_DG_CHANGE_MONARCH_LORD_ACK, 0, sizeof(TPacketChangeMonarchLordACK));
  4516.                 client->Encode(&ack, sizeof(TPacketChangeMonarchLordACK));
  4517.  
  4518.                 client->EncodeHeader(HEADER_DG_UPDATE_MONARCH_INFO, 0, sizeof(TMonarchInfo));
  4519.                 client->Encode(newInfo, sizeof(TMonarchInfo));
  4520.             }
  4521.         }
  4522.  
  4523.         delete pMsg2;
  4524.     }
  4525.  
  4526.     delete pMsg;
  4527. }
  4528.  
  4529. void CClientManager::BlockException(TPacketBlockException *data)
  4530. {
  4531.     sys_log(0, "[BLOCK_EXCEPTION] CMD(%d) login(%s)", data->cmd, data->login);
  4532.  
  4533.     // save sql
  4534.     {
  4535.         char buf[1024];
  4536.  
  4537.         switch (data->cmd)
  4538.         {
  4539.             case BLOCK_EXCEPTION_CMD_ADD:
  4540.                 snprintf(buf, sizeof(buf), "INSERT INTO block_exception VALUES('%s')", data->login);
  4541.                 CDBManager::instance().AsyncQuery(buf, SQL_ACCOUNT);
  4542.                 CBlockCountry::instance().AddBlockException(data->login);
  4543.                 break;
  4544.             case BLOCK_EXCEPTION_CMD_DEL:
  4545.                 snprintf(buf, sizeof(buf), "DELETE FROM block_exception VALUES('%s')", data->login);
  4546.                 CDBManager::instance().AsyncQuery(buf, SQL_ACCOUNT);
  4547.                 CBlockCountry::instance().DelBlockException(data->login);
  4548.                 break;
  4549.             default:
  4550.                 return;
  4551.         }
  4552.  
  4553.     }
  4554.  
  4555.     for (itertype(m_peerList) it = m_peerList.begin(); it != m_peerList.end(); ++it)
  4556.     {
  4557.         CPeer   *peer = *it;
  4558.  
  4559.         if (!peer->GetChannel())
  4560.             continue;
  4561.  
  4562.         CBlockCountry::instance().SendBlockExceptionOne(peer, data->login, data->cmd);
  4563.     }
  4564. }
  4565.  
  4566. void CClientManager::SendSpareItemIDRange(CPeer* peer)
  4567. {
  4568.     peer->SendSpareItemIDRange();
  4569. }
  4570.  
  4571. //
  4572. // Login Key¸¸ ¸ĘżˇĽ­ Áöżî´Ů.
  4573. //
  4574. void CClientManager::DeleteLoginKey(TPacketDC *data)
  4575. {
  4576.     char login[LOGIN_MAX_LEN+1] = {0};
  4577.     trim_and_lower(data->login, login, sizeof(login));
  4578.  
  4579.     CLoginData *pkLD = GetLoginDataByLogin(login);
  4580.  
  4581.     if (pkLD)
  4582.     {
  4583.         TLoginDataByLoginKey::iterator it = m_map_pkLoginData.find(pkLD->GetKey());
  4584.  
  4585.         if (it != m_map_pkLoginData.end())
  4586.             m_map_pkLoginData.erase(it);
  4587.     }
  4588. }
  4589.  
  4590. // delete gift notify icon
  4591. void CClientManager::DeleteAwardId(TPacketDeleteAwardID *data)
  4592. {
  4593.     //sys_log(0,"data from game server arrived %d",data->dwID);
  4594.     std::map<DWORD, TItemAward *>::iterator it;
  4595.     it = ItemAwardManager::Instance().GetMapAward().find(data->dwID);
  4596.     if ( it != ItemAwardManager::Instance().GetMapAward().end() )
  4597.     {
  4598.         std::set<TItemAward *> & kSet = ItemAwardManager::Instance().GetMapkSetAwardByLogin()[it->second->szLogin];
  4599.         if(kSet.erase(it->second))
  4600.             sys_log(0,"erase ItemAward id: %d from cache", data->dwID);
  4601.         ItemAwardManager::Instance().GetMapAward().erase(data->dwID);
  4602.     }
  4603.     else
  4604.     {
  4605.         sys_log(0,"DELETE_AWARDID : could not find the id: %d", data->dwID);
  4606.     }
  4607.  
  4608. }
  4609.  
  4610. void CClientManager::UpdateChannelStatus(TChannelStatus* pData)
  4611. {
  4612.     TChannelStatusMap::iterator it = m_mChannelStatus.find(pData->nPort);
  4613.     if (it != m_mChannelStatus.end()) {
  4614.         it->second = pData->bStatus;
  4615.     }
  4616.     else {
  4617.         m_mChannelStatus.insert(TChannelStatusMap::value_type(pData->nPort, pData->bStatus));
  4618.     }
  4619. }
  4620.  
  4621. void CClientManager::RequestChannelStatus(CPeer* peer, DWORD dwHandle)
  4622. {
  4623.     const int nSize = m_mChannelStatus.size();
  4624.     peer->EncodeHeader(HEADER_DG_RESPOND_CHANNELSTATUS, dwHandle, sizeof(TChannelStatus)*nSize+sizeof(int));
  4625.     peer->Encode(&nSize, sizeof(int));
  4626.     for (TChannelStatusMap::iterator it = m_mChannelStatus.begin(); it != m_mChannelStatus.end(); it++) {
  4627.         peer->Encode(&it->first, sizeof(short));
  4628.         peer->Encode(&it->second, sizeof(BYTE));
  4629.     }
  4630. }
  4631.  
  4632. void CClientManager::ResetLastPlayerID(const TPacketNeedLoginLogInfo* data)
  4633. {
  4634.     CLoginData* pkLD = GetLoginDataByAID( data->dwPlayerID );
  4635.  
  4636.     if (NULL != pkLD)
  4637.     {
  4638.         pkLD->SetLastPlayerID( 0 );
  4639.     }
  4640. }
  4641.  
  4642. void CClientManager::ChargeCash(const TRequestChargeCash* packet)
  4643. {
  4644.     char szQuery[512];
  4645.  
  4646.     if (ERequestCharge_Cash == packet->eChargeType)
  4647.         sprintf(szQuery, "update account set cash = cash + %d where id = %d limit 1", packet->dwAmount, packet->dwAID);
  4648.     else if(ERequestCharge_Mileage == packet->eChargeType)
  4649.         sprintf(szQuery, "update account set mileage = mileage + %d where id = %d limit 1", packet->dwAmount, packet->dwAID);
  4650.     else
  4651.     {
  4652.         sys_err ("Invalid request charge type (type : %d, amount : %d, aid : %d)", packet->eChargeType, packet->dwAmount, packet->dwAID);
  4653.         return;
  4654.     }
  4655.  
  4656.     sys_err ("Request Charge (type : %d, amount : %d, aid : %d)", packet->eChargeType, packet->dwAmount, packet->dwAID);
  4657.  
  4658.     CDBManager::Instance().AsyncQuery(szQuery, SQL_ACCOUNT);
  4659. }
  4660.  
  4661. #ifdef __AUCTION__
  4662. void CClientManager::EnrollInAuction (CPeer * peer, DWORD owner_id, AuctionEnrollProductInfo* data)
  4663. {
  4664.     TPlayerTableCacheMap::iterator it = m_map_playerCache.find (owner_id);
  4665.  
  4666.     if (it == m_map_playerCache.end())
  4667.     {
  4668.         sys_err ("Invalid Player id %d. how can you get it?", owner_id);
  4669.         return;
  4670.     }
  4671.     CItemCache* c = GetItemCache (data->get_item_id());
  4672.  
  4673.     if (c == NULL)
  4674.     {
  4675.         sys_err ("Item %d doesn't exist in db cache.", data->get_item_id());
  4676.         return;
  4677.     }
  4678.     TPlayerItem* item = c->Get(false);
  4679.  
  4680.     if (item->owner != owner_id)
  4681.     {
  4682.         sys_err ("Player id %d doesn't have item %d.", owner_id, data->get_item_id());
  4683.         return;
  4684.     }
  4685.     // ÇöŔç ˝Ă°˘ + 24˝Ă°Ł ČÄ.
  4686.     time_t expired_time = time(0) + 24 * 60 * 60;
  4687.     TAuctionItemInfo auctioned_item_info (item->vnum, data->get_bid_price(),
  4688.         data->get_impur_price(), owner_id, "", expired_time, data->get_item_id(), 0, data->get_empire());
  4689.  
  4690.     AuctionResult result = AuctionManager::instance().EnrollInAuction( c, auctioned_item_info );
  4691.  
  4692.     if (result <= AUCTION_FAIL)
  4693.     {
  4694.         TPacketDGResultAuction enroll_result;
  4695.         enroll_result.cmd = AUCTION_ENR_AUC;
  4696.         enroll_result.target = data->get_item_id();
  4697.         enroll_result.result = result;
  4698.         peer->EncodeHeader(HEADER_DG_AUCTION_RESULT, owner_id, sizeof(TPacketDGResultAuction) + sizeof(TPlayerItem));
  4699.         peer->Encode(&enroll_result, sizeof(TPacketDGResultAuction));
  4700.         peer->Encode(c->Get(false), sizeof(TPlayerItem));
  4701.     }
  4702.     else
  4703.     {
  4704.         // ľĆŔĚĹŰ Äɽø¦ Auctionżˇ µî·Ď ÇßŔ¸´Ď ClientManagerżˇĽ­´Â »«´Ů.
  4705.         TItemCacheSetPtrMap::iterator it = m_map_pkItemCacheSetPtr.find(item->owner);
  4706.  
  4707.         if (it != m_map_pkItemCacheSetPtr.end())
  4708.         {
  4709.             it->second->erase(c);
  4710.         }
  4711.         m_map_itemCache.erase(item->id);
  4712.         sys_log(0, "Enroll In Auction Success. owner_id item_id %d %d", owner_id, item->id);
  4713.  
  4714.         TPacketDGResultAuction enroll_result;
  4715.         enroll_result.cmd = AUCTION_ENR_AUC;
  4716.         enroll_result.target = data->get_item_id();
  4717.         enroll_result.result = result;
  4718.         for (TPeerList::iterator it = m_peerList.begin(); it != m_peerList.end(); it++)
  4719.         {
  4720.             (*it)->EncodeHeader(HEADER_DG_AUCTION_RESULT, owner_id, sizeof(TPacketDGResultAuction) + sizeof(TPlayerItem) + sizeof(TAuctionItemInfo));
  4721.             (*it)->Encode(&enroll_result, sizeof(TPacketDGResultAuction));
  4722.             (*it)->Encode(c->Get(false), sizeof(TPlayerItem));
  4723.             (*it)->Encode(&auctioned_item_info, sizeof(TAuctionItemInfo));
  4724.         }
  4725.     }
  4726.  
  4727.     return;
  4728. }
  4729.  
  4730. void CClientManager::EnrollInSale (CPeer * peer, DWORD owner_id, AuctionEnrollSaleInfo* data)
  4731. {
  4732.     TPlayerTableCacheMap::iterator it = m_map_playerCache.find (owner_id);
  4733.  
  4734.     if (it == m_map_playerCache.end())
  4735.     {
  4736.         sys_err ("Invalid Player id %d. how can you get it?", owner_id);
  4737.         return;
  4738.     }
  4739.  
  4740.     CPlayerTableCache* player_cache = it->second;
  4741.     TPlayerTable* player = player_cache->Get(false);
  4742.  
  4743.     CItemCache* c = GetItemCache (data->get_item_id());
  4744.  
  4745.     if (c == NULL)
  4746.     {
  4747.         sys_err ("Item %d doesn't exist in db cache.", data->get_item_id());
  4748.         return;
  4749.     }
  4750.     TPlayerItem* item = c->Get(false);
  4751.  
  4752.     if (item->owner != owner_id)
  4753.     {
  4754.         sys_err ("Player id %d doesn't have item %d.", owner_id, data->get_item_id());
  4755.         return;
  4756.     }
  4757.     // ÇöŔç ˝Ă°˘ + 24˝Ă°Ł ČÄ.
  4758.     time_t expired_time = time(0) + 24 * 60 * 60;
  4759.     TSaleItemInfo sold_item_info (item->vnum, data->get_sale_price(),
  4760.         owner_id, player->name, data->get_item_id(), data->get_wisher_id());
  4761.  
  4762.     AuctionResult result = AuctionManager::instance().EnrollInSale( c, sold_item_info );
  4763.  
  4764.     if (result <= AUCTION_FAIL)
  4765.     {
  4766.         TPacketDGResultAuction enroll_result;
  4767.         enroll_result.cmd = AUCTION_ENR_SALE;
  4768.         enroll_result.target = data->get_item_id();
  4769.         enroll_result.result = result;
  4770.         peer->EncodeHeader(HEADER_DG_AUCTION_RESULT, owner_id, sizeof(TPacketDGResultAuction) + sizeof(TPlayerItem));
  4771.         peer->Encode(&enroll_result, sizeof(TPacketDGResultAuction));
  4772.         peer->Encode(c->Get(false), sizeof(TPlayerItem));
  4773.     }
  4774.     else
  4775.     {
  4776.         // ľĆŔĚĹŰ Äɽø¦ Auctionżˇ µî·Ď ÇßŔ¸´Ď ClientManagerżˇĽ­´Â »«´Ů.
  4777.         TItemCacheSetPtrMap::iterator it = m_map_pkItemCacheSetPtr.find(item->owner);
  4778.  
  4779.         if (it != m_map_pkItemCacheSetPtr.end())
  4780.         {
  4781.             it->second->erase(c);
  4782.         }
  4783.         m_map_itemCache.erase(item->id);
  4784.         sys_log(0, "Enroll In Sale Success. owner_id item_id %d %d", owner_id, item->id);
  4785.  
  4786.         TPacketDGResultAuction enroll_result;
  4787.         enroll_result.cmd = AUCTION_ENR_SALE;
  4788.         enroll_result.target = data->get_item_id();
  4789.         enroll_result.result = result;
  4790.  
  4791.         for (TPeerList::iterator it = m_peerList.begin(); it != m_peerList.end(); it++)
  4792.         {
  4793.             (*it)->EncodeHeader(HEADER_DG_AUCTION_RESULT, owner_id, sizeof(TPacketDGResultAuction) + sizeof(TPlayerItem) + sizeof(TSaleItemInfo));
  4794.             (*it)->Encode(&enroll_result, sizeof(TPacketDGResultAuction));
  4795.             (*it)->Encode(c->Get(false), sizeof(TPlayerItem));
  4796.             (*it)->Encode(&sold_item_info, sizeof(TSaleItemInfo));
  4797.         }
  4798.     }
  4799.  
  4800.     return;
  4801. }
  4802.  
  4803. void CClientManager::EnrollInWish (CPeer * peer, DWORD wisher_id, AuctionEnrollWishInfo* data)
  4804. {
  4805.     TPlayerTableCacheMap::iterator it = m_map_playerCache.find (wisher_id);
  4806.  
  4807.     if (it == m_map_playerCache.end())
  4808.     {
  4809.         sys_err ("Invalid Player id %d. how can you get it?", wisher_id);
  4810.         return;
  4811.     }
  4812.  
  4813.     CPlayerTableCache* player_cache = it->second;
  4814.     TPlayerTable* player = player_cache->Get(false);
  4815.  
  4816.     // ÇöŔç ˝Ă°˘ + 24˝Ă°Ł ČÄ.
  4817.     time_t expired_time = time(0) + 24 * 60 * 60;
  4818.     TWishItemInfo wished_item_info (data->get_item_num(), data->get_wish_price(), wisher_id, player->name, expired_time, data->get_empire());
  4819.  
  4820.     AuctionResult result = AuctionManager::instance().EnrollInWish ( wished_item_info );
  4821.  
  4822.     if (result <= AUCTION_FAIL)
  4823.     {
  4824.         sys_log(0, "Enroll In Wish Success. wisher_id item_num %d %d", wisher_id, data->get_item_num());
  4825.  
  4826.         TPacketDGResultAuction enroll_result;
  4827.         enroll_result.cmd = AUCTION_ENR_WISH;
  4828.         enroll_result.target = data->get_item_num();
  4829.         enroll_result.result = result;
  4830.         peer->EncodeHeader(HEADER_DG_AUCTION_RESULT, wisher_id, sizeof(TPacketDGResultAuction));
  4831.         peer->Encode(&enroll_result, sizeof(TPacketDGResultAuction));
  4832.     }
  4833.     else
  4834.     {
  4835.         sys_log(0, "Enroll In Wish Fail. wisher_id item_num %d %d", wisher_id, data->get_item_num());
  4836.  
  4837.         TPacketDGResultAuction enroll_result;
  4838.         enroll_result.cmd = AUCTION_ENR_WISH;
  4839.         enroll_result.target = data->get_item_num();
  4840.         enroll_result.result = result;
  4841.  
  4842.         for (TPeerList::iterator it = m_peerList.begin(); it != m_peerList.end(); it++)
  4843.         {
  4844.             (*it)->EncodeHeader(HEADER_DG_AUCTION_RESULT, wisher_id, sizeof(TPacketDGResultAuction) + sizeof(TWishItemInfo));
  4845.             (*it)->Encode(&enroll_result, sizeof(TPacketDGResultAuction));
  4846.             (*it)->Encode(&wished_item_info, sizeof(TWishItemInfo));
  4847.         }
  4848.     }
  4849.  
  4850.     return;
  4851. }
  4852.  
  4853. void CClientManager::AuctionBid (CPeer * peer, DWORD bidder_id, AuctionBidInfo* data)
  4854. {
  4855.     TPlayerTableCacheMap::iterator it = m_map_playerCache.find (bidder_id);
  4856.  
  4857.     if (it == m_map_playerCache.end())
  4858.     {
  4859.         sys_err ("Invalid Player id %d. how can you get it?", bidder_id);
  4860.         return;
  4861.     }
  4862.  
  4863.     CPlayerTableCache* player_cache = it->second;
  4864.     TPlayerTable* player = player_cache->Get(false);
  4865.  
  4866.     AuctionResult result = AuctionManager::instance().Bid(bidder_id, player->name, data->get_item_id(), data->get_bid_price());
  4867.  
  4868.     if (result == AUCTION_FAIL)
  4869.     {
  4870.         sys_log(0, "Bid Fail. bidder_id item_id %d %d", bidder_id, data->get_item_id());
  4871.     }
  4872.     else
  4873.     {
  4874.         sys_log(0, "Bid Success. bidder_id item_id %d %d", bidder_id, data->get_item_id());
  4875.     }
  4876.  
  4877.     if (result <= AUCTION_FAIL)
  4878.     {
  4879.         TPacketDGResultAuction enroll_result;
  4880.         enroll_result.cmd = AUCTION_BID;
  4881.         enroll_result.target = data->get_bid_price();
  4882.         enroll_result.result = result;
  4883.  
  4884.         peer->EncodeHeader(HEADER_DG_AUCTION_RESULT, bidder_id, sizeof(TPacketDGResultAuction) + sizeof(AuctionBidInfo));
  4885.         peer->Encode(&enroll_result, sizeof(TPacketDGResultAuction));
  4886.     }
  4887.     else
  4888.     {
  4889.         TPacketDGResultAuction enroll_result;
  4890.         enroll_result.cmd = AUCTION_BID;
  4891.         enroll_result.target = data->get_item_id();
  4892.         enroll_result.result = result;
  4893.  
  4894.         TAuctionItemInfo* auctioned_item_info = AuctionManager::instance().GetAuctionItemInfoCache(data->get_item_id())->Get(false);
  4895.  
  4896.         for (TPeerList::iterator it = m_peerList.begin(); it != m_peerList.end(); it++)
  4897.         {
  4898.             (*it)->EncodeHeader(HEADER_DG_AUCTION_RESULT, bidder_id, sizeof(TPacketDGResultAuction) + sizeof(TAuctionItemInfo));
  4899.             (*it)->Encode(&enroll_result, sizeof(TPacketDGResultAuction));
  4900.             (*it)->Encode(auctioned_item_info, sizeof(TAuctionItemInfo));
  4901.         }
  4902.  
  4903.     }
  4904.     return;
  4905. }
  4906.  
  4907. void CClientManager::AuctionImpur (CPeer * peer, DWORD purchaser_id, AuctionImpurInfo* data)
  4908. {
  4909.     TPlayerTableCacheMap::iterator it = m_map_playerCache.find (purchaser_id);
  4910.  
  4911.     if (it == m_map_playerCache.end())
  4912.     {
  4913.         sys_err ("Invalid Player id %d. how can you get it?", purchaser_id);
  4914.         return;
  4915.     }
  4916.  
  4917.     CPlayerTableCache* player_cache = it->second;
  4918.     TPlayerTable* player = player_cache->Get(false);
  4919.  
  4920.     AuctionResult result = AuctionManager::instance().Impur(purchaser_id, player->name, data->get_item_id());
  4921.  
  4922.     if (result == AUCTION_FAIL)
  4923.     {
  4924.         sys_log(0, "Impur Fail. purchaser_id item_id %d %d", purchaser_id, data->get_item_id());
  4925.     }
  4926.     else
  4927.     {
  4928.         sys_log(0, "Impur Success. purchaser_id item_id %d %d", purchaser_id, data->get_item_id());
  4929.     }
  4930.  
  4931.     if (result <= AUCTION_FAIL)
  4932.     {
  4933.         TPacketDGResultAuction enroll_result;
  4934.         enroll_result.cmd = AUCTION_IMME_PUR;
  4935.         enroll_result.target = data->get_item_id();
  4936.         enroll_result.result = result;
  4937.  
  4938.         peer->EncodeHeader(HEADER_DG_AUCTION_RESULT, purchaser_id, sizeof(TPacketDGResultAuction));
  4939.         peer->Encode(&enroll_result, sizeof(TPacketDGResultAuction));
  4940.     }
  4941.     else
  4942.     {
  4943.         TPacketDGResultAuction enroll_result;
  4944.         enroll_result.cmd = AUCTION_IMME_PUR;
  4945.         enroll_result.target = data->get_item_id();
  4946.         enroll_result.result = result;
  4947.  
  4948.         TAuctionItemInfo* auctioned_item_info = AuctionManager::instance().GetAuctionItemInfoCache(data->get_item_id())->Get(false);
  4949.         for (TPeerList::iterator it = m_peerList.begin(); it != m_peerList.end(); it++)
  4950.         {
  4951.             (*it)->EncodeHeader(HEADER_DG_AUCTION_RESULT, purchaser_id, sizeof(TPacketDGResultAuction) + sizeof(TAuctionItemInfo));
  4952.             (*it)->Encode(&enroll_result, sizeof(TPacketDGResultAuction));
  4953.             (*it)->Encode(auctioned_item_info, sizeof(TAuctionItemInfo));
  4954.         }
  4955.     }
  4956.     return;
  4957. }
  4958.  
  4959. void CClientManager::AuctionGetAuctionedItem (CPeer * peer, DWORD actor_id, DWORD item_id)
  4960. {
  4961.     TPlayerTableCacheMap::iterator it = m_map_playerCache.find (actor_id);
  4962.     AuctionResult result = AUCTION_FAIL;
  4963.     if (it == m_map_playerCache.end())
  4964.     {
  4965.         sys_err ("Invalid Player id %d. how can you get it?", actor_id);
  4966.         return;
  4967.     }
  4968.  
  4969.     TPlayerItem item;
  4970.     result = AuctionManager::instance().GetAuctionedItem(actor_id, item_id, item);
  4971.  
  4972.     if (result <= AUCTION_FAIL)
  4973.     {
  4974.         TPacketDGResultAuction enroll_result;
  4975.         enroll_result.cmd = AUCTION_GET_AUC;
  4976.         enroll_result.target = item_id;
  4977.         enroll_result.result = result;
  4978.  
  4979.         peer->EncodeHeader (HEADER_DG_AUCTION_RESULT, actor_id, sizeof(TPacketDGResultAuction));
  4980.         peer->Encode (&enroll_result, sizeof(TPacketDGResultAuction));
  4981.     }
  4982.     else
  4983.     {
  4984.         TPacketDGResultAuction enroll_result;
  4985.         enroll_result.cmd = AUCTION_GET_AUC;
  4986.         enroll_result.target = item_id;
  4987.         enroll_result.result = result;
  4988.  
  4989.         for (TPeerList::iterator it = m_peerList.begin(); it != m_peerList.end(); it++)
  4990.         {
  4991.             (*it)->EncodeHeader (HEADER_DG_AUCTION_RESULT, actor_id, sizeof(TPacketDGResultAuction) + sizeof(TPlayerItem));
  4992.             (*it)->Encode (&enroll_result, sizeof(TPacketDGResultAuction));
  4993.             (*it)->Encode (&item, sizeof(TPlayerItem));
  4994.         }
  4995.     }
  4996.     return;
  4997. }
  4998.  
  4999. void CClientManager::AuctionBuySoldItem (CPeer * peer, DWORD actor_id, DWORD item_id)
  5000. {
  5001.     TPlayerTableCacheMap::iterator it = m_map_playerCache.find (actor_id);
  5002.     AuctionResult result = AUCTION_FAIL;
  5003.     if (it == m_map_playerCache.end())
  5004.     {
  5005.         sys_err ("Invalid Player id %d. how can you get it?", actor_id);
  5006.         return;
  5007.     }
  5008.  
  5009.     TPlayerItem item;
  5010.     result = AuctionManager::instance().BuySoldItem(actor_id, item_id, item);
  5011.  
  5012.     if (result <= AUCTION_FAIL)
  5013.     {
  5014.         TPacketDGResultAuction enroll_result;
  5015.         enroll_result.cmd = AUCTION_BUY_SOLD;
  5016.         enroll_result.target = item_id;
  5017.         enroll_result.result = result;
  5018.  
  5019.         peer->EncodeHeader (HEADER_DG_AUCTION_RESULT, actor_id, sizeof(TPacketDGResultAuction));
  5020.         peer->Encode (&enroll_result, sizeof(TPacketDGResultAuction));
  5021.     }
  5022.     else
  5023.     {
  5024.         TPacketDGResultAuction enroll_result;
  5025.         enroll_result.cmd = AUCTION_BUY_SOLD;
  5026.         enroll_result.target = item_id;
  5027.         enroll_result.result = result;
  5028.  
  5029.         for (TPeerList::iterator it = m_peerList.begin(); it != m_peerList.end(); it++)
  5030.         {
  5031.             (*it)->EncodeHeader (HEADER_DG_AUCTION_RESULT, actor_id, sizeof(TPacketDGResultAuction) + sizeof(TPlayerItem));
  5032.             (*it)->Encode (&enroll_result, sizeof(TPacketDGResultAuction));
  5033.             (*it)->Encode (&item, sizeof(TPlayerItem));
  5034.         }
  5035.     }
  5036.     return;
  5037. }
  5038.  
  5039. void CClientManager::AuctionCancelAuction (CPeer * peer, DWORD actor_id, DWORD item_id)
  5040. {
  5041.     TPlayerTableCacheMap::iterator it = m_map_playerCache.find (actor_id);
  5042.     AuctionResult result = AUCTION_FAIL;
  5043.     if (it == m_map_playerCache.end())
  5044.     {
  5045.         sys_err ("Invalid Player id %d. how can you get it?", actor_id);
  5046.         return;
  5047.     }
  5048.  
  5049.     TPlayerItem item;
  5050.     result = AuctionManager::instance().CancelAuction(actor_id, item_id, item);
  5051.  
  5052.     if (result <= AUCTION_FAIL)
  5053.     {
  5054.         TPacketDGResultAuction enroll_result;
  5055.         enroll_result.cmd = AUCTION_CANCEL_AUC;
  5056.         enroll_result.target = item_id;
  5057.         enroll_result.result = result;
  5058.  
  5059.         peer->EncodeHeader (HEADER_DG_AUCTION_RESULT, actor_id, sizeof(TPacketDGResultAuction));
  5060.         peer->Encode (&enroll_result, sizeof(TPacketDGResultAuction));
  5061.     }
  5062.     else
  5063.     {
  5064.         TPacketDGResultAuction enroll_result;
  5065.         enroll_result.cmd = AUCTION_CANCEL_AUC;
  5066.         enroll_result.target = item_id;
  5067.         enroll_result.result = result;
  5068.  
  5069.         for (TPeerList::iterator it = m_peerList.begin(); it != m_peerList.end(); it++)
  5070.         {
  5071.             (*it)->EncodeHeader (HEADER_DG_AUCTION_RESULT, actor_id, sizeof(TPacketDGResultAuction) + sizeof(TPlayerItem));
  5072.             (*it)->Encode (&enroll_result, sizeof(TPacketDGResultAuction));
  5073.             (*it)->Encode (&item, sizeof(TPlayerItem));
  5074.         }
  5075.     }
  5076.     return;
  5077. }
  5078.  
  5079. void CClientManager::AuctionCancelWish (CPeer * peer, DWORD actor_id, DWORD item_num)
  5080. {
  5081.     TPlayerTableCacheMap::iterator it = m_map_playerCache.find (actor_id);
  5082.     AuctionResult result = AUCTION_FAIL;
  5083.     if (it == m_map_playerCache.end())
  5084.     {
  5085.         sys_err ("Invalid Player id %d. how can you get it?", actor_id);
  5086.         return;
  5087.     }
  5088.  
  5089.     TPlayerItem item;
  5090.     result = AuctionManager::instance().CancelWish(actor_id, item_num);
  5091.  
  5092.     if (result <= AUCTION_FAIL)
  5093.     {
  5094.         TPacketDGResultAuction enroll_result;
  5095.         enroll_result.cmd = AUCTION_CANCEL_WISH;
  5096.         enroll_result.target = item_num;
  5097.         enroll_result.result = result;
  5098.  
  5099.         peer->EncodeHeader (HEADER_DG_AUCTION_RESULT, actor_id, sizeof(TPacketDGResultAuction));
  5100.         peer->Encode (&enroll_result, sizeof(TPacketDGResultAuction));
  5101.     }
  5102.     else
  5103.     {
  5104.         TPacketDGResultAuction enroll_result;
  5105.         enroll_result.cmd = AUCTION_CANCEL_WISH;
  5106.         enroll_result.target = item_num;
  5107.         enroll_result.result = result;
  5108.  
  5109.         for (TPeerList::iterator it = m_peerList.begin(); it != m_peerList.end(); it++)
  5110.         {
  5111.             (*it)->EncodeHeader (HEADER_DG_AUCTION_RESULT, actor_id, sizeof(TPacketDGResultAuction));
  5112.             (*it)->Encode (&enroll_result, sizeof(TPacketDGResultAuction));
  5113.         }
  5114.     }
  5115.     return;
  5116. }
  5117.  
  5118. void CClientManager::AuctionCancelSale (CPeer * peer, DWORD actor_id, DWORD item_id)
  5119. {
  5120.     TPlayerTableCacheMap::iterator it = m_map_playerCache.find (actor_id);
  5121.     AuctionResult result = AUCTION_FAIL;
  5122.     if (it == m_map_playerCache.end())
  5123.     {
  5124.         sys_err ("Invalid Player id %d. how can you get it?", actor_id);
  5125.         return;
  5126.     }
  5127.  
  5128.     TPlayerItem item;
  5129.     result = AuctionManager::instance().CancelSale(actor_id, item_id, item);
  5130.  
  5131.     if (result <= AUCTION_FAIL)
  5132.     {
  5133.         TPacketDGResultAuction enroll_result;
  5134.         enroll_result.cmd = AUCTION_CANCEL_SALE;
  5135.         enroll_result.target = item_id;
  5136.         enroll_result.result = result;
  5137.  
  5138.         peer->EncodeHeader (HEADER_DG_AUCTION_RESULT, actor_id, sizeof(TPacketDGResultAuction));
  5139.         peer->Encode (&enroll_result, sizeof(TPacketDGResultAuction));
  5140.     }
  5141.     else
  5142.     {
  5143.         TPacketDGResultAuction enroll_result;
  5144.         enroll_result.cmd = AUCTION_CANCEL_SALE;
  5145.         enroll_result.target = item_id;
  5146.         enroll_result.result = result;
  5147.  
  5148.         for (TPeerList::iterator it = m_peerList.begin(); it != m_peerList.end(); it++)
  5149.         {
  5150.             (*it)->EncodeHeader (HEADER_DG_AUCTION_RESULT, actor_id, sizeof(TPacketDGResultAuction) + sizeof(TPlayerItem));
  5151.             (*it)->Encode (&enroll_result, sizeof(TPacketDGResultAuction));
  5152.             (*it)->Encode (&item, sizeof(TPlayerItem));
  5153.         }
  5154.     }
  5155.     return;
  5156. }
  5157.  
  5158. void CClientManager::AuctionDeleteAuctionItem (CPeer * peer, DWORD actor_id, DWORD item_id)
  5159. {
  5160.     TPlayerTableCacheMap::iterator it = m_map_playerCache.find (actor_id);
  5161.     AuctionResult result = AUCTION_FAIL;
  5162.     if (it == m_map_playerCache.end())
  5163.     {
  5164.         sys_err ("Invalid Player id %d. how can you get it?", actor_id);
  5165.         return;
  5166.     }
  5167.  
  5168.     AuctionManager::instance().DeleteAuctionItem (actor_id, item_id);
  5169. }
  5170. void CClientManager::AuctionDeleteSaleItem (CPeer * peer, DWORD actor_id, DWORD item_id)
  5171. {
  5172.     TPlayerTableCacheMap::iterator it = m_map_playerCache.find (actor_id);
  5173.     AuctionResult result = AUCTION_FAIL;
  5174.     if (it == m_map_playerCache.end())
  5175.     {
  5176.         sys_err ("Invalid Player id %d. how can you get it?", actor_id);
  5177.         return;
  5178.     }
  5179.  
  5180.     AuctionManager::instance().DeleteSaleItem (actor_id, item_id);
  5181. }
  5182.  
  5183. // ReBid´Â ŔĚŔü ŔÔÂű±Ýľ×żˇ ´őÇŘĽ­ ŔÔÂűÇŃ´Ů.
  5184. // ReBidżˇĽ± data->bid_price°ˇ ŔĚŔü ŔÔÂű°ˇżˇ ´őÇŘÁ®Ľ­
  5185. // ±× ±Ýľ×Ŕ¸·Î rebidÇĎ´Â °Í.
  5186. // ŔĚ·¸°Ô ÇŃ ŔĚŔŻ´Â rebidżˇ ˝ÇĆĐ ÇßŔ» ¶§,
  5187. // ŔŻŔúŔÇ ČŁÁÖ¸Ó´ĎżˇĽ­ »« µ·Ŕ» µą·ÁÁÖ±â ĆíÇĎ°Ô Çϱâ Ŕ§ÇÔŔĚ´Ů.
  5188.  
  5189. void CClientManager::AuctionReBid (CPeer * peer, DWORD bidder_id, AuctionBidInfo* data)
  5190. {
  5191.     TPlayerTableCacheMap::iterator it = m_map_playerCache.find (bidder_id);
  5192.  
  5193.     if (it == m_map_playerCache.end())
  5194.     {
  5195.         sys_err ("Invalid Player id %d. how can you get it?", bidder_id);
  5196.         return;
  5197.     }
  5198.  
  5199.     CPlayerTableCache* player_cache = it->second;
  5200.     TPlayerTable* player = player_cache->Get(false);
  5201.  
  5202.     AuctionResult result = AuctionManager::instance().ReBid(bidder_id, player->name, data->get_item_id(), data->get_bid_price());
  5203.  
  5204.     if (result == AUCTION_FAIL)
  5205.     {
  5206.         sys_log(0, "ReBid Fail. bidder_id item_id %d %d", bidder_id, data->get_item_id());
  5207.     }
  5208.     else
  5209.     {
  5210.         sys_log(0, "ReBid Success. bidder_id item_id %d %d", bidder_id, data->get_item_id());
  5211.     }
  5212.  
  5213.     {
  5214.         TPacketDGResultAuction enroll_result;
  5215.         enroll_result.cmd = AUCTION_REBID;
  5216.         enroll_result.target = data->get_item_id();
  5217.         enroll_result.result = result;
  5218.  
  5219.         peer->EncodeHeader(HEADER_DG_AUCTION_RESULT, bidder_id, sizeof(TPacketDGResultAuction) + sizeof(int));
  5220.         peer->Encode(&enroll_result, sizeof(TPacketDGResultAuction));
  5221.         peer->EncodeDWORD(data->get_bid_price());
  5222.     }
  5223.     else
  5224.     {
  5225.         TPacketDGResultAuction enroll_result;
  5226.         enroll_result.cmd = AUCTION_REBID;
  5227.         enroll_result.target = data->get_item_id();
  5228.         enroll_result.result = result;
  5229.  
  5230.         TAuctionItemInfo* auctioned_item_info = AuctionManager::instance().GetAuctionItemInfoCache(data->get_item_id())->Get(false);
  5231.  
  5232.         for (TPeerList::iterator it = m_peerList.begin(); it != m_peerList.end(); it++)
  5233.         {
  5234.             (*it)->EncodeHeader(HEADER_DG_AUCTION_RESULT, bidder_id, sizeof(TPacketDGResultAuction) + sizeof(TAuctionItemInfo));
  5235.             (*it)->Encode(&enroll_result, sizeof(TPacketDGResultAuction));
  5236.             (*it)->Encode(auctioned_item_info, sizeof(TAuctionItemInfo));
  5237.         }
  5238.     }
  5239.     return;
  5240. }
  5241.  
  5242. void CClientManager::AuctionBidCancel (CPeer * peer, DWORD bidder_id, DWORD item_id)
  5243. {
  5244.     AuctionResult result = AuctionManager::instance().BidCancel (bidder_id, item_id);
  5245.  
  5246.     if (result <= AUCTION_FAIL)
  5247.     {
  5248.         TPacketDGResultAuction enroll_result;
  5249.         enroll_result.cmd = AUCTION_BID_CANCEL;
  5250.         enroll_result.target = item_id;
  5251.         enroll_result.result = result;
  5252.  
  5253.         peer->EncodeHeader(HEADER_DG_AUCTION_RESULT, bidder_id, sizeof(TPacketDGResultAuction));
  5254.         peer->Encode(&enroll_result, sizeof(TPacketDGResultAuction));
  5255.     }
  5256.     else
  5257.     {
  5258.         TPacketDGResultAuction enroll_result;
  5259.         enroll_result.cmd = AUCTION_BID_CANCEL;
  5260.         enroll_result.target = item_id;
  5261.         enroll_result.result = result;
  5262.  
  5263.         peer->EncodeHeader(HEADER_DG_AUCTION_RESULT, bidder_id, sizeof(TPacketDGResultAuction));
  5264.         peer->Encode(&enroll_result, sizeof(TPacketDGResultAuction));
  5265.     }
  5266. }
  5267. #endif
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top