Source code: jcsq/serverinfo/ServerInfo.java
1 package jcsq.serverinfo;
2
3 import jcsq.util.CSPacket;
4
5 /**
6 * Container for the info of current server.
7 */
8 public class ServerInfo implements Cloneable{
9
10 private String ip = "";
11 private boolean to;
12 private byte players = -1;
13 private byte maxPlayers = -1;
14 private byte protocolVersion = -1;
15 private int port = 27015;
16 private StringBuffer hostAddressBuffer = new StringBuffer();
17 private StringBuffer nameBuffer = new StringBuffer();
18 private StringBuffer mapBuffer = new StringBuffer();
19 private StringBuffer infoBuffer = new StringBuffer();
20 private StringBuffer dirBuffer = new StringBuffer();
21 private StringBuffer descriptionBuffer = new StringBuffer();
22
23 public ServerInfo(){}
24
25
26 public void setHostAddress(byte b){
27 this.hostAddressBuffer.append((char)b);
28 }
29 public void setMap(byte b){
30 this.mapBuffer.append((char)b);
31 }
32 public void setName(byte b){
33 this.nameBuffer.append((char)b);
34 }
35 public void setGameInfoString(byte b){
36 this.infoBuffer.append((char)b);
37 }
38 public void setDir(byte b){
39 this.dirBuffer.append((char)b);
40 }
41 public void setDescription(byte b){
42 this.descriptionBuffer.append((char)b);
43 }
44 public String getMap(){
45 return this.mapBuffer.toString();
46 }
47
48 public String getServerName(){
49 return this.nameBuffer.toString();
50 }
51 public String getDescription(){
52 return this.descriptionBuffer.toString();
53 }
54 public String getGameInfoString(){
55 return this.infoBuffer.toString();
56 }
57 public void setMaxPlayers(byte b){
58 this.maxPlayers = b;
59 }
60 public byte getMaxPlayers(){
61 return this.maxPlayers;
62 }
63 public void setPlayers(byte b){
64 this.players = b;
65 }
66 public void setProtocolVersion(byte b){
67 this.protocolVersion = b;
68 }
69 public byte getProtocolVersion(){
70 return this.protocolVersion;
71 }
72 public byte getPlayers(){
73 return this.players;
74 }
75
76 public int getPort(){
77 return this.port;
78 }
79 public void setPort(int port){
80 this.port = port;
81 }
82 public boolean isFull(){
83 if((this.players==this.maxPlayers) && players!=-1) return true;
84 else return false;
85 }
86 public boolean isEmpty(){
87 if (this.players==0) return true;
88 else return false;
89 }
90 public boolean timedOut(){
91 return this.to;
92 }
93 public void setTimedOut(boolean b){
94 this.to = b;
95 }
96 public void setIp(String ip){
97 this.ip = ip;
98 }
99 public String getIp(){
100 return this.ip;
101 }
102
103 public Object clone()
104 {
105 try{
106 ServerInfo cloned = (ServerInfo)super.clone();
107 return cloned;
108 }
109 catch( CloneNotSupportedException e ){
110 return null;
111 }
112 }
113
114 }