[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Camino-devel] camino/src client/ClientEngine.cpp client/Clien...
From: |
Philippe Fremy |
Subject: |
[Camino-devel] camino/src client/ClientEngine.cpp client/Clien... |
Date: |
Tue, 28 Jan 2003 16:54:28 -0500 |
CVSROOT: /cvsroot/camino
Module name: camino
Changes by: Philippe Fremy <address@hidden> 03/01/28 16:54:27
Modified files:
src/client : ClientEngine.cpp ClientInterface.cpp
ClientInterface.h
src/common : Board.cpp PhilAsserts.h PhilTestRunner.h
src/server : CaminoServer.cpp CaminoServer.h Player.cpp
Player.h ServerDialog.cpp ServerDialog.h
ServerDialogUI.ui
Log message:
bugfix: msg was also inside the typestring
Patches:
Index: camino/src/client/ClientEngine.cpp
diff -u camino/src/client/ClientEngine.cpp:1.4
camino/src/client/ClientEngine.cpp:1.5
--- camino/src/client/ClientEngine.cpp:1.4 Mon Jan 27 17:52:53 2003
+++ camino/src/client/ClientEngine.cpp Tue Jan 28 16:54:27 2003
@@ -2,7 +2,7 @@
**
** Camino
**
-** Version : $Id: ClientEngine.cpp,v 1.4 2003/01/27 22:52:53 Audoux Exp $
+** Version : $Id: ClientEngine.cpp,v 1.5 2003/01/28 21:54:27 pfremy Exp $
**
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 14/01/2003
@@ -87,7 +87,6 @@
break;
}
- typeString += source + " : " + msg;
qDebug( "Client - %s from %s : %s", typeString.latin1(),
source.latin1(), msg.latin1() );
QString text = source + " : " + msg;
emit sig_message( text );
Index: camino/src/client/ClientInterface.cpp
diff -u camino/src/client/ClientInterface.cpp:1.11
camino/src/client/ClientInterface.cpp:1.12
--- camino/src/client/ClientInterface.cpp:1.11 Mon Jan 27 17:52:53 2003
+++ camino/src/client/ClientInterface.cpp Tue Jan 28 16:54:27 2003
@@ -2,7 +2,7 @@
**
** Camino
**
-** Version : $Id: ClientInterface.cpp,v 1.11 2003/01/27 22:52:53 Audoux Exp $
+** Version : $Id: ClientInterface.cpp,v 1.12 2003/01/28 21:54:27 pfremy Exp $
**
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 15/01/2003
@@ -32,19 +32,29 @@
#include <qsignalmapper.h>
#include <qstatusbar.h>
#include <qlineedit.h>
+#include <qpushbutton.h>
+
// application specific include files
#include "client/DialogConnection.h"
#include "client/Game.h"
-#include "server/ServerDialog.h"
#include "client/Theme.h"
-
#include "client/ClientInterface.h"
+#include "client/ClientEngine.h"
+
+#include "server/ServerDialog.h"
+#include "server/CaminoServer.h"
+#include "server/ServerWidget.h"
+
extern Theme theme;
ClientInterface::ClientInterface()
{
+ _clientEngine = new ClientEngine();
+ _serverDialog = 0;
_server = 0;
+ _serverWidget = 0;
+
setCaption( "Camino" );
initActions();
initMenuBar();
@@ -63,8 +73,8 @@
void ClientInterface::closeEvent( QCloseEvent* event )
{
- quitting();
- event->accept();
+ quitting();
+ event->accept();
}
#define CREATEACTION( text, menuText, num ) action = new QAction( this ); \
@@ -128,7 +138,7 @@
{
switch( num ) {
case ACT_SERVER:
- launchServer();
+ launchServerDialog();
break;
case ACT_CONNECT:
connectToServer();
@@ -162,15 +172,22 @@
qApp->quit();
}
-void ClientInterface::launchServer()
+void ClientInterface::launchServerDialog()
{
- if( _server ) {
- QMessageBox::warning( this, "Warning", "Server already started"
);
- } else {
- _server = new ServerDialog( this );
- _server->show();
- connect( _server, SIGNAL( sig_quit() ), SLOT( slot_quitServer()
) );
+ // if server widget, raise server widget
+
+ if( _serverDialog ) {
+ _serverDialog->raise();
+ return;
}
+
+ // add a test on server.
+
+ _serverDialog = new ServerDialog( this );
+ connect( _serverDialog, SIGNAL( sig_quit() ), SLOT(
slot_quitServerDialog() ) );
+ connect( _serverDialog, SIGNAL( sig_serverStarted( CaminoServer *,
ServerWidget * ) ),
+ SLOT(slot_serverStarted( CaminoServer *,
ServerWidget * )) );
+ _serverDialog->show();
}
void ClientInterface::connectToServer()
@@ -183,12 +200,13 @@
}
}
-void ClientInterface::slot_quitServer()
+void ClientInterface::slot_quitServerDialog()
{
- if( _server ) {
- delete _server;
- _server = 0;
+ if( _serverDialog ) {
+ delete _serverDialog;
+ _serverDialog = 0;
}
+
}
void ClientInterface::zoom( int level )
@@ -210,4 +228,23 @@
theme.setZoomLevel( level );
//_game->reupdate();
}
+
+// the server widget must be created with the server, else, it loses some
messages
+void ClientInterface::slot_serverStarted( CaminoServer * server, ServerWidget
* serverWidget)
+{
+ qDebug("ClientInterface::slot_caminoServerStarted!");
+
+ if (_server) {
+ delete _server;
+ _server = 0L;
+ }
+ _server = server;
+ if (server == 0L) {
+ return;
+ }
+
+ _serverWidget = serverWidget;
+ _serverWidget->show();
+}
+
Index: camino/src/client/ClientInterface.h
diff -u camino/src/client/ClientInterface.h:1.9
camino/src/client/ClientInterface.h:1.10
--- camino/src/client/ClientInterface.h:1.9 Mon Jan 27 17:52:53 2003
+++ camino/src/client/ClientInterface.h Tue Jan 28 16:54:27 2003
@@ -5,7 +5,7 @@
** ClientInterface.h
** Interface of the client
**
-** Version : $Id: ClientInterface.h,v 1.9 2003/01/27 22:52:53 Audoux Exp $
+** Version : $Id: ClientInterface.h,v 1.10 2003/01/28 21:54:27 pfremy Exp $
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 14/01/2003
** Copyright: Pascal Audoux, Philippe Fremy 2003
@@ -39,6 +39,9 @@
class Game;
class ServerDialog;
+class ServerWidget;
+class CaminoServer;
+class ClientEngine;
/* ------------------------------
* ClientInterface
@@ -65,7 +68,10 @@
void slot_status( QString text );
/** Slot for destroying the server dialog */
- void slot_quitServer();
+ void slot_quitServerDialog();
+
+ /** when the serverdialog finishes, it calls this slot */
+ void slot_serverStarted( CaminoServer * server, ServerWidget *);
protected:
void closeEvent( QCloseEvent* );
@@ -95,14 +101,17 @@
void quitting();
- void launchServer();
+ void launchServerDialog();
void connectToServer();
void zoom( int level );
Game * _game;
- ServerDialog * _server;
+ ClientEngine * _clientEngine;
+ ServerDialog * _serverDialog;
+ CaminoServer * _server;
+ ServerWidget * _serverWidget;
QAction * _actions[NUMBER_OF_ACTION];
};
Index: camino/src/common/Board.cpp
diff -u camino/src/common/Board.cpp:1.3 camino/src/common/Board.cpp:1.4
--- camino/src/common/Board.cpp:1.3 Sun Jan 26 04:50:00 2003
+++ camino/src/common/Board.cpp Tue Jan 28 16:54:27 2003
@@ -2,7 +2,7 @@
**
** Camino
**
-** Version : $Id: Board.cpp,v 1.3 2003/01/26 09:50:00 Audoux Exp $
+** Version : $Id: Board.cpp,v 1.4 2003/01/28 21:54:27 pfremy Exp $
**
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 16/01/2003
@@ -88,7 +88,7 @@
return ret;
}
-bool Board::isPossible( int row, int col, Tile * tile )
+bool Board::isPossible( int row, int col, Tile * /* tile */ )
{
bool ret = true;
@@ -133,7 +133,7 @@
return ret;
}
-int Board::computeRotation( int row, int col, Tile * tile )
+int Board::computeRotation( int /* row */, int /* col */, Tile * /* tile */ )
{
int ret = 0;
Index: camino/src/common/PhilAsserts.h
diff -u camino/src/common/PhilAsserts.h:1.2 camino/src/common/PhilAsserts.h:1.3
--- camino/src/common/PhilAsserts.h:1.2 Sun Jan 26 16:53:30 2003
+++ camino/src/common/PhilAsserts.h Tue Jan 28 16:54:27 2003
@@ -8,6 +8,76 @@
#include <cppunit/TestAssert.h>
#include <string>
+/**
+ * This is a set of replacements for the default asserts of CppUnit. This
+ * works with CppUnit 1.8.0 . Thank to the architecture of CppUnit, it
+ * integrates seemlessly.
+ *
+ * The differences are:
+ *
+ * - my asserts are shorter and easier to type because I do not prepend them
+ * by CPPUNIT_ and because I use mainly non capitalised letters. This does
+ * not respect the convention that macros should be in capitalised letters
+ * but it saves me a lot of pain, so it is worthwile.
+ *
+ * - the order of equality assertion is reversed, because it is more intuitive
+ * for me to have the actual value before the expected one. So
+ * CPPUNIT_ASSERT_EQUALS( 1, a ) becomes checkEquals( a, 1 )
+ *
+ * - I display the name of the expression being tested inside the failure, not
+ * just the value that did not match.
+ *
+ * - for int equality asserts, I display the int value in decimal and
+ * hexadecimal
+ *
+ * - I support native string equality tests, which avoids the following
+ * drawbacks of CppUnit:
+ *
+ * 1. With Visual C++, CPPUNIT_ASSERT_EQUAL( std::string("a"), "a" )
+ * won't compile because the it does not know which template to use.
+ *
+ * 2. If you do a
+ *
+ char * s1 = "abcd";
+ char s2[10];
+ strcpy( s2, s1);
+ CPPUNIT_ASSERT_EQUAL( s1, (char *) s2 );
+
+ * CppUnit will report a failure with the unhelpful message :
+ *
+ * "Expected: abcd, but was: abcd."
+ *
+ * This is because CppUnit has unintuitively compared the two
pointers
+ * instead of comparing the strings. My functions know how to cast
a
+ * (char *) to a string
+ *
+ *
+ * - when displaying an error with a string, my strings are in quote, so that
+ * you can see precicely where it begins and finish. No more
+ * your-strings-are-not-equal-but-you-do-not-know-why-because-you-have-
+ * not-seen-this-naughty-space-at-the-end-of-one-of-them.
+ *
+ * - for string equality asserts, I support case sensitive and insenstive
+ * check.
+ *
+ * - I support also a assertion to test whether a string contains another one,
+ * with adjustable case sensitivity
+ *
+ * - if you define QT_DLL, I support tests on QString too
+ *
+ *
+ * This list of macros available are :
+ * check( assertion ) for bool
+ * checkEquals( actual, expected ) for int, long, double, std::string, QString
and char *
+ * checkNotEquals( actual, notExpected ) for the same types as checkEquals
+ * checkDeltaEquals( doubleValue1, doubleValue2 ) for double
+ * checkIEquals( s1, s2 ) for std::string, QString, (char *)
+ * checkContains( s1, s2 ) for std::string, QString, (char *)
+ * checkIContains( s1, s2 ) for std::string, QString, (char *)
+ *
+ * Send any bug, comment, suggestion, patch to address@hidden
+ *
+ */
void philAssert( std::string actualExpr, bool assertion,
long lineNumber, std::string fileName );
@@ -39,8 +109,6 @@
#ifdef QT_DLL
#include <qstring.h>
-// #warning( "compiling PhilAsserts.h with Qt support" )
-
/* It is necessary to provide QString functions, because VC++ does not cast
* QString to char * or std::string
*/
@@ -59,37 +127,29 @@
inline void philAssertIContains( std::string actualExpr, QString string,
QString substring,
long lineNumber, std::string
fileName );
-// ---- Implementation
-
-inline std::string convert( QString s )
-{
- if (s.latin1()) return std::string( s.latin1() );
- return std::string();
-}
-
inline void philAssertEquals( std::string actualExpr, QString actual, QString
expected,
long lineNumber, std::string fileName
) {
- philAssertEquals( actualExpr, convert( actual ),
- convert( expected ), lineNumber, fileName );
+ philAssertEquals( actualExpr, std::string( actual.latin1() ),
+ std::string( expected.latin1() ), lineNumber, fileName );
}
inline void philAssertIEquals( std::string actualExpr, QString actual, QString
expected,
long lineNumber, std::string
fileName ) {
- philAssertIEquals( actualExpr, convert( actual ), convert( expected),
lineNumber, fileName );
+ philAssertIEquals( actualExpr, std::string(actual.latin1()),
std::string( expected.latin1()), lineNumber, fileName );
}
inline void philAssertNotEquals( std::string actualExpr, QString actual,
QString expected,
long lineNumber, std::string
fileName ) {
- philAssertNotEquals( actualExpr, convert( actual), convert(expected),
lineNumber, fileName );
+ philAssertNotEquals( actualExpr, std::string( actual.latin1()),
std::string(expected.latin1()), lineNumber, fileName );
}
inline void philAssertContains( std::string actualExpr, QString string,
QString substring,
long lineNumber, std::string
fileName ) {
- philAssertContains( actualExpr, convert(string), convert(substring),
lineNumber, fileName );
+ philAssertContains( actualExpr, std::string(string.latin1()),
std::string(substring.latin1()), lineNumber, fileName );
}
inline void philAssertIContains( std::string actualExpr, QString string,
QString substring, long lineNumber, std::string fileName ) {
- philAssertIContains( actualExpr, convert(string), convert(substring),
lineNumber, fileName );
+ philAssertIContains( actualExpr, std::string(string.latin1()),
std::string(substring.latin1()), lineNumber, fileName );
}
#endif // Qt
Index: camino/src/common/PhilTestRunner.h
diff -u camino/src/common/PhilTestRunner.h:1.1
camino/src/common/PhilTestRunner.h:1.2
--- camino/src/common/PhilTestRunner.h:1.1 Sun Jan 19 17:33:11 2003
+++ camino/src/common/PhilTestRunner.h Tue Jan 28 16:54:27 2003
@@ -14,7 +14,8 @@
* I wrote this class because I was dissatisfied with the text runner of
* CppUnit. In fact, except for the concept of running test suites, I am
* dissatisfied with CppUnit. I find the overall architecture very complex,
- * and still not as helpful as I wish it were.
+ * and still not as helpful as I wish it were. This works with CppUnit 1.8.0
+ * I don't think it work with any other version.
*
* The goal of PhilTestRunner was for me to make the output of the testing
* more readable and useful. It has the following characteristics:
@@ -22,7 +23,7 @@
* - it prints the name of the suite being run and separate two suites with a
* blank line, so that you know better in which suite you are.
*
- * - it prints the name of the test being run, so that if you have some kind
+ * - it prints the name of the test being run, so that when you have some kind
* of debug output, you know to which test it belongs.
*
* - the failures are reported in detail while the suite still runs, directly
@@ -47,6 +48,7 @@
+ testTwo
d:\software\cppunit-1.8.0\testunitexample\testfoo.cpp(40) : Failure!
Expected: 7, but was: 2.
+
+ testThree
d:\software\cppunit-1.8.0\testunitexample\testfoo.cpp(45) : Failure!
Uh uh, this test failed
@@ -65,6 +67,9 @@
runner.addTest( CppUnit::TestFactoryRegistry::getRegistry().makeTest()
);
return runner.run( "", false, true, true );
+ *
+ *
+ * Send any comment, bug, suggestion, patch to address@hidden
*
*/
Index: camino/src/server/CaminoServer.cpp
diff -u camino/src/server/CaminoServer.cpp:1.7
camino/src/server/CaminoServer.cpp:1.8
--- camino/src/server/CaminoServer.cpp:1.7 Sun Jan 26 17:15:20 2003
+++ camino/src/server/CaminoServer.cpp Tue Jan 28 16:54:27 2003
@@ -2,7 +2,7 @@
**
** Camino
**
-** Version : $Id: CaminoServer.cpp,v 1.7 2003/01/26 22:15:20 pfremy Exp $
+** Version : $Id: CaminoServer.cpp,v 1.8 2003/01/28 21:54:27 pfremy Exp $
**
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 19/01/2003
@@ -33,54 +33,69 @@
#include "server/Player.h"
-CaminoServer::CaminoServer( int port )
+CaminoServer::CaminoServer( int port, int playerNb )
: QServerSocket( port )
{
- _num = 0;
- _currentSocket = 0;
- _theSockets.setAutoDelete( true );
- _mapper = new QSignalMapper( this );
- connect( _mapper, SIGNAL( mapped( int ) ), SIGNAL( sig_readEvent( int
) ) );
+ _playerNb = playerNb;
+ _state = WaitingForConnection;
}
void CaminoServer::newConnection( int numSocket )
{
- //logDD("Connection to the server");
+ QSocket * uneso = new QSocket;
+ uneso->setSocket( numSocket );
- // if number of player has been reached, reject connection
-
- QSocket * uneso = new QSocket;
- uneso->setSocket( numSocket );
- _theSockets.append( uneso );
+ // if number of player has been reached, reject connection
+ if ( _playerList.count() == (uint) _playerNb ) {
+ uneso->close();
+ qDebug("CaminoServer::newConnection - reject connection because
number of player has been reached");
+ return;
+ }
+
+ _playerList.append( new Player( uneso, this ) );
+}
+void CaminoServer::broadcastMsg( NetMsgSubtype msgLevel, QString source,
QString msg )
+{
+ QPtrListIterator<Player> it( _playerList );
+ while( it.current() ) {
+ it.current()->sendMsg( msgLevel, source, msg );
+ ++it;
+ }
+}
- _playerList.append( new Player( uneso, this ) );
- qDebug("Camino Server - player appended to list" );
+bool CaminoServer::isPlayerNameValid( QString playerName )
+{
+ QPtrListIterator<Player> it( _playerList );
+ while( it.current() ) {
+ if (it.current()->getPlayerName().isEmpty() == false
+ && it.current()->getPlayerName() == playerName ) {
+ return false;
+ }
+ ++it;
+ }
+ return true;
+}
- _mapper->setMapping( uneso, _theSockets.count()-1 );
- connect( uneso, SIGNAL( readyRead() ), _mapper, SLOT( map() ) );
- //connect( uneso, SIGNAL( connectionClosed() ), SLOT(
slot_socketClose() ) );
- //emit sig_newConnection( uneso );
- // XXX: uneso->sendConnectionOk();
+void CaminoServer::setTeamConfiguration( int /* teamConfiguration */ )
+{
+ // sort players accorging to team configuration
+ beginParty();
}
-void CaminoServer::recvServerConnect( QString hostName, QString playerName )
+void CaminoServer::beginParty()
{
- qDebug("CaminoServer - recv client name : %s", playerName.latin1() );
+ if (_state != SelectTeam && _state != WaitingForConnection ) {
+ QString s = QString("CaminoServer::beginParty - unexpected
state : %1").arg(_state);
+ qWarning("%s", s.latin1() );
+ serverBroadcastMsg( DebugMsg, s );
+ return;
+ }
- // check if player name is valid
- // if player name is invalid notify all clients
+ serverBroadcastMsg( InfoMsg, "Distributing tiles" );
+ _state = BeginParty;
- emit sig_playerConnected( playerName, hostName );
- broadcastMsg( InfoMsg, "Server", playerName +" from " + hostName + "
has connected!");
+ // ...
}
-void CaminoServer::broadcastMsg( NetMsgSubtype msgLevel, QString source,
QString msg )
-{
- QPtrListIterator<Player> it( _playerList );
- while( it.current() ) {
- it.current()->sendMsg( msgLevel, source, msg );
- ++it;
- }
-}
Index: camino/src/server/CaminoServer.h
diff -u camino/src/server/CaminoServer.h:1.6
camino/src/server/CaminoServer.h:1.7
--- camino/src/server/CaminoServer.h:1.6 Sun Jan 26 16:54:29 2003
+++ camino/src/server/CaminoServer.h Tue Jan 28 16:54:27 2003
@@ -5,7 +5,7 @@
** CaminoServer.h
** Server for the game
**
-** Version : $Id: CaminoServer.h,v 1.6 2003/01/26 21:54:29 pfremy Exp $
+** Version : $Id: CaminoServer.h,v 1.7 2003/01/28 21:54:27 pfremy Exp $
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 19/01/2003
** Copyright: Pascal Audoux, Philippe Fremy 2003
@@ -38,11 +38,16 @@
#include "server/Player.h"
class QSignalMapper;
+class Player;
/* ------------------------------
* CaminoServer
* ------------------------------ */
+#ifdef DEBUG
+class TestCaminoServer;
+#endif
+
/** comment for the class */
@@ -52,27 +57,47 @@
public:
/** Constructor */
- CaminoServer( int port );
+ CaminoServer( int port, int playerNb );
- void newConnection ( int numSocket );
- void recvServerConnect( QString hostName, QString playerName );
+ enum ServerState {
+ WaitingForConnection,
+ SelectTeam,
+ BeginParty,
+ PlayGame,
+ UndoRequested,
+ EndOfGameRequested,
+ EndOfGame,
+ PlayerCompletesTheBoard,
+ WaitForOtherPlayersToCompletTheBoard,
+ EndOfParty
+ };
+ void newConnection ( int numSocket );
+ bool isPlayerNameValid( QString playerName );
void broadcastMsg( NetMsgSubtype msgLevel, QString source, QString msg
);
+ void serverBroadcastMsg( NetMsgSubtype msgLevel, QString msg ) {
broadcastMsg( msgLevel, "Server", msg); }
+ void setTeamConfiguration( int teamConfiguration );
+ void beginParty();
signals:
- void sig_readEvent( int );
void sig_newConnection( QSocket * );
void sig_endConnection( QString name );
void sig_playerConnected( QString hostName, QString playerName );
+ void sig_selectTeam();
+ void sig_msg( NetMsgSubtype level, QString source, QString msg );
protected:
QPtrList<Player> _playerList;
- QPtrList<QSocket> _theSockets;
- QSocket * _currentSocket;
- QSignalMapper * _mapper;
- uint _num;
+ int _playerNb;
+ ServerState _state;
+
+friend class Player;
+#ifdef DEBUG
+friend class TestCaminoServer;
+#endif
+
};
#endif // CAMINOSERVER_H
Index: camino/src/server/Player.cpp
diff -u camino/src/server/Player.cpp:1.3 camino/src/server/Player.cpp:1.4
--- camino/src/server/Player.cpp:1.3 Sun Jan 26 16:53:58 2003
+++ camino/src/server/Player.cpp Tue Jan 28 16:54:27 2003
@@ -2,7 +2,7 @@
**
** Camino
**
-** Version : $Id: Player.cpp,v 1.3 2003/01/26 21:53:58 pfremy Exp $
+** Version : $Id: Player.cpp,v 1.4 2003/01/28 21:54:27 pfremy Exp $
**
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 14/01/2003
@@ -35,11 +35,10 @@
Player::Player( QSocket * socket, CaminoServer * caminoServer)
: MsgCoder( socket ), MsgDecoder( socket )
{
- _caminoServer = caminoServer;
+ _server = caminoServer;
_socket = socket;
connect( socket, SIGNAL( readyRead() ), SLOT( slotDecode() ) );
- qDebug("Player::Player - Socket = %p, caminoServer = %p", socket,
caminoServer );
}
void Player::slotDecode()
@@ -52,6 +51,37 @@
void Player::recvServerConnect( QString playerName )
{
- qDebug("Player - recvServerConnect - %s", playerName.latin1() );
- _caminoServer->recvServerConnect( _socket->address().toString(),
playerName );
+ // normally, this a client can not connect a server if it has enough
players.
+
+ if ( _server->isPlayerNameValid( playerName ) == false ) {
+ _server->serverBroadcastMsg( InfoMsg,
+ QString( "rejects connection with existing player name
%1").arg(playerName)
+ );
+ _socket->close();
+ return;
+ }
+
+ // check client version
+
+ QString hostName = _socket->address().toString();
+ _server->sig_playerConnected( playerName, hostName );
+ _server->serverBroadcastMsg( InfoMsg, playerName +" from " + hostName + "
has connected!");
+ setPlayerName( playerName );
+
+ if ( _server->_playerList.count() == (uint) _server->_playerNb ) {
+ if ( _server->_playerNb > 2) {
+ _server->_state = CaminoServer::SelectTeam;
+ emit _server->sig_selectTeam();
+ } else {
+ emit _server->sig_selectTeam(); // normally not
necessary in two players mode
+ _server->beginParty();
+ }
+ }
+}
+
+void Player::recvMsg( QString source, QString msg )
+{
+ _server->sig_msg( _subtype, source, msg );
}
+
+
Index: camino/src/server/Player.h
diff -u camino/src/server/Player.h:1.3 camino/src/server/Player.h:1.4
--- camino/src/server/Player.h:1.3 Sun Jan 26 16:53:58 2003
+++ camino/src/server/Player.h Tue Jan 28 16:54:27 2003
@@ -5,7 +5,7 @@
** Player.h
** this is a template for all .h files
**
-** Version : $Id: Player.h,v 1.3 2003/01/26 21:53:58 pfremy Exp $
+** Version : $Id: Player.h,v 1.4 2003/01/28 21:54:27 pfremy Exp $
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 14/01/2003
** Copyright: Pascal Audoux, Philippe Fremy 2003
@@ -52,17 +52,20 @@
Player( QSocket * , CaminoServer * );
void setPlayerName( QString & playerName ) { _playerName = playerName; }
+ const QString & getPlayerName() { return _playerName; }
+
virtual void slotDecode();
virtual void recvServerConnect( QString playerName );
+ virtual void recvMsg( QString source, QString msg );
protected:
- CaminoServer * _caminoServer;
+ CaminoServer * _server;
QString _playerName;
QSocket * _socket;
-
+friend class CaminoServer;
};
#endif // PLAYER_H
Index: camino/src/server/ServerDialog.cpp
diff -u camino/src/server/ServerDialog.cpp:1.8
camino/src/server/ServerDialog.cpp:1.9
--- camino/src/server/ServerDialog.cpp:1.8 Sun Jan 26 17:28:54 2003
+++ camino/src/server/ServerDialog.cpp Tue Jan 28 16:54:27 2003
@@ -2,7 +2,7 @@
**
** Camino
**
-** Version : $Id: ServerDialog.cpp,v 1.8 2003/01/26 22:28:54 pfremy Exp $
+** Version : $Id: ServerDialog.cpp,v 1.9 2003/01/28 21:54:27 pfremy Exp $
**
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 14/01/2003
@@ -30,9 +30,12 @@
#include <qradiobutton.h>
#include <qlineedit.h>
#include <qlistview.h>
+
// application specific include files
#include "ServerDialog.h"
#include "server/CaminoServer.h"
+#include "server/ServerWidget.h"
+
#include "common/log.h"
ServerDialog::ServerDialog( QWidget * parent, const char * name )
@@ -43,7 +46,11 @@
setFinishEnabled( _pageTeam, true );
setNextEnabled( _pageWaitConnection, false );
+ helpButton()->hide();
+ backButton()->hide();
+
_server = 0L;
+ _serverWidget = 0L;
connect( _2players, SIGNAL( clicked() ), SLOT( slot_2players() ) );
connect( _4players, SIGNAL( clicked() ), SLOT( slot_4players() ) );
@@ -106,20 +113,55 @@
int portNumber = _ipPortNb->text().toInt();
- qDebug("ServerDialog - Port number : %d", portNumber );
+ qDebug("ServerDialog - starting server on port : %d", portNumber );
+
+ _server = new CaminoServer( portNumber, _nb );
+ _serverWidget = new ServerWidget( _server );
+ _serverWidget->hide();
- _server = new CaminoServer( portNumber );
connect( _server, SIGNAL( sig_playerConnected(QString,QString)),
- SLOT( slotPlayerConnected(QString,QString)) );
+ SLOT( slot_playerConnected(QString,QString)) );
+ connect ( _server, SIGNAL( sig_selectTeam() ), SLOT( slot_selectTeam()
) );
+ connect( _server, SIGNAL( sig_msg( NetMsgSubtype, QString, QString )
),
+ _serverWidget, SLOT( slot_appendMsg( NetMsgSubtype,
QString, QString ) ) );
}
-void ServerDialog::slotPlayerConnected( QString hostName, QString playerName )
+void ServerDialog::slot_playerConnected( QString hostName, QString playerName )
{
qDebug("ServerDialog - slotPlayerConnected!");
new QListViewItem( _playerList, playerName, hostName );
}
+void ServerDialog::slot_selectTeam()
+{
+ Q_ASSERT( _playerList->childCount() >= _nb);
+ setNextEnabled( _pageWaitConnection, true );
+}
+void ServerDialog::accept()
+{
+ if (_nb != 2) {
+ _server->setTeamConfiguration( _team );
+ }
+ emit sig_serverStarted( _server, _serverWidget );
+ ServerDialogUI::accept();
+ emit sig_quit();
+}
+void ServerDialog::reject()
+{
+ // to avoid memory leaks
+ if (_server) {
+ delete _server;
+ _server = 0;
+ }
+ if (_serverWidget) {
+ delete _serverWidget;
+ _serverWidget = 0;
+ }
+
+ ServerDialogUI::reject();
+ emit sig_quit();
+}
Index: camino/src/server/ServerDialog.h
diff -u camino/src/server/ServerDialog.h:1.7
camino/src/server/ServerDialog.h:1.8
--- camino/src/server/ServerDialog.h:1.7 Sun Jan 26 17:28:54 2003
+++ camino/src/server/ServerDialog.h Tue Jan 28 16:54:27 2003
@@ -5,7 +5,7 @@
** ServerDialog.h
** Main dialog of the server
**
-** Version : $Id: ServerDialog.h,v 1.7 2003/01/26 22:28:54 pfremy Exp $
+** Version : $Id: ServerDialog.h,v 1.8 2003/01/28 21:54:27 pfremy Exp $
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 15/01/2003
** Copyright: Pascal Audoux, Philippe Fremy 2003
@@ -39,6 +39,7 @@
* ------------------------------ */
class CaminoServer;
+class ServerWidget;
/** comment for the class */
class ServerDialog : public ServerDialogUI
@@ -52,7 +53,7 @@
CaminoServer * getServer() { return _server; }
- virtual void slotPlayerConnected( QString hostName, QString playerName );
+ virtual void slot_playerConnected( QString hostName, QString playerName );
public slots:
void slot_2players();
@@ -62,14 +63,21 @@
void slot_team3();
void slot_selection( const QString & title );
+ void slot_selectTeam(); // advance to select team
signals:
void sig_quit();
+ void sig_serverStarted( CaminoServer *, ServerWidget * );
+
+protected:
+ virtual void reject();
+ virtual void accept();
protected:
int _nb;
int _team;
CaminoServer * _server;
+ ServerWidget * _serverWidget;
};
Index: camino/src/server/ServerDialogUI.ui
diff -u camino/src/server/ServerDialogUI.ui:1.5
camino/src/server/ServerDialogUI.ui:1.6
--- camino/src/server/ServerDialogUI.ui:1.5 Sun Jan 26 17:28:54 2003
+++ camino/src/server/ServerDialogUI.ui Tue Jan 28 16:54:27 2003
@@ -103,6 +103,12 @@
<property name="name">
<cstring>_ipPortNb</cstring>
</property>
+ <property name="frameShape">
+ <enum>LineEditPanel</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>Sunken</enum>
+ </property>
<property name="text">
<string>6789</string>
</property>
@@ -235,8 +241,8 @@
</widget>
</widget>
<slots>
- <slot>slotStartGame()</slot>
- <slot>slotPlayerConnected( QString, QString )</slot>
+ <slot>slot_startGame()</slot>
+ <slot>slot_playerConnected( QString, QString )</slot>
</slots>
<layoutdefaults spacing="6" margin="11"/>
</UI>