warc222

bu report krais

Jan 13th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.88 KB | None | 0 0
  1. And the last thing you have to do it's to create a NPC in the database, and as type set L2BugReport
  2.  
  3.  
  4. L2BugReportInstance.java
  5.  
  6.  
  7. /*
  8. * This program is free software: you can redistribute it and/or modify it under
  9. * the terms of the GNU General Public License as published by the Free Software
  10. * Foundation, either version 3 of the License, or (at your option) any later
  11. * version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  15. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU General Public License along with
  19. * this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. package com.l2jfrozen.gameserver.model.actor.instance;
  22.  
  23. import java.io.*;
  24. import java.util.StringTokenizer;
  25.  
  26. import javolution.text.TextBuilder;
  27.  
  28. import com.l2jfrozen.gameserver.ai.CtrlIntention;
  29. import com.l2jfrozen.gameserver.model.L2World;
  30. import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
  31. import com.l2jfrozen.gameserver.network.L2GameClient;
  32. import com.l2jfrozen.gameserver.network.clientpackets.Say2;
  33. import com.l2jfrozen.gameserver.network.serverpackets.ActionFailed;
  34. import com.l2jfrozen.gameserver.network.serverpackets.CreatureSay;
  35. import com.l2jfrozen.gameserver.network.serverpackets.MyTargetSelected;
  36. import com.l2jfrozen.gameserver.network.serverpackets.NpcHtmlMessage;
  37. import com.l2jfrozen.gameserver.network.serverpackets.ValidateLocation;
  38. import com.l2jfrozen.gameserver.templates.L2NpcTemplate;
  39.  
  40. /**
  41. * @author squallcs
  42. *
  43. */
  44. public class L2BugReportInstance extends L2FolkInstance
  45. {
  46. private static String _type;
  47.  
  48. public L2BugReportInstance(int objectId, L2NpcTemplate template)
  49. {
  50. super(objectId, template);
  51. }
  52.  
  53. @Override
  54. public void onBypassFeedback(L2PcInstance player, String command)
  55. {
  56. if (command.startsWith("send_report"))
  57. {
  58. StringTokenizer st = new StringTokenizer(command);
  59. st.nextToken();
  60. String msg = null;
  61. String type = null;
  62. type = st.nextToken();
  63. msg = st.nextToken();
  64. try
  65. {
  66. while (st.hasMoreTokens())
  67. {
  68. msg = msg + " " + st.nextToken();
  69. }
  70.  
  71. sendReport(player, type, msg);
  72. }
  73. catch (StringIndexOutOfBoundsException e)
  74. {
  75. }
  76. }
  77. }
  78.  
  79. static
  80. {
  81. new File("log/BugReports/").mkdirs();
  82. }
  83.  
  84. private void sendReport(L2PcInstance player, String command, String msg)
  85. {
  86. String type = command;
  87. L2GameClient info = player.getClient().getConnection().getClient();
  88.  
  89. if (type.equals("General"))
  90. _type = "General";
  91. if (type.equals("Fatal"))
  92. _type = "Fatal";
  93. if (type.equals("Misuse"))
  94. _type = "Misuse";
  95. if (type.equals("Balance"))
  96. _type = "Balance";
  97. if (type.equals("Other"))
  98. _type = "Other";
  99.  
  100. try
  101. {
  102. String fname = "log/BugReports/" + player.getName() + ".txt";
  103. File file = new File(fname);
  104. boolean exist = file.createNewFile();
  105. if (!exist)
  106. {
  107. player.sendMessage("You have already sent a bug report, GMs must check it first.");
  108. return;
  109. }
  110. FileWriter fstream = new FileWriter(fname);
  111. BufferedWriter out = new BufferedWriter(fstream);
  112. out.write("Character Info: " + info + "\r\nBug Type: " + _type + "\r\nMessage: " + msg);
  113. player.sendMessage("Report sent. GMs will check it soon. Thanks...");
  114.  
  115. for (L2PcInstance allgms : L2World.getInstance().getAllGMs())
  116. allgms.sendPacket(new CreatureSay(0, Say2.SHOUT, "Bug Report Manager", player.getName() + " sent a bug report."));
  117.  
  118. System.out.println("Character: " + player.getName() + " sent a bug report.");
  119. out.close();
  120. }
  121. catch (Exception e)
  122. {
  123. player.sendMessage("Something went wrong try again.");
  124. }
  125. }
  126.  
  127. @Override
  128. public void onAction(L2PcInstance player)
  129. {
  130. if (!canTarget(player))
  131. {
  132. return;
  133. }
  134.  
  135. if (this != player.getTarget())
  136. {
  137. player.setTarget(this);
  138.  
  139. player.sendPacket(new MyTargetSelected(getObjectId(), 0));
  140.  
  141. player.sendPacket(new ValidateLocation(this));
  142. }
  143. else if (!canInteract(player))
  144. {
  145. player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this);
  146. }
  147. else
  148. {
  149. showHtmlWindow(player);
  150. }
  151.  
  152. player.sendPacket(new ActionFailed());
  153. }
  154.  
  155. private void showHtmlWindow(L2PcInstance activeChar)
  156. {
  157. NpcHtmlMessage nhm = new NpcHtmlMessage(5);
  158. TextBuilder replyMSG = new TextBuilder("");
  159.  
  160. replyMSG.append("<html><title>Bug Report Manager</title>");
  161. replyMSG.append("<body><br><br><center>");
  162. replyMSG.append("<table border=0 height=10 bgcolor=\"444444\" width=240>");
  163. replyMSG.append("<tr><td align=center><font color=\"00FFFF\">Hello " + activeChar.getName() + ".</font></td></tr>");
  164. replyMSG.append("<tr><td align=center><font color=\"00FFFF\">There are no Gms online</font></td></tr>");
  165. replyMSG.append("<tr><td align=center><font color=\"00FFFF\">and you want to report something?</font></td></tr>");
  166. replyMSG.append("</table><br>");
  167. replyMSG.append("<img src=\"L2UI.SquareWhite\" width=280 height=1><br><br>");
  168. replyMSG.append("<table width=250><tr>");
  169. replyMSG.append("<td><font color=\"LEVEL\">Select Report Type:</font></td>");
  170. replyMSG.append("<td><combobox width=105 var=type list=General;Fatal;Misuse;Balance;Other></td>");
  171. replyMSG.append("</tr></table><br><br>");
  172. replyMSG.append("<multiedit var=\"msg\" width=250 height=50><br>");
  173. replyMSG.append("<br><img src=\"L2UI.SquareWhite\" width=280 height=1><br><br><br><br><br><br><br>");
  174. replyMSG.append("<button value=\"Send Report\" action=\"bypass -h npc_" + getObjectId() + "_send_report $type $msg\" width=204 height=20 back=\"sek.cbui75\" fore=\"sek.cbui75\">");
  175. replyMSG.append("</center></body></html>");
  176.  
  177. nhm.setHtml(replyMSG.toString());
  178. activeChar.sendPacket(nhm);
  179.  
  180. activeChar.sendPacket(new ActionFailed());
  181. }
  182.  
  183. }
Advertisement
Add Comment
Please, Sign In to add comment