Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 17.77 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <sstream>
  3.  
  4. #include "desc.h"
  5. #include "desc_manager.h"
  6. #include "char.h"
  7. #include "buffer_manager.h"
  8. #include "config.h"
  9. #include "profiler.h"
  10. #include "p2p.h"
  11. #include "log.h"
  12. #include "db.h"
  13. #include "questmanager.h"
  14. #include "login_sim.h"
  15. #include "fishing.h"
  16. #include "TrafficProfiler.h"
  17. #include "priv_manager.h"
  18. #include "castle.h"
  19. #include "dev_log.h"
  20. #include "HackShield_Impl.h"
  21. #include "check_server.h"
  22. #ifndef __WIN32__
  23.     #include "limit_time.h"
  24. #endif
  25. #include "../../common/CommonDefines.h"
  26.  
  27. #include "utils.h"
  28.  
  29. bool IsEmptyAdminPage()
  30. {
  31.     return g_stAdminPageIP.empty();
  32. }
  33.  
  34. bool IsAdminPage(const char * ip)
  35. {
  36.     for (size_t n = 0; n < g_stAdminPageIP.size(); ++n)
  37.     {
  38.         if (g_stAdminPageIP[n] == ip)
  39.             return 1;
  40.     }
  41.     return 0;
  42. }
  43.  
  44. void ClearAdminPages()
  45. {
  46.     for (size_t n = 0; n < g_stAdminPageIP.size(); ++n)
  47.         g_stAdminPageIP[n].clear();
  48.  
  49.     g_stAdminPageIP.clear();
  50. }
  51.  
  52. CInputProcessor::CInputProcessor() : m_pPacketInfo(NULL), m_iBufferLeft(0)
  53. {
  54.     if (!m_pPacketInfo)
  55.         BindPacketInfo(&m_packetInfoCG);
  56. }
  57.  
  58. void CInputProcessor::BindPacketInfo(CPacketInfo * pPacketInfo)
  59. {
  60.     m_pPacketInfo = pPacketInfo;
  61. }
  62.  
  63. bool CInputProcessor::Process(LPDESC lpDesc, const void * c_pvOrig, int iBytes, int & r_iBytesProceed)
  64. {
  65.     const char * c_pData = (const char *) c_pvOrig;
  66.  
  67.     BYTE    bLastHeader = 0;
  68.     int     iLastPacketLen = 0;
  69.     int     iPacketLen;
  70.  
  71.     if (!m_pPacketInfo)
  72.     {
  73.         sys_err("No packet info has been binded to");
  74.         return true;
  75.     }
  76.  
  77.     for (m_iBufferLeft = iBytes; m_iBufferLeft > 0;)
  78.     {
  79.         BYTE bHeader = (BYTE) *(c_pData);
  80.         const char * c_pszName;
  81.  
  82.         if (bHeader == 0) // 암호화 처리가 있으므로 0번 헤더는 스킵한다.
  83.             iPacketLen = 1;
  84.         else if (!m_pPacketInfo->Get(bHeader, &iPacketLen, &c_pszName))
  85.         {
  86.             sys_err("UNKNOWN HEADER: %d, LAST HEADER: %d(%d), REMAIN BYTES: %d, fd: %d",
  87.                     bHeader, bLastHeader, iLastPacketLen, m_iBufferLeft, lpDesc->GetSocket());
  88.             //printdata((BYTE *) c_pvOrig, m_iBufferLeft);
  89.             lpDesc->SetPhase(PHASE_CLOSE);
  90.             return true;
  91.         }
  92.  
  93.         if (m_iBufferLeft < iPacketLen)
  94.             return true;
  95.  
  96.         if (bHeader)
  97.         {
  98.             if (test_server && bHeader != HEADER_CG_MOVE)
  99.                 sys_log(0, "Packet Analyze [Header %d][bufferLeft %d] ", bHeader, m_iBufferLeft);
  100.  
  101.             m_pPacketInfo->Start();
  102.  
  103.             int iExtraPacketSize = Analyze(lpDesc, bHeader, c_pData);
  104.  
  105.             if (iExtraPacketSize < 0)
  106.                 return true;
  107.  
  108.             iPacketLen += iExtraPacketSize;
  109.             lpDesc->Log("%s %d", c_pszName, iPacketLen);
  110.             m_pPacketInfo->End();
  111.         }
  112.  
  113.         // TRAFFIC_PROFILER
  114.         if (g_bTrafficProfileOn)
  115.             TrafficProfiler::instance().Report(TrafficProfiler::IODIR_INPUT, bHeader, iPacketLen);
  116.         // END_OF_TRAFFIC_PROFILER
  117.  
  118.         if (bHeader == HEADER_CG_PONG)
  119.             sys_log(0, "PONG! %u %u", m_pPacketInfo->IsSequence(bHeader), *(BYTE *) (c_pData + iPacketLen - sizeof(BYTE)));
  120.  
  121.         if (m_pPacketInfo->IsSequence(bHeader))
  122.         {
  123.             BYTE bSeq = lpDesc->GetSequence();
  124.             BYTE bSeqReceived = *(BYTE *) (c_pData + iPacketLen - sizeof(BYTE));
  125.  
  126.             if (bSeq != bSeqReceived)
  127.             {
  128.                 sys_err("SEQUENCE %x mismatch 0x%x != 0x%x header %u", get_pointer(lpDesc), bSeq, bSeqReceived, bHeader);
  129.  
  130.                 LPCHARACTER ch = lpDesc->GetCharacter();
  131.  
  132.                 char buf[1024];
  133.                 int offset, len;
  134.  
  135.                 offset = snprintf(buf, sizeof(buf), "SEQUENCE_LOG [%s]-------------\n", ch ? ch->GetName() : "UNKNOWN");
  136.  
  137.                 if (offset < 0 || offset >= (int) sizeof(buf))
  138.                     offset = sizeof(buf) - 1;
  139.  
  140.                 for (size_t i = 0; i < lpDesc->m_seq_vector.size(); ++i)
  141.                 {
  142.                     len = snprintf(buf + offset, sizeof(buf) - offset, "\t[%03d : 0x%x]\n",
  143.                             lpDesc->m_seq_vector[i].hdr,
  144.                             lpDesc->m_seq_vector[i].seq);
  145.  
  146.                     if (len < 0 || len >= (int) sizeof(buf) - offset)
  147.                         offset += (sizeof(buf) - offset) - 1;
  148.                     else
  149.                         offset += len;
  150.                 }
  151.  
  152.                 snprintf(buf + offset, sizeof(buf) - offset, "\t[%03d : 0x%x]\n", bHeader, bSeq);
  153.                 sys_err("%s", buf);
  154.  
  155.                 lpDesc->SetPhase(PHASE_CLOSE);
  156.                 return true;
  157.             }
  158.             else
  159.             {
  160.                 lpDesc->push_seq(bHeader, bSeq);
  161.                 lpDesc->SetNextSequence();
  162.                 //sys_err("SEQUENCE %x match %u next %u header %u", lpDesc, bSeq, lpDesc->GetSequence(), bHeader);
  163.             }
  164.         }
  165.  
  166.         c_pData += iPacketLen;
  167.         m_iBufferLeft -= iPacketLen;
  168.         r_iBytesProceed += iPacketLen;
  169.  
  170.         iLastPacketLen = iPacketLen;
  171.         bLastHeader = bHeader;
  172.  
  173.         if (GetType() != lpDesc->GetInputProcessor()->GetType())
  174.             return false;
  175.     }
  176.  
  177.     return true;
  178. }
  179.  
  180. void CInputProcessor::Pong(LPDESC d)
  181. {
  182.     d->SetPong(true);
  183.  
  184. #ifdef ENABLE_LIMIT_TIME
  185.     if (!CCheckServer::Instance().IsValid())
  186.     {
  187.         exit(0);
  188.         return;
  189.     }
  190. #endif
  191. }
  192.  
  193. void CInputProcessor::Handshake(LPDESC d, const char * c_pData)
  194. {
  195.     TPacketCGHandshake * p = (TPacketCGHandshake *) c_pData;
  196.  
  197.     if (d->GetHandshake() != p->dwHandshake)
  198.     {
  199.         sys_err("Invalid Handshake on %d", d->GetSocket());
  200.         d->SetPhase(PHASE_CLOSE);
  201.     }
  202.     else
  203.     {
  204.         if (d->IsPhase(PHASE_HANDSHAKE))
  205.         {
  206.             if (d->HandshakeProcess(p->dwTime, p->lDelta, false))
  207.             {
  208. #ifdef _IMPROVED_PACKET_ENCRYPTION_
  209.                 d->SendKeyAgreement();
  210. #else
  211.                 if (g_bAuthServer)
  212.                     d->SetPhase(PHASE_AUTH);
  213.                 else
  214.                     d->SetPhase(PHASE_LOGIN);
  215. #endif // #ifdef _IMPROVED_PACKET_ENCRYPTION_
  216.             }
  217.         }
  218.         else
  219.             d->HandshakeProcess(p->dwTime, p->lDelta, true);
  220.     }
  221. }
  222.  
  223. void CInputProcessor::Version(LPCHARACTER ch, const char* c_pData)
  224. {
  225.     if (!ch)
  226.         return;
  227.  
  228.     TPacketCGClientVersion * p = (TPacketCGClientVersion *) c_pData;
  229.     sys_log(0, "VERSION: %s %s %s", ch->GetName(), p->timestamp, p->filename);
  230.     ch->GetDesc()->SetClientVersion(p->timestamp);
  231. }
  232.  
  233. void LoginFailure(LPDESC d, const char * c_pszStatus)
  234. {
  235.     if (!d)
  236.         return;
  237.  
  238.     TPacketGCLoginFailure failurePacket;
  239.  
  240.     failurePacket.header = HEADER_GC_LOGIN_FAILURE;
  241.     strlcpy(failurePacket.szStatus, c_pszStatus, sizeof(failurePacket.szStatus));
  242.  
  243.     d->Packet(&failurePacket, sizeof(failurePacket));
  244. }
  245.  
  246. CInputHandshake::CInputHandshake()
  247. {
  248.     CPacketInfoCG * pkPacketInfo = M2_NEW CPacketInfoCG;
  249.     pkPacketInfo->SetSequence(HEADER_CG_PONG, false);
  250.  
  251.     m_pMainPacketInfo = m_pPacketInfo;
  252.     BindPacketInfo(pkPacketInfo);
  253. }
  254.  
  255. CInputHandshake::~CInputHandshake()
  256. {
  257.     if( NULL != m_pPacketInfo )
  258.     {
  259.         M2_DELETE(m_pPacketInfo);
  260.         m_pPacketInfo = NULL;
  261.     }
  262. }
  263.  
  264.  
  265. std::map<DWORD, CLoginSim *> g_sim;
  266. std::map<DWORD, CLoginSim *> g_simByPID;
  267. std::vector<TPlayerTable> g_vec_save;
  268.  
  269. // BLOCK_CHAT
  270. ACMD(do_block_chat);
  271. // END_OF_BLOCK_CHAT
  272.  
  273. int CInputHandshake::Analyze(LPDESC d, BYTE bHeader, const char * c_pData)
  274. {
  275.     if (bHeader == 10) // 엔터는 무시
  276.         return 0;
  277.  
  278.     if (bHeader == HEADER_CG_TEXT)
  279.     {
  280. #ifdef ENABLE_PORT_SECURITY
  281.         if (IsEmptyAdminPage() || !IsAdminPage(inet_ntoa(d->GetAddr().sin_addr))) // block if adminpage is not set or if not admin
  282.         {
  283.             sys_log(0, "SOCKET_CMD: BLOCK FROM(%s)", d->GetHostName());
  284.             return -1;
  285.         }
  286. #endif
  287.         ++c_pData;
  288.         const char * c_pSep;
  289.  
  290.         if (!(c_pSep = strchr(c_pData, '\n')))  // \n을 찾는다.
  291.             return -1;
  292.  
  293.         if (*(c_pSep - 1) == '\r')
  294.             --c_pSep;
  295.  
  296.         std::string stResult;
  297.         std::string stBuf;
  298.         stBuf.assign(c_pData, 0, c_pSep - c_pData);
  299.  
  300.         sys_log(0, "SOCKET_CMD: FROM(%s) CMD(%s)", d->GetHostName(), stBuf.c_str());
  301.  
  302.         if (!stBuf.compare("IS_SERVER_UP"))
  303.         {
  304.             if (g_bNoMoreClient)
  305.                 stResult = "NO";
  306.             else
  307.                 stResult = "YES";
  308.         }
  309.         else if (!stBuf.compare("IS_PASSPOD_UP"))
  310.         {
  311.             if (g_bNoPasspod)
  312.                 stResult = "NO";
  313.             else
  314.                 stResult = "YES";
  315.         }
  316.         //else if (!stBuf.compare("SHOWMETHEMONEY"))
  317.         else if (stBuf == g_stAdminPagePassword)
  318.         {
  319.             if (!IsEmptyAdminPage())
  320.             {
  321.                 if (!IsAdminPage(inet_ntoa(d->GetAddr().sin_addr)))
  322.                 {
  323.                     char szTmp[64];
  324.                     snprintf(szTmp, sizeof(szTmp), "WEBADMIN : Wrong Connector : %s", inet_ntoa(d->GetAddr().sin_addr));
  325.                     stResult += szTmp;
  326.                 }
  327.                 else
  328.                 {
  329.                     d->SetAdminMode();
  330.                     stResult = "UNKNOWN";
  331.                 }
  332.             }
  333.             else
  334.             {
  335.                 d->SetAdminMode();
  336.                 stResult = "UNKNOWN";
  337.             }
  338.         }
  339.         else if (!stBuf.compare("USER_COUNT"))
  340.         {
  341.             char szTmp[64];
  342.  
  343.             if (!IsEmptyAdminPage())
  344.             {
  345.                 if (!IsAdminPage(inet_ntoa(d->GetAddr().sin_addr)))
  346.                 {
  347.                     snprintf(szTmp, sizeof(szTmp), "WEBADMIN : Wrong Connector : %s", inet_ntoa(d->GetAddr().sin_addr));
  348.                 }
  349.                 else
  350.                 {
  351.                     int iTotal;
  352.                     int * paiEmpireUserCount;
  353.                     int iLocal;
  354.                     DESC_MANAGER::instance().GetUserCount(iTotal, &paiEmpireUserCount, iLocal);
  355.                     snprintf(szTmp, sizeof(szTmp), "%d %d %d %d %d", iTotal, paiEmpireUserCount[1], paiEmpireUserCount[2], paiEmpireUserCount[3], iLocal);
  356.                 }
  357.             }
  358.             else
  359.             {
  360.                 int iTotal;
  361.                 int * paiEmpireUserCount;
  362.                 int iLocal;
  363.                 DESC_MANAGER::instance().GetUserCount(iTotal, &paiEmpireUserCount, iLocal);
  364.                 snprintf(szTmp, sizeof(szTmp), "%d %d %d %d %d", iTotal, paiEmpireUserCount[1], paiEmpireUserCount[2], paiEmpireUserCount[3], iLocal);
  365.             }
  366.             stResult += szTmp;
  367.         }
  368.         else if (!stBuf.compare("CHECK_P2P_CONNECTIONS"))
  369.         {
  370.             std::ostringstream oss(std::ostringstream::out);
  371.  
  372.             oss << "P2P CONNECTION NUMBER : " << P2P_MANAGER::instance().GetDescCount() << "\n";
  373.             std::string hostNames;
  374.             P2P_MANAGER::Instance().GetP2PHostNames(hostNames);
  375.             oss << hostNames;
  376.             stResult = oss.str();
  377.             TPacketGGCheckAwakeness packet;
  378.             packet.bHeader = HEADER_GG_CHECK_AWAKENESS;
  379.  
  380.             P2P_MANAGER::instance().Send(&packet, sizeof(packet));
  381.         }
  382.         else if (!stBuf.compare("PACKET_INFO"))
  383.         {
  384.             m_pMainPacketInfo->Log("packet_info.txt");
  385.             stResult = "OK";
  386.         }
  387.         else if (!stBuf.compare("PROFILE"))
  388.         {
  389.             CProfiler::instance().Log("profile.txt");
  390.             stResult = "OK";
  391.         }
  392.         //gift notify delete command
  393.         else if (!stBuf.compare(0,15,"DELETE_AWARDID "))
  394.             {
  395.                 char szTmp[64];
  396.                 std::string msg = stBuf.substr(15,26);  // item_award의 id범위?
  397.  
  398.                 TPacketDeleteAwardID p;
  399.                 p.dwID = (DWORD)(atoi(msg.c_str()));
  400.                 snprintf(szTmp,sizeof(szTmp),"Sent to DB cache to delete ItemAward, id: %d",p.dwID);
  401.                 //sys_log(0,"%d",p.dwID);
  402.                 // strlcpy(p.login, msg.c_str(), sizeof(p.login));
  403.                 db_clientdesc->DBPacket(HEADER_GD_DELETE_AWARDID, 0, &p, sizeof(p));
  404.                 stResult += szTmp;
  405.             }
  406.         else
  407.         {
  408.             stResult = "UNKNOWN";
  409.  
  410.             if (d->IsAdminMode())
  411.             {
  412.                 // 어드민 명령들
  413.                 if (!stBuf.compare(0, 7, "NOTICE "))
  414.                 {
  415.                     std::string msg = stBuf.substr(7, 50);
  416.                     LogManager::instance().CharLog(0, 0, 0, 1, "NOTICE", msg.c_str(), d->GetHostName());
  417.                     BroadcastNotice(msg.c_str());
  418.                 }
  419. #ifdef ENABLE_FULL_NOTICE
  420.                 else if (!stBuf.compare(0, 11, "BIG_NOTICE "))
  421.                 {
  422.                     std::string msg = stBuf.substr(11, 50);
  423.                     LogManager::instance().CharLog(0, 0, 0, 1, "BIG_NOTICE", msg.c_str(), d->GetHostName());
  424.                     BroadcastNotice(msg.c_str(), true);
  425.                 }
  426. #endif
  427.                 else if (!stBuf.compare("CLOSE_PASSPOD"))
  428.                 {
  429.                     g_bNoPasspod = true;
  430.                     stResult += "CLOSE_PASSPOD";
  431.                 }
  432.                 else if (!stBuf.compare("OPEN_PASSPOD"))
  433.                 {
  434.                     g_bNoPasspod = false;
  435.                     stResult += "OPEN_PASSPOD";
  436.                 }
  437.                 else if (!stBuf.compare("SHUTDOWN"))
  438.                 {
  439.                     LogManager::instance().CharLog(0, 0, 0, 2, "SHUTDOWN", "", d->GetHostName());
  440.                     TPacketGGShutdown p;
  441.                     p.bHeader = HEADER_GG_SHUTDOWN;
  442.                     P2P_MANAGER::instance().Send(&p, sizeof(TPacketGGShutdown));
  443.                     sys_err("Accept shutdown command from %s.", d->GetHostName());
  444.                     Shutdown(10);
  445.                 }
  446.                 else if (!stBuf.compare("SHUTDOWN_ONLY"))
  447.                 {
  448.                     LogManager::instance().CharLog(0, 0, 0, 2, "SHUTDOWN", "", d->GetHostName());
  449.                     sys_err("Accept shutdown only command from %s.", d->GetHostName());
  450.                     Shutdown(10);
  451.                 }
  452.                 else if (!stBuf.compare(0, 3, "DC "))
  453.                 {
  454.                     std::string msg = stBuf.substr(3, LOGIN_MAX_LEN);
  455.  
  456.                     dev_log(LOG_DEB0, "DC : '%s'", msg.c_str());
  457.  
  458.                     TPacketGGDisconnect pgg;
  459.  
  460.                     pgg.bHeader = HEADER_GG_DISCONNECT;
  461.                     strlcpy(pgg.szLogin, msg.c_str(), sizeof(pgg.szLogin));
  462.  
  463.                     P2P_MANAGER::instance().Send(&pgg, sizeof(TPacketGGDisconnect));
  464.  
  465.                     // delete login key
  466.                     {
  467.                         TPacketDC p;
  468.                         strlcpy(p.login, msg.c_str(), sizeof(p.login));
  469.                         db_clientdesc->DBPacket(HEADER_GD_DC, 0, &p, sizeof(p));
  470.                     }
  471.                 }
  472.                 else if (!stBuf.compare(0, 10, "RELOAD_CRC"))
  473.                 {
  474.                     LoadValidCRCList();
  475.  
  476.                     BYTE bHeader = HEADER_GG_RELOAD_CRC_LIST;
  477.                     P2P_MANAGER::instance().Send(&bHeader, sizeof(BYTE));
  478.                     stResult = "OK";
  479.                 }
  480.                 else if (!stBuf.compare(0, 20, "CHECK_CLIENT_VERSION"))
  481.                 {
  482.                     CheckClientVersion();
  483.  
  484.                     BYTE bHeader = HEADER_GG_CHECK_CLIENT_VERSION;
  485.                     P2P_MANAGER::instance().Send(&bHeader, sizeof(BYTE));
  486.                     stResult = "OK";
  487.                 }
  488.                 else if (!stBuf.compare(0, 6, "RELOAD"))
  489.                 {
  490.                     if (stBuf.size() == 6)
  491.                     {
  492.                         LoadStateUserCount();
  493.                         db_clientdesc->DBPacket(HEADER_GD_RELOAD_PROTO, 0, NULL, 0);
  494.                         DBManager::instance().LoadDBString();
  495.                     }
  496.                     else
  497.                     {
  498.                         char c = stBuf[7];
  499.  
  500.                         switch (LOWER(c))
  501.                         {
  502.                             case 'u':
  503.                                 LoadStateUserCount();
  504.                                 break;
  505.  
  506.                             case 'p':
  507.                                 db_clientdesc->DBPacket(HEADER_GD_RELOAD_PROTO, 0, NULL, 0);
  508.                                 break;
  509.  
  510.                             case 's':
  511.                                 DBManager::instance().LoadDBString();
  512.                                 break;
  513.  
  514.                             case 'q':
  515.                                 quest::CQuestManager::instance().Reload();
  516.                                 break;
  517.  
  518.                             case 'f':
  519.                                 fishing::Initialize();
  520.                                 break;
  521.  
  522.                             case 'a':
  523.                                 db_clientdesc->DBPacket(HEADER_GD_RELOAD_ADMIN, 0, NULL, 0);
  524.                                 sys_log(0, "Reloading admin infomation.");
  525.                                 break;
  526.                         }
  527.                     }
  528.                 }
  529.                 else if (!stBuf.compare(0, 6, "EVENT "))
  530.                 {
  531.                     std::istringstream is(stBuf);
  532.                     std::string strEvent, strFlagName;
  533.                     long lValue;
  534.                     is >> strEvent >> strFlagName >> lValue;
  535.  
  536.                     if (!is.fail())
  537.                     {
  538.                         sys_log(0, "EXTERNAL EVENT FLAG name %s value %d", strFlagName.c_str(), lValue);
  539.                         quest::CQuestManager::instance().RequestSetEventFlag(strFlagName, lValue);
  540.                         stResult = "EVENT FLAG CHANGE ";
  541.                         stResult += strFlagName;
  542.                     }
  543.                     else
  544.                     {
  545.                         stResult = "EVENT FLAG FAIL";
  546.                     }
  547.                 }
  548.                 // BLOCK_CHAT
  549.                 else if (!stBuf.compare(0, 11, "BLOCK_CHAT "))
  550.                 {
  551.                     std::istringstream is(stBuf);
  552.                     std::string strBlockChat, strCharName;
  553.                     long lDuration;
  554.                     is >> strBlockChat >> strCharName >> lDuration;
  555.  
  556.                     if (!is.fail())
  557.                     {
  558.                         sys_log(0, "EXTERNAL BLOCK_CHAT name %s duration %d", strCharName.c_str(), lDuration);
  559.  
  560.                         do_block_chat(NULL, const_cast<char*>(stBuf.c_str() + 11), 0, 0);
  561.  
  562.                         stResult = "BLOCK_CHAT ";
  563.                         stResult += strCharName;
  564.                     }
  565.                     else
  566.                     {
  567.                         stResult = "BLOCK_CHAT FAIL";
  568.                     }
  569.                 }
  570.                 // END_OF_BLOCK_CHAT
  571.                 else if (!stBuf.compare(0, 12, "PRIV_EMPIRE "))
  572.                 {
  573.                     int empire, type, value, duration;
  574.                     std::istringstream is(stBuf);
  575.                     std::string strPrivEmpire;
  576.                     is >> strPrivEmpire >> empire >> type >> value >> duration;
  577.  
  578.                     // 최대치 10배
  579.                     value = MINMAX(0, value, 1000);
  580.                     stResult = "PRIV_EMPIRE FAIL";
  581.  
  582.                     if (!is.fail())
  583.                     {
  584.                         // check parameter
  585.                         if (empire < 0 || 3 < empire);
  586.                         else if (type < 1 || 4 < type);
  587.                         else if (value < 0);
  588.                         else if (duration < 0);
  589.                         else
  590.                         {
  591.                             stResult = "PRIV_EMPIRE SUCCEED";
  592.  
  593.                             // 시간 단위로 변경
  594.                             duration = duration * (60 * 60);
  595.  
  596.                             sys_log(0, "_give_empire_privileage(empire=%d, type=%d, value=%d, duration=%d) by web",
  597.                                     empire, type, value, duration);
  598.                             CPrivManager::instance().RequestGiveEmpirePriv(empire, type, value, duration);
  599.                         }
  600.                     }
  601.                 }
  602.                 else if (!stBuf.compare(0, 15, "BLOCK_EXCEPTION"))
  603.                 {
  604.                     // BLOCK_EXCEPTION cmd(add=1, del=2) login
  605.                     std::istringstream is(stBuf);
  606.                     std::string dummy_string;
  607.                     std::string login_string;
  608.                     int         cmd;
  609.  
  610.                     is >> dummy_string >> cmd >> login_string;
  611.  
  612.                     sys_log(0, "block_exception %s:%d", login_string.c_str(), cmd);
  613.                     DBManager::instance().RequestBlockException(login_string.c_str(), cmd);
  614.                     stResult = "BLOCK_EXCEPTION_YES";
  615.                 }
  616.             }
  617.         }
  618.  
  619.         sys_log(1, "TEXT %s RESULT %s", stBuf.c_str(), stResult.c_str());
  620.         stResult += "\n";
  621.         d->Packet(stResult.c_str(), stResult.length());
  622.         return (c_pSep - c_pData) + 1;
  623.     }
  624.     else if (bHeader == HEADER_CG_MARK_LOGIN)
  625.     {
  626.         if (!guild_mark_server)
  627.         {
  628.             // 끊어버려! - 마크 서버가 아닌데 마크를 요청하려고?
  629.             sys_err("Guild Mark login requested but i'm not a mark server!");
  630.             d->SetPhase(PHASE_CLOSE);
  631.             return 0;
  632.         }
  633.  
  634.         // 무조건 인증 --;
  635.         sys_log(0, "MARK_SERVER: Login");
  636.         d->SetPhase(PHASE_LOGIN);
  637.         return 0;
  638.     }
  639.     else if (bHeader == HEADER_CG_STATE_CHECKER)
  640.     {
  641.         if (d->isChannelStatusRequested()) {
  642.             return 0;
  643.         }
  644.         d->SetChannelStatusRequested(true);
  645.         db_clientdesc->DBPacket(HEADER_GD_REQUEST_CHANNELSTATUS, d->GetHandle(), NULL, 0);
  646.     }
  647.     else if (bHeader == HEADER_CG_PONG)
  648.         Pong(d);
  649.     else if (bHeader == HEADER_CG_HANDSHAKE)
  650.         Handshake(d, c_pData);
  651. #ifdef _IMPROVED_PACKET_ENCRYPTION_
  652.     else if (bHeader == HEADER_CG_KEY_AGREEMENT)
  653.     {
  654.         // Send out the key agreement completion packet first
  655.         // to help client to enter encryption mode
  656.         d->SendKeyAgreementCompleted();
  657.         // Flush socket output before going encrypted
  658.         d->ProcessOutput();
  659.  
  660.         TPacketKeyAgreement* p = (TPacketKeyAgreement*)c_pData;
  661.         if (!d->IsCipherPrepared())
  662.         {
  663.             sys_err ("Cipher isn't prepared. %s maybe a Hacker.", inet_ntoa(d->GetAddr().sin_addr));
  664.             d->DelayedDisconnect(5);
  665.             return 0;
  666.         }
  667.         if (d->FinishHandshake(p->wAgreedLength, p->data, p->wDataLength)) {
  668.             // Handshaking succeeded
  669.             if (g_bAuthServer) {
  670.                 d->SetPhase(PHASE_AUTH);
  671.             } else {
  672.                 d->SetPhase(PHASE_LOGIN);
  673.             }
  674.         } else {
  675.             sys_log(0, "[CInputHandshake] Key agreement failed: al=%u dl=%u",
  676.                 p->wAgreedLength, p->wDataLength);
  677.             d->SetPhase(PHASE_CLOSE);
  678.         }
  679.     }
  680. #endif // _IMPROVED_PACKET_ENCRYPTION_
  681.     else
  682.         sys_err("Handshake phase does not handle packet %d (fd %d)", bHeader, d->GetSocket());
  683.  
  684.     return 0;
  685. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement