|
@@ -1,25 +1,33 @@
|
|
|
#include "Datenbank.h"
|
|
|
#include <Zeit.h>
|
|
|
+#include <iostream>
|
|
|
|
|
|
// Inhalt der LSDatenbank Klasse aus Datenbank.h
|
|
|
// Konstruktor
|
|
|
EdSDatenbank::EdSDatenbank( InitDatei *zIni )
|
|
|
{
|
|
|
- if( !zIni->wertExistiert( "DBBenutzer" ) )
|
|
|
- zIni->addWert( "DBBenutzer", "editorserveru" );
|
|
|
- if( !zIni->wertExistiert( "DBPasswort" ) )
|
|
|
- zIni->addWert( "DBPasswort", "LTEditorServerPW" );
|
|
|
- if( !zIni->wertExistiert( "DBName" ) )
|
|
|
- zIni->addWert( "DBName", "koljadb" );
|
|
|
- if( !zIni->wertExistiert( "DBIP" ) )
|
|
|
- zIni->addWert( "DBIP", "127.0.0.1" );
|
|
|
- if( !zIni->wertExistiert( "DBPort" ) )
|
|
|
- zIni->addWert( "DBPort", "5432" );
|
|
|
datenbank = new Datenbank( zIni->zWert( "DBBenutzer" )->getText(), zIni->zWert( "DBPasswort" )->getText(),
|
|
|
zIni->zWert( "DBName" )->getText(), zIni->zWert( "DBIP" )->getText(),
|
|
|
(unsigned short)TextZuInt( zIni->zWert( "DBPort" )->getText(), 10 ) );
|
|
|
+ if( !datenbank->istOk() )
|
|
|
+ {
|
|
|
+ std::cout << "EdS: Die Verbindung zur Datenbank konnte nicht hergestellt werden.\nDas Programm wird beendet.";
|
|
|
+ exit( 1 );
|
|
|
+ }
|
|
|
InitializeCriticalSection( &cs );
|
|
|
ref = 1;
|
|
|
+ Text befehl = "SELECT port, admin_port FROM server WHERE id = ";
|
|
|
+ befehl += zIni->zWert( "ServerId" )->getText();
|
|
|
+ lock();
|
|
|
+ datenbank->befehl( befehl );
|
|
|
+ Result res = datenbank->getResult();
|
|
|
+ unlock();
|
|
|
+ if( res.zeilenAnzahl == 1 )
|
|
|
+ {
|
|
|
+ zIni->addWert( "ServerPort", res.values[ 0 ] );
|
|
|
+ zIni->addWert( "AdminServerPort", res.values[ 1 ] );
|
|
|
+ }
|
|
|
+ res.destroy();
|
|
|
}
|
|
|
|
|
|
// Destruktor
|
|
@@ -44,9 +52,9 @@ int EdSDatenbank::istAdministrator( const char *name, const char *passwort )
|
|
|
{
|
|
|
Text *befehl = new Text( "SELECT id FROM benutzer WHERE name = '" );
|
|
|
befehl->append( name );
|
|
|
- befehl->append( "' AND passwort = '" );
|
|
|
+ befehl->append( "' AND passwort = md5('" );
|
|
|
befehl->append( passwort );
|
|
|
- befehl->append( "'" );
|
|
|
+ befehl->append( "')" );
|
|
|
lock();
|
|
|
datenbank->befehl( befehl->getText() );
|
|
|
Result res = datenbank->getResult();
|
|
@@ -75,7 +83,7 @@ bool EdSDatenbank::adminHatRecht( int id, int recht )
|
|
|
|
|
|
bool EdSDatenbank::proveKlient( int num, int sNum )
|
|
|
{
|
|
|
- Text *befehl = new Text( "SELECT * FROM server_editor_clients WHERE server_editor_id = " );
|
|
|
+ Text *befehl = new Text( "SELECT * FROM server_client WHERE server_id = " );
|
|
|
befehl->append( sNum );
|
|
|
befehl->append( " AND client_id = " );
|
|
|
befehl->append( num );
|
|
@@ -94,7 +102,7 @@ bool EdSDatenbank::proveKlient( int num, int sNum )
|
|
|
Text *EdSDatenbank::getKlientKey( int cId )
|
|
|
{
|
|
|
lock();
|
|
|
- if( !datenbank->befehl( Text( "SELECT schluessel FROM clients WHERE id = " ) += cId ) )
|
|
|
+ if( !datenbank->befehl( Text( "SELECT schluessel FROM client WHERE id = " ) += cId ) )
|
|
|
{
|
|
|
unlock();
|
|
|
return 0;
|
|
@@ -113,7 +121,7 @@ Text *EdSDatenbank::getKlientKey( int cId )
|
|
|
|
|
|
void EdSDatenbank::unregisterKlient( int num, int sNum )
|
|
|
{
|
|
|
- Text *befehl = new Text( "DELETE FROM server_editor_clients WHERE client_id = " );
|
|
|
+ Text *befehl = new Text( "DELETE FROM server_client WHERE client_id = " );
|
|
|
befehl->append( num );
|
|
|
befehl->append( " AND server_editor_id = " );
|
|
|
befehl->append( sNum );
|
|
@@ -123,114 +131,9 @@ void EdSDatenbank::unregisterKlient( int num, int sNum )
|
|
|
befehl->release();
|
|
|
}
|
|
|
|
|
|
-bool EdSDatenbank::serverAnmelden( InitDatei *zIni )
|
|
|
-{
|
|
|
- if( !zIni->wertExistiert( "ServerId" ) )
|
|
|
- zIni->addWert( "ServerId", "0" );
|
|
|
- if( !zIni->wertExistiert( "ServerName" ) )
|
|
|
- zIni->addWert( "ServerName", "Name" );
|
|
|
- if( !zIni->wertExistiert( "ServerPort" ) )
|
|
|
- zIni->addWert( "ServerPort", "49144" );
|
|
|
- if( !zIni->wertExistiert( "ServerIP" ) )
|
|
|
- zIni->addWert( "ServerIP", "127.0.0.1" );
|
|
|
- if( !zIni->wertExistiert( "AdminServerPort" ) )
|
|
|
- zIni->addWert( "AdminServerPort", "49143" );
|
|
|
- if( !zIni->wertExistiert( "Aktiv" ) )
|
|
|
- zIni->addWert( "Aktiv", "FALSE" );
|
|
|
- if( !zIni->wertExistiert( "MaxKarten" ) )
|
|
|
- zIni->addWert( "MaxKarten", "50" );
|
|
|
- bool insert = 0;
|
|
|
- int id = *zIni->zWert( "ServerId" );
|
|
|
- if( id )
|
|
|
- {
|
|
|
- lock();
|
|
|
- if( !datenbank->befehl( Text( "SELECT id FROM server_editor WHERE id = " ) += id ) )
|
|
|
- {
|
|
|
- unlock();
|
|
|
- return 0;
|
|
|
- }
|
|
|
- int anz = datenbank->getZeilenAnzahl();
|
|
|
- unlock();
|
|
|
- insert = anz == 0;
|
|
|
- if( !insert )
|
|
|
- {
|
|
|
- lock();
|
|
|
- if( !datenbank->befehl( Text( "SELECT id FROM server_editor WHERE server_status_id = 1 AND id = " ) += id ) )
|
|
|
- {
|
|
|
- unlock();
|
|
|
- return 0;
|
|
|
- }
|
|
|
- int anz = datenbank->getZeilenAnzahl();
|
|
|
- unlock();
|
|
|
- if( !anz ) // Server läuft bereits
|
|
|
- return 0;
|
|
|
- }
|
|
|
- }
|
|
|
- if( insert || !id )
|
|
|
- { // Neuer Eintrag in Tabelle server_editor
|
|
|
- Text *befehl = new Text( "INSERT INTO server_editor( " );
|
|
|
- if( id )
|
|
|
- *befehl += "id, ";
|
|
|
- *befehl += "name, ip, port, admin_port, server_status_id, max_karten ) VALUES( ";
|
|
|
- if( id )
|
|
|
- {
|
|
|
- *befehl += id;
|
|
|
- *befehl += ", ";
|
|
|
- }
|
|
|
- *befehl += "'";
|
|
|
- *befehl += zIni->zWert( "ServerName" )->getText();
|
|
|
- *befehl += "', '";
|
|
|
- *befehl += zIni->zWert( "ServerIP" )->getText();
|
|
|
- *befehl += "', ";
|
|
|
- *befehl += zIni->zWert( "ServerPort" )->getText();
|
|
|
- *befehl += ", ";
|
|
|
- *befehl += zIni->zWert( "AdminServerPort" )->getText();
|
|
|
- *befehl += ", 1, ";
|
|
|
- *befehl += zIni->zWert( "MaxKarten" )->getText();
|
|
|
- *befehl += " ) RETURNING id";
|
|
|
- lock();
|
|
|
- if( !datenbank->befehl( *befehl ) )
|
|
|
- {
|
|
|
- unlock();
|
|
|
- befehl->release();
|
|
|
- return 0;
|
|
|
- }
|
|
|
- Result res = datenbank->getResult();
|
|
|
- unlock();
|
|
|
- befehl->release();
|
|
|
- if( !res.zeilenAnzahl )
|
|
|
- {
|
|
|
- res.destroy();
|
|
|
- return 0;
|
|
|
- }
|
|
|
- zIni->setWert( "ServerId", res.values[ 0 ] );
|
|
|
- return 1;
|
|
|
- }
|
|
|
- else
|
|
|
- { // Alten Eintrag aus Tabelle server_editor ändern
|
|
|
- Text *befehl = new Text( "UPDATE server_editor SET name = '" );
|
|
|
- *befehl += zIni->zWert( "ServerName" )->getText();
|
|
|
- *befehl += "', port = ";
|
|
|
- *befehl += zIni->zWert( "ServerPort" )->getText();
|
|
|
- *befehl += ", ip = '";
|
|
|
- *befehl += zIni->zWert( "ServerIP" )->getText();
|
|
|
- *befehl += "', max_karten = ";
|
|
|
- *befehl += zIni->zWert( "MaxKarten" )->getText();
|
|
|
- *befehl += ", admin_port = ";
|
|
|
- *befehl += zIni->zWert( "AdminServerPort" )->getText();
|
|
|
- *befehl += " WHERE id = ";
|
|
|
- *befehl += id;
|
|
|
- lock();
|
|
|
- bool ret = datenbank->befehl( *befehl );
|
|
|
- unlock();
|
|
|
- befehl->release();
|
|
|
- return ret;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
bool EdSDatenbank::setServerStatus( int id, int status )
|
|
|
{
|
|
|
- Text *befehl = new Text( "UPDATE server_editor SET server_status_id = " );
|
|
|
+ Text *befehl = new Text( "UPDATE server SET server_status_id = " );
|
|
|
*befehl += status;
|
|
|
*befehl += "WHERE id = ";
|
|
|
*befehl += id;
|
|
@@ -249,7 +152,7 @@ bool EdSDatenbank::setServerStatus( int id, int status )
|
|
|
|
|
|
bool EdSDatenbank::setMaxKarten( int id, int maxK )
|
|
|
{
|
|
|
- Text *befehl = new Text( "UPDATE server_editor SET max_karten = " );
|
|
|
+ Text *befehl = new Text( "UPDATE server SET max_tasks = " );
|
|
|
befehl->append( maxK );
|
|
|
befehl->append( " WHERE id = " );
|
|
|
befehl->append( id );
|
|
@@ -266,33 +169,9 @@ bool EdSDatenbank::setMaxKarten( int id, int maxK )
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-int EdSDatenbank::getAdminPort( int id )
|
|
|
-{
|
|
|
- Text *befehl = new Text( "SELECT admin_port FROM server_editor WHERE id = " );
|
|
|
- befehl->append( id );
|
|
|
- lock();
|
|
|
- if( !datenbank->befehl( befehl->getText() ) )
|
|
|
- {
|
|
|
- unlock();
|
|
|
- befehl->release();
|
|
|
- return 0;
|
|
|
- }
|
|
|
- Result res = datenbank->getResult();
|
|
|
- unlock();
|
|
|
- befehl->release();
|
|
|
- if( !res.zeilenAnzahl )
|
|
|
- {
|
|
|
- res.destroy();
|
|
|
- return 0;
|
|
|
- }
|
|
|
- int ret = TextZuInt( res.values[ 0 ].getText(), 10 );
|
|
|
- res.destroy();
|
|
|
- return ret;
|
|
|
-}
|
|
|
-
|
|
|
bool EdSDatenbank::serverIstNichtPausiert( int id )
|
|
|
{
|
|
|
- Text *befehl = new Text( "SELECT server_status_id FROM server_editor WHERE id = " );
|
|
|
+ Text *befehl = new Text( "SELECT server_status_id FROM server WHERE id = " );
|
|
|
befehl->append( id );
|
|
|
lock();
|
|
|
if( !datenbank->befehl( befehl->getText() ) )
|
|
@@ -338,7 +217,7 @@ Text *EdSDatenbank::getKarteName( int id )
|
|
|
|
|
|
bool EdSDatenbank::proveKarte( int id, int cId, int sNum )
|
|
|
{
|
|
|
- Text befehl = "SELECT a.id FROM karte a, account_clients b WHERE a.id = ";
|
|
|
+ Text befehl = "SELECT a.id FROM karte a, account_client b WHERE a.id = ";
|
|
|
befehl += id;
|
|
|
befehl += " AND a.account_id = b.account_id AND b.client_id = ";
|
|
|
befehl += cId;
|
|
@@ -573,7 +452,7 @@ bool EdSDatenbank::karteErstellen( const char *name, int spielArt, int klient )
|
|
|
return 0;
|
|
|
}
|
|
|
unlock();
|
|
|
- befehl = "SELECT account_id FROM account_clients WHERE client_id = ";
|
|
|
+ befehl = "SELECT account_id FROM account_client WHERE client_id = ";
|
|
|
befehl = klient;
|
|
|
lock();
|
|
|
if( !datenbank->befehl( befehl ) )
|