From 7a3147a3b356f24c9e030bb9d1dd3b058082d316 Mon Sep 17 00:00:00 2001 From: KimLS Date: Thu, 29 Sep 2016 22:21:39 -0700 Subject: [PATCH] Streams work on all of the servers now --- common/CMakeLists.txt | 7 --- common/eq_stream_ident.cpp | 10 ++-- common/eq_stream_ident.h | 2 +- common/eq_stream_intf.h | 1 + common/eq_stream_proxy.cpp | 1 - common/eq_stream_proxy.h | 1 - common/net/daybreak_connection.cpp | 88 +++++++++++++++++++----------- common/net/daybreak_connection.h | 12 +++- common/packet_dump_file.cpp | 2 +- common/struct_strategy.cpp | 3 +- loginserver/CMakeLists.txt | 12 ++-- loginserver/client.h | 6 +- loginserver/client_manager.cpp | 63 ++++++--------------- loginserver/client_manager.h | 7 +-- loginserver/main.cpp | 7 +-- loginserver/server_manager.h | 1 - loginserver/world_server.h | 1 - queryserv/queryserv.cpp | 5 +- ucs/CMakeLists.txt | 13 ++--- ucs/clientlist.cpp | 37 ++++--------- ucs/clientlist.h | 5 +- ucs/ucs.cpp | 7 +-- world/client.h | 1 - world/net.cpp | 9 +-- zone/net.cpp | 8 +-- 25 files changed, 128 insertions(+), 181 deletions(-) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 5448707fb..445d355da 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -26,8 +26,6 @@ SET(common_sources eqemu_logsys.cpp eq_limits.cpp eq_packet.cpp - eq_stream.cpp - eq_stream_factory.cpp eq_stream_ident.cpp eq_stream_proxy.cpp eqtime.cpp @@ -69,7 +67,6 @@ SET(common_sources tcp_connection.cpp tcp_server.cpp textures.cpp - timeoutmgr.cpp timer.cpp unix.cpp worldconn.cpp @@ -142,13 +139,10 @@ SET(common_headers eqemu_logsys.h eq_limits.h eq_packet.h - eq_stream.h - eq_stream_factory.h eq_stream_ident.h eq_stream_intf.h eq_stream_locator.h eq_stream_proxy.h - eq_stream_type.h eqtime.h errmsg.h extprofile.h @@ -205,7 +199,6 @@ SET(common_headers tcp_connection.h tcp_server.h textures.h - timeoutmgr.h timer.h types.h unix.h diff --git a/common/eq_stream_ident.cpp b/common/eq_stream_ident.cpp index 8890bf05c..cbe8ce80a 100644 --- a/common/eq_stream_ident.cpp +++ b/common/eq_stream_ident.cpp @@ -4,7 +4,7 @@ #include "eqemu_logsys.h" #include "eq_stream_ident.h" #include "eq_stream_proxy.h" - +#include "misc.h" EQStreamIdentifier::~EQStreamIdentifier() { while(!m_identified.empty()) { @@ -98,14 +98,14 @@ void EQStreamIdentifier::Process() { Patch *p = *curp; //ask the stream to see if it matches the supplied signature - EQStream::MatchState res = r.stream->CheckSignature(&p->signature); + EQStreamInterface::MatchState res = r.stream->CheckSignature(&p->signature); switch(res) { - case EQStream::MatchNotReady: + case EQStreamInterface::MatchNotReady: //the stream has not received enough packets to compare with this signature // Log.LogDebugType(Logs::General, Logs::Netcode, "[IDENT_TRACE] %s:%d: Tried patch %s, but stream is not ready for it.", long2ip(r.stream->GetRemoteIP()).c_str(), ntohs(r.stream->GetRemotePort()), p->name.c_str()); all_ready = false; break; - case EQStream::MatchSuccessful: { + case EQStreamInterface::MatchSuccessful: { //yay, a match. Log.Out(Logs::General, Logs::Netcode, "[IDENTIFY] Identified stream %s:%d with signature %s", long2ip(r.stream->GetRemoteIP()).c_str(), ntohs(r.stream->GetRemotePort()), p->name.c_str()); @@ -120,7 +120,7 @@ void EQStreamIdentifier::Process() { found_one = true; break; } - case EQStream::MatchFailed: + case EQStreamInterface::MatchFailed: //do nothing... Log.Out(Logs::General, Logs::Netcode, "[IDENT_TRACE] %s:%d: Tried patch %s, and it did not match.", long2ip(r.stream->GetRemoteIP()).c_str(), ntohs(r.stream->GetRemotePort()), p->name.c_str()); break; diff --git a/common/eq_stream_ident.h b/common/eq_stream_ident.h index 4b9bfac31..2a58606b5 100644 --- a/common/eq_stream_ident.h +++ b/common/eq_stream_ident.h @@ -1,7 +1,7 @@ #ifndef EQSTREAMIDENT_H_ #define EQSTREAMIDENT_H_ -#include "eq_stream.h" +#include "eq_stream_intf.h" #include "timer.h" #include #include diff --git a/common/eq_stream_intf.h b/common/eq_stream_intf.h index 5c62c0b39..40358998f 100644 --- a/common/eq_stream_intf.h +++ b/common/eq_stream_intf.h @@ -5,6 +5,7 @@ #include #include "emu_versions.h" +#include "eq_packet.h" typedef enum { ESTABLISHED, diff --git a/common/eq_stream_proxy.cpp b/common/eq_stream_proxy.cpp index 0817edbd2..1d6a3bd08 100644 --- a/common/eq_stream_proxy.cpp +++ b/common/eq_stream_proxy.cpp @@ -1,7 +1,6 @@ #include "global_define.h" #include "eq_stream_proxy.h" -#include "eq_stream.h" #include "struct_strategy.h" diff --git a/common/eq_stream_proxy.h b/common/eq_stream_proxy.h index e0a2327ca..602c59a83 100644 --- a/common/eq_stream_proxy.h +++ b/common/eq_stream_proxy.h @@ -4,7 +4,6 @@ #include "types.h" #include "eq_stream_intf.h" -#include "eq_stream.h" #include class StructStrategy; diff --git a/common/net/daybreak_connection.cpp b/common/net/daybreak_connection.cpp index 5f392b664..89b8edef7 100644 --- a/common/net/daybreak_connection.cpp +++ b/common/net/daybreak_connection.cpp @@ -46,7 +46,7 @@ void EQ::Net::DaybreakConnectionManager::Attach(uv_loop_t *loop) uv_timer_start(&m_resend_timer, [](uv_timer_t *handle) { DaybreakConnectionManager *c = (DaybreakConnectionManager*)handle->data; c->ProcessResend(); - }, 10, 10); + }, 5, 5); uv_udp_init(loop, &m_socket); m_socket.data = this; @@ -174,6 +174,10 @@ void EQ::Net::DaybreakConnectionManager::ProcessResend() void EQ::Net::DaybreakConnectionManager::ProcessPacket(const std::string &endpoint, int port, const char *data, size_t size) { + if (m_options.simulated_in_packet_loss && m_options.simulated_in_packet_loss >= m_rand.Int(0, 100)) { + return; + } + if (size < DaybreakHeader::size()) { Log.OutF(Logs::Detail, Logs::Netcode, "Packet of size {0} which is less than {1}", size, DaybreakHeader::size()); return; @@ -200,7 +204,7 @@ void EQ::Net::DaybreakConnectionManager::ProcessPacket(const std::string &endpoi connection->ProcessPacket(p); } else if(data[1] != OP_OutOfSession) { - SendSessionLost(endpoint, port); + SendDisconnect(endpoint, port); } } } @@ -220,11 +224,12 @@ std::shared_ptr EQ::Net::DaybreakConnectionManager: return nullptr; } -void EQ::Net::DaybreakConnectionManager::SendSessionLost(const std::string &addr, int port) +void EQ::Net::DaybreakConnectionManager::SendDisconnect(const std::string &addr, int port) { - DaybreakHeader header; + DaybreakDisconnect header; header.zero = 0; - header.opcode = OP_OutOfSession; + header.opcode = OP_SessionDisconnect; + header.connect_code = 0; WritablePacket out; out.PutSerialize(0, header); @@ -336,28 +341,28 @@ void EQ::Net::DaybreakConnection::ResetStats() void EQ::Net::DaybreakConnection::Process() { - m_resend_delay = (size_t)(m_rolling_ping * 1.33); + try { + m_resend_delay = (size_t)(m_stats.last_stat_ping * m_owner->m_options.resend_delay_factor) + m_owner->m_options.resend_delay_ms; + if (m_resend_delay > 1000) { + m_resend_delay = 1000; + } - if (m_resend_delay < 15) { - m_resend_delay = 15; + auto now = Clock::now(); + auto time_since_hold = (size_t)std::chrono::duration_cast(now - m_hold_time).count(); + if (time_since_hold >= m_owner->m_options.hold_length_ms) { + FlushBuffer(); + } + + ProcessQueue(); + + auto time_since_stats = (size_t)std::chrono::duration_cast(now - m_last_stats).count(); + if (m_owner->m_options.stats_delay_ms > 0 && time_since_stats >= m_owner->m_options.stats_delay_ms) { + SendStatSync(); + m_last_stats = now; + } } - - if (m_resend_delay > 1000) { - m_resend_delay = 1000; - } - - auto now = Clock::now(); - auto time_since_hold = (size_t)std::chrono::duration_cast(now - m_hold_time).count(); - if (time_since_hold >= m_owner->m_options.hold_length_ms) { - FlushBuffer(); - } - - ProcessQueue(); - - auto time_since_stats = (size_t)std::chrono::duration_cast(now - m_last_stats).count(); - if (m_owner->m_options.stats_delay_ms > 0 && time_since_stats >= m_owner->m_options.stats_delay_ms) { - SendStatSync(); - m_last_stats = now; + catch (std::exception ex) { + Log.OutF(Logs::Detail, Logs::Netcode, "Error processing connection: {0}", ex.what()); } } @@ -954,10 +959,19 @@ void EQ::Net::DaybreakConnection::ProcessResend(int stream) auto s = &m_streams[stream]; for (auto &entry : s->sent_packets) { auto time_since_last_send = std::chrono::duration_cast(now - entry.second.last_sent); - if ((size_t)time_since_last_send.count() > m_resend_delay) { - InternalBufferedSend(entry.second.packet); - entry.second.last_sent = now; - entry.second.times_resent++; + if(entry.second.times_resent == 0) { + if ((size_t)time_since_last_send.count() > m_resend_delay) { + InternalBufferedSend(entry.second.packet); + entry.second.last_sent = now; + entry.second.times_resent++; + } + } + else { + if ((size_t)time_since_last_send.count() > std::min(m_resend_delay / (entry.second.times_resent + 1), 5ULL)) { + InternalBufferedSend(entry.second.packet); + entry.second.last_sent = now; + entry.second.times_resent++; + } } } } @@ -1042,6 +1056,7 @@ void EQ::Net::DaybreakConnection::SendStatSync() request.packets_sent = m_stats.sent_packets + 1; request.packets_recv = m_stats.recv_packets; m_last_session_stats = Clock::now(); + //InternalSend() } void EQ::Net::DaybreakConnection::InternalBufferedSend(Packet &p) @@ -1130,9 +1145,14 @@ void EQ::Net::DaybreakConnection::InternalSend(Packet &p) send_buffers[0].base = (char*)out.Data(); send_buffers[0].len = out.Length(); - uv_udp_send(send_req, &m_owner->m_socket, send_buffers, 1, (sockaddr*)&send_addr, send_func); m_stats.sent_bytes += out.Length(); m_stats.sent_packets++; + if (m_owner->m_options.simulated_out_packet_loss && m_owner->m_options.simulated_out_packet_loss >= m_owner->m_rand.Int(0, 100)) { + delete send_req; + return; + } + + uv_udp_send(send_req, &m_owner->m_socket, send_buffers, 1, (sockaddr*)&send_addr, send_func); return; } @@ -1144,9 +1164,15 @@ void EQ::Net::DaybreakConnection::InternalSend(Packet &p) send_buffers[0].base = (char*)p.Data(); send_buffers[0].len = p.Length(); - uv_udp_send(send_req, &m_owner->m_socket, send_buffers, 1, (sockaddr*)&send_addr, send_func); m_stats.sent_bytes += p.Length(); m_stats.sent_packets++; + + if (m_owner->m_options.simulated_out_packet_loss && m_owner->m_options.simulated_out_packet_loss >= m_owner->m_rand.Int(0, 100)) { + delete send_req; + return; + } + + uv_udp_send(send_req, &m_owner->m_socket, send_buffers, 1, (sockaddr*)&send_addr, send_func); } void EQ::Net::DaybreakConnection::InternalQueuePacket(Packet &p, int stream_id, bool reliable) diff --git a/common/net/daybreak_connection.h b/common/net/daybreak_connection.h index 762536ce1..75970f76e 100644 --- a/common/net/daybreak_connection.h +++ b/common/net/daybreak_connection.h @@ -217,10 +217,11 @@ namespace EQ DaybreakConnectionManagerOptions() { max_connection_count = 0; keepalive_delay_ms = 0; - resend_delay_ms = 1000; + resend_delay_ms = 10; + resend_delay_factor = 1.25; stats_delay_ms = 0; connect_delay_ms = 1000; - stale_connection_ms = 60000; + stale_connection_ms = 135000; crc_length = 2; max_packet_size = 512; encode_passes[0] = DaybreakEncodeType::EncodeNone; @@ -228,11 +229,14 @@ namespace EQ port = 0; hold_size = 384; hold_length_ms = 50; + simulated_in_packet_loss = 0; + simulated_out_packet_loss = 0; } size_t max_packet_size; size_t max_connection_count; size_t keepalive_delay_ms; + double resend_delay_factor; size_t resend_delay_ms; size_t stats_delay_ms; size_t connect_delay_ms; @@ -240,6 +244,8 @@ namespace EQ size_t crc_length; size_t hold_size; size_t hold_length_ms; + size_t simulated_in_packet_loss; + size_t simulated_out_packet_loss; DaybreakEncodeType encode_passes[2]; int port; }; @@ -274,7 +280,7 @@ namespace EQ void ProcessPacket(const std::string &endpoint, int port, const char *data, size_t size); std::shared_ptr FindConnectionByEndpoint(std::string addr, int port); - void SendSessionLost(const std::string &addr, int port); + void SendDisconnect(const std::string &addr, int port); friend class DaybreakConnection; }; diff --git a/common/packet_dump_file.cpp b/common/packet_dump_file.cpp index d8b6b09c5..ac468a639 100644 --- a/common/packet_dump_file.cpp +++ b/common/packet_dump_file.cpp @@ -37,7 +37,7 @@ #include #endif -#include "eq_stream.h" +#include "eq_stream_intf.h" #include "packet_dump_file.h" void FileDumpPacketAscii(const char* filename, const uchar* buf, uint32 size, uint32 cols, uint32 skip) { diff --git a/common/struct_strategy.cpp b/common/struct_strategy.cpp index 52442cee6..e1561de18 100644 --- a/common/struct_strategy.cpp +++ b/common/struct_strategy.cpp @@ -3,7 +3,8 @@ #include "eqemu_logsys.h" #include "struct_strategy.h" -#include "eq_stream.h" +#include "eq_stream_intf.h" +#include "opcodemgr.h" #include #include diff --git a/loginserver/CMakeLists.txt b/loginserver/CMakeLists.txt index c1c4054b5..5a3c1d0d2 100644 --- a/loginserver/CMakeLists.txt +++ b/loginserver/CMakeLists.txt @@ -41,16 +41,12 @@ ADD_EXECUTABLE(loginserver ${eqlogin_sources} ${eqlogin_headers}) INSTALL(TARGETS loginserver RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) -TARGET_LINK_LIBRARIES(loginserver common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY}) +TARGET_LINK_LIBRARIES(loginserver common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY} libuv fmt) -IF(MSVC) - SET_TARGET_PROPERTIES(loginserver PROPERTIES LINK_FLAGS_RELEASE "/OPT:REF /OPT:ICF") - TARGET_LINK_LIBRARIES(loginserver "Ws2_32.lib") -ENDIF(MSVC) +IF(WIN32) + TARGET_LINK_LIBRARIES(loginserver "ws2_32" "psapi" "iphlpapi" "userenv") +ENDIF(WIN32) -IF(MINGW) - TARGET_LINK_LIBRARIES(loginserver "WS2_32") -ENDIF(MINGW) IF(UNIX) TARGET_LINK_LIBRARIES(loginserver "${CMAKE_DL_LIBS}") diff --git a/loginserver/client.h b/loginserver/client.h index 872b5189c..bc08f6fb7 100644 --- a/loginserver/client.h +++ b/loginserver/client.h @@ -20,13 +20,13 @@ #include "../common/global_define.h" #include "../common/opcodemgr.h" -#include "../common/eq_stream_type.h" -#include "../common/eq_stream_factory.h" #include "../common/random.h" #ifndef WIN32 #include "eq_crypto_api.h" #endif -#include + +#include +#include "../common/eq_stream_intf.h" using namespace std; diff --git a/loginserver/client_manager.cpp b/loginserver/client_manager.cpp index e19cb220f..9b1906bd9 100644 --- a/loginserver/client_manager.cpp +++ b/loginserver/client_manager.cpp @@ -27,7 +27,8 @@ extern EQEmuLogSys Log; ClientManager::ClientManager() { int titanium_port = atoi(server.config->GetVariable("Titanium", "port").c_str()); - titanium_stream = new EQStreamFactory(LoginStream, titanium_port); + EQ::Net::EQStreamManagerOptions titanium_opts(titanium_port, false, false); + titanium_stream = new EQ::Net::EQStreamManager(titanium_opts); titanium_ops = new RegularOpcodeManager; if(!titanium_ops->LoadOpcodes(server.config->GetVariable("Titanium", "opcodes").c_str())) { @@ -36,18 +37,16 @@ ClientManager::ClientManager() run_server = false; } - if(titanium_stream->Open()) - { - Log.Out(Logs::General, Logs::Login_Server, "ClientManager listening on Titanium stream."); - } - else - { - Log.Out(Logs::General, Logs::Error, "ClientManager fatal error: couldn't open Titanium stream."); - run_server = false; - } + titanium_stream->OnNewConnection([this](std::shared_ptr stream) { + Log.OutF(Logs::General, Logs::Login_Server, "New Titanium client connection from {0}:{1}", stream->RemoteEndpoint(), stream->GetRemotePort()); + stream->SetOpcodeManager(&titanium_ops); + Client *c = new Client(stream, cv_titanium); + clients.push_back(c); + }); int sod_port = atoi(server.config->GetVariable("SoD", "port").c_str()); - sod_stream = new EQStreamFactory(LoginStream, sod_port); + EQ::Net::EQStreamManagerOptions sod_opts(sod_port, false, false); + sod_stream = new EQ::Net::EQStreamManager(sod_opts); sod_ops = new RegularOpcodeManager; if(!sod_ops->LoadOpcodes(server.config->GetVariable("SoD", "opcodes").c_str())) { @@ -56,22 +55,18 @@ ClientManager::ClientManager() run_server = false; } - if(sod_stream->Open()) - { - Log.Out(Logs::General, Logs::Login_Server, "ClientManager listening on SoD stream."); - } - else - { - Log.Out(Logs::General, Logs::Error, "ClientManager fatal error: couldn't open SoD stream."); - run_server = false; - } + sod_stream->OnNewConnection([this](std::shared_ptr stream) { + Log.OutF(Logs::General, Logs::Login_Server, "New SoD client connection from {0}:{1}", stream->RemoteEndpoint(), stream->GetRemotePort()); + stream->SetOpcodeManager(&sod_ops); + Client *c = new Client(stream, cv_sod); + clients.push_back(c); + }); } ClientManager::~ClientManager() { if(titanium_stream) { - titanium_stream->Close(); delete titanium_stream; } @@ -82,7 +77,6 @@ ClientManager::~ClientManager() if(sod_stream) { - sod_stream->Close(); delete sod_stream; } @@ -95,31 +89,6 @@ ClientManager::~ClientManager() void ClientManager::Process() { ProcessDisconnect(); - std::shared_ptr cur = titanium_stream->Pop(); - while(cur) - { - struct in_addr in; - in.s_addr = cur->GetRemoteIP(); - Log.Out(Logs::General, Logs::Login_Server, "New Titanium client connection from %s:%d", inet_ntoa(in), ntohs(cur->GetRemotePort())); - - cur->SetOpcodeManager(&titanium_ops); - Client *c = new Client(cur, cv_titanium); - clients.push_back(c); - cur = titanium_stream->Pop(); - } - - cur = sod_stream->Pop(); - while(cur) - { - struct in_addr in; - in.s_addr = cur->GetRemoteIP(); - Log.Out(Logs::General, Logs::Login_Server, "New SoD client connection from %s:%d", inet_ntoa(in), ntohs(cur->GetRemotePort())); - - cur->SetOpcodeManager(&sod_ops); - Client *c = new Client(cur, cv_sod); - clients.push_back(c); - cur = sod_stream->Pop(); - } list::iterator iter = clients.begin(); while(iter != clients.end()) diff --git a/loginserver/client_manager.h b/loginserver/client_manager.h index dc7637776..839124d75 100644 --- a/loginserver/client_manager.h +++ b/loginserver/client_manager.h @@ -20,8 +20,7 @@ #include "../common/global_define.h" #include "../common/opcodemgr.h" -#include "../common/eq_stream_type.h" -#include "../common/eq_stream_factory.h" +#include "../common/net/eqstream.h" #include "client.h" #include @@ -71,9 +70,9 @@ private: list clients; OpcodeManager *titanium_ops; - EQStreamFactory *titanium_stream; + EQ::Net::EQStreamManager *titanium_stream; OpcodeManager *sod_ops; - EQStreamFactory *sod_stream; + EQ::Net::EQStreamManager *sod_stream; }; #endif diff --git a/loginserver/main.cpp b/loginserver/main.cpp index 128bdd3c7..4ddb7fbd4 100644 --- a/loginserver/main.cpp +++ b/loginserver/main.cpp @@ -18,7 +18,7 @@ #include "../common/global_define.h" #include "../common/types.h" #include "../common/opcodemgr.h" -#include "../common/eq_stream_factory.h" +#include "../common/event/event_loop.h" #include "../common/timer.h" #include "../common/platform.h" #include "../common/crash.h" @@ -29,7 +29,6 @@ #include #include -TimeoutManager timeout_manager; LoginServer server; EQEmuLogSys Log; bool run_server = true; @@ -199,8 +198,8 @@ int main() Timer::SetCurrentTime(); server.client_manager->Process(); server.server_manager->Process(); - timeout_manager.CheckTimeouts(); - Sleep(100); + EQ::EventLoop::Get().Process(); + Sleep(1); } Log.Out(Logs::General, Logs::Login_Server, "Server Shutdown."); diff --git a/loginserver/server_manager.h b/loginserver/server_manager.h index 6f9db9afa..6fb6c9758 100644 --- a/loginserver/server_manager.h +++ b/loginserver/server_manager.h @@ -19,7 +19,6 @@ #define EQEMU_SERVERMANAGER_H #include "../common/global_define.h" -#include "../common/eq_stream_factory.h" #include "../common/emu_tcp_connection.h" #include "../common/emu_tcp_server.h" #include "../common/servertalk.h" diff --git a/loginserver/world_server.h b/loginserver/world_server.h index b9a64ffe5..bceba4baa 100644 --- a/loginserver/world_server.h +++ b/loginserver/world_server.h @@ -19,7 +19,6 @@ #define EQEMU_WORLDSERVER_H #include "../common/global_define.h" -#include "../common/eq_stream_factory.h" #include "../common/emu_tcp_connection.h" #include "../common/emu_tcp_server.h" #include "../common/servertalk.h" diff --git a/queryserv/queryserv.cpp b/queryserv/queryserv.cpp index 4ce00ed4b..2e354fb20 100644 --- a/queryserv/queryserv.cpp +++ b/queryserv/queryserv.cpp @@ -20,7 +20,6 @@ #include "../common/global_define.h" #include "../common/eqemu_logsys.h" #include "../common/opcodemgr.h" -#include "../common/eq_stream_factory.h" #include "../common/rulesys.h" #include "../common/servertalk.h" #include "../common/platform.h" @@ -34,7 +33,6 @@ volatile bool RunLoops = true; -TimeoutManager timeout_manager; Database database; LFGuildManager lfguildmanager; std::string WorldShortName; @@ -117,8 +115,7 @@ int main() { worldserver->AsyncConnect(); } worldserver->Process(); - timeout_manager.CheckTimeouts(); - Sleep(100); + Sleep(1); } Log.CloseFileLogs(); } diff --git a/ucs/CMakeLists.txt b/ucs/CMakeLists.txt index 73969e92b..a1f785c4a 100644 --- a/ucs/CMakeLists.txt +++ b/ucs/CMakeLists.txt @@ -23,16 +23,11 @@ INSTALL(TARGETS ucs RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) ADD_DEFINITIONS(-DUCS) -TARGET_LINK_LIBRARIES(ucs common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY}) +TARGET_LINK_LIBRARIES(ucs common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY} libuv fmt) -IF(MSVC) - SET_TARGET_PROPERTIES(ucs PROPERTIES LINK_FLAGS_RELEASE "/OPT:REF /OPT:ICF") - TARGET_LINK_LIBRARIES(ucs "Ws2_32.lib") -ENDIF(MSVC) - -IF(MINGW) - TARGET_LINK_LIBRARIES(ucs "WS2_32") -ENDIF(MINGW) +IF(WIN32) + TARGET_LINK_LIBRARIES(ucs "ws2_32" "psapi" "iphlpapi" "userenv") +ENDIF(WIN32) IF(UNIX) TARGET_LINK_LIBRARIES(ucs "${CMAKE_DL_LIBS}") diff --git a/ucs/clientlist.cpp b/ucs/clientlist.cpp index bd4bdcb45..feb1c8992 100644 --- a/ucs/clientlist.cpp +++ b/ucs/clientlist.cpp @@ -25,7 +25,6 @@ #include "database.h" #include "chatchannel.h" -#include "../common/eq_stream_factory.h" #include "../common/emu_tcp_connection.h" #include "../common/emu_tcp_server.h" #include @@ -468,21 +467,22 @@ static void ProcessCommandIgnore(Client *c, std::string Ignoree) { } Clientlist::Clientlist(int ChatPort) { - - chatsf = new EQStreamFactory(ChatStream, ChatPort, 45000); + EQ::Net::EQStreamManagerOptions chat_opts(ChatPort, false, false); + chat_opts.opcode_size = 1; + chatsf = new EQ::Net::EQStreamManager(chat_opts); ChatOpMgr = new RegularOpcodeManager; if(!ChatOpMgr->LoadOpcodes("mail_opcodes.conf")) exit(1); - if (chatsf->Open()) - Log.Out(Logs::Detail, Logs::UCS_Server,"Client (UDP) Chat listener started on port %i.", ChatPort); - else { - Log.Out(Logs::Detail, Logs::UCS_Server,"Failed to start client (UDP) listener (port %-4i)", ChatPort); + chatsf->OnNewConnection([this](std::shared_ptr stream) { + Log.OutF(Logs::General, Logs::Login_Server, "New Client UDP connection from {0}:{1}", stream->RemoteEndpoint(), stream->GetRemotePort()); + stream->SetOpcodeManager(&ChatOpMgr); - exit(1); - } + auto c = new Client(stream); + ClientChatConnections.push_back(c); + }); } Client::Client(std::shared_ptr eqs) { @@ -574,21 +574,6 @@ void Clientlist::CheckForStaleConnections(Client *c) { void Clientlist::Process() { - std::shared_ptr eqs; - - while ((eqs = chatsf->Pop())) { - struct in_addr in; - in.s_addr = eqs->GetRemoteIP(); - - Log.Out(Logs::Detail, Logs::UCS_Server, "New Client UDP connection from %s:%d", inet_ntoa(in), - ntohs(eqs->GetRemotePort())); - - eqs->SetOpcodeManager(&ChatOpMgr); - - auto c = new Client(eqs); - ClientChatConnections.push_back(c); - } - auto it = ClientChatConnections.begin(); while (it != ClientChatConnections.end()) { (*it)->AccountUpdate(); @@ -614,7 +599,7 @@ void Clientlist::Process() switch (opcode) { case OP_MailLogin: { - char *PacketBuffer = (char *)app->pBuffer; + char *PacketBuffer = (char *)app->pBuffer + 1; char MailBox[64]; char Key[64]; char ConnectionTypeIndicator; @@ -668,7 +653,7 @@ void Clientlist::Process() } case OP_Mail: { - std::string CommandString = (const char *)app->pBuffer; + std::string CommandString = (const char *)app->pBuffer + 1; ProcessOPMailCommand((*it), CommandString); break; } diff --git a/ucs/clientlist.h b/ucs/clientlist.h index 6fa0d49da..9b72df51a 100644 --- a/ucs/clientlist.h +++ b/ucs/clientlist.h @@ -21,8 +21,7 @@ #define CHATSERVER_CLIENTLIST_H #include "../common/opcodemgr.h" -#include "../common/eq_stream_type.h" -#include "../common/eq_stream_factory.h" +#include "../common/net/eqstream.h" #include "../common/rulesys.h" #include "chatchannel.h" #include @@ -185,7 +184,7 @@ public: private: - EQStreamFactory *chatsf; + EQ::Net::EQStreamManager *chatsf; std::list ClientChatConnections; diff --git a/ucs/ucs.cpp b/ucs/ucs.cpp index 877ff0d0c..8e067b12a 100644 --- a/ucs/ucs.cpp +++ b/ucs/ucs.cpp @@ -21,11 +21,11 @@ #include "../common/global_define.h" #include "clientlist.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 "../common/event/event_loop.h" #include "database.h" #include "ucsconfig.h" #include "chatchannel.h" @@ -36,7 +36,6 @@ ChatChannelList *ChannelList; Clientlist *g_Clientlist; EQEmuLogSys Log; -TimeoutManager timeout_manager; Database database; WorldServer *worldserver = nullptr; @@ -158,9 +157,9 @@ int main() { } worldserver->Process(); - timeout_manager.CheckTimeouts(); + EQ::EventLoop::Get().Process(); - Sleep(100); + Sleep(1); } ChannelList->RemoveAllChannels(); diff --git a/world/client.h b/world/client.h index 391a20c1d..88dc27c57 100644 --- a/world/client.h +++ b/world/client.h @@ -20,7 +20,6 @@ #include -//#include "../common/eq_stream.h" #include "../common/linked_list.h" #include "../common/timer.h" //#include "zoneserver.h" diff --git a/world/net.cpp b/world/net.cpp index 245d09274..b864c1363 100644 --- a/world/net.cpp +++ b/world/net.cpp @@ -28,16 +28,12 @@ #include "../common/eqemu_logsys.h" #include "../common/queue.h" #include "../common/timer.h" -#include "../common/eq_stream_factory.h" #include "../common/eq_packet.h" #include "../common/seperator.h" #include "../common/version.h" #include "../common/eqtime.h" -#include "../common/timeoutmgr.h" - #include "../common/event/event_loop.h" #include "../common/net/eqstream.h" - #include "../common/opcodemgr.h" #include "../common/guilds.h" #include "../common/eq_stream_ident.h" @@ -90,7 +86,6 @@ #include "ucs.h" #include "queryserv.h" -TimeoutManager timeout_manager; EmuTCPServer tcps; ClientList client_list; GroupLFPList LFPGroupList; @@ -395,7 +390,7 @@ int main(int argc, char** argv) { return 1; } - EQ::Net::EQStreamManagerOptions opts(9000, false, true); + EQ::Net::EQStreamManagerOptions opts(9000, false, false); EQ::Net::EQStreamManager eqsm(opts); //register all the patches we have avaliable with the stream identifier. @@ -492,8 +487,6 @@ int main(int argc, char** argv) { Log.Out(Logs::Detail, Logs::World_Server, "EQTime successfully saved."); } - //check for timeouts in other threads - timeout_manager.CheckTimeouts(); loginserverlist.Process(); console_list.Process(); zoneserver_list.Process(); diff --git a/zone/net.cpp b/zone/net.cpp index a02713457..72b87811c 100644 --- a/zone/net.cpp +++ b/zone/net.cpp @@ -23,8 +23,6 @@ #include "../common/features.h" #include "../common/queue.h" #include "../common/timer.h" -#include "../common/eq_stream.h" -#include "../common/eq_stream_factory.h" #include "../common/eq_packet_structs.h" #include "../common/mutex.h" #include "../common/version.h" @@ -95,7 +93,6 @@ volatile bool RunLoops = true; extern volatile bool is_zone_loaded; -TimeoutManager timeout_manager; NetConnection net; EntityList entity_list; WorldServer worldserver; @@ -448,7 +445,7 @@ int main(int argc, char** argv) { if (!eqsf_open && Config->ZonePort != 0) { Log.Out(Logs::General, Logs::Zone_Server, "Starting EQ Network server on port %d", Config->ZonePort); - EQ::Net::EQStreamManagerOptions opts(Config->ZonePort, false, true); + EQ::Net::EQStreamManagerOptions opts(Config->ZonePort, false, false); eqsm.reset(new EQ::Net::EQStreamManager(opts)); eqsf_open = true; @@ -479,9 +476,6 @@ int main(int argc, char** argv) { zoneupdate_timer.Trigger(); } - //check for timeouts in other threads - timeout_manager.CheckTimeouts(); - if (worldserver.Connected()) { worldwasconnected = true; }