From 0b63eaa25d4a8b97f3ee1f30505b7f2549f4457c Mon Sep 17 00:00:00 2001 From: KimLS Date: Thu, 21 Aug 2014 19:34:45 -0700 Subject: [PATCH] Got rid of socket_server, why the heck is it still around --- socket_server/CMakeLists.txt | 44 ---- socket_server/database.cpp | 131 ------------ socket_server/database.h | 54 ----- socket_server/socket_server.cpp | 281 ------------------------- socket_server/socket_server_config.cpp | 28 --- socket_server/socket_server_config.h | 55 ----- socket_server/worldserver.cpp | 68 ------ socket_server/worldserver.h | 35 --- 8 files changed, 696 deletions(-) delete mode 100644 socket_server/CMakeLists.txt delete mode 100644 socket_server/database.cpp delete mode 100644 socket_server/database.h delete mode 100644 socket_server/socket_server.cpp delete mode 100644 socket_server/socket_server_config.cpp delete mode 100644 socket_server/socket_server_config.h delete mode 100644 socket_server/worldserver.cpp delete mode 100644 socket_server/worldserver.h diff --git a/socket_server/CMakeLists.txt b/socket_server/CMakeLists.txt deleted file mode 100644 index abaec0f21..000000000 --- a/socket_server/CMakeLists.txt +++ /dev/null @@ -1,44 +0,0 @@ -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 ${Boost_LIBRARIES} 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) diff --git a/socket_server/database.cpp b/socket_server/database.cpp deleted file mode 100644 index d27079af0..000000000 --- a/socket_server/database.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/* 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// Disgrace: for windows compile -#ifdef _WINDOWS -#include -#define snprintf _snprintf -#define strncasecmp _strnicmp -#define strcasecmp _stricmp -#else -#include "../common/unix.h" -#include -#endif - -#include "database.h" -#include "../common/eq_packet_structs.h" -#include "../common/string_util.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; -} \ No newline at end of file diff --git a/socket_server/database.h b/socket_server/database.h deleted file mode 100644 index 6500ffad6..000000000 --- a/socket_server/database.h +++ /dev/null @@ -1,54 +0,0 @@ -/* 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 -#include -#include - -//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 - diff --git a/socket_server/socket_server.cpp b/socket_server/socket_server.cpp deleted file mode 100644 index 71c8342ff..000000000 --- a/socket_server/socket_server.cpp +++ /dev/null @@ -1,281 +0,0 @@ -/* 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 -#include -#include -/*#include -#include -#include */ -#include - -typedef websocketpp::server server; - -using websocketpp::connection_hdl; -using websocketpp::lib::placeholders::_1; -using websocketpp::lib::placeholders::_2; -using websocketpp::lib::bind; - -using websocketpp::lib::thread; -using websocketpp::lib::mutex; -using websocketpp::lib::unique_lock; -using websocketpp::lib::condition_variable; - -#include "../common/debug.h" -#include "../common/opcodemgr.h" -#include "../common/eq_stream_factory.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 - -#include -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(); -} - -/* Web Sockets Start Shit */ - -enum action_type { - SUBSCRIBE, - UNSUBSCRIBE, - MESSAGE -}; - -struct action { - action(action_type t, connection_hdl h) : type(t), hdl(h) {} - action(action_type t, connection_hdl h, server::message_ptr m) - : type(t), hdl(h), msg(m) {} - - action_type type; - websocketpp::connection_hdl hdl; - server::message_ptr msg; -}; - -class broadcast_server { -public: - broadcast_server() { - // Initialize Asio Transport - m_server.init_asio(); - - // Register handler callbacks - m_server.set_open_handler(bind(&broadcast_server::on_open, this, ::_1)); - m_server.set_close_handler(bind(&broadcast_server::on_close, this, ::_1)); - m_server.set_message_handler(bind(&broadcast_server::on_message, this, ::_1, ::_2)); - } - - void run(uint16_t port) { - // listen on specified port - m_server.listen(port); - - // Start the server accept loop - m_server.start_accept(); - - // Start the ASIO io_service run loop - try { - m_server.run(); - } - catch (const std::exception & e) { - std::cout << e.what() << std::endl; - } - catch (websocketpp::lib::error_code e) { - std::cout << e.message() << std::endl; - } - catch (...) { - std::cout << "other exception" << std::endl; - } - } - - void on_open(connection_hdl hdl) { - unique_lock lock(m_action_lock); - //std::cout << "on_open" << std::endl; - m_actions.push(action(SUBSCRIBE, hdl)); - lock.unlock(); - m_action_cond.notify_one(); - } - - void on_close(connection_hdl hdl) { - unique_lock lock(m_action_lock); - //std::cout << "on_close" << std::endl; - m_actions.push(action(UNSUBSCRIBE, hdl)); - lock.unlock(); - m_action_cond.notify_one(); - } - - void on_message(connection_hdl hdl, server::message_ptr msg) { - // queue message up for sending by processing thread - unique_lock lock(m_action_lock); - msg->set_payload("Niggers"); - // std::cout << "on_message" << std::endl; - m_actions.push(action(MESSAGE, hdl, msg)); - lock.unlock(); - m_action_cond.notify_one(); - } - - void process_messages() { - while (1) { - unique_lock lock(m_action_lock); - - while (m_actions.empty()) { - m_action_cond.wait(lock); - } - - action a = m_actions.front(); - m_actions.pop(); - - lock.unlock(); - - if (a.type == SUBSCRIBE) { - unique_lock con_lock(m_connection_lock); - m_connections.insert(a.hdl); - } - else if (a.type == UNSUBSCRIBE) { - unique_lock con_lock(m_connection_lock); - m_connections.erase(a.hdl); - } - else if (a.type == MESSAGE) { - unique_lock con_lock(m_connection_lock); - - con_list::iterator it; - for (it = m_connections.begin(); it != m_connections.end(); ++it) { - m_server.send(*it, a.msg); - } - } - else { - // undefined. - } - } - } -private: - typedef std::set> con_list; - - server m_server; - con_list m_connections; - std::queue m_actions; - - mutex m_action_lock; - mutex m_connection_lock; - condition_variable m_action_cond; -}; - -/* Web Sockets Shit End*/ - -int main() { - - try { - broadcast_server server_instance; - - // Start a thread to run the processing loop - thread t(bind(&broadcast_server::process_messages, &server_instance)); - - // Run the asio loop with the main thread - server_instance.run(9002); - - t.join(); - - } - catch (std::exception & e) { - std::cout << e.what() << std::endl; - } - - 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 -} diff --git a/socket_server/socket_server_config.cpp b/socket_server/socket_server_config.cpp deleted file mode 100644 index 8f08eba9d..000000000 --- a/socket_server/socket_server_config.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* 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)); -} - diff --git a/socket_server/socket_server_config.h b/socket_server/socket_server_config.h deleted file mode 100644 index 73b966ce4..000000000 --- a/socket_server/socket_server_config.h +++ /dev/null @@ -1,55 +0,0 @@ -/* 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/eqemu_config.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 - diff --git a/socket_server/worldserver.cpp b/socket_server/worldserver.cpp deleted file mode 100644 index 9c6afa138..000000000 --- a/socket_server/worldserver.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* 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 -#include -#include -#include -#include -#include -#include - -#include "../common/servertalk.h" -#include "worldserver.h" -#include "socket_server_config.h" -#include "database.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; -} \ No newline at end of file diff --git a/socket_server/worldserver.h b/socket_server/worldserver.h deleted file mode 100644 index 167342248..000000000 --- a/socket_server/worldserver.h +++ /dev/null @@ -1,35 +0,0 @@ -/* 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 -