123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830 |
- #include "Datenbank.h"
- // Inhalt der CSDatenbank Klasse aus Datenbank.h
- // Konstruktor
- CSDatenbank::CSDatenbank( InitDatei *zIni )
- {
- if( !zIni->wertExistiert( "DBBenutzer" ) )
- zIni->addWert( "DBBenutzer", "chatserveru" );
- if( !zIni->wertExistiert( "DBPasswort" ) )
- zIni->addWert( "DBPasswort", "LTChatServerPW" );
- 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 ) );
- InitializeCriticalSection( &cs );
- ref = 1;
- }
- // Destruktor
- CSDatenbank::~CSDatenbank()
- {
- datenbank->release();
- DeleteCriticalSection( &cs );
- }
- // nicht constant
- void CSDatenbank::lock()
- {
- EnterCriticalSection( &cs );
- }
- void CSDatenbank::unlock()
- {
- LeaveCriticalSection( &cs );
- }
- int CSDatenbank::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 = '" );
- 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 CSDatenbank::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;
- }
- bool CSDatenbank::proveKlient( int num, int sNum )
- {
- Text *befehl = new Text( "SELECT * FROM server_chat_clients WHERE server_chat_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 *CSDatenbank::getKlientKey( int cId )
- {
- lock();
- if( !datenbank->befehl( Text( "SELECT schluessel FROM clients 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 CSDatenbank::unregisterKlient( int num, int sNum )
- {
- Text *befehl = new Text( "DELETE FROM server_chat_clients WHERE client_id = " );
- befehl->append( num );
- befehl->append( " AND server_chat_id = " );
- befehl->append( sNum );
- lock();
- datenbank->befehl( befehl->getText() );
- int za = datenbank->getZeilenAnzahl();
- unlock();
- if( za == 1 )
- {
- befehl->setText( "UPDATE server_chat SET clients = clients - 1 WHERE id = " );
- befehl->append( sNum );
- lock();
- datenbank->befehl( befehl->getText() );
- unlock();
- }
- befehl->release();
- }
- bool CSDatenbank::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_chat 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_chat 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_chat
- Text *befehl = new Text( "INSERT INTO server_chat( " );
- 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_chat ändern
- Text *befehl = new Text( "UPDATE server_chat 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 CSDatenbank::setServerStatus( int id, int status )
- {
- Text *befehl = new Text( "UPDATE server_chat 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 CSDatenbank::setMaxClients( int id, int maxC )
- {
- Text *befehl = new Text( "UPDATE server_chat SET max_clients = " );
- befehl->append( maxC );
- 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;
- }
- int CSDatenbank::getAdminPort( int id )
- {
- Text *befehl = new Text( "SELECT admin_port FROM server_chat 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 CSDatenbank::serverIstNichtPausiert( int id )
- {
- Text *befehl = new Text( "SELECT server_status_id FROM server_chat 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;
- }
- int CSDatenbank::getKlientAccountId( int klientId )
- {
- Text *befehl = new Text( "SELECT account_id FROM account_clients WHERE client_id = " );
- befehl->append( klientId );
- lock();
- datenbank->befehl( befehl->getText() );
- Result res = datenbank->getResult();
- unlock();
- befehl->release();
- if( res.zeilenAnzahl )
- {
- int ret = TextZuInt( res.values[ 0 ].getText(), 10 );
- res.destroy();
- return ret;
- }
- res.destroy();
- return 0;
- }
- int CSDatenbank::getAccountFreunde( int accountId, Array< int > *fAccountId )
- {
- Text *befehl = new Text( "SELECT account_id AS freundId FROM freund WHERE freund_account_id = " );
- befehl->append( accountId );
- befehl->append( " UNION SELECT freund_account_id AS freundId FROM freund WHERE account_id = " );
- befehl->append( accountId );
- lock();
- datenbank->befehl( befehl->getText() );
- Result res = datenbank->getResult();
- unlock();
- befehl->release();
- int anzahl = res.zeilenAnzahl;
- for( int i = 0; i < anzahl; i++ )
- fAccountId->add( TextZuInt( res.values[ i ].getText(), 10 ), i );
- res.destroy();
- return anzahl;
- }
- int CSDatenbank::getAccountOnlineFreunde( int accountId, Array< int > *fAccountId )
- {
- Text *befehl = new Text( "SELECT freund.account_id AS freundId FROM freund, account_clients WHERE freund.freund_account_id = " );
- befehl->append( accountId );
- befehl->append( " AND freund.account_id = account_clients.account_id "
- "UNION SELECT freund.freund_account_id AS freundId FROM freund, account_clients WHERE freund.account_id = " );
- befehl->append( accountId );
- befehl->append( " AND freund.freund_account_id = account_clients.account_id " );
- lock();
- datenbank->befehl( befehl->getText() );
- Result res = datenbank->getResult();
- unlock();
- befehl->release();
- int anzahl = res.zeilenAnzahl;
- for( int i = 0; i < anzahl; i++ )
- fAccountId->add( TextZuInt( res.values[ i ].getText(), 10 ), i );
- res.destroy();
- return anzahl;
- }
- bool CSDatenbank::accountNameChange( int accountId, const char *name )
- {
- if( !name )
- return 1;
- Text *befehl = new Text( "UPDATE account SET ruf_name = '" );
- Text n( name );
- n.ersetzen( "'", "''" );
- befehl->append( (char*)n );
- befehl->append( "' WHERE id = " );
- befehl->append( accountId );
- bool ret = 0;
- lock();
- ret = datenbank->befehl( befehl->getText() );
- unlock();
- befehl->release();
- return ret;
- }
- bool CSDatenbank::beendeFreundschaft( int accountId1, int accountId2 )
- {
- Text *befehl = new Text( "DELETE FROM freund WHERE ( account_id = " );
- befehl->append( accountId1 );
- befehl->append( " AND freund_account_id = " );
- befehl->append( accountId2 );
- befehl->append( " ) OR ( freund_account_id = " );
- befehl->append( accountId1 );
- befehl->append( " AND account_id = " );
- befehl->append( accountId2 );
- befehl->append( " )" );
- lock();
- if( !datenbank->befehl( befehl->getText() ) )
- {
- unlock();
- return 0;
- }
- unlock();
- befehl->release();
- return 1;
- }
- bool CSDatenbank::proveFreundschaftsAnfrage( int vonAccountId, int zuAccountId )
- {
- if( vonAccountId == zuAccountId )
- return 0;
- Text *befehl = new Text( "SELECT account_id AS freundId FROM freund WHERE freund_account_id = " );
- befehl->append( vonAccountId );
- befehl->append( " AND freund.account_id = " );
- befehl->append( zuAccountId );
- befehl->append( "UNION SELECT freund_account_id AS freundId FROM freund WHERE freund_account_id = " );
- befehl->append( zuAccountId );
- befehl->append( " AND freund.account_id = " );
- befehl->append( vonAccountId );
- lock();
- datenbank->befehl( befehl->getText() );
- Result res = datenbank->getResult();
- unlock();
- befehl->release();
- bool ret = res.zeilenAnzahl == 0;
- res.destroy();
- return ret;
- }
- bool CSDatenbank::saveFreundschaftsAnfrage( int vonAccountId, int zuAccountId )
- {
- Text *befehl = new Text( "SELECT account_id FROM freund_anfrage WHERE ( account_id = " );
- befehl->append( vonAccountId );
- befehl->append( " AND freund_id = " );
- befehl->append( zuAccountId );
- befehl->append( " ) OR ( freund_id = " );
- befehl->append( vonAccountId );
- befehl->append( " AND account_id = " );
- befehl->append( zuAccountId );
- befehl->append( " )" );
- lock();
- if( !datenbank->befehl( befehl->getText() ) )
- {
- unlock();
- befehl->release();
- return 0;
- }
- Result res = datenbank->getResult();
- unlock();
- if( res.zeilenAnzahl )
- {
- res.destroy();
- befehl->release();
- return 1;
- }
- res.destroy();
- befehl->setText( "INSERT INTO freund_anfrage( account_id, freund_id ) VALUES( " );
- befehl->append( vonAccountId );
- befehl->append( ", " );
- befehl->append( zuAccountId );
- befehl->append( " )" );
- lock();
- if( !datenbank->befehl( befehl->getText() ) )
- {
- unlock();
- befehl->release();
- return 0;
- }
- unlock();
- befehl->release();
- return 1;
- }
- int CSDatenbank::getFreundschaftsAnfragen( int accountId, Array< int > *vonAccountIds )
- {
- Text *befehl = new Text( "SELECT account_id FROM freund_anfrage WHERE freund_id = " );
- befehl->append( accountId );
- lock();
- if( !datenbank->befehl( befehl->getText() ) )
- {
- unlock();
- befehl->release();
- return 0;
- }
- Result res = datenbank->getResult();
- unlock();
- befehl->setText( "DELETE FROM freund_anfrage WHERE freund_id = " );
- befehl->append( accountId ); lock();
- if( !datenbank->befehl( befehl->getText() ) )
- {
- unlock();
- befehl->release();
- res.destroy();
- return 0;
- }
- unlock();
- befehl->release();
- int anzahl = res.zeilenAnzahl;
- for( int i = 0; i < anzahl; i++ )
- vonAccountIds->set( res.values[ i ], i );
- res.destroy();
- return anzahl;
- }
- bool CSDatenbank::neueFreundschaft( int accountId1, int accountId2 )
- {
- Text *befehl = new Text( "INSERT INTO freund VALUES( " );
- befehl->append( accountId1 );
- befehl->append( ", " );
- befehl->append( accountId2 );
- befehl->append( " )" );
- lock();
- bool ret = datenbank->befehl( befehl->getText() );
- unlock();
- befehl->release();
- return ret;
- }
- Text *CSDatenbank::getAccountRufName( int accountId )
- {
- Text *befehl = new Text( "SELECT ruf_name FROM account WHERE id = " );
- befehl->append( accountId );
- lock();
- datenbank->befehl( befehl->getText() );
- Result res = datenbank->getResult();
- unlock();
- befehl->release();
- Text *ret = new Text( res.values[ 0 ].getText() );
- res.destroy();
- return ret;
- }
- bool CSDatenbank::accountIstOnline( int accountId )
- {
- Text *befehl = new Text( "SELECT * FROM account_clients WHERE account_id = " );
- befehl->append( accountId );
- lock();
- datenbank->befehl( befehl->getText() );
- int res = datenbank->getZeilenAnzahl();
- unlock();
- befehl->release();
- return res != 0;
- }
- bool CSDatenbank::accountIstImSpiel( int accountId )
- {
- Text *befehl = new Text( "SELECT b.id FROM spiel_spieler a, spiel b WHERE b.spiel_status_id = 2 "
- "AND a.spiel_spieler_status_id = 5 AND a.spiel_id = b.id AND a.account_id = " );
- befehl->append( accountId );
- lock();
- datenbank->befehl( befehl->getText() );
- int res = datenbank->getZeilenAnzahl();
- unlock();
- befehl->release();
- return res != 0;
- }
- int CSDatenbank::getChatServerId( int accountId )
- {
- Text *befehl = new Text( "SELECT server_chat_clients.server_chat_id FROM server_chat_clients, account_clients "
- "WHERE server_chat_clients.client_id = account_clients.client_id AND account_clients.account_id = " );
- befehl->append( accountId );
- lock();
- datenbank->befehl( befehl->getText() );
- 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 CSDatenbank::getChatServerIpPort( int serverId, unsigned short *port, char **ip )
- {
- Text *befehl = new Text( "SELECT port, ip FROM server_chat WHERE id = " );
- befehl->append( serverId );
- lock();
- datenbank->befehl( befehl->getText() );
- Result res = datenbank->getResult();
- unlock();
- befehl->release();
- if( !res.zeilenAnzahl )
- {
- res.destroy();
- return 0;
- }
- *port = (unsigned short)TextZuInt( res.values[ 0 ].getText(), 10 );
- int len = res.values[ 1 ].getLength();
- char *ipTmp = new char[ len + 1 ];
- ipTmp[ len ] = 0;
- int i = 0;
- for( char *c = res.values[ 1 ].getText(); i < len; c++ )
- {
- ipTmp[ i ] = *c;
- i++;
- }
- res.destroy();
- return 1;
- }
- int CSDatenbank::getChatNachrichten( int accountId, Array< int > *vonAccount, RCArray< Text > *nachricht )
- {
- Text *befehl = new Text( "SELECT von_account_id, nachricht FROM chat_nachricht WHERE zu_account_id = " );
- befehl->append( accountId );
- lock();
- datenbank->befehl( befehl->getText() );
- Result res = datenbank->getResult();
- unlock();
- if( !res.zeilenAnzahl )
- {
- befehl->release();
- res.destroy();
- return 0;
- }
- int ret = res.zeilenAnzahl;
- for( int i = 0; i < ret; i++ )
- {
- vonAccount->add( TextZuInt( res.values[ i * 2 ].getText(), 10 ), i );
- nachricht->add( new Text( res.values[ i * 2 + 1 ].getText() ), i );
- }
- res.destroy();
- befehl->setText( "DELETE FROM chat_nachricht WHERE zu_account_id = " );
- befehl->append( accountId );
- lock();
- datenbank->befehl( befehl->getText() );
- unlock();
- befehl->release();
- return ret;
- }
- bool CSDatenbank::speicherChatNachricht( int vonAccount, int zuAccount, const char *nachricht )
- {
- if( !nachricht )
- return 1;
- Text *befehl = new Text( "INSERT INTO chat_nachricht VALUES( " );
- befehl->append( vonAccount );
- befehl->append( ", " );
- befehl->append( zuAccount );
- befehl->append( ", '" );
- Text n( nachricht );
- n.ersetzen( "'", "''" );
- befehl->append( (char*)n );
- befehl->append( "' )" );
- lock();
- bool ret = datenbank->befehl( befehl->getText() );
- unlock();
- befehl->release();
- return ret;
- }
- int CSDatenbank::getChatroomAccount( int chatroomId, Array< int > *accountId )
- {
- Text *befehl = new Text( "SELECT account_id FROM chatroom_spieler WHERE chatroom_id = " );
- befehl->append( chatroomId );
- lock();
- datenbank->befehl( befehl->getText() );
- Result res = datenbank->getResult();
- unlock();
- befehl->release();
- if( !res.zeilenAnzahl )
- {
- res.destroy();
- return 0;
- }
- int ret = res.zeilenAnzahl;
- for( int i = 0; i < ret; i++ )
- accountId->add( TextZuInt( res.values[ i ].getText(), 10 ), i );
- res.destroy();
- return ret;
- }
- int CSDatenbank::chatroomErstellen( int accountId, const char *name )
- {
- Text *befehl = new Text( "INSERT INTO chatroom( admin_account_id, name ) VALUES( " );
- befehl->append( accountId );
- befehl->append( ", '" );
- Text n( name );
- n.ersetzen( "'", "''" );
- befehl->append( (char*)n );
- befehl->append( "' ) RETURNING id" );
- lock();
- if( !datenbank->befehl( befehl->getText() ) )
- {
- unlock();
- befehl->release();
- return 0;
- }
- Result res = datenbank->getResult();
- unlock();
- befehl->setText( "INSERT INTO chatroom_spieler VALUES( ( SELECT id FROM chatroom WHERE name = '" );
- befehl->append( (char*)n );
- befehl->append( "' ), " );
- befehl->append( accountId );
- befehl->append( " )" );
- lock();
- datenbank->befehl( befehl->getText() );
- unlock();
- befehl->release();
- if( !res.zeilenAnzahl )
- {
- res.destroy();
- return 0;
- }
- int ret = TextZuInt( res.values[ 0 ].getText(), 10 );
- res.destroy();
- return ret;
- }
- bool CSDatenbank::proveChatroomEinladung( int vonAccount, int zuAccount, int chatroomId )
- {
- Text *befehl = new Text( "SELECT pruef_chatroom_einladung( " );
- befehl->append( chatroomId );
- befehl->append( ", " );
- befehl->append( vonAccount );
- befehl->append( ", " );
- befehl->append( zuAccount );
- befehl->append( " )" );
- lock();
- datenbank->befehl( befehl->getText() );
- Result res = datenbank->getResult();
- unlock();
- befehl->release();
- if( !res.zeilenAnzahl )
- {
- res.destroy();
- return 0;
- }
- bool ret = res.values[ 0 ].istGleich( "t" );
- res.destroy();
- return ret;
- }
- bool CSDatenbank::chatroomBeitreten( int accountId, int chatroomId )
- {
- Text *befehl = new Text( "INSERT INTO chatroom_spieler values( " );
- befehl->append( chatroomId );
- befehl->append( " , " );
- befehl->append( accountId );
- befehl->append( " )" );
- lock();
- bool ret = datenbank->befehl( befehl->getText() );
- unlock();
- befehl->release();
- return ret;
- }
- int CSDatenbank::chatroomVerlassen( int accountId, int chatroomId )
- {
- Text *befehl = new Text( "SELECT chatroom_verlassen( " );
- befehl->append( chatroomId );
- befehl->append( ", " );
- befehl->append( accountId );
- befehl->append( " )" );
- lock();
- datenbank->befehl( befehl->getText() );
- 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;
- }
- int CSDatenbank::getChatroomAdmin( int chatroomId )
- {
- Text *befehl = new Text( "SELECT admin_account_id FROM chatroom WHERE id = " );
- befehl->append( chatroomId );
- lock();
- datenbank->befehl( befehl->getText() );
- 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;
- }
- // constant
- Text *CSDatenbank::getLetzterFehler() const
- {
- return datenbank->getLetzterFehler();
- }
- // Reference Counting
- CSDatenbank *CSDatenbank::getThis()
- {
- ref++;
- return this;
- }
- CSDatenbank *CSDatenbank::release()
- {
- ref--;
- if( !ref )
- delete this;
- return 0;
- }
|