Răsfoiți Sursa

fix array usage

Kolja Strohm 2 ani în urmă
părinte
comite
4b96e658f1
2 a modificat fișierele cu 15 adăugiri și 17 ștergeri
  1. 15 16
      LoginServer/LoginServer.cpp
  2. 0 1
      LoginServer/LoginServer.h

+ 15 - 16
LoginServer/LoginServer.cpp

@@ -11,7 +11,6 @@ LoginServer::LoginServer( InitDatei *zIni )
     Network::Start( 100 );
     std::cout << "LS: Verbindung mit Datenbank wird hergestellt...\n";
     db = new LSDatenbank( zIni );
-    klientAnzahl = 0;
     klients = new RCArray< LSKlient >();
     empfangen = 0;
     gesendet = 0;
@@ -87,8 +86,7 @@ void LoginServer::thread()
         Framework::getThreadRegister()->cleanUpClosedThreads();
         LSKlient *clHandle = new LSKlient( klient, dynamic_cast<LoginServer *>( getThis() ) );
         EnterCriticalSection( &cs );
-        klients->set( clHandle, klientAnzahl );
-        klientAnzahl++;
+        klients->add( clHandle );
         LeaveCriticalSection( &cs );
         clHandle->start();
     }
@@ -102,10 +100,9 @@ void LoginServer::close()
     warteAufThread( 1000 );
 #endif
     EnterCriticalSection( &cs );
-    for( int i = 0; i < klientAnzahl; i++ )
-        klients->z( i )->absturz();
+    for( LSKlient *client : *klients )
+        client->absturz();
     klients = ( RCArray<LSKlient>* )klients->release();
-    klientAnzahl = 0;
     LeaveCriticalSection( &cs );
     ende();
     run = 0;
@@ -208,16 +205,17 @@ bool LoginServer::absturzKlient( int klientId )
 {
     bool gefunden = 0;
     EnterCriticalSection( &cs );
-    for( int i = 0; i < klientAnzahl; i++ )
+    int index = 0;
+    for( LSKlient* client : *klients )
     {
-        if( klients->z( i ) && klients->z( i )->getKlientNummer() == klientId )
+        if( client->getKlientNummer() == klientId )
         {
-            klients->z( i )->absturz();
-            klients->remove( i );
-            klientAnzahl--;
+            client->absturz();
+            klients->remove( index );
             gefunden = 1;
             break;
         }
+        index++;
     }
     LeaveCriticalSection( &cs );
     return gefunden;
@@ -227,15 +225,16 @@ bool LoginServer::removeKlient( LSKlient *zKlient )
 {
     bool gefunden = 0;
     EnterCriticalSection( &cs );
-    for( int i = 0; i < klientAnzahl; i++ )
+    int index = 0;
+    for( LSKlient* client : *klients )
     {
-        if( klients->z( i ) == zKlient )
+        if( client == zKlient )
         {
-            klients->remove( i );
-            klientAnzahl--;
+            klients->remove( index );
             gefunden = 1;
             break;
         }
+        index++;
     }
     LeaveCriticalSection( &cs );
     return gefunden;
@@ -269,7 +268,7 @@ LSDatenbank *LoginServer::zDB() const
 
 bool LoginServer::hatClients() const
 {
-    return klientAnzahl > 0;
+    return klients->hat(0);
 }
 
 int LoginServer::getId() const

+ 0 - 1
LoginServer/LoginServer.h

@@ -23,7 +23,6 @@ private:
     CRITICAL_SECTION cs;
     RCArray< LSKlient > *klients;
     Text *fehler;
-    int klientAnzahl;
     int id;
     bool nichtPausiert;
     int empfangen;