Advertisement
Guest User

Untitled

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