PageRenderTime 54ms CodeModel.GetById 33ms app.highlight 18ms RepoModel.GetById 1ms app.codeStats 0ms

/src/ft.java

https://github.com/kpfile/Minecraft-Server-Mod
Java | 358 lines | 306 code | 42 blank | 10 comment | 53 complexity | c5c8edc84230b8e0ea2f31f91905f0d8 MD5 | raw file
  1
  2import java.io.BufferedReader;
  3import java.io.File;
  4import java.io.FileReader;
  5import java.io.FileWriter;
  6import java.io.PrintWriter;
  7import java.util.ArrayList;
  8import java.util.List;
  9import java.util.logging.Logger;
 10import net.minecraft.server.MinecraftServer;
 11
 12public class ft {
 13
 14    public static Logger a = Logger.getLogger("Minecraft");
 15    public List b = new ArrayList();
 16    private MinecraftServer c;
 17    private hg d;
 18    private int e;
 19    private ArrayList f = new ArrayList();
 20    private ArrayList g = new ArrayList();
 21    private ArrayList h = new ArrayList();
 22    private File i;
 23    private File j;
 24    private File k;
 25    private cl l;
 26
 27    public ft(MinecraftServer paramMinecraftServer) {
 28        this.c = paramMinecraftServer;
 29        this.i = paramMinecraftServer.a("banned-players.txt");
 30        this.j = paramMinecraftServer.a("banned-ips.txt");
 31        this.k = paramMinecraftServer.a("ops.txt");
 32        this.d = new hg(paramMinecraftServer);
 33        this.e = paramMinecraftServer.d.a("max-players", 20);
 34        e();
 35        g();
 36        i();
 37        f();
 38        h();
 39        j();
 40    }
 41
 42    public void a(ee paramee) {
 43        this.l = new cl(new File(paramee.s, "players"));
 44    }
 45
 46    public int a() {
 47        return this.d.b();
 48    }
 49
 50    public void a(ea paramea) {
 51        this.b.add(paramea);
 52        this.l.b(paramea);
 53
 54        this.c.e.y.d((int) paramea.l >> 4, (int) paramea.n >> 4);
 55
 56        while (this.c.e.a(paramea, paramea.v).size() != 0) {
 57            paramea.a(paramea.l, paramea.m + 1.0D, paramea.n);
 58        }
 59        this.c.e.a(paramea);
 60        this.d.a(paramea);
 61
 62        for (String str : etc.getInstance().motd) {
 63            paramea.a.b(new ba(str));
 64        }
 65        etc.getInstance().getLoader().callHook(PluginLoader.Hook.LOGIN, new Object[]{paramea});
 66    }
 67
 68    public void b(ea paramea) {
 69        try {
 70            this.d.c(paramea);
 71        } catch (NullPointerException ex) {
 72            a.info("What?");
 73        }
 74    }
 75
 76    public void c(ea paramea) {
 77        this.d.b(paramea);
 78        this.l.a(paramea);
 79        this.c.e.d(paramea);
 80        this.b.remove(paramea);
 81    }
 82
 83    public ea a(ew paramew, String paramString1, String paramString2) {
 84        if (this.f.contains(paramString1.trim().toLowerCase())) {
 85            paramew.b("You are banned from this server!");
 86            return null;
 87        }
 88        
 89        String ip = paramew.b.b().toString().split(":")[0].substring(1);
 90        if (this.g.contains(ip)) {
 91            paramew.b("Your IP address is banned from this server!");
 92            return null;
 93        }
 94        for (int i = 0; i < this.b.size(); ++i) {
 95            ea localea = (ea) this.b.get(i);
 96            if (localea.aq.equalsIgnoreCase(paramString1)) {
 97                String ip2 = localea.a.b.b().toString().split(":")[0].substring(1);
 98
 99                // perhaps they timed out since they're coming from the same IP
100                if (ip2.equals(ip)) {
101                    localea.a.b("You logged in from another location.");
102                } else {
103                    paramew.b("You are currently logged in.");
104                }
105                // ^ otherwise no.
106            }
107        }
108        if (etc.getInstance().whitelistEnabled && !(etc.getInstance().getDataSource().isUserOnWhitelist(paramString1)
109                || etc.getInstance().isAdmin(paramString1))) {
110            paramew.b(etc.getInstance().whitelistMessage);
111            return null;
112        } else if (this.b.size() >= this.e && !(etc.getInstance().getDataSource().hasReserveList() && (etc.getInstance().isAdmin(paramString1)
113                || etc.getInstance().getDataSource().isUserOnReserveList(paramString1)))) {
114            paramew.b("Server is full.");
115            return null;
116        }
117        User user = etc.getInstance().getUser(paramString1);
118        if (user != null) {
119            if (!user.IPs[0].equals("")) {
120                boolean kick = true;
121                for (int i = 0; i < user.IPs.length; i++) {
122                    if (!user.IPs[i].equals("") && ip.equals(user.IPs[i])) {
123                        kick = false;
124                    }
125                }
126                if (kick) {
127                    paramew.b("IP doesn't match specified IP.");
128                    return null;
129                }
130            }
131        }
132        
133        Object obj = etc.getInstance().getLoader().callHook(PluginLoader.Hook.LOGINCHECK, new Object[]{paramString1});
134        if (obj instanceof String) {
135            String result = (String)obj;
136            if (result != null && !result.equals("")) {
137                paramew.b(result);
138                return null;
139            }
140        }
141
142        return new ea(this.c, this.c.e, paramString1, new in(this.c.e));
143    }
144
145    /**
146     * Returns the list of bans
147     * @return
148     */
149    public String getBans() {
150        StringBuilder builder = new StringBuilder();
151        for (int l = 0; l < this.f.size(); ++l) {
152            if (l > 0) {
153                builder.append(", ");
154            }
155            builder.append(this.f.get(l));
156        }
157        return builder.toString();
158    }
159
160    /**
161     * Returns the list of IP bans
162     * @return
163     */
164    public String getIpBans() {
165        StringBuilder builder = new StringBuilder();
166        for (int l = 0; l < this.g.size(); ++l) {
167            if (l > 0) {
168                builder.append(", ");
169            }
170            builder.append(this.g.get(l));
171        }
172        return builder.toString();
173    }
174
175    public void b() {
176        this.d.a();
177    }
178
179    public void a(int paramInt1, int paramInt2, int paramInt3) {
180        this.d.a(paramInt1, paramInt2, paramInt3);
181    }
182
183    public void a(hp paramhp) {
184        for (int m = 0; m < this.b.size(); m++) {
185            ea localea = (ea) this.b.get(m);
186            localea.a.b(paramhp);
187        }
188    }
189
190    public String c() {
191        String str = "";
192        for (int m = 0; m < this.b.size(); m++) {
193            if (m > 0) {
194                str = str + ", ";
195            }
196            str = str + ((ea) this.b.get(m)).aq;
197        }
198        return str;
199    }
200
201    public void a(String paramString) {
202        this.f.add(paramString.toLowerCase());
203        f();
204    }
205
206    public void b(String paramString) {
207        this.f.remove(paramString.toLowerCase());
208        f();
209    }
210
211    private void e() {
212        try {
213            this.f.clear();
214            BufferedReader localBufferedReader = new BufferedReader(new FileReader(this.i));
215            String str = "";
216            while ((str = localBufferedReader.readLine()) != null) {
217                this.f.add(str.trim().toLowerCase());
218            }
219            localBufferedReader.close();
220        } catch (Exception localException) {
221            a.warning("Failed to load ban list: " + localException);
222        }
223    }
224
225    private void f() {
226        try {
227            PrintWriter localPrintWriter = new PrintWriter(new FileWriter(this.i, false));
228            for (Object str : this.f) {
229                localPrintWriter.println(str);
230            }
231            localPrintWriter.close();
232        } catch (Exception localException) {
233            a.warning("Failed to save ban list: " + localException);
234        }
235    }
236
237    public void c(String paramString) {
238        this.g.add(paramString.toLowerCase());
239        h();
240    }
241
242    public void d(String paramString) {
243        this.g.remove(paramString.toLowerCase());
244        h();
245    }
246
247    private void g() {
248        try {
249            this.g.clear();
250            BufferedReader localBufferedReader = new BufferedReader(new FileReader(this.j));
251            String str = "";
252            while ((str = localBufferedReader.readLine()) != null) {
253                this.g.add(str.trim().toLowerCase());
254            }
255            localBufferedReader.close();
256        } catch (Exception localException) {
257            a.warning("Failed to load ip ban list: " + localException);
258        }
259    }
260
261    private void h() {
262        try {
263            PrintWriter localPrintWriter = new PrintWriter(new FileWriter(this.j, false));
264            for (Object str : this.g) {
265                localPrintWriter.println(str);
266            }
267            localPrintWriter.close();
268        } catch (Exception localException) {
269            a.warning("Failed to save ip ban list: " + localException);
270        }
271    }
272
273    public void e(String paramString) {
274        this.h.add(paramString.toLowerCase());
275        j();
276    }
277
278    public void f(String paramString) {
279        this.h.remove(paramString.toLowerCase());
280        j();
281    }
282
283    private void i() {
284        try {
285            this.h.clear();
286            BufferedReader localBufferedReader = new BufferedReader(new FileReader(this.k));
287            String str = "";
288            while ((str = localBufferedReader.readLine()) != null) {
289                this.h.add(str.trim().toLowerCase());
290            }
291            localBufferedReader.close();
292        } catch (Exception localException) {
293            a.warning("Failed to load ip ban list: " + localException);
294        }
295    }
296
297    private void j() {
298        try {
299            PrintWriter localPrintWriter = new PrintWriter(new FileWriter(this.k, false));
300            for (Object str : this.h) {
301                localPrintWriter.println(str);
302            }
303            localPrintWriter.close();
304        } catch (Exception localException) {
305            a.warning("Failed to save ip ban list: " + localException);
306        }
307    }
308
309    public boolean g(String paramString) {
310        return this.h.contains(paramString.trim().toLowerCase());
311    }
312
313    public ea h(String paramString) {
314        for (int m = 0; m < this.b.size(); m++) {
315            ea localea = (ea) this.b.get(m);
316            if (localea.aq.equalsIgnoreCase(paramString)) {
317                return localea;
318            }
319        }
320        return null;
321    }
322
323    public void a(String paramString1, String paramString2) {
324        ea localea = h(paramString1);
325        if (localea != null) {
326            localea.a.b(new ba(paramString2));
327        }
328    }
329
330    public void i(String paramString) {
331        ba localba = new ba(paramString);
332        for (int m = 0; m < this.b.size(); m++) {
333            ea localea = (ea) this.b.get(m);
334            if (g(localea.aq)) {
335                localea.a.b(localba);
336            }
337        }
338    }
339
340    public boolean a(String paramString, hp paramhp) {
341        ea localea = h(paramString);
342        if (localea != null) {
343            localea.a.b(paramhp);
344            return true;
345        }
346        return false;
347    }
348
349    public void a(int paramInt1, int paramInt2, int paramInt3, as paramas) {
350        this.d.a(new ib(paramInt1, paramInt2, paramInt3, paramas), paramInt1, paramInt2, paramInt3);
351    }
352
353    public void d() {
354        for (int m = 0; m < this.b.size(); m++) {
355            this.l.a((ea) this.b.get(m));
356        }
357    }
358}