mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-14 11:31:30 +00:00
Remove logging from daybreak network code to make it thread safe, there is a threadsafe replacement if you care (there's only like 4 logs in the code anyway); made event loop thread local so we can have one for each thread
This commit is contained in:
parent
9dc83d389e
commit
cbfd02b9ff
@ -9,7 +9,7 @@ namespace EQ
|
||||
{
|
||||
public:
|
||||
static EventLoop &Get() {
|
||||
static EventLoop inst;
|
||||
static thread_local EventLoop inst;
|
||||
return inst;
|
||||
}
|
||||
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
#include "daybreak_connection.h"
|
||||
#include "../event/event_loop.h"
|
||||
#include "../event/task.h"
|
||||
#include "../eqemu_logsys.h"
|
||||
#include "../eqemu_logsys_fmt.h"
|
||||
#include "../data_verification.h"
|
||||
#include "crc32.h"
|
||||
#include <zlib.h>
|
||||
#include <fmt/format.h>
|
||||
#include <sstream>
|
||||
|
||||
EQ::Net::DaybreakConnectionManager::DaybreakConnectionManager()
|
||||
@ -211,7 +210,9 @@ void EQ::Net::DaybreakConnectionManager::ProcessPacket(const std::string &endpoi
|
||||
}
|
||||
|
||||
if (size < DaybreakHeader::size()) {
|
||||
LogF(Logs::Detail, Logs::Netcode, "Packet of size {0} which is less than {1}", size, DaybreakHeader::size());
|
||||
if (m_on_error_message) {
|
||||
m_on_error_message(fmt::format("Packet of size {0} which is less than {1}", size, DaybreakHeader::size()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -241,7 +242,9 @@ void EQ::Net::DaybreakConnectionManager::ProcessPacket(const std::string &endpoi
|
||||
}
|
||||
}
|
||||
catch (std::exception &ex) {
|
||||
LogF(Logs::Detail, Logs::Netcode, "Error processing packet: {0}", ex.what());
|
||||
if (m_on_error_message) {
|
||||
m_on_error_message(fmt::format("Error processing packet: {0}", ex.what()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -396,7 +399,9 @@ void EQ::Net::DaybreakConnection::Process()
|
||||
ProcessQueue();
|
||||
}
|
||||
catch (std::exception ex) {
|
||||
LogF(Logs::Detail, Logs::Netcode, "Error processing connection: {0}", ex.what());
|
||||
if (m_owner->m_on_error_message) {
|
||||
m_owner->m_on_error_message(fmt::format("Error processing connection: {0}", ex.what()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -417,7 +422,9 @@ void EQ::Net::DaybreakConnection::ProcessPacket(Packet &p)
|
||||
|
||||
if (PacketCanBeEncoded(p)) {
|
||||
if (!ValidateCRC(p)) {
|
||||
LogF(Logs::Detail, Logs::Netcode, "Tossed packet that failed CRC of type {0:#x}", p.Length() >= 2 ? p.GetInt8(1) : 0);
|
||||
if (m_owner->m_on_error_message) {
|
||||
m_owner->m_on_error_message(fmt::format("Tossed packet that failed CRC of type {0:#x}", p.Length() >= 2 ? p.GetInt8(1) : 0));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -798,7 +805,9 @@ void EQ::Net::DaybreakConnection::ProcessDecodedPacket(const Packet &p)
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LogF(Logs::Detail, Logs::Netcode, "Unhandled opcode {0:#x}", p.GetInt8(1));
|
||||
if (m_owner->m_on_error_message) {
|
||||
m_owner->m_on_error_message(fmt::format("Unhandled opcode {0:#x}", p.GetInt8(1)));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -291,6 +291,7 @@ namespace EQ
|
||||
void OnNewConnection(std::function<void(std::shared_ptr<DaybreakConnection>)> func) { m_on_new_connection = func; }
|
||||
void OnConnectionStateChange(std::function<void(std::shared_ptr<DaybreakConnection>, DbProtocolStatus, DbProtocolStatus)> func) { m_on_connection_state_change = func; }
|
||||
void OnPacketRecv(std::function<void(std::shared_ptr<DaybreakConnection>, const Packet &)> func) { m_on_packet_recv = func; }
|
||||
void OnErrorMessage(std::function<void(const std::string&)> func) { m_on_error_message = func; }
|
||||
|
||||
DaybreakConnectionManagerOptions& GetOptions() { return m_options; }
|
||||
private:
|
||||
@ -305,6 +306,7 @@ namespace EQ
|
||||
std::function<void(std::shared_ptr<DaybreakConnection>)> m_on_new_connection;
|
||||
std::function<void(std::shared_ptr<DaybreakConnection>, DbProtocolStatus, DbProtocolStatus)> m_on_connection_state_change;
|
||||
std::function<void(std::shared_ptr<DaybreakConnection>, const Packet&)> m_on_packet_recv;
|
||||
std::function<void(const std::string&)> m_on_error_message;
|
||||
std::map<std::pair<std::string, int>, std::shared_ptr<DaybreakConnection>> m_connections;
|
||||
|
||||
void ProcessPacket(const std::string &endpoint, int port, const char *data, size_t size);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user