GameStatusThread.java 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174
  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.status;
  16. import java.io.BufferedReader;
  17. import java.io.File;
  18. import java.io.FileInputStream;
  19. import java.io.FileOutputStream;
  20. import java.io.IOException;
  21. import java.io.InputStream;
  22. import java.io.InputStreamReader;
  23. import java.io.OutputStreamWriter;
  24. import java.io.PrintWriter;
  25. import java.net.InetAddress;
  26. import java.net.Socket;
  27. import java.sql.Connection;
  28. import java.sql.PreparedStatement;
  29. import java.sql.SQLException;
  30. import java.text.SimpleDateFormat;
  31. import java.util.Calendar;
  32. import java.util.Map;
  33. import java.util.NoSuchElementException;
  34. import java.util.Properties;
  35. import java.util.StringTokenizer;
  36. import java.util.Map.Entry;
  37. import net.sf.l2j.Config;
  38. import net.sf.l2j.L2DatabaseFactory;
  39. import net.sf.l2j.gameserver.Announcements;
  40. import net.sf.l2j.gameserver.GameTimeController;
  41. import net.sf.l2j.gameserver.GmListTable;
  42. import net.sf.l2j.gameserver.LoginServerThread;
  43. import net.sf.l2j.gameserver.Shutdown;
  44. import net.sf.l2j.gameserver.ThreadPoolManager;
  45. import net.sf.l2j.gameserver.cache.HtmCache;
  46. import net.sf.l2j.gameserver.clientpackets.Say2;
  47. import net.sf.l2j.gameserver.datatables.ItemTable;
  48. import net.sf.l2j.gameserver.datatables.NpcTable;
  49. import net.sf.l2j.gameserver.datatables.SkillTable;
  50. import net.sf.l2j.gameserver.datatables.SpawnTable;
  51. import net.sf.l2j.gameserver.datatables.TeleportLocationTable;
  52. import net.sf.l2j.gameserver.instancemanager.DayNightSpawnManager;
  53. import net.sf.l2j.gameserver.instancemanager.Manager;
  54. import net.sf.l2j.gameserver.instancemanager.RaidBossSpawnManager;
  55. import net.sf.l2j.gameserver.model.GMAudit;
  56. import net.sf.l2j.gameserver.model.Inventory;
  57. import net.sf.l2j.gameserver.model.L2Character;
  58. import net.sf.l2j.gameserver.model.L2ItemInstance;
  59. import net.sf.l2j.gameserver.model.L2Multisell;
  60. import net.sf.l2j.gameserver.model.L2Object;
  61. import net.sf.l2j.gameserver.model.L2Summon;
  62. import net.sf.l2j.gameserver.model.L2World;
  63. import net.sf.l2j.gameserver.model.TradeList;
  64. import net.sf.l2j.gameserver.model.TradeList.TradeItem;
  65. import net.sf.l2j.gameserver.model.actor.instance.L2DoorInstance;
  66. import net.sf.l2j.gameserver.model.actor.instance.L2MonsterInstance;
  67. import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
  68. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  69. import net.sf.l2j.gameserver.network.SystemMessageId;
  70. import net.sf.l2j.gameserver.serverpackets.CharInfo;
  71. import net.sf.l2j.gameserver.serverpackets.CreatureSay;
  72. import net.sf.l2j.gameserver.serverpackets.InventoryUpdate;
  73. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  74. import net.sf.l2j.gameserver.serverpackets.UserInfo;
  75. import net.sf.l2j.gameserver.taskmanager.DecayTaskManager;
  76. import net.sf.l2j.gameserver.util.DynamicExtension;
  77. public class GameStatusThread extends Thread
  78. {
  79. //private static final Logger _log = Logger.getLogger(AdminTeleport.class.getName());
  80. private Socket _cSocket;
  81. private PrintWriter _print;
  82. private BufferedReader _read;
  83. private int _uptime;
  84. private void telnetOutput(int type, String text)
  85. {
  86. if (Config.DEVELOPER)
  87. {
  88. if ( type == 1 ) System.out.println("TELNET | "+text);
  89. else if ( type == 2 ) System.out.print("TELNET | "+text);
  90. else if ( type == 3 ) System.out.print(text);
  91. else if ( type == 4 ) System.out.println(text);
  92. else System.out.println("TELNET | "+text);
  93. }
  94. else
  95. {
  96. //only print output if the message is rejected
  97. if ( type == 5 ) System.out.println("TELNET | "+text);
  98. }
  99. }
  100. private boolean isValidIP(Socket client) {
  101. boolean result = false;
  102. InetAddress ClientIP = client.getInetAddress();
  103. // convert IP to String, and compare with list
  104. String clientStringIP = ClientIP.getHostAddress();
  105. telnetOutput(1, "Connection from: "+clientStringIP);
  106. // read and loop thru list of IPs, compare with newIP
  107. if ( Config.DEVELOPER ) telnetOutput(2, "");
  108. try {
  109. Properties telnetSettings = new Properties();
  110. InputStream telnetIS = new FileInputStream(new File(Config.TELNET_FILE));
  111. telnetSettings.load(telnetIS);
  112. telnetIS.close();
  113. String HostList = telnetSettings.getProperty("ListOfHosts", "127.0.0.1,localhost");
  114. if ( Config.DEVELOPER ) telnetOutput(3, "Comparing ip to list...");
  115. // compare
  116. String ipToCompare = null;
  117. for (String ip:HostList.split(",")) {
  118. if ( !result ) {
  119. ipToCompare = InetAddress.getByName(ip).getHostAddress();
  120. if ( clientStringIP.equals(ipToCompare) ) result = true;
  121. if ( Config.DEVELOPER ) telnetOutput(3, clientStringIP + " = " + ipToCompare + "("+ip+") = " + result);
  122. }
  123. }
  124. }
  125. catch ( IOException e) {
  126. if ( Config.DEVELOPER ) telnetOutput(4, "");
  127. telnetOutput(1, "Error: "+e);
  128. }
  129. if ( Config.DEVELOPER ) telnetOutput(4, "Allow IP: "+result);
  130. return result;
  131. }
  132. public GameStatusThread(Socket client, int uptime, String StatusPW) throws IOException
  133. {
  134. _cSocket = client;
  135. _uptime = uptime;
  136. _print = new PrintWriter(_cSocket.getOutputStream());
  137. _read = new BufferedReader(new InputStreamReader(_cSocket.getInputStream()));
  138. if ( isValidIP(client) ) {
  139. telnetOutput(1, client.getInetAddress().getHostAddress()+" accepted.");
  140. _print.println("Welcome To The L2J Telnet Session.");
  141. _print.println("Please Insert Your Password!");
  142. _print.print("Password: ");
  143. _print.flush();
  144. String tmpLine = _read.readLine();
  145. if ( tmpLine == null ) {
  146. _print.println("Error.");
  147. _print.println("Disconnected...");
  148. _print.flush();
  149. _cSocket.close();
  150. }
  151. else {
  152. if (tmpLine.compareTo(StatusPW) != 0)
  153. {
  154. _print.println("Incorrect Password!");
  155. _print.println("Disconnected...");
  156. _print.flush();
  157. _cSocket.close();
  158. }
  159. else
  160. {
  161. _print.println("Password Correct!");
  162. _print.println("[L2J Game Server]");
  163. _print.print("");
  164. _print.flush();
  165. start();
  166. }
  167. }
  168. }
  169. else {
  170. telnetOutput(5, "Connection attempt from "+ client.getInetAddress().getHostAddress() +" rejected.");
  171. _cSocket.close();
  172. }
  173. }
  174. @Override
  175. @SuppressWarnings("deprecation")
  176. public void run()
  177. {
  178. String _usrCommand = "";
  179. try
  180. {
  181. while (_usrCommand.compareTo("quit") != 0 && _usrCommand.compareTo("exit") != 0)
  182. {
  183. _usrCommand = _read.readLine();
  184. if(_usrCommand == null)
  185. {
  186. _cSocket.close();
  187. break;
  188. }
  189. if (_usrCommand.equals("help")) {
  190. _print.println("The following is a list of all available commands: ");
  191. _print.println("help - shows this help.");
  192. _print.println("status - displays basic server statistics.");
  193. _print.println("performance - shows server performance statistics.");
  194. _print.println("purge - removes finished threads from thread pools.");
  195. _print.println("announce <text> - announces <text> in game.");
  196. _print.println("msg <nick> <text> - Sends a whisper to char <nick> with <text>.");
  197. _print.println("gmchat <text> - Sends a message to all GMs with <text>.");
  198. _print.println("gmlist - lists all gms online.");
  199. _print.println("kick - kick player <name> from server.");
  200. _print.println("shutdown <time> - shuts down server in <time> seconds.");
  201. _print.println("restart <time> - restarts down server in <time> seconds.");
  202. _print.println("abort - aborts shutdown/restart.");
  203. _print.println("give <player> <itemid> <amount>");
  204. _print.println("enchant <player> <itemType> <enchant> (itemType: 1 - Helmet, 2 - Chest, 3 - Gloves, 4 - Feet, 5 - Legs, 6 - Right Hand, 7 - Left Hand, 8 - Left Ear, 9 - Right Ear , 10 - Left Finger, 11 - Right Finger, 12- Necklace, 13 - Underwear, 14 - Back, 0 - No Enchant)");
  205. _print.println("extlist - list all loaded extension classes");
  206. _print.println("extreload <name> - reload and initializes the named extension or all if used without argument");
  207. _print.println("extinit <name> - initilizes the named extension or all if used without argument");
  208. _print.println("extunload <name> - unload the named extension or all if used without argument");
  209. _print.println("debug <cmd> - executes the debug command (see 'help debug').");
  210. _print.println("jail <player> [time]");
  211. _print.println("unjail <player>");
  212. _print.println("quit - closes telnet session.");
  213. }
  214. else if(_usrCommand.equals("help debug"))
  215. {
  216. _print.println("The following is a list of all available debug commands: ");
  217. _print.println("full - Dumps complete debug information to an file (recommended)");
  218. _print.println("decay - prints info about the DecayManager");
  219. _print.println("PacketTP - prints info about the General Packet ThreadPool");
  220. _print.println("IOPacketTP - prints info about the I/O Packet ThreadPool");
  221. _print.println("GeneralTP - prints info about the General ThreadPool");
  222. }
  223. else if (_usrCommand.equals("status"))
  224. {
  225. _print.print(this.getServerStatus());
  226. _print.flush();
  227. }
  228. else if (_usrCommand.equals("performance"))
  229. {
  230. for (String line : ThreadPoolManager.getInstance().getStats())
  231. {
  232. _print.println(line);
  233. }
  234. _print.flush();
  235. }
  236. else if (_usrCommand.equals("purge"))
  237. {
  238. ThreadPoolManager.getInstance().purge();
  239. _print.println("STATUS OF THREAD POOLS AFTER PURGE COMMAND:");
  240. _print.println("");
  241. for (String line : ThreadPoolManager.getInstance().getStats())
  242. {
  243. _print.println(line);
  244. }
  245. _print.flush();
  246. }
  247. else if (_usrCommand.startsWith("announce"))
  248. {
  249. try
  250. {
  251. _usrCommand = _usrCommand.substring(9);
  252. Announcements.getInstance().announceToAll(_usrCommand);
  253. _print.println("Announcement Sent!");
  254. }
  255. catch (StringIndexOutOfBoundsException e)
  256. {
  257. _print.println("Please Enter Some Text To Announce!");
  258. }
  259. }
  260. else if (_usrCommand.startsWith("msg"))
  261. {
  262. try
  263. {
  264. String val = _usrCommand.substring(4);
  265. StringTokenizer st = new StringTokenizer(val);
  266. String name = st.nextToken();
  267. String message = val.substring(name.length()+1);
  268. L2PcInstance reciever = L2World.getInstance().getPlayer(name);
  269. CreatureSay cs = new CreatureSay(0, Say2.TELL, "Telnet Priv", message);
  270. if(reciever != null)
  271. {
  272. reciever.sendPacket(cs);
  273. _print.println("Telnet Priv->" + name + ": " + message);
  274. _print.println("Message Sent!");
  275. }
  276. else
  277. {
  278. _print.println("Unable To Find Username: " + name);
  279. }
  280. }
  281. catch (StringIndexOutOfBoundsException e)
  282. {
  283. _print.println("Please Enter Some Text!");
  284. }
  285. }
  286. else if (_usrCommand.startsWith("gmchat"))
  287. {
  288. try
  289. {
  290. _usrCommand = _usrCommand.substring(7);
  291. CreatureSay cs = new CreatureSay(0, 9, "Telnet GM Broadcast from " + _cSocket.getInetAddress().getHostAddress(), _usrCommand);
  292. GmListTable.broadcastToGMs(cs);
  293. _print.println("Your Message Has Been Sent To " + getOnlineGMS() + " GM(s).");
  294. }
  295. catch (StringIndexOutOfBoundsException e)
  296. {
  297. _print.println("Please Enter Some Text To Announce!");
  298. }
  299. }
  300. else if (_usrCommand.equals("gmlist"))
  301. {
  302. int igm = 0;
  303. String gmList = "";
  304. for (String player : GmListTable.getInstance().getAllGmNames(true))
  305. {
  306. gmList = gmList + ", " + player;
  307. igm++;
  308. }
  309. _print.println("There are currently " + igm +" GM(s) online...");
  310. if ( gmList != "" ) _print.println(gmList);
  311. }
  312. /*else if (_usrCommand.startsWith("unblock"))
  313. {
  314. try
  315. {
  316. _usrCommand = _usrCommand.substring(8);
  317. if (LoginServer.getInstance().unblockIp(_usrCommand))
  318. {
  319. _log.warning("IP removed via TELNET by host: " + _csocket.getInetAddress().getHostAddress());
  320. _print.println("The IP " + _usrCommand + " has been removed from the hack protection list!");
  321. }
  322. else
  323. {
  324. _print.println("IP not found in hack protection list...");
  325. }
  326. //TODO: with packet
  327. }
  328. catch (StringIndexOutOfBoundsException e)
  329. {
  330. _print.println("Please Enter the IP to Unblock!");
  331. }
  332. }*/
  333. else if (_usrCommand.startsWith("kick"))
  334. {
  335. try
  336. {
  337. _usrCommand = _usrCommand.substring(5);
  338. L2PcInstance player = L2World.getInstance().getPlayer(_usrCommand);
  339. if(player != null)
  340. {
  341. player.sendMessage("You are kicked by gm");
  342. player.logout();
  343. _print.println("Player kicked");
  344. }
  345. }
  346. catch (StringIndexOutOfBoundsException e)
  347. {
  348. _print.println("Please enter player name to kick");
  349. }
  350. }
  351. else if (_usrCommand.startsWith("shutdown"))
  352. {
  353. try
  354. {
  355. int val = Integer.parseInt(_usrCommand.substring(9));
  356. Shutdown.getInstance().startTelnetShutdown(_cSocket.getInetAddress().getHostAddress(), val, false);
  357. _print.println("Server Will Shutdown In " + val + " Seconds!");
  358. _print.println("Type \"abort\" To Abort Shutdown!");
  359. }
  360. catch (StringIndexOutOfBoundsException e)
  361. {
  362. _print.println("Please Enter * amount of seconds to shutdown!");
  363. }
  364. catch (Exception NumberFormatException) {
  365. _print.println("Numbers Only!");
  366. }
  367. }
  368. else if (_usrCommand.startsWith("restart"))
  369. {
  370. try
  371. {
  372. int val = Integer.parseInt(_usrCommand.substring(8));
  373. Shutdown.getInstance().startTelnetShutdown(_cSocket.getInetAddress().getHostAddress(), val, true);
  374. _print.println("Server Will Restart In " + val + " Seconds!");
  375. _print.println("Type \"abort\" To Abort Restart!");
  376. }
  377. catch (StringIndexOutOfBoundsException e)
  378. {
  379. _print.println("Please Enter * amount of seconds to restart!");
  380. }
  381. catch (Exception NumberFormatException) {
  382. _print.println("Numbers Only!");
  383. }
  384. }
  385. else if (_usrCommand.startsWith("abort"))
  386. {
  387. Shutdown.getInstance().telnetAbort(_cSocket.getInetAddress().getHostAddress());
  388. _print.println("OK! - Shutdown/Restart Aborted.");
  389. }
  390. else if (_usrCommand.equals("quit")) { /* Do Nothing :p - Just here to save us from the "Command Not Understood" Text */ }
  391. else if (_usrCommand.startsWith("give"))
  392. {
  393. StringTokenizer st = new StringTokenizer(_usrCommand.substring(5));
  394. try
  395. {
  396. L2PcInstance player = L2World.getInstance().getPlayer(st.nextToken());
  397. int itemId = Integer.parseInt(st.nextToken());
  398. int amount = Integer.parseInt(st.nextToken());
  399. if(player != null)
  400. {
  401. L2ItemInstance item = player.getInventory().addItem("Status-Give", itemId, amount, null, null);
  402. InventoryUpdate iu = new InventoryUpdate();
  403. iu.addItem(item);
  404. player.sendPacket(iu);
  405. SystemMessage sm = new SystemMessage(SystemMessageId.YOU_PICKED_UP_S1_S2);
  406. sm.addItemName(itemId);
  407. sm.addNumber(amount);
  408. player.sendPacket(sm);
  409. _print.println("ok");
  410. }
  411. }
  412. catch(Exception e)
  413. {
  414. }
  415. }
  416. else if (_usrCommand.startsWith("enchant"))
  417. {
  418. StringTokenizer st = new StringTokenizer(_usrCommand.substring(8), " ");
  419. int enchant = 0, itemType = 0;
  420. try
  421. {
  422. L2PcInstance player = L2World.getInstance().getPlayer(st.nextToken());
  423. itemType = Integer.parseInt(st.nextToken());
  424. enchant = Integer.parseInt(st.nextToken());
  425. switch(itemType)
  426. {
  427. case 1:
  428. itemType = Inventory.PAPERDOLL_HEAD;
  429. break;
  430. case 2:
  431. itemType = Inventory.PAPERDOLL_CHEST;
  432. break;
  433. case 3:
  434. itemType = Inventory.PAPERDOLL_GLOVES;
  435. break;
  436. case 4:
  437. itemType = Inventory.PAPERDOLL_FEET;
  438. break;
  439. case 5:
  440. itemType = Inventory.PAPERDOLL_LEGS;
  441. break;
  442. case 6:
  443. itemType = Inventory.PAPERDOLL_RHAND;
  444. break;
  445. case 7:
  446. itemType = Inventory.PAPERDOLL_LHAND;
  447. break;
  448. case 8:
  449. itemType = Inventory.PAPERDOLL_LEAR;
  450. break;
  451. case 9:
  452. itemType = Inventory.PAPERDOLL_REAR;
  453. break;
  454. case 10:
  455. itemType = Inventory.PAPERDOLL_LFINGER;
  456. break;
  457. case 11:
  458. itemType = Inventory.PAPERDOLL_RFINGER;
  459. break;
  460. case 12:
  461. itemType = Inventory.PAPERDOLL_NECK;
  462. break;
  463. case 13:
  464. itemType = Inventory.PAPERDOLL_UNDER;
  465. break;
  466. case 14:
  467. itemType = Inventory.PAPERDOLL_BACK;
  468. break;
  469. default:
  470. itemType = 0;
  471. }
  472. if (enchant > 65535)
  473. enchant = 65535;
  474. else if (enchant < 0)
  475. enchant = 0;
  476. boolean success = false;
  477. if(player != null && itemType > 0)
  478. {
  479. success = setEnchant(player, enchant, itemType);
  480. if (success)_print.println("Item enchanted successfully.");
  481. }
  482. else if (!success)
  483. _print.println("Item failed to enchant.");
  484. }
  485. catch(Exception e)
  486. {
  487. }
  488. }
  489. else if (_usrCommand.startsWith("jail"))
  490. {
  491. StringTokenizer st = new StringTokenizer(_usrCommand.substring(5));
  492. try
  493. {
  494. L2PcInstance playerObj = L2World.getInstance().getPlayer(st.nextToken());
  495. int delay = 0;
  496. try
  497. {
  498. delay = Integer.parseInt(st.nextToken());
  499. } catch (NumberFormatException nfe) {
  500. } catch (NoSuchElementException nsee) {}
  501. //L2PcInstance playerObj = L2World.getInstance().getPlayer(player);
  502. if (playerObj != null)
  503. {
  504. playerObj.setInJail(true, delay);
  505. _print.println("Character "+playerObj.getName()+" jailed for "+(delay>0 ? delay+" minutes." : "ever!"));
  506. } else
  507. jailOfflinePlayer(playerObj.getName(), delay);
  508. } catch (NoSuchElementException nsee)
  509. {
  510. _print.println("Specify a character name.");
  511. } catch(Exception e)
  512. {
  513. if (Config.DEBUG) e.printStackTrace();
  514. }
  515. }
  516. else if (_usrCommand.startsWith("unjail"))
  517. {
  518. StringTokenizer st = new StringTokenizer(_usrCommand.substring(7));
  519. try
  520. {
  521. L2PcInstance playerObj = L2World.getInstance().getPlayer(st.nextToken());
  522. if (playerObj != null)
  523. {
  524. playerObj.stopJailTask(false);
  525. playerObj.setInJail(false, 0);
  526. _print.println("Character "+playerObj.getName()+" removed from jail");
  527. } else
  528. unjailOfflinePlayer(playerObj.getName());
  529. } catch (NoSuchElementException nsee)
  530. {
  531. _print.println("Specify a character name.");
  532. } catch(Exception e)
  533. {
  534. if (Config.DEBUG) e.printStackTrace();
  535. }
  536. }
  537. else if (_usrCommand.startsWith("debug") && _usrCommand.length() > 6)
  538. {
  539. StringTokenizer st = new StringTokenizer(_usrCommand.substring(6));
  540. try
  541. {
  542. String dbg = st.nextToken();
  543. if(dbg.equals("decay"))
  544. {
  545. _print.print(DecayTaskManager.getInstance().toString());
  546. }
  547. else if(dbg.equals("ai"))
  548. {
  549. /*
  550. _print.println("AITaskManagerStats");
  551. for(String line : AITaskManager.getInstance().getStats())
  552. {
  553. _print.println(line);
  554. }
  555. */
  556. }
  557. else if(dbg.equals("aiflush"))
  558. {
  559. //AITaskManager.getInstance().flush();
  560. }
  561. else if(dbg.equals("PacketTP"))
  562. {
  563. String str = ThreadPoolManager.getInstance().getPacketStats();
  564. _print.println(str);
  565. int i = 0;
  566. File f = new File("./log/StackTrace-PacketTP-"+i+".txt");
  567. while(f.exists())
  568. {
  569. i++;
  570. f = new File("./log/StackTrace-PacketTP-"+i+".txt");
  571. }
  572. f.getParentFile().mkdirs();
  573. FileOutputStream fos = new FileOutputStream(f);
  574. OutputStreamWriter out = new OutputStreamWriter(fos, "UTF-8");
  575. out.write(str);
  576. out.flush();
  577. out.close();
  578. fos.close();
  579. }
  580. else if(dbg.equals("IOPacketTP"))
  581. {
  582. String str = ThreadPoolManager.getInstance().getIOPacketStats();
  583. _print.println(str);
  584. int i = 0;
  585. File f = new File("./log/StackTrace-IOPacketTP-"+i+".txt");
  586. while(f.exists())
  587. {
  588. i++;
  589. f = new File("./log/StackTrace-IOPacketTP-"+i+".txt");
  590. }
  591. f.getParentFile().mkdirs();
  592. FileOutputStream fos = new FileOutputStream(f);
  593. OutputStreamWriter out = new OutputStreamWriter(fos, "UTF-8");
  594. out.write(str);
  595. out.flush();
  596. out.close();
  597. fos.close();
  598. }
  599. else if(dbg.equals("GeneralTP"))
  600. {
  601. String str = ThreadPoolManager.getInstance().getGeneralStats();
  602. _print.println(str);
  603. int i = 0;
  604. File f = new File("./log/StackTrace-GeneralTP-"+i+".txt");
  605. while(f.exists())
  606. {
  607. i++;
  608. f = new File("./log/StackTrace-GeneralTP-"+i+".txt");
  609. }
  610. f.getParentFile().mkdirs();
  611. FileOutputStream fos = new FileOutputStream(f);
  612. OutputStreamWriter out = new OutputStreamWriter(fos, "UTF-8");
  613. out.write(str);
  614. out.flush();
  615. out.close();
  616. fos.close();
  617. }
  618. else if(dbg.equals("full"))
  619. {
  620. this.debugAll();
  621. }
  622. }
  623. catch(Exception e){}
  624. }
  625. else if (_usrCommand.startsWith("reload"))
  626. {
  627. StringTokenizer st = new StringTokenizer(_usrCommand.substring(7));
  628. try
  629. {
  630. String type = st.nextToken();
  631. if(type.equals("multisell"))
  632. {
  633. _print.print("Reloading multisell... ");
  634. L2Multisell.getInstance().reload();
  635. _print.print("done\n");
  636. }
  637. else if(type.equals("skill"))
  638. {
  639. _print.print("Reloading skills... ");
  640. SkillTable.getInstance().reload();
  641. _print.print("done\n");
  642. }
  643. else if(type.equals("npc"))
  644. {
  645. _print.print("Reloading npc templates... ");
  646. NpcTable.getInstance().reloadAllNpc();
  647. _print.print("done\n");
  648. }
  649. else if(type.equals("html"))
  650. {
  651. _print.print("Reloading html cache... ");
  652. HtmCache.getInstance().reload();
  653. _print.print("done\n");
  654. }
  655. else if(type.equals("item"))
  656. {
  657. _print.print("Reloading item templates... ");
  658. ItemTable.getInstance().reload();
  659. _print.print("done\n");
  660. }
  661. else if(type.equals("instancemanager"))
  662. {
  663. _print.print("Reloading instance managers... ");
  664. Manager.reloadAll();
  665. _print.print("done\n");
  666. }
  667. else if(type.equals("zone"))
  668. {
  669. _print.print("Reloading zone tables... ");
  670. //TODO: ZONETODO reload zones using telnet ZoneManager.getInstance().reload();
  671. _print.print("done\n");
  672. }
  673. else if(type.equals("teleports"))
  674. {
  675. _print.print("Reloading telport location table... ");
  676. TeleportLocationTable.getInstance().reloadAll();
  677. _print.print("done\n");
  678. }
  679. else if(type.equals("spawns"))
  680. {
  681. _print.print("Reloading spawns... ");
  682. RaidBossSpawnManager.getInstance().cleanUp();
  683. DayNightSpawnManager.getInstance().cleanUp();
  684. L2World.getInstance().deleteVisibleNpcSpawns();
  685. NpcTable.getInstance().reloadAllNpc();
  686. SpawnTable.getInstance().reloadAll();
  687. RaidBossSpawnManager.getInstance().reloadBosses();
  688. _print.print("done\n");
  689. }
  690. }
  691. catch(Exception e){}
  692. }
  693. else if (_usrCommand.startsWith("gamestat"))
  694. {
  695. StringTokenizer st = new StringTokenizer(_usrCommand.substring(9));
  696. try
  697. {
  698. String type = st.nextToken();
  699. // name;type;x;y;itemId:enchant:price...
  700. if(type.equals("privatestore"))
  701. {
  702. for(L2PcInstance player : L2World.getInstance().getAllPlayers())
  703. {
  704. if(player.getPrivateStoreType() == 0)
  705. continue;
  706. TradeList list = null;
  707. String content = "";
  708. if(player.getPrivateStoreType() == 1) // sell
  709. {
  710. list = player.getSellList();
  711. for(TradeItem item : list.getItems())
  712. {
  713. content += item.getItem().getItemId()+":"+item.getEnchant()+":"+item.getPrice()+":";
  714. }
  715. content = player.getName()+";"+"sell;"+player.getX()+";"+player.getY()+";"+content;
  716. _print.println(content);
  717. continue;
  718. }
  719. else if(player.getPrivateStoreType() == 3) // buy
  720. {
  721. list = player.getBuyList();
  722. for(TradeItem item : list.getItems())
  723. {
  724. content += item.getItem().getItemId()+":"+item.getEnchant()+":"+item.getPrice()+":";
  725. }
  726. content = player.getName()+";"+"buy;"+player.getX()+";"+player.getY()+";"+content;
  727. _print.println(content);
  728. continue;
  729. }
  730. }
  731. }
  732. }
  733. catch(Exception e){}
  734. }
  735. else if (_usrCommand.startsWith("extreload")) {
  736. String[] args = _usrCommand.split("\\s+");
  737. if (args.length > 1) {
  738. for (int i = 1; i < args.length; i++)
  739. DynamicExtension.getInstance().reload(args[i]);
  740. } else {
  741. DynamicExtension.getInstance().reload();
  742. }
  743. }
  744. else if (_usrCommand.startsWith("extinit")) {
  745. String[] args = _usrCommand.split("\\s+");
  746. if (args.length > 1) {
  747. for (int i = 1; i < args.length; i++)
  748. _print.print(DynamicExtension.getInstance().initExtension(args[i]) + "\r\n");
  749. } else {
  750. _print.print(DynamicExtension.getInstance().initExtensions());
  751. }
  752. }
  753. else if (_usrCommand.startsWith("extunload")) {
  754. String[] args = _usrCommand.split("\\s+");
  755. if (args.length > 1) {
  756. for (int i = 1; i < args.length; i++)
  757. _print.print(DynamicExtension.getInstance().unloadExtension(args[i]) + "\r\n");
  758. } else {
  759. _print.print(DynamicExtension.getInstance().unloadExtensions());
  760. }
  761. }
  762. else if (_usrCommand.startsWith("extlist")) {
  763. for (String e : DynamicExtension.getInstance().getExtensions())
  764. _print.print(e + "\r\n");
  765. }
  766. else if (_usrCommand.startsWith("get")) {
  767. Object o = null;
  768. try {
  769. String[] args = _usrCommand.substring(3).split("\\s+");
  770. if (args.length == 1)
  771. o = DynamicExtension.getInstance().get(args[0], null);
  772. else
  773. o = DynamicExtension.getInstance().get(args[0], args[1]);
  774. } catch (Exception ex) {
  775. _print.print(ex.toString() + "\r\n");
  776. }
  777. if (o != null)
  778. _print.print(o.toString() + "\r\n");
  779. }
  780. else if (_usrCommand.length() > 0) {
  781. try {
  782. String[] args = _usrCommand.split("\\s+");
  783. if (args.length == 1)
  784. DynamicExtension.getInstance().set(args[0], null, null);
  785. else if (args.length == 2)
  786. DynamicExtension.getInstance().set(args[0], null, args[1]);
  787. else
  788. DynamicExtension.getInstance().set(args[0], args[1], args[2]);
  789. } catch (Exception ex) {
  790. _print.print(ex.toString());
  791. }
  792. }
  793. else if (_usrCommand.length() == 0) { /* Do Nothing Again - Same reason as the quit part */ }
  794. _print.print("");
  795. _print.flush();
  796. }
  797. if(!_cSocket.isClosed())
  798. {
  799. _print.println("Bye Bye!");
  800. _print.flush();
  801. _cSocket.close();
  802. }
  803. telnetOutput(1, "Connection from "+_cSocket.getInetAddress().getHostAddress()+" was closed by client.");
  804. }
  805. catch (IOException e)
  806. {
  807. e.printStackTrace();
  808. }
  809. }
  810. private boolean setEnchant(L2PcInstance activeChar, int ench, int armorType)
  811. {
  812. // get the target
  813. L2Object target = activeChar;
  814. L2PcInstance player = null;
  815. if (target instanceof L2PcInstance)
  816. {
  817. player = (L2PcInstance) target;
  818. }
  819. else
  820. {
  821. activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
  822. return false;
  823. }
  824. // now we need to find the equipped weapon of the targeted character...
  825. int curEnchant = 0; // display purposes only
  826. L2ItemInstance itemInstance = null;
  827. // only attempt to enchant if there is a weapon equipped
  828. L2ItemInstance parmorInstance = player.getInventory().getPaperdollItem(armorType);
  829. if (parmorInstance != null && parmorInstance.getLocationSlot() == armorType)
  830. {
  831. itemInstance = parmorInstance;
  832. } else
  833. {
  834. // for bows/crossbows and double handed weapons
  835. parmorInstance = player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_LRHAND);
  836. if (parmorInstance != null && parmorInstance.getLocationSlot() == Inventory.PAPERDOLL_LRHAND)
  837. itemInstance = parmorInstance;
  838. }
  839. if (itemInstance != null)
  840. {
  841. curEnchant = itemInstance.getEnchantLevel();
  842. // set enchant value
  843. player.getInventory().unEquipItemInSlotAndRecord(armorType);
  844. itemInstance.setEnchantLevel(ench);
  845. player.getInventory().equipItemAndRecord(itemInstance);
  846. // send packets
  847. InventoryUpdate iu = new InventoryUpdate();
  848. iu.addModifiedItem(itemInstance);
  849. player.sendPacket(iu);
  850. player.broadcastPacket(new CharInfo(player));
  851. player.sendPacket(new UserInfo(player));
  852. // informations
  853. activeChar.sendMessage("Changed enchantment of " + player.getName() + "'s "
  854. + itemInstance.getItem().getName() + " from " + curEnchant + " to " + ench + ".");
  855. player.sendMessage("Admin has changed the enchantment of your "
  856. + itemInstance.getItem().getName() + " from " + curEnchant + " to " + ench + ".");
  857. // log
  858. GMAudit.auditGMAction("TelnetAdministrator", "enchant", player.getName(), itemInstance.getItem().getName() + "(" + itemInstance.getObjectId() + ")" + " from " + curEnchant + " to " + ench);
  859. return true;
  860. }
  861. return false;
  862. }
  863. private void jailOfflinePlayer(String name, int delay)
  864. {
  865. Connection con = null;
  866. try
  867. {
  868. con = L2DatabaseFactory.getInstance().getConnection();
  869. PreparedStatement statement = con.prepareStatement("UPDATE characters SET x=?, y=?, z=?, in_jail=?, jail_timer=? WHERE char_name=?");
  870. statement.setInt(1, -114356);
  871. statement.setInt(2, -249645);
  872. statement.setInt(3, -2984);
  873. statement.setInt(4, 1);
  874. statement.setLong(5, delay * 60000L);
  875. statement.setString(6, name);
  876. statement.execute();
  877. int count = statement.getUpdateCount();
  878. statement.close();
  879. if (count == 0)
  880. _print.println("Character not found!");
  881. else
  882. _print.println("Character "+name+" jailed for "+(delay>0 ? delay+" minutes." : "ever!"));
  883. } catch (SQLException se)
  884. {
  885. _print.println("SQLException while jailing player");
  886. if (Config.DEBUG) se.printStackTrace();
  887. } finally
  888. {
  889. try { con.close(); } catch (Exception e) {}
  890. }
  891. }
  892. private void unjailOfflinePlayer(String name)
  893. {
  894. Connection con = null;
  895. try
  896. {
  897. con = L2DatabaseFactory.getInstance().getConnection();
  898. PreparedStatement statement = con.prepareStatement("UPDATE characters SET x=?, y=?, z=?, in_jail=?, jail_timer=? WHERE char_name=?");
  899. statement.setInt(1, 17836);
  900. statement.setInt(2, 170178);
  901. statement.setInt(3, -3507);
  902. statement.setInt(4, 0);
  903. statement.setLong(5, 0);
  904. statement.setString(6, name);
  905. statement.execute();
  906. int count = statement.getUpdateCount();
  907. statement.close();
  908. if (count == 0)
  909. _print.println("Character not found!");
  910. else
  911. _print.println("Character "+name+" set free.");
  912. } catch (SQLException se)
  913. {
  914. _print.println("SQLException while jailing player");
  915. if (Config.DEBUG) se.printStackTrace();
  916. } finally
  917. {
  918. try { con.close(); } catch (Exception e) {}
  919. }
  920. }
  921. private int getOnlineGMS()
  922. {
  923. return GmListTable.getInstance().getAllGms(true).size();
  924. }
  925. private String getUptime(int time)
  926. {
  927. int uptime = (int)System.currentTimeMillis() - time;
  928. uptime = uptime / 1000;
  929. int h = uptime / 3600;
  930. int m = (uptime-(h*3600))/60;
  931. int s = ((uptime-(h*3600))-(m*60));
  932. return h + "hrs " + m + "mins " + s + "secs";
  933. }
  934. private String gameTime()
  935. {
  936. int t = GameTimeController.getInstance().getGameTime();
  937. int h = t/60;
  938. int m = t%60;
  939. SimpleDateFormat format = new SimpleDateFormat("H:mm");
  940. Calendar cal = Calendar.getInstance();
  941. cal.set(Calendar.HOUR_OF_DAY, h);
  942. cal.set(Calendar.MINUTE, m);
  943. return format.format(cal.getTime());
  944. }
  945. @SuppressWarnings("deprecation")
  946. public String getServerStatus()
  947. {
  948. int playerCount = 0, objectCount = 0;
  949. int max = LoginServerThread.getInstance().getMaxPlayer();
  950. playerCount = L2World.getInstance().getAllPlayersCount();
  951. objectCount = L2World.getInstance().getAllVisibleObjectsCount();
  952. int itemCount=0;
  953. int itemVoidCount=0;
  954. int monsterCount=0;
  955. int minionCount = 0;
  956. int minionsGroupCount = 0;
  957. int npcCount=0;
  958. int charCount=0;
  959. int pcCount=0;
  960. int doorCount=0;
  961. int summonCount=0;
  962. int AICount=0;
  963. for (L2Object obj : L2World.getInstance().getAllVisibleObjects())
  964. {
  965. if(obj == null)
  966. continue;
  967. if (obj instanceof L2Character)
  968. if (((L2Character)obj).hasAI())
  969. AICount++;
  970. if (obj instanceof L2ItemInstance)
  971. if (((L2ItemInstance)obj).getLocation() == L2ItemInstance.ItemLocation.VOID)
  972. itemVoidCount++;
  973. else
  974. itemCount++;
  975. else if (obj instanceof L2MonsterInstance)
  976. {
  977. monsterCount++;
  978. minionCount += ((L2MonsterInstance)obj).getTotalSpawnedMinionsInstances();
  979. minionsGroupCount += ((L2MonsterInstance)obj).getTotalSpawnedMinionsGroups();
  980. }
  981. else if (obj instanceof L2NpcInstance)
  982. npcCount++;
  983. else if (obj instanceof L2PcInstance)
  984. pcCount++;
  985. else if (obj instanceof L2Summon)
  986. summonCount++;
  987. else if (obj instanceof L2DoorInstance)
  988. doorCount++;
  989. else if (obj instanceof L2Character)
  990. charCount++;
  991. }
  992. StringBuilder sb = new StringBuilder();
  993. sb.append("Server Status: ");
  994. sb.append("\r\n ---> Player Count: " + playerCount + "/" + max);
  995. sb.append("\r\n +--> Object Count: " + objectCount);
  996. sb.append("\r\n +--> AI Count: " + AICount);
  997. sb.append("\r\n +.... L2Item(Void): " + itemVoidCount);
  998. sb.append("\r\n +.......... L2Item: " + itemCount);
  999. sb.append("\r\n +....... L2Monster: " + monsterCount);
  1000. sb.append("\r\n +......... Minions: " + minionCount);
  1001. sb.append("\r\n +.. Minions Groups: " + minionsGroupCount);
  1002. sb.append("\r\n +........... L2Npc: " + npcCount);
  1003. sb.append("\r\n +............ L2Pc: " + pcCount);
  1004. sb.append("\r\n +........ L2Summon: " + summonCount);
  1005. sb.append("\r\n +.......... L2Door: " + doorCount);
  1006. sb.append("\r\n +.......... L2Char: " + charCount);
  1007. sb.append("\r\n ---> Ingame Time: " + gameTime());
  1008. sb.append("\r\n ---> Server Uptime: " + getUptime(_uptime));
  1009. sb.append("\r\n ---> GM Count: " + getOnlineGMS());
  1010. sb.append("\r\n ---> Threads: " + Thread.activeCount());
  1011. sb.append("\r\n RAM Used: "+((Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory())/1048576)); // 1024 * 1024 = 1048576
  1012. sb.append("\r\n");
  1013. return sb.toString();
  1014. }
  1015. public void debugAll() throws IOException
  1016. {
  1017. Calendar cal = Calendar.getInstance();
  1018. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
  1019. StringBuilder sb = new StringBuilder();
  1020. sb.append(sdf.format(cal.getTime()));
  1021. sb.append("\n\nL2J Server Version: "+Config.SERVER_VERSION);
  1022. sb.append("\nDP Revision: "+Config.DATAPACK_VERSION);
  1023. sb.append("\n\n");
  1024. sb.append(this.getServerStatus());
  1025. sb.append("\n\n");
  1026. sb.append("\n## Java Platform Information ##");
  1027. sb.append("\nJava Runtime Name: "+System.getProperty("java.runtime.name"));
  1028. sb.append("\nJava Version: "+System.getProperty("java.version"));
  1029. sb.append("\nJava Class Version: "+System.getProperty("java.class.version"));
  1030. sb.append('\n');
  1031. sb.append("\n## Virtual Machine Information ##");
  1032. sb.append("\nVM Name: "+System.getProperty("java.vm.name"));
  1033. sb.append("\nVM Version: "+System.getProperty("java.vm.version"));
  1034. sb.append("\nVM Vendor: "+System.getProperty("java.vm.vendor"));
  1035. sb.append("\nVM Info: "+System.getProperty("java.vm.info"));
  1036. sb.append('\n');
  1037. sb.append("\n## OS Information ##");
  1038. sb.append("\nName: "+System.getProperty("os.name"));
  1039. sb.append("\nArchiteture: "+System.getProperty("os.arch"));
  1040. sb.append("\nVersion: "+System.getProperty("os.version"));
  1041. sb.append('\n');
  1042. sb.append("\n## Runtime Information ##");
  1043. sb.append("\nCPU Count: "+Runtime.getRuntime().availableProcessors());
  1044. sb.append("\nCurrent Free Heap Size: "+(Runtime.getRuntime().freeMemory() / 1024 / 1024)+" mb");
  1045. sb.append("\nCurrent Heap Size: "+(Runtime.getRuntime().totalMemory() / 1024 / 1024)+" mb");
  1046. sb.append("\nMaximum Heap Size: "+(Runtime.getRuntime().maxMemory() / 1024 / 1024)+" mb");
  1047. sb.append('\n');
  1048. sb.append("\n## Class Path Information ##\n");
  1049. String cp = System.getProperty("java.class.path");
  1050. String[] libs = cp.split(File.pathSeparator);
  1051. for (String lib : libs)
  1052. {
  1053. sb.append(lib);
  1054. sb.append('\n');
  1055. }
  1056. sb.append('\n');
  1057. sb.append("## Threads Information ##\n");
  1058. Map<Thread, StackTraceElement[]> allThread = Thread.getAllStackTraces();
  1059. for (Entry<Thread, StackTraceElement[]> entry : allThread.entrySet())
  1060. {
  1061. StackTraceElement[] stes = entry.getValue();
  1062. Thread t = entry.getKey();
  1063. sb.append("--------------\n");
  1064. sb.append(t.toString()+" ("+t.getId()+")\n");
  1065. sb.append("State: "+t.getState()+'\n');
  1066. sb.append("isAlive: "+t.isAlive()+" | isDaemon: "+t.isDaemon()+" | isInterrupted: "+t.isInterrupted()+'\n');
  1067. sb.append('\n');
  1068. for (StackTraceElement ste : stes)
  1069. {
  1070. sb.append(ste.toString());
  1071. sb.append('\n');
  1072. }
  1073. sb.append('\n');
  1074. }
  1075. sb.append("\n\n## Thread Pool Manager Statistics ##\n");
  1076. for (String line : ThreadPoolManager.getInstance().getStats())
  1077. {
  1078. sb.append(line);
  1079. sb.append('\n');
  1080. }
  1081. int i = 0;
  1082. File f = new File("./log/Debug-"+i+".txt");
  1083. while(f.exists())
  1084. {
  1085. i++;
  1086. f = new File("./log/Debug-"+i+".txt");
  1087. }
  1088. f.getParentFile().mkdirs();
  1089. FileOutputStream fos = new FileOutputStream(f);
  1090. OutputStreamWriter out = new OutputStreamWriter(fos, "UTF-8");
  1091. out.write(sb.toString());
  1092. out.flush();
  1093. out.close();
  1094. fos.close();
  1095. _print.println("Debug output saved to log/"+f.getName());
  1096. _print.flush();
  1097. }
  1098. }