diff --git a/CMakeLists.txt b/CMakeLists.txt index 16a2bfa20..90e896b9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -297,11 +297,6 @@ IF(EQEMU_BUILD_LUA) ENDIF(EQEMU_SANITIZE_LUA_LIBS) ENDIF(EQEMU_BUILD_LUA) -IF(EQEMU_BUILD_SOCKET_SERVER) - INCLUDE_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}/dependencies/websocketpp") - ADD_DEFINITIONS(-D_WEBSOCKETPP_CPP11_STL_) -ENDIF(EQEMU_BUILD_SOCKET_SERVER) - INCLUDE_DIRECTORIES("${ZLIB_INCLUDE_DIRS}" "${MySQL_INCLUDE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/common/glm/glm") IF(EQEMU_BUILD_LUA) @@ -317,9 +312,7 @@ IF(EQEMU_BUILD_SERVER) ADD_SUBDIRECTORY(zone) ADD_SUBDIRECTORY(ucs) ADD_SUBDIRECTORY(queryserv) -IF(EQEMU_BUILD_SOCKET_SERVER) - ADD_SUBDIRECTORY(socket_server) -ENDIF(EQEMU_BUILD_SOCKET_SERVER) + ADD_SUBDIRECTORY(web_interface) ADD_SUBDIRECTORY(eqlaunch) ENDIF(EQEMU_BUILD_SERVER) IF(EQEMU_BUILD_LOGIN) diff --git a/common/EmuTCPConnection.cpp b/common/EmuTCPConnection.cpp index 39c297ccf..f71b3822b 100644 --- a/common/EmuTCPConnection.cpp +++ b/common/EmuTCPConnection.cpp @@ -366,13 +366,13 @@ bool EmuTCPConnection::LineOutQueuePush(char* line) { safe_delete_array(line); return(true); } - if (strcmp(line, "**PACKETMODESS**") == 0) { + if (strcmp(line, "**PACKETMODEWI**") == 0) { MSendQueue.lock(); safe_delete_array(sendbuf); if (TCPMode == modeConsole) - Send((const uchar*) "\0**PACKETMODESS**\r", 18); + Send((const uchar*) "\0**PACKETMODEWI**\r", 18); TCPMode = modePacket; - PacketMode = packetModeSocket_Server; + PacketMode = packetModeWebInterface; EmuTCPNetPacket_Struct* tnps = 0; while ((tnps = InModeQueue.pop())) { SendPacket(tnps); @@ -435,12 +435,12 @@ bool EmuTCPConnection::ConnectIP(uint32 irIP, uint16 irPort, char* errbuf) { sendbuf = new uchar[sendbuf_size]; memcpy(sendbuf, "\0**PACKETMODEQS**\r", sendbuf_size); } - else if (PacketMode == packetModeSocket_Server) { + else if (PacketMode == packetModeWebInterface) { safe_delete_array(sendbuf); sendbuf_size = 18; sendbuf_used = sendbuf_size; sendbuf = new uchar[sendbuf_size]; - memcpy(sendbuf, "\0**PACKETMODESS**\r", sendbuf_size); + memcpy(sendbuf, "\0**PACKETMODEWI**\r", sendbuf_size); } else { //default: packetModeZone diff --git a/common/EmuTCPConnection.h b/common/EmuTCPConnection.h index 947ee9480..155319ffa 100644 --- a/common/EmuTCPConnection.h +++ b/common/EmuTCPConnection.h @@ -30,7 +30,7 @@ class EmuTCPServer; class EmuTCPConnection : public TCPConnection { public: enum eTCPMode { modeConsole, modeTransition, modePacket }; - enum ePacketMode { packetModeZone, packetModeLauncher, packetModeLogin, packetModeUCS, packetModeQueryServ, packetModeSocket_Server }; + enum ePacketMode { packetModeZone, packetModeLauncher, packetModeLogin, packetModeUCS, packetModeQueryServ, packetModeWebInterface }; EmuTCPConnection(uint32 ID, EmuTCPServer* iServer, SOCKET iSock, uint32 irIP, uint16 irPort, bool iOldFormat = false); EmuTCPConnection(bool iOldFormat = false, EmuTCPServer* iRelayServer = 0, eTCPMode iMode = modePacket); // for outgoing connections diff --git a/common/logtypes.h b/common/logtypes.h index 1776c9518..f110f6cc4 100644 --- a/common/logtypes.h +++ b/common/logtypes.h @@ -65,12 +65,12 @@ LOG_TYPE( QUERYSERV, CLIENT, DISABLED ) LOG_TYPE( QUERYSERV, TRACE, DISABLED ) LOG_TYPE( QUERYSERV, PACKETS, DISABLED) -LOG_CATEGORY(SOCKET_SERVER) -LOG_TYPE(SOCKET_SERVER, INIT, ENABLED) -LOG_TYPE(SOCKET_SERVER, ERROR, ENABLED) -LOG_TYPE(SOCKET_SERVER, CLIENT, DISABLED) -LOG_TYPE(SOCKET_SERVER, TRACE, DISABLED) -LOG_TYPE(SOCKET_SERVER, PACKETS, DISABLED) +LOG_CATEGORY( WEB_INTERFACE ) +LOG_TYPE( WEB_INTERFACE, INIT, ENABLED ) +LOG_TYPE( WEB_INTERFACE, ERROR, ENABLED ) +LOG_TYPE( WEB_INTERFACE, CLIENT, DISABLED ) +LOG_TYPE( WEB_INTERFACE, TRACE, DISABLED ) +LOG_TYPE( WEB_INTERFACE, PACKETS, DISABLED ) LOG_CATEGORY( SPAWNS ) LOG_TYPE( SPAWNS, MAIN, DISABLED ) diff --git a/common/platform.h b/common/platform.h index 7eaae045b..eff16f61c 100644 --- a/common/platform.h +++ b/common/platform.h @@ -8,7 +8,7 @@ enum EQEmuExePlatform ExePlatformWorld, ExePlatformLogin, ExePlatformQueryServ, - ExePlatformSocket_Server, + ExePlatformWebInterface, ExePlatformUCS, ExePlatformLaunch, ExePlatformSharedMemory, diff --git a/socket_server/CMakeLists.txt b/socket_server/CMakeLists.txt deleted file mode 100644 index f647863d9..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 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 a2c04bbb4..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/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; -} \ 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 83af27d4c..000000000 --- a/socket_server/socket_server.cpp +++ /dev/null @@ -1,240 +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 "../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 - -#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 */ - -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("Test Message"); - // 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 */ -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 -} 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 bc86107d3..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/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 - diff --git a/web_interface/CMakeLists.txt b/web_interface/CMakeLists.txt new file mode 100644 index 000000000..632d6d5a8 --- /dev/null +++ b/web_interface/CMakeLists.txt @@ -0,0 +1,40 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) + +SET(web_interface_sources + web_interface.cpp + worldserver.cpp +) + +SET(web_interface_headers + worldserver.h +) + +ADD_EXECUTABLE(web_interface ${web_interface_sources} ${web_interface_headers}) + +INSTALL(TARGETS web_interface RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}) + +ADD_DEFINITIONS(-DQSERV) + +TARGET_LINK_LIBRARIES(web_interface Common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY}) + +IF(MSVC) + SET_TARGET_PROPERTIES(web_interface PROPERTIES LINK_FLAGS_RELEASE "/OPT:REF /OPT:ICF") + TARGET_LINK_LIBRARIES(web_interface "Ws2_32.lib") +ENDIF(MSVC) + +IF(MINGW) + TARGET_LINK_LIBRARIES(web_interface "WS2_32") +ENDIF(MINGW) + +IF(UNIX) + TARGET_LINK_LIBRARIES(web_interface "${CMAKE_DL_LIBS}") + TARGET_LINK_LIBRARIES(web_interface "z") + TARGET_LINK_LIBRARIES(web_interface "m") + IF(NOT DARWIN) + TARGET_LINK_LIBRARIES(web_interface "rt") + ENDIF(NOT DARWIN) + TARGET_LINK_LIBRARIES(web_interface "pthread") + ADD_DEFINITIONS(-fPIC) +ENDIF(UNIX) + +SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/Bin) diff --git a/web_interface/web_interface.cpp b/web_interface/web_interface.cpp new file mode 100644 index 000000000..9f609839a --- /dev/null +++ b/web_interface/web_interface.cpp @@ -0,0 +1,55 @@ +#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 "../common/EQEmuConfig.h" +#include "worldserver.h" +#include + +volatile bool run = true; +TimeoutManager timeout_manager; +const EQEmuConfig *config = nullptr; +WorldServer *worldserver = nullptr; + +void CatchSignal(int sig_num) { + run = false; + if(worldserver) + worldserver->Disconnect(); +} + +int main() { + RegisterExecutablePlatform(ExePlatformWebInterface); + set_exception_handler(); + Timer InterserverTimer(INTERSERVER_TIMER); // does auto-reconnect + _log(WEB_INTERFACE__INIT, "Starting EQEmu Socket Server."); + + if (signal(SIGINT, CatchSignal) == SIG_ERR) { + _log(WEB_INTERFACE__ERROR, "Could not set signal handler"); + return 1; + } + + if (signal(SIGTERM, CatchSignal) == SIG_ERR) { + _log(WEB_INTERFACE__ERROR, "Could not set signal handler"); + return 1; + } + + config = EQEmuConfig::get(); + + worldserver = new WorldServer(config->SharedKey); + worldserver->Connect(); + + while(run) { + Timer::SetCurrentTime(); + if (InterserverTimer.Check()) { + if (worldserver->TryReconnect() && (!worldserver->Connected())) + worldserver->AsyncConnect(); + } + worldserver->Process(); + timeout_manager.CheckTimeouts(); + Sleep(10); + } +} + diff --git a/socket_server/worldserver.cpp b/web_interface/worldserver.cpp similarity index 74% rename from socket_server/worldserver.cpp rename to web_interface/worldserver.cpp index f4e7cdf76..9b34d500d 100644 --- a/socket_server/worldserver.cpp +++ b/web_interface/worldserver.cpp @@ -1,5 +1,5 @@ /* EQEMu: Everquest Server Emulator - Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org) + Copyright (C) 2001-2014 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 @@ -25,20 +25,13 @@ #include #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" +#include "worldserver.h" -extern WorldServer worldserver; -extern const socket_server_config *Config; -extern Database database; - -WorldServer::WorldServer() -: WorldConnection(EmuTCPConnection::packetModeSocket_Server, Config->SharedKey.c_str()){ +WorldServer::WorldServer(std::string shared_key) +: WorldConnection(EmuTCPConnection::packetModeWebInterface, shared_key.c_str()){ pTryReconnect = true; } @@ -46,7 +39,7 @@ WorldServer::~WorldServer(){ } void WorldServer::OnConnected(){ - _log(SOCKET_SERVER__INIT, "Connected to World."); + _log(WEB_INTERFACE__INIT, "Connected to World."); WorldConnection::OnConnected(); } @@ -55,9 +48,9 @@ void WorldServer::Process(){ if (!Connected()) return; - ServerPacket *pack = 0; + ServerPacket *pack = nullptr; while((pack = tcpc.PopPacket())){ - _log(SOCKET_SERVER__TRACE, "Received Opcode: %4X", pack->opcode); + _log(WEB_INTERFACE__TRACE, "Received Opcode: %4X", pack->opcode); switch(pack->opcode) { case 0: { break; } case ServerOP_KeepAlive: { break; } @@ -66,4 +59,4 @@ void WorldServer::Process(){ safe_delete(pack); return; -} \ No newline at end of file +} diff --git a/socket_server/worldserver.h b/web_interface/worldserver.h similarity index 86% rename from socket_server/worldserver.h rename to web_interface/worldserver.h index 167342248..e9918f2e0 100644 --- a/socket_server/worldserver.h +++ b/web_interface/worldserver.h @@ -1,5 +1,5 @@ /* EQEMu: Everquest Server Emulator - Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org) + Copyright (C) 2001-2014 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 @@ -15,8 +15,8 @@ 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 +#ifndef WI_WORLDSERVER_H +#define WI_WORLDSERVER_H #include "../common/worldconn.h" #include "../common/eq_packet_structs.h" @@ -24,7 +24,7 @@ class WorldServer : public WorldConnection { public: - WorldServer(); + WorldServer(std::string shared_key); virtual ~WorldServer(); virtual void Process(); diff --git a/world/CMakeLists.txt b/world/CMakeLists.txt index 594f77bc1..c2b4eb1a1 100644 --- a/world/CMakeLists.txt +++ b/world/CMakeLists.txt @@ -23,8 +23,8 @@ SET(world_sources perl_EQW.cpp perl_HTTPRequest.cpp queryserv.cpp - socket_server.cpp ucs.cpp + web_interface.cpp wguild_mgr.cpp world_logsys.cpp WorldConfig.cpp @@ -54,9 +54,9 @@ SET(world_headers LoginServerList.h net.h queryserv.h - socket_server.h SoFCharCreateData.h ucs.h + web_interface.h wguild_mgr.h WorldConfig.h worlddb.h diff --git a/world/console.cpp b/world/console.cpp index 5a9ee60f5..afbdf6dba 100644 --- a/world/console.cpp +++ b/world/console.cpp @@ -46,7 +46,7 @@ #include "LauncherList.h" #include "ucs.h" #include "queryserv.h" -#include "socket_server.h" +#include "web_interface.h" #ifdef _WINDOWS #define snprintf _snprintf @@ -61,7 +61,7 @@ extern ClientList client_list; extern LauncherList launcher_list; extern UCSConnection UCSLink; extern QueryServConnection QSLink; -extern Socket_Server_Connection SSLink; +extern WebInterfaceConnection WILink; extern volatile bool RunLoops; ConsoleList console_list; @@ -265,10 +265,10 @@ bool Console::Process() { QSLink.SetConnection(tcpc); tcpc = 0; } - else if (tcpc->GetPacketMode() == EmuTCPConnection::packetModeSocket_Server) + else if (tcpc->GetPacketMode() == EmuTCPConnection::packetModeWebInterface) { - _log(WORLD__CONSOLE, "New Socket Server Connection from %s:%d", inet_ntoa(in), GetPort()); - SSLink.SetConnection(tcpc); + _log(WORLD__CONSOLE, "New WI Connection from %s:%d", inet_ntoa(in), GetPort()); + WILink.SetConnection(tcpc); tcpc = 0; } else { diff --git a/world/net.cpp b/world/net.cpp index f8d3410c0..bb7b4313a 100644 --- a/world/net.cpp +++ b/world/net.cpp @@ -86,7 +86,7 @@ #include "AdventureManager.h" #include "ucs.h" #include "queryserv.h" -#include "socket_server.h" +#include "web_interface.h" TimeoutManager timeout_manager; EQStreamFactory eqsf(WorldStream,9000); @@ -98,7 +98,7 @@ LoginServerList loginserverlist; EQWHTTPServer http_server; UCSConnection UCSLink; QueryServConnection QSLink; -Socket_Server_Connection SSLink; +WebInterfaceConnection WILink; LauncherList launcher_list; AdventureManager adventure_manager; DBAsync *dbasync = nullptr; @@ -456,7 +456,7 @@ int main(int argc, char** argv) { QSLink.Process(); - SSLink.Process(); + WILink.Process(); LFPGroupList.Process(); diff --git a/world/socket_server.cpp b/world/web_interface.cpp similarity index 57% rename from world/socket_server.cpp rename to world/web_interface.cpp index 3c6631c49..b01d857f5 100644 --- a/world/socket_server.cpp +++ b/world/web_interface.cpp @@ -1,5 +1,5 @@ #include "../common/debug.h" -#include "socket_server.h" +#include "web_interface.h" #include "WorldConfig.h" #include "clientlist.h" #include "zonelist.h" @@ -12,33 +12,33 @@ extern ClientList client_list; extern ZSList zoneserver_list; -Socket_Server_Connection::Socket_Server_Connection() +WebInterfaceConnection::WebInterfaceConnection() { - Stream = 0; + stream = 0; authenticated = false; } -void Socket_Server_Connection::SetConnection(EmuTCPConnection *inStream) +void WebInterfaceConnection::SetConnection(EmuTCPConnection *inStream) { - if(Stream) + if(stream) { - _log(SOCKET_SERVER__ERROR, "Incoming Socket_Server Connection while we were already connected to a Socket_Server."); - Stream->Disconnect(); + _log(WEB_INTERFACE__ERROR, "Incoming WebInterface Connection while we were already connected to a WebInterface."); + stream->Disconnect(); } - Stream = inStream; + stream = inStream; authenticated = false; } -bool Socket_Server_Connection::Process() +bool WebInterfaceConnection::Process() { - if (!Stream || !Stream->Connected()) + if (!stream || !stream->Connected()) return false; ServerPacket *pack = 0; - while((pack = Stream->PopPacket())) + while((pack = stream->PopPacket())) { if (!authenticated) { @@ -56,7 +56,7 @@ bool Socket_Server_Connection::Process() { struct in_addr in; in.s_addr = GetIP(); - _log(SOCKET_SERVER__ERROR, "Socket_Server authorization failed."); + _log(WEB_INTERFACE__ERROR, "WebInterface authorization failed."); ServerPacket* pack = new ServerPacket(ServerOP_ZAAuthFailed); SendPacket(pack); delete pack; @@ -68,7 +68,7 @@ bool Socket_Server_Connection::Process() { struct in_addr in; in.s_addr = GetIP(); - _log(SOCKET_SERVER__ERROR, "Socket_Server_ authorization failed."); + _log(WEB_INTERFACE__ERROR, "WebInterface authorization failed."); ServerPacket* pack = new ServerPacket(ServerOP_ZAAuthFailed); SendPacket(pack); delete pack; @@ -78,7 +78,7 @@ bool Socket_Server_Connection::Process() } else { - _log(SOCKET_SERVER__ERROR,"**WARNING** You have not configured a world shared key in your config file. You should add a STRING element to your element to prevent unauthorized zone access."); + _log(WEB_INTERFACE__ERROR, "**WARNING** You have not configured a world shared key in your config file. You should add a STRING element to your element to prevent unauthorized zone access."); authenticated = true; } delete pack; @@ -96,17 +96,12 @@ bool Socket_Server_Connection::Process() } case ServerOP_ZAAuth: { - _log(SOCKET_SERVER__ERROR, "Got authentication from Socket_Server_ when they are already authenticated."); - break; - } - case ServerOP_LFGuildUpdate: - { - zoneserver_list.SendPacket(pack); + _log(WEB_INTERFACE__ERROR, "Got authentication from WebInterface when they are already authenticated."); break; } default: { - _log(SOCKET_SERVER__ERROR, "Unknown ServerOPcode from Socket_Server_ 0x%04x, size %d", pack->opcode, pack->size); + _log(WEB_INTERFACE__ERROR, "Unknown ServerOPcode from WebInterface 0x%04x, size %d", pack->opcode, pack->size); DumpPacket(pack->pBuffer, pack->size); break; } @@ -117,11 +112,11 @@ bool Socket_Server_Connection::Process() return(true); } -bool Socket_Server_Connection::SendPacket(ServerPacket* pack) +bool WebInterfaceConnection::SendPacket(ServerPacket* pack) { - if(!Stream) + if(!stream) return false; - return Stream->SendPacket(pack); + return stream->SendPacket(pack); } diff --git a/world/socket_server.h b/world/web_interface.h similarity index 51% rename from world/socket_server.h rename to world/web_interface.h index 7cb39c2d6..6db1900e2 100644 --- a/world/socket_server.h +++ b/world/web_interface.h @@ -1,23 +1,23 @@ -#ifndef Socket_Server__H -#define Socket_Server__H +#ifndef WORLD_WEB_INTERFACE_H +#define WORLD_WEB_INTERFACE_H #include "../common/types.h" #include "../common/EmuTCPConnection.h" #include "../common/servertalk.h" -class Socket_Server_Connection +class WebInterfaceConnection { public: - Socket_Server_Connection(); + WebInterfaceConnection(); void SetConnection(EmuTCPConnection *inStream); bool Process(); bool SendPacket(ServerPacket* pack); - void Disconnect() { if(Stream) Stream->Disconnect(); } + void Disconnect() { if(stream) stream->Disconnect(); } void SendMessage(const char *From, const char *Message); private: - inline uint32 GetIP() const { return Stream ? Stream->GetrIP() : 0; } - EmuTCPConnection *Stream; + inline uint32 GetIP() const { return stream ? stream->GetrIP() : 0; } + EmuTCPConnection *stream; bool authenticated; }; -#endif /*Socket_Server__H_*/ +#endif /*WORLD_WEB_INTERFACE_H*/