My favorites | Sign in
Project Logo
                
Changes to /trunk/api/src/org/jogre/client/awt/GameConnectionPanel.java
r2 vs. r12   Edit
  Compare: vs.   Format:
Revision r12
Go to: 
Project members, sign in to write a code review
/trunk/api/src/org/jogre/client/awt/GameConnectionPanel.java   r2 /trunk/api/src/org/jogre/client/awt/GameConnectionPanel.java   r12
1 /* 1 /*
2 * JOGRE (Java Online Gaming Real-time Engine) - API 2 * JOGRE (Java Online Gaming Real-time Engine) - API
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.client.awt; 20 package org.jogre.client.awt;
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.ClientConnectionThread; 26 import org.jogre.client.ClientConnectionThread;
27 import org.jogre.common.Game; 27 import org.jogre.common.Game;
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.CommError; 30 import org.jogre.common.comm.CommError;
31 import org.jogre.common.comm.CommGameConnect; 31 import org.jogre.common.comm.CommGameConnect;
32 import org.jogre.common.util.GameProperties; 32 import org.jogre.common.util.GameProperties;
33 import org.jogre.common.util.JogreLabels; 33 import org.jogre.common.util.JogreLabels;
34 34
35 /** 35 /**
36 * Connection panel for games to connect. 36 * Connection panel for games to connect.
37 * 37 *
38 * @author Bob 38 * @author Bob
39 * @version Beta 0.3 39 * @version Beta 0.3
40 */ 40 */
41 public class GameConnectionPanel extends ConnectionPanel { 41 public class GameConnectionPanel extends ConnectionPanel {
42 42
43 /** Link the GUI. */ 43 /** Link the GUI. */
44 private IJogreGUI client; 44 private IJogreGUI client;
45 45
46 /** Link to the client connection thread for the game. */ 46 /** Link to the client connection thread for the game. */
47 private ClientConnectionThread conn = null; 47 private ClientConnectionThread conn = null;
48 48
49 /** 49 /**
50 * Constructor for an application which doesn't take a 50 * Constructor for an application which doesn't take a
51 * username / password. 51 * username / password.
52 * 52 *
53 * @param client Link to frame / applet. 53 * @param client Link to frame / applet.
54 */ 54 */
55 public GameConnectionPanel (IJogreGUI client) { 55 public GameConnectionPanel (IJogreGUI client) {
56 super (); 56 super ();
57 57
58 this.client = client; 58 this.client = client;
59 } 59 }
60 60
61 /** 61 /**
62 * Silent connect which takes a server, port, username and password. 62 * Silent connect which takes a server, port, username and password.
63 * 63 *
64 * @param client Link to frame / applet. 64 * @param client Link to frame / applet.
65 * @param server Name of the server. 65 * @param server Name of the server.
66 * @param port Server port. 66 * @param port Server port.
67 * @param username Username of person trying to connect. 67 * @param username Username of person trying to connect.
68 * @param password Password of the person trying to connect. 68 * @param password Password of the person trying to connect.
69 */ 69 */
70 public GameConnectionPanel (IJogreGUI client, 70 public GameConnectionPanel (IJogreGUI client,
71 String server, 71 String server,
72 int port, 72 int port,
73 String username, 73 String username,
74 String password) 74 String password)
75 { 75 {
76 super (server, port, username, password); 76 super (server, port, username, password);
77 77
78 this.client = client; 78 this.client = client;
79 } 79 }
80 /** 80 /**
81 * Override the connect method for handling game traffic. 81 * Override the connect method for handling game traffic.
82 * 82 *
83 * @see org.jogre.client.awt.ConnectionPanel#connect(java.lang.String, int, java.lang.String, java.lang.String) 83 * @see org.jogre.client.awt.ConnectionPanel#connect(java.lang.String, int, java.lang.String, java.lang.String)
84 */ 84 */
85 protected void connect (Socket socket, 85 protected void connect (Socket socket,
86 String username, 86 String username,
87 String password) 87 String password)
88 { 88 {
89 // Create a new connection thread to handle communication 89 // Create a new connection thread to handle communication
90 this.conn = new ClientConnectionThread (socket, username, this); 90 this.conn = new ClientConnectionThread (socket, username, this);
91 conn.start(); // Start the thread 91 conn.getMessageBus().open(conn); // Start the thread
92 92
93 // Create a connect message. 93 // Create a connect message.
94 CommGameConnect commConnect; 94 CommGameConnect commConnect;
95 if (password.equals ("")) 95 if (password.equals (""))
96 commConnect = new CommGameConnect 96 commConnect = new CommGameConnect
97 (username, GameProperties.getGameID()); 97 (username, GameProperties.getGameID());
98 else 98 else
99 commConnect = new CommGameConnect 99 commConnect = new CommGameConnect
100 (username, password, GameProperties.getGameID()); 100 (username, password, GameProperties.getGameID());
101 101
102 // Send connect message to the server. 102 // Send connect message to the server.
103 conn.send (commConnect); 103 conn.send (commConnect);
104 104
105 } 105 }
106 106
107 /** 107 /**
108 * @see org.jogre.client.IClient#receiveGameMessage(nanoxml.XMLElement) 108 * @see org.jogre.client.IClient#receiveGameMessage(nanoxml.XMLElement)
109 */ 109 */
110 public void receiveGameMessage (XMLElement message) { 110 public void receiveGameMessage (XMLElement message) {
111 String messageType = message.getName(); 111 String messageType = message.getName();
112 112
113 // Message could be 113 // Message could be
114 // <error> - Error message. 114 // <error> - Error message.
115 // <game> - Game message (success) 115 // <game> - Game message (success)
116 if (messageType.equals (Comm.ERROR)) { 116 if (messageType.equals (Comm.ERROR)) {
117 // Create comm object and create error description 117 // Create comm object and create error description
118 CommError commError = new CommError (message); 118 CommError commError = new CommError (message);
119 String errorStr = JogreLabels.getError (commError.getStatus()); 119 String errorStr = JogreLabels.getError (commError.getStatus());
120 120
121 // Update label 121 // Update label
122 statusLabel.setText (errorStr); 122 statusLabel.setText (errorStr);
123 } 123 }
124 else if (messageType.equals (Comm.GAME)) { 124 else if (messageType.equals (Comm.GAME)) {
125 try { 125 try {
126 // Create game object on connection 126 // Create game object on connection
127 conn.setGame (new Game (message)); 127 conn.setGame (new Game (message));
128 128
129 // User is sucessfully connected so set game object and return object. 129 // User is sucessfully connected so set game object and return object.
130 client.connectOK (conn); 130 client.connectOK (conn);
131 } 131 }
132 catch (TransmissionException tEx) {} 132 catch (TransmissionException tEx) {}
133 } 133 }
134 } 134 }
135 135
136 public void receiveTableMessage (XMLElement message, int tableNum) {} // does nothing 136 public void receiveTableMessage (XMLElement message, int tableNum) {} // does nothing
137 } 137 }
Hosted by Google Code