| /trunk/server/src/org/jogre/server/administrator/AdminConnectionPanel.java r2 | /trunk/server/src/org/jogre/server/administrator/AdminConnectionPanel.java r12 | ||
| 1 | /* | 1 | /* |
|---|---|---|---|
| 2 | * JOGRE (Java Online Gaming Real-time Engine) - Server | 2 | * JOGRE (Java Online Gaming Real-time Engine) - Server |
| 3 | * Copyright (C) 2005 Bob Marks (marksie531@yahoo.com) | 3 | * Copyright (C) 2005 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.awt.ConnectionPanel; | 26 | import org.jogre.client.awt.ConnectionPanel; |
| 27 | import org.jogre.common.GameList; | 27 | import org.jogre.common.GameList; |
| 28 | import org.jogre.common.TransmissionException; | 28 | import org.jogre.common.TransmissionException; |
| 29 | import org.jogre.common.comm.Comm; | 29 | import org.jogre.common.comm.Comm; |
| 30 | import org.jogre.common.comm.CommAdminConnect; | 30 | import org.jogre.common.comm.CommAdminConnect; |
| 31 | import org.jogre.common.comm.CommAdminIconData; | 31 | import org.jogre.common.comm.CommAdminIconData; |
| 32 | import org.jogre.server.ServerProperties; | 32 | import org.jogre.server.ServerProperties; |
| 33 | 33 | ||
| 34 | /** | 34 | /** |
| 35 | * Connection panel for the server manager to connect to a server. | 35 | * Connection panel for the server manager to connect to a server. |
| 36 | * | 36 | * |
| 37 | * @author Bob | 37 | * @author Bob |
| 38 | * @version Beta 0.3 | 38 | * @version Beta 0.3 |
| 39 | */ | 39 | */ |
| 40 | public class AdminConnectionPanel extends ConnectionPanel { | 40 | public class AdminConnectionPanel extends ConnectionPanel { |
| 41 | 41 | ||
| 42 | /** Link the GUI. */ | 42 | /** Link the GUI. */ |
| 43 | private JogreServerAdministrator serverManager; | 43 | private JogreServerAdministrator serverManager; |
| 44 | 44 | ||
| 45 | /** Link to the client connection thread for the game. */ | 45 | /** Link to the client connection thread for the game. */ |
| 46 | private AdminClientConnectionThread conn = null; | 46 | private AdminClientConnectionThread conn = null; |
| 47 | 47 | ||
| 48 | /** | 48 | /** |
| 49 | * Constructor for an application which doesn't take a | 49 | * Constructor for an application which doesn't take a |
| 50 | * username / password. | 50 | * username / password. |
| 51 | * | 51 | * |
| 52 | * @param client Link to frame / applet. | 52 | * @param client Link to frame / applet. |
| 53 | */ | 53 | */ |
| 54 | public AdminConnectionPanel (JogreServerAdministrator serverManager) { | 54 | public AdminConnectionPanel (JogreServerAdministrator serverManager) { |
| 55 | super (); | 55 | super (); |
| 56 | 56 | ||
| 57 | this.serverManager = serverManager; | 57 | this.serverManager = serverManager; |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | /** | 60 | /** |
| 61 | * Override the connect method for handling traffic. | 61 | * Override the connect method for handling traffic. |
| 62 | * | 62 | * |
| 63 | * @see org.jogre.client.awt.ConnectionPanel#connect(java.lang.String, int, java.lang.String, java.lang.String) | 63 | * @see org.jogre.client.awt.ConnectionPanel#connect(java.lang.String, int, java.lang.String, java.lang.String) |
| 64 | */ | 64 | */ |
| 65 | protected void connect (Socket socket, | 65 | protected void connect (Socket socket, |
| 66 | String username, | 66 | String username, |
| 67 | String password) | 67 | String password) |
| 68 | { | 68 | { |
| 69 | // Create a new connection thread to handle communication | 69 | // Create a new connection thread to handle communication |
| 70 | this.conn = new AdminClientConnectionThread (socket, username, this); | 70 | this.conn = new AdminClientConnectionThread (socket, username, this); |
| 71 | conn.start(); // Start the thread | 71 | conn.getMessageBus().open(conn); // Start the thread |
| 72 | 72 | ||
| 73 | // Create a connect message. | 73 | // Create a connect message. |
| 74 | CommAdminConnect commConnect = new CommAdminConnect (username, password); | 74 | CommAdminConnect commConnect = new CommAdminConnect (username, password); |
| 75 | 75 | ||
| 76 | // Send connect message to the server. | 76 | // Send connect message to the server. |
| 77 | conn.send (commConnect); | 77 | conn.send (commConnect); |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | /** | 80 | /** |
| 81 | * Receive game message. | 81 | * Receive game message. |
| 82 | * | 82 | * |
| 83 | * @see org.jogre.client.IClient#receiveGameMessage(nanoxml.XMLElement) | 83 | * @see org.jogre.client.IClient#receiveGameMessage(nanoxml.XMLElement) |
| 84 | */ | 84 | */ |
| 85 | public void receiveGameMessage (XMLElement message) { | 85 | public void receiveGameMessage (XMLElement message) { |
| 86 | String messageType = message.getName(); | 86 | String messageType = message.getName(); |
| 87 | 87 | ||
| 88 | if (messageType.equals(Comm.GAME_LIST)) { | 88 | if (messageType.equals(Comm.GAME_LIST)) { |
| 89 | try { | 89 | try { |
| 90 | GameList gameList = new GameList (message); | 90 | GameList gameList = new GameList (message); |
| 91 | conn.setGameList (gameList); | 91 | conn.setGameList (gameList); |
| 92 | } | 92 | } |
| 93 | catch (TransmissionException transEx) {} | 93 | catch (TransmissionException transEx) {} |
| 94 | } else if (messageType.equals(Comm.ADMIN_ICON_DATA)) { | 94 | } else if (messageType.equals(Comm.ADMIN_ICON_DATA)) { |
| 95 | CommAdminIconData commIconData = new CommAdminIconData (message); | 95 | CommAdminIconData commIconData = new CommAdminIconData (message); |
| 96 | serverManager.setIconData(commIconData.getIconData()); | 96 | serverManager.setIconData(commIconData.getIconData()); |
| 97 | } | 97 | } |
| 98 | else if (messageType.equals(Comm.ADMIN_SERVER_PROPERTIES)) { | 98 | else if (messageType.equals(Comm.ADMIN_SERVER_PROPERTIES)) { |
| 99 | // User is sucessfully connected so set game object and return object. | 99 | // User is sucessfully connected so set game object and return object. |
| 100 | ServerProperties.setUpFromString(message.getContent()); | 100 | ServerProperties.setUpFromString(message.getContent()); |
| 101 | 101 | ||
| 102 | // Administration client should be good to go | 102 | // Administration client should be good to go |
| 103 | serverManager.connectOK (conn); | 103 | serverManager.connectOK (conn); |
| 104 | } else { | 104 | } else { |
| 105 | super.receiveGameMessage (message); | 105 | super.receiveGameMessage (message); |
| 106 | } | 106 | } |
| 107 | } | 107 | } |
| 108 | public void receiveTableMessage (XMLElement message, int tableNum) {} // does nothing | 108 | public void receiveTableMessage (XMLElement message, int tableNum) {} // does nothing |
| 109 | } | 109 | } |