· 6 years ago · Sep 06, 2019, 07:46 PM
1SQL: on game server database
2[code]SET FOREIGN_KEY_CHECKS=0;
3-- ----------------------------
4-- Table structure for donate_holder
5-- ----------------------------
6DROP TABLE IF EXISTS `donate_holder`;
7CREATE TABLE `donate_holder` (
8 `no` int(11) NOT NULL AUTO_INCREMENT,
9 `id` int(11) NOT NULL,
10 `count` int(11) NOT NULL,
11 `playername` varchar(255) CHARACTER SET utf8 NOT NULL,
12 `order_status` int(11) DEFAULT '1' NOT NULL,
13 PRIMARY KEY (`no`)
14) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
15
16-- ----------------------------
17-- Table structure for paygol_donation_log
18-- ----------------------------
19DROP TABLE IF EXISTS `paygol_donation_log`;
20CREATE TABLE `paygol_donation_log` (
21 `id` int(11) NOT NULL AUTO_INCREMENT,
22 `transaction_id` varchar(255) NOT NULL DEFAULT '',
23 `action` varchar(255) NOT NULL,
24 `service_id` varchar(255) NOT NULL DEFAULT '',
25 `country` varchar(255) NOT NULL DEFAULT '0',
26 `price` varchar(255) NOT NULL DEFAULT '0',
27 `currency` varchar(255) NOT NULL,
28 `frmprice` varchar(255) NOT NULL DEFAULT '',
29 `frmcurrency` varchar(255) NOT NULL,
30 `custom` varchar(255) NOT NULL,
31 `method` varchar(255) NOT NULL,
32 `keyword` varchar(255) DEFAULT NULL,
33 `message` varchar(255) DEFAULT NULL,
34 `message_id` varchar(255) DEFAULT NULL,
35 `sender` varchar(255) DEFAULT NULL,
36 `operator` varchar(255) DEFAULT NULL,
37 PRIMARY KEY (`id`,`transaction_id`)
38) ENGINE=InnoDB AUTO_INCREMENT=37 DEFAULT CHARSET=utf8;
39
40-- ----------------------------
41-- Table structure for paypal_donation_log
42-- ----------------------------
43DROP TABLE IF EXISTS `paypal_donation_log`;
44CREATE TABLE `paypal_donation_log` (
45 `transaction_id` varchar(64) NOT NULL DEFAULT '',
46 `donation` varchar(255) NOT NULL DEFAULT '',
47 `amount` double NOT NULL DEFAULT 0,
48 `amountminfee` double NOT NULL DEFAULT 0,
49 `character_name` text NOT NULL,
50 `dt` timestamp NOT NULL DEFAULT current_timestamp(),
51 PRIMARY KEY (`transaction_id`)
52) ENGINE=InnoDB DEFAULT CHARSET=utf8;
53
54-- ----------------------------
55-- Table structure for payg2a_donation_log
56-- ----------------------------
57DROP TABLE IF EXISTS `payg2a_donation_log`;
58CREATE TABLE `payg2a_donation_log` (
59 `transaction_id` varchar(64) NOT NULL DEFAULT '',
60 `donation` varchar(255) NOT NULL DEFAULT '',
61 `amount` double NOT NULL DEFAULT 0,
62 `amountminfee` double NOT NULL DEFAULT 0,
63 `character_name` text NOT NULL,
64 `dt` timestamp NOT NULL DEFAULT current_timestamp(),
65 PRIMARY KEY (`transaction_id`)
66) ENGINE=InnoDB DEFAULT CHARSET=utf8;
67
68-- ----------------------------
69-- Table structure for paynext_donation_log
70-- ----------------------------
71DROP TABLE IF EXISTS `paynext_donation_log`;
72 CREATE TABLE `paynext_donation_log` (
73 `order_id` int(11) NOT NULL DEFAULT '0',
74 `date_created` datetime NOT NULL DEFAULT current_timestamp(),
75 `product_id` int(11) NOT NULL DEFAULT '0',
76 `volute` int(11) NOT NULL DEFAULT '0',
77 `product_count` int(11) NOT NULL DEFAULT '0',
78 `server` int(11) NOT NULL DEFAULT '0',
79 `char_name` varchar(255) NOT NULL DEFAULT '',
80 `profit` float NOT NULL DEFAULT '0',
81 `comment` varchar(255) DEFAULT NULL,
82 `status` int(11) NOT NULL DEFAULT '0',
83 PRIMARY KEY (`order_id`)
84) ENGINE=MyISAM;[/code]
85
86java part
87[code]
88/**
89 * Author Nightwolf
90 * bugs contact:
91 * Email Nightw0lv@hotmail.com
92 * Skype nightwolf.black
93 * Created for Denart Designs that holds the ownership of this files
94 * You are allowed to edit this code but you are not allowed to sell this code or parts of this code under any sircuimstances.
95 * buy this from https://shop.denart-designs.com/ get updates latest news and support.
96 * Do not remove this, or any credits in order to ask for support.
97 * Damn we created that think and changing a line or remove the authors credits does not make you author
98 * plus its not helping us to improve it and give you updates..
99 */
100package l2f.gameserver.taskmanager;
101
102import java.sql.Connection;
103import java.sql.PreparedStatement;
104import java.sql.ResultSet;
105import java.sql.SQLException;
106import java.util.logging.Logger;
107
108import l2f.commons.threading.RunnableImpl;
109import l2f.gameserver.ThreadPoolManager;
110import l2f.gameserver.database.DatabaseFactory;
111import l2f.gameserver.model.Player;
112import l2f.gameserver.model.World;
113import l2f.gameserver.utils.ItemFunctions;
114
115public class DonateGiverTaskManager
116{
117 private static Logger _log = Logger.getLogger(DonateGiverTaskManager.class.getName());
118
119 public static DonateGiverTaskManager getInstance()
120 {
121 return SingletonHolder._instance;
122 }
123
124 private static class SingletonHolder
125 {
126 protected static final DonateGiverTaskManager _instance = new DonateGiverTaskManager();
127 }
128
129 protected DonateGiverTaskManager()
130 {
131 _log.info("DonateGiver: started.");
132
133 ThreadPoolManager.getInstance().scheduleAtFixedRate(new RunnableImpl()
134 {
135 @Override
136 public void runImpl()
137 {
138 Logger __log = Logger.getLogger(DonateGiverTaskManager.class.getName());
139 String charName = null;
140 int id = 0;
141 int count = 0;
142 String playerName = null;
143 try (Connection con = DatabaseFactory.getInstance().getConnection();
144 PreparedStatement statement = con.prepareStatement("SELECT id, count, playername FROM donate_holder WHERE order_status=1;"))
145 {
146 try (ResultSet rset = statement.executeQuery())
147 {
148 while (rset.next())
149 {
150 id = rset.getInt("id");
151 count = rset.getInt("count");
152 playerName = rset.getString("playername");
153 if (id > 0 && count > 0 && playerName != null)
154 {
155 int obj_id = selectPlayer(playerName);
156 Player Player = World.getPlayer(obj_id);
157 if (Player != null && Player.isOnline() == true)
158 for (Player activeChar : World.getPlayer(obj_id))
159 {
160 if (activeChar == null || activeChar.isOnline() == false)
161 {
162 continue;
163 }
164 if (activeChar.getName().toLowerCase().equals(playerName.toLowerCase()))
165 {
166 charName = activeChar.getName();
167 ItemFunctions.addItem(activeChar, id, count, true, "Donate");
168 activeChar.getInventory().store();
169 activeChar.sendItemList(false);
170 activeChar.sendMessage("Received "+ count +" donate coins.");
171 RemoveDonation(charName);
172 activeChar.sendActionFailed();
173 }
174 }
175 }
176 }
177 }
178 catch (Exception e)
179 {
180 __log.warning("Donate rewarder fail: for character: " + charName + " " + count + " Donate Coins! " + e.getMessage());
181 }
182 }
183 catch (Exception e)
184 {
185 __log.warning("Check donate items failed. " + e.getMessage());
186 }
187 }
188 }, 5000L, 5000L);
189 }
190
191 /**
192 * @param playername
193 */
194 private static void RemoveDonation(String playername)
195 {
196 try (Connection con = DatabaseFactory.getInstance().getConnection();
197 PreparedStatement statement = con.prepareStatement("DELETE FROM donate_holder WHERE playername=?;"))
198 {
199 statement.setString(1, playername);
200 statement.execute();
201 }
202 catch (SQLException e)
203 {
204 _log.warning("Failed to remove donation from database char: " + playername);
205 _log.warning(e.getMessage());
206 }
207 }
208
209 private static int selectPlayer(String playername)
210 {
211 int charId=0;
212 try (Connection con = DatabaseFactory.getInstance().getConnection();
213 PreparedStatement statement = con.prepareStatement("SELECT * FROM `characters` WHERE `char_name`=? LIMIT 1;"))
214 {
215 statement.setString(1, playername);
216 try (ResultSet rset3 = statement.executeQuery())
217 {
218 while (rset3.next())
219 {
220 charId = rset3.getInt("obj_Id");
221 }
222 }
223 }
224 catch (SQLException e)
225 {
226 _log.warning("Failed to remove donation from database char: " + playername);
227 _log.warning(e.getMessage());
228 }
229 return charId;
230 }
231}
232[/code]