Guest User

Untitled

a guest
Jun 18th, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.41 KB | None | 0 0
  1. /*
  2. * This program is free software; you can redistribute it and/or modify it
  3. * under the terms of the GNU General Public License as published by the
  4. * Free Software Foundation; either version 2 of the License, or (at your
  5. * option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. * more details.
  11. *
  12. * You should have received a copy of the GNU General Public License along
  13. * with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #include "Language.h"
  16. #include "ScriptMgr.h"
  17. #include "ObjectMgr.h"
  18. #include "Chat.h"
  19. #include "AnticheatMgr.h"
  20.  
  21. class anticheat_commandscript : public CommandScript
  22. {
  23. public:
  24. anticheat_commandscript() : CommandScript("anticheat_commandscript") { }
  25.  
  26. ChatCommand* GetCommands() const
  27. {
  28. static ChatCommand anticheatCommandTable[] =
  29. {
  30. { "global", SEC_GAMEMASTER, true, &HandleAntiCheatGlobalCommand, "", NULL },
  31. { "player", SEC_GAMEMASTER, true, &HandleAntiCheatPlayerCommand, "", NULL },
  32. { "delete", SEC_ADMINISTRATOR, true, &HandleAntiCheatDeleteCommand, "", NULL },
  33. { "handle", SEC_ADMINISTRATOR, true, &HandleAntiCheatHandleCommand, "", NULL },
  34. { "jail", SEC_GAMEMASTER, true, &HandleAnticheatJailCommand, "", NULL },
  35. { "warn", SEC_GAMEMASTER, true, &HandleAnticheatWarnCommand, "", NULL },
  36. { NULL, 0, false, NULL, "", NULL }
  37. };
  38.  
  39. static ChatCommand commandTable[] =
  40. {
  41. { "anticheat", SEC_GAMEMASTER, true, NULL, "", anticheatCommandTable },
  42. { NULL, 0, false, NULL, "", NULL }
  43. };
  44.  
  45. return commandTable;
  46. }
  47.  
  48. static bool HandleAnticheatWarnCommand(ChatHandler* handler, const char* args)
  49. {
  50. if (!sWorld->getBoolConfig(CONFIG_ANTICHEAT_ENABLE))
  51. return false;
  52.  
  53. Player* pTarget = NULL;
  54.  
  55. std::string strCommand;
  56.  
  57. char* command = strtok((char*)args, " ");
  58.  
  59. if (command)
  60. {
  61. strCommand = command;
  62. normalizePlayerName(strCommand);
  63.  
  64. pTarget = sObjectAccessor->FindPlayerByName(strCommand.c_str()); //get player by name
  65. }
  66. else
  67. pTarget = handler->getSelectedPlayer();
  68.  
  69. if (!pTarget)
  70. return false;
  71.  
  72. WorldPacket data;
  73.  
  74. // need copy to prevent corruption by strtok call in LineFromMessage original string
  75. char* buf = strdup("The anticheat system has reported several times that you may be cheating. You will be monitored to confirm if this is accurate.");
  76. char* pos = buf;
  77.  
  78. while (char* line = handler->LineFromMessage(pos))
  79. {
  80. handler->BuildChatPacket(data, CHAT_MSG_SYSTEM, LANG_UNIVERSAL, NULL, NULL, line);
  81. pTarget->GetSession()->SendPacket(&data);
  82. }
  83.  
  84. free(buf);
  85. return true;
  86. }
  87.  
  88. static bool HandleAnticheatJailCommand(ChatHandler* handler, const char* args)
  89. {
  90. if (!sWorld->getBoolConfig(CONFIG_ANTICHEAT_ENABLE))
  91. return false;
  92.  
  93. Player* pTarget = NULL;
  94.  
  95. std::string strCommand;
  96.  
  97. char* command = strtok((char*)args, " ");
  98.  
  99. if (command)
  100. {
  101. strCommand = command;
  102. normalizePlayerName(strCommand);
  103.  
  104. pTarget = sObjectAccessor->FindPlayerByName(strCommand.c_str()); //get player by name
  105. }
  106. else
  107. pTarget = handler->getSelectedPlayer();
  108.  
  109. if (!pTarget)
  110. {
  111. handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
  112. handler->SetSentErrorMessage(true);
  113. return false;
  114. }
  115.  
  116. if (pTarget == handler->GetSession()->GetPlayer())
  117. return false;
  118.  
  119. // teleport both to jail.
  120. pTarget->TeleportTo(1, 16226.5f, 16403.6f, -64.5f, 3.2f);
  121. handler->GetSession()->GetPlayer()->TeleportTo(1, 16226.5f, 16403.6f, -64.5f, 3.2f);
  122.  
  123. WorldLocation loc;
  124.  
  125. // the player should be already there, but no :(
  126. // pTarget->GetPosition(&loc);
  127.  
  128. loc.m_mapId = 1;
  129. loc.m_positionX = 16226.5f;
  130. loc.m_positionY = 16403.6f;
  131. loc.m_positionZ = -64.5f;
  132. loc.m_orientation = 3.2f;
  133.  
  134. pTarget->SetHomebind(loc, 876);
  135. return true;
  136. }
  137.  
  138. static bool HandleAntiCheatDeleteCommand(ChatHandler* handler, const char* args)
  139. {
  140. if (!sWorld->getBoolConfig(CONFIG_ANTICHEAT_ENABLE))
  141. return false;
  142.  
  143. std::string strCommand;
  144.  
  145. char* command = strtok((char*)args, " "); //get entered name
  146.  
  147. if (!command)
  148. return true;
  149.  
  150. strCommand = command;
  151.  
  152. if (strCommand.compare("deleteall") == 0)
  153. sAnticheatMgr->AnticheatDeleteCommand(0);
  154. else
  155. {
  156. normalizePlayerName(strCommand);
  157. Player* player = sObjectAccessor->FindPlayerByName(strCommand.c_str()); //get player by name
  158. if (!player)
  159. handler->PSendSysMessage("Player doesn't exist");
  160. else
  161. sAnticheatMgr->AnticheatDeleteCommand(player->GetGUIDLow());
  162. }
  163.  
  164. return true;
  165. }
  166.  
  167. static bool HandleAntiCheatPlayerCommand(ChatHandler* handler, const char* args)
  168. {
  169. if (!sWorld->getBoolConfig(CONFIG_ANTICHEAT_ENABLE))
  170. return false;
  171.  
  172. std::string strCommand;
  173.  
  174. char* command = strtok((char*)args, " ");
  175.  
  176. uint32 guid = 0;
  177. Player* player = NULL;
  178.  
  179. if (command)
  180. {
  181. strCommand = command;
  182.  
  183. normalizePlayerName(strCommand);
  184. player = sObjectAccessor->FindPlayerByName(strCommand.c_str()); //get player by name
  185.  
  186. if (player)
  187. guid = player->GetGUIDLow();
  188. }
  189. else
  190. {
  191. player = handler->getSelectedPlayer();
  192. if (player)
  193. guid = player->GetGUIDLow();
  194. }
  195.  
  196. if (!guid)
  197. {
  198. handler->PSendSysMessage("There is no player.");
  199. return true;
  200. }
  201.  
  202. float average = sAnticheatMgr->GetAverage(guid);
  203. uint32 total_reports = sAnticheatMgr->GetTotalReports(guid);
  204. uint32 speed_reports = sAnticheatMgr->GetTypeReports(guid, 0);
  205. uint32 fly_reports = sAnticheatMgr->GetTypeReports(guid, 1);
  206. uint32 jump_reports = sAnticheatMgr->GetTypeReports(guid, 3);
  207. uint32 waterwalk_reports = sAnticheatMgr->GetTypeReports(guid, 2);
  208. uint32 teleportplane_reports = sAnticheatMgr->GetTypeReports(guid, 4);
  209. uint32 climb_reports = sAnticheatMgr->GetTypeReports(guid, 5);
  210.  
  211. handler->PSendSysMessage("Information about player %s", player->GetName().c_str());
  212. handler->PSendSysMessage("Average: %f || Total Reports: %u ", average, total_reports);
  213. handler->PSendSysMessage("Speed Reports: %u || Fly Reports: %u || Jump Reports: %u ", speed_reports, fly_reports, jump_reports);
  214. handler->PSendSysMessage("Walk On Water Reports: %u || Teleport To Plane Reports: %u", waterwalk_reports, teleportplane_reports);
  215. handler->PSendSysMessage("Climb Reports: %u", climb_reports);
  216.  
  217. return true;
  218. }
  219.  
  220. static bool HandleAntiCheatHandleCommand(ChatHandler* handler, const char* args)
  221. {
  222. std::string strCommand;
  223.  
  224. char* command = strtok((char*)args, " ");
  225.  
  226. if (!command)
  227. return true;
  228.  
  229. if (!handler->GetSession()->GetPlayer())
  230. return true;
  231.  
  232. strCommand = command;
  233.  
  234. if (strCommand.compare("on") == 0)
  235. {
  236. sWorld->setBoolConfig(CONFIG_ANTICHEAT_ENABLE, true);
  237. handler->SendSysMessage("The Anticheat System is now: Enabled!");
  238. }
  239. else if (strCommand.compare("off") == 0)
  240. {
  241. sWorld->setBoolConfig(CONFIG_ANTICHEAT_ENABLE, false);
  242. handler->SendSysMessage("The Anticheat System is now: Disabled!");
  243. }
  244.  
  245. return true;
  246. }
  247.  
  248. static bool HandleAntiCheatGlobalCommand(ChatHandler* handler, const char* /* args */)
  249. {
  250. if (!sWorld->getBoolConfig(CONFIG_ANTICHEAT_ENABLE))
  251. {
  252. handler->PSendSysMessage("The Anticheat System is disabled.");
  253. return true;
  254. }
  255.  
  256. sAnticheatMgr->AnticheatGlobalCommand(handler);
  257.  
  258. return true;
  259. }
  260. };
  261.  
  262. void AddSC_anticheat_commandscript()
  263. {
  264. new anticheat_commandscript();
  265. }
Advertisement
Add Comment
Please, Sign In to add comment