AdminEditChar.java 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579
  1. /*
  2. * Copyright (C) 2004-2013 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.admincommandhandlers;
  20. import java.sql.Connection;
  21. import java.sql.PreparedStatement;
  22. import java.util.ArrayList;
  23. import java.util.Arrays;
  24. import java.util.Collections;
  25. import java.util.Comparator;
  26. import java.util.HashMap;
  27. import java.util.List;
  28. import java.util.Map;
  29. import java.util.StringTokenizer;
  30. import java.util.logging.Logger;
  31. import com.l2jserver.Config;
  32. import com.l2jserver.L2DatabaseFactory;
  33. import com.l2jserver.gameserver.ai.CtrlIntention;
  34. import com.l2jserver.gameserver.communitybbs.Manager.RegionBBSManager;
  35. import com.l2jserver.gameserver.datatables.CharNameTable;
  36. import com.l2jserver.gameserver.datatables.ClassListData;
  37. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  38. import com.l2jserver.gameserver.model.L2Object;
  39. import com.l2jserver.gameserver.model.L2World;
  40. import com.l2jserver.gameserver.model.actor.L2Summon;
  41. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  42. import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
  43. import com.l2jserver.gameserver.model.base.ClassId;
  44. import com.l2jserver.gameserver.network.L2GameClient;
  45. import com.l2jserver.gameserver.network.SystemMessageId;
  46. import com.l2jserver.gameserver.network.communityserver.CommunityServerThread;
  47. import com.l2jserver.gameserver.network.communityserver.writepackets.WorldInfo;
  48. import com.l2jserver.gameserver.network.serverpackets.CharInfo;
  49. import com.l2jserver.gameserver.network.serverpackets.ExBrExtraUserInfo;
  50. import com.l2jserver.gameserver.network.serverpackets.ExVoteSystemInfo;
  51. import com.l2jserver.gameserver.network.serverpackets.GMViewItemList;
  52. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  53. import com.l2jserver.gameserver.network.serverpackets.PartySmallWindowAll;
  54. import com.l2jserver.gameserver.network.serverpackets.PartySmallWindowDeleteAll;
  55. import com.l2jserver.gameserver.network.serverpackets.SetSummonRemainTime;
  56. import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
  57. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  58. import com.l2jserver.gameserver.network.serverpackets.UserInfo;
  59. import com.l2jserver.gameserver.util.Util;
  60. import com.l2jserver.util.StringUtil;
  61. /**
  62. * This class handles following admin commands: - edit_character - current_player - character_list - show_characters - find_character - find_ip - find_account - rec - nokarma - setkarma - settitle - changename - setsex - setclass - fullfood - save_modifications - setcolor - settcolor - setpk -
  63. * setpvp - remove_clan_penalty - summon_info - unsummon - summon_setlvl - show_pet_inv - partyinfo
  64. * @version $Revision: 1.3.2.1.2.10 $ $Date: 2005/04/11 10:06:06 $ Typo fix, rework for admin_tracert, gatherCharacterInfo and editCharacter by Zoey76 28/02/2011
  65. */
  66. public class AdminEditChar implements IAdminCommandHandler
  67. {
  68. private static Logger _log = Logger.getLogger(AdminEditChar.class.getName());
  69. private static final String[] ADMIN_COMMANDS =
  70. {
  71. "admin_edit_character",
  72. "admin_current_player",
  73. "admin_nokarma", // this is to remove karma from selected char...
  74. "admin_setkarma", // sets karma of target char to any amount. //setkarma <karma>
  75. "admin_setfame", // sets fame of target char to any amount. //setfame <fame>
  76. "admin_character_list", // same as character_info, kept for compatibility purposes
  77. "admin_character_info", // given a player name, displays an information window
  78. "admin_show_characters",// list of characters
  79. "admin_find_character", // find a player by his name or a part of it (case-insensitive)
  80. "admin_find_ip", // find all the player connections from a given IPv4 number
  81. "admin_find_account", // list all the characters from an account (useful for GMs w/o DB access)
  82. "admin_find_dualbox", // list all the IPs with more than 1 char logged in (dualbox)
  83. "admin_strict_find_dualbox",
  84. "admin_tracert",
  85. "admin_save_modifications", // consider it deprecated...
  86. "admin_rec", // gives recommendation points
  87. "admin_settitle", // changes char title
  88. "admin_changename", // changes char name
  89. "admin_setsex", // changes characters' sex
  90. "admin_setcolor", // change charnames' color display
  91. "admin_settcolor", // change char title color
  92. "admin_setclass", // changes chars' classId
  93. "admin_setpk", // changes PK count
  94. "admin_setpvp", // changes PVP count
  95. "admin_fullfood", // fulfills a pet's food bar
  96. "admin_remove_clan_penalty", // removes clan penalties
  97. "admin_summon_info", // displays an information window about target summon
  98. "admin_unsummon",
  99. "admin_summon_setlvl",
  100. "admin_show_pet_inv",
  101. "admin_partyinfo",
  102. "admin_setnoble"
  103. };
  104. @Override
  105. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  106. {
  107. if (command.equals("admin_current_player"))
  108. {
  109. showCharacterInfo(activeChar, activeChar);
  110. }
  111. else if (command.startsWith("admin_character_info"))
  112. {
  113. String[] data = command.split(" ");
  114. if ((data.length > 1))
  115. {
  116. showCharacterInfo(activeChar, L2World.getInstance().getPlayer(data[1]));
  117. }
  118. else if (activeChar.getTarget() instanceof L2PcInstance)
  119. {
  120. showCharacterInfo(activeChar, activeChar.getTarget().getActingPlayer());
  121. }
  122. else
  123. {
  124. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  125. }
  126. }
  127. else if (command.startsWith("admin_character_list"))
  128. {
  129. listCharacters(activeChar, 0);
  130. }
  131. else if (command.startsWith("admin_show_characters"))
  132. {
  133. try
  134. {
  135. String val = command.substring(22);
  136. int page = Integer.parseInt(val);
  137. listCharacters(activeChar, page);
  138. }
  139. catch (StringIndexOutOfBoundsException e)
  140. {
  141. // Case of empty page number
  142. activeChar.sendMessage("Usage: //show_characters <page_number>");
  143. }
  144. }
  145. else if (command.startsWith("admin_find_character"))
  146. {
  147. try
  148. {
  149. String val = command.substring(21);
  150. findCharacter(activeChar, val);
  151. }
  152. catch (StringIndexOutOfBoundsException e)
  153. { // Case of empty character name
  154. activeChar.sendMessage("Usage: //find_character <character_name>");
  155. listCharacters(activeChar, 0);
  156. }
  157. }
  158. else if (command.startsWith("admin_find_ip"))
  159. {
  160. try
  161. {
  162. String val = command.substring(14);
  163. findCharactersPerIp(activeChar, val);
  164. }
  165. catch (Exception e)
  166. { // Case of empty or malformed IP number
  167. activeChar.sendMessage("Usage: //find_ip <www.xxx.yyy.zzz>");
  168. listCharacters(activeChar, 0);
  169. }
  170. }
  171. else if (command.startsWith("admin_find_account"))
  172. {
  173. try
  174. {
  175. String val = command.substring(19);
  176. findCharactersPerAccount(activeChar, val);
  177. }
  178. catch (Exception e)
  179. { // Case of empty or malformed player name
  180. activeChar.sendMessage("Usage: //find_account <player_name>");
  181. listCharacters(activeChar, 0);
  182. }
  183. }
  184. else if (command.startsWith("admin_edit_character"))
  185. {
  186. String[] data = command.split(" ");
  187. if ((data.length > 1))
  188. {
  189. editCharacter(activeChar, data[1]);
  190. }
  191. else if (activeChar.getTarget() instanceof L2PcInstance)
  192. {
  193. editCharacter(activeChar, null);
  194. }
  195. else
  196. {
  197. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  198. }
  199. }
  200. // Karma control commands
  201. else if (command.equals("admin_nokarma"))
  202. {
  203. setTargetKarma(activeChar, 0);
  204. }
  205. else if (command.startsWith("admin_setkarma"))
  206. {
  207. try
  208. {
  209. String val = command.substring(15);
  210. int karma = Integer.parseInt(val);
  211. setTargetKarma(activeChar, karma);
  212. }
  213. catch (Exception e)
  214. {
  215. if (Config.DEVELOPER)
  216. {
  217. _log.warning("Set karma error: " + e);
  218. }
  219. activeChar.sendMessage("Usage: //setkarma <new_karma_value>");
  220. }
  221. }
  222. else if (command.startsWith("admin_setpk"))
  223. {
  224. try
  225. {
  226. String val = command.substring(12);
  227. int pk = Integer.parseInt(val);
  228. L2Object target = activeChar.getTarget();
  229. if (target instanceof L2PcInstance)
  230. {
  231. L2PcInstance player = (L2PcInstance) target;
  232. player.setPkKills(pk);
  233. player.broadcastUserInfo();
  234. player.sendPacket(new UserInfo(player));
  235. player.sendPacket(new ExBrExtraUserInfo(player));
  236. player.sendMessage("A GM changed your PK count to " + pk);
  237. activeChar.sendMessage(player.getName() + "'s PK count changed to " + pk);
  238. }
  239. else
  240. {
  241. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  242. }
  243. }
  244. catch (Exception e)
  245. {
  246. if (Config.DEVELOPER)
  247. {
  248. _log.warning("Set pk error: " + e);
  249. }
  250. activeChar.sendMessage("Usage: //setpk <pk_count>");
  251. }
  252. }
  253. else if (command.startsWith("admin_setpvp"))
  254. {
  255. try
  256. {
  257. String val = command.substring(13);
  258. int pvp = Integer.parseInt(val);
  259. L2Object target = activeChar.getTarget();
  260. if (target instanceof L2PcInstance)
  261. {
  262. L2PcInstance player = (L2PcInstance) target;
  263. player.setPvpKills(pvp);
  264. player.broadcastUserInfo();
  265. player.sendPacket(new UserInfo(player));
  266. player.sendPacket(new ExBrExtraUserInfo(player));
  267. player.sendMessage("A GM changed your PVP count to " + pvp);
  268. activeChar.sendMessage(player.getName() + "'s PVP count changed to " + pvp);
  269. }
  270. else
  271. {
  272. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  273. }
  274. }
  275. catch (Exception e)
  276. {
  277. if (Config.DEVELOPER)
  278. {
  279. _log.warning("Set pvp error: " + e);
  280. }
  281. activeChar.sendMessage("Usage: //setpvp <pvp_count>");
  282. }
  283. }
  284. else if (command.startsWith("admin_setfame"))
  285. {
  286. try
  287. {
  288. String val = command.substring(14);
  289. int fame = Integer.parseInt(val);
  290. L2Object target = activeChar.getTarget();
  291. if (target instanceof L2PcInstance)
  292. {
  293. L2PcInstance player = (L2PcInstance) target;
  294. player.setFame(fame);
  295. player.broadcastUserInfo();
  296. player.sendPacket(new UserInfo(player));
  297. player.sendPacket(new ExBrExtraUserInfo(player));
  298. player.sendMessage("A GM changed your Reputation points to " + fame);
  299. activeChar.sendMessage(player.getName() + "'s Fame changed to " + fame);
  300. }
  301. else
  302. {
  303. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  304. }
  305. }
  306. catch (Exception e)
  307. {
  308. if (Config.DEVELOPER)
  309. {
  310. _log.warning("Set Fame error: " + e);
  311. }
  312. activeChar.sendMessage("Usage: //setfame <new_fame_value>");
  313. }
  314. }
  315. else if (command.startsWith("admin_save_modifications"))
  316. {
  317. try
  318. {
  319. String val = command.substring(24);
  320. adminModifyCharacter(activeChar, val);
  321. }
  322. catch (StringIndexOutOfBoundsException e)
  323. { // Case of empty character name
  324. activeChar.sendMessage("Error while modifying character.");
  325. listCharacters(activeChar, 0);
  326. }
  327. }
  328. else if (command.startsWith("admin_rec"))
  329. {
  330. try
  331. {
  332. String val = command.substring(10);
  333. int recVal = Integer.parseInt(val);
  334. L2Object target = activeChar.getTarget();
  335. if (target instanceof L2PcInstance)
  336. {
  337. L2PcInstance player = (L2PcInstance) target;
  338. player.setRecomHave(recVal);
  339. player.broadcastUserInfo();
  340. player.sendPacket(new UserInfo(player));
  341. player.sendPacket(new ExBrExtraUserInfo(player));
  342. player.sendPacket(new ExVoteSystemInfo(player));
  343. player.sendMessage("A GM changed your Recommend points to " + recVal);
  344. activeChar.sendMessage(player.getName() + "'s Recommend changed to " + recVal);
  345. }
  346. else
  347. {
  348. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  349. }
  350. }
  351. catch (Exception e)
  352. {
  353. activeChar.sendMessage("Usage: //rec number");
  354. }
  355. }
  356. else if (command.startsWith("admin_setclass"))
  357. {
  358. try
  359. {
  360. String val = command.substring(15).trim();
  361. int classidval = Integer.parseInt(val);
  362. L2Object target = activeChar.getTarget();
  363. L2PcInstance player = null;
  364. if (target instanceof L2PcInstance)
  365. {
  366. player = (L2PcInstance) target;
  367. }
  368. else
  369. {
  370. return false;
  371. }
  372. boolean valid = false;
  373. for (ClassId classid : ClassId.values())
  374. {
  375. if (classidval == classid.getId())
  376. {
  377. valid = true;
  378. }
  379. }
  380. if (valid && (player.getClassId().getId() != classidval))
  381. {
  382. player.setClassId(classidval);
  383. if (!player.isSubClassActive())
  384. {
  385. player.setBaseClass(classidval);
  386. }
  387. String newclass = ClassListData.getInstance().getClass(player.getClassId()).getClassName();
  388. player.store();
  389. player.sendMessage("A GM changed your class to " + newclass + ".");
  390. player.broadcastUserInfo();
  391. activeChar.sendMessage(player.getName() + " is a " + newclass + ".");
  392. }
  393. else
  394. {
  395. activeChar.sendMessage("Usage: //setclass <valid_new_classid>");
  396. }
  397. }
  398. catch (StringIndexOutOfBoundsException e)
  399. {
  400. AdminHtml.showAdminHtml(activeChar, "charclasses.htm");
  401. }
  402. catch (NumberFormatException e)
  403. {
  404. activeChar.sendMessage("Usage: //setclass <valid_new_classid>");
  405. }
  406. }
  407. else if (command.startsWith("admin_settitle"))
  408. {
  409. try
  410. {
  411. String val = command.substring(15);
  412. L2Object target = activeChar.getTarget();
  413. L2PcInstance player = null;
  414. if (target instanceof L2PcInstance)
  415. {
  416. player = (L2PcInstance) target;
  417. }
  418. else
  419. {
  420. return false;
  421. }
  422. player.setTitle(val);
  423. player.sendMessage("Your title has been changed by a GM");
  424. player.broadcastTitleInfo();
  425. }
  426. catch (StringIndexOutOfBoundsException e)
  427. { // Case of empty character title
  428. activeChar.sendMessage("You need to specify the new title.");
  429. }
  430. }
  431. else if (command.startsWith("admin_changename"))
  432. {
  433. try
  434. {
  435. String val = command.substring(17);
  436. L2Object target = activeChar.getTarget();
  437. L2PcInstance player = null;
  438. if (target instanceof L2PcInstance)
  439. {
  440. player = (L2PcInstance) target;
  441. }
  442. else
  443. {
  444. return false;
  445. }
  446. if (CharNameTable.getInstance().getIdByName(val) > 0)
  447. {
  448. activeChar.sendMessage("Warning, player " + val + " already exists");
  449. return false;
  450. }
  451. player.setName(val);
  452. player.store();
  453. activeChar.sendMessage("Changed name to " + val);
  454. player.sendMessage("Your name has been changed by a GM.");
  455. player.broadcastUserInfo();
  456. CommunityServerThread.getInstance().sendPacket(new WorldInfo(player, null, WorldInfo.TYPE_UPDATE_PLAYER_DATA));
  457. if (player.isInParty())
  458. {
  459. // Delete party window for other party members
  460. player.getParty().broadcastToPartyMembers(player, PartySmallWindowDeleteAll.STATIC_PACKET);
  461. for (L2PcInstance member : player.getParty().getMembers())
  462. {
  463. // And re-add
  464. if (member != player)
  465. {
  466. member.sendPacket(new PartySmallWindowAll(member, player.getParty()));
  467. }
  468. }
  469. }
  470. if (player.getClan() != null)
  471. {
  472. player.getClan().broadcastClanStatus();
  473. }
  474. RegionBBSManager.getInstance().changeCommunityBoard();
  475. }
  476. catch (StringIndexOutOfBoundsException e)
  477. { // Case of empty character name
  478. activeChar.sendMessage("Usage: //setname new_name_for_target");
  479. }
  480. }
  481. else if (command.startsWith("admin_setsex"))
  482. {
  483. L2Object target = activeChar.getTarget();
  484. L2PcInstance player = null;
  485. if (target instanceof L2PcInstance)
  486. {
  487. player = (L2PcInstance) target;
  488. }
  489. else
  490. {
  491. return false;
  492. }
  493. player.getAppearance().setSex(player.getAppearance().getSex() ? false : true);
  494. player.sendMessage("Your gender has been changed by a GM");
  495. player.broadcastUserInfo();
  496. }
  497. else if (command.startsWith("admin_setcolor"))
  498. {
  499. try
  500. {
  501. String val = command.substring(15);
  502. L2Object target = activeChar.getTarget();
  503. L2PcInstance player = null;
  504. if (target instanceof L2PcInstance)
  505. {
  506. player = (L2PcInstance) target;
  507. }
  508. else
  509. {
  510. return false;
  511. }
  512. player.getAppearance().setNameColor(Integer.decode("0x" + val));
  513. player.sendMessage("Your name color has been changed by a GM");
  514. player.broadcastUserInfo();
  515. }
  516. catch (Exception e)
  517. { // Case of empty color or invalid hex string
  518. activeChar.sendMessage("You need to specify a valid new color.");
  519. }
  520. }
  521. else if (command.startsWith("admin_settcolor"))
  522. {
  523. try
  524. {
  525. String val = command.substring(16);
  526. L2Object target = activeChar.getTarget();
  527. L2PcInstance player = null;
  528. if (target instanceof L2PcInstance)
  529. {
  530. player = (L2PcInstance) target;
  531. }
  532. else
  533. {
  534. return false;
  535. }
  536. player.getAppearance().setTitleColor(Integer.decode("0x" + val));
  537. player.sendMessage("Your title color has been changed by a GM");
  538. player.broadcastUserInfo();
  539. }
  540. catch (Exception e)
  541. { // Case of empty color or invalid hex string
  542. activeChar.sendMessage("You need to specify a valid new color.");
  543. }
  544. }
  545. else if (command.startsWith("admin_fullfood"))
  546. {
  547. L2Object target = activeChar.getTarget();
  548. if (target instanceof L2PetInstance)
  549. {
  550. L2PetInstance targetPet = (L2PetInstance) target;
  551. targetPet.setCurrentFed(targetPet.getMaxFed());
  552. targetPet.sendPacket(new SetSummonRemainTime(targetPet.getMaxFed(), targetPet.getCurrentFed()));
  553. }
  554. else
  555. {
  556. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  557. }
  558. }
  559. else if (command.startsWith("admin_remove_clan_penalty"))
  560. {
  561. try
  562. {
  563. StringTokenizer st = new StringTokenizer(command, " ");
  564. if (st.countTokens() != 3)
  565. {
  566. activeChar.sendMessage("Usage: //remove_clan_penalty join|create charname");
  567. return false;
  568. }
  569. st.nextToken();
  570. boolean changeCreateExpiryTime = st.nextToken().equalsIgnoreCase("create");
  571. String playerName = st.nextToken();
  572. L2PcInstance player = null;
  573. player = L2World.getInstance().getPlayer(playerName);
  574. if (player == null)
  575. {
  576. Connection con = L2DatabaseFactory.getInstance().getConnection();
  577. PreparedStatement ps = con.prepareStatement("UPDATE characters SET " + (changeCreateExpiryTime ? "clan_create_expiry_time" : "clan_join_expiry_time") + " WHERE char_name=? LIMIT 1");
  578. ps.setString(1, playerName);
  579. ps.execute();
  580. }
  581. else
  582. {
  583. // removing penalty
  584. if (changeCreateExpiryTime)
  585. {
  586. player.setClanCreateExpiryTime(0);
  587. }
  588. else
  589. {
  590. player.setClanJoinExpiryTime(0);
  591. }
  592. }
  593. activeChar.sendMessage("Clan penalty successfully removed to character: " + playerName);
  594. }
  595. catch (Exception e)
  596. {
  597. e.printStackTrace();
  598. }
  599. }
  600. else if (command.startsWith("admin_find_dualbox"))
  601. {
  602. int multibox = 2;
  603. try
  604. {
  605. String val = command.substring(19);
  606. multibox = Integer.parseInt(val);
  607. if (multibox < 1)
  608. {
  609. activeChar.sendMessage("Usage: //find_dualbox [number > 0]");
  610. return false;
  611. }
  612. }
  613. catch (Exception e)
  614. {
  615. }
  616. findDualbox(activeChar, multibox);
  617. }
  618. else if (command.startsWith("admin_strict_find_dualbox"))
  619. {
  620. int multibox = 2;
  621. try
  622. {
  623. String val = command.substring(26);
  624. multibox = Integer.parseInt(val);
  625. if (multibox < 1)
  626. {
  627. activeChar.sendMessage("Usage: //strict_find_dualbox [number > 0]");
  628. return false;
  629. }
  630. }
  631. catch (Exception e)
  632. {
  633. }
  634. findDualboxStrict(activeChar, multibox);
  635. }
  636. else if (command.startsWith("admin_tracert"))
  637. {
  638. String[] data = command.split(" ");
  639. L2PcInstance pl = null;
  640. if ((data.length > 1))
  641. {
  642. pl = L2World.getInstance().getPlayer(data[1]);
  643. }
  644. else
  645. {
  646. L2Object target = activeChar.getTarget();
  647. if (target instanceof L2PcInstance)
  648. {
  649. pl = (L2PcInstance) target;
  650. }
  651. }
  652. if (pl == null)
  653. {
  654. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  655. return false;
  656. }
  657. final L2GameClient client = pl.getClient();
  658. if (client == null)
  659. {
  660. activeChar.sendMessage("Client is null.");
  661. return false;
  662. }
  663. if (client.isDetached())
  664. {
  665. activeChar.sendMessage("Client is detached.");
  666. return false;
  667. }
  668. String ip;
  669. int[][] trace = client.getTrace();
  670. for (int i = 0; i < trace.length; i++)
  671. {
  672. ip = "";
  673. for (int o = 0; o < trace[0].length; o++)
  674. {
  675. ip = ip + trace[i][o];
  676. if (o != (trace[0].length - 1))
  677. {
  678. ip = ip + ".";
  679. }
  680. }
  681. activeChar.sendMessage("Hop" + i + ": " + ip);
  682. }
  683. }
  684. else if (command.startsWith("admin_summon_info"))
  685. {
  686. L2Object target = activeChar.getTarget();
  687. if (target instanceof L2Summon)
  688. {
  689. gatherSummonInfo((L2Summon) target, activeChar);
  690. }
  691. else
  692. {
  693. activeChar.sendMessage("Invalid target.");
  694. }
  695. }
  696. else if (command.startsWith("admin_unsummon"))
  697. {
  698. L2Object target = activeChar.getTarget();
  699. if (target instanceof L2Summon)
  700. {
  701. ((L2Summon) target).unSummon(((L2Summon) target).getOwner());
  702. }
  703. else
  704. {
  705. activeChar.sendMessage("Usable only with Pets/Summons");
  706. }
  707. }
  708. else if (command.startsWith("admin_summon_setlvl"))
  709. {
  710. L2Object target = activeChar.getTarget();
  711. if (target instanceof L2PetInstance)
  712. {
  713. L2PetInstance pet = (L2PetInstance) target;
  714. try
  715. {
  716. String val = command.substring(20);
  717. int level = Integer.parseInt(val);
  718. long newexp, oldexp = 0;
  719. oldexp = pet.getStat().getExp();
  720. newexp = pet.getStat().getExpForLevel(level);
  721. if (oldexp > newexp)
  722. {
  723. pet.getStat().removeExp(oldexp - newexp);
  724. }
  725. else if (oldexp < newexp)
  726. {
  727. pet.getStat().addExp(newexp - oldexp);
  728. }
  729. }
  730. catch (Exception e)
  731. {
  732. }
  733. }
  734. else
  735. {
  736. activeChar.sendMessage("Usable only with Pets");
  737. }
  738. }
  739. else if (command.startsWith("admin_show_pet_inv"))
  740. {
  741. String val;
  742. int objId;
  743. L2Object target;
  744. try
  745. {
  746. val = command.substring(19);
  747. objId = Integer.parseInt(val);
  748. target = L2World.getInstance().getPet(objId);
  749. }
  750. catch (Exception e)
  751. {
  752. target = activeChar.getTarget();
  753. }
  754. if (target instanceof L2PetInstance)
  755. {
  756. activeChar.sendPacket(new GMViewItemList((L2PetInstance) target));
  757. }
  758. else
  759. {
  760. activeChar.sendMessage("Usable only with Pets");
  761. }
  762. }
  763. else if (command.startsWith("admin_partyinfo"))
  764. {
  765. String val;
  766. L2Object target;
  767. try
  768. {
  769. val = command.substring(16);
  770. target = L2World.getInstance().getPlayer(val);
  771. if (target == null)
  772. {
  773. target = activeChar.getTarget();
  774. }
  775. }
  776. catch (Exception e)
  777. {
  778. target = activeChar.getTarget();
  779. }
  780. if (target instanceof L2PcInstance)
  781. {
  782. if (((L2PcInstance) target).isInParty())
  783. {
  784. gatherPartyInfo((L2PcInstance) target, activeChar);
  785. }
  786. else
  787. {
  788. activeChar.sendMessage("Not in party.");
  789. }
  790. }
  791. else
  792. {
  793. activeChar.sendMessage("Invalid target.");
  794. }
  795. }
  796. else if (command.equals("admin_setnoble"))
  797. {
  798. L2PcInstance player = null;
  799. if (activeChar.getTarget() == null)
  800. {
  801. player = activeChar;
  802. }
  803. else if ((activeChar.getTarget() != null) && (activeChar.getTarget() instanceof L2PcInstance))
  804. {
  805. player = (L2PcInstance) activeChar.getTarget();
  806. }
  807. if (player != null)
  808. {
  809. player.setNoble(!player.isNoble());
  810. if (player.getObjectId() != activeChar.getObjectId())
  811. {
  812. activeChar.sendMessage("You've changed nobless status of: " + player.getName());
  813. }
  814. player.sendMessage("GM changed your nobless status!");
  815. }
  816. }
  817. return true;
  818. }
  819. @Override
  820. public String[] getAdminCommandList()
  821. {
  822. return ADMIN_COMMANDS;
  823. }
  824. private void listCharacters(L2PcInstance activeChar, int page)
  825. {
  826. L2PcInstance[] players = L2World.getInstance().getAllPlayersArray();
  827. int maxCharactersPerPage = 20;
  828. int maxPages = players.length / maxCharactersPerPage;
  829. if (players.length > (maxCharactersPerPage * maxPages))
  830. {
  831. maxPages++;
  832. }
  833. // Check if number of users changed
  834. if (page > maxPages)
  835. {
  836. page = maxPages;
  837. }
  838. int charactersStart = maxCharactersPerPage * page;
  839. int charactersEnd = players.length;
  840. if ((charactersEnd - charactersStart) > maxCharactersPerPage)
  841. {
  842. charactersEnd = charactersStart + maxCharactersPerPage;
  843. }
  844. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  845. adminReply.setFile(activeChar.getHtmlPrefix(), "data/html/admin/charlist.htm");
  846. final StringBuilder replyMSG = new StringBuilder(1000);
  847. for (int x = 0; x < maxPages; x++)
  848. {
  849. int pagenr = x + 1;
  850. StringUtil.append(replyMSG, "<center><a action=\"bypass -h admin_show_characters ", String.valueOf(x), "\">Page ", String.valueOf(pagenr), "</a></center>");
  851. }
  852. adminReply.replace("%pages%", replyMSG.toString());
  853. replyMSG.setLength(0);
  854. for (int i = charactersStart; i < charactersEnd; i++)
  855. {
  856. // Add player info into new Table row
  857. StringUtil.append(replyMSG, "<tr><td width=80><a action=\"bypass -h admin_character_info ", players[i].getName(), "\">", players[i].getName(), "</a></td><td width=110>", ClassListData.getInstance().getClass(players[i].getClassId()).getClientCode(), "</td><td width=40>", String.valueOf(players[i].getLevel()), "</td></tr>");
  858. }
  859. adminReply.replace("%players%", replyMSG.toString());
  860. activeChar.sendPacket(adminReply);
  861. }
  862. private void showCharacterInfo(L2PcInstance activeChar, L2PcInstance player)
  863. {
  864. if (player == null)
  865. {
  866. L2Object target = activeChar.getTarget();
  867. if (target instanceof L2PcInstance)
  868. {
  869. player = (L2PcInstance) target;
  870. }
  871. else
  872. {
  873. return;
  874. }
  875. }
  876. else
  877. {
  878. activeChar.setTarget(player);
  879. }
  880. gatherCharacterInfo(activeChar, player, "charinfo.htm");
  881. }
  882. /**
  883. * Retrieve and replace player's info in filename htm file, sends it to activeChar as NpcHtmlMessage.
  884. * @param activeChar
  885. * @param player
  886. * @param filename
  887. */
  888. private void gatherCharacterInfo(L2PcInstance activeChar, L2PcInstance player, String filename)
  889. {
  890. String ip = "N/A";
  891. if (player == null)
  892. {
  893. activeChar.sendMessage("Player is null.");
  894. return;
  895. }
  896. final L2GameClient client = player.getClient();
  897. if (client == null)
  898. {
  899. activeChar.sendMessage("Client is null.");
  900. }
  901. else if (client.isDetached())
  902. {
  903. activeChar.sendMessage("Client is detached.");
  904. }
  905. else
  906. {
  907. ip = client.getConnection().getInetAddress().getHostAddress();
  908. }
  909. final NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  910. adminReply.setFile(activeChar.getHtmlPrefix(), "data/html/admin/" + filename);
  911. adminReply.replace("%name%", player.getName());
  912. adminReply.replace("%level%", String.valueOf(player.getLevel()));
  913. adminReply.replace("%clan%", String.valueOf(player.getClan() != null ? "<a action=\"bypass -h admin_clan_info " + player.getObjectId() + "\">" + player.getClan().getName() + "</a>" : null));
  914. adminReply.replace("%xp%", String.valueOf(player.getExp()));
  915. adminReply.replace("%sp%", String.valueOf(player.getSp()));
  916. adminReply.replace("%class%", ClassListData.getInstance().getClass(player.getClassId()).getClientCode());
  917. adminReply.replace("%ordinal%", String.valueOf(player.getClassId().ordinal()));
  918. adminReply.replace("%classid%", String.valueOf(player.getClassId()));
  919. adminReply.replace("%baseclass%", ClassListData.getInstance().getClass(player.getBaseClass()).getClientCode());
  920. adminReply.replace("%x%", String.valueOf(player.getX()));
  921. adminReply.replace("%y%", String.valueOf(player.getY()));
  922. adminReply.replace("%z%", String.valueOf(player.getZ()));
  923. adminReply.replace("%currenthp%", String.valueOf((int) player.getCurrentHp()));
  924. adminReply.replace("%maxhp%", String.valueOf(player.getMaxHp()));
  925. adminReply.replace("%karma%", String.valueOf(player.getKarma()));
  926. adminReply.replace("%currentmp%", String.valueOf((int) player.getCurrentMp()));
  927. adminReply.replace("%maxmp%", String.valueOf(player.getMaxMp()));
  928. adminReply.replace("%pvpflag%", String.valueOf(player.getPvpFlag()));
  929. adminReply.replace("%currentcp%", String.valueOf((int) player.getCurrentCp()));
  930. adminReply.replace("%maxcp%", String.valueOf(player.getMaxCp()));
  931. adminReply.replace("%pvpkills%", String.valueOf(player.getPvpKills()));
  932. adminReply.replace("%pkkills%", String.valueOf(player.getPkKills()));
  933. adminReply.replace("%currentload%", String.valueOf(player.getCurrentLoad()));
  934. adminReply.replace("%maxload%", String.valueOf(player.getMaxLoad()));
  935. adminReply.replace("%percent%", String.valueOf(Util.roundTo(((float) player.getCurrentLoad() / (float) player.getMaxLoad()) * 100, 2)));
  936. adminReply.replace("%patk%", String.valueOf(player.getPAtk(null)));
  937. adminReply.replace("%matk%", String.valueOf(player.getMAtk(null, null)));
  938. adminReply.replace("%pdef%", String.valueOf(player.getPDef(null)));
  939. adminReply.replace("%mdef%", String.valueOf(player.getMDef(null, null)));
  940. adminReply.replace("%accuracy%", String.valueOf(player.getAccuracy()));
  941. adminReply.replace("%evasion%", String.valueOf(player.getEvasionRate(null)));
  942. adminReply.replace("%critical%", String.valueOf(player.getCriticalHit(null, null)));
  943. adminReply.replace("%runspeed%", String.valueOf(player.getRunSpeed()));
  944. adminReply.replace("%patkspd%", String.valueOf(player.getPAtkSpd()));
  945. adminReply.replace("%matkspd%", String.valueOf(player.getMAtkSpd()));
  946. adminReply.replace("%access%", player.getAccessLevel().getLevel() + " (" + player.getAccessLevel().getName() + ")");
  947. adminReply.replace("%account%", player.getAccountName());
  948. adminReply.replace("%ip%", ip);
  949. adminReply.replace("%ai%", String.valueOf(player.getAI().getIntention().name()));
  950. adminReply.replace("%inst%", player.getInstanceId() > 0 ? "<tr><td>InstanceId:</td><td><a action=\"bypass -h admin_instance_spawns " + String.valueOf(player.getInstanceId()) + "\">" + String.valueOf(player.getInstanceId()) + "</a></td></tr>" : "");
  951. adminReply.replace("%noblesse%", player.isNoble() ? "Yes" : "No");
  952. activeChar.sendPacket(adminReply);
  953. }
  954. private void setTargetKarma(L2PcInstance activeChar, int newKarma)
  955. {
  956. // function to change karma of selected char
  957. L2Object target = activeChar.getTarget();
  958. L2PcInstance player = null;
  959. if (target instanceof L2PcInstance)
  960. {
  961. player = (L2PcInstance) target;
  962. }
  963. else
  964. {
  965. return;
  966. }
  967. if (newKarma >= 0)
  968. {
  969. // for display
  970. int oldKarma = player.getKarma();
  971. // update karma
  972. player.setKarma(newKarma);
  973. // Common character information
  974. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOUR_KARMA_HAS_BEEN_CHANGED_TO_S1);
  975. sm.addNumber(newKarma);
  976. player.sendPacket(sm);
  977. // Admin information
  978. activeChar.sendMessage("Successfully Changed karma for " + player.getName() + " from (" + oldKarma + ") to (" + newKarma + ").");
  979. if (Config.DEBUG)
  980. {
  981. _log.fine("[SET KARMA] [GM]" + activeChar.getName() + " Changed karma for " + player.getName() + " from (" + oldKarma + ") to (" + newKarma + ").");
  982. }
  983. }
  984. else
  985. {
  986. // tell admin of mistake
  987. activeChar.sendMessage("You must enter a value for karma greater than or equal to 0.");
  988. if (Config.DEBUG)
  989. {
  990. _log.fine("[SET KARMA] ERROR: [GM]" + activeChar.getName() + " entered an incorrect value for new karma: " + newKarma + " for " + player.getName() + ".");
  991. }
  992. }
  993. }
  994. private void adminModifyCharacter(L2PcInstance activeChar, String modifications)
  995. {
  996. L2Object target = activeChar.getTarget();
  997. if (!(target instanceof L2PcInstance))
  998. {
  999. return;
  1000. }
  1001. L2PcInstance player = (L2PcInstance) target;
  1002. StringTokenizer st = new StringTokenizer(modifications);
  1003. if (st.countTokens() != 6)
  1004. {
  1005. editCharacter(activeChar, null);
  1006. return;
  1007. }
  1008. String hp = st.nextToken();
  1009. String mp = st.nextToken();
  1010. String cp = st.nextToken();
  1011. String pvpflag = st.nextToken();
  1012. String pvpkills = st.nextToken();
  1013. String pkkills = st.nextToken();
  1014. int hpval = Integer.parseInt(hp);
  1015. int mpval = Integer.parseInt(mp);
  1016. int cpval = Integer.parseInt(cp);
  1017. int pvpflagval = Integer.parseInt(pvpflag);
  1018. int pvpkillsval = Integer.parseInt(pvpkills);
  1019. int pkkillsval = Integer.parseInt(pkkills);
  1020. // Common character information
  1021. player.sendMessage("Admin has changed your stats." + " HP: " + hpval + " MP: " + mpval + " CP: " + cpval + " PvP Flag: " + pvpflagval + " PvP/PK " + pvpkillsval + "/" + pkkillsval);
  1022. player.setCurrentHp(hpval);
  1023. player.setCurrentMp(mpval);
  1024. player.setCurrentCp(cpval);
  1025. player.setPvpFlag(pvpflagval);
  1026. player.setPvpKills(pvpkillsval);
  1027. player.setPkKills(pkkillsval);
  1028. // Save the changed parameters to the database.
  1029. player.store();
  1030. StatusUpdate su = new StatusUpdate(player);
  1031. su.addAttribute(StatusUpdate.CUR_HP, hpval);
  1032. su.addAttribute(StatusUpdate.MAX_HP, player.getMaxHp());
  1033. su.addAttribute(StatusUpdate.CUR_MP, mpval);
  1034. su.addAttribute(StatusUpdate.MAX_MP, player.getMaxMp());
  1035. su.addAttribute(StatusUpdate.CUR_CP, cpval);
  1036. su.addAttribute(StatusUpdate.MAX_CP, player.getMaxCp());
  1037. player.sendPacket(su);
  1038. // Admin information
  1039. activeChar.sendMessage("Changed stats of " + player.getName() + "." + " HP: " + hpval + " MP: " + mpval + " CP: " + cpval + " PvP: " + pvpflagval + " / " + pvpkillsval);
  1040. if (Config.DEBUG)
  1041. {
  1042. _log.fine("[GM]" + activeChar.getName() + " changed stats of " + player.getName() + ". " + " HP: " + hpval + " MP: " + mpval + " CP: " + cpval + " PvP: " + pvpflagval + " / " + pvpkillsval);
  1043. }
  1044. showCharacterInfo(activeChar, null); // Back to start
  1045. player.broadcastPacket(new CharInfo(player));
  1046. player.sendPacket(new UserInfo(player));
  1047. player.broadcastPacket(new ExBrExtraUserInfo(player));
  1048. player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  1049. player.decayMe();
  1050. player.spawnMe(activeChar.getX(), activeChar.getY(), activeChar.getZ());
  1051. }
  1052. private void editCharacter(L2PcInstance activeChar, String targetName)
  1053. {
  1054. L2Object target = null;
  1055. if (targetName != null)
  1056. {
  1057. target = L2World.getInstance().getPlayer(targetName);
  1058. }
  1059. else
  1060. {
  1061. target = activeChar.getTarget();
  1062. }
  1063. if (target instanceof L2PcInstance)
  1064. {
  1065. L2PcInstance player = (L2PcInstance) target;
  1066. gatherCharacterInfo(activeChar, player, "charedit.htm");
  1067. }
  1068. }
  1069. /**
  1070. * @param activeChar
  1071. * @param CharacterToFind
  1072. */
  1073. private void findCharacter(L2PcInstance activeChar, String CharacterToFind)
  1074. {
  1075. int CharactersFound = 0;
  1076. String name;
  1077. L2PcInstance[] players = L2World.getInstance().getAllPlayersArray();
  1078. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  1079. adminReply.setFile(activeChar.getHtmlPrefix(), "data/html/admin/charfind.htm");
  1080. final StringBuilder replyMSG = new StringBuilder(1000);
  1081. for (L2PcInstance player : players)
  1082. { // Add player info into new Table row
  1083. name = player.getName();
  1084. if (name.toLowerCase().contains(CharacterToFind.toLowerCase()))
  1085. {
  1086. CharactersFound = CharactersFound + 1;
  1087. StringUtil.append(replyMSG, "<tr><td width=80><a action=\"bypass -h admin_character_info ", name, "\">", name, "</a></td><td width=110>", ClassListData.getInstance().getClass(player.getClassId()).getClientCode(), "</td><td width=40>", String.valueOf(player.getLevel()), "</td></tr>");
  1088. }
  1089. if (CharactersFound > 20)
  1090. {
  1091. break;
  1092. }
  1093. }
  1094. adminReply.replace("%results%", replyMSG.toString());
  1095. final String replyMSG2;
  1096. if (CharactersFound == 0)
  1097. {
  1098. replyMSG2 = "s. Please try again.";
  1099. }
  1100. else if (CharactersFound > 20)
  1101. {
  1102. adminReply.replace("%number%", " more than 20");
  1103. replyMSG2 = "s.<br>Please refine your search to see all of the results.";
  1104. }
  1105. else if (CharactersFound == 1)
  1106. {
  1107. replyMSG2 = ".";
  1108. }
  1109. else
  1110. {
  1111. replyMSG2 = "s.";
  1112. }
  1113. adminReply.replace("%number%", String.valueOf(CharactersFound));
  1114. adminReply.replace("%end%", replyMSG2);
  1115. activeChar.sendPacket(adminReply);
  1116. }
  1117. /**
  1118. * @param activeChar
  1119. * @param IpAdress
  1120. * @throws IllegalArgumentException
  1121. */
  1122. private void findCharactersPerIp(L2PcInstance activeChar, String IpAdress) throws IllegalArgumentException
  1123. {
  1124. boolean findDisconnected = false;
  1125. if (IpAdress.equals("disconnected"))
  1126. {
  1127. findDisconnected = true;
  1128. }
  1129. else
  1130. {
  1131. if (!IpAdress.matches("^(?:(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2(?:[0-4][0-9]|5[0-5]))\\.){3}(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2(?:[0-4][0-9]|5[0-5]))$"))
  1132. {
  1133. throw new IllegalArgumentException("Malformed IPv4 number");
  1134. }
  1135. }
  1136. L2PcInstance[] players = L2World.getInstance().getAllPlayersArray();
  1137. int CharactersFound = 0;
  1138. L2GameClient client;
  1139. String name, ip = "0.0.0.0";
  1140. final StringBuilder replyMSG = new StringBuilder(1000);
  1141. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  1142. adminReply.setFile(activeChar.getHtmlPrefix(), "data/html/admin/ipfind.htm");
  1143. for (L2PcInstance player : players)
  1144. {
  1145. client = player.getClient();
  1146. if (client == null)
  1147. {
  1148. continue;
  1149. }
  1150. if (client.isDetached())
  1151. {
  1152. if (!findDisconnected)
  1153. {
  1154. continue;
  1155. }
  1156. }
  1157. else
  1158. {
  1159. if (findDisconnected)
  1160. {
  1161. continue;
  1162. }
  1163. ip = client.getConnection().getInetAddress().getHostAddress();
  1164. if (!ip.equals(IpAdress))
  1165. {
  1166. continue;
  1167. }
  1168. }
  1169. name = player.getName();
  1170. CharactersFound = CharactersFound + 1;
  1171. StringUtil.append(replyMSG, "<tr><td width=80><a action=\"bypass -h admin_character_info ", name, "\">", name, "</a></td><td width=110>", ClassListData.getInstance().getClass(player.getClassId()).getClientCode(), "</td><td width=40>", String.valueOf(player.getLevel()), "</td></tr>");
  1172. if (CharactersFound > 20)
  1173. {
  1174. break;
  1175. }
  1176. }
  1177. adminReply.replace("%results%", replyMSG.toString());
  1178. final String replyMSG2;
  1179. if (CharactersFound == 0)
  1180. {
  1181. replyMSG2 = "s. Maybe they got d/c? :)";
  1182. }
  1183. else if (CharactersFound > 20)
  1184. {
  1185. adminReply.replace("%number%", " more than " + String.valueOf(CharactersFound));
  1186. replyMSG2 = "s.<br>In order to avoid you a client crash I won't <br1>display results beyond the 20th character.";
  1187. }
  1188. else if (CharactersFound == 1)
  1189. {
  1190. replyMSG2 = ".";
  1191. }
  1192. else
  1193. {
  1194. replyMSG2 = "s.";
  1195. }
  1196. adminReply.replace("%ip%", IpAdress);
  1197. adminReply.replace("%number%", String.valueOf(CharactersFound));
  1198. adminReply.replace("%end%", replyMSG2);
  1199. activeChar.sendPacket(adminReply);
  1200. }
  1201. /**
  1202. * @param activeChar
  1203. * @param characterName
  1204. * @throws IllegalArgumentException
  1205. */
  1206. private void findCharactersPerAccount(L2PcInstance activeChar, String characterName) throws IllegalArgumentException
  1207. {
  1208. if (characterName.matches(Config.CNAME_TEMPLATE))
  1209. {
  1210. String account = null;
  1211. Map<Integer, String> chars;
  1212. L2PcInstance player = L2World.getInstance().getPlayer(characterName);
  1213. if (player == null)
  1214. {
  1215. throw new IllegalArgumentException("Player doesn't exist");
  1216. }
  1217. chars = player.getAccountChars();
  1218. account = player.getAccountName();
  1219. final StringBuilder replyMSG = new StringBuilder(chars.size() * 20);
  1220. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  1221. adminReply.setFile(activeChar.getHtmlPrefix(), "data/html/admin/accountinfo.htm");
  1222. for (String charname : chars.values())
  1223. {
  1224. StringUtil.append(replyMSG, charname, "<br1>");
  1225. }
  1226. adminReply.replace("%characters%", replyMSG.toString());
  1227. adminReply.replace("%account%", account);
  1228. adminReply.replace("%player%", characterName);
  1229. activeChar.sendPacket(adminReply);
  1230. }
  1231. else
  1232. {
  1233. throw new IllegalArgumentException("Malformed character name");
  1234. }
  1235. }
  1236. /**
  1237. * @param activeChar
  1238. * @param multibox
  1239. */
  1240. private void findDualbox(L2PcInstance activeChar, int multibox)
  1241. {
  1242. L2PcInstance[] players = L2World.getInstance().getAllPlayersArray();
  1243. Map<String, List<L2PcInstance>> ipMap = new HashMap<>();
  1244. String ip = "0.0.0.0";
  1245. L2GameClient client;
  1246. final Map<String, Integer> dualboxIPs = new HashMap<>();
  1247. for (L2PcInstance player : players)
  1248. {
  1249. client = player.getClient();
  1250. if ((client == null) || client.isDetached())
  1251. {
  1252. continue;
  1253. }
  1254. ip = client.getConnection().getInetAddress().getHostAddress();
  1255. if (ipMap.get(ip) == null)
  1256. {
  1257. ipMap.put(ip, new ArrayList<L2PcInstance>());
  1258. }
  1259. ipMap.get(ip).add(player);
  1260. if (ipMap.get(ip).size() >= multibox)
  1261. {
  1262. Integer count = dualboxIPs.get(ip);
  1263. if (count == null)
  1264. {
  1265. dualboxIPs.put(ip, multibox);
  1266. }
  1267. else
  1268. {
  1269. dualboxIPs.put(ip, count + 1);
  1270. }
  1271. }
  1272. }
  1273. List<String> keys = new ArrayList<>(dualboxIPs.keySet());
  1274. Collections.sort(keys, new Comparator<String>()
  1275. {
  1276. @Override
  1277. public int compare(String left, String right)
  1278. {
  1279. return dualboxIPs.get(left).compareTo(dualboxIPs.get(right));
  1280. }
  1281. });
  1282. Collections.reverse(keys);
  1283. final StringBuilder results = new StringBuilder();
  1284. for (String dualboxIP : keys)
  1285. {
  1286. StringUtil.append(results, "<a action=\"bypass -h admin_find_ip " + dualboxIP + "\">" + dualboxIP + " (" + dualboxIPs.get(dualboxIP) + ")</a><br1>");
  1287. }
  1288. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  1289. adminReply.setFile(activeChar.getHtmlPrefix(), "data/html/admin/dualbox.htm");
  1290. adminReply.replace("%multibox%", String.valueOf(multibox));
  1291. adminReply.replace("%results%", results.toString());
  1292. adminReply.replace("%strict%", "");
  1293. activeChar.sendPacket(adminReply);
  1294. }
  1295. private void findDualboxStrict(L2PcInstance activeChar, int multibox)
  1296. {
  1297. L2PcInstance[] players = L2World.getInstance().getAllPlayersArray();
  1298. Map<IpPack, List<L2PcInstance>> ipMap = new HashMap<>();
  1299. L2GameClient client;
  1300. final Map<IpPack, Integer> dualboxIPs = new HashMap<>();
  1301. for (L2PcInstance player : players)
  1302. {
  1303. client = player.getClient();
  1304. if ((client == null) || client.isDetached())
  1305. {
  1306. continue;
  1307. }
  1308. IpPack pack = new IpPack(client.getConnection().getInetAddress().getHostAddress(), client.getTrace());
  1309. if (ipMap.get(pack) == null)
  1310. {
  1311. ipMap.put(pack, new ArrayList<L2PcInstance>());
  1312. }
  1313. ipMap.get(pack).add(player);
  1314. if (ipMap.get(pack).size() >= multibox)
  1315. {
  1316. Integer count = dualboxIPs.get(pack);
  1317. if (count == null)
  1318. {
  1319. dualboxIPs.put(pack, multibox);
  1320. }
  1321. else
  1322. {
  1323. dualboxIPs.put(pack, count + 1);
  1324. }
  1325. }
  1326. }
  1327. List<IpPack> keys = new ArrayList<>(dualboxIPs.keySet());
  1328. Collections.sort(keys, new Comparator<IpPack>()
  1329. {
  1330. @Override
  1331. public int compare(IpPack left, IpPack right)
  1332. {
  1333. return dualboxIPs.get(left).compareTo(dualboxIPs.get(right));
  1334. }
  1335. });
  1336. Collections.reverse(keys);
  1337. final StringBuilder results = new StringBuilder();
  1338. for (IpPack dualboxIP : keys)
  1339. {
  1340. StringUtil.append(results, "<a action=\"bypass -h admin_find_ip " + dualboxIP.ip + "\">" + dualboxIP.ip + " (" + dualboxIPs.get(dualboxIP) + ")</a><br1>");
  1341. }
  1342. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  1343. adminReply.setFile(activeChar.getHtmlPrefix(), "data/html/admin/dualbox.htm");
  1344. adminReply.replace("%multibox%", String.valueOf(multibox));
  1345. adminReply.replace("%results%", results.toString());
  1346. adminReply.replace("%strict%", "strict_");
  1347. activeChar.sendPacket(adminReply);
  1348. }
  1349. private final class IpPack
  1350. {
  1351. String ip;
  1352. int[][] tracert;
  1353. public IpPack(String ip, int[][] tracert)
  1354. {
  1355. this.ip = ip;
  1356. this.tracert = tracert;
  1357. }
  1358. @Override
  1359. public int hashCode()
  1360. {
  1361. final int prime = 31;
  1362. int result = 1;
  1363. result = (prime * result) + ((ip == null) ? 0 : ip.hashCode());
  1364. for (int[] array : tracert)
  1365. {
  1366. result = (prime * result) + Arrays.hashCode(array);
  1367. }
  1368. return result;
  1369. }
  1370. @Override
  1371. public boolean equals(Object obj)
  1372. {
  1373. if (this == obj)
  1374. {
  1375. return true;
  1376. }
  1377. if (obj == null)
  1378. {
  1379. return false;
  1380. }
  1381. if (getClass() != obj.getClass())
  1382. {
  1383. return false;
  1384. }
  1385. IpPack other = (IpPack) obj;
  1386. if (!getOuterType().equals(other.getOuterType()))
  1387. {
  1388. return false;
  1389. }
  1390. if (ip == null)
  1391. {
  1392. if (other.ip != null)
  1393. {
  1394. return false;
  1395. }
  1396. }
  1397. else if (!ip.equals(other.ip))
  1398. {
  1399. return false;
  1400. }
  1401. for (int i = 0; i < tracert.length; i++)
  1402. {
  1403. for (int o = 0; o < tracert[0].length; o++)
  1404. {
  1405. if (tracert[i][o] != other.tracert[i][o])
  1406. {
  1407. return false;
  1408. }
  1409. }
  1410. }
  1411. return true;
  1412. }
  1413. private AdminEditChar getOuterType()
  1414. {
  1415. return AdminEditChar.this;
  1416. }
  1417. }
  1418. private void gatherSummonInfo(L2Summon target, L2PcInstance activeChar)
  1419. {
  1420. NpcHtmlMessage html = new NpcHtmlMessage(0);
  1421. html.setFile(activeChar.getHtmlPrefix(), "data/html/admin/petinfo.htm");
  1422. String name = target.getName();
  1423. html.replace("%name%", name == null ? "N/A" : name);
  1424. html.replace("%level%", Integer.toString(target.getLevel()));
  1425. html.replace("%exp%", Long.toString(target.getStat().getExp()));
  1426. String owner = target.getActingPlayer().getName();
  1427. html.replace("%owner%", " <a action=\"bypass -h admin_character_info " + owner + "\">" + owner + "</a>");
  1428. html.replace("%class%", target.getClass().getSimpleName());
  1429. html.replace("%ai%", target.hasAI() ? String.valueOf(target.getAI().getIntention().name()) : "NULL");
  1430. html.replace("%hp%", (int) target.getStatus().getCurrentHp() + "/" + target.getStat().getMaxHp());
  1431. html.replace("%mp%", (int) target.getStatus().getCurrentMp() + "/" + target.getStat().getMaxMp());
  1432. html.replace("%karma%", Integer.toString(target.getKarma()));
  1433. html.replace("%undead%", target.isUndead() ? "yes" : "no");
  1434. if (target instanceof L2PetInstance)
  1435. {
  1436. int objId = target.getActingPlayer().getObjectId();
  1437. html.replace("%inv%", " <a action=\"bypass admin_show_pet_inv " + objId + "\">view</a>");
  1438. }
  1439. else
  1440. {
  1441. html.replace("%inv%", "none");
  1442. }
  1443. if (target instanceof L2PetInstance)
  1444. {
  1445. html.replace("%food%", ((L2PetInstance) target).getCurrentFed() + "/" + ((L2PetInstance) target).getPetLevelData().getPetMaxFeed());
  1446. html.replace("%load%", ((L2PetInstance) target).getInventory().getTotalWeight() + "/" + ((L2PetInstance) target).getMaxLoad());
  1447. }
  1448. else
  1449. {
  1450. html.replace("%food%", "N/A");
  1451. html.replace("%load%", "N/A");
  1452. }
  1453. activeChar.sendPacket(html);
  1454. }
  1455. private void gatherPartyInfo(L2PcInstance target, L2PcInstance activeChar)
  1456. {
  1457. boolean color = true;
  1458. NpcHtmlMessage html = new NpcHtmlMessage(0);
  1459. html.setFile(activeChar.getHtmlPrefix(), "data/html/admin/partyinfo.htm");
  1460. StringBuilder text = new StringBuilder(400);
  1461. for (L2PcInstance member : target.getParty().getMembers())
  1462. {
  1463. if (color)
  1464. {
  1465. text.append("<tr><td><table width=270 border=0 bgcolor=131210 cellpadding=2><tr><td width=30 align=right>");
  1466. }
  1467. else
  1468. {
  1469. text.append("<tr><td><table width=270 border=0 cellpadding=2><tr><td width=30 align=right>");
  1470. }
  1471. text.append(member.getLevel() + "</td><td width=130><a action=\"bypass -h admin_character_info " + member.getName() + "\">" + member.getName() + "</a>");
  1472. text.append("</td><td width=110 align=right>" + member.getClassId().toString() + "</td></tr></table></td></tr>");
  1473. color = !color;
  1474. }
  1475. html.replace("%player%", target.getName());
  1476. html.replace("%party%", text.toString());
  1477. activeChar.sendPacket(html);
  1478. }
  1479. }