· 9 years ago · Feb 05, 2017, 05:56 AM
1package mineplex.core.antihack;
2
3import java.sql.Connection;
4import java.sql.DriverManager;
5import java.sql.PreparedStatement;
6import java.sql.SQLException;
7import mineplex.core.logger.Logger;
8import net.minecraft.server.v1_7_R3.EntityPlayer;
9import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
10import org.bukkit.entity.Player;
11
12
13
14public class AntiHackRepository
15{
16 private String _serverName;
17 private static Connection _connection;
18 private String _connectionString = "jdbc:mysql://sqlstats.mineplex.com:3306/Mineplex?autoReconnect=true";
19 private String _userName = "root";
20 private String _password = "tAbechAk3wR7tuTh";
21
22 private static String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS AntiHack_Kick_Log (id INT NOT NULL AUTO_INCREMENT, updated LONG, playerName VARCHAR(256), motd VARCHAR(56), gameType VARCHAR(56), map VARCHAR(256), serverName VARCHAR(256), report VARCHAR(256), ping VARCHAR(25), PRIMARY KEY (id));";
23 private static String UPDATE_PLAYER_OFFENSES = "INSERT INTO AntiHack_Kick_Log (updated, playerName, motd, gameType, map, serverName, report, ping) VALUES (now(), ?, ?, ?, ?, ?, ?, ?);";
24
25 public AntiHackRepository(String serverName)
26 {
27 this._serverName = serverName;
28 }
29
30 public void initialize()
31 {
32 PreparedStatement preparedStatement = null;
33
34 try
35 {
36 if ((_connection == null) || (_connection.isClosed())) {
37 _connection = DriverManager.getConnection(this._connectionString, this._userName, this._password);
38 }
39
40 preparedStatement = _connection.prepareStatement(CREATE_TABLE);
41 preparedStatement.execute();
42 }
43 catch (Exception exception)
44 {
45 exception.printStackTrace();
46 Logger.Instance.log(exception);
47
48
49
50 if (preparedStatement != null)
51 {
52 try
53 {
54 preparedStatement.close();
55 }
56 catch (SQLException e)
57 {
58 e.printStackTrace();
59 }
60 }
61 }
62 finally
63 {
64 if (preparedStatement != null)
65 {
66 try
67 {
68 preparedStatement.close();
69 }
70 catch (SQLException e)
71 {
72 e.printStackTrace();
73 }
74 }
75 }
76 }
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122 public void saveOffense(final Player player, final String motd, final String game, final String map, final String report)
123 {
124 new Thread(new Runnable()
125 {
126 public void run()
127 {
128 PreparedStatement preparedStatement = null;
129
130 try
131 {
132 if ((AntiHackRepository._connection == null) || (AntiHackRepository._connection.isClosed())) {
133 AntiHackRepository._connection = DriverManager.getConnection(AntiHackRepository.this._connectionString, AntiHackRepository.this._userName, AntiHackRepository.this._password);
134 }
135 preparedStatement = AntiHackRepository._connection.prepareStatement(AntiHackRepository.UPDATE_PLAYER_OFFENSES);
136
137
138 preparedStatement.setString(1, player.getName());
139 preparedStatement.setString(2, motd);
140 preparedStatement.setString(3, game);
141 preparedStatement.setString(4, map);
142 preparedStatement.setString(5, AntiHackRepository.this._serverName);
143 preparedStatement.setString(6, report);
144 preparedStatement.setString(7, ((CraftPlayer)player).getHandle().ping + "ms");
145
146 preparedStatement.execute();
147 }
148 catch (Exception exception)
149 {
150 exception.printStackTrace();
151 Logger.Instance.log(exception);
152
153
154
155 if (preparedStatement != null)
156 {
157 try
158 {
159 preparedStatement.close();
160 }
161 catch (SQLException e)
162 {
163 e.printStackTrace();
164 }
165 }
166 }
167 finally
168 {
169 if (preparedStatement != null)
170 {
171 try
172 {
173 preparedStatement.close();
174 }
175 catch (SQLException e)
176 {
177 e.printStackTrace();
178 }
179 }
180 }
181 }
182 })
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226 .start();
227 }
228}