source: java-rpg-portal/PortalThread.java@ 704247c

Last change on this file since 704247c was ec3114d, checked in by dportnoy <dmp1488@…>, 17 years ago

[svn r30]

  • Property mode set to 100644
File size: 2.1 KB
Line 
1import javax.swing.*;
2
3/*
4 * This class processes messages from the server.
5 */
6
7public class PortalThread extends Connection {
8 private LostHavenPortal main;
9
10 public PortalThread(String ip, int port, LostHavenPortal main) {
11 super(ip, port, "PortalThread");
12
13 this.main = main;
14 }
15
16 protected void processMessage(MessageType type, String input) {
17 Player p;
18 int id;
19 String name;
20 boolean online;
21
22 switch(type) {
23 case Info:
24 if(input.equals("started")) {
25 main.lblServerStatus.setText("online");
26 }else if(input.equals("stopped")) {
27 main.lblServerStatus.setText("offline");
28 }
29 break;
30 case Registered:
31 id = Integer.parseInt(input.substring(0, input.indexOf(";")));
32 input = input.substring(input.indexOf(";")+1);
33 name = input.substring(0, input.indexOf(";"));
34 input = input.substring(input.indexOf(";")+1);
35 online = input.equals("true");
36
37 p = new Player(id, name, "");
38
39 if(!main.registered.containsKey(name)) {
40 main.addRegList(name, p);
41 if(online) {
42 main.addOnlineList(name);
43 }
44 }
45 break;
46 }
47 }
48
49 protected void connectionStart() {
50
51 }
52
53 protected void connectionSuccess() {
54 main.lblConnectionStatus.setText("connected");
55 sendMessage(MessageType.Admin, "");
56 }
57
58 protected void connectionFailure() {
59 JOptionPane.showMessageDialog(main, "Connection could not be established.");
60 }
61
62 protected void connectionBreak() {
63 JOptionPane.showMessageDialog(main, "Your connection was interrupted");
64 }
65
66 protected void peerDisconnect() {
67 JOptionPane.showMessageDialog(main, "The server disconnected");
68 }
69
70 protected void connectionEnd() {
71 main.registered.clear();
72 main.orderedReg.clear();
73 main.orderedOnline.clear();
74 main.lblConnectionStatus.setText("disconnected");
75 main.lblServerStatus.setText("not available");
76 main.updateGui();
77 }
78}
Note: See TracBrowser for help on using the repository browser.