Advertisement
horato

ClanSearcher

Sep 18th, 2011
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.92 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P L2J_Server_BETA
  3. Index: java/com/l2jserver/gameserver/network/serverpackets/NpcHtmlMessage.java
  4. ===================================================================
  5. --- java/com/l2jserver/gameserver/network/serverpackets/NpcHtmlMessage.java (revision 4769)
  6. +++ java/com/l2jserver/gameserver/network/serverpackets/NpcHtmlMessage.java (working copy)
  7. @@ -236,6 +236,11 @@
  8. }
  9. }
  10.  
  11. + public String getHTML()
  12. + {
  13. + return _html;
  14. + }
  15. +
  16. @Override
  17. protected final void writeImpl()
  18. {
  19. #P L2J_DataPack_BETA
  20. Index: data/scripts/custom/ClanSearcher/ClanSearcher.java
  21. ===================================================================
  22. --- data/scripts/custom/ClanSearcher/ClanSearcher.java (revision 0)
  23. +++ data/scripts/custom/ClanSearcher/ClanSearcher.java (revision 0)
  24. @@ -0,0 +1,379 @@
  25. +/*
  26. + * This program is free software: you can redistribute it and/or modify it under
  27. + * the terms of the GNU General Public License as published by the Free Software
  28. + * Foundation, either version 3 of the License, or (at your option) any later
  29. + * version.
  30. + *
  31. + * This program is distributed in the hope that it will be useful, but WITHOUT
  32. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  33. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  34. + * details.
  35. + *
  36. + * You should have received a copy of the GNU General Public License along with
  37. + * this program. If not, see <http://www.gnu.org/licenses/>.
  38. + */
  39. +package custom.ClanSearcher;
  40. +
  41. +import java.sql.Connection;
  42. +import java.sql.PreparedStatement;
  43. +import java.sql.ResultSet;
  44. +import java.sql.SQLException;
  45. +import java.util.List;
  46. +import java.util.Map;
  47. +
  48. +import javolution.util.FastList;
  49. +import javolution.util.FastMap;
  50. +
  51. +import com.l2jserver.L2DatabaseFactory;
  52. +import com.l2jserver.gameserver.datatables.ClanTable;
  53. +import com.l2jserver.gameserver.instancemanager.QuestManager;
  54. +import com.l2jserver.gameserver.model.L2Clan;
  55. +import com.l2jserver.gameserver.model.L2ClanMember;
  56. +import com.l2jserver.gameserver.model.actor.L2Npc;
  57. +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  58. +import com.l2jserver.gameserver.model.quest.Quest;
  59. +import com.l2jserver.gameserver.model.quest.QuestState;
  60. +import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
  61. +import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  62. +import com.l2jserver.gameserver.network.serverpackets.ShowBoard;
  63. +
  64. +/*
  65. + * @author Horato
  66. + */
  67. +public class ClanSearcher extends Quest
  68. +{
  69. + private static final int NpcId = 152036;
  70. +
  71. + public ClanSearcher(int questId, String name, String descr)
  72. + {
  73. + super(questId, name, descr);
  74. + addFirstTalkId(NpcId);
  75. + addTalkId(NpcId);
  76. + addStartNpc(NpcId);
  77. + }
  78. +
  79. + @Override
  80. + public String onTalk(L2Npc npc, L2PcInstance player)
  81. + {
  82. + talk(npc, player);
  83. + return "";
  84. + }
  85. +
  86. + @Override
  87. + public String onFirstTalk(L2Npc npc, L2PcInstance player)
  88. + {
  89. + talk(npc, player);
  90. + return "";
  91. + }
  92. +
  93. + @Override
  94. + public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  95. + {
  96. + if (event.startsWith("show_list"))
  97. + {
  98. + loadClansAndShowWindow(npc, player, 1);
  99. + }
  100. + else if (event.startsWith("add"))
  101. + {
  102. + saveClanPresentation(event, npc, player);
  103. + }
  104. + else if (event.startsWith("moreinfo_"))
  105. + {
  106. + showMoreClanInfo(event, npc, player);
  107. + }
  108. + else if (event.startsWith("requestjoin_"))
  109. + {
  110. + sendClanJoinRequest(event, npc, player);
  111. + }
  112. + else if (event.startsWith("remove"))
  113. + {
  114. + removeClanPresentation(npc, player);
  115. + }
  116. + else if (event.startsWith("newclan.htm"))
  117. + {
  118. + NpcHtmlMessage html = new NpcHtmlMessage(npc.getObjectId());
  119. + html.setFile(player.getHtmlPrefix(), "data/scripts/custom/ClanSearcher/newclan.htm");
  120. + html.replace("%clanname%", player.getClan().getName());
  121. + html.replace("%clanlevel%", "" + player.getClan().getLevel());
  122. + html.replace("%clanleader%", player.getClan().getLeaderName());
  123. +
  124. + sendCBHtml(player, html.getHTML(), loadClansAndShowWindow(npc, player, 2));
  125. + }
  126. + else if (event.startsWith("deleteclan.htm"))
  127. + {
  128. + NpcHtmlMessage html = new NpcHtmlMessage(npc.getObjectId());
  129. + html.setFile(player.getHtmlPrefix(), "data/scripts/custom/ClanSearcher/deleteclan.htm");
  130. + sendCBHtml(player, html.getHTML());
  131. + }
  132. + return "";
  133. + }
  134. +
  135. + private void removeClanPresentation(L2Npc npc, L2PcInstance player)
  136. + {
  137. + Connection con = null;
  138. + try
  139. + {
  140. + con = L2DatabaseFactory.getInstance().getConnection();
  141. + PreparedStatement statement = con.prepareStatement("DELETE FROM clan_search WHERE clanId=?");
  142. + statement.setInt(1, player.getClanId());
  143. + statement.execute();
  144. + sendCBHtml(player, "<html><body><br>&nbsp;Your presentation has been deleted.</body></html>");
  145. + statement.close();
  146. + }
  147. + catch (SQLException e)
  148. + {
  149. + e.printStackTrace();
  150. + }
  151. + finally
  152. + {
  153. + L2DatabaseFactory.close(con);
  154. + }
  155. + }
  156. +
  157. + private void sendClanJoinRequest(String event, L2Npc npc, L2PcInstance requester)
  158. + {
  159. + L2Clan clan = ClanTable.getInstance().getClan(Integer.parseInt(event.split("_")[1]));
  160. + String text = "Player " + requester.getName() + " requested to join your clan. If you agree type .claninvite " + requester.getName() + " <subpledgeName>";
  161. + int success = 0;
  162. + for (L2ClanMember member : clan.getMembers())
  163. + {
  164. + if (member.getPlayerInstance() == null && !member.isOnline())
  165. + continue;
  166. + L2PcInstance player = member.getPlayerInstance();
  167. +
  168. + if ((player.getClanPrivileges() & L2Clan.CP_CL_JOIN_CLAN) == L2Clan.CP_CL_JOIN_CLAN)
  169. + {
  170. + player.sendPacket(new CreatureSay(player.getObjectId(), 2, player.getName(), text));
  171. + success++;
  172. + }
  173. + }
  174. + if (success > 0)
  175. + sendCBHtml(requester, "<html><body><br>&nbsp;Your request was successfully send.</body></html>");
  176. + else
  177. + sendCBHtml(requester, "<html><body><br>&nbsp;Nobody was able to see your request, try it again later.</body></html>");
  178. + }
  179. +
  180. + private void showMoreClanInfo(String event, L2Npc npc, L2PcInstance player)
  181. + {
  182. + Connection con = null;
  183. + StringBuilder sb = new StringBuilder();
  184. + try
  185. + {
  186. + con = L2DatabaseFactory.getInstance().getConnection();
  187. + PreparedStatement statement = con.prepareStatement("SELECT * FROM clan_search WHERE clanId=?");
  188. + statement.setInt(1, Integer.parseInt(event.split("_")[1]));
  189. + final ResultSet set = statement.executeQuery();
  190. +
  191. + if (set.next())
  192. + {
  193. + L2Clan clan = ClanTable.getInstance().getClan(set.getInt("clanId"));
  194. + String message = set.getString("message");
  195. + sb.append("<html><body><br><table border=\"0\" width=\"280\">");
  196. + sb.append("<tr><td width=\"93\">Clan Name</td><td width=\"93\">Clan Level</td><td width=\"94\">Clan Leader</td></tr>");
  197. + sb.append("<tr><td>" + clan.getName() + "</td><td>" + clan.getLevel() + "</td><td>" + clan.getLeaderName() + "</td></tr></table>");
  198. + sb.append("<br>&nbsp;" + message + "<br><br>");
  199. + sb.append("&nbsp;<a action=\"bypass -h Quest ClanSearcher requestjoin_" + clan.getClanId() + "\">Send invitation request</a>");
  200. + sb.append("</body></html>");
  201. + sendCBHtml(player, sb.toString());
  202. + }
  203. + statement.close();
  204. + set.close();
  205. + }
  206. + catch (SQLException e)
  207. + {
  208. + e.printStackTrace();
  209. + }
  210. + finally
  211. + {
  212. + L2DatabaseFactory.close(con);
  213. + }
  214. + }
  215. +
  216. + private void saveClanPresentation(String event, L2Npc npc, L2PcInstance player)
  217. + {
  218. + if (event.length() < 5)
  219. + return;
  220. + Connection con = null;
  221. + String message = null;
  222. + try
  223. + {
  224. + con = L2DatabaseFactory.getInstance().getConnection();
  225. + PreparedStatement statement = con.prepareStatement("INSERT INTO clan_search (clanId,message) values (?,?) ON DUPLICATE KEY UPDATE clanId=?,message=?");
  226. + message = event.substring(4);
  227. + message = message.replaceAll("\n", "<br>");
  228. + statement.setInt(1, player.getClanId());
  229. + statement.setString(2, message);
  230. + statement.setInt(3, player.getClanId());
  231. + statement.setString(4, message);
  232. + statement.execute();
  233. + statement.close();
  234. + sendCBHtml(player, "<html><body><br>&nbsp;Your presentation has been saved.</body></html>");
  235. + }
  236. + catch (SQLException e)
  237. + {
  238. + e.printStackTrace();
  239. + }
  240. + finally
  241. + {
  242. + L2DatabaseFactory.close(con);
  243. + }
  244. + }
  245. +
  246. + private String loadClansAndShowWindow(L2Npc npc, L2PcInstance player, int mode)
  247. + {
  248. + Connection con = null;
  249. + StringBuilder sb = new StringBuilder();
  250. + try
  251. + {
  252. + L2Clan clan = null;
  253. + Map<L2Clan, String> clans = new FastMap<L2Clan, String>();
  254. + con = L2DatabaseFactory.getInstance().getConnection();
  255. + final ResultSet set = con.prepareStatement("SELECT * FROM clan_search ORDER BY clanId").executeQuery();
  256. + while (set.next())
  257. + {
  258. + clan = ClanTable.getInstance().getClan(set.getInt("clanId"));
  259. + if (clan == null)
  260. + continue;
  261. + clans.put(clan, set.getString("message"));
  262. + }
  263. + set.close();
  264. + if (mode == 2)
  265. + {
  266. + return clans.get(player.getClan());
  267. + }
  268. + sb.append("<html><body><br><table border=\"0\" width=\"280\">");
  269. + sb.append("<tr><td width=\"70\">Clan Name</td><td width=\"70\">Clan Level</td><td width=\"70\">Clan Leader</td><td width=\"70\"> </td></tr>");
  270. + for (Map.Entry<L2Clan, String> entry : clans.entrySet())
  271. + {
  272. + if (entry.getKey() == null)
  273. + continue;
  274. + sb.append("<tr><td>" + entry.getKey().getName() + "</td><td>" + entry.getKey().getLevel() + "</td><td>" + entry.getKey().getLeaderName() + "</td><td><a action=\"bypass -h Quest ClanSearcher moreinfo_" + entry.getKey().getClanId() + "\">More Info</a></td></tr>");
  275. + }
  276. + sb.append("</table></body></html>");
  277. + sendCBHtml(player, sb.toString());
  278. + }
  279. + catch (SQLException e)
  280. + {
  281. + e.printStackTrace();
  282. + }
  283. + finally
  284. + {
  285. + L2DatabaseFactory.close(con);
  286. + }
  287. + return "";
  288. + }
  289. +
  290. + private void talk(L2Npc npc, L2PcInstance player)
  291. + {
  292. + if (npc.getNpcId() == NpcId)
  293. + {
  294. + QuestState qs = player.getQuestState("ClanSearcher");
  295. + if (qs == null)
  296. + QuestManager.getInstance().getQuest("ClanSearcher").newQuestState(player);
  297. +
  298. + NpcHtmlMessage html = new NpcHtmlMessage(npc.getObjectId());
  299. + html.setFile(player.getHtmlPrefix(), "data/scripts/custom/ClanSearcher/1.htm");
  300. + html.replace("%player%", player.getName());
  301. +
  302. + if (player.getClan() == null)
  303. + html.replace("%text%", "Iam here to help you find a clan. Good luck!");
  304. + else if (player.isClanLeader())
  305. + html.replace("%text%", "Do you wish to present your clan?");
  306. + else
  307. + html.replace("%text%", "Do you want see your concurence?");
  308. +
  309. + if (player.isClanLeader())
  310. + {
  311. + html.replace("%add%", "<a action=\"bypass -h Quest ClanSearcher newclan.htm\">Add/Change clan presentation</a>");
  312. + html.replace("%remove%", "<a action=\"bypass -h Quest ClanSearcher deleteclan.htm\">Remove clan presentation</a>");
  313. + }
  314. + else
  315. + {
  316. + html.replace("%add%", "");
  317. + html.replace("%remove%", "");
  318. + }
  319. + sendCBHtml(player, html.getHTML());
  320. + }
  321. + }
  322. +
  323. + private final void sendCBHtml(L2PcInstance activeChar, String html)
  324. + {
  325. + sendCBHtml(activeChar, html, "");
  326. + }
  327. +
  328. + private final void sendCBHtml(L2PcInstance activeChar, String html, String fillMultiEdit)
  329. + {
  330. + if (activeChar == null)
  331. + return;
  332. +
  333. + if (html != null)
  334. + {
  335. + activeChar.clearBypass();
  336. + int len = html.length();
  337. + for (int i = 0; i < len; i++)
  338. + {
  339. + int start = html.indexOf("\"bypass ", i);
  340. + int finish = html.indexOf("\"", start + 1);
  341. + if (start < 0 || finish < 0)
  342. + break;
  343. +
  344. + if (html.substring(start + 8, start + 10).equals("-h"))
  345. + start += 11;
  346. + else
  347. + start += 8;
  348. +
  349. + i = finish;
  350. + int finish2 = html.indexOf("$", start);
  351. + if (finish2 < finish && finish2 > 0)
  352. + activeChar.addBypass2(html.substring(start, finish2).trim());
  353. + else
  354. + activeChar.addBypass(html.substring(start, finish).trim());
  355. + }
  356. + }
  357. +
  358. + if (fillMultiEdit != null)
  359. + {
  360. + activeChar.sendPacket(new ShowBoard(html, "1001"));
  361. + fillMultiEditContent(activeChar, fillMultiEdit);
  362. + }
  363. + else
  364. + {
  365. + activeChar.sendPacket(new ShowBoard(null, "101"));
  366. + activeChar.sendPacket(new ShowBoard(html, "101"));
  367. + activeChar.sendPacket(new ShowBoard(null, "102"));
  368. + activeChar.sendPacket(new ShowBoard(null, "103"));
  369. + }
  370. + }
  371. +
  372. + /**
  373. + *
  374. + * Must send after sendCBHtml
  375. + */
  376. + private void fillMultiEditContent(L2PcInstance activeChar, String text)
  377. + {
  378. + List<String> _arg = new FastList<String>();
  379. + _arg.add("0");
  380. + _arg.add("0");
  381. + _arg.add("0");
  382. + _arg.add("0");
  383. + _arg.add("0");
  384. + _arg.add("0");
  385. + _arg.add(activeChar.getName());
  386. + _arg.add(Integer.toString(activeChar.getObjectId()));
  387. + _arg.add(activeChar.getAccountName());
  388. + _arg.add("9");
  389. + _arg.add(" ");
  390. + _arg.add(" ");
  391. + _arg.add(text);
  392. + _arg.add("0");
  393. + _arg.add("0");
  394. + _arg.add("0");
  395. + _arg.add("0");
  396. + activeChar.sendPacket(new ShowBoard(_arg));
  397. + }
  398. +
  399. + public static void main(String[] args)
  400. + {
  401. + new ClanSearcher(-1, "ClanSearcher", "custom");
  402. + }
  403. +}
  404. Index: data/scripts/custom/ClanSearcher/newclan.htm
  405. ===================================================================
  406. --- data/scripts/custom/ClanSearcher/newclan.htm (revision 0)
  407. +++ data/scripts/custom/ClanSearcher/newclan.htm (revision 0)
  408. @@ -0,0 +1,12 @@
  409. +<html>
  410. +<body><br>
  411. +<table border="0" width="280">
  412. +<tr><td width="93">Clan Name</td><td width="93">Clan Level</td><td width="93">Clan Leader</td></tr>
  413. +<tr><td width="93">%clanname%</td><td width="93">%clanlevel%</td><td width="93">%clanleader%</td></tr>
  414. +</table><br>
  415. +&nbsp;Add some info about your clan:
  416. +&nbsp;<multiedit var="msg" width=150 height=150><br>
  417. +&nbsp;If you dont want add any info, put None.
  418. +<button value="Submit" action="bypass -h Quest ClanSearcher add $msg" width=160 height=25 back="L2UI_ct1.button_df" fore="L2UI_ct1.button_df">
  419. +</body>
  420. +</html>
  421. \ No newline at end of file
  422. Index: data/scripts/custom/ClanSearcher/1.htm
  423. ===================================================================
  424. --- data/scripts/custom/ClanSearcher/1.htm (revision 0)
  425. +++ data/scripts/custom/ClanSearcher/1.htm (revision 0)
  426. @@ -0,0 +1,10 @@
  427. +<html><body><br>
  428. +<table border="0">
  429. +<tr><td height="30">Clan presenter:</td></tr>
  430. +<tr><td>Hello %player%.</td></tr>
  431. +<tr><td height="30">%text%</td></tr>
  432. +<tr><td><a action="bypass -h Quest ClanSearcher show_list">Show me the list</a></td></tr>
  433. +<tr><td>%add%</td></tr>
  434. +<tr><td>%remove%</td></tr>
  435. +</table>
  436. +</body></html>
  437. \ No newline at end of file
  438. Index: data/scripts/custom/ClanSearcher/deleteclan.htm
  439. ===================================================================
  440. --- data/scripts/custom/ClanSearcher/deleteclan.htm (revision 0)
  441. +++ data/scripts/custom/ClanSearcher/deleteclan.htm (revision 0)
  442. @@ -0,0 +1,4 @@
  443. +<html><body><br>
  444. +&nbsp;Your clan presentation will be erased. Are you sure?<br>
  445. +&nbsp;<a action="bypass -h Quest ClanSearcher remove">Remove presentation</a><br>
  446. +</body></html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement