Browse Source

Funktionen für SMP hinzugefügt

Kolja Strohm 6 years ago
parent
commit
b9ac67b32c
3 changed files with 137 additions and 1 deletions
  1. 54 0
      MainServer/Datenbank.cpp
  2. 23 1
      MainServer/Datenbank.h
  3. 60 0
      MainServer/MainServer.cpp

+ 54 - 0
MainServer/Datenbank.cpp

@@ -992,6 +992,60 @@ bool MSDatenbank::getMinigameServer( int client, Text *ip, int *port )
     return 1;
 }
 
+bool MSDatenbank::getPatchServerList( Array< ServerData* > *list )
+{
+    lock();
+    if( !datenbank->befehl( "SELECT a.id, a.name, a.ip, a.port, a.admin_port, b.bezeichnung FROM server a, server_status b WHERE a.server_status_id = b.id AND a.server_typ_name = 'patch'" ) )
+    {
+        unlock();
+        Result res;
+        res.feldAnzahl = 0;
+        res.zeilenAnzahl = 0;
+        res.felder = 0;
+        res.values = 0;
+        return 0;
+    }
+    Result res = datenbank->getResult();
+    unlock();
+    for( int i = 0; i < res.zeilenAnzahl; i++ )
+    {
+        ServerData *d = new ServerData();
+        d->id = res.values[ 0 + i * 6 ];
+        d->name = res.values[ 1 + i * 6 ].getText();
+        d->ip = res.values[ 2 + i * 6 ].getText();
+        d->port = (unsigned short)(int)res.values[ 3 + i * 6 ];
+        d->adminPort = (unsigned short)(int)res.values[ 4 + i * 6 ];
+        d->status = res.values[ 5 + i * 6 ].getText();
+        list->add( d );
+    }
+    res.destroy();
+    return 1;
+}
+
+bool MSDatenbank::getPatchServerDetails( int id, ServerDetails *details )
+{
+    Text befehl = "SELECT name, ip, port, admin_port, tasks, max_tasks FROM server WHERE id = ";
+    befehl += id;
+    lock();
+    if( !datenbank->befehl( befehl ) )
+    {
+        unlock();
+        return 0;
+    }
+    Result res = datenbank->getResult();
+    unlock();
+    if( !res.zeilenAnzahl )
+        return 0;
+    details->name = (char*)res.values[ 0 ];
+    details->ip = (char*)res.values[ 1 ];
+    details->port = (unsigned short)(int)res.values[ 2 ];
+    details->adminPort = (unsigned short)(int)res.values[ 3 ];
+    details->tasks = res.values[ 4 ];
+    details->maxTasks = res.values[ 5 ];
+    res.destroy();
+    return 1;
+}
+
 // Reference Counting
 MSDatenbank *MSDatenbank::getThis()
 {

+ 23 - 1
MainServer/Datenbank.h

@@ -14,6 +14,26 @@ namespace Admin_Recht
 	const int MSBeenden = 2;
 }
 
+struct ServerData
+{
+    int id;
+    Text name;
+    Text ip;
+    unsigned short port;
+    unsigned short adminPort;
+    Text status;
+};
+
+struct ServerDetails
+{
+    Text name;
+    Text ip;
+    unsigned short port;
+    unsigned short adminPort;
+    int tasks;
+    int maxTasks;
+};
+
 class MSDatenbank
 {
 private:
@@ -68,7 +88,9 @@ public:
     bool getKartenServer( int client, Text *ip, int *port );
     bool getEditorServer( int client, Text *ip, int *port );
     bool getMinigameServer( int client, Text *ip, int *port );
-	// Reference Counting
+    bool getPatchServerList( Array< ServerData* > *list );
+    bool getPatchServerDetails( int id, ServerDetails *details );
+    // Reference Counting
 	MSDatenbank *getThis();
 	MSDatenbank *release();
 };

+ 60 - 0
MainServer/MainServer.cpp

@@ -379,6 +379,66 @@ void MSAKlient::thread()
 					klient->sende( &status, 1 );
 				}
 				break;
+            case 9: // Patch Server Liste
+                if( adminId )
+                {
+                    Array< ServerData* > d;
+                    if( ms->zDB()->getPatchServerList( &d ) )
+                        klient->sende( "\1", 1 );
+                    else
+                        errorZuKlient( "Fehler beim Abruf der Patch Server Tabelle." );
+                    int anz = d.getEintragAnzahl();
+                    klient->sende( (char*)&anz, 4 );
+                    for( int i = 0; i < anz; i++ )
+                    {
+                        ServerData *s = d.get( i );
+                        klient->sende( (char*)&s->id, 4 );
+                        klient->sende( (char*)&s->port, 2 );
+                        klient->sende( (char*)&s->adminPort, 2 );
+                        unsigned char len = (unsigned char)s->name.getLength();
+                        klient->sende( (char*)&len, 1 );
+                        klient->sende( s->name, len );
+                        len = (unsigned char)s->ip.getLength();
+                        klient->sende( (char*)&len, 1 );
+                        klient->sende( s->ip, len );
+                        len = (unsigned char)s->status.getLength();
+                        klient->sende( (char*)&len, 1 );
+                        klient->sende( s->status, len );
+                        delete s;
+                    }
+                }
+                else
+                    errorZuKlient( "Du musst dich einloggen." );
+                break;
+            case 10: // get Patch Server Details
+            {
+                if( adminId )
+                {
+                    klient->sende( "\1", 1 );
+                    int id = 0;
+                    klient->getNachricht( (char*)&id, 4 );
+                    ServerDetails d;
+                    if( ms->zDB()->getPatchServerDetails( id, &d ) )
+                    {
+                        klient->sende( "\1", 1 );
+                        unsigned char len = (unsigned char)d.name.getLength();
+                        klient->sende( (char*)&len, 1 );
+                        klient->sende( d.name, len );
+                        len = (unsigned char)d.ip.getLength();
+                        klient->sende( (char*)&len, 1 );
+                        klient->sende( d.ip, len );
+                        klient->sende( (char*)&d.port, 2 );
+                        klient->sende( (char*)&d.adminPort, 2 );
+                        klient->sende( (char*)&d.tasks, 4 );
+                        klient->sende( (char*)&d.maxTasks, 4 );
+                    }
+                    else
+                        errorZuKlient( "Fehler beim abrufen der Server Details." );
+                }
+                else
+                    errorZuKlient( "Du musst dich einloggen." );
+                break;
+            }
 			default:
 				errorZuKlient( "Unbekannte Nachricht!" );
 				break;