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