· 9 years ago · Oct 06, 2016, 06:10 PM
1### Eclipse Workspace Patch 1.0
2#P L2jFrozen_DataPack
3Index: data/html/admin/senddonate.htm
4===================================================================
5--- data/html/admin/senddonate.htm (revision 0)
6+++ data/html/admin/senddonate.htm (working copy)
7@@ -0,0 +1,23 @@
8+<html><title>Donate</title><body>
9+ <center>
10+ <img src="Sek.cbui371" width=275 height=1>
11+ <table width=275 bgcolor=000000>
12+ <tr>
13+ <td width=45><button value="Main" action="bypass -h admin_admin" width=45 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
14+ <td width=180 align="center"><font color="LEVEL">Send Donate Menu</font></td>
15+ <td width=45><button value="Back" action="bypass -h admin_admin" width=45 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
16+ </tr>
17+ </table>
18+ <img src="Sek.cbui371" width=275 height=1><br>
19+ <table width=280><tr><td>First fill the player's name. Then, fill in the ID number of the Item ID to create the item you want. Then fill in the quantity of the item you want to create in item count. Finally, choose where to create the item: in the warehouse or in the inventory.</td></tr></table><br>
20+ <table width=240>
21+ <tr><td>Player Name:</td><td><edit var="playername" width=100></td></tr>
22+ <tr><td>Item ID:</td><td><edit var="itemid" width=100 type=number></td></tr>
23+ <tr><td>Item Count:</td><td><edit var="itemnum" width=100 type=number></td></tr>
24+ <tr><td>Location:</td><td><combobox width=100 height=17 var=location list=Warehouse;Inventory;></td></tr>
25+ </table>
26+ <br><br>
27+ <button value="Send Donate" action="bypass -h admin_givedonate $playername $itemid $itemnum $location" width=95 height=21 back="bigbutton_over" fore="bigbutton"><br>
28+ <table width=280><tr><td align="center"><font color="FF0000">Non-stackable items can't have amount superior to 10.</font></font></td></tr></table>
29+ </center>
30+</body></html>
31Index: sql/admin_command_access_rights.sql
32===================================================================
33--- sql/admin_command_access_rights.sql (revision 1004)
34+++ sql/admin_command_access_rights.sql (working copy)
35@@ -634,6 +634,10 @@
36 ('admin_zone_check','2'),
37 ('admin_zone_reload','2'),
38
39+-- Section: SendDonate
40+('admin_senddonate','1'),
41+('admin_givedonate','1'),
42+
43 -- Section: AIO
44 ('admin_setaio','2'),
45 ('admin_removeaio','2');
46#P L2jFrozen_GameServer
47Index: head-src/com/l2jfrozen/gameserver/handler/AdminCommandHandler.java
48===================================================================
49--- head-src/com/l2jfrozen/gameserver/handler/AdminCommandHandler.java (revision 1004)
50+++ head-src/com/l2jfrozen/gameserver/handler/AdminCommandHandler.java (working copy)
51@@ -79,6 +79,7 @@
52 import com.l2jfrozen.gameserver.handler.admincommandhandlers.AdminRes;
53 import com.l2jfrozen.gameserver.handler.admincommandhandlers.AdminRideWyvern;
54 import com.l2jfrozen.gameserver.handler.admincommandhandlers.AdminScript;
55+import com.l2jfrozen.gameserver.handler.admincommandhandlers.AdminSendDonate;
56 import com.l2jfrozen.gameserver.handler.admincommandhandlers.AdminShop;
57 import com.l2jfrozen.gameserver.handler.admincommandhandlers.AdminShutdown;
58 import com.l2jfrozen.gameserver.handler.admincommandhandlers.AdminSiege;
59@@ -186,6 +187,7 @@
60 registerAdminCommandHandler(new AdminAio());
61 registerAdminCommandHandler(new AdminCharSupervision());
62 registerAdminCommandHandler(new AdminWho()); // L2OFF command
63+ registerAdminCommandHandler(new AdminSendDonate());
64 // ATTENTION: adding new command handlers, you have to change the
65 // sql file containing the access levels rights
66
67Index: head-src/com/l2jfrozen/gameserver/handler/admincommandhandlers/AdminSendDonate.java
68===================================================================
69--- head-src/com/l2jfrozen/gameserver/handler/admincommandhandlers/AdminSendDonate.java (revision 0)
70+++ head-src/com/l2jfrozen/gameserver/handler/admincommandhandlers/AdminSendDonate.java (working copy)
71@@ -0,0 +1,246 @@
72+/*
73+ * This program is free software: you can redistribute it and/or modify it under
74+ * the terms of the GNU General Public License as published by the Free Software
75+ * Foundation, either version 3 of the License, or (at your option) any later
76+ * version.
77+ *
78+ * This program is distributed in the hope that it will be useful, but WITHOUT
79+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
80+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
81+ * details.
82+ *
83+ * You should have received a copy of the GNU General Public License along with
84+ * this program. If not, see <http://www.gnu.org/licenses/>.
85+ */
86+package com.l2jfrozen.gameserver.handler.admincommandhandlers;
87+
88+import java.sql.Connection;
89+import java.sql.PreparedStatement;
90+import java.sql.ResultSet;
91+import java.sql.SQLException;
92+import java.util.StringTokenizer;
93+import java.util.logging.Level;
94+import java.util.logging.Logger;
95+
96+import com.l2jfrozen.Config;
97+import com.l2jfrozen.gameserver.datatables.sql.ItemTable;
98+import com.l2jfrozen.gameserver.handler.IAdminCommandHandler;
99+import com.l2jfrozen.gameserver.idfactory.IdFactory;
100+import com.l2jfrozen.gameserver.model.L2World;
101+import com.l2jfrozen.gameserver.model.actor.instance.L2ItemInstance.ItemLocation;
102+import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
103+import com.l2jfrozen.gameserver.network.SystemMessageId;
104+import com.l2jfrozen.gameserver.network.serverpackets.CreatureSay;
105+import com.l2jfrozen.gameserver.network.serverpackets.SystemMessage;
106+import com.l2jfrozen.gameserver.templates.L2Item;
107+import com.l2jfrozen.gameserver.util.GMAudit;
108+import com.l2jfrozen.util.CloseUtil;
109+import com.l2jfrozen.util.database.L2DatabaseFactory;
110+
111+public class AdminSendDonate implements IAdminCommandHandler
112+{
113+ protected static final Logger _log = Logger.getLogger(AdminSendDonate.class.getName());
114+
115+ private static final String[] ADMIN_COMMANDS =
116+ {
117+ "admin_senddonate",
118+ "admin_givedonate"
119+ };
120+
121+ @Override
122+ public boolean useAdminCommand(String command, L2PcInstance activeChar)
123+ {
124+ if (command.equals("admin_senddonate"))
125+ {
126+ AdminHelpPage.showHelpPage(activeChar, "senddonate.htm");
127+ }
128+ else if (command.startsWith("admin_givedonate"))
129+ {
130+ StringTokenizer st = new StringTokenizer(command, " ");
131+ st.nextToken();
132+
133+ String playername = "";
134+ L2PcInstance player = null;
135+
136+ if (st.countTokens() == 4)
137+ {
138+ playername = st.nextToken();
139+ player = L2World.getInstance().getPlayer(playername);
140+ String id = st.nextToken();
141+ int idval = Integer.parseInt(id);
142+ String num = st.nextToken();
143+ int numval = Integer.parseInt(num);
144+ String location = st.nextToken();
145+
146+ // Can't ban yourself
147+ if (player != null && player.equals(activeChar))
148+ {
149+ activeChar.sendPacket(SystemMessageId.CANNOT_USE_ON_YOURSELF);
150+ return false;
151+ }
152+
153+ if (player != null)
154+ createItem(activeChar, player, idval, numval, getItemLocation(location));
155+ else
156+ giveItemToOfflinePlayer(activeChar, playername, idval, numval, getItemLocation(location));
157+
158+ auditAction(command, activeChar, playername);
159+ }
160+ else
161+ {
162+ sendMessage(activeChar, 0, 0, "SYS", "Please fill in all the blanks before requesting a item creation.");
163+ }
164+
165+ AdminHelpPage.showHelpPage(activeChar, "senddonate.htm");
166+ }
167+
168+ return true;
169+ }
170+
171+ /**
172+ * Create item on player inventory. If player is offline, store item on database by giveItemToOfflinePlayer method.
173+ * @param activeChar
174+ * @param player
175+ * @param id
176+ * @param count
177+ * @param location
178+ */
179+ private static void createItem(L2PcInstance activeChar, L2PcInstance player, int id, int count, ItemLocation location)
180+ {
181+ L2Item item = ItemTable.getInstance().getTemplate(id);
182+ if (item == null)
183+ {
184+ sendMessage(activeChar, 0, 0, "SYS", "Unknown Item ID.");
185+ return;
186+ }
187+
188+ if (count > 10 && !item.isStackable())
189+ {
190+ sendMessage(activeChar, 0, 0, "SYS", "You can't to create more than 10 non stackable items!");
191+ return;
192+ }
193+
194+ if (location == ItemLocation.INVENTORY)
195+ player.getInventory().addItem("Admin", id, count, player, activeChar);
196+ else if (location == ItemLocation.WAREHOUSE)
197+ player.getWarehouse().addItem("Admin", id, count, player, activeChar);
198+
199+ if (activeChar != player)
200+ {
201+ if (count > 1)
202+ player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_PICKED_UP_S1_S2).addItemName(id).addNumber(count));
203+ else
204+ player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_PICKED_UP_S1).addItemName(id));
205+ }
206+
207+ sendMessage(activeChar, 0, 0, "SYS", "Spawned " + count + " " + item.getName() + " in " + player.getName() + " " + (location == ItemLocation.INVENTORY ? "inventory" : "warehouse") + ".");
208+ }
209+
210+ /**
211+ * If player is offline, store item by SQL Query
212+ * @param activeChar
213+ * @param playername
214+ * @param id
215+ * @param count
216+ * @param location
217+ */
218+ private static void giveItemToOfflinePlayer(L2PcInstance activeChar, String playername, int id, int count, ItemLocation location)
219+ {
220+ L2Item item = ItemTable.getInstance().getTemplate(id);
221+ int objectId = IdFactory.getInstance().getNextId();
222+
223+ Connection con = null;
224+ try
225+ {
226+ con = L2DatabaseFactory.getInstance().getConnection();
227+ PreparedStatement statement = con.prepareStatement("SELECT obj_Id FROM characters WHERE char_name=?");
228+ statement.setString(1, playername);
229+ ResultSet result = statement.executeQuery();
230+ int objId = 0;
231+
232+ if (result.next())
233+ {
234+ objId = result.getInt(1);
235+ }
236+
237+ result.close();
238+ statement.close();
239+
240+ if (objId == 0)
241+ {
242+ sendMessage(activeChar, 0, 0, "SYS", "Char \"" + playername + "\" does not exists!");
243+ con.close();
244+ return;
245+ }
246+
247+ if (item == null)
248+ {
249+ sendMessage(activeChar, 0, 0, "SYS", "Unknown Item ID.");
250+ return;
251+ }
252+
253+ if (count > 1 && !item.isStackable())
254+ {
255+ sendMessage(activeChar, 0, 0, "SYS", "You can't to create more than 1 non stackable items!");
256+ return;
257+ }
258+
259+ statement = con.prepareStatement("INSERT INTO items (owner_id,item_id,count,loc,loc_data,enchant_level,object_id,custom_type1,custom_type2,mana_left) VALUES (?,?,?,?,?,?,?,?,?,?)");
260+ statement.setInt(1, objId);
261+ statement.setInt(2, item.getItemId());
262+ statement.setInt(3, count);
263+ statement.setString(4, location.name());
264+ statement.setInt(5, 0);
265+ statement.setInt(6, 0);
266+ statement.setInt(7, objectId);
267+ statement.setInt(8, 0);
268+ statement.setInt(9, 0);
269+ statement.setInt(10, -1);
270+
271+ statement.executeUpdate();
272+ statement.close();
273+
274+ sendMessage(activeChar, 0, 0, "SYS", "Created " + count + " " + item.getName() + " in " + playername + " " + (location == ItemLocation.INVENTORY ? "inventory" : "warehouse") + ".");
275+ _log.info("Insert item: (" + objId + ", " + item.getName() + ", " + count + ", " + objectId + ")");
276+ }
277+ catch (SQLException e)
278+ {
279+ _log.log(Level.SEVERE, "Could not insert item " + item.getName() + " into DB: Reason: " + e.getMessage(), e);
280+ }
281+ finally
282+ {
283+ CloseUtil.close(con);
284+ }
285+ }
286+
287+ private static ItemLocation getItemLocation(String name)
288+ {
289+ ItemLocation location = null;
290+ if (name.equalsIgnoreCase("inventory"))
291+ location = ItemLocation.INVENTORY;
292+ else if (name.equalsIgnoreCase("warehouse"))
293+ location = ItemLocation.WAREHOUSE;
294+ return location;
295+ }
296+
297+ private static void auditAction(String fullCommand, L2PcInstance activeChar, String target)
298+ {
299+ if (!Config.GMAUDIT)
300+ return;
301+
302+ String[] command = fullCommand.split(" ");
303+
304+ GMAudit.auditGMAction(activeChar.getName() + " [" + activeChar.getObjectId() + "]", command[0], (target.equals("") ? "no-target" : target), (command.length > 2 ? command[2] : ""));
305+ }
306+
307+ private static void sendMessage(L2PcInstance player, int objectId, int messageType, String charName, String text)
308+ {
309+ player.sendPacket(new CreatureSay(objectId, messageType, charName, text));
310+ }
311+
312+ @Override
313+ public String[] getAdminCommandList()
314+ {
315+ return ADMIN_COMMANDS;
316+ }
317+}