Browse Source

An neues Framework angepasst

Kolja Strohm 5 years ago
parent
commit
a8c46fceb5
2 changed files with 47 additions and 87 deletions
  1. 47 79
      Minigame Server/MinigameServer.cpp
  2. 0 8
      Minigame Server/MinigameServer.h

+ 47 - 79
Minigame Server/MinigameServer.cpp

@@ -33,7 +33,6 @@ MinigameServer::MinigameServer( InitDatei *zIni )
     end = 0;
     nichtPausiert = 0;
     InitializeCriticalSection( &cs );
-    ref = 1;
     if( zIni->zWert( "Aktiv" )->istGleich( "TRUE" ) )
     {
         serverStarten();
@@ -72,7 +71,7 @@ void MinigameServer::runn()
         }
         if( !klient )
             continue;
-        MSAKlient *clHandle = new MSAKlient( klient, getThis() );
+        MSAKlient * clHandle = new MSAKlient( klient, (MinigameServer *)getThis() );
         clHandle->start();
     }
 }
@@ -86,7 +85,7 @@ void MinigameServer::thread()
         if( !klient )
             continue;
         Framework::getThreadRegister()->cleanUpClosedThreads();
-        MSKlient *clHandle = new MSKlient( klient, getThis() );
+        MSKlient * clHandle = new MSKlient( klient, (MinigameServer *)getThis() );
         EnterCriticalSection( &cs );
         klients->set( clHandle, klientAnzahl );
         klientAnzahl++;
@@ -111,7 +110,7 @@ void MinigameServer::close()
     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();
@@ -224,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 );
@@ -288,25 +287,10 @@ InitDatei *MinigameServer::zInit() const
     return ini;
 }
 
-// Reference Counting
-MinigameServer *MinigameServer::getThis()
-{
-    ref++;
-    return this;
-}
-
-MinigameServer *MinigameServer::release()
-{
-    ref--;
-    if( !ref )
-        delete this;
-    return 0;
-}
-
 
 // Inhalt der LSAKlient Klasse aus LoginServer.h
 // Konstruktor 
-MSAKlient::MSAKlient( SSLSKlient *klient, MinigameServer *ls )
+MSAKlient::MSAKlient( SSLSKlient * klient, MinigameServer * ls )
     : Thread()
 {
     this->klient = klient;
@@ -345,13 +329,13 @@ void MSAKlient::thread()
                 {
                     klient->sende( "\1", 1 );
                     unsigned char nLen = 0;
-                    klient->getNachricht( (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 );
+                    klient->getNachricht( (char *)& pLen, 1 );
                     char *p = new char[ pLen + 1 ];
                     p[ (int)pLen ] = 0;
                     if( pLen )
@@ -447,7 +431,7 @@ void MSAKlient::thread()
                     }
                     else
                         ok = 1;
-                    if( ok && ms->hatClients() )
+                    if( ok &&ms->hatClients() )
                     {
                         errorZuKlient( "Es sind noch Klients Online. Bitte versuche es später erneut." );
                         break;
@@ -543,7 +527,7 @@ 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 ) )
@@ -565,8 +549,8 @@ void MSAKlient::thread()
                 {
                     klient->sende( "\1", 1 );
                     int klientId = 0;
-                    klient->getNachricht( (char*)&klientId, 4 );
-                    if( klientId && ms->absturzKlient( klientId ) )
+                    klient->getNachricht( (char *)& klientId, 4 );
+                    if( klientId &&ms->absturzKlient( klientId ) )
                         klient->sende( "\1", 1 );
                     else
                         klient->sende( "\0", 1 );
@@ -598,16 +582,15 @@ 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;
-    ref = 1;
 }
 
 // Destruktor 
@@ -638,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;
@@ -669,8 +652,8 @@ void MSKlient::thread()
                         if( 1 )
                         {
                             int klientId = 0;
-                            klient->getNachrichtEncrypted( (char*)&klientId, 4 );
-                            if( klientId && ms->absturzKlient( klientId ) )
+                            klient->getNachrichtEncrypted( (char *)& klientId, 4 );
+                            if( klientId &&ms->absturzKlient( klientId ) )
                                 klient->sendeEncrypted( "\1", 1 );
                             else
                                 klient->sendeEncrypted( "\0", 1 );
@@ -707,18 +690,18 @@ void MSKlient::thread()
             {
                 klient->sendeEncrypted( "\1", 1 );
                 unsigned char l = 0;
-                klient->getNachrichtEncrypted( (char*)&l, 1 );
+                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 );
+                klient->sendeEncrypted( (char *)& anz, 4 );
                 for( auto t = oList.getIterator(); t && t._; t++ )
                 {
                     l = (char)t->getLength();
-                    klient->sendeEncrypted( (char*)&l, 1 );
+                    klient->sendeEncrypted( (char *)& l, 1 );
                     klient->sendeEncrypted( t->getText(), l );
                 }
                 break;
@@ -727,7 +710,7 @@ void MSKlient::thread()
             {
                 klient->sendeEncrypted( "\1", 1 );
                 unsigned char l = 0;
-                klient->getNachrichtEncrypted( (char*)&l, 1 );
+                klient->getNachrichtEncrypted( (char *)& l, 1 );
                 char *mName = new char[ l ];
                 mName[ (int)l ] = 0;
                 klient->getNachrichtEncrypted( mName, l );
@@ -736,16 +719,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;
@@ -754,11 +737,11 @@ void MSKlient::thread()
             {
                 klient->sendeEncrypted( "\1", 1 );
                 unsigned char l = 0;
-                klient->getNachrichtEncrypted( (char*)&l, 1 );
+                klient->getNachrichtEncrypted( (char *)& l, 1 );
                 char *mName = new char[ l ];
                 mName[ (int)l ] = 0;
                 klient->getNachrichtEncrypted( mName, l );
-                klient->getNachrichtEncrypted( (char*)&l, 1 );
+                klient->getNachrichtEncrypted( (char *)& l, 1 );
                 char *oName = new char[ l ];
                 oName[ (int)l ] = 0;
                 klient->getNachrichtEncrypted( oName, l );
@@ -766,11 +749,11 @@ void MSKlient::thread()
                 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;
@@ -784,16 +767,16 @@ void MSKlient::thread()
                 }
                 klient->sendeEncrypted( "\1", 1 );
                 unsigned char l = 0;
-                klient->getNachrichtEncrypted( (char*)&l, 1 );
+                klient->getNachrichtEncrypted( (char *)& l, 1 );
                 char *mName = new char[ l ];
                 mName[ (int)l ] = 0;
                 klient->getNachrichtEncrypted( mName, l );
-                klient->getNachrichtEncrypted( (char*)&l, 1 );
+                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 ) )
                 {
@@ -801,7 +784,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();
@@ -809,7 +792,7 @@ void MSKlient::thread()
                     {
                         klient->sendeEncrypted( "\1", 1 );
                         int size;
-                        klient->getNachrichtEncrypted( (char*)&size, 4 );
+                        klient->getNachrichtEncrypted( (char *)& size, 4 );
                         char *buffer = new char[ 2048 ];
                         while( size > 0 )
                         {
@@ -835,11 +818,11 @@ void MSKlient::thread()
             {
                 klient->sendeEncrypted( "\1", 1 );
                 unsigned char l = 0;
-                klient->getNachrichtEncrypted( (char*)&l, 1 );
+                klient->getNachrichtEncrypted( (char *)& l, 1 );
                 char *mName = new char[ l ];
                 mName[ (int)l ] = 0;
                 klient->getNachrichtEncrypted( mName, l );
-                klient->getNachrichtEncrypted( (char*)&l, 1 );
+                klient->getNachrichtEncrypted( (char *)& l, 1 );
                 char *oName = new char[ l ];
                 oName[ (int)l ] = 0;
                 klient->getNachrichtEncrypted( oName, l );
@@ -859,7 +842,7 @@ void MSKlient::thread()
                     {
                         klient->sendeEncrypted( "\1", 1 );
                         int size = (int)d.getSize();
-                        klient->sendeEncrypted( (char*)&size, 4 );
+                        klient->sendeEncrypted( (char *)& size, 4 );
                         char *buffer = new char[ 2048 ];
                         while( size > 0 )
                         {
@@ -882,9 +865,9 @@ void MSKlient::thread()
                     {
                         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;
@@ -892,18 +875,18 @@ 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 );
+                                    k->getNachrichtEncrypted( (char *)& size, 4 );
+                                    klient->sendeEncrypted( (char *)& size, 4 );
                                     char *buffer = new char[ 2048 ];
                                     while( size > 0 )
                                     {
@@ -917,7 +900,7 @@ void MSKlient::thread()
                             }
                             if( ret == 3 )
                             {
-                                k->getNachrichtEncrypted( (char*)&l, 1 );
+                                k->getNachrichtEncrypted( (char *)& l, 1 );
                                 char *error = new char[ l + 1 ];
                                 error[ (int)l ] = 0;
                                 k->getNachrichtEncrypted( error, l );
@@ -952,7 +935,7 @@ void MSKlient::thread()
                 }
                 klient->sendeEncrypted( "\1", 1 );
                 int acc = ms->zDB()->getAccountId( klientNummer );
-                klient->sendeEncrypted( (char*)&acc, 4 );
+                klient->sendeEncrypted( (char *)& acc, 4 );
             }
             case 0xC:
             {
@@ -963,7 +946,7 @@ void MSKlient::thread()
                 }
                 klient->sendeEncrypted( "\1", 1 );
                 int acc;
-                klient->getNachrichtEncrypted( (char*)&acc, 4 );
+                klient->getNachrichtEncrypted( (char *)& acc, 4 );
                 Text *name = ms->zDB()->getAccountName( acc );
                 if( !name )
                     errorZuKlient( "Der Acount existiert nicht." );
@@ -1022,19 +1005,4 @@ void MSKlient::errorZuKlient( const char *nachricht ) const // sendet eine Fehle
 int MSKlient::getKlientNummer() const // gibt die KlientId zurück
 {
     return klientNummer;
-}
-
-// Reference Counting
-MSKlient *MSKlient::getThis()
-{
-    ref++;
-    return this;
-}
-
-MSKlient *MSKlient::release()
-{
-    ref--;
-    if( !ref )
-        delete this;
-    return 0;
 }

+ 0 - 8
Minigame Server/MinigameServer.h

@@ -28,7 +28,6 @@ private:
     int empfangen;
     int gesendet;
     bool end;
-    int ref;
 
 public:
     // Konstruktor 
@@ -56,9 +55,6 @@ public:
     int getId() const;
     char *getLetzterFehler() const;
     InitDatei *zInit() const;
-    // Reference Counting
-    MinigameServer *getThis();
-    MinigameServer *release();
 };
 
 class MSAKlient : public Thread
@@ -87,7 +83,6 @@ private:
     SKlient     *klient;
     unsigned int klientNummer;
     MinigameServer *ms;
-    int ref;
 
 public:
     // Konstruktor 
@@ -100,7 +95,4 @@ public:
     // constant
     void errorZuKlient( const char *nachricht ) const; // sendet eine Fehlernachricht zum Klient
     int getKlientNummer() const;
-    // Reference Counting
-    MSKlient *getThis();
-    MSKlient *release();
 };