mirror of
https://github.com/EQEmu/Server.git
synced 2026-03-11 02:52:26 +00:00
Remove postgres
This commit is contained in:
parent
6638b9ade5
commit
9e0f440106
@ -1,234 +0,0 @@
|
|||||||
/* EQEMu: Everquest Server Emulator
|
|
||||||
Copyright (C) 2001-2010 EQEMu Development Team (http://eqemulator.net)
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; version 2 of the License.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY except by those people which sell it, which
|
|
||||||
are required to give you total support for your newly bought product;
|
|
||||||
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
||||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*/
|
|
||||||
#include "../common/global_define.h"
|
|
||||||
#include "database.h"
|
|
||||||
|
|
||||||
#ifdef EQEMU_POSTGRESQL_ENABLED
|
|
||||||
#include "database_postgresql.h"
|
|
||||||
#include "error_log.h"
|
|
||||||
#include "login_server.h"
|
|
||||||
|
|
||||||
|
|
||||||
extern LoginServer server;
|
|
||||||
|
|
||||||
#pragma comment(lib, "libpq.lib")
|
|
||||||
|
|
||||||
DatabasePostgreSQL::DatabasePostgreSQL(string user, string pass, string host, string port, string name)
|
|
||||||
{
|
|
||||||
db = nullptr;
|
|
||||||
db = PQsetdbLogin(host.c_str(), port.c_str(), nullptr, nullptr, name.c_str(), user.c_str(), pass.c_str());
|
|
||||||
if(!db)
|
|
||||||
{
|
|
||||||
Log(Logs::General, Logs::Error, "Failed to connect to PostgreSQL Database.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(PQstatus(db) != CONNECTION_OK)
|
|
||||||
{
|
|
||||||
Log(Logs::General, Logs::Error, "Failed to connect to PostgreSQL Database.");
|
|
||||||
PQfinish(db);
|
|
||||||
db = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DatabasePostgreSQL::~DatabasePostgreSQL()
|
|
||||||
{
|
|
||||||
if(db)
|
|
||||||
{
|
|
||||||
PQfinish(db);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DatabasePostgreSQL::GetLoginDataFromAccountName(string name, string &password, unsigned int &id, std::string &loginserver)
|
|
||||||
{
|
|
||||||
if(!db)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PostgreSQL doesn't have automatic reconnection option like mysql
|
|
||||||
* but it's easy to check and reconnect
|
|
||||||
*/
|
|
||||||
if(PQstatus(db) != CONNECTION_OK)
|
|
||||||
{
|
|
||||||
PQreset(db);
|
|
||||||
if(PQstatus(db) != CONNECTION_OK)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stringstream query(stringstream::in | stringstream::out);
|
|
||||||
query << "SELECT LoginServerID, AccountPassword FROM " << server.options.GetAccountTable() << " WHERE AccountName = '";
|
|
||||||
query << name;
|
|
||||||
query << "'";
|
|
||||||
|
|
||||||
PGresult *res = PQexec(db, query.str().c_str());
|
|
||||||
|
|
||||||
char *error = PQresultErrorMessage(res);
|
|
||||||
if(strlen(error) > 0)
|
|
||||||
{
|
|
||||||
Log(Logs::General, Logs::Error, "Database error in DatabasePostgreSQL::GetLoginDataFromAccountName(): %s", error);
|
|
||||||
PQclear(res);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(PQntuples(res) > 0)
|
|
||||||
{
|
|
||||||
id = atoi(PQgetvalue(res, 0, 0));
|
|
||||||
password = PQgetvalue(res, 0, 1);
|
|
||||||
PQclear(res);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
PQclear(res);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DatabasePostgreSQL::GetWorldRegistration(string long_name, string short_name, unsigned int &id, string &desc, unsigned int &list_id,
|
|
||||||
unsigned int &trusted, string &list_desc, string &account, string &password)
|
|
||||||
{
|
|
||||||
if(!db)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PostgreSQL doesn't have automatic reconnection option like mysql
|
|
||||||
* but it's easy to check and reconnect
|
|
||||||
*/
|
|
||||||
if(PQstatus(db) != CONNECTION_OK)
|
|
||||||
{
|
|
||||||
PQreset(db);
|
|
||||||
if(PQstatus(db) != CONNECTION_OK)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stringstream query(stringstream::in | stringstream::out);
|
|
||||||
query << "SELECT WSR.ServerID, WSR.ServerTagDescription, WSR.ServerTrusted, SLT.ServerListTypeID, ";
|
|
||||||
query << "SLT.ServerListTypeDescription, SAR.AccountName, SAR.AccountPassword FROM " << server.options.GetWorldRegistrationTable();
|
|
||||||
query << " AS WSR JOIN " << server.options.GetWorldServerTypeTable() << " AS SLT ON WSR.ServerListTypeID = SLT.ServerListTypeID JOIN ";
|
|
||||||
query << server.options.GetWorldAdminRegistrationTable() << " AS SAR ON WSR.ServerAdminID = SAR.ServerAdminID WHERE WSR.ServerShortName";
|
|
||||||
query << " = '";
|
|
||||||
query << short_name;
|
|
||||||
query << "'";
|
|
||||||
|
|
||||||
PGresult *res = PQexec(db, query.str().c_str());
|
|
||||||
|
|
||||||
char *error = PQresultErrorMessage(res);
|
|
||||||
if(strlen(error) > 0)
|
|
||||||
{
|
|
||||||
Log(Logs::General, Logs::Error, "Database error in DatabasePostgreSQL::GetWorldRegistration(): %s", error);
|
|
||||||
PQclear(res);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(PQntuples(res) > 0)
|
|
||||||
{
|
|
||||||
id = atoi(PQgetvalue(res, 0, 0));
|
|
||||||
desc = PQgetvalue(res, 0, 1);
|
|
||||||
trusted = atoi(PQgetvalue(res, 0, 2));
|
|
||||||
list_id = atoi(PQgetvalue(res, 0, 3));
|
|
||||||
list_desc = PQgetvalue(res, 0, 4);
|
|
||||||
account = PQgetvalue(res, 0, 5);
|
|
||||||
password = PQgetvalue(res, 0, 6);
|
|
||||||
|
|
||||||
PQclear(res);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
PQclear(res);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DatabasePostgreSQL::UpdateLSAccountData(unsigned int id, string ip_address)
|
|
||||||
{
|
|
||||||
if(!db)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PostgreSQL doesn't have automatic reconnection option like mysql
|
|
||||||
* but it's easy to check and reconnect
|
|
||||||
*/
|
|
||||||
if(PQstatus(db) != CONNECTION_OK)
|
|
||||||
{
|
|
||||||
PQreset(db);
|
|
||||||
if(PQstatus(db) != CONNECTION_OK)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stringstream query(stringstream::in | stringstream::out);
|
|
||||||
query << "UPDATE " << server.options.GetAccountTable() << " SET LastIPAddress = '";
|
|
||||||
query << ip_address;
|
|
||||||
query << "', LastLoginDate = current_date where LoginServerID = ";
|
|
||||||
query << id;
|
|
||||||
PGresult *res = PQexec(db, query.str().c_str());
|
|
||||||
|
|
||||||
char *error = PQresultErrorMessage(res);
|
|
||||||
if(strlen(error) > 0)
|
|
||||||
{
|
|
||||||
Log(Logs::General, Logs::Error, "Database error in DatabasePostgreSQL::GetLoginDataFromAccountName(): %s", error);
|
|
||||||
}
|
|
||||||
PQclear(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DatabasePostgreSQL::UpdateWorldRegistration(unsigned int id, string long_name, string ip_address)
|
|
||||||
{
|
|
||||||
if(!db)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PostgreSQL doesn't have automatic reconnection option like mysql
|
|
||||||
* but it's easy to check and reconnect
|
|
||||||
*/
|
|
||||||
if(PQstatus(db) != CONNECTION_OK)
|
|
||||||
{
|
|
||||||
PQreset(db);
|
|
||||||
if(PQstatus(db) != CONNECTION_OK)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stringstream query(stringstream::in | stringstream::out);
|
|
||||||
query << "UPDATE " << server.options.GetWorldRegistrationTable() << " SET ServerLastLoginDate = current_date, ServerLastIPAddr = '";
|
|
||||||
query << ip_address;
|
|
||||||
query << "', ServerLongName = '";
|
|
||||||
query << long_name;
|
|
||||||
query << "' where ServerID = ";
|
|
||||||
query << id;
|
|
||||||
PGresult *res = PQexec(db, query.str().c_str());
|
|
||||||
|
|
||||||
char *error = PQresultErrorMessage(res);
|
|
||||||
if(strlen(error) > 0)
|
|
||||||
{
|
|
||||||
Log(Logs::General, Logs::Error, "Database error in DatabasePostgreSQL::GetLoginDataFromAccountName(): %s", error);
|
|
||||||
}
|
|
||||||
PQclear(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@ -1,91 +0,0 @@
|
|||||||
/* EQEMu: Everquest Server Emulator
|
|
||||||
Copyright (C) 2001-2010 EQEMu Development Team (http://eqemulator.net)
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; version 2 of the License.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY except by those people which sell it, which
|
|
||||||
are required to give you total support for your newly bought product;
|
|
||||||
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
||||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*/
|
|
||||||
#ifndef EQEMU_DATABASEPOSTGRESQL_H
|
|
||||||
#define EQEMU_DATABASEPOSTGRESQL_H
|
|
||||||
|
|
||||||
#include "database.h"
|
|
||||||
#ifdef EQEMU_POSTGRESQL_ENABLED
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <sstream>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <libpq-fe.h>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PostgreSQL Database class
|
|
||||||
*/
|
|
||||||
class DatabasePostgreSQL : public Database
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Constructor, sets our database to null.
|
|
||||||
*/
|
|
||||||
DatabasePostgreSQL() { db = nullptr; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor, tries to set our database to connect to the supplied options.
|
|
||||||
*/
|
|
||||||
DatabasePostgreSQL(std::string user, std::string pass, std::string host, std::string port, std::string name);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destructor, frees our database if needed.
|
|
||||||
*/
|
|
||||||
virtual ~DatabasePostgreSQL();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the database successfully connected.
|
|
||||||
*/
|
|
||||||
virtual bool IsConnected() { return (db != nullptr); }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the login data (password hash and account id) from the account name provided
|
|
||||||
* Needed for client login procedure.
|
|
||||||
* Returns true if the record was found, false otherwise.
|
|
||||||
*/
|
|
||||||
virtual bool GetLoginDataFromAccountName(std::string name, std::string &password, unsigned int &id, std::string &loginserver);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the world registration from the long and short names provided.
|
|
||||||
* Needed for world login procedure.
|
|
||||||
* Returns true if the record was found, false otherwise.
|
|
||||||
*/
|
|
||||||
virtual bool GetWorldRegistration(std::string long_name, std::string short_name, unsigned int &id, std::string &desc, unsigned int &list_id,
|
|
||||||
unsigned int &trusted, std::string &list_desc, std::string &account, std::string &password);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the ip address of the client with account id = id
|
|
||||||
*/
|
|
||||||
virtual void UpdateLSAccountData(unsigned int id, std::string ip_address);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the ip address of the world with account id = id
|
|
||||||
*/
|
|
||||||
virtual void UpdateWorldRegistration(unsigned int id, std::string long_name, std::string ip_address);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates new world registration for unregistered servers and returns new id
|
|
||||||
*/
|
|
||||||
virtual bool CreateWorldRegistration(std::string long_name, std::string short_name, unsigned int &id);
|
|
||||||
protected:
|
|
||||||
std::string user, pass, host, port, name;
|
|
||||||
PGconn *db;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@ -1,57 +0,0 @@
|
|||||||
DROP TABLE IF EXISTS tblLoginServerAccounts;
|
|
||||||
CREATE TABLE tblLoginServerAccounts (
|
|
||||||
LoginServerID SERIAL,
|
|
||||||
AccountName text NOT NULL,
|
|
||||||
AccountPassword text NOT NULL,
|
|
||||||
AccountCreateDate date NOT NULL,
|
|
||||||
AccountEmail text NOT NULL,
|
|
||||||
LastLoginDate date NOT NULL,
|
|
||||||
LastIPAddress text NOT NULL,
|
|
||||||
PRIMARY KEY(LoginServerID, AccountName)
|
|
||||||
);
|
|
||||||
|
|
||||||
insert into tblLoginServerAccounts (AccountName, AccountPassword, AccountEmail, AccountCreateDate, LastLoginDate, LastIPAddress) values('Admin', '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8', 'admin@somewhere.com', current_date, current_date, '127.0.0.1');
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS tblServerListType;
|
|
||||||
CREATE TABLE tblServerListType (
|
|
||||||
ServerListTypeID integer NOT NULL,
|
|
||||||
CHECK (ServerListTypeID >= 0),
|
|
||||||
ServerListTypeDescription text NOT NULL,
|
|
||||||
PRIMARY KEY (ServerListTypeID)
|
|
||||||
);
|
|
||||||
|
|
||||||
INSERT INTO tblServerListType (ServerListTypeID, ServerListTypeDescription) VALUES (1, 'Legends');
|
|
||||||
INSERT INTO tblServerListType (ServerListTypeID, ServerListTypeDescription) VALUES (2, 'Preferred');
|
|
||||||
INSERT INTO tblServerListType (ServerListTypeID, ServerListTypeDescription) VALUES (3, 'Standard');
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS tblServerAdminRegistration;
|
|
||||||
CREATE TABLE tblServerAdminRegistration (
|
|
||||||
ServerAdminID SERIAL,
|
|
||||||
AccountName text NOT NULL,
|
|
||||||
AccountPassword text NOT NULL,
|
|
||||||
FirstName text NOT NULL,
|
|
||||||
LastName text NOT NULL,
|
|
||||||
Email text NOT NULL,
|
|
||||||
RegistrationDate date NOT NULL,
|
|
||||||
RegistrationIPAddr text NOT NULL,
|
|
||||||
PRIMARY KEY (ServerAdminID, Email)
|
|
||||||
);
|
|
||||||
|
|
||||||
INSERT INTO tblServerAdminRegistration (AccountName, AccountPassword, FirstName, LastName, Email, RegistrationDate, RegistrationIPAddr) VALUES ('Admin', 'Password', 'Tom', 'Wilson', 'Tom.Wilson@gmail.com', current_date, '0.0.0.0');
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS tblWorldServerRegistration;
|
|
||||||
CREATE TABLE tblWorldServerRegistration (
|
|
||||||
ServerID SERIAL,
|
|
||||||
ServerLongName text NOT NULL,
|
|
||||||
ServerTagDescription text NOT NULL,
|
|
||||||
ServerShortName text NOT NULL,
|
|
||||||
ServerListTypeID integer NOT NULL,
|
|
||||||
ServerLastLoginDate date NULL,
|
|
||||||
ServerLastIPAddr text NOT NULL,
|
|
||||||
ServerAdminID integer NOT NULL,
|
|
||||||
ServerTrusted integer NOT NULL,
|
|
||||||
Note text NOT NULL,
|
|
||||||
PRIMARY KEY (ServerID, ServerLongName)
|
|
||||||
);
|
|
||||||
|
|
||||||
INSERT INTO tblWorldServerRegistration (ServerLongName, ServerTagDescription, ServerShortName, ServerListTypeID, ServerLastLoginDate, ServerLastIPAddr, ServerAdminID, ServerTrusted, Note) VALUES ('My Test Server', 'A test server', 'MTST', 1, current_date, '0.0.0.0', 1, 0, 'This is a note for the test server');
|
|
||||||
Loading…
x
Reference in New Issue
Block a user