ソースを参照

fix array iteration

Kolja Strohm 3 年 前
コミット
ff4f2dbd32
1 ファイル変更86 行追加83 行削除
  1. 86 83
      Minigame Server/MinigameServer.cpp

+ 86 - 83
Minigame Server/MinigameServer.cpp

@@ -5,7 +5,7 @@
 
 // Inhalt der LoginServer Klasse aus LoginServer.h
 // Konstruktor 
-MinigameServer::MinigameServer( InitDatei *zIni )
+MinigameServer::MinigameServer( InitDatei* zIni )
     : Thread()
 {
     Network::Start( 100 );
@@ -16,7 +16,7 @@ MinigameServer::MinigameServer( InitDatei *zIni )
     empfangen = 0;
     gesendet = 0;
     fehler = new Text();
-    ini = dynamic_cast<InitDatei *>( zIni->getThis() );
+    ini = dynamic_cast<InitDatei*>(zIni->getThis());
     id = *zIni->zWert( "ServerId" );
     server = new Server();
     aServer = new SSLServer();
@@ -60,18 +60,18 @@ void MinigameServer::runn()
 {
     while( !end && aServer->isConnected() )
     {
-        SSLSKlient *klient;
+        SSLSKlient* klient;
         klient = aServer->getKlient();
         if( end && klient )
         {
             klient->trenne();
-            klient = (SSLSKlient *)klient->release();
+            klient = (SSLSKlient*)klient->release();
             Sleep( 1000 );
             return;
         }
         if( !klient )
             continue;
-        MSAKlient *clHandle = new MSAKlient( klient, dynamic_cast<MinigameServer *>( getThis() ) );
+        MSAKlient* clHandle = new MSAKlient( klient, dynamic_cast<MinigameServer*>(getThis()) );
         clHandle->start();
     }
 }
@@ -80,12 +80,12 @@ void MinigameServer::thread()
 {
     while( server->isConnected() )
     {
-        SKlient *klient;
+        SKlient* klient;
         klient = server->getKlient();
         if( !klient )
             continue;
         Framework::getThreadRegister()->cleanUpClosedThreads();
-        MSKlient *clHandle = new MSKlient( klient, dynamic_cast<MinigameServer *>( getThis() ) );
+        MSKlient* clHandle = new MSKlient( klient, dynamic_cast<MinigameServer*>(getThis()) );
         EnterCriticalSection( &cs );
         klients->set( clHandle, klientAnzahl );
         klientAnzahl++;
@@ -104,13 +104,13 @@ void MinigameServer::close()
     EnterCriticalSection( &cs );
     for( int i = 0; i < klientAnzahl; i++ )
         klients->z( i )->absturz();
-    klients = ( RCArray<MSKlient>* )klients->release();
+    klients = (RCArray<MSKlient>*)klients->release();
     klientAnzahl = 0;
     LeaveCriticalSection( &cs );
     ende();
     run = 0;
     end = 1;
-    Klient *klient = new Klient();
+    Klient* klient = new Klient();
     klient->verbinde( aServer->getPort(), "127.0.0.1" );
     Sleep( 500 );
     aServer->trenne();
@@ -223,7 +223,7 @@ bool MinigameServer::absturzKlient( int klientId )
     return gefunden;
 }
 
-bool MinigameServer::removeKlient( MSKlient *zKlient )
+bool MinigameServer::removeKlient( MSKlient* zKlient )
 {
     bool gefunden = 0;
     EnterCriticalSection( &cs );
@@ -257,12 +257,12 @@ bool MinigameServer::istAn() const
     return db->serverIstNichtPausiert( id );
 }
 
-Server *MinigameServer::zServer() const
+Server* MinigameServer::zServer() const
 {
     return server;
 }
 
-MSDatenbank *MinigameServer::zDB() const
+MSDatenbank* MinigameServer::zDB() const
 {
     return db;
 }
@@ -277,12 +277,12 @@ int MinigameServer::getId() const
     return id;
 }
 
-char *MinigameServer::getLetzterFehler() const
+char* MinigameServer::getLetzterFehler() const
 {
     return fehler->getText();
 }
 
-InitDatei *MinigameServer::zInit() const
+InitDatei* MinigameServer::zInit() const
 {
     return ini;
 }
@@ -290,7 +290,7 @@ InitDatei *MinigameServer::zInit() const
 
 // Inhalt der LSAKlient Klasse aus LoginServer.h
 // Konstruktor 
-MSAKlient::MSAKlient( SSLSKlient *klient, MinigameServer *ls )
+MSAKlient::MSAKlient( SSLSKlient* klient, MinigameServer* ls )
     : Thread()
 {
     this->klient = klient;
@@ -329,14 +329,14 @@ void MSAKlient::thread()
                 {
                     klient->sende( "\1", 1 );
                     unsigned char nLen = 0;
-                    klient->getNachricht( (char *)&nLen, 1 );
-                    char *n = new char[ nLen + 1 ];
+                    klient->getNachricht( (char*)&nLen, 1 );
+                    char* n = new char[ nLen + 1 ];
                     n[ (int)nLen ] = 0;
                     if( nLen )
                         klient->getNachricht( n, nLen );
                     unsigned char pLen = 0;
-                    klient->getNachricht( (char *)&pLen, 1 );
-                    char *p = new char[ pLen + 1 ];
+                    klient->getNachricht( (char*)&pLen, 1 );
+                    char* p = new char[ pLen + 1 ];
                     p[ (int)pLen ] = 0;
                     if( pLen )
                         klient->getNachricht( p, pLen );
@@ -373,7 +373,7 @@ void MSAKlient::thread()
                     {
                         if( !ms->serverStarten() )
                         {
-                            Text *err = new Text();
+                            Text* err = new Text();
                             err->append( ms->getLetzterFehler() );
                             errorZuKlient( err->getText() );
                             err->release();
@@ -396,7 +396,7 @@ void MSAKlient::thread()
                             klient->sende( "\1", 1 );
                         else
                         {
-                            Text *err = new Text();
+                            Text* err = new Text();
                             err->append( ms->getLetzterFehler() );
                             errorZuKlient( err->getText() );
                             err->release();
@@ -420,7 +420,7 @@ void MSAKlient::thread()
                                 ok = 1;
                             else
                             {
-                                Text *err = new Text();
+                                Text* err = new Text();
                                 err->append( ms->getLetzterFehler() );
                                 errorZuKlient( err->getText() );
                                 err->release();
@@ -505,7 +505,7 @@ void MSAKlient::thread()
                             klient->sende( "\1", 1 );
                         else
                         {
-                            Text *err = new Text();
+                            Text* err = new Text();
                             err->append( ms->getLetzterFehler() );
                             errorZuKlient( err->getText() );
                             err->release();
@@ -527,14 +527,14 @@ void MSAKlient::thread()
                 {
                     klient->sende( "\1", 1 );
                     int maxC = 0;
-                    klient->getNachricht( (char *)&maxC, 4 );
+                    klient->getNachricht( (char*)&maxC, 4 );
                     if( ms->zDB()->adminHatRecht( adminId, Admin_Recht::MSMCChange ) )
                     {
                         if( ms->setMaxKlients( maxC ) )
                             klient->sende( "\1", 1 );
                         else
                         {
-                            Text *err = new Text();
+                            Text* err = new Text();
                             err->append( ms->getLetzterFehler() );
                             errorZuKlient( err->getText() );
                             err->release();
@@ -549,7 +549,7 @@ void MSAKlient::thread()
                 {
                     klient->sende( "\1", 1 );
                     int klientId = 0;
-                    klient->getNachricht( (char *)&klientId, 4 );
+                    klient->getNachricht( (char*)&klientId, 4 );
                     if( klientId && ms->absturzKlient( klientId ) )
                         klient->sende( "\1", 1 );
                     else
@@ -571,7 +571,7 @@ void MSAKlient::thread()
     delete this;
 }
 
-void MSAKlient::errorZuKlient( const char *nachricht ) const // sendet eine Fehlernachricht zum Klient
+void MSAKlient::errorZuKlient( const char* nachricht ) const // sendet eine Fehlernachricht zum Klient
 {
     klient->sende( "\3", 1 );
     char len = (char)textLength( nachricht );
@@ -582,13 +582,13 @@ void MSAKlient::errorZuKlient( const char *nachricht ) const // sendet eine Fehl
 
 // Inhalt der LSKlient aus LoginServer.h
 // Konstruktor
-MSKlient::MSKlient( SKlient *klient, MinigameServer *ls )
+MSKlient::MSKlient( SKlient* klient, MinigameServer* ls )
     : Thread()
 {
     this->klient = klient;
     unsigned char key[ 20 ] = { 88, 103, 192, 232, 69, 54, 57, 3, 239, 138, 234, 172, 126, 72, 81, 55, 205, 97, 59, 255 };
-    klient->setSendeKey( (char *)key, 20 );
-    klient->setEmpfangKey( (char *)key, 20 );
+    klient->setSendeKey( (char*)key, 20 );
+    klient->setEmpfangKey( (char*)key, 20 );
     klientNummer = 0;
     this->ms = ls;
 }
@@ -621,7 +621,7 @@ void MSKlient::thread()
             switch( c )
             {
             case 1: // Klient identifikation
-                klient->getNachrichtEncrypted( (char *)&klientNummer, 4 );
+                klient->getNachrichtEncrypted( (char*)&klientNummer, 4 );
                 if( !ms->zDB()->proveKlient( klientNummer, ms->getId() ) )
                 {
                     klientNummer = 0;
@@ -629,7 +629,7 @@ void MSKlient::thread()
                 }
                 else
                 {
-                    Text *key = ms->zDB()->getKlientKey( klientNummer );
+                    Text* key = ms->zDB()->getKlientKey( klientNummer );
                     if( !key )
                         errorZuKlient( "Es konnte kein Schlüssel ermittelt werden." );
                     else
@@ -652,7 +652,7 @@ void MSKlient::thread()
                         if( 1 )
                         {
                             int klientId = 0;
-                            klient->getNachrichtEncrypted( (char *)&klientId, 4 );
+                            klient->getNachrichtEncrypted( (char*)&klientId, 4 );
                             if( klientId && ms->absturzKlient( klientId ) )
                                 klient->sendeEncrypted( "\1", 1 );
                             else
@@ -690,19 +690,22 @@ void MSKlient::thread()
             {
                 klient->sendeEncrypted( "\1", 1 );
                 unsigned char l = 0;
-                klient->getNachrichtEncrypted( (char *)&l, 1 );
-                char *mName = new char[ l ];
+                klient->getNachrichtEncrypted( (char*)&l, 1 );
+                char* mName = new char[ l ];
                 mName[ (int)l ] = 0;
                 klient->getNachrichtEncrypted( mName, l );
                 RCArray< Text > oList;
                 int anz = ms->zDB()->getMinigameOptionList( mName, &oList );
                 delete[] mName;
-                klient->sendeEncrypted( (char *)&anz, 4 );
-                for( auto t = oList.getIterator(); t && t._; t++ )
+                klient->sendeEncrypted( (char*)&anz, 4 );
+                for( Text* t : oList )
                 {
-                    l = (char)t->getLength();
-                    klient->sendeEncrypted( (char *)&l, 1 );
-                    klient->sendeEncrypted( t->getText(), l );
+                    if( t )
+                    {
+                        l = (char)t->getLength();
+                        klient->sendeEncrypted( (char*)&l, 1 );
+                        klient->sendeEncrypted( t->getText(), l );
+                    }
                 }
                 break;
             }
@@ -710,8 +713,8 @@ void MSKlient::thread()
             {
                 klient->sendeEncrypted( "\1", 1 );
                 unsigned char l = 0;
-                klient->getNachrichtEncrypted( (char *)&l, 1 );
-                char *mName = new char[ l ];
+                klient->getNachrichtEncrypted( (char*)&l, 1 );
+                char* mName = new char[ l ];
                 mName[ (int)l ] = 0;
                 klient->getNachrichtEncrypted( mName, l );
                 Array< int > sList;
@@ -719,16 +722,16 @@ void MSKlient::thread()
                 RCArray< Text > oList;
                 int anz = ms->zDB()->getMinigameBestscore( mName, &sList, &pList, &oList );
                 delete[] mName;
-                klient->sendeEncrypted( (char *)&anz, 4 );
+                klient->sendeEncrypted( (char*)&anz, 4 );
                 for( int i = 0; i < anz; i++ )
                 {
                     int s = sList.get( i );
-                    klient->sendeEncrypted( (char *)&s, 4 );
+                    klient->sendeEncrypted( (char*)&s, 4 );
                     l = (char)pList.z( i )->getLength();
-                    klient->sendeEncrypted( (char *)&l, 1 );
+                    klient->sendeEncrypted( (char*)&l, 1 );
                     klient->sendeEncrypted( pList.z( i )->getText(), l );
                     l = (char)oList.z( i )->getLength();
-                    klient->sendeEncrypted( (char *)&l, 1 );
+                    klient->sendeEncrypted( (char*)&l, 1 );
                     klient->sendeEncrypted( oList.z( i )->getText(), l );
                 }
                 break;
@@ -737,23 +740,23 @@ void MSKlient::thread()
             {
                 klient->sendeEncrypted( "\1", 1 );
                 unsigned char l = 0;
-                klient->getNachrichtEncrypted( (char *)&l, 1 );
-                char *mName = new char[ l ];
+                klient->getNachrichtEncrypted( (char*)&l, 1 );
+                char* mName = new char[ l ];
                 mName[ (int)l ] = 0;
                 klient->getNachrichtEncrypted( mName, l );
-                klient->getNachrichtEncrypted( (char *)&l, 1 );
-                char *oName = new char[ l ];
+                klient->getNachrichtEncrypted( (char*)&l, 1 );
+                char* oName = new char[ l ];
                 oName[ (int)l ] = 0;
                 klient->getNachrichtEncrypted( oName, l );
                 Text player;
                 int score = ms->zDB()->getMinigameBestscore( oName, mName, &player );
                 delete[] mName;
                 delete[] oName;
-                klient->sendeEncrypted( (char *)&score, 4 );
+                klient->sendeEncrypted( (char*)&score, 4 );
                 if( score )
                 {
                     l = (char)player.getLength();
-                    klient->sendeEncrypted( (char *)&l, 1 );
+                    klient->sendeEncrypted( (char*)&l, 1 );
                     klient->sendeEncrypted( player.getText(), l );
                 }
                 break;
@@ -767,16 +770,16 @@ void MSKlient::thread()
                 }
                 klient->sendeEncrypted( "\1", 1 );
                 unsigned char l = 0;
-                klient->getNachrichtEncrypted( (char *)&l, 1 );
-                char *mName = new char[ l ];
+                klient->getNachrichtEncrypted( (char*)&l, 1 );
+                char* mName = new char[ l ];
                 mName[ (int)l ] = 0;
                 klient->getNachrichtEncrypted( mName, l );
-                klient->getNachrichtEncrypted( (char *)&l, 1 );
-                char *oName = new char[ l ];
+                klient->getNachrichtEncrypted( (char*)&l, 1 );
+                char* oName = new char[ l ];
                 oName[ (int)l ] = 0;
                 klient->getNachrichtEncrypted( oName, l );
                 int score;
-                klient->getNachrichtEncrypted( (char *)&score, 4 );
+                klient->getNachrichtEncrypted( (char*)&score, 4 );
                 Text fName;
                 if( ms->zDB()->updateMinigameScore( score, oName, klientNummer, mName, ms->getId(), &fName ) )
                 {
@@ -784,7 +787,7 @@ void MSKlient::thread()
                     Text path = ms->zInit()->zWert( "MGC_Pfad" )->getText();
                     if( path.getText()[ path.getLength() - 1 ] != '/' )
                         path += "/";
-                    path += (char *)fName;
+                    path += (char*)fName;
                     Datei d;
                     d.setDatei( path );
                     d.erstellen();
@@ -792,8 +795,8 @@ void MSKlient::thread()
                     {
                         klient->sendeEncrypted( "\1", 1 );
                         int size;
-                        klient->getNachrichtEncrypted( (char *)&size, 4 );
-                        char *buffer = new char[ 2048 ];
+                        klient->getNachrichtEncrypted( (char*)&size, 4 );
+                        char* buffer = new char[ 2048 ];
                         while( size > 0 )
                         {
                             int l = size > 2048 ? 2048 : size;
@@ -818,19 +821,19 @@ void MSKlient::thread()
             {
                 klient->sendeEncrypted( "\1", 1 );
                 unsigned char l = 0;
-                klient->getNachrichtEncrypted( (char *)&l, 1 );
-                char *mName = new char[ l ];
+                klient->getNachrichtEncrypted( (char*)&l, 1 );
+                char* mName = new char[ l ];
                 mName[ (int)l ] = 0;
                 klient->getNachrichtEncrypted( mName, l );
-                klient->getNachrichtEncrypted( (char *)&l, 1 );
-                char *oName = new char[ l ];
+                klient->getNachrichtEncrypted( (char*)&l, 1 );
+                char* oName = new char[ l ];
                 oName[ (int)l ] = 0;
                 klient->getNachrichtEncrypted( oName, l );
                 int serverId = ms->zDB()->getMinigameServer( mName, oName );
                 if( serverId && serverId == ms->getId() )
                 {
                     ms->zDB()->lock();
-                    Text *fileName = ms->zDB()->getMinigameCaptureFileName( oName, mName );
+                    Text* fileName = ms->zDB()->getMinigameCaptureFileName( oName, mName );
                     Text path = ms->zInit()->zWert( "MGC_Pfad" )->getText();
                     if( path.getText()[ path.getLength() - 1 ] != '/' )
                         path += "/";
@@ -842,8 +845,8 @@ void MSKlient::thread()
                     {
                         klient->sendeEncrypted( "\1", 1 );
                         int size = (int)d.getSize();
-                        klient->sendeEncrypted( (char *)&size, 4 );
-                        char *buffer = new char[ 2048 ];
+                        klient->sendeEncrypted( (char*)&size, 4 );
+                        char* buffer = new char[ 2048 ];
                         while( size > 0 )
                         {
                             int l = size > 2048 ? 2048 : size;
@@ -863,11 +866,11 @@ void MSKlient::thread()
                     Text port;
                     if( ms->zDB()->getMinigameServer( mName, oName, &ip, &port ) )
                     {
-                        Klient *k = new Klient();
+                        Klient* k = new Klient();
                         unsigned char key[ 20 ] = { 88, 103, 192, 232, 69, 54, 57, 3, 239, 138, 234, 172, 126, 72, 81, 55, 205, 97, 59, 255 };
-                        k->setSendeKey( (char *)key, 20 );
-                        k->setEmpfangKey( (char *)key, 20 );
-                        if( k->verbinde( (unsigned short)(int)port, (char *)ip ) )
+                        k->setSendeKey( (char*)key, 20 );
+                        k->setEmpfangKey( (char*)key, 20 );
+                        if( k->verbinde( (unsigned short)(int)port, (char*)ip ) )
                         {
                             k->sendeEncrypted( "\xA", 1 );
                             char ret;
@@ -875,19 +878,19 @@ void MSKlient::thread()
                             if( ret == 1 )
                             {
                                 l = (char)textLength( mName );
-                                k->sendeEncrypted( (char *)&l, 1 );
+                                k->sendeEncrypted( (char*)&l, 1 );
                                 k->sendeEncrypted( mName, l );
                                 l = (char)textLength( oName );
-                                k->sendeEncrypted( (char *)&l, 1 );
+                                k->sendeEncrypted( (char*)&l, 1 );
                                 k->sendeEncrypted( oName, l );
                                 k->getNachrichtEncrypted( &ret, 1 );
                                 if( ret == 1 )
                                 {
                                     klient->sendeEncrypted( "\1", 1 );
                                     int size;
-                                    k->getNachrichtEncrypted( (char *)&size, 4 );
-                                    klient->sendeEncrypted( (char *)&size, 4 );
-                                    char *buffer = new char[ 2048 ];
+                                    k->getNachrichtEncrypted( (char*)&size, 4 );
+                                    klient->sendeEncrypted( (char*)&size, 4 );
+                                    char* buffer = new char[ 2048 ];
                                     while( size > 0 )
                                     {
                                         int l = size > 2048 ? 2048 : size;
@@ -900,8 +903,8 @@ void MSKlient::thread()
                             }
                             if( ret == 3 )
                             {
-                                k->getNachrichtEncrypted( (char *)&l, 1 );
-                                char *error = new char[ l + 1 ];
+                                k->getNachrichtEncrypted( (char*)&l, 1 );
+                                char* error = new char[ l + 1 ];
                                 error[ (int)l ] = 0;
                                 k->getNachrichtEncrypted( error, l );
                                 errorZuKlient( error );
@@ -935,7 +938,7 @@ void MSKlient::thread()
                 }
                 klient->sendeEncrypted( "\1", 1 );
                 int acc = ms->zDB()->getAccountId( klientNummer );
-                klient->sendeEncrypted( (char *)&acc, 4 );
+                klient->sendeEncrypted( (char*)&acc, 4 );
                 break;
             }
             case 0xC:
@@ -947,8 +950,8 @@ void MSKlient::thread()
                 }
                 klient->sendeEncrypted( "\1", 1 );
                 int acc;
-                klient->getNachrichtEncrypted( (char *)&acc, 4 );
-                Text *name = ms->zDB()->getAccountName( acc );
+                klient->getNachrichtEncrypted( (char*)&acc, 4 );
+                Text* name = ms->zDB()->getAccountName( acc );
                 if( !name )
                     errorZuKlient( "Der Acount existiert nicht." );
                 else
@@ -968,7 +971,7 @@ void MSKlient::thread()
                     errorZuKlient( "Du bist nicht Identifiziert." );
                     break;
                 }
-                Text *name = ms->zDB()->getSecret( klientNummer );
+                Text* name = ms->zDB()->getSecret( klientNummer );
                 if( !name )
                     errorZuKlient( "Kein secret gefunden." );
                 else
@@ -997,7 +1000,7 @@ void MSKlient::thread()
 }
 
 // constant
-void MSKlient::errorZuKlient( const char *nachricht ) const // sendet eine Fehlernachricht zum Klient
+void MSKlient::errorZuKlient( const char* nachricht ) const // sendet eine Fehlernachricht zum Klient
 {
     klient->sendeEncrypted( "\3", 1 );
     char len = (char)textLength( nachricht );