Ver código fonte

AN neue Datenbank angepasst

Kolja Strohm 7 anos atrás
pai
commit
5a9f19a21f

+ 36 - 79
ErhaltungServer/Datenbank.cpp

@@ -54,11 +54,11 @@ int ESDatenbank::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();
@@ -87,7 +87,7 @@ bool ESDatenbank::adminHatRecht( int id, int recht )
 
 bool ESDatenbank::proveKlient( int num, int sNum )
 {
-	Text *befehl = new Text( "SELECT * FROM server_erhaltung_clients WHERE server_erhaltung_id = " );
+	Text *befehl = new Text( "SELECT * FROM server_client WHERE server_id = " );
 	befehl->append( sNum );
 	befehl->append( " AND client_id = " );
 	befehl->append( num );
@@ -106,7 +106,7 @@ bool ESDatenbank::proveKlient( int num, int sNum )
 Text *ESDatenbank::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;
@@ -125,9 +125,9 @@ Text *ESDatenbank::getKlientKey( int cId )
 
 void ESDatenbank::unregisterKlient( int num, int sNum )
 {
-	Text *befehl = new Text( "DELETE FROM server_erhaltung_clients WHERE client_id = " );
+	Text *befehl = new Text( "DELETE FROM server_client WHERE client_id = " );
 	befehl->append( num );
-	befehl->append( " AND server_erhaltung_id = " );
+	befehl->append( " AND server_id = " );
 	befehl->append( sNum );
 	lock();
 	datenbank->befehl( befehl->getText() );
@@ -135,7 +135,7 @@ void ESDatenbank::unregisterKlient( int num, int sNum )
 	unlock();
 	if( za == 1 )
 	{
-		befehl->setText( "UPDATE server_erhaltung SET clients = clients - 1 WHERE id = " );
+		befehl->setText( "UPDATE server SET tasks = tasks - 1 WHERE id = " );
 		befehl->append( sNum );
 		lock();
 		datenbank->befehl( befehl->getText() );
@@ -146,7 +146,7 @@ void ESDatenbank::unregisterKlient( int num, int sNum )
 
 bool ESDatenbank::setServerStatus( int id, int status )
 {
-	Text *befehl = new Text( "UPDATE server_erhaltung SET server_status_id = " );
+	Text *befehl = new Text( "UPDATE server SET server_status_id = " );
 	*befehl += status;
 	*befehl += "WHERE id = ";
 	*befehl += id;
@@ -165,7 +165,7 @@ bool ESDatenbank::setServerStatus( int id, int status )
 
 bool ESDatenbank::setMaxClients( int id, int maxC )
 {
-	Text *befehl = new Text( "UPDATE server_erhaltung SET max_clients = " );
+	Text *befehl = new Text( "UPDATE server SET max_tasks = " );
 	befehl->append( maxC );
 	befehl->append( " WHERE id = " );
 	befehl->append( id );
@@ -182,33 +182,9 @@ bool ESDatenbank::setMaxClients( int id, int maxC )
 	return ret;
 }
 
-int ESDatenbank::getAdminPort( int id )
-{
-	Text *befehl = new Text( "SELECT admin_port FROM server_erhaltung 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 ESDatenbank::serverIstNichtPausiert( int id )
 {
-	Text *befehl = new Text( "SELECT server_status_id FROM server_erhaltung WHERE id = " );
+	Text *befehl = new Text( "SELECT server_status_id FROM server WHERE id = " );
 	befehl->append( id );
 	lock();
 	if( !datenbank->befehl( befehl->getText() ) )
@@ -232,8 +208,8 @@ bool ESDatenbank::serverIstNichtPausiert( int id )
 
 bool ESDatenbank::getPatchServer( int client, Text *ip, int *port )
 {
-	Text *befehl = new Text( "SELECT a.port, a.ip FROM server_patch AS a, server_patch_clients AS b "
-							 "WHERE a.id = b.server_patch_id AND b.client_id = " );
+	Text *befehl = new Text( "SELECT a.port, a.ip FROM server AS a, server_client AS b "
+							 "WHERE a.id = b.server_id AND a.server_typ_name = 'patch' AND b.client_id = " );
 	befehl->append( client );
 	lock();
 	if( !datenbank->befehl( befehl->getText() ) )
@@ -258,8 +234,8 @@ bool ESDatenbank::getPatchServer( int client, Text *ip, int *port )
 
 bool ESDatenbank::getRegisterServer( int client, Text *ip, int *port )
 {
-	Text *befehl = new Text( "SELECT a.port, a.ip FROM server_register AS a, server_register_clients AS b "
-							 "WHERE a.id = b.server_register_id AND b.client_id = " );
+	Text *befehl = new Text( "SELECT a.port, a.ip FROM server AS a, server_client AS b "
+							 "WHERE a.id = b.server_id AND a.server_typ_name = 'register' AND b.client_id = " );
 	befehl->append( client );
 	lock();
 	if( !datenbank->befehl( befehl->getText() ) )
@@ -284,8 +260,8 @@ bool ESDatenbank::getRegisterServer( int client, Text *ip, int *port )
 
 bool ESDatenbank::getLoginServer( int client, Text *ip, int *port )
 {
-	Text *befehl = new Text( "SELECT a.port, a.ip FROM server_login AS a, server_login_clients AS b "
-							 "WHERE a.id = b.server_login_id AND b.client_id = " );
+	Text *befehl = new Text( "SELECT a.port, a.ip FROM server AS a, server_client AS b "
+							 "WHERE a.id = b.server_id AND a.server_typ_name = 'login' AND b.client_id = " );
 	befehl->append( client );
 	lock();
 	if( !datenbank->befehl( befehl->getText() ) )
@@ -310,8 +286,8 @@ bool ESDatenbank::getLoginServer( int client, Text *ip, int *port )
 
 bool ESDatenbank::getInformationServer( int client, Text *ip, int *port )
 {
-	Text *befehl = new Text( "SELECT a.port, a.ip FROM server_information AS a, server_information_clients AS b "
-							 "WHERE a.id = b.server_information_id AND b.client_id = " );
+	Text *befehl = new Text( "SELECT a.port, a.ip FROM server AS a, server_client AS b "
+							 "WHERE a.id = b.server_id AND a.server_typ_name = 'information' AND b.client_id = " );
 	befehl->append( client );
 	lock();
 	if( !datenbank->befehl( befehl->getText() ) )
@@ -336,8 +312,8 @@ bool ESDatenbank::getInformationServer( int client, Text *ip, int *port )
 
 bool ESDatenbank::getChatServer( int client, Text *ip, int *port )
 {
-	Text *befehl = new Text( "SELECT a.port, a.ip FROM server_chat AS a, server_chat_clients AS b "
-							 "WHERE a.id = b.server_chat_id AND b.client_id = " );
+	Text *befehl = new Text( "SELECT a.port, a.ip FROM server AS a, server_client AS b "
+							 "WHERE a.id = b.server_id AND a.server_typ_name = 'chat' AND b.client_id = " );
 	befehl->append( client );
 	lock();
 	if( !datenbank->befehl( befehl->getText() ) )
@@ -362,8 +338,8 @@ bool ESDatenbank::getChatServer( int client, Text *ip, int *port )
 
 bool ESDatenbank::getAnmeldungServer( int client, Text *ip, int *port )
 {
-	Text *befehl = new Text( "SELECT a.port, a.ip FROM server_anmeldung AS a, server_anmeldung_clients AS b "
-							 "WHERE a.id = b.server_anmeldung_id AND b.client_id = " );
+	Text *befehl = new Text( "SELECT a.port, a.ip FROM server AS a, server_client AS b "
+							 "WHERE a.id = b.server_id AND a.server_typ_name = 'anmeldung' AND b.client_id = " );
 	befehl->append( client );
 	lock();
 	if( !datenbank->befehl( befehl->getText() ) )
@@ -388,7 +364,7 @@ bool ESDatenbank::getAnmeldungServer( int client, Text *ip, int *port )
 
 bool ESDatenbank::getSpielServer( int client, Text *ip, int *port )
 {
-	Text *befehl = new Text( "SELECT account_id FROM account_clients WHERE client_id = " );
+	Text *befehl = new Text( "SELECT account_id FROM account_client WHERE client_id = " );
 	befehl->append( client );
 	lock();
 	if( !datenbank->befehl( befehl->getText() ) )
@@ -407,7 +383,7 @@ bool ESDatenbank::getSpielServer( int client, Text *ip, int *port )
 	}
 	int accountId = TextZuInt( res.values[ 0 ].getText(), 10 );
 	res.destroy();
-	befehl->setText( "SELECT a.id FROM spiel a, spiel_spieler b WHERE b.spiel_id = a.id "
+	befehl->setText( "SELECT a.spiel_server_id FROM spiel a, spiel_spieler b WHERE b.spiel_id = a.id "
 					  "AND a.spiel_status_id < 3 AND b.spiel_spieler_status_id = 5 AND b.account_id = " );
 	befehl->append( accountId );
 	lock();
@@ -425,28 +401,9 @@ bool ESDatenbank::getSpielServer( int client, Text *ip, int *port )
 		befehl->release();
 		return 0;
 	}
-	int spielId = TextZuInt( res.values[ 0 ].getText(), 10 );
-	res.destroy();
-	befehl->setText( "SELECT spiel_server_id FROM spiel WHERE id = " );
-	befehl->append( spielId );
-	lock();
-	if( !datenbank->befehl( befehl->getText() ) )
-	{
-		unlock();
-		befehl->release();
-		return 0;
-	}
-	res = datenbank->getResult();
-	unlock();
-	if( !res.zeilenAnzahl )
-	{
-		res.destroy();
-		befehl->release();
-		return 0;
-	}
 	int serverId = TextZuInt( res.values[ 0 ].getText(), 10 );
 	res.destroy();
-	befehl->setText( "SELECT port, ip FROM server_spiel WHERE id = " );
+	befehl->setText( "SELECT port, ip FROM server WHERE id = " );
 	befehl->append( serverId );
 	lock();
 	if( !datenbank->befehl( befehl->getText() ) )
@@ -471,8 +428,8 @@ bool ESDatenbank::getSpielServer( int client, Text *ip, int *port )
 
 bool ESDatenbank::getShopServer( int client, Text *ip, int *port )
 {
-	Text *befehl = new Text( "SELECT a.port, a.ip FROM server_shop AS a, server_shop_clients AS b "
-							 "WHERE a.id = b.server_shop_id AND b.client_id = " );
+	Text *befehl = new Text( "SELECT a.port, a.ip FROM server AS a, server_client AS b "
+							 "WHERE a.id = b.server_id AND a.server_typ_name = 'shop' AND b.client_id = " );
 	befehl->append( client );
 	lock();
 	if( !datenbank->befehl( befehl->getText() ) )
@@ -497,8 +454,8 @@ bool ESDatenbank::getShopServer( int client, Text *ip, int *port )
 
 bool ESDatenbank::getNewsServer( int client, Text *ip, int *port )
 {
-	Text *befehl = new Text( "SELECT a.port, a.ip FROM server_news AS a, server_news_clients AS b "
-							 "WHERE a.id = b.server_news_id AND b.client_id = " );
+	Text *befehl = new Text( "SELECT a.port, a.ip FROM server AS a, server_client AS b "
+							 "WHERE a.id = b.server_id AND a.server_typ_name = 'news' AND b.client_id = " );
 	befehl->append( client );
 	lock();
 	if( !datenbank->befehl( befehl->getText() ) )
@@ -523,8 +480,8 @@ bool ESDatenbank::getNewsServer( int client, Text *ip, int *port )
 
 bool ESDatenbank::getHistorieServer( int client, Text *ip, int *port )
 {
-	Text *befehl = new Text( "SELECT a.port, a.ip FROM server_historie AS a, server_historie_clients AS b "
-							 "WHERE a.id = b.server_historie_id AND b.client_id = " );
+	Text *befehl = new Text( "SELECT a.port, a.ip FROM server AS a, server_client AS b "
+							 "WHERE a.id = b.server_id AND a.server_typ_name = 'historie' AND b.client_id = " );
 	befehl->append( client );
 	lock();
 	if( !datenbank->befehl( befehl->getText() ) )
@@ -549,8 +506,8 @@ bool ESDatenbank::getHistorieServer( int client, Text *ip, int *port )
 
 bool ESDatenbank::getKartenServer( int client, Text *ip, int *port )
 {
-    Text *befehl = new Text( "SELECT a.port, a.ip FROM server_karten AS a, server_karten_clients AS b "
-                             "WHERE a.id = b.server_karten_id AND b.client_id = " );
+    Text *befehl = new Text( "SELECT a.port, a.ip FROM server AS a, server_client AS b "
+                             "WHERE a.id = b.server_id AND a.server_typ_name = 'karten' AND b.client_id = " );
     befehl->append( client );
     lock();
     if( !datenbank->befehl( befehl->getText() ) )
@@ -575,8 +532,8 @@ bool ESDatenbank::getKartenServer( int client, Text *ip, int *port )
 
 bool ESDatenbank::getEditorServer( int client, Text *ip, int *port )
 {
-    Text *befehl = new Text( "SELECT a.port, a.ip FROM server_editor AS a, server_editor_clients AS b "
-                             "WHERE a.id = b.server_editor_id AND b.client_id = " );
+    Text *befehl = new Text( "SELECT a.port, a.ip FROM server AS a, server_client AS b "
+                             "WHERE a.id = b.server_id AND a.server_typ_name = 'editor' AND b.client_id = " );
     befehl->append( client );
     lock();
     if( !datenbank->befehl( befehl->getText() ) )
@@ -612,7 +569,7 @@ void ESDatenbank::removeKlient( int klientId )
 
 int ESDatenbank::clientIstEingeloggt( int clientId )
 {
-	Text *befehl = new Text( "SELECT account_id FROM account_clients WHERE client_id = " );
+	Text *befehl = new Text( "SELECT account_id FROM account_client WHERE client_id = " );
 	befehl->append( clientId );
 	lock();
 	if( !datenbank->befehl( befehl->getText() ) )

+ 0 - 1
ErhaltungServer/Datenbank.h

@@ -40,7 +40,6 @@ public:
 	void unregisterKlient( int num, int sNum );
 	bool setServerStatus( int id, int status );
 	bool setMaxClients( int id, int maxC );
-	int getAdminPort( int id );
 	bool serverIstNichtPausiert( int id );
 	bool getPatchServer( int client, Text *ip, int *port );
 	bool getRegisterServer( int client, Text *ip, int *port );

+ 9 - 5
ErhaltungServer/ErhaltungServer.vcxproj

@@ -37,12 +37,16 @@
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
     <TargetExt />
     <RemoteProjectDir>$(RemoteRootDir)/Server/$(ProjectName)/Release</RemoteProjectDir>
-    <IncludePath>..\..\..\..\Allgemein\Framework;../../../Framework/Release;..\..\..\..\Allgemein\Network\Network;../../../Network/Release;..\..\..\..\Allgemein\sql\sql;../../../sql/Release;$(IncludePath)</IncludePath>
+    <IncludePath>..\..\..\..\Allgemein\Framework;../../../Framework/release;..\..\..\..\Allgemein\Network\Network;../../../Network/release;..\..\..\..\Allgemein\sql\sql;../../../sql/release;$(IncludePath)</IncludePath>
+    <OutDir>$(ProjectDir)bin\$(Platform)\release\</OutDir>
+    <IntDir>$(ProjectDir)obj\$(Platform)\release\</IntDir>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
     <TargetExt />
-    <RemoteProjectDir>$(RemoteRootDir)/Server/$(ProjectName)/Debug</RemoteProjectDir>
-    <IncludePath>..\..\..\..\Allgemein\Framework;../../../Framework/Debug;..\..\..\..\Allgemein\Network\Network;../../../Network/Debug;..\..\..\..\Allgemein\sql\sql;../../../sql/Debug;$(IncludePath)</IncludePath>
+    <RemoteProjectDir>$(RemoteRootDir)/Server/$(ProjectName)/debug</RemoteProjectDir>
+    <IncludePath>..\..\..\..\Allgemein\Framework;../../../Framework/debug;..\..\..\..\Allgemein\Network\Network;../../../Network/debug;..\..\..\..\Allgemein\sql\sql;../../../sql/debug;$(IncludePath)</IncludePath>
+    <OutDir>$(ProjectDir)bin\$(Platform)\debug\</OutDir>
+    <IntDir>$(ProjectDir)obj\$(Platform)\debug\</IntDir>
   </PropertyGroup>
   <ItemGroup>
     <ClInclude Include="Datenbank.h" />
@@ -56,14 +60,14 @@
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
     <Link>
       <LibraryDependencies>Framework;Network;SQL;pq;pthread</LibraryDependencies>
-      <AdditionalLibraryDirectories>$(RemoteRootDir)/sql/Release/bin/x64/release;$(RemoteRootDir)/Network/Release/bin/x64/release;$(RemoteRootDir)/Framework/Release/bin/x64/release;/usr/lib/;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <AdditionalLibraryDirectories>$(RemoteRootDir)/sql/release/bin/x64/release;$(RemoteRootDir)/Network/release/bin/x64/release;$(RemoteRootDir)/Framework/release/bin/x64/release;/usr/lib/;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
       <AdditionalOptions>-Wl,-rpath,../lib %(AdditionalOptions)</AdditionalOptions>
     </Link>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
     <Link>
       <LibraryDependencies>dbgFramework;dbgNetwork;dbgSQL;pq;pthread</LibraryDependencies>
-      <AdditionalLibraryDirectories>$(RemoteRootDir)/sql/Debug/bin/x64/debug;$(RemoteRootDir)/Network/Debug/bin/x64/debug;$(RemoteRootDir)/Framework/Debug/bin/x64/debug;/usr/lib/;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <AdditionalLibraryDirectories>$(RemoteRootDir)/sql/debug/bin/x64/debug;$(RemoteRootDir)/Network/debug/bin/x64/debug;$(RemoteRootDir)/Framework/debug/bin/x64/debug;/usr/lib/;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
       <AdditionalOptions>-Wl,-rpath,../lib %(AdditionalOptions)</AdditionalOptions>
     </Link>
   </ItemDefinitionGroup>