2
# This program is free software: you can redistribute it and/or modify
3
# it under the terms of the GNU General Public License as published by
4
# the Free Software Foundation, either version 3 of the License, or
5
# (at your option) any later version.
7
# This program is distributed in the hope that it will be useful,
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
# GNU General Public License for more details.
12
# You should have received a copy of the GNU General Public License
13
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
package jchess.server;
18
import java.io.IOException;
20
import java.util.logging.Level;
21
import java.util.logging.Logger;
30
public static void main(String[] args)
32
System.out.println("JChess Server Start!");
34
Server server = new Server(); //create server
35
server.isPrintEnable = false;
40
System.out.println("--------------------");
41
System.out.println("[1] Nowy stół");
42
System.out.println("[2] Lista aktywnych stołów");
43
System.out.println("[3] Włącz/wyłącz komunikaty serwera");
44
System.out.println("[4] Wyłącz serwer");
45
System.out.print("-> ");
46
String str = readString();
48
if(str.equals("1")) //new table
50
System.out.print("ID gry: ");
51
int gameID = Integer.parseInt(readString());
53
System.out.print("Hasło: ");
54
String pass = MD5.encrypt(readString());
59
System.out.print("Gra z obserwatorami[t/n]: ");
60
observer = readString();
61
}while(!observer.equalsIgnoreCase("t") && !observer.equalsIgnoreCase("n"));
63
boolean canObserver = observer.equalsIgnoreCase("t");
65
server.newTable(gameID, pass, canObserver, true); //create new table
67
else if(str.equals("2")) //list of tables
69
for (Map.Entry<Integer, Table> entry : server.tables.entrySet())
71
Integer id = entry.getKey();
72
Table table = entry.getValue();
76
if(table.clientPlayer1==null || table.clientPlayer1.nick == null) p1 = "empty";
77
else p1 = table.clientPlayer1.nick;
79
if(table.clientPlayer2==null || table.clientPlayer2.nick == null) p2 = "empty";
80
else p2 = table.clientPlayer2.nick;
82
System.out.println("\t"+id+": "+p1+" vs "+p2);
85
else if(str.equals("3")) //on/off server's communicats
87
if(server.isPrintEnable == false)
89
server.isPrintEnable = true;
90
System.out.println("Komunikaty serwera zostały włączone");
94
server.isPrintEnable = false;
95
System.out.println("Komunikaty serwera zostały wyłączone");
98
else if(str.equals("4")) //exit
104
System.out.println("Nierozpoznane polecenie");
110
public static String readString() //read string from console
113
StringBuffer sb = new StringBuffer();
116
while ((ch = System.in.read()) != 10)
118
sb.append((char) ch);
120
} catch (IOException ex)
122
Logger.getLogger(Console.class.getName()).log(Level.SEVERE, null, ex);
125
return sb.toString();