[Orxonox-commit 2877] r7580 - code/branches/masterserver/src/modules/masterserver
smerkli at orxonox.net
smerkli at orxonox.net
Sun Oct 24 20:33:58 CEST 2010
Author: smerkli
Date: 2010-10-24 20:33:58 +0200 (Sun, 24 Oct 2010)
New Revision: 7580
Modified:
code/branches/masterserver/src/modules/masterserver/MasterServer.cpp
code/branches/masterserver/src/modules/masterserver/PeerList.cpp
code/branches/masterserver/src/modules/masterserver/PeerList.h
Log:
Further implementation, constructing a testing environment soon.
Modified: code/branches/masterserver/src/modules/masterserver/MasterServer.cpp
===================================================================
--- code/branches/masterserver/src/modules/masterserver/MasterServer.cpp 2010-10-22 14:19:40 UTC (rev 7579)
+++ code/branches/masterserver/src/modules/masterserver/MasterServer.cpp 2010-10-24 18:33:58 UTC (rev 7580)
@@ -40,9 +40,9 @@
}
/* output debug info */
- printf( "A new client connected from %x:%u.\n",
- event->peer->address.host,
- event->peer->address.port);
+ //printf( "A new client connected from %x:%u.\n",
+ //event->peer->address.host,
+ //event->peer->address.port);
/* game server or client connection? */
/* game server */
@@ -68,7 +68,7 @@
}
/* output that the disconnect happened, to be removed at a later time. */
- printf ("%s disconnected.\n", event.peer -> data);
+ //printf ("%s disconnected.\n", event->peer -> data);
/* remove the server from the list it belongs to */
@@ -86,11 +86,11 @@
}
/* output debug info about the data that has come, to be removed */
- printf( "A packet of length %u containing %s was received from %s on channel %u.\n",
- event->packet->dataLength,
- event->packet->data,
- event->peer->data,
- event->channelID );
+ //printf( "A packet of length %u containing %s was received from %s on channel %u.\n",
+ //event->packet->dataLength,
+ //event->packet->data,
+ //event->peer->data,
+ //event->channelID );
/* game server or client connection? */
/* game server */
@@ -154,7 +154,7 @@
//}
/***** ENTER MAIN LOOP *****/
- ENetEvent *event = calloc(sizeof(ENetEvent), sizeof(char));
+ ENetEvent *event = (ENetEvent *)calloc(sizeof(ENetEvent), sizeof(char));
if( event == NULL )
{ fprintf( stderr, "Could not create ENetEvent structure, exiting.\n" );
exit( EXIT_FAILURE );
Modified: code/branches/masterserver/src/modules/masterserver/PeerList.cpp
===================================================================
--- code/branches/masterserver/src/modules/masterserver/PeerList.cpp 2010-10-22 14:19:40 UTC (rev 7579)
+++ code/branches/masterserver/src/modules/masterserver/PeerList.cpp 2010-10-24 18:33:58 UTC (rev 7580)
@@ -27,6 +27,7 @@
*/
#include "PeerList.h"
+#include <cstdio>
namespace orxonox
{
@@ -35,27 +36,49 @@
int
PeerList::addPeer( ENetPeer *toadd )
- {
+ { /* error correction */
+ if( toadd == NULL )
+ { fprintf( stderr, "PeerList::addPeer: empty peer given.\n" );
+ return -1;
+ }
-
+ /* if all went well, push to back of list */
+ this->peerlist.push_back( toadd );
return 0;
}
- int
+ bool sub_compAddr( ENetAddress addr1, ENetAddress addr2 )
+ { return ( (addr1.host == addr2.host) && (addr1.port == addr2.port) ); }
+
+ bool
PeerList::remPeerByAddr( ENetAddress addr )
- {
+ { /* get an iterator */
+ list<packet::ENetPeer *>::iterator i;
+ /* loop through list elements */
+ for( i = peerlist.begin(); i != peerlist.end(); ++i )
+ if( sub_compAddr((*i)->address, addr ) )
+ { /* found this name, remove and quit */
+ this->peerlist.remove( i );
+ return true;
+ }
-
- return 0;
+ /* not found */
+ return false;
}
ENetPeer *
PeerList::findPeerByAddr( ENetAddress addr )
- {
+ { /* get an iterator */
+ list<packet::ENetPeer *>::iterator i;
+ /* loop through list elements */
+ for( i = peerlist.begin(); i != peerlist.end(); ++i )
+ if( sub_compAddr((*i)->address, addr ) )
+ /* found this name, remove and quit */
+ return i;
-
+ /* not found */
return NULL;
}
Modified: code/branches/masterserver/src/modules/masterserver/PeerList.h
===================================================================
--- code/branches/masterserver/src/modules/masterserver/PeerList.h 2010-10-22 14:19:40 UTC (rev 7579)
+++ code/branches/masterserver/src/modules/masterserver/PeerList.h 2010-10-24 18:33:58 UTC (rev 7580)
@@ -48,16 +48,18 @@
~PeerList();
/** \param toadd The peer to add
+ * \return 0 for success, -1 for error.
*
* Add new peer to list
*/
int addPeer( ENetPeer *toadd );
/** \param addr Address to look for
+ * \return if the peer was found or not
*
* Remove peer from list by address
*/
- int remPeerByAddr( ENetAddress addr );
+ bool remPeerByAddr( ENetAddress addr );
/** \param addr The address to find by
*
More information about the Orxonox-commit
mailing list