diff --git a/common/eq_stream_ident.cpp b/common/eq_stream_ident.cpp index fa7435910..deebd9aee 100644 --- a/common/eq_stream_ident.cpp +++ b/common/eq_stream_ident.cpp @@ -144,7 +144,7 @@ void EQStreamIdentifier::Process() { } //end foreach stream } -void EQStreamIdentifier::AddStream(std::shared_ptr &eqs) { +void EQStreamIdentifier::AddStream(std::shared_ptr eqs) { m_streams.push_back(Record(eqs)); eqs = nullptr; } diff --git a/common/eq_stream_ident.h b/common/eq_stream_ident.h index e26857292..4b9bfac31 100644 --- a/common/eq_stream_ident.h +++ b/common/eq_stream_ident.h @@ -22,7 +22,7 @@ public: //main processing interface void Process(); - void AddStream(std::shared_ptr &eqs); + void AddStream(std::shared_ptr eqs); EQStreamInterface *PopIdentified(); protected: diff --git a/common/net/daybreak_connection.cpp b/common/net/daybreak_connection.cpp index 7790edd12..6d87dc9cb 100644 --- a/common/net/daybreak_connection.cpp +++ b/common/net/daybreak_connection.cpp @@ -900,7 +900,8 @@ void EQ::Net::DaybreakConnection::Decompress(Packet &p, size_t offset, size_t le new_length = (uint32_t)length - 1; } else { - return; + memcpy(new_buffer, buffer, length); + new_length = length; } p.Resize(offset); diff --git a/common/net/eqstream.cpp b/common/net/eqstream.cpp index e56cba4b4..dee97df01 100644 --- a/common/net/eqstream.cpp +++ b/common/net/eqstream.cpp @@ -120,7 +120,7 @@ EQApplicationPacket *EQ::Net::EQStream::PopPacket() { } EmuOpcode emu_op = (*m_opcode_manager)->EQToEmu(opcode); - EQApplicationPacket *ret = new EQApplicationPacket(emu_op, (unsigned char*)p->Data(), p->Length() - m_owner->m_options.opcode_size); + EQApplicationPacket *ret = new EQApplicationPacket(emu_op, (unsigned char*)p->Data() + m_owner->m_options.opcode_size, p->Length() - m_owner->m_options.opcode_size); m_packet_queue.pop_front(); return ret; } diff --git a/common/net/eqstream.h b/common/net/eqstream.h index a9838549a..04f523671 100644 --- a/common/net/eqstream.h +++ b/common/net/eqstream.h @@ -75,8 +75,7 @@ namespace EQ virtual void ReleaseFromUse() { }; virtual void RemoveData() { }; virtual uint32 GetRemoteIP() const; - //the code is dumb and assumes this is in network order... - virtual uint16 GetRemotePort() const { return EQ::Net::HostToNetwork(m_connection->RemotePort()); } + virtual uint16 GetRemotePort() const { return m_connection->RemotePort(); } virtual bool CheckState(EQStreamState state); virtual std::string Describe() const { return "Direct EQStream"; } virtual void SetActive(bool val) { } diff --git a/world/CMakeLists.txt b/world/CMakeLists.txt index cccfa74cc..775648674 100644 --- a/world/CMakeLists.txt +++ b/world/CMakeLists.txt @@ -68,16 +68,11 @@ INSTALL(TARGETS world RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) ADD_DEFINITIONS(-DWORLD) -TARGET_LINK_LIBRARIES(world common ${PERL_LIBRARY} debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY}) +TARGET_LINK_LIBRARIES(world common ${PERL_LIBRARY} debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY} libuv fmt) -IF(MSVC) - SET_TARGET_PROPERTIES(world PROPERTIES LINK_FLAGS_RELEASE "/OPT:REF /OPT:ICF") - TARGET_LINK_LIBRARIES(world "Ws2_32.lib") -ENDIF(MSVC) - -IF(MINGW) - TARGET_LINK_LIBRARIES(world "WS2_32") -ENDIF(MINGW) +IF(WIN32) + TARGET_LINK_LIBRARIES(world "ws2_32" "psapi" "iphlpapi" "userenv") +ENDIF(WIN32) IF(UNIX) TARGET_LINK_LIBRARIES(world "${CMAKE_DL_LIBS}") diff --git a/world/net.cpp b/world/net.cpp index 6354a6467..a723b2aeb 100644 --- a/world/net.cpp +++ b/world/net.cpp @@ -35,6 +35,9 @@ #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" @@ -88,7 +91,6 @@ #include "queryserv.h" TimeoutManager timeout_manager; -EQStreamFactory eqsf(WorldStream,9000); EmuTCPServer tcps; ClientList client_list; GroupLFPList LFPGroupList; @@ -395,12 +397,12 @@ int main(int argc, char** argv) { Log.Out(Logs::General, Logs::World_Server," %s",errbuf); return 1; } - if (eqsf.Open()) { - Log.Out(Logs::General, Logs::World_Server,"Client (UDP) listener started."); - } else { - Log.Out(Logs::General, Logs::World_Server,"Failed to start client (UDP) listener (port 9000)"); - return 1; - } + + EQ::Net::EQStreamManagerOptions opts(true, false); + opts.daybreak_options.port = 9000; + opts.opcode_size = 2; + + EQ::Net::EQStreamManager eqsm(opts); //register all the patches we have avaliable with the stream identifier. EQStreamIdentifier stream_identifier; @@ -416,20 +418,13 @@ int main(int argc, char** argv) { EmuTCPConnection* tcpc; EQStreamInterface *eqsi; + eqsm.OnNewConnection([&stream_identifier](std::shared_ptr stream) { + stream_identifier.AddStream(stream); + Log.OutF(Logs::Detail, Logs::World_Server, "New connection from IP {0}:{1}", stream->RemoteEndpoint(), ntohs(stream->GetRemotePort())); + }); + while(RunLoops) { Timer::SetCurrentTime(); - - //check the factory for any new incoming streams. - while ((eqs = eqsf.Pop())) { - //pull the stream out of the factory and give it to the stream identifier - //which will figure out what patch they are running, and set up the dynamic - //structures and opcodes for that patch. - struct in_addr in; - in.s_addr = eqs->GetRemoteIP(); - Log.Out(Logs::Detail, Logs::World_Server, "New connection from IP %s:%d", inet_ntoa(in),ntohs(eqs->GetRemotePort())); - stream_identifier.AddStream(eqs); //takes the stream - } - eqs = nullptr; //give the stream identifier a chance to do its work.... @@ -528,11 +523,9 @@ int main(int argc, char** argv) { } } - if (numclients == 0) { - Sleep(50); - continue; - } - Sleep(20); + + EQ::EventLoop::Get().Process(); + Sleep(1); } Log.Out(Logs::General, Logs::World_Server, "World main loop completed."); Log.Out(Logs::General, Logs::World_Server, "Shutting down console connections (if any)."); @@ -541,8 +534,6 @@ int main(int argc, char** argv) { zoneserver_list.KillAll(); Log.Out(Logs::General, Logs::World_Server, "Zone (TCP) listener stopped."); tcps.Close(); - Log.Out(Logs::General, Logs::World_Server, "Client (UDP) listener stopped."); - eqsf.Close(); Log.Out(Logs::General, Logs::World_Server, "Signaling HTTP service to stop..."); http_server.Stop(); Log.CloseFileLogs();