1 | import java.net.*;
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * This thread handles connections from the portal and will start a thread that listens for connections from the client if it receives
|
---|
5 | * a request to do so.
|
---|
6 | */
|
---|
7 |
|
---|
8 | public class PortalInterfaceThread extends Connection {
|
---|
9 | private LostHavenServer main;
|
---|
10 | private boolean accepted;
|
---|
11 |
|
---|
12 | public PortalInterfaceThread(Socket socket, LostHavenServer main) {
|
---|
13 | super(socket, "PortalInterfaceThread");
|
---|
14 |
|
---|
15 | this.main = main;
|
---|
16 | accepted = false;
|
---|
17 | }
|
---|
18 |
|
---|
19 | protected void processMessage(MessageType type, String input) {
|
---|
20 | if(type != MessageType.Admin && !accepted) {
|
---|
21 | closeConnection();
|
---|
22 | return;
|
---|
23 | }
|
---|
24 |
|
---|
25 | switch(type) {
|
---|
26 | case Admin:
|
---|
27 | accepted = true;
|
---|
28 | if(main.running)
|
---|
29 | sendMessage(MessageType.Info, "started");
|
---|
30 | else
|
---|
31 | sendMessage(MessageType.Info, "stopped");
|
---|
32 | sendRegisteredPlayers();
|
---|
33 | break;
|
---|
34 | case StartServer:
|
---|
35 | main.start();
|
---|
36 | sendMessage(MessageType.Info, "started");
|
---|
37 | break;
|
---|
38 | case StopServer:
|
---|
39 | main.stop();
|
---|
40 | sendMessage(MessageType.Info, "stopped");
|
---|
41 | break;
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | private void sendRegisteredPlayers() {
|
---|
46 | String[] reg;
|
---|
47 | Player p;
|
---|
48 | String str;
|
---|
49 |
|
---|
50 | reg = (String[])main.orderedReg.toArray(new String[0]);
|
---|
51 | for(int x=0; x<main.orderedReg.size(); x++) {
|
---|
52 | p = main.registered.get(reg[x]);
|
---|
53 |
|
---|
54 | str = p.getId() + ";" + p.getName() + ";" + main.online.containsKey(p.getName());
|
---|
55 | sendMessage(MessageType.Registered, str);
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | protected void connectionStart() {
|
---|
60 |
|
---|
61 | }
|
---|
62 |
|
---|
63 | protected void connectionSuccess() {
|
---|
64 |
|
---|
65 | }
|
---|
66 |
|
---|
67 | protected void connectionFailure() {
|
---|
68 |
|
---|
69 | }
|
---|
70 |
|
---|
71 | protected void connectionBreak() {
|
---|
72 | //record unexpected portal exit in the log
|
---|
73 | }
|
---|
74 |
|
---|
75 | protected void peerDisconnect() {
|
---|
76 | //record regular portal exit in the log
|
---|
77 | }
|
---|
78 |
|
---|
79 | protected void connectionEnd() {
|
---|
80 |
|
---|
81 | }
|
---|
82 | }
|
---|