|
@@ -4,17 +4,17 @@
|
|
// Inhalt der HSDatenbank Klasse aus Datenbank.h
|
|
// Inhalt der HSDatenbank Klasse aus Datenbank.h
|
|
// Konstruktor
|
|
// Konstruktor
|
|
HSDatenbank::HSDatenbank( InitDatei *zIni )
|
|
HSDatenbank::HSDatenbank( InitDatei *zIni )
|
|
|
|
+ : ReferenceCounter()
|
|
{
|
|
{
|
|
- 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 ) );
|
|
|
|
|
|
+ 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() )
|
|
if( !datenbank->istOk() )
|
|
{
|
|
{
|
|
std::cout << "HS: Die Verbindung zur Datenbank konnte nicht hergestellt werden.\nDas Programm wird beendet.";
|
|
std::cout << "HS: Die Verbindung zur Datenbank konnte nicht hergestellt werden.\nDas Programm wird beendet.";
|
|
exit( 1 );
|
|
exit( 1 );
|
|
}
|
|
}
|
|
- InitializeCriticalSection( &cs );
|
|
|
|
- ref = 1;
|
|
|
|
|
|
+ InitializeCriticalSection( &cs );
|
|
Text befehl = "SELECT port, admin_port FROM server WHERE id = ";
|
|
Text befehl = "SELECT port, admin_port FROM server WHERE id = ";
|
|
befehl += zIni->zWert( "ServerId" )->getText();
|
|
befehl += zIni->zWert( "ServerId" )->getText();
|
|
lock();
|
|
lock();
|
|
@@ -32,247 +32,232 @@ HSDatenbank::HSDatenbank( InitDatei *zIni )
|
|
// Destruktor
|
|
// Destruktor
|
|
HSDatenbank::~HSDatenbank()
|
|
HSDatenbank::~HSDatenbank()
|
|
{
|
|
{
|
|
- datenbank->release();
|
|
|
|
- DeleteCriticalSection( &cs );
|
|
|
|
|
|
+ datenbank->release();
|
|
|
|
+ DeleteCriticalSection( &cs );
|
|
}
|
|
}
|
|
|
|
|
|
// nicht constant
|
|
// nicht constant
|
|
void HSDatenbank::lock()
|
|
void HSDatenbank::lock()
|
|
{
|
|
{
|
|
- EnterCriticalSection( &cs );
|
|
|
|
|
|
+ EnterCriticalSection( &cs );
|
|
}
|
|
}
|
|
|
|
|
|
void HSDatenbank::unlock()
|
|
void HSDatenbank::unlock()
|
|
{
|
|
{
|
|
- LeaveCriticalSection( &cs );
|
|
|
|
|
|
+ LeaveCriticalSection( &cs );
|
|
}
|
|
}
|
|
|
|
|
|
int HSDatenbank::istAdministrator( const char *name, const char *passwort )
|
|
int HSDatenbank::istAdministrator( const char *name, const char *passwort )
|
|
{
|
|
{
|
|
- Text *befehl = new Text( "SELECT id FROM benutzer WHERE name = '" );
|
|
|
|
- Text n( name );
|
|
|
|
- n.ersetzen( "'", "''" );
|
|
|
|
- befehl->append( (char*)n );
|
|
|
|
- befehl->append( "' AND passwort = md5('" );
|
|
|
|
- Text p( passwort );
|
|
|
|
- p.ersetzen( "'", "''" );
|
|
|
|
- befehl->append( (char*)p );
|
|
|
|
- befehl->append( "')" );
|
|
|
|
- lock();
|
|
|
|
- datenbank->befehl( befehl->getText() );
|
|
|
|
- Result res = datenbank->getResult();
|
|
|
|
- unlock();
|
|
|
|
- befehl->release();
|
|
|
|
- int ret = 0;
|
|
|
|
- if( res.zeilenAnzahl > 0 )
|
|
|
|
- ret = TextZuInt( res.values[ 0 ].getText(), 10 );
|
|
|
|
- res.destroy();
|
|
|
|
- return ret;
|
|
|
|
|
|
+ Text *befehl = new Text( "SELECT id FROM benutzer WHERE name = '" );
|
|
|
|
+ Text n( name );
|
|
|
|
+ n.ersetzen( "'", "''" );
|
|
|
|
+ befehl->append( (char *)n );
|
|
|
|
+ befehl->append( "' AND passwort = md5('" );
|
|
|
|
+ Text p( passwort );
|
|
|
|
+ p.ersetzen( "'", "''" );
|
|
|
|
+ befehl->append( (char *)p );
|
|
|
|
+ befehl->append( "')" );
|
|
|
|
+ lock();
|
|
|
|
+ datenbank->befehl( befehl->getText() );
|
|
|
|
+ Result res = datenbank->getResult();
|
|
|
|
+ unlock();
|
|
|
|
+ befehl->release();
|
|
|
|
+ int ret = 0;
|
|
|
|
+ if( res.zeilenAnzahl > 0 )
|
|
|
|
+ ret = TextZuInt( res.values[ 0 ].getText(), 10 );
|
|
|
|
+ res.destroy();
|
|
|
|
+ return ret;
|
|
}
|
|
}
|
|
|
|
|
|
bool HSDatenbank::adminHatRecht( int id, int recht )
|
|
bool HSDatenbank::adminHatRecht( int id, int recht )
|
|
{
|
|
{
|
|
- Text *befehl = new Text( "SELECT * FROM benutzer_rechte WHERE benutzer_id = " );
|
|
|
|
- befehl->append( id );
|
|
|
|
- befehl->append( " AND rechte_id = " );
|
|
|
|
- befehl->append( recht );
|
|
|
|
- lock();
|
|
|
|
- datenbank->befehl( befehl->getText() );
|
|
|
|
- int ret = datenbank->getZeilenAnzahl();
|
|
|
|
- unlock();
|
|
|
|
- befehl->release();
|
|
|
|
- return ret != 0;
|
|
|
|
|
|
+ Text *befehl = new Text( "SELECT * FROM benutzer_rechte WHERE benutzer_id = " );
|
|
|
|
+ befehl->append( id );
|
|
|
|
+ befehl->append( " AND rechte_id = " );
|
|
|
|
+ befehl->append( recht );
|
|
|
|
+ lock();
|
|
|
|
+ datenbank->befehl( befehl->getText() );
|
|
|
|
+ int ret = datenbank->getZeilenAnzahl();
|
|
|
|
+ unlock();
|
|
|
|
+ befehl->release();
|
|
|
|
+ return ret != 0;
|
|
}
|
|
}
|
|
|
|
|
|
bool HSDatenbank::proveKlient( int num, int sNum )
|
|
bool HSDatenbank::proveKlient( int num, int sNum )
|
|
{
|
|
{
|
|
- Text *befehl = new Text( "SELECT * FROM server_client WHERE server_id = " );
|
|
|
|
- befehl->append( sNum );
|
|
|
|
- befehl->append( " AND client_id = " );
|
|
|
|
- befehl->append( num );
|
|
|
|
- lock();
|
|
|
|
- datenbank->befehl( befehl->getText() );
|
|
|
|
- Result res = datenbank->getResult();
|
|
|
|
- unlock();
|
|
|
|
- befehl->release();
|
|
|
|
- bool ret = 0;
|
|
|
|
- if( res.zeilenAnzahl == 1 )
|
|
|
|
- ret = 1;
|
|
|
|
- res.destroy();
|
|
|
|
- return ret;
|
|
|
|
|
|
+ Text *befehl = new Text( "SELECT * FROM server_client WHERE server_id = " );
|
|
|
|
+ befehl->append( sNum );
|
|
|
|
+ befehl->append( " AND client_id = " );
|
|
|
|
+ befehl->append( num );
|
|
|
|
+ lock();
|
|
|
|
+ datenbank->befehl( befehl->getText() );
|
|
|
|
+ Result res = datenbank->getResult();
|
|
|
|
+ unlock();
|
|
|
|
+ befehl->release();
|
|
|
|
+ bool ret = 0;
|
|
|
|
+ if( res.zeilenAnzahl == 1 )
|
|
|
|
+ ret = 1;
|
|
|
|
+ res.destroy();
|
|
|
|
+ return ret;
|
|
}
|
|
}
|
|
|
|
|
|
Text *HSDatenbank::getKlientKey( int cId )
|
|
Text *HSDatenbank::getKlientKey( int cId )
|
|
{
|
|
{
|
|
- lock();
|
|
|
|
- if( !datenbank->befehl( Text( "SELECT schluessel FROM client WHERE id = " ) += cId ) )
|
|
|
|
- {
|
|
|
|
- unlock();
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- Result res = datenbank->getResult();
|
|
|
|
- unlock();
|
|
|
|
- if( !res.zeilenAnzahl )
|
|
|
|
- {
|
|
|
|
- res.destroy();
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- Text *ret = new Text( res.values[ 0 ].getText() );
|
|
|
|
- res.destroy();
|
|
|
|
- return ret;
|
|
|
|
|
|
+ lock();
|
|
|
|
+ if( !datenbank->befehl( Text( "SELECT schluessel FROM client WHERE id = " ) += cId ) )
|
|
|
|
+ {
|
|
|
|
+ unlock();
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ Result res = datenbank->getResult();
|
|
|
|
+ unlock();
|
|
|
|
+ if( !res.zeilenAnzahl )
|
|
|
|
+ {
|
|
|
|
+ res.destroy();
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ Text *ret = new Text( res.values[ 0 ].getText() );
|
|
|
|
+ res.destroy();
|
|
|
|
+ return ret;
|
|
}
|
|
}
|
|
|
|
|
|
void HSDatenbank::unregisterKlient( int num, int sNum )
|
|
void HSDatenbank::unregisterKlient( int num, int sNum )
|
|
{
|
|
{
|
|
- Text *befehl = new Text( "DELETE FROM server_client WHERE client_id = " );
|
|
|
|
- befehl->append( num );
|
|
|
|
- befehl->append( " AND server_id = " );
|
|
|
|
- befehl->append( sNum );
|
|
|
|
- lock();
|
|
|
|
- datenbank->befehl( befehl->getText() );
|
|
|
|
- unlock();
|
|
|
|
- befehl->release();
|
|
|
|
|
|
+ Text *befehl = new Text( "DELETE FROM server_client WHERE client_id = " );
|
|
|
|
+ befehl->append( num );
|
|
|
|
+ befehl->append( " AND server_id = " );
|
|
|
|
+ befehl->append( sNum );
|
|
|
|
+ lock();
|
|
|
|
+ datenbank->befehl( befehl->getText() );
|
|
|
|
+ unlock();
|
|
|
|
+ befehl->release();
|
|
}
|
|
}
|
|
|
|
|
|
bool HSDatenbank::setServerStatus( int id, int status )
|
|
bool HSDatenbank::setServerStatus( int id, int status )
|
|
{
|
|
{
|
|
- Text *befehl = new Text( "UPDATE server SET server_status_id = " );
|
|
|
|
- *befehl += status;
|
|
|
|
- *befehl += "WHERE id = ";
|
|
|
|
- *befehl += id;
|
|
|
|
- lock();
|
|
|
|
- if( !datenbank->befehl( befehl->getText() ) )
|
|
|
|
- {
|
|
|
|
- unlock();
|
|
|
|
- befehl->release();
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- bool ret = datenbank->getZeilenAnzahl() != 0;
|
|
|
|
- unlock();
|
|
|
|
- befehl->release();
|
|
|
|
- return ret;
|
|
|
|
|
|
+ Text *befehl = new Text( "UPDATE server SET server_status_id = " );
|
|
|
|
+ *befehl += status;
|
|
|
|
+ *befehl += "WHERE id = ";
|
|
|
|
+ *befehl += id;
|
|
|
|
+ lock();
|
|
|
|
+ if( !datenbank->befehl( befehl->getText() ) )
|
|
|
|
+ {
|
|
|
|
+ unlock();
|
|
|
|
+ befehl->release();
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ bool ret = datenbank->getZeilenAnzahl() != 0;
|
|
|
|
+ unlock();
|
|
|
|
+ befehl->release();
|
|
|
|
+ return ret;
|
|
}
|
|
}
|
|
|
|
|
|
bool HSDatenbank::setMaxSpiele( int id, int maxS )
|
|
bool HSDatenbank::setMaxSpiele( int id, int maxS )
|
|
{
|
|
{
|
|
- Text *befehl = new Text( "UPDATE server SET max_tasks = " );
|
|
|
|
- befehl->append( maxS );
|
|
|
|
- befehl->append( " WHERE id = " );
|
|
|
|
- befehl->append( id );
|
|
|
|
- lock();
|
|
|
|
- if( !datenbank->befehl( befehl->getText() ) )
|
|
|
|
- {
|
|
|
|
- unlock();
|
|
|
|
- befehl->release();
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- bool ret = datenbank->getZeilenAnzahl() > 0;
|
|
|
|
- unlock();
|
|
|
|
- befehl->release();
|
|
|
|
- return ret;
|
|
|
|
|
|
+ Text *befehl = new Text( "UPDATE server SET max_tasks = " );
|
|
|
|
+ befehl->append( maxS );
|
|
|
|
+ befehl->append( " WHERE id = " );
|
|
|
|
+ befehl->append( id );
|
|
|
|
+ lock();
|
|
|
|
+ if( !datenbank->befehl( befehl->getText() ) )
|
|
|
|
+ {
|
|
|
|
+ unlock();
|
|
|
|
+ befehl->release();
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ bool ret = datenbank->getZeilenAnzahl() > 0;
|
|
|
|
+ unlock();
|
|
|
|
+ befehl->release();
|
|
|
|
+ return ret;
|
|
}
|
|
}
|
|
|
|
|
|
bool HSDatenbank::serverIstNichtPausiert( int id )
|
|
bool HSDatenbank::serverIstNichtPausiert( int id )
|
|
{
|
|
{
|
|
- Text *befehl = new Text( "SELECT server_status_id FROM server 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;
|
|
|
|
- }
|
|
|
|
- bool ret = (int)res.values[ 0 ] == 3;
|
|
|
|
- res.destroy();
|
|
|
|
- return ret;
|
|
|
|
|
|
+ Text *befehl = new Text( "SELECT server_status_id FROM server 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;
|
|
|
|
+ }
|
|
|
|
+ bool ret = (int)res.values[ 0 ] == 3;
|
|
|
|
+ res.destroy();
|
|
|
|
+ return ret;
|
|
}
|
|
}
|
|
|
|
|
|
bool HSDatenbank::getSpielServerPortIp( int id, short *port, Text *ip )
|
|
bool HSDatenbank::getSpielServerPortIp( int id, short *port, Text *ip )
|
|
{
|
|
{
|
|
- lock();
|
|
|
|
- if( !datenbank->befehl( Text( "SELECT admin_port, ip FROM server WHERE id = " ) += id ) )
|
|
|
|
- {
|
|
|
|
- unlock();
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- Result res = datenbank->getResult();
|
|
|
|
- unlock();
|
|
|
|
- if( !res.zeilenAnzahl )
|
|
|
|
- {
|
|
|
|
- res.destroy();
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- *port = (short)(int)res.values[ 0 ];
|
|
|
|
- *ip = res.values[ 1 ].getText();
|
|
|
|
- res.destroy();
|
|
|
|
- return 1;
|
|
|
|
|
|
+ lock();
|
|
|
|
+ if( !datenbank->befehl( Text( "SELECT admin_port, ip FROM server WHERE id = " ) += id ) )
|
|
|
|
+ {
|
|
|
|
+ unlock();
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ Result res = datenbank->getResult();
|
|
|
|
+ unlock();
|
|
|
|
+ if( !res.zeilenAnzahl )
|
|
|
|
+ {
|
|
|
|
+ res.destroy();
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ *port = (short)(int)res.values[ 0 ];
|
|
|
|
+ *ip = res.values[ 1 ].getText();
|
|
|
|
+ res.destroy();
|
|
|
|
+ return 1;
|
|
}
|
|
}
|
|
|
|
|
|
bool HSDatenbank::istSpielHistorieFrei( int id )
|
|
bool HSDatenbank::istSpielHistorieFrei( int id )
|
|
{
|
|
{
|
|
- lock();
|
|
|
|
- if( !datenbank->befehl( Text( "SELECT * FROM server_historie_spiel WHERE spiel_id = " ) += id ) )
|
|
|
|
- {
|
|
|
|
- unlock();
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- bool ret = datenbank->getZeilenAnzahl() == 0;
|
|
|
|
- unlock();
|
|
|
|
- return ret;
|
|
|
|
|
|
+ lock();
|
|
|
|
+ if( !datenbank->befehl( Text( "SELECT * FROM server_historie_spiel WHERE spiel_id = " ) += id ) )
|
|
|
|
+ {
|
|
|
|
+ unlock();
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ bool ret = datenbank->getZeilenAnzahl() == 0;
|
|
|
|
+ unlock();
|
|
|
|
+ return ret;
|
|
}
|
|
}
|
|
|
|
|
|
bool HSDatenbank::addSpielHistorie( int server, int spiel )
|
|
bool HSDatenbank::addSpielHistorie( int server, int spiel )
|
|
{
|
|
{
|
|
- Text *befehl = new Text( "INSERT INTO server_historie_spiel( spiel_id, server_historie_id ) VALUES( " );
|
|
|
|
- *befehl += spiel;
|
|
|
|
- *befehl += ", ";
|
|
|
|
- *befehl += server;
|
|
|
|
- *befehl += " )";
|
|
|
|
- lock();
|
|
|
|
- if( !datenbank->befehl( *befehl ) )
|
|
|
|
- {
|
|
|
|
- unlock();
|
|
|
|
- befehl->release();
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- unlock();
|
|
|
|
- befehl->release();
|
|
|
|
- lock();
|
|
|
|
- if( !datenbank->befehl( Text( "UPDATE server SET tasks = tasks + 1 WHERE id = " ) += server ) )
|
|
|
|
- {
|
|
|
|
- unlock();
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- unlock();
|
|
|
|
- return 1;
|
|
|
|
|
|
+ Text *befehl = new Text( "INSERT INTO server_historie_spiel( spiel_id, server_historie_id ) VALUES( " );
|
|
|
|
+ *befehl += spiel;
|
|
|
|
+ *befehl += ", ";
|
|
|
|
+ *befehl += server;
|
|
|
|
+ *befehl += " )";
|
|
|
|
+ lock();
|
|
|
|
+ if( !datenbank->befehl( *befehl ) )
|
|
|
|
+ {
|
|
|
|
+ unlock();
|
|
|
|
+ befehl->release();
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ unlock();
|
|
|
|
+ befehl->release();
|
|
|
|
+ lock();
|
|
|
|
+ if( !datenbank->befehl( Text( "UPDATE server SET tasks = tasks + 1 WHERE id = " ) += server ) )
|
|
|
|
+ {
|
|
|
|
+ unlock();
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ unlock();
|
|
|
|
+ return 1;
|
|
}
|
|
}
|
|
|
|
|
|
// constant
|
|
// constant
|
|
Text *HSDatenbank::getLetzterFehler() const
|
|
Text *HSDatenbank::getLetzterFehler() const
|
|
{
|
|
{
|
|
- return datenbank->getLetzterFehler();
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// Reference Counting
|
|
|
|
-HSDatenbank *HSDatenbank::getThis()
|
|
|
|
-{
|
|
|
|
- ref++;
|
|
|
|
- return this;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-HSDatenbank *HSDatenbank::release()
|
|
|
|
-{
|
|
|
|
- ref--;
|
|
|
|
- if( !ref )
|
|
|
|
- delete this;
|
|
|
|
- return 0;
|
|
|
|
|
|
+ return datenbank->getLetzterFehler();
|
|
}
|
|
}
|