|
@@ -1,24 +1,32 @@
|
|
|
#include "Datenbank.h"
|
|
|
+#include <iostream>
|
|
|
|
|
|
// Inhalt der LSDatenbank Klasse aus Datenbank.h
|
|
|
// Konstruktor
|
|
|
LSDatenbank::LSDatenbank( InitDatei *zIni )
|
|
|
{
|
|
|
- if( !zIni->wertExistiert( "DBBenutzer" ) )
|
|
|
- zIni->addWert( "DBBenutzer", "loginserveru" );
|
|
|
- if( !zIni->wertExistiert( "DBPasswort" ) )
|
|
|
- zIni->addWert( "DBPasswort", "LTLoginServerPW" );
|
|
|
- if( !zIni->wertExistiert( "DBName" ) )
|
|
|
- zIni->addWert( "DBName", "lenck_tech_db" );
|
|
|
- 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 << "LS: 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
|
|
@@ -45,11 +53,11 @@ int LSDatenbank::istAdministrator( const char *name, const char *passwort )
|
|
|
Text n( name );
|
|
|
n.ersetzen( "'", "''" );
|
|
|
befehl->append( (char*)n );
|
|
|
- befehl->append( "' AND passwort = '" );
|
|
|
+ befehl->append( "' AND passwort = md5( '" );
|
|
|
Text p( passwort );
|
|
|
p.ersetzen( "'", "''" );
|
|
|
befehl->append( (char*)p );
|
|
|
- befehl->append( "'" );
|
|
|
+ befehl->append( "' )" );
|
|
|
lock();
|
|
|
datenbank->befehl( befehl->getText() );
|
|
|
Result res = datenbank->getResult();
|
|
@@ -78,7 +86,7 @@ bool LSDatenbank::adminHatRecht( int id, int recht )
|
|
|
|
|
|
bool LSDatenbank::proveKlient( int num, int sNum )
|
|
|
{
|
|
|
- Text *befehl = new Text( "SELECT * FROM server_login_clients WHERE server_login_id = " );
|
|
|
+ Text *befehl = new Text( "SELECT * FROM server_client WHERE server_id = " );
|
|
|
befehl->append( sNum );
|
|
|
befehl->append( " AND client_id = " );
|
|
|
befehl->append( num );
|
|
@@ -97,7 +105,7 @@ bool LSDatenbank::proveKlient( int num, int sNum )
|
|
|
Text *LSDatenbank::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;
|
|
@@ -116,9 +124,9 @@ Text *LSDatenbank::getKlientKey( int cId )
|
|
|
|
|
|
void LSDatenbank::unregisterKlient( int num, int sNum )
|
|
|
{
|
|
|
- Text *befehl = new Text( "DELETE FROM server_login_clients WHERE client_id = " );
|
|
|
+ Text *befehl = new Text( "DELETE FROM server_client WHERE client_id = " );
|
|
|
befehl->append( num );
|
|
|
- befehl->append( " AND server_login_id = " );
|
|
|
+ befehl->append( " AND server_id = " );
|
|
|
befehl->append( sNum );
|
|
|
lock();
|
|
|
datenbank->befehl( befehl->getText() );
|
|
@@ -126,7 +134,7 @@ void LSDatenbank::unregisterKlient( int num, int sNum )
|
|
|
unlock();
|
|
|
if( za == 1 )
|
|
|
{
|
|
|
- befehl->setText( "UPDATE server_login SET clients = clients - 1 WHERE id = " );
|
|
|
+ befehl->setText( "UPDATE server SET tasks = tasks - 1 WHERE id = " );
|
|
|
befehl->append( sNum );
|
|
|
lock();
|
|
|
datenbank->befehl( befehl->getText() );
|
|
@@ -135,114 +143,9 @@ void LSDatenbank::unregisterKlient( int num, int sNum )
|
|
|
befehl->release();
|
|
|
}
|
|
|
|
|
|
-bool LSDatenbank::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( "MaxClients" ) )
|
|
|
- zIni->addWert( "MaxClients", "50" );
|
|
|
- bool insert = 0;
|
|
|
- int id = *zIni->zWert( "ServerId" );
|
|
|
- if( id )
|
|
|
- {
|
|
|
- lock();
|
|
|
- if( !datenbank->befehl( Text( "SELECT id FROM server_login 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_login 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_login
|
|
|
- Text *befehl = new Text( "INSERT INTO server_login( " );
|
|
|
- if( id )
|
|
|
- *befehl += "id, ";
|
|
|
- *befehl += "name, ip, port, admin_port, server_status_id, max_clients ) 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( "MaxClients" )->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_login ändern
|
|
|
- Text *befehl = new Text( "UPDATE server_login SET name = '" );
|
|
|
- *befehl += zIni->zWert( "ServerName" )->getText();
|
|
|
- *befehl += "', port = ";
|
|
|
- *befehl += zIni->zWert( "ServerPort" )->getText();
|
|
|
- *befehl += ", ip = '";
|
|
|
- *befehl += zIni->zWert( "ServerIP" )->getText();
|
|
|
- *befehl += "', max_clients = ";
|
|
|
- *befehl += zIni->zWert( "MaxClients" )->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 LSDatenbank::setServerStatus( int id, int status )
|
|
|
{
|
|
|
- Text *befehl = new Text( "UPDATE server_login SET server_status_id = " );
|
|
|
+ Text *befehl = new Text( "UPDATE server SET server_status_id = " );
|
|
|
*befehl += status;
|
|
|
*befehl += "WHERE id = ";
|
|
|
*befehl += id;
|
|
@@ -261,7 +164,7 @@ bool LSDatenbank::setServerStatus( int id, int status )
|
|
|
|
|
|
bool LSDatenbank::setMaxClients( int id, int maxC )
|
|
|
{
|
|
|
- Text *befehl = new Text( "UPDATE server_login SET max_clients = " );
|
|
|
+ Text *befehl = new Text( "UPDATE server SET max_tasks = " );
|
|
|
befehl->append( maxC );
|
|
|
befehl->append( " WHERE id = " );
|
|
|
befehl->append( id );
|
|
@@ -278,33 +181,9 @@ bool LSDatenbank::setMaxClients( int id, int maxC )
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-int LSDatenbank::getAdminPort( int id )
|
|
|
-{
|
|
|
- Text *befehl = new Text( "SELECT admin_port FROM server_login 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 LSDatenbank::serverIstNichtPausiert( int id )
|
|
|
{
|
|
|
- Text *befehl = new Text( "SELECT server_status_id FROM server_login WHERE id = " );
|
|
|
+ Text *befehl = new Text( "SELECT server_status_id FROM server WHERE id = " );
|
|
|
befehl->append( id );
|
|
|
lock();
|
|
|
if( !datenbank->befehl( befehl->getText() ) )
|
|
@@ -332,11 +211,11 @@ int LSDatenbank::getAccountId( char *name, char *pass )
|
|
|
Text n( name );
|
|
|
n.ersetzen( "'", "''" );
|
|
|
befehl->append( (char*)n );
|
|
|
- befehl->append( "' AND passwort = '" );
|
|
|
+ befehl->append( "' AND passwort = md5( '" );
|
|
|
Text p( pass );
|
|
|
p.ersetzen( "'", "''" );
|
|
|
befehl->append( (char*)p );
|
|
|
- befehl->append( "'" );
|
|
|
+ befehl->append( "' )" );
|
|
|
lock();
|
|
|
datenbank->befehl( befehl->getText() );
|
|
|
Result res = datenbank->getResult();
|
|
@@ -463,7 +342,7 @@ int LSDatenbank::logoutKlient( int klientId, Array< int > *ret )
|
|
|
|
|
|
Text **LSDatenbank::getChatServerIpPort( int id )
|
|
|
{
|
|
|
- Text *befehl = new Text( "SELECT ip, port FROM server_chat WHERE id = " );
|
|
|
+ Text *befehl = new Text( "SELECT ip, port FROM server WHERE id = " );
|
|
|
befehl->append( id );
|
|
|
lock();
|
|
|
datenbank->befehl( befehl->getText() );
|
|
@@ -483,7 +362,7 @@ Text **LSDatenbank::getChatServerIpPort( int id )
|
|
|
|
|
|
bool LSDatenbank::getSpielServerPortIp( int spielErstelltId, unsigned short *port, Text *ip )
|
|
|
{
|
|
|
- Text *befehl = new Text( "SELECT a.port, a.ip FROM server_spiel a, spiel_erstellt b "
|
|
|
+ Text *befehl = new Text( "SELECT a.port, a.ip FROM server a, spiel_erstellt b "
|
|
|
"WHERE a.id = b.server_spiel_id AND b.id = " );
|
|
|
befehl->append( spielErstelltId );
|
|
|
lock();
|
|
@@ -546,8 +425,8 @@ int LSDatenbank::kickSpielerAusGruppe( int gruppeId, int accountId )
|
|
|
|
|
|
bool LSDatenbank::getChatServerPortIp( int accountId, unsigned short *port, Text *ip )
|
|
|
{
|
|
|
- Text *befehl = new Text( "SELECT a.port, a.ip FROM server_chat AS a, server_chat_clients AS b, account_clients AS c "
|
|
|
- "WHERE c.client_id = b.client_id AND a.id = b.server_chat_id AND c.account_id = " );
|
|
|
+ Text *befehl = new Text( "SELECT a.port, a.ip FROM server a, server_client b, account_client c "
|
|
|
+ "WHERE a.server_typ_id = 'chat' AND c.client_id = b.client_id AND a.id = b.server_id AND c.account_id = " );
|
|
|
befehl->append( accountId );
|
|
|
lock();
|
|
|
if( !datenbank->befehl( befehl->getText() ) )
|