summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/DedicatedServerConnectionThread.java
blob: 311265fcde78e460c0b9c96317aa0578afd7bc43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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
123
124
125
126
127
128
129
130
package net.minecraft.server;

import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class DedicatedServerConnectionThread extends Thread {

    private static Logger a = Logger.getLogger("Minecraft");
    private final List b = Collections.synchronizedList(new ArrayList());
    private final HashMap c = new HashMap();
    private int d = 0;
    private final ServerSocket e;
    private ServerConnection f;
    private final InetAddress g;
    private final int h;

    long connectionThrottle; // CraftBukkit

    public DedicatedServerConnectionThread(ServerConnection serverconnection, InetAddress inetaddress, int i) throws IOException { // CraftBukkit - added throws
        super("Listen thread");
        this.f = serverconnection;
        this.h = i;
        this.e = new ServerSocket(i, 0, inetaddress);
        this.g = inetaddress == null ? this.e.getInetAddress() : inetaddress;
        this.e.setPerformancePreferences(0, 2, 1);
    }

    public void a() {
        List list = this.b;

        synchronized (this.b) {
            for (int i = 0; i < this.b.size(); ++i) {
                NetLoginHandler netloginhandler = (NetLoginHandler) this.b.get(i);

                try {
                    netloginhandler.c();
                } catch (Exception exception) {
                    netloginhandler.disconnect("Internal server error");
                    a.log(Level.WARNING, "Failed to handle packet for " + netloginhandler.getName() + ": " + exception, exception);
                }

                if (netloginhandler.c) {
                    this.b.remove(i--);
                }

                netloginhandler.networkManager.a();
            }
        }
    }

    public void run() {
        while (this.f.b) {
            try {
                Socket socket = this.e.accept();
                InetAddress inetaddress = socket.getInetAddress();
                long i = System.currentTimeMillis();
                HashMap hashmap = this.c;

                // CraftBukkit start
                if (((MinecraftServer) this.f.d()).server == null) {
                    socket.close();
                    continue;
                }

                connectionThrottle = ((MinecraftServer) this.f.d()).server.getConnectionThrottle();
                // CraftBukkit end

                synchronized (this.c) {
                    if (this.c.containsKey(inetaddress) && !b(inetaddress) && i - ((Long) this.c.get(inetaddress)).longValue() < connectionThrottle) {
                        this.c.put(inetaddress, Long.valueOf(i));
                        socket.close();
                        continue;
                    }

                    this.c.put(inetaddress, Long.valueOf(i));
                }

                NetLoginHandler netloginhandler = new NetLoginHandler(this.f.d(), socket, "Connection #" + this.d++);

                this.a(netloginhandler);
            } catch (IOException ioexception) {
                a.warning("DSCT: " + ioexception.getMessage()); // CraftBukkit
            }
        }

        System.out.println("Closing listening thread");
    }

    private void a(NetLoginHandler netloginhandler) {
        if (netloginhandler == null) {
            throw new IllegalArgumentException("Got null pendingconnection!");
        } else {
            List list = this.b;

            synchronized (this.b) {
                this.b.add(netloginhandler);
            }
        }
    }

    private static boolean b(InetAddress inetaddress) {
        return "127.0.0.1".equals(inetaddress.getHostAddress());
    }

    public void a(InetAddress inetaddress) {
        if (inetaddress != null) {
            HashMap hashmap = this.c;

            synchronized (this.c) {
                this.c.remove(inetaddress);
            }
        }
    }

    public void b() {
        try {
            this.e.close();
        } catch (Throwable throwable) {
            ;
        }
    }
}