Revision: 1461
          http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=1461&view=rev
Author:   rorthomas
Date:     2010-07-19 02:57:24 +0000 (Mon, 19 Jul 2010)

Log Message:
-----------
improved network class interface

Modified Paths:
--------------
    trunk/source/main/network.cpp
    trunk/source/main/network.h

Modified: trunk/source/main/network.cpp
===================================================================
--- trunk/source/main/network.cpp       2010-07-19 02:56:33 UTC (rev 1460)
+++ trunk/source/main/network.cpp       2010-07-19 02:57:24 UTC (rev 1461)
@@ -82,7 +82,7 @@
 Timer Network::timer = Ogre::Timer();
 unsigned int Network::myuid=0;
 
-Network::Network(Beam **btrucks, std::string servername, long sport, 
RoRFrameListener *efl): lagDataClients()
+Network::Network(Beam **btrucks, std::string servername, long sport, 
RoRFrameListener *efl): lagDataClients(), initiated(false)
 {
        // update factories network objects
 
@@ -121,10 +121,14 @@
        // reset client list
        pthread_mutex_lock(&clients_mutex);
        for (int i=0; i<MAX_PEERS; i++)
+       {
                clients[i].used=false;
+               memset(&clients[i].user, 0, sizeof(user_info_t));
+       }
        pthread_mutex_unlock(&clients_mutex);
 
        // direct start, no vehicle required
+       initiated = true;
 }
 
 Network::~Network()
@@ -550,7 +554,7 @@
                {
                        if(header.source == (int)myuid)
                        {
-                               netFatalError("disconnected", false);
+                               netFatalError("disconnected: remote side closed 
the connection", false);
                                return;
                        }
 
@@ -614,6 +618,15 @@
        }
 }
 
+int Network::getClientInfos(client_t c[MAX_PEERS])
+{
+       if(!initiated) return 1;
+       pthread_mutex_lock(&clients_mutex);
+       for(int i=0;i<MAX_PEERS;i++)
+               c[i] = clients[i]; // copy the whole client list
+       pthread_mutex_unlock(&clients_mutex);
+       return 0;
+}
 
 client_t *Network::getClientInfo(unsigned int uid)
 {

Modified: trunk/source/main/network.h
===================================================================
--- trunk/source/main/network.h 2010-07-19 02:56:33 UTC (rev 1460)
+++ trunk/source/main/network.h 2010-07-19 02:57:24 UTC (rev 1461)
@@ -72,6 +72,7 @@
        std::map<Ogre::String, Ogre::String> downloadingMods;
        void updatePlayerList();
        server_info_t server_settings;
+       bool initiated;
 public:
 
        Network(Beam **btrucks, std::string servername, long sport, 
RoRFrameListener *efl);
@@ -95,6 +96,7 @@
        unsigned int getUserID() { return myuid; };
        static unsigned long getNetTime();
        client_t *getClientInfo(unsigned int uid);
+       int getClientInfos(client_t c[MAX_PEERS]);
 
        int getSpeedUp();
        int getSpeedDown();


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Rigsofrods-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel

Reply via email to