Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.46 KB | None | 0 0
  1. Game Log.Cpp
  2.  
  3. #include "stdafx.h"
  4. #include "constants.h"
  5. #include "config.h"
  6. #include "log.h"
  7.  
  8. #include "char.h"
  9. #include "desc.h"
  10. #include "item.h"
  11. #include "locale_service.h"
  12.  
  13. static char __escape_hint[1024];
  14.  
  15. LogManager::LogManager() : m_bIsConnect(false)
  16. {
  17. }
  18.  
  19. LogManager::~LogManager()
  20. {
  21. }
  22.  
  23. bool LogManager::Connect(const char * host, const int port, const char * user, const char * pwd, const char * db)
  24. {
  25.     if (m_sql.Setup(host, user, pwd, db, g_stLocale.c_str(), false, port))
  26.         m_bIsConnect = true;
  27.  
  28.     return m_bIsConnect;
  29. }
  30.  
  31. void LogManager::Query(const char * c_pszFormat, ...)
  32. {
  33.     char szQuery[4096];
  34.     va_list args;
  35.  
  36.     va_start(args, c_pszFormat);
  37.     vsnprintf(szQuery, sizeof(szQuery), c_pszFormat, args);
  38.     va_end(args);
  39.  
  40.     if (test_server)
  41.         sys_log(0, "LOG: %s", szQuery);
  42.  
  43.     m_sql.AsyncQuery(szQuery);
  44. }
  45.  
  46. bool LogManager::IsConnected()
  47. {
  48.     return m_bIsConnect;
  49. }
  50.  
  51. ////// MySQL log.log disable //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  52.  
  53. void LogManager::ItemLog(DWORD dwPID, DWORD x, DWORD y, DWORD dwItemID, const char * c_pszText, const char * c_pszHint, const char * c_pszIP, DWORD dwVnum)
  54. {
  55.     return;
  56.     //m_sql.EscapeString(__escape_hint, sizeof(__escape_hint), c_pszHint, strlen(c_pszHint));
  57.  
  58.     //Query("INSERT DELAYED INTO log%s (type, time, who, x, y, what, how, hint, ip, vnum) VALUES('ITEM', NOW(), %u, %u, %u, %u, '%s', '%s', '%s', %u)",
  59.             //get_table_postfix(), dwPID, x, y, dwItemID, c_pszText, __escape_hint, c_pszIP, dwVnum);*/
  60. }
  61.  
  62. void LogManager::ItemLog(LPCHARACTER ch, LPITEM item, const char * c_pszText, const char * c_pszHint)
  63. {
  64.     return;
  65.     //if (NULL == ch || NULL == item)
  66.     //{
  67.         //sys_err("character or item nil (ch %p item %p text %s)", get_pointer(ch), get_pointer(item), c_pszText);
  68.         //return;
  69.     //}
  70.  
  71.     //ItemLog(ch->GetPlayerID(), ch->GetX(), ch->GetY(), item->GetID(),
  72.             //NULL == c_pszText ? "" : c_pszText,
  73.             //c_pszHint, ch->GetDesc() ? ch->GetDesc()->GetHostName() : "",
  74.             //item->GetOriginalVnum());
  75. }
  76.  
  77. void LogManager::ItemLog(LPCHARACTER ch, int itemID, int itemVnum, const char * c_pszText, const char * c_pszHint)
  78. {
  79.     return;
  80.     //ItemLog(ch->GetPlayerID(), ch->GetX(), ch->GetY(), itemID, c_pszText, c_pszHint, ch->GetDesc() ? ch->GetDesc()->GetHostName() : "", itemVnum);
  81. }
  82.  
  83. void LogManager::CharLog(DWORD dwPID, DWORD x, DWORD y, DWORD dwValue, const char * c_pszText, const char * c_pszHint, const char * c_pszIP)
  84. {
  85.     return;
  86.     //m_sql.EscapeString(__escape_hint, sizeof(__escape_hint), c_pszHint, strlen(c_pszHint));
  87.  
  88.     //Query("INSERT DELAYED INTO log%s (type, time, who, x, y, what, how, hint, ip) VALUES('CHARACTER', NOW(), %u, %u, %u, %u, '%s', '%s', '%s')",
  89.             //get_table_postfix(), dwPID, x, y, dwValue, c_pszText, __escape_hint, c_pszIP);
  90. }
  91.  
  92. void LogManager::CharLog(LPCHARACTER ch, DWORD dw, const char * c_pszText, const char * c_pszHint)
  93. {
  94.     return;
  95.     //if (ch)
  96.         //CharLog(ch->GetPlayerID(), ch->GetX(), ch->GetY(), dw, c_pszText, c_pszHint, ch->GetDesc() ? ch->GetDesc()->GetHostName() : "");
  97.     //else
  98.         //CharLog(0, 0, 0, dw, c_pszText, c_pszHint, "");
  99. }
  100.  
  101. void LogManager::LoginLog(bool isLogin, DWORD dwAccountID, DWORD dwPID, BYTE bLevel, BYTE bJob, DWORD dwPlayTime)
  102. {
  103.     Query("INSERT DELAYED INTO loginlog%s (type, time, channel, account_id, pid, level, job, playtime) VALUES (%s, NOW(), %d, %u, %u, %d, %d, %u)",
  104.             get_table_postfix(), isLogin ? "'LOGIN'" : "'LOGOUT'", g_bChannel, dwAccountID, dwPID, bLevel, bJob, dwPlayTime);
  105. }
  106.  
  107. void LogManager::MoneyLog(BYTE type, DWORD vnum, int gold)
  108. {
  109.     if (type == MONEY_LOG_RESERVED || type >= MONEY_LOG_TYPE_MAX_NUM)
  110.     {
  111.         sys_err("TYPE ERROR: type %d vnum %u gold %d", type, vnum, gold);
  112.         return;
  113.     }
  114.  
  115.     Query("INSERT DELAYED INTO money_log%s VALUES (NOW(), %d, %d, %d)", get_table_postfix(), type, vnum, gold);
  116. }
  117.  
  118. void LogManager::HackLog(const char * c_pszHackName, const char * c_pszLogin, const char * c_pszName, const char * c_pszIP)
  119. {
  120.     m_sql.EscapeString(__escape_hint, sizeof(__escape_hint), c_pszHackName, strlen(c_pszHackName));
  121.  
  122.     Query("INSERT INTO hack_log (time, login, name, ip, server, why) VALUES(NOW(), '%s', '%s', '%s', '%s', '%s')", c_pszLogin, c_pszName, c_pszIP, g_stHostname.c_str(), __escape_hint);
  123. }
  124.  
  125. void LogManager::HackLog(const char * c_pszHackName, LPCHARACTER ch)
  126. {
  127.     if (ch->GetDesc())
  128.     {
  129.         HackLog(c_pszHackName,
  130.                 ch->GetDesc()->GetAccountTable().login,
  131.                 ch->GetName(),
  132.                 ch->GetDesc()->GetHostName());
  133.     }
  134. }
  135.  
  136. void LogManager::HackCRCLog(const char * c_pszHackName, const char * c_pszLogin, const char * c_pszName, const char * c_pszIP, DWORD dwCRC)
  137. {
  138.     Query("INSERT INTO hack_crc_log (time, login, name, ip, server, why, crc) VALUES(NOW(), '%s', '%s', '%s', '%s', '%s', %u)", c_pszLogin, c_pszName, c_pszIP, g_stHostname.c_str(), c_pszHackName, dwCRC);
  139. }
  140.  
  141. void LogManager::PCBangLoginLog(DWORD dwPCBangID, const char* c_szPCBangIP, DWORD dwPlayerID, DWORD dwPlayTime)
  142. {
  143.     Query("INSERT INTO pcbang_loginlog (time, pcbang_id, ip, pid, play_time) VALUES (NOW(), %u, '%s', %u, %u)",
  144.             dwPCBangID, c_szPCBangIP, dwPlayerID, dwPlayTime);
  145. }
  146.  
  147. void LogManager::GoldBarLog(DWORD dwPID, DWORD dwItemID, GOLDBAR_HOW eHow, const char* c_pszHint)
  148. {
  149.     char szHow[32+1];
  150.    
  151.     switch (eHow)
  152.     {
  153.         case PERSONAL_SHOP_BUY:
  154.             snprintf(szHow, sizeof(szHow), "'BUY'");
  155.             break;
  156.            
  157.         case PERSONAL_SHOP_SELL:
  158.             snprintf(szHow, sizeof(szHow), "'SELL'");
  159.             break;
  160.            
  161.         case SHOP_BUY:
  162.             snprintf(szHow, sizeof(szHow), "'SHOP_BUY'");
  163.             break;
  164.            
  165.         case SHOP_SELL:
  166.             snprintf(szHow, sizeof(szHow), "'SHOP_SELL'");
  167.             break;
  168.            
  169.         case EXCHANGE_TAKE:
  170.             snprintf(szHow, sizeof(szHow), "'EXCHANGE_TAKE'");
  171.             break;
  172.            
  173.         case EXCHANGE_GIVE:
  174.             snprintf(szHow, sizeof(szHow), "'EXCHANGE_GIVE'");
  175.             break;
  176.  
  177.         case QUEST:
  178.             snprintf(szHow, sizeof(szHow), "'QUEST'");
  179.             break;
  180.  
  181.         default:
  182.             snprintf(szHow, sizeof(szHow), "''");
  183.             break;
  184.     }
  185.    
  186.     Query("INSERT DELAYED INTO goldlog%s (date, time, pid, what, how, hint) VALUES(CURDATE(), CURTIME(), %u, %u, %s, '%s')",
  187.             get_table_postfix(), dwPID, dwItemID, szHow, c_pszHint);
  188. }
  189.  
  190. void LogManager::CubeLog(DWORD dwPID, DWORD x, DWORD y, DWORD item_vnum, DWORD item_uid, int item_count, bool success)
  191. {
  192.     Query("INSERT DELAYED INTO cube%s (pid, time, x, y, item_vnum, item_uid, item_count, success) "
  193.             "VALUES(%u, NOW(), %u, %u, %u, %u, %d, %d)",
  194.             get_table_postfix(), dwPID, x, y, item_vnum, item_uid, item_count, success?1:0);
  195. }
  196.  
  197. void LogManager::AcceLog(DWORD dwPID, DWORD x, DWORD y, DWORD item_vnum, DWORD item_uid, int item_count, int abs_chance, bool success)
  198. {
  199.     Query("INSERT DELAYED INTO acce%s (pid, time, x, y, item_vnum, item_uid, item_count, item_abs_chance, success) VALUES(%u, NOW(), %u, %u, %u, %u, %d, %d, %d)", get_table_postfix(), dwPID, x, y, item_vnum, item_uid, item_count, abs_chance, success?1:0);
  200. }
  201.  
  202. void LogManager::SpeedHackLog(DWORD pid, DWORD x, DWORD y, int hack_count)
  203. {
  204.     Query("INSERT INTO speed_hack%s (pid, time, x, y, hack_count) "
  205.             "VALUES(%u, NOW(), %u, %u, %d)",
  206.             get_table_postfix(), pid, x, y, hack_count);
  207. }
  208.  
  209. void LogManager::ChangeNameLog(DWORD pid, const char *old_name, const char *new_name, const char *ip)
  210. {
  211.     Query("INSERT DELAYED INTO change_name%s (pid, old_name, new_name, time, ip) "
  212.             "VALUES(%u, '%s', '%s', NOW(), '%s') ",
  213.             get_table_postfix(), pid, old_name, new_name, ip);
  214. }
  215.  
  216. void LogManager::GMCommandLog(DWORD dwPID, const char* szName, const char* szIP, BYTE byChannel, const char* szCommand)
  217. {
  218.     m_sql.EscapeString(__escape_hint, sizeof(__escape_hint), szCommand, strlen(szCommand));
  219.  
  220.     Query("INSERT DELAYED INTO command_log%s (userid, server, ip, port, username, command, date ) "
  221.             "VALUES(%u, 999, '%s', %u, '%s', '%s', NOW()) ",
  222.             get_table_postfix(), dwPID, szIP, byChannel, szName, __escape_hint);
  223. }
  224.  
  225. void LogManager::RefineLog(DWORD pid, const char* item_name, DWORD item_id, int item_refine_level, int is_success, const char* how)
  226. {
  227.     return;
  228.     // m_sql.EscapeString(__escape_hint, sizeof(__escape_hint), item_name, strlen(item_name));
  229.  
  230.     // Query("INSERT INTO refinelog%s (pid, item_name, item_id, step, time, is_success, setType) VALUES(%u, '%s', %u, %d, NOW(), %d, '%s')",
  231.             // get_table_postfix(), pid, __escape_hint, item_id, item_refine_level, is_success, how);
  232. }
  233.  
  234.  
  235. void LogManager::ShoutLog(BYTE bChannel, BYTE bEmpire, const char * pszText)
  236. {
  237.     return;
  238.     // m_sql.EscapeString(__escape_hint, sizeof(__escape_hint), pszText, strlen(pszText));
  239.  
  240.     // Query("INSERT INTO shout_log%s VALUES(NOW(), %d, %d,'%s')", get_table_postfix(), bChannel, bEmpire, __escape_hint);
  241. }
  242.  
  243. void LogManager::LevelLog(LPCHARACTER pChar, unsigned int level, unsigned int playhour)
  244. {
  245.     if (true == LC_IsEurope())
  246.     {
  247.         DWORD aid = 0;
  248.  
  249.         if (NULL != pChar->GetDesc())
  250.         {
  251.             aid = pChar->GetDesc()->GetAccountTable().id;
  252.         }
  253.  
  254.         Query("REPLACE INTO levellog%s (name, level, time, account_id, pid, playtime) VALUES('%s', %u, NOW(), %u, %u, %d)",
  255.                 get_table_postfix(), pChar->GetName(), level, aid, pChar->GetPlayerID(), playhour);
  256.     }
  257.     else
  258.     {
  259.         Query("REPLACE INTO levellog%s (name, level, time, playtime) VALUES('%s', %u, NOW(), %d)",
  260.                 get_table_postfix(), pChar->GetName(), level, playhour);
  261.     }
  262. }
  263.  
  264. void LogManager::BootLog(const char * c_pszHostName, BYTE bChannel)
  265. {
  266.     Query("INSERT INTO bootlog (time, hostname, channel) VALUES(NOW(), '%s', %d)",
  267.             c_pszHostName, bChannel);
  268. }
  269.  
  270. void LogManager::VCardLog(DWORD vcard_id, DWORD x, DWORD y, const char * hostname, const char * giver_name, const char * giver_ip, const char * taker_name, const char * taker_ip)
  271. {
  272.     Query("INSERT DELAYED INTO vcard_log (vcard_id, x, y, hostname, giver_name, giver_ip, taker_name, taker_ip) VALUES(%u, %u, %u, '%s', '%s', '%s', '%s', '%s')",
  273.             vcard_id, x, y, hostname, giver_name, giver_ip, taker_name, taker_ip);
  274. }
  275.  
  276. void LogManager::FishLog(DWORD dwPID, int prob_idx, int fish_id, int fish_level, DWORD dwMiliseconds, DWORD dwVnum, DWORD dwValue)
  277. {
  278.     return;
  279.     // Query("INSERT INTO fish_log%s VALUES(NOW(), %u, %d, %u, %d, %u, %u, %u)",
  280.             // get_table_postfix(),
  281.             // dwPID,
  282.             // prob_idx,
  283.             // fish_id,
  284.             // fish_level,
  285.             // dwMiliseconds,
  286.             // dwVnum,
  287.             // dwValue);
  288. }
  289.  
  290. void LogManager::QuestRewardLog(const char * c_pszQuestName, DWORD dwPID, DWORD dwLevel, int iValue1, int iValue2)
  291. {
  292.     return;
  293.     //Query("INSERT INTO quest_reward_log%s VALUES('%s',%u,%u,2,%u,%u,NOW())",
  294.             //get_table_postfix(),
  295.             //c_pszQuestName,
  296.             //dwPID,
  297.             //dwLevel,
  298.             //iValue1,
  299.             //iValue2);
  300. }
  301.  
  302. void LogManager::DetailLoginLog(bool isLogin, LPCHARACTER ch)
  303. {
  304.     if (NULL == ch->GetDesc())
  305.         return;
  306.  
  307.     if (true == isLogin)
  308.     {
  309.         Query("INSERT INTO loginlog2(type, is_gm, login_time, channel, account_id, pid, ip, client_version) "
  310.                 "VALUES('INVALID', %s, NOW(), %d, %u, %u, inet_aton('%s'), '%s')",
  311.                 ch->IsGM() == true ? "'Y'" : "'N'",
  312.                 g_bChannel,
  313.                 ch->GetDesc()->GetAccountTable().id,
  314.                 ch->GetPlayerID(),
  315.                 ch->GetDesc()->GetHostName(),
  316.                 ch->GetDesc()->GetClientVersion());
  317.     }
  318.     else
  319.     {
  320.         Query("SET @i = (SELECT MAX(id) FROM loginlog2 WHERE account_id=%u AND pid=%u)",
  321.                 ch->GetDesc()->GetAccountTable().id,
  322.                 ch->GetPlayerID());
  323.  
  324.         Query("UPDATE loginlog2 SET type='VALID', logout_time=NOW(), playtime=TIMEDIFF(logout_time,login_time) WHERE id=@i");
  325.     }
  326. }
  327.  
  328. void LogManager::DragonSlayLog(DWORD dwGuildID, DWORD dwDragonVnum, DWORD dwStartTime, DWORD dwEndTime)
  329. {
  330.     Query( "INSERT INTO dragon_slay_log%s VALUES( %d, %d, FROM_UNIXTIME(%d), FROM_UNIXTIME(%d) )",
  331.             get_table_postfix(),
  332.             dwGuildID, dwDragonVnum, dwStartTime, dwEndTime);
  333. }
  334.  
  335. void LogManager::HackShieldLog(unsigned long ErrorCode, LPCHARACTER ch)
  336. {
  337.     struct in_addr st_addr;
  338.  
  339. #ifndef __WIN32__
  340.     if (0 == inet_aton(ch->GetDesc()->GetHostName(), &st_addr))
  341. #else
  342.     unsigned long in_address;
  343.     in_address = inet_addr(ch->GetDesc()->GetHostName());
  344.     st_addr.s_addr = in_address;
  345.     if (INADDR_NONE == in_address)
  346. #endif
  347.     {
  348.         Query( "INSERT INTO hackshield_log(time, account_id, login, pid, name, reason, ip) "
  349.                 "VALUES(NOW(), %u, '%s', %u, '%s', %u, 0)",
  350.                 ch->GetDesc()->GetAccountTable().id, ch->GetDesc()->GetAccountTable().login,
  351.                 ch->GetPlayerID(), ch->GetName(),
  352.                 ErrorCode);
  353.     }
  354.     else
  355.     {
  356.         Query( "INSERT INTO hackshield_log(time, account_id, login, pid, name, reason, ip) "
  357.                 "VALUES(NOW(), %u, '%s', %u, '%s', %u, inet_aton('%s'))",
  358.                 ch->GetDesc()->GetAccountTable().id, ch->GetDesc()->GetAccountTable().login,
  359.                 ch->GetPlayerID(), ch->GetName(),
  360.                 ErrorCode,
  361.                 ch->GetDesc()->GetHostName());
  362.     }
  363. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement