mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-17 11:28:25 +00:00
Initial Socket Server implementation with CMakeLists.txt updated. Socket server will connect to world at this point.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
|
||||
SET(socket_server_sources
|
||||
database.cpp
|
||||
socket_server.cpp
|
||||
socket_server_config.cpp
|
||||
worldserver.cpp
|
||||
)
|
||||
|
||||
SET(socket_server_headers
|
||||
database.h
|
||||
socket_server_config.h
|
||||
worldserver.h
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(socket_server ${socket_server_sources} ${socket_server_headers})
|
||||
|
||||
INSTALL(TARGETS socket_server RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
|
||||
|
||||
ADD_DEFINITIONS(-DQSERV)
|
||||
|
||||
TARGET_LINK_LIBRARIES(socket_server Common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY})
|
||||
|
||||
IF(MSVC)
|
||||
SET_TARGET_PROPERTIES(socket_server PROPERTIES LINK_FLAGS_RELEASE "/OPT:REF /OPT:ICF")
|
||||
TARGET_LINK_LIBRARIES(socket_server "Ws2_32.lib")
|
||||
ENDIF(MSVC)
|
||||
|
||||
IF(MINGW)
|
||||
TARGET_LINK_LIBRARIES(socket_server "WS2_32")
|
||||
ENDIF(MINGW)
|
||||
|
||||
IF(UNIX)
|
||||
TARGET_LINK_LIBRARIES(socket_server "${CMAKE_DL_LIBS}")
|
||||
TARGET_LINK_LIBRARIES(socket_server "z")
|
||||
TARGET_LINK_LIBRARIES(socket_server "m")
|
||||
IF(NOT DARWIN)
|
||||
TARGET_LINK_LIBRARIES(socket_server "rt")
|
||||
ENDIF(NOT DARWIN)
|
||||
TARGET_LINK_LIBRARIES(socket_server "pthread")
|
||||
ADD_DEFINITIONS(-fPIC)
|
||||
ENDIF(UNIX)
|
||||
|
||||
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/Bin)
|
||||
@@ -0,0 +1,131 @@
|
||||
/* EQEMu: Everquest Server Emulator
|
||||
Copyright (C) 2001-2008 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/debug.h"
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errmsg.h>
|
||||
#include <mysqld_error.h>
|
||||
#include <limits.h>
|
||||
#include <ctype.h>
|
||||
#include <assert.h>
|
||||
#include <map>
|
||||
|
||||
// Disgrace: for windows compile
|
||||
#ifdef _WINDOWS
|
||||
#include <windows.h>
|
||||
#define snprintf _snprintf
|
||||
#define strncasecmp _strnicmp
|
||||
#define strcasecmp _stricmp
|
||||
#else
|
||||
#include "../common/unix.h"
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#include "database.h"
|
||||
#include "../common/eq_packet_structs.h"
|
||||
#include "../common/StringUtil.h"
|
||||
#include "../common/servertalk.h"
|
||||
|
||||
Database::Database ()
|
||||
{
|
||||
DBInitVars();
|
||||
}
|
||||
|
||||
/*
|
||||
Establish a connection to a mysql database with the supplied parameters
|
||||
*/
|
||||
|
||||
Database::Database(const char* host, const char* user, const char* passwd, const char* database, uint32 port)
|
||||
{
|
||||
DBInitVars();
|
||||
Connect(host, user, passwd, database, port);
|
||||
}
|
||||
|
||||
bool Database::Connect(const char* host, const char* user, const char* passwd, const char* database, uint32 port)
|
||||
{
|
||||
uint32 errnum= 0;
|
||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
||||
if (!Open(host, user, passwd, database, port, &errnum, errbuf))
|
||||
{
|
||||
LogFile->write(EQEMuLog::Error, "Failed to connect to database: Error: %s", errbuf);
|
||||
HandleMysqlError(errnum);
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogFile->write(EQEMuLog::Status, "Using database '%s' at %s:%d",database,host,port);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void Database::DBInitVars() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Database::HandleMysqlError(uint32 errnum) {
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Close the connection to the database
|
||||
*/
|
||||
Database::~Database()
|
||||
{
|
||||
}
|
||||
|
||||
bool Database::GetVariable(const char* varname, char* varvalue, uint16 varvalue_len) {
|
||||
|
||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
||||
char* query = 0;
|
||||
MYSQL_RES *result;
|
||||
MYSQL_ROW row;
|
||||
|
||||
if (!RunQuery(query,MakeAnyLenString(&query, "select `value` from `variables` where `varname`='%s'", varname), errbuf, &result)) {
|
||||
|
||||
_log(UCS__ERROR, "Unable to get message count from database. %s %s", query, errbuf);
|
||||
|
||||
safe_delete_array(query);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
safe_delete_array(query);
|
||||
|
||||
if (mysql_num_rows(result) != 1) {
|
||||
|
||||
mysql_free_result(result);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
row = mysql_fetch_row(result);
|
||||
|
||||
snprintf(varvalue, varvalue_len, "%s", row[0]);
|
||||
|
||||
mysql_free_result(result);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/* EQEMu: Everquest Server Emulator
|
||||
Copyright (C) 2001-2008 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 CHATSERVER_DATABASE_H
|
||||
#define CHATSERVER_DATABASE_H
|
||||
|
||||
#define AUTHENTICATION_TIMEOUT 60
|
||||
#define INVALID_ID 0xFFFFFFFF
|
||||
|
||||
#include "../common/debug.h"
|
||||
#include "../common/types.h"
|
||||
#include "../common/dbcore.h"
|
||||
#include "../common/linked_list.h"
|
||||
#include "../common/servertalk.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
//atoi is not uint32 or uint32 safe!!!!
|
||||
#define atoul(str) strtoul(str, nullptr, 10)
|
||||
|
||||
class Database : public DBcore {
|
||||
public:
|
||||
Database();
|
||||
Database(const char* host, const char* user, const char* passwd, const char* database,uint32 port);
|
||||
bool Connect(const char* host, const char* user, const char* passwd, const char* database,uint32 port);
|
||||
~Database();
|
||||
|
||||
bool GetVariable(const char* varname, char* varvalue, uint16 varvalue_len);
|
||||
protected:
|
||||
void HandleMysqlError(uint32 errnum);
|
||||
private:
|
||||
void DBInitVars();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
/* EQEMu: Everquest Server Emulator
|
||||
Copyright (C) 2001-2008 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/debug.h"
|
||||
#include "../common/opcodemgr.h"
|
||||
#include "../common/EQStreamFactory.h"
|
||||
#include "../common/rulesys.h"
|
||||
#include "../common/servertalk.h"
|
||||
#include "../common/platform.h"
|
||||
#include "../common/crash.h"
|
||||
#include "database.h"
|
||||
#include "socket_server_config.h"
|
||||
#include "worldserver.h"
|
||||
#include <list>
|
||||
|
||||
#include <signal.h>
|
||||
volatile bool RunLoops = true;
|
||||
TimeoutManager timeout_manager;
|
||||
Database database;
|
||||
std::string WorldShortName;
|
||||
|
||||
const socket_server_config *Config;
|
||||
WorldServer *worldserver = 0;
|
||||
|
||||
void CatchSignal(int sig_num) {
|
||||
RunLoops = false;
|
||||
if(worldserver)
|
||||
worldserver->Disconnect();
|
||||
}
|
||||
|
||||
int main() {
|
||||
RegisterExecutablePlatform(ExePlatformSocket_Server);
|
||||
set_exception_handler();
|
||||
Timer InterserverTimer(INTERSERVER_TIMER); // does auto-reconnect
|
||||
_log(SOCKET_SERVER__INIT, "Starting EQEmu Socket Server.");
|
||||
if (!socket_server_config::LoadConfig()) {
|
||||
_log(SOCKET_SERVER__INIT, "Loading server configuration failed.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
Config = socket_server_config::get();
|
||||
|
||||
if(!load_log_settings(Config->LogSettingsFile.c_str()))
|
||||
_log(SOCKET_SERVER__INIT, "Warning: Unable to read %s", Config->LogSettingsFile.c_str());
|
||||
else
|
||||
_log(SOCKET_SERVER__INIT, "Log settings loaded from %s", Config->LogSettingsFile.c_str());
|
||||
|
||||
WorldShortName = Config->ShortName;
|
||||
|
||||
/*
|
||||
_log(SOCKET_SERVER__INIT, "Connecting to MySQL...");
|
||||
|
||||
if (!database.Connect(
|
||||
Config->QSDatabaseHost.c_str(),
|
||||
Config->QSDatabaseUsername.c_str(),
|
||||
Config->QSDatabasePassword.c_str(),
|
||||
Config->QSDatabaseDB.c_str(),
|
||||
Config->QSDatabasePort)) {
|
||||
_log(WORLD__INIT_ERR, "Cannot continue without a database connection.");
|
||||
return 1;
|
||||
}
|
||||
*/
|
||||
|
||||
if (signal(SIGINT, CatchSignal) == SIG_ERR) {
|
||||
_log(SOCKET_SERVER__ERROR, "Could not set signal handler");
|
||||
return 1;
|
||||
}
|
||||
if (signal(SIGTERM, CatchSignal) == SIG_ERR) {
|
||||
_log(SOCKET_SERVER__ERROR, "Could not set signal handler");
|
||||
return 1;
|
||||
}
|
||||
|
||||
worldserver = new WorldServer;
|
||||
worldserver->Connect();
|
||||
|
||||
while(RunLoops) {
|
||||
Timer::SetCurrentTime();
|
||||
if (InterserverTimer.Check()) {
|
||||
if (worldserver->TryReconnect() && (!worldserver->Connected()))
|
||||
worldserver->AsyncConnect();
|
||||
}
|
||||
worldserver->Process();
|
||||
timeout_manager.CheckTimeouts();
|
||||
Sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateWindowTitle(char* iNewTitle) {
|
||||
#ifdef _WINDOWS
|
||||
char tmp[500];
|
||||
if (iNewTitle) {
|
||||
snprintf(tmp, sizeof(tmp), "SOCKET_SERVER: %s", iNewTitle);
|
||||
}
|
||||
else {
|
||||
snprintf(tmp, sizeof(tmp), "SOCKET_SERVER");
|
||||
}
|
||||
SetConsoleTitle(tmp);
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/* EQEMu: Everquest Server Emulator
|
||||
Copyright (C) 2001-2008 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/debug.h"
|
||||
#include "socket_server_config.h"
|
||||
|
||||
socket_server_config *socket_server_config::_chat_config = nullptr;
|
||||
|
||||
std::string socket_server_config::GetByName(const std::string &var_name) const {
|
||||
return(EQEmuConfig::GetByName(var_name));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/* EQEMu: Everquest Server Emulator
|
||||
Copyright (C) 2001-2008 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 __socket_server_config_H
|
||||
#define __socket_server_config_H
|
||||
|
||||
#include "../common/EQEmuConfig.h"
|
||||
|
||||
class socket_server_config : public EQEmuConfig {
|
||||
public:
|
||||
virtual std::string GetByName(const std::string &var_name) const;
|
||||
|
||||
private:
|
||||
|
||||
static socket_server_config *_chat_config;
|
||||
|
||||
public:
|
||||
|
||||
// Produce a const singleton
|
||||
static const socket_server_config *get() {
|
||||
if (_chat_config == nullptr)
|
||||
LoadConfig();
|
||||
return(_chat_config);
|
||||
}
|
||||
|
||||
// Load the config
|
||||
static bool LoadConfig() {
|
||||
if (_chat_config != nullptr)
|
||||
delete _chat_config;
|
||||
_chat_config=new socket_server_config;
|
||||
_config=_chat_config;
|
||||
|
||||
return _config->ParseFile(EQEmuConfig::ConfigFile.c_str(),"server");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/* EQEMu: Everquest Server Emulator
|
||||
Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org)
|
||||
|
||||
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/debug.h"
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <iomanip>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "../common/servertalk.h"
|
||||
#include "worldserver.h"
|
||||
#include "socket_server_config.h"
|
||||
#include "database.h"
|
||||
#include "lfguild.h"
|
||||
#include "../common/packet_functions.h"
|
||||
#include "../common/md5.h"
|
||||
#include "../common/packet_dump.h"
|
||||
|
||||
extern WorldServer worldserver;
|
||||
extern const socket_server_config *Config;
|
||||
extern Database database;
|
||||
|
||||
WorldServer::WorldServer()
|
||||
: WorldConnection(EmuTCPConnection::packetModeSocket_Server, Config->SharedKey.c_str()){
|
||||
pTryReconnect = true;
|
||||
}
|
||||
|
||||
WorldServer::~WorldServer(){
|
||||
}
|
||||
|
||||
void WorldServer::OnConnected(){
|
||||
_log(SOCKET_SERVER__INIT, "Connected to World.");
|
||||
WorldConnection::OnConnected();
|
||||
}
|
||||
|
||||
void WorldServer::Process(){
|
||||
WorldConnection::Process();
|
||||
if (!Connected())
|
||||
return;
|
||||
|
||||
ServerPacket *pack = 0;
|
||||
while((pack = tcpc.PopPacket())){
|
||||
_log(SOCKET_SERVER__TRACE, "Received Opcode: %4X", pack->opcode);
|
||||
switch(pack->opcode) {
|
||||
case 0: { break; }
|
||||
case ServerOP_KeepAlive: { break; }
|
||||
}
|
||||
}
|
||||
|
||||
safe_delete(pack);
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/* EQEMu: Everquest Server Emulator
|
||||
Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org)
|
||||
|
||||
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 WORLDSERVER_H
|
||||
#define WORLDSERVER_H
|
||||
|
||||
#include "../common/worldconn.h"
|
||||
#include "../common/eq_packet_structs.h"
|
||||
|
||||
class WorldServer : public WorldConnection
|
||||
{
|
||||
public:
|
||||
WorldServer();
|
||||
virtual ~WorldServer();
|
||||
virtual void Process();
|
||||
|
||||
private:
|
||||
virtual void OnConnected();
|
||||
};
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user