My favorites | Sign in
Project Logo
                
Changes to /trunk/server/src/org/jogre/server/administrator/AdminClientConnectionThread.java
r2 vs. r16   Edit
  Compare: vs.   Format:
Revision r16
Go to: 
Project members, sign in to write a code review
/trunk/server/src/org/jogre/server/administrator/AdminClientConnectionThread.java   r2 /trunk/server/src/org/jogre/server/administrator/AdminClientConnectionThread.java   r16
1 /* 1 /*
2 * JOGRE (Java Online Gaming Real-time Engine) - Server 2 * JOGRE (Java Online Gaming Real-time Engine) - Server
3 * Copyright (C) 2004 Bob Marks (marksie531@yahoo.com) 3 * Copyright (C) 2004 Bob Marks (marksie531@yahoo.com)
4 * http://jogre.sourceforge.org 4 * http://jogre.sourceforge.org
5 * 5 *
6 * This program is free software; you can redistribute it and/or 6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License 7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2 8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version. 9 * of the License, or (at your option) any later version.
10 * 10 *
11 * This program is distributed in the hope that it will be useful, 11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software 17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */ 19 */
20 package org.jogre.server.administrator; 20 package org.jogre.server.administrator;
21 21
22 import java.net.Socket; 22 import java.net.Socket;
23 23
24 import nanoxml.XMLElement; 24 import nanoxml.XMLElement;
25 25
26 import org.jogre.client.IClient; 26 import org.jogre.client.IClient;
27 import org.jogre.common.AbstractConnectionThread; 27 import org.jogre.common.AbstractConnectionThread;
28 import org.jogre.common.GameList; 28 import org.jogre.common.GameList;
29 import org.jogre.common.SocketBasedMessageBus;
29 import org.jogre.common.comm.Comm; 30 import org.jogre.common.comm.Comm;
30 import org.jogre.common.comm.CommAdminMessage; 31 import org.jogre.common.comm.CommAdminMessage;
31 import org.jogre.common.comm.CommGameMessage; 32 import org.jogre.common.comm.CommGameMessage;
32 import org.jogre.common.comm.CommTableMessage; 33 import org.jogre.common.comm.CommTableMessage;
33 34
34 /** 35 /**
35 * Class for listening to data coming from the ServerConnectionThread 36 * Class for listening to data coming from the ServerConnectionThread
36 * to the Jogre Server Administrator. 37 * to the Jogre Server Administrator.
37 * 38 *
38 * @author Bob Marks 39 * @author Bob Marks
39 * @version Beta 0.3 40 * @version Beta 0.3
40 */ 41 */
41 public class AdminClientConnectionThread extends AbstractConnectionThread { 42 public class AdminClientConnectionThread extends AbstractConnectionThread {
42 43
43 /** Interface betweem this thread and the Frame */ 44 /** Interface betweem this thread and the Frame */
44 protected IClient clientInterface; 45 protected IClient clientInterface;
45 46
46 private ClientCommDataReceiverList dataReceiver = null; 47 private ClientCommDataReceiverList dataReceiver = null;
47 48
48 /** 49 /**
49 * Default constructor which takes a Socket connection to the server, a 50 * Default constructor which takes a Socket connection to the server, a
50 * username and an IClient which sits between this class and the GUI. 51 * username and an IClient which sits between this class and the GUI.
51 * 52 *
52 * @param connection Socket connection to server. 53 * @param connection Socket connection to server.
53 * @param username Username 54 * @param username Username
54 * @param clientInterface Interface between this class and GUI. 55 * @param clientInterface Interface between this class and GUI.
55 */ 56 */
56 public AdminClientConnectionThread (Socket connection, String username, IClient clientInterface) { 57 public AdminClientConnectionThread (Socket connection, String username, IClient clientInterface) {
57 super (connection); 58 super (new SocketBasedMessageBus(connection));
58 59
59 this.username = username; 60 setUsername(username);
60 this.clientInterface = clientInterface; 61 this.clientInterface = clientInterface;
61 } 62 }
62 63
63 /** 64 /**
64 * Set the client interface. 65 * Set the client interface.
65 * 66 *
66 * @param clientInterface Client interface 67 * @param clientInterface Client interface
67 */ 68 */
68 public void setClientInterface (IClient clientInterface) { 69 public void setClientInterface (IClient clientInterface) {
69 this.clientInterface = clientInterface; 70 this.clientInterface = clientInterface;
70 } 71 }
71 72
72 /** 73 /**
73 * Parse method which reads the first token of the message and delegate 74 * Parse method which reads the first token of the message and delegate
74 * to the implementating client. 75 * to the implementating client.
75 * 76 *
76 * @see org.jogre.common.AbstractConnectionThread#parse(nanoxml.XMLElement) 77 * @see org.jogre.common.AbstractConnectionThread#parse(nanoxml.XMLElement)
77 */ 78 */
78 public void parse (XMLElement message) { 79 public void parse (XMLElement message) {
79 // Receive data messages and update tree 80 // Receive data messages and update tree
80 if (Comm.ADMIN_DATA_MESSAGE.equals(message.getName())) { 81 if (Comm.ADMIN_DATA_MESSAGE.equals(message.getName())) {
81 CommAdminMessage adminMessage = new CommAdminMessage (message); 82 CommAdminMessage adminMessage = new CommAdminMessage (message);
82 83
83 if (dataReceiver != null) { 84 if (dataReceiver != null) {
84 String gameID = adminMessage.getGameID(); 85 String gameID = adminMessage.getGameID();
85 String username = adminMessage.getUsername(); 86 String username = adminMessage.getUsername();
86 XMLElement subMessage = adminMessage.getMessage(); 87 XMLElement subMessage = adminMessage.getMessage();
87 88
88 String sTableNum = subMessage.getStringAttribute(CommTableMessage.XML_ATT_TABLE_NUM); 89 String sTableNum = subMessage.getStringAttribute(CommTableMessage.XML_ATT_TABLE_NUM);
89 if (sTableNum == null) 90 if (sTableNum == null)
90 this.dataReceiver.receiveGameMessage (adminMessage.getMessage(), gameID, username); 91 this.dataReceiver.receiveGameMessage (adminMessage.getMessage(), gameID, username);
91 else 92 else
92 this.dataReceiver.receiveTableMessage (adminMessage.getMessage(), gameID, username, Integer.parseInt(sTableNum)); 93 this.dataReceiver.receiveTableMessage (adminMessage.getMessage(), gameID, username, Integer.parseInt(sTableNum));
93 } 94 }
94 } 95 }
95 96
96 // Delegate ALL message to GUI interface 97 // Delegate ALL message to GUI interface
97 String sTableNum = message.getStringAttribute (CommTableMessage.XML_ATT_TABLE_NUM); 98 String sTableNum = message.getStringAttribute (CommTableMessage.XML_ATT_TABLE_NUM);
98 if (sTableNum == null) 99 if (sTableNum == null)
99 this.clientInterface.receiveGameMessage (message); 100 this.clientInterface.receiveGameMessage (message);
100 else 101 else
101 this.clientInterface.receiveTableMessage (message, Integer.parseInt (sTableNum)); 102 this.clientInterface.receiveTableMessage (message, Integer.parseInt (sTableNum));
102 } 103 }
103 104
104 /** 105 /**
105 * Send a ITransmittable object from a client to the server. 106 * Send a ITransmittable object from a client to the server.
106 * 107 *
107 * @param message 108 * @param message
108 */ 109 */
109 public void send (CommGameMessage message) { 110 public void send (CommGameMessage message) {
110 super.send (message); 111 getMessageBus().send(message);
111 } 112 }
112 113
113 /** 114 /**
114 * Convience Delegate method to return the game list object which 115 * Convience Delegate method to return the game list object which
115 * should be mirrored to that on the jogre server. 116 * should be mirrored to that on the jogre server.
116 * 117 *
117 * @return Game list object consisting of user and table lists. 118 * @return Game list object consisting of user and table lists.
118 */ 119 */
119 public GameList getGameList () { 120 public GameList getGameList () {
120 return JogreServerAdministrator.getInstance().getGameList(); 121 return JogreServerAdministrator.getInstance().getGameList();
121 } 122 }
122 123
123 /** 124 /**
124 * Set the game list object from the server. 125 * Set the game list object from the server.
125 * 126 *
126 * @param gamelist Game list object. 127 * @param gamelist Game list object.
127 */ 128 */
128 public void setGameList (GameList gamelist) { 129 public void setGameList (GameList gamelist) {
129 JogreServerAdministrator.getInstance().setGameList(gamelist); 130 JogreServerAdministrator.getInstance().setGameList(gamelist);
130 131
131 this.dataReceiver = new ClientCommDataReceiverList (gamelist); 132 this.dataReceiver = new ClientCommDataReceiverList (gamelist);
132 } 133 }
133 134
134 /** 135 /**
135 * Stop the thread. 136 * Stop the thread.
136 */ 137 */
137 protected void disconnect () { 138 protected void disconnect () {
138 super.loop = false; // End thread 139 getMessageBus().close(); // End thread
139 } 140 }
140 141
141 /** 142 /**
142 * Client has exitted so clean everything up. 143 * Client has exitted so clean everything up.
143 * 144 *
144 * @see org.jogre.common.AbstractConnectionThread#cleanup() 145 * @see org.jogre.common.AbstractConnectionThread#cleanup()
145 */ 146 */
146 public void cleanup () { 147 public void cleanup () {
147 // Clean up 148 // Clean up
148 } 149 }
149 } 150 }
Hosted by Google Code