AdminAdmin.java 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * 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 FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package net.sf.l2j.gameserver.handler.admincommandhandlers;
  16. import java.util.StringTokenizer;
  17. import net.sf.l2j.Config;
  18. import net.sf.l2j.gameserver.GmListTable;
  19. import net.sf.l2j.gameserver.Olympiad;
  20. import net.sf.l2j.gameserver.cache.HtmCache;
  21. import net.sf.l2j.gameserver.datatables.ItemTable;
  22. import net.sf.l2j.gameserver.datatables.NpcTable;
  23. import net.sf.l2j.gameserver.datatables.NpcWalkerRoutesTable;
  24. import net.sf.l2j.gameserver.datatables.SkillTable;
  25. import net.sf.l2j.gameserver.datatables.TeleportLocationTable;
  26. import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  27. import net.sf.l2j.gameserver.instancemanager.Manager;
  28. import net.sf.l2j.gameserver.model.L2Multisell;
  29. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  30. import net.sf.l2j.gameserver.network.SystemMessageId;
  31. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  32. /**
  33. * This class handles following admin commands:
  34. * - admin|admin1/admin2/admin3/admin4/admin5 = slots for the 5 starting admin menus
  35. * - gmliston/gmlistoff = includes/excludes active character from /gmlist results
  36. * - silence = toggles private messages acceptance mode
  37. * - diet = toggles weight penalty mode
  38. * - tradeoff = toggles trade acceptance mode
  39. * - reload = reloads specified component from multisell|skill|npc|htm|item|instancemanager
  40. * - set/set_menu/set_mod = alters specified server setting
  41. * - saveolymp = saves olympiad state manually
  42. * - manualhero = cycles olympiad and calculate new heroes.
  43. * @version $Revision: 1.3.2.1.2.4 $ $Date: 2007/07/28 10:06:06 $
  44. */
  45. public class AdminAdmin implements IAdminCommandHandler {
  46. private static final String[] ADMIN_COMMANDS =
  47. {
  48. "admin_admin",
  49. "admin_admin1",
  50. "admin_admin2",
  51. "admin_admin3",
  52. "admin_admin4",
  53. "admin_admin5",
  54. "admin_gmliston",
  55. "admin_gmlistoff",
  56. "admin_silence",
  57. "admin_diet",
  58. "admin_tradeoff",
  59. "admin_reload",
  60. "admin_set",
  61. "admin_set_menu",
  62. "admin_set_mod",
  63. "admin_saveolymp",
  64. "admin_manualhero",
  65. "admin_sethero",
  66. "admin_endolympiad"
  67. };
  68. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  69. {
  70. if (command.startsWith("admin_admin"))
  71. {
  72. showMainPage(activeChar,command);
  73. }
  74. else if(command.startsWith("admin_gmliston"))
  75. {
  76. GmListTable.getInstance().showGm(activeChar);
  77. activeChar.sendMessage("Registered into gm list");
  78. }
  79. else if(command.startsWith("admin_gmlistoff"))
  80. {
  81. GmListTable.getInstance().hideGm(activeChar);
  82. activeChar.sendMessage("Removed from gm list");
  83. }
  84. else if(command.startsWith("admin_silence"))
  85. {
  86. if (activeChar.getMessageRefusal()) // already in message refusal mode
  87. {
  88. activeChar.setMessageRefusal(false);
  89. activeChar.sendPacket(new SystemMessage(SystemMessageId.MESSAGE_ACCEPTANCE_MODE));
  90. }
  91. else
  92. {
  93. activeChar.setMessageRefusal(true);
  94. activeChar.sendPacket(new SystemMessage(SystemMessageId.MESSAGE_REFUSAL_MODE));
  95. }
  96. }
  97. else if(command.startsWith("admin_saveolymp"))
  98. {
  99. try
  100. {
  101. Olympiad.getInstance().save();
  102. }
  103. catch(Exception e){e.printStackTrace();}
  104. activeChar.sendMessage("olympiad stuff saved!!");
  105. }
  106. else if(command.startsWith("admin_endolympiad"))
  107. {
  108. try
  109. {
  110. Olympiad.getInstance().manualSelectHeroes();
  111. }
  112. catch(Exception e){e.printStackTrace();}
  113. activeChar.sendMessage("Heroes formed");
  114. }
  115. else if (command.startsWith("admin_manualhero") || command.startsWith("admin_sethero"))
  116. {
  117. L2PcInstance target = null;
  118. if (activeChar.getTarget() instanceof L2PcInstance)
  119. {
  120. target = (L2PcInstance)activeChar.getTarget();
  121. target.setHero(target.isHero()? false : true);
  122. }
  123. else
  124. {
  125. target = activeChar;
  126. target.setHero(target.isHero()? false : true);
  127. }
  128. }
  129. else if(command.startsWith("admin_diet"))
  130. {
  131. try
  132. {
  133. StringTokenizer st = new StringTokenizer(command);
  134. st.nextToken();
  135. if(st.nextToken().equalsIgnoreCase("on"))
  136. {
  137. activeChar.setDietMode(true);
  138. activeChar.sendMessage("Diet mode on");
  139. }
  140. else if(st.nextToken().equalsIgnoreCase("off"))
  141. {
  142. activeChar.setDietMode(false);
  143. activeChar.sendMessage("Diet mode off");
  144. }
  145. }
  146. catch(Exception ex)
  147. {
  148. if(activeChar.getDietMode())
  149. {
  150. activeChar.setDietMode(false);
  151. activeChar.sendMessage("Diet mode off");
  152. }
  153. else
  154. {
  155. activeChar.setDietMode(true);
  156. activeChar.sendMessage("Diet mode on");
  157. }
  158. }
  159. finally
  160. {
  161. activeChar.refreshOverloaded();
  162. }
  163. }
  164. else if(command.startsWith("admin_tradeoff"))
  165. {
  166. try
  167. {
  168. String mode = command.substring(15);
  169. if (mode.equalsIgnoreCase("on"))
  170. {
  171. activeChar.setTradeRefusal(true);
  172. activeChar.sendMessage("Trade refusal enabled");
  173. }
  174. else if (mode.equalsIgnoreCase("off"))
  175. {
  176. activeChar.setTradeRefusal(false);
  177. activeChar.sendMessage("Trade refusal disabled");
  178. }
  179. }
  180. catch(Exception ex)
  181. {
  182. if(activeChar.getTradeRefusal())
  183. {
  184. activeChar.setTradeRefusal(false);
  185. activeChar.sendMessage("Trade refusal disabled");
  186. }
  187. else
  188. {
  189. activeChar.setTradeRefusal(true);
  190. activeChar.sendMessage("Trade refusal enabled");
  191. }
  192. }
  193. }
  194. else if(command.startsWith("admin_reload"))
  195. {
  196. StringTokenizer st = new StringTokenizer(command);
  197. st.nextToken();
  198. try
  199. {
  200. String type = st.nextToken();
  201. if(type.equals("multisell"))
  202. {
  203. L2Multisell.getInstance().reload();
  204. activeChar.sendMessage("multisell reloaded");
  205. }
  206. else if(type.startsWith("teleport"))
  207. {
  208. TeleportLocationTable.getInstance().reloadAll();
  209. activeChar.sendMessage("teleport location table reloaded");
  210. }
  211. else if(type.startsWith("skill"))
  212. {
  213. SkillTable.getInstance().reload();
  214. activeChar.sendMessage("skills reloaded");
  215. }
  216. else if(type.equals("npc"))
  217. {
  218. NpcTable.getInstance().reloadAllNpc();
  219. activeChar.sendMessage("npcs reloaded");
  220. }
  221. else if(type.startsWith("htm"))
  222. {
  223. HtmCache.getInstance().reload();
  224. activeChar.sendMessage("Cache[HTML]: " + HtmCache.getInstance().getMemoryUsage() + " megabytes on " + HtmCache.getInstance().getLoadedFiles() + " files loaded");
  225. }
  226. else if(type.startsWith("item"))
  227. {
  228. ItemTable.getInstance().reload();
  229. activeChar.sendMessage("Item templates reloaded");
  230. }
  231. else if(type.startsWith("instancemanager"))
  232. {
  233. Manager.reloadAll();
  234. activeChar.sendMessage("All instance manager has been reloaded");
  235. }
  236. else if(type.startsWith("npcwalkers"))
  237. {
  238. NpcWalkerRoutesTable.getInstance().load();
  239. activeChar.sendMessage("All NPC walker routes have been reloaded");
  240. }
  241. }
  242. catch(Exception e)
  243. {
  244. activeChar.sendMessage("Usage: //reload <multisell|skill|npc|htm|item|instancemanager>");
  245. }
  246. }
  247. else if(command.startsWith("admin_set"))
  248. {
  249. StringTokenizer st = new StringTokenizer(command);
  250. String[] cmd=st.nextToken().split("_");
  251. try
  252. {
  253. String[] parameter = st.nextToken().split("=");
  254. String pName = parameter[0].trim();
  255. String pValue = parameter[1].trim();
  256. if (Config.setParameterValue(pName, pValue))
  257. activeChar.sendMessage("parameter "+pName+" succesfully set to "+pValue);
  258. else
  259. activeChar.sendMessage("Invalid parameter!");
  260. }
  261. catch(Exception e)
  262. {
  263. if (cmd.length==2)
  264. activeChar.sendMessage("Usage: //set parameter=value");
  265. }
  266. finally
  267. {
  268. if (cmd.length==3)
  269. {
  270. if (cmd[2].equalsIgnoreCase("menu"))
  271. AdminHelpPage.showHelpPage(activeChar, "settings.htm");
  272. else if (cmd[2].equalsIgnoreCase("mod"))
  273. AdminHelpPage.showHelpPage(activeChar, "mods_menu.htm");
  274. }
  275. }
  276. }
  277. return true;
  278. }
  279. public String[] getAdminCommandList()
  280. {
  281. return ADMIN_COMMANDS;
  282. }
  283. private void showMainPage(L2PcInstance activeChar, String command)
  284. {
  285. int mode = 0;
  286. String filename=null;
  287. try
  288. {
  289. mode = Integer.parseInt(command.substring(11));
  290. }
  291. catch (Exception e) {}
  292. switch (mode)
  293. {
  294. case 1:
  295. filename="main";
  296. break;
  297. case 2:
  298. filename="game";
  299. break;
  300. case 3:
  301. filename="effects";
  302. break;
  303. case 4:
  304. filename="server";
  305. break;
  306. case 5:
  307. filename="mods";
  308. break;
  309. default:
  310. if (Config.GM_ADMIN_MENU_STYLE.equals("modern"))
  311. filename="main";
  312. else
  313. filename="classic";
  314. break;
  315. }
  316. AdminHelpPage.showHelpPage(activeChar, filename+"_menu.htm");
  317. }
  318. }