hachiwari

Untitled

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