Methods Summary |
---|
static int | getPortNumber()
for (int i=socketnum - basePort;i<maxConnections;i++) {
if (availablePort[i]) {
socketnum = i + basePort + 1;
availablePort[i] = false;
return i + basePort;
}
}
System.out.println("looking from the beginning");
for (int i=0;i<maxConnections;i++) {
if (availablePort[i]) {
socketnum = i + basePort + 1;
availablePort[i] = false;
return i + basePort;
}
}
return 0;
|
public static void | main(java.lang.String[] args)
ChessServer m = new ChessServer();
for (int i = 0;i< args.length;i++) {
if (args[i].startsWith("connections=")) {
try {
maxConnections = Integer.parseInt(args[i].substring(12));
}
catch (Exception e){
System.out.println("connections param " + args[i] + " not a valid int");
}
}
else
System.out.println("don\'t know what to do with " + args[i]);
}
socketnum = basePort;
m.start();
|
static void | portIdle(int portNum)
System.out.println("giving back port " + portNum);
availablePort[portNum - basePort] = true;
|
public void | run()
File shutdownfile = new File("shutdown.txt");
if (shutdownfile.exists())
shutdownfile.renameTo(new File("shutdown.xyz"));
PlayerId.readUserFile();
Thread h = new HelloThread();
h.start();
while (true) {
synchronized (this) {
try {
wait(60000); //60000 = one minute
}
catch (InterruptedException e) {
}
}
if (shutdownfile.exists()) {
System.out.println("we be shutting down ");
shutdown = true;
synchronized (h) {
h.stop();
}
sendWarning (shutdownfile);
suspendGames();
PlayerId.writeUserList();
break;
}
PlayerId.writeUserList();
} //end of while (true)
System.out.println("TTFN");
System.exit(0);
|
public void | sendWarning(java.io.File shutdownFile)
//could read the delay time out of the shutdown file
SendThread np;
System.out.println("tell people they have " + warningTime + " minutes");
for (Enumeration e = ChessServer.playerlist.elements() ; e.hasMoreElements() ;) {
np = (SendThread)e.nextElement();
if (np != null ) {
np.addMsg(0,"Status","Chess Server shutting down in "+ warningTime + " minutes - sorry");
}
}
synchronized (this) {
try {
wait(warningTime * 60000);
}
catch (InterruptedException e) {}
}
|
public void | suspendGames()
SendThread np;
for (Enumeration e = ChessServer.playerlist.elements();e.hasMoreElements();){
np = (SendThread)e.nextElement();
np.addMsg(0,"Bye","");
}
|