1
2
3
4
5 package spellcast.net;
6
7 import java.io.*;
8 import java.net.*;
9
10 import spellcast.server.Server;
11
12 /***
13 * This class contains the status of the server.
14 * The server status contains the game name, the number of players,
15 * the ip address of the server and the current state for new connections.
16 * It also provides hooks for accessing the data via numeric indices so the class
17 * can be used as part of a TableModel.
18 *
19 * @see spellcast.ui.ServerListTableModel
20 * @author Barrie Treloar
21 */
22 public class ServerStatus
23 implements Serializable
24 {
25 /***
26 * The number of member variables in this class
27 */
28 private static final int numberOfMemberVariables = 6;
29
30 private String gameName;
31 private int numberOfPlayers;
32 private InetAddress serverIPAddress;
33 private int port;
34 private ConnectionStatus connectionStatus;
35 private VersionDetails versionDetails;
36
37 /***
38 * @param server
39 */
40 public ServerStatus(Server server) {
41 gameName = server.getGameServer().getGame().getName();
42 numberOfPlayers = server.getGameServer().getGame().getWizards().size();
43 serverIPAddress = server.getBindAddress();
44 port = server.getPort();
45 connectionStatus = server.getConnectionStatus();
46 versionDetails = server.getProgramVersionDetails();
47 }
48
49 /***
50 * Used by ServerListTableModel to obtain a column indexed version
51 * of this classes attributes.
52 * The attributes are mapped as follows:
53 * <ul>
54 * <li>gameName = 0
55 * <li>numberOfPlayers = 1
56 * <li>connectionStatus = 2
57 * <li>serverIPAddress = 3
58 * <li>port = 4
59 * <li>versionDetails = 5
60 * <ul>
61 */
62 public Object get( int index )
63 {
64 Object result = null;
65
66 switch ( index )
67 {
68 case 0:
69 result = getGameName();
70 break;
71 case 1:
72 result = new Integer( getNumberOfPlayers() );
73 break;
74 case 2:
75 result = getConnectionStatus();
76 break;
77 case 3:
78 result = getServerIPAddress();
79 break;
80 case 4:
81 result = new Integer( getPort() );
82 break;
83 case 5:
84 result = getVersionDetails();
85 break;
86 }
87
88 return result;
89 }
90
91 /***
92 * Returns the column headers needed for table headers as an array of strings.
93 */
94 public static String[] getColumnHeaders()
95 {
96 return new String[] { "Game Name",
97 "# of Players",
98 "Status",
99 "IP Address",
100 "Port",
101 "Version" };
102 }
103
104 public String getGameName()
105 {
106 return gameName;
107 }
108
109 public int getNumberOfPlayers()
110 {
111 return numberOfPlayers;
112 }
113
114 public InetAddress getServerIPAddress()
115 {
116 return serverIPAddress;
117 }
118
119 public int getPort()
120 {
121 return port;
122 }
123
124 public ConnectionStatus getConnectionStatus()
125 {
126 return connectionStatus;
127 }
128
129 /***
130 * Get the value of versionDetails.
131 *
132 * @return value of versionDetails.
133 */
134 public VersionDetails getVersionDetails()
135 {
136 return versionDetails;
137 }
138
139 public boolean equals( Object obj )
140 {
141 boolean result = false;
142
143 if ( obj instanceof ServerStatus )
144 {
145 ServerStatus other = (ServerStatus)obj;
146 if ( getGameName().equals( other.getGameName() ) &&
147 getNumberOfPlayers() == other.getNumberOfPlayers() &&
148 getServerIPAddress().equals( other.getServerIPAddress() ) &&
149 getPort() == other.getPort() &&
150 getConnectionStatus().equals( other.getConnectionStatus() ) )
151 {
152 result = true;
153 }
154 }
155
156 return result;
157 }
158 }
159