GameStatusThread.java 51 KB

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