mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-12 09:31:30 +00:00
Add crazy logging to daybreak class
This commit is contained in:
parent
d8d77d88f2
commit
d774de3a1b
@ -65,6 +65,13 @@ void EQ::Net::DaybreakConnectionManager::Attach(uv_loop_t *loop)
|
|||||||
char endpoint[16];
|
char endpoint[16];
|
||||||
uv_ip4_name((const sockaddr_in*)addr, endpoint, 16);
|
uv_ip4_name((const sockaddr_in*)addr, endpoint, 16);
|
||||||
auto port = ntohs(((const sockaddr_in*)addr)->sin_port);
|
auto port = ntohs(((const sockaddr_in*)addr)->sin_port);
|
||||||
|
|
||||||
|
//raw data in
|
||||||
|
if(nread > 0) {
|
||||||
|
EQ::Net::StaticPacket wire((void*)buf->base, (uint64_t)nread);
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Raw Packet in\n{0}", wire.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
c->ProcessPacket(endpoint, port, buf->base, nread);
|
c->ProcessPacket(endpoint, port, buf->base, nread);
|
||||||
delete[] buf->base;
|
delete[] buf->base;
|
||||||
});
|
});
|
||||||
@ -176,9 +183,10 @@ void EQ::Net::DaybreakConnectionManager::ProcessResend()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EQ::Net::DaybreakConnectionManager::ProcessPacket(const std::string &endpoint, int port, const char *data, size_t size)
|
void EQ::Net::DaybreakConnectionManager::ProcessPacket(const std::string &endpoint, int port, const char *data, uint64_t size)
|
||||||
{
|
{
|
||||||
if (m_options.simulated_in_packet_loss && m_options.simulated_in_packet_loss >= m_rand.Int(0, 100)) {
|
if (m_options.simulated_in_packet_loss && m_options.simulated_in_packet_loss >= m_rand.Int(0, 100)) {
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Dropped a packet from {0}:{1} because of simulated packet loss", endpoint, port);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,6 +216,7 @@ void EQ::Net::DaybreakConnectionManager::ProcessPacket(const std::string &endpoi
|
|||||||
connection->ProcessPacket(p);
|
connection->ProcessPacket(p);
|
||||||
}
|
}
|
||||||
else if(data[1] != OP_OutOfSession) {
|
else if(data[1] != OP_OutOfSession) {
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Recv {0:#x} from {1}:{2} but there is no identified connection from this address.", data[1], endpoint, port);
|
||||||
SendDisconnect(endpoint, port);
|
SendDisconnect(endpoint, port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -243,10 +252,13 @@ void EQ::Net::DaybreakConnectionManager::SendDisconnect(const std::string &addr,
|
|||||||
uv_ip4_addr(addr.c_str(), port, &send_addr);
|
uv_ip4_addr(addr.c_str(), port, &send_addr);
|
||||||
uv_buf_t send_buffers[1];
|
uv_buf_t send_buffers[1];
|
||||||
|
|
||||||
char *data = new char[out.Length()];
|
char *data = new char[(size_t)out.Length()];
|
||||||
memcpy(data, out.Data(), out.Length());
|
memcpy(data, out.Data(), (size_t)out.Length());
|
||||||
send_buffers[0] = uv_buf_init(data, out.Length());
|
send_buffers[0] = uv_buf_init(data, (unsigned int)out.Length());
|
||||||
send_req->data = send_buffers[0].base;
|
send_req->data = send_buffers[0].base;
|
||||||
|
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Sending disconnect to {0}:{1}", addr, port);
|
||||||
|
|
||||||
int ret = uv_udp_send(send_req, &m_socket, send_buffers, 1, (sockaddr*)&send_addr,
|
int ret = uv_udp_send(send_req, &m_socket, send_buffers, 1, (sockaddr*)&send_addr,
|
||||||
[](uv_udp_send_t* req, int status) {
|
[](uv_udp_send_t* req, int status) {
|
||||||
delete[] (char*)req->data;
|
delete[] (char*)req->data;
|
||||||
@ -265,7 +277,7 @@ EQ::Net::DaybreakConnection::DaybreakConnection(DaybreakConnectionManager *owner
|
|||||||
m_port = port;
|
m_port = port;
|
||||||
m_connect_code = NetworkToHost(connect.connect_code);
|
m_connect_code = NetworkToHost(connect.connect_code);
|
||||||
m_encode_key = m_owner->m_rand.Int(std::numeric_limits<uint32_t>::min(), std::numeric_limits<uint32_t>::max());
|
m_encode_key = m_owner->m_rand.Int(std::numeric_limits<uint32_t>::min(), std::numeric_limits<uint32_t>::max());
|
||||||
m_max_packet_size = (uint32_t)std::min(owner->m_options.max_packet_size, (size_t)NetworkToHost(connect.max_packet_size));
|
m_max_packet_size = (uint32_t)std::min((uint32_t)owner->m_options.max_packet_size, (uint32_t)NetworkToHost(connect.max_packet_size));
|
||||||
m_crc_bytes = (uint32_t)owner->m_options.crc_length;
|
m_crc_bytes = (uint32_t)owner->m_options.crc_length;
|
||||||
m_encode_passes[0] = owner->m_options.encode_passes[0];
|
m_encode_passes[0] = owner->m_options.encode_passes[0];
|
||||||
m_encode_passes[1] = owner->m_options.encode_passes[1];
|
m_encode_passes[1] = owner->m_options.encode_passes[1];
|
||||||
@ -277,6 +289,7 @@ EQ::Net::DaybreakConnection::DaybreakConnection(DaybreakConnectionManager *owner
|
|||||||
m_combined[0] = 0;
|
m_combined[0] = 0;
|
||||||
m_combined[1] = OP_Combined;
|
m_combined[1] = OP_Combined;
|
||||||
m_last_session_stats = Clock::now();
|
m_last_session_stats = Clock::now();
|
||||||
|
m_last_stats = Clock::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
//new connection made as client
|
//new connection made as client
|
||||||
@ -300,6 +313,7 @@ EQ::Net::DaybreakConnection::DaybreakConnection(DaybreakConnectionManager *owner
|
|||||||
m_combined[0] = 0;
|
m_combined[0] = 0;
|
||||||
m_combined[1] = OP_Combined;
|
m_combined[1] = OP_Combined;
|
||||||
m_last_session_stats = Clock::now();
|
m_last_session_stats = Clock::now();
|
||||||
|
m_last_stats = Clock::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
EQ::Net::DaybreakConnection::~DaybreakConnection()
|
EQ::Net::DaybreakConnection::~DaybreakConnection()
|
||||||
@ -308,6 +322,7 @@ EQ::Net::DaybreakConnection::~DaybreakConnection()
|
|||||||
|
|
||||||
void EQ::Net::DaybreakConnection::Close()
|
void EQ::Net::DaybreakConnection::Close()
|
||||||
{
|
{
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Closing daybreak connection, status was {0}", (int)m_status);
|
||||||
if (m_status == StatusConnected) {
|
if (m_status == StatusConnected) {
|
||||||
DaybreakDisconnect disconnect;
|
DaybreakDisconnect disconnect;
|
||||||
disconnect.zero = 0;
|
disconnect.zero = 0;
|
||||||
@ -354,20 +369,20 @@ void EQ::Net::DaybreakConnection::ResetStats()
|
|||||||
void EQ::Net::DaybreakConnection::Process()
|
void EQ::Net::DaybreakConnection::Process()
|
||||||
{
|
{
|
||||||
try {
|
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;
|
m_resend_delay = (uint64_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) {
|
if (m_resend_delay > 1000) {
|
||||||
m_resend_delay = 1000;
|
m_resend_delay = 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto now = Clock::now();
|
auto now = Clock::now();
|
||||||
auto time_since_hold = (size_t)std::chrono::duration_cast<std::chrono::milliseconds>(now - m_hold_time).count();
|
auto time_since_hold = (uint64_t)std::chrono::duration_cast<std::chrono::milliseconds>(now - m_hold_time).count();
|
||||||
if (time_since_hold >= m_owner->m_options.hold_length_ms) {
|
if (time_since_hold >= m_owner->m_options.hold_length_ms) {
|
||||||
FlushBuffer();
|
FlushBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcessQueue();
|
ProcessQueue();
|
||||||
|
|
||||||
auto time_since_stats = (size_t)std::chrono::duration_cast<std::chrono::milliseconds>(now - m_last_stats).count();
|
auto time_since_stats = (uint64_t)std::chrono::duration_cast<std::chrono::milliseconds>(now - m_last_stats).count();
|
||||||
if (m_owner->m_options.stats_delay_ms > 0 && time_since_stats >= m_owner->m_options.stats_delay_ms) {
|
if (m_owner->m_options.stats_delay_ms > 0 && time_since_stats >= m_owner->m_options.stats_delay_ms) {
|
||||||
SendStatSync();
|
SendStatSync();
|
||||||
m_last_stats = now;
|
m_last_stats = now;
|
||||||
@ -385,6 +400,7 @@ void EQ::Net::DaybreakConnection::ProcessPacket(Packet &p)
|
|||||||
m_stats.recv_bytes += p.Length();
|
m_stats.recv_bytes += p.Length();
|
||||||
|
|
||||||
if (p.Length() < 1) {
|
if (p.Length() < 1) {
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Error parsing packet, length was < 1");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -395,6 +411,7 @@ void EQ::Net::DaybreakConnection::ProcessPacket(Packet &p)
|
|||||||
|
|
||||||
auto opcode = p.GetInt8(1);
|
auto opcode = p.GetInt8(1);
|
||||||
if (opcode == OP_KeepAlive || opcode == OP_OutboundPing) {
|
if (opcode == OP_KeepAlive || opcode == OP_OutboundPing) {
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Discard packet of type {0:#x}", opcode);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -474,18 +491,24 @@ void EQ::Net::DaybreakConnection::ProcessDecodedPacket(const Packet &p)
|
|||||||
{
|
{
|
||||||
if (p.GetInt8(0) == 0) {
|
if (p.GetInt8(0) == 0) {
|
||||||
if (p.Length() < 2) {
|
if (p.Length() < 2) {
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Failed to process decoded packet, length < 2\n{0}", p.ToString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Processing decoded packet of type {0:#x}", p.GetInt8(1));
|
||||||
switch (p.GetInt8(1)) {
|
switch (p.GetInt8(1)) {
|
||||||
case OP_Combined: {
|
case OP_Combined: {
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Processing OP_Combined of length {0}", p.Length());
|
||||||
char *current = (char*)p.Data() + 2;
|
char *current = (char*)p.Data() + 2;
|
||||||
char *end = (char*)p.Data() + p.Length();
|
char *end = (char*)p.Data() + p.Length();
|
||||||
while (current < end) {
|
while (current < end) {
|
||||||
uint8_t subpacket_length = *(uint8_t*)current;
|
uint8_t subpacket_length = *(uint8_t*)current;
|
||||||
current += 1;
|
current += 1;
|
||||||
|
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Subpacket length {0}", subpacket_length);
|
||||||
|
|
||||||
if (end < current + subpacket_length) {
|
if (end < current + subpacket_length) {
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Subpacket length out of range, bailing");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -497,6 +520,7 @@ void EQ::Net::DaybreakConnection::ProcessDecodedPacket(const Packet &p)
|
|||||||
|
|
||||||
case OP_AppCombined:
|
case OP_AppCombined:
|
||||||
{
|
{
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Processing OP_AppCombined of length {0}", p.Length());
|
||||||
uint8_t *current = (uint8_t*)p.Data() + 2;
|
uint8_t *current = (uint8_t*)p.Data() + 2;
|
||||||
uint8_t *end = (uint8_t*)p.Data() + p.Length();
|
uint8_t *end = (uint8_t*)p.Data() + p.Length();
|
||||||
|
|
||||||
@ -505,11 +529,13 @@ void EQ::Net::DaybreakConnection::ProcessDecodedPacket(const Packet &p)
|
|||||||
if (*current == 0xFF)
|
if (*current == 0xFF)
|
||||||
{
|
{
|
||||||
if (end < current + 3) {
|
if (end < current + 3) {
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Error in OP_AppCombined, end < current + 3");
|
||||||
throw std::out_of_range("Error in OP_AppCombined, end < current + 3");
|
throw std::out_of_range("Error in OP_AppCombined, end < current + 3");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*(current + 1) == 0xFF && *(current + 2) == 0xFF) {
|
if (*(current + 1) == 0xFF && *(current + 2) == 0xFF) {
|
||||||
if (end < current + 7) {
|
if (end < current + 7) {
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Error in OP_AppCombined, end < current + 7");
|
||||||
throw std::out_of_range("Error in OP_AppCombined, end < current + 7");
|
throw std::out_of_range("Error in OP_AppCombined, end < current + 7");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -534,6 +560,7 @@ void EQ::Net::DaybreakConnection::ProcessDecodedPacket(const Packet &p)
|
|||||||
current += 1;
|
current += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Processing subpacket of length {0}", subpacket_length);
|
||||||
ProcessDecodedPacket(StaticPacket(current, subpacket_length));
|
ProcessDecodedPacket(StaticPacket(current, subpacket_length));
|
||||||
current += subpacket_length;
|
current += subpacket_length;
|
||||||
}
|
}
|
||||||
@ -541,6 +568,7 @@ void EQ::Net::DaybreakConnection::ProcessDecodedPacket(const Packet &p)
|
|||||||
|
|
||||||
case OP_SessionRequest:
|
case OP_SessionRequest:
|
||||||
{
|
{
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "OP_SessionRequest recieved current status is {0}", m_status);
|
||||||
if (m_status == StatusConnected) {
|
if (m_status == StatusConnected) {
|
||||||
auto request = p.GetSerialize<DaybreakConnect>(0);
|
auto request = p.GetSerialize<DaybreakConnect>(0);
|
||||||
|
|
||||||
@ -567,6 +595,7 @@ void EQ::Net::DaybreakConnection::ProcessDecodedPacket(const Packet &p)
|
|||||||
|
|
||||||
case OP_SessionResponse:
|
case OP_SessionResponse:
|
||||||
{
|
{
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "OP_SessionResponse recieved current status is {0}", m_status);
|
||||||
if (m_status == StatusConnecting) {
|
if (m_status == StatusConnecting) {
|
||||||
auto reply = p.GetSerialize<DaybreakConnectReply>(0);
|
auto reply = p.GetSerialize<DaybreakConnectReply>(0);
|
||||||
|
|
||||||
@ -592,15 +621,20 @@ void EQ::Net::DaybreakConnection::ProcessDecodedPacket(const Packet &p)
|
|||||||
auto stream_id = header.opcode - OP_Packet;
|
auto stream_id = header.opcode - OP_Packet;
|
||||||
auto stream = &m_streams[stream_id];
|
auto stream = &m_streams[stream_id];
|
||||||
|
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Recv Reliable Packet for stream {0} with sequence {1}", stream_id, sequence);
|
||||||
|
|
||||||
auto order = CompareSequence(stream->sequence_in, sequence);
|
auto order = CompareSequence(stream->sequence_in, sequence);
|
||||||
if (order == SequenceFuture) {
|
if (order == SequenceFuture) {
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Reliable packet resolved to be a future packet, adding to the packet queue");
|
||||||
SendOutOfOrderAck(stream_id, sequence);
|
SendOutOfOrderAck(stream_id, sequence);
|
||||||
AddToQueue(stream_id, sequence, p);
|
AddToQueue(stream_id, sequence, p);
|
||||||
}
|
}
|
||||||
else if (order == SequencePast) {
|
else if (order == SequencePast) {
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Reliable packet resolved to be a past packet, sending an ack");
|
||||||
SendAck(stream_id, stream->sequence_in - 1);
|
SendAck(stream_id, stream->sequence_in - 1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Reliable packet is the one we want, removing it from queue and processing it.");
|
||||||
RemoveFromQueue(stream_id, sequence);
|
RemoveFromQueue(stream_id, sequence);
|
||||||
SendAck(stream_id, stream->sequence_in);
|
SendAck(stream_id, stream->sequence_in);
|
||||||
stream->sequence_in++;
|
stream->sequence_in++;
|
||||||
@ -621,16 +655,21 @@ void EQ::Net::DaybreakConnection::ProcessDecodedPacket(const Packet &p)
|
|||||||
auto stream_id = header.opcode - OP_Fragment;
|
auto stream_id = header.opcode - OP_Fragment;
|
||||||
auto stream = &m_streams[stream_id];
|
auto stream = &m_streams[stream_id];
|
||||||
|
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Recv Reliable Fragment Packet for stream {0} with sequence {1}", stream_id, sequence);
|
||||||
|
|
||||||
auto order = CompareSequence(stream->sequence_in, sequence);
|
auto order = CompareSequence(stream->sequence_in, sequence);
|
||||||
|
|
||||||
if (order == SequenceFuture) {
|
if (order == SequenceFuture) {
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Reliable fragment packet resolved to be a future packet, adding to the packet queue");
|
||||||
SendOutOfOrderAck(stream_id, sequence);
|
SendOutOfOrderAck(stream_id, sequence);
|
||||||
AddToQueue(stream_id, sequence, p);
|
AddToQueue(stream_id, sequence, p);
|
||||||
}
|
}
|
||||||
else if (order == SequencePast) {
|
else if (order == SequencePast) {
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Reliable fragment packet resolved to be a past packet, sending an ack");
|
||||||
SendAck(stream_id, stream->sequence_in - 1);
|
SendAck(stream_id, stream->sequence_in - 1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Reliable fragment packet is the one we want, removing it from queue and processing it.");
|
||||||
RemoveFromQueue(stream_id, sequence);
|
RemoveFromQueue(stream_id, sequence);
|
||||||
SendAck(stream_id, stream->sequence_in);
|
SendAck(stream_id, stream->sequence_in);
|
||||||
stream->sequence_in++;
|
stream->sequence_in++;
|
||||||
@ -645,6 +684,8 @@ void EQ::Net::DaybreakConnection::ProcessDecodedPacket(const Packet &p)
|
|||||||
(char*)p.Data() + DaybreakReliableFragmentHeader::size(), p.Length() - DaybreakReliableFragmentHeader::size());
|
(char*)p.Data() + DaybreakReliableFragmentHeader::size(), p.Length() - DaybreakReliableFragmentHeader::size());
|
||||||
|
|
||||||
stream->fragment_current_bytes += (uint32_t)(p.Length() - DaybreakReliableFragmentHeader::size());
|
stream->fragment_current_bytes += (uint32_t)(p.Length() - DaybreakReliableFragmentHeader::size());
|
||||||
|
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Fragment packet created {0}/{1} bytes", stream->fragment_current_bytes, stream->fragment_total_bytes);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
stream->fragment_packet.PutData(
|
stream->fragment_packet.PutData(
|
||||||
@ -659,6 +700,8 @@ void EQ::Net::DaybreakConnection::ProcessDecodedPacket(const Packet &p)
|
|||||||
stream->fragment_total_bytes = 0;
|
stream->fragment_total_bytes = 0;
|
||||||
stream->fragment_current_bytes = 0;
|
stream->fragment_current_bytes = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Fragment packet accumulated {0}/{1} bytes", stream->fragment_current_bytes, stream->fragment_total_bytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -673,6 +716,8 @@ void EQ::Net::DaybreakConnection::ProcessDecodedPacket(const Packet &p)
|
|||||||
auto header = p.GetSerialize<DaybreakReliableHeader>(0);
|
auto header = p.GetSerialize<DaybreakReliableHeader>(0);
|
||||||
auto sequence = NetworkToHost(header.sequence);
|
auto sequence = NetworkToHost(header.sequence);
|
||||||
auto stream_id = header.opcode - OP_Ack;
|
auto stream_id = header.opcode - OP_Ack;
|
||||||
|
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Ack recv for stream {0} and sequence {1}", stream_id, sequence);
|
||||||
Ack(stream_id, sequence);
|
Ack(stream_id, sequence);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -685,12 +730,15 @@ void EQ::Net::DaybreakConnection::ProcessDecodedPacket(const Packet &p)
|
|||||||
auto header = p.GetSerialize<DaybreakReliableHeader>(0);
|
auto header = p.GetSerialize<DaybreakReliableHeader>(0);
|
||||||
auto sequence = NetworkToHost(header.sequence);
|
auto sequence = NetworkToHost(header.sequence);
|
||||||
auto stream_id = header.opcode - OP_OutOfOrderAck;
|
auto stream_id = header.opcode - OP_OutOfOrderAck;
|
||||||
|
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Out of Order Ack recv for stream {0} and sequence {1}", stream_id, sequence);
|
||||||
OutOfOrderAck(stream_id, sequence);
|
OutOfOrderAck(stream_id, sequence);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case OP_SessionDisconnect:
|
case OP_SessionDisconnect:
|
||||||
{
|
{
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "OP_SessionDisconnect recieved current status is {0}", m_status);
|
||||||
if (m_status == StatusConnected || m_status == StatusDisconnecting) {
|
if (m_status == StatusConnected || m_status == StatusDisconnecting) {
|
||||||
DaybreakDisconnect disconnect;
|
DaybreakDisconnect disconnect;
|
||||||
disconnect.zero = 0;
|
disconnect.zero = 0;
|
||||||
@ -707,6 +755,7 @@ void EQ::Net::DaybreakConnection::ProcessDecodedPacket(const Packet &p)
|
|||||||
|
|
||||||
case OP_Padding:
|
case OP_Padding:
|
||||||
{
|
{
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "OP_Padding recv, processing packet");
|
||||||
auto self = m_self.lock();
|
auto self = m_self.lock();
|
||||||
if (m_owner->m_on_packet_recv && self) {
|
if (m_owner->m_on_packet_recv && self) {
|
||||||
m_owner->m_on_packet_recv(self, StaticPacket((char*)p.Data() + 1, p.Length() - 1));
|
m_owner->m_on_packet_recv(self, StaticPacket((char*)p.Data() + 1, p.Length() - 1));
|
||||||
@ -715,13 +764,14 @@ void EQ::Net::DaybreakConnection::ProcessDecodedPacket(const Packet &p)
|
|||||||
}
|
}
|
||||||
case OP_SessionStatRequest:
|
case OP_SessionStatRequest:
|
||||||
{
|
{
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "OP_SessionStatRequest recv");
|
||||||
auto request = p.GetSerialize<DaybreakSessionStatRequest>(0);
|
auto request = p.GetSerialize<DaybreakSessionStatRequest>(0);
|
||||||
|
|
||||||
DaybreakSessionStatResponse response;
|
DaybreakSessionStatResponse response;
|
||||||
response.zero = 0;
|
response.zero = 0;
|
||||||
response.opcode = OP_SessionStatResponse;
|
response.opcode = OP_SessionStatResponse;
|
||||||
response.timestamp = request.timestamp;
|
response.timestamp = request.timestamp;
|
||||||
response.our_timestamp = EQ::Net::HostToNetwork(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count());
|
response.our_timestamp = (uint32_t)EQ::Net::HostToNetwork(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count());
|
||||||
response.client_sent = request.packets_sent;
|
response.client_sent = request.packets_sent;
|
||||||
response.client_recv = request.packets_recv;
|
response.client_recv = request.packets_recv;
|
||||||
response.server_sent = EQ::Net::HostToNetwork(m_stats.sent_packets);
|
response.server_sent = EQ::Net::HostToNetwork(m_stats.sent_packets);
|
||||||
@ -732,6 +782,7 @@ void EQ::Net::DaybreakConnection::ProcessDecodedPacket(const Packet &p)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OP_SessionStatResponse:
|
case OP_SessionStatResponse:
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "OP_SessionStatResponse recv, not yet implemented.");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Log.OutF(Logs::Detail, Logs::Netcode, "Unhandled opcode {0:#x}", p.GetInt8(1));
|
Log.OutF(Logs::Detail, Logs::Netcode, "Unhandled opcode {0:#x}", p.GetInt8(1));
|
||||||
@ -739,6 +790,7 @@ void EQ::Net::DaybreakConnection::ProcessDecodedPacket(const Packet &p)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Recv raw app packet, processing");
|
||||||
auto self = m_self.lock();
|
auto self = m_self.lock();
|
||||||
if (m_owner->m_on_packet_recv && self) {
|
if (m_owner->m_on_packet_recv && self) {
|
||||||
m_owner->m_on_packet_recv(self, p);
|
m_owner->m_on_packet_recv(self, p);
|
||||||
@ -752,7 +804,7 @@ bool EQ::Net::DaybreakConnection::ValidateCRC(Packet &p)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p.Length() < (size_t)m_crc_bytes) {
|
if (p.Length() < (uint64_t)m_crc_bytes) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -761,12 +813,12 @@ bool EQ::Net::DaybreakConnection::ValidateCRC(Packet &p)
|
|||||||
int actual = 0;
|
int actual = 0;
|
||||||
switch (m_crc_bytes) {
|
switch (m_crc_bytes) {
|
||||||
case 2:
|
case 2:
|
||||||
actual = NetworkToHost(*(int16_t*)&data[p.Length() - (size_t)m_crc_bytes]) & 0xffff;
|
actual = NetworkToHost(*(int16_t*)&data[p.Length() - (uint64_t)m_crc_bytes]) & 0xffff;
|
||||||
calculated = Crc32(data, (int)(p.Length() - (size_t)m_crc_bytes), m_encode_key) & 0xffff;
|
calculated = Crc32(data, (int)(p.Length() - (uint64_t)m_crc_bytes), m_encode_key) & 0xffff;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
actual = NetworkToHost(*(int32_t*)&data[p.Length() - (size_t)m_crc_bytes]);
|
actual = NetworkToHost(*(int32_t*)&data[p.Length() - (uint64_t)m_crc_bytes]);
|
||||||
calculated = Crc32(data, (int)(p.Length() - (size_t)m_crc_bytes), m_encode_key);
|
calculated = Crc32(data, (int)(p.Length() - (uint64_t)m_crc_bytes), m_encode_key);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
@ -806,6 +858,7 @@ void EQ::Net::DaybreakConnection::ChangeStatus(DbProtocolStatus new_status)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Status changed from {0} to {1}", (int)m_status, (int)new_status);
|
||||||
m_status = new_status;
|
m_status = new_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -823,12 +876,12 @@ bool EQ::Net::DaybreakConnection::PacketCanBeEncoded(Packet &p) const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EQ::Net::DaybreakConnection::Decode(Packet &p, size_t offset, size_t length)
|
void EQ::Net::DaybreakConnection::Decode(Packet &p, uint64_t offset, uint64_t length)
|
||||||
{
|
{
|
||||||
int key = m_encode_key;
|
int key = m_encode_key;
|
||||||
char *buffer = (char*)p.Data() + offset;
|
char *buffer = (char*)p.Data() + offset;
|
||||||
|
|
||||||
size_t i = 0;
|
uint64_t i = 0;
|
||||||
for (i = 0; i + 4 <= length; i += 4)
|
for (i = 0; i + 4 <= length; i += 4)
|
||||||
{
|
{
|
||||||
int pt = (*(int*)&buffer[i]) ^ (key);
|
int pt = (*(int*)&buffer[i]) ^ (key);
|
||||||
@ -843,12 +896,12 @@ void EQ::Net::DaybreakConnection::Decode(Packet &p, size_t offset, size_t length
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EQ::Net::DaybreakConnection::Encode(Packet &p, size_t offset, size_t length)
|
void EQ::Net::DaybreakConnection::Encode(Packet &p, uint64_t offset, uint64_t length)
|
||||||
{
|
{
|
||||||
int key = m_encode_key;
|
int key = m_encode_key;
|
||||||
char *buffer = (char*)p.Data() + offset;
|
char *buffer = (char*)p.Data() + offset;
|
||||||
|
|
||||||
size_t i = 0;
|
uint64_t i = 0;
|
||||||
for (i = 0; i + 4 <= length; i += 4)
|
for (i = 0; i + 4 <= length; i += 4)
|
||||||
{
|
{
|
||||||
int pt = (*(int*)&buffer[i]) ^ (key);
|
int pt = (*(int*)&buffer[i]) ^ (key);
|
||||||
@ -932,7 +985,7 @@ uint32_t Deflate(const uint8_t* in, uint32_t in_len, uint8_t* out, uint32_t out_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EQ::Net::DaybreakConnection::Decompress(Packet &p, size_t offset, size_t length)
|
void EQ::Net::DaybreakConnection::Decompress(Packet &p, uint64_t offset, uint64_t length)
|
||||||
{
|
{
|
||||||
if (length < 2) {
|
if (length < 2) {
|
||||||
return;
|
return;
|
||||||
@ -946,7 +999,7 @@ void EQ::Net::DaybreakConnection::Decompress(Packet &p, size_t offset, size_t le
|
|||||||
new_length = Inflate(buffer + 1, (uint32_t)length - 1, new_buffer, 4096);
|
new_length = Inflate(buffer + 1, (uint32_t)length - 1, new_buffer, 4096);
|
||||||
}
|
}
|
||||||
else if (buffer[0] == 0xa5) {
|
else if (buffer[0] == 0xa5) {
|
||||||
memcpy(new_buffer, buffer + 1, length - 1);
|
memcpy(new_buffer, buffer + 1, (size_t)length - 1);
|
||||||
new_length = (uint32_t)length - 1;
|
new_length = (uint32_t)length - 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -957,7 +1010,7 @@ void EQ::Net::DaybreakConnection::Decompress(Packet &p, size_t offset, size_t le
|
|||||||
p.PutData(offset, new_buffer, new_length);
|
p.PutData(offset, new_buffer, new_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EQ::Net::DaybreakConnection::Compress(Packet &p, size_t offset, size_t length)
|
void EQ::Net::DaybreakConnection::Compress(Packet &p, uint64_t offset, uint64_t length)
|
||||||
{
|
{
|
||||||
uint8_t new_buffer[2048] = { 0 };
|
uint8_t new_buffer[2048] = { 0 };
|
||||||
uint8_t *buffer = (uint8_t*)p.Data() + offset;
|
uint8_t *buffer = (uint8_t*)p.Data() + offset;
|
||||||
@ -968,9 +1021,9 @@ void EQ::Net::DaybreakConnection::Compress(Packet &p, size_t offset, size_t leng
|
|||||||
new_buffer[0] = 0x5a;
|
new_buffer[0] = 0x5a;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
memcpy(new_buffer + 1, buffer, length);
|
memcpy(new_buffer + 1, buffer, (size_t)length);
|
||||||
new_buffer[0] = 0xa5;
|
new_buffer[0] = 0xa5;
|
||||||
new_length = length + 1;
|
new_length = (size_t)length + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Resize(offset);
|
p.Resize(offset);
|
||||||
@ -991,14 +1044,16 @@ void EQ::Net::DaybreakConnection::ProcessResend(int stream)
|
|||||||
for (auto &entry : s->sent_packets) {
|
for (auto &entry : s->sent_packets) {
|
||||||
auto time_since_last_send = std::chrono::duration_cast<std::chrono::milliseconds>(now - entry.second.last_sent);
|
auto time_since_last_send = std::chrono::duration_cast<std::chrono::milliseconds>(now - entry.second.last_sent);
|
||||||
if(entry.second.times_resent == 0) {
|
if(entry.second.times_resent == 0) {
|
||||||
if ((size_t)time_since_last_send.count() > m_resend_delay) {
|
if ((uint64_t)time_since_last_send.count() > m_resend_delay) {
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Resending reliable packet\n{0}", entry.second.packet.ToString());
|
||||||
InternalBufferedSend(entry.second.packet);
|
InternalBufferedSend(entry.second.packet);
|
||||||
entry.second.last_sent = now;
|
entry.second.last_sent = now;
|
||||||
entry.second.times_resent++;
|
entry.second.times_resent++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ((size_t)time_since_last_send.count() > std::min(m_resend_delay / (entry.second.times_resent + 1), (size_t)5ULL)) {
|
if ((uint64_t)time_since_last_send.count() > std::min(m_resend_delay / (entry.second.times_resent + 1), (uint64_t)50ULL)) {
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Resending reliable packet\n{0}", entry.second.packet.ToString());
|
||||||
InternalBufferedSend(entry.second.packet);
|
InternalBufferedSend(entry.second.packet);
|
||||||
entry.second.last_sent = now;
|
entry.second.last_sent = now;
|
||||||
entry.second.times_resent++;
|
entry.second.times_resent++;
|
||||||
@ -1075,19 +1130,22 @@ void EQ::Net::DaybreakConnection::SendStatSync()
|
|||||||
DaybreakSessionStatRequest request;
|
DaybreakSessionStatRequest request;
|
||||||
request.zero = 0;
|
request.zero = 0;
|
||||||
request.opcode = OP_SessionStatRequest;
|
request.opcode = OP_SessionStatRequest;
|
||||||
request.timestamp = EQ::Net::HostToNetwork(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() & 0xFFFFLL);
|
request.timestamp = (uint32_t)EQ::Net::HostToNetwork(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() & 0xFFFFLL);
|
||||||
request.stat_ping = m_stats.last_stat_ping;
|
request.stat_ping = (uint32_t)m_stats.last_stat_ping;
|
||||||
if (m_stats.total_stat_count > 0)
|
if (m_stats.total_stat_count > 0)
|
||||||
request.avg_ping = m_stats.total_stat_ping / m_stats.total_stat_count;
|
request.avg_ping = (uint32)(m_stats.total_stat_ping / m_stats.total_stat_count);
|
||||||
else
|
else
|
||||||
request.avg_ping = 0;
|
request.avg_ping = 0;
|
||||||
request.min_ping = m_stats.min_stat_ping;
|
request.min_ping = (uint32_t)m_stats.min_stat_ping;
|
||||||
request.max_ping = m_stats.max_stat_ping;
|
request.max_ping = (uint32_t)m_stats.max_stat_ping;
|
||||||
request.last_ping = m_stats.last_stat_ping;
|
request.last_ping = (uint32_t)m_stats.last_stat_ping;
|
||||||
request.packets_sent = m_stats.sent_packets + 1;
|
request.packets_sent = (uint32_t)m_stats.sent_packets + 1;
|
||||||
request.packets_recv = m_stats.recv_packets;
|
request.packets_recv = (uint32_t)m_stats.recv_packets;
|
||||||
m_last_session_stats = Clock::now();
|
m_last_session_stats = Clock::now();
|
||||||
//InternalSend()
|
|
||||||
|
EQ::Net::DynamicPacket p;
|
||||||
|
p.PutSerialize(0, request);
|
||||||
|
InternalSend(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EQ::Net::DaybreakConnection::InternalBufferedSend(Packet &p)
|
void EQ::Net::DaybreakConnection::InternalBufferedSend(Packet &p)
|
||||||
@ -1099,7 +1157,7 @@ void EQ::Net::DaybreakConnection::InternalBufferedSend(Packet &p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//we could add this packet to a combined
|
//we could add this packet to a combined
|
||||||
size_t raw_size = DaybreakHeader::size() + (size_t)m_crc_bytes + m_buffered_packets_length + m_buffered_packets.size() + 1 + p.Length();
|
uint64_t raw_size = DaybreakHeader::size() + (uint64_t)m_crc_bytes + m_buffered_packets_length + m_buffered_packets.size() + 1 + p.Length();
|
||||||
if (raw_size > m_max_packet_size) {
|
if (raw_size > m_max_packet_size) {
|
||||||
FlushBuffer();
|
FlushBuffer();
|
||||||
}
|
}
|
||||||
@ -1175,9 +1233,9 @@ void EQ::Net::DaybreakConnection::InternalSend(Packet &p)
|
|||||||
uv_ip4_addr(m_endpoint.c_str(), m_port, &send_addr);
|
uv_ip4_addr(m_endpoint.c_str(), m_port, &send_addr);
|
||||||
uv_buf_t send_buffers[1];
|
uv_buf_t send_buffers[1];
|
||||||
|
|
||||||
char *data = new char[out.Length()];
|
char *data = new char[(size_t)out.Length()];
|
||||||
memcpy(data, out.Data(), out.Length());
|
memcpy(data, out.Data(), (size_t)out.Length());
|
||||||
send_buffers[0] = uv_buf_init(data, out.Length());
|
send_buffers[0] = uv_buf_init(data, (size_t)out.Length());
|
||||||
send_req->data = send_buffers[0].base;
|
send_req->data = send_buffers[0].base;
|
||||||
|
|
||||||
m_stats.sent_bytes += out.Length();
|
m_stats.sent_bytes += out.Length();
|
||||||
@ -1197,14 +1255,16 @@ void EQ::Net::DaybreakConnection::InternalSend(Packet &p)
|
|||||||
uv_ip4_addr(m_endpoint.c_str(), m_port, &send_addr);
|
uv_ip4_addr(m_endpoint.c_str(), m_port, &send_addr);
|
||||||
uv_buf_t send_buffers[1];
|
uv_buf_t send_buffers[1];
|
||||||
|
|
||||||
char *data = new char[p.Length()];
|
char *data = new char[(size_t)p.Length()];
|
||||||
memcpy(data, p.Data(), p.Length());
|
memcpy(data, p.Data(), (size_t)p.Length());
|
||||||
send_buffers[0] = uv_buf_init(data, p.Length());
|
send_buffers[0] = uv_buf_init(data, (size_t)p.Length());
|
||||||
send_req->data = send_buffers[0].base;
|
send_req->data = send_buffers[0].base;
|
||||||
|
|
||||||
m_stats.sent_bytes += p.Length();
|
m_stats.sent_bytes += p.Length();
|
||||||
m_stats.sent_packets++;
|
m_stats.sent_packets++;
|
||||||
|
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Sending reliable packet\n{0}", p.ToString());
|
||||||
|
|
||||||
if (m_owner->m_options.simulated_out_packet_loss && m_owner->m_options.simulated_out_packet_loss >= m_owner->m_rand.Int(0, 100)) {
|
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[] (char*)send_req->data;
|
delete[] (char*)send_req->data;
|
||||||
delete send_req;
|
delete send_req;
|
||||||
@ -1217,18 +1277,24 @@ void EQ::Net::DaybreakConnection::InternalSend(Packet &p)
|
|||||||
void EQ::Net::DaybreakConnection::InternalQueuePacket(Packet &p, int stream_id, bool reliable)
|
void EQ::Net::DaybreakConnection::InternalQueuePacket(Packet &p, int stream_id, bool reliable)
|
||||||
{
|
{
|
||||||
if (!reliable) {
|
if (!reliable) {
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Queue non-reliable packet for stream {0}\n{1}", p.ToString());
|
||||||
|
|
||||||
auto max_raw_size = m_max_packet_size - m_crc_bytes;
|
auto max_raw_size = m_max_packet_size - m_crc_bytes;
|
||||||
if (p.Length() > max_raw_size) {
|
if (p.Length() > max_raw_size) {
|
||||||
InternalQueuePacket(p, stream_id, true);
|
InternalQueuePacket(p, stream_id, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Non-reliable packet was too large, queuing as a reliable");
|
||||||
InternalBufferedSend(p);
|
InternalBufferedSend(p);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Queue reliable packet for stream {0}\n{1}", p.ToString());
|
||||||
|
|
||||||
auto stream = &m_streams[stream_id];
|
auto stream = &m_streams[stream_id];
|
||||||
auto max_raw_size = m_max_packet_size - m_crc_bytes - DaybreakReliableHeader::size();
|
auto max_raw_size = m_max_packet_size - m_crc_bytes - DaybreakReliableHeader::size();
|
||||||
size_t length = p.Length();
|
uint64_t length = p.Length();
|
||||||
if (length > max_raw_size) {
|
if (length > max_raw_size) {
|
||||||
DaybreakReliableFragmentHeader first_header;
|
DaybreakReliableFragmentHeader first_header;
|
||||||
first_header.reliable.zero = 0;
|
first_header.reliable.zero = 0;
|
||||||
@ -1236,8 +1302,10 @@ void EQ::Net::DaybreakConnection::InternalQueuePacket(Packet &p, int stream_id,
|
|||||||
first_header.reliable.sequence = HostToNetwork(stream->sequence_out);
|
first_header.reliable.sequence = HostToNetwork(stream->sequence_out);
|
||||||
first_header.total_size = (uint32_t)HostToNetwork((uint32_t)length);
|
first_header.total_size = (uint32_t)HostToNetwork((uint32_t)length);
|
||||||
|
|
||||||
size_t used = 0;
|
Log.OutF(Logs::Detail, Logs::Netcode, "Packet too large, fragmenting {0} total size", first_header.total_size);
|
||||||
size_t sublen = m_max_packet_size - m_crc_bytes - DaybreakReliableFragmentHeader::size();
|
|
||||||
|
uint64_t used = 0;
|
||||||
|
uint64_t sublen = m_max_packet_size - m_crc_bytes - DaybreakReliableFragmentHeader::size();
|
||||||
DynamicPacket first_packet;
|
DynamicPacket first_packet;
|
||||||
first_packet.PutSerialize(0, first_header);
|
first_packet.PutSerialize(0, first_header);
|
||||||
first_packet.PutData(DaybreakReliableFragmentHeader::size(), (char*)p.Data() + used, sublen);
|
first_packet.PutData(DaybreakReliableFragmentHeader::size(), (char*)p.Data() + used, sublen);
|
||||||
@ -1251,6 +1319,8 @@ void EQ::Net::DaybreakConnection::InternalQueuePacket(Packet &p, int stream_id,
|
|||||||
stream->sent_packets.insert(std::make_pair(stream->sequence_out, sent));
|
stream->sent_packets.insert(std::make_pair(stream->sequence_out, sent));
|
||||||
stream->sequence_out++;
|
stream->sequence_out++;
|
||||||
|
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Fragmented packet {0}/{1}", used, first_header.total_size);
|
||||||
|
|
||||||
InternalBufferedSend(first_packet);
|
InternalBufferedSend(first_packet);
|
||||||
|
|
||||||
while (used < length) {
|
while (used < length) {
|
||||||
@ -1279,6 +1349,8 @@ void EQ::Net::DaybreakConnection::InternalQueuePacket(Packet &p, int stream_id,
|
|||||||
stream->sent_packets.insert(std::make_pair(stream->sequence_out, sent));
|
stream->sent_packets.insert(std::make_pair(stream->sequence_out, sent));
|
||||||
stream->sequence_out++;
|
stream->sequence_out++;
|
||||||
|
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Fragmented packet {0}/{1}", used, first_header.total_size);
|
||||||
|
|
||||||
InternalBufferedSend(packet);
|
InternalBufferedSend(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1299,6 +1371,8 @@ void EQ::Net::DaybreakConnection::InternalQueuePacket(Packet &p, int stream_id,
|
|||||||
stream->sent_packets.insert(std::make_pair(stream->sequence_out, sent));
|
stream->sent_packets.insert(std::make_pair(stream->sequence_out, sent));
|
||||||
stream->sequence_out++;
|
stream->sequence_out++;
|
||||||
|
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Reliable packet was able to be sent without fragmenting");
|
||||||
|
|
||||||
InternalBufferedSend(packet);
|
InternalBufferedSend(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1310,8 +1384,10 @@ void EQ::Net::DaybreakConnection::FlushBuffer()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m_buffered_packets.size() > 1) {
|
if (m_buffered_packets.size() > 1) {
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Flushing buffer of size {0} packets and {1} bytes", m_buffered_packets.size(), m_buffered_packets_length);
|
||||||
|
|
||||||
StaticPacket out(m_combined.get(), 512);
|
StaticPacket out(m_combined.get(), 512);
|
||||||
size_t length = 2;
|
uint64_t length = 2;
|
||||||
for (auto &p : m_buffered_packets) {
|
for (auto &p : m_buffered_packets) {
|
||||||
out.PutUInt8(length, (uint8_t)p.Length());
|
out.PutUInt8(length, (uint8_t)p.Length());
|
||||||
out.PutPacket(length + 1, p);
|
out.PutPacket(length + 1, p);
|
||||||
@ -1322,6 +1398,8 @@ void EQ::Net::DaybreakConnection::FlushBuffer()
|
|||||||
InternalSend(out);
|
InternalSend(out);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Log.OutF(Logs::Detail, Logs::Netcode, "Flushing buffer of size 1 packet and {0} bytes", m_buffered_packets_length);
|
||||||
|
|
||||||
auto &front = m_buffered_packets.front();
|
auto &front = m_buffered_packets.front();
|
||||||
InternalSend(front);
|
InternalSend(front);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -124,7 +124,7 @@ namespace EQ
|
|||||||
void QueuePacket(Packet &p, int stream, bool reliable);
|
void QueuePacket(Packet &p, int stream, bool reliable);
|
||||||
const DaybreakConnectionStats& GetStats() const { return m_stats; }
|
const DaybreakConnectionStats& GetStats() const { return m_stats; }
|
||||||
void ResetStats();
|
void ResetStats();
|
||||||
size_t GetRollingPing() const { return m_rolling_ping; }
|
uint64_t GetRollingPing() const { return m_rolling_ping; }
|
||||||
DbProtocolStatus GetStatus() { return m_status; }
|
DbProtocolStatus GetStatus() { return m_status; }
|
||||||
private:
|
private:
|
||||||
DaybreakConnectionManager *m_owner;
|
DaybreakConnectionManager *m_owner;
|
||||||
@ -141,20 +141,20 @@ namespace EQ
|
|||||||
DbProtocolStatus m_status;
|
DbProtocolStatus m_status;
|
||||||
Timestamp m_hold_time;
|
Timestamp m_hold_time;
|
||||||
std::list<DynamicPacket> m_buffered_packets;
|
std::list<DynamicPacket> m_buffered_packets;
|
||||||
size_t m_buffered_packets_length;
|
uint64_t m_buffered_packets_length;
|
||||||
std::unique_ptr<char[]> m_combined;
|
std::unique_ptr<char[]> m_combined;
|
||||||
Timestamp m_last_stats;
|
Timestamp m_last_stats;
|
||||||
DaybreakConnectionStats m_stats;
|
DaybreakConnectionStats m_stats;
|
||||||
Timestamp m_last_session_stats;
|
Timestamp m_last_session_stats;
|
||||||
size_t m_resend_delay;
|
uint64_t m_resend_delay;
|
||||||
size_t m_rolling_ping;
|
uint64_t m_rolling_ping;
|
||||||
|
|
||||||
struct DaybreakSentPacket
|
struct DaybreakSentPacket
|
||||||
{
|
{
|
||||||
DynamicPacket packet;
|
DynamicPacket packet;
|
||||||
Timestamp last_sent;
|
Timestamp last_sent;
|
||||||
Timestamp first_sent;
|
Timestamp first_sent;
|
||||||
size_t times_resent;
|
uint64_t times_resent;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DaybreakStream
|
struct DaybreakStream
|
||||||
@ -190,10 +190,10 @@ namespace EQ
|
|||||||
bool ValidateCRC(Packet &p);
|
bool ValidateCRC(Packet &p);
|
||||||
void AppendCRC(Packet &p);
|
void AppendCRC(Packet &p);
|
||||||
bool PacketCanBeEncoded(Packet &p) const;
|
bool PacketCanBeEncoded(Packet &p) const;
|
||||||
void Decode(Packet &p, size_t offset, size_t length);
|
void Decode(Packet &p, uint64_t offset, uint64_t length);
|
||||||
void Encode(Packet &p, size_t offset, size_t length);
|
void Encode(Packet &p, uint64_t offset, uint64_t length);
|
||||||
void Decompress(Packet &p, size_t offset, size_t length);
|
void Decompress(Packet &p, uint64_t offset, uint64_t length);
|
||||||
void Compress(Packet &p, size_t offset, size_t length);
|
void Compress(Packet &p, uint64_t offset, uint64_t length);
|
||||||
void ProcessResend();
|
void ProcessResend();
|
||||||
void ProcessResend(int stream);
|
void ProcessResend(int stream);
|
||||||
void Ack(int stream, uint16_t seq);
|
void Ack(int stream, uint16_t seq);
|
||||||
@ -236,20 +236,20 @@ namespace EQ
|
|||||||
tic_rate_hertz = 20.0;
|
tic_rate_hertz = 20.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t max_packet_size;
|
uint64_t max_packet_size;
|
||||||
size_t max_connection_count;
|
uint64_t max_connection_count;
|
||||||
size_t keepalive_delay_ms;
|
uint64_t keepalive_delay_ms;
|
||||||
double resend_delay_factor;
|
double resend_delay_factor;
|
||||||
size_t resend_delay_ms;
|
uint64_t resend_delay_ms;
|
||||||
size_t stats_delay_ms;
|
uint64_t stats_delay_ms;
|
||||||
size_t connect_delay_ms;
|
uint64_t connect_delay_ms;
|
||||||
size_t connect_stale_ms;
|
uint64_t connect_stale_ms;
|
||||||
size_t stale_connection_ms;
|
uint64_t stale_connection_ms;
|
||||||
size_t crc_length;
|
uint64_t crc_length;
|
||||||
size_t hold_size;
|
uint64_t hold_size;
|
||||||
size_t hold_length_ms;
|
uint64_t hold_length_ms;
|
||||||
size_t simulated_in_packet_loss;
|
uint64_t simulated_in_packet_loss;
|
||||||
size_t simulated_out_packet_loss;
|
uint64_t simulated_out_packet_loss;
|
||||||
double tic_rate_hertz;
|
double tic_rate_hertz;
|
||||||
DaybreakEncodeType encode_passes[2];
|
DaybreakEncodeType encode_passes[2];
|
||||||
int port;
|
int port;
|
||||||
@ -282,7 +282,7 @@ namespace EQ
|
|||||||
std::function<void(std::shared_ptr<DaybreakConnection>, const Packet&)> m_on_packet_recv;
|
std::function<void(std::shared_ptr<DaybreakConnection>, const Packet&)> m_on_packet_recv;
|
||||||
std::map<std::pair<std::string, int>, std::shared_ptr<DaybreakConnection>> m_connections;
|
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);
|
void ProcessPacket(const std::string &endpoint, int port, const char *data, uint64_t size);
|
||||||
std::shared_ptr<DaybreakConnection> FindConnectionByEndpoint(std::string addr, int port);
|
std::shared_ptr<DaybreakConnection> FindConnectionByEndpoint(std::string addr, int port);
|
||||||
void SendDisconnect(const std::string &addr, int port);
|
void SendDisconnect(const std::string &addr, int port);
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
|
||||||
void EQ::Net::Packet::PutInt8(size_t offset, int8_t value)
|
void EQ::Net::Packet::PutInt8(uint64_t offset, int8_t value)
|
||||||
{
|
{
|
||||||
if (Length() < offset + 1) {
|
if (Length() < offset + 1) {
|
||||||
if (!Resize(offset + 1)) {
|
if (!Resize(offset + 1)) {
|
||||||
@ -14,7 +14,7 @@ void EQ::Net::Packet::PutInt8(size_t offset, int8_t value)
|
|||||||
*(int8_t*)((char*)Data() + offset) = value;
|
*(int8_t*)((char*)Data() + offset) = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EQ::Net::Packet::PutInt16(size_t offset, int16_t value)
|
void EQ::Net::Packet::PutInt16(uint64_t offset, int16_t value)
|
||||||
{
|
{
|
||||||
if (Length() < offset + 2) {
|
if (Length() < offset + 2) {
|
||||||
if (!Resize(offset + 2)) {
|
if (!Resize(offset + 2)) {
|
||||||
@ -25,7 +25,7 @@ void EQ::Net::Packet::PutInt16(size_t offset, int16_t value)
|
|||||||
*(int16_t*)((char*)Data() + offset) = value;
|
*(int16_t*)((char*)Data() + offset) = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EQ::Net::Packet::PutInt32(size_t offset, int32_t value)
|
void EQ::Net::Packet::PutInt32(uint64_t offset, int32_t value)
|
||||||
{
|
{
|
||||||
if (Length() < offset + 4) {
|
if (Length() < offset + 4) {
|
||||||
if (!Resize(offset + 4)) {
|
if (!Resize(offset + 4)) {
|
||||||
@ -36,7 +36,7 @@ void EQ::Net::Packet::PutInt32(size_t offset, int32_t value)
|
|||||||
*(int32_t*)((char*)Data() + offset) = value;
|
*(int32_t*)((char*)Data() + offset) = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EQ::Net::Packet::PutInt64(size_t offset, int64_t value)
|
void EQ::Net::Packet::PutInt64(uint64_t offset, int64_t value)
|
||||||
{
|
{
|
||||||
if (Length() < offset + 8) {
|
if (Length() < offset + 8) {
|
||||||
if (!Resize(offset + 8)) {
|
if (!Resize(offset + 8)) {
|
||||||
@ -47,7 +47,7 @@ void EQ::Net::Packet::PutInt64(size_t offset, int64_t value)
|
|||||||
*(int64_t*)((char*)Data() + offset) = value;
|
*(int64_t*)((char*)Data() + offset) = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EQ::Net::Packet::PutUInt8(size_t offset, uint8_t value)
|
void EQ::Net::Packet::PutUInt8(uint64_t offset, uint8_t value)
|
||||||
{
|
{
|
||||||
if (Length() < offset + 1) {
|
if (Length() < offset + 1) {
|
||||||
if (!Resize(offset + 1)) {
|
if (!Resize(offset + 1)) {
|
||||||
@ -58,7 +58,7 @@ void EQ::Net::Packet::PutUInt8(size_t offset, uint8_t value)
|
|||||||
*(uint8_t*)((char*)Data() + offset) = value;
|
*(uint8_t*)((char*)Data() + offset) = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EQ::Net::Packet::PutUInt16(size_t offset, uint16_t value)
|
void EQ::Net::Packet::PutUInt16(uint64_t offset, uint16_t value)
|
||||||
{
|
{
|
||||||
if (Length() < offset + 2) {
|
if (Length() < offset + 2) {
|
||||||
if (!Resize(offset + 2)) {
|
if (!Resize(offset + 2)) {
|
||||||
@ -69,7 +69,7 @@ void EQ::Net::Packet::PutUInt16(size_t offset, uint16_t value)
|
|||||||
*(uint16_t*)((char*)Data() + offset) = value;
|
*(uint16_t*)((char*)Data() + offset) = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EQ::Net::Packet::PutUInt32(size_t offset, uint32_t value)
|
void EQ::Net::Packet::PutUInt32(uint64_t offset, uint32_t value)
|
||||||
{
|
{
|
||||||
if (Length() < offset + 4) {
|
if (Length() < offset + 4) {
|
||||||
if (!Resize(offset + 4)) {
|
if (!Resize(offset + 4)) {
|
||||||
@ -80,7 +80,7 @@ void EQ::Net::Packet::PutUInt32(size_t offset, uint32_t value)
|
|||||||
*(uint32_t*)((char*)Data() + offset) = value;
|
*(uint32_t*)((char*)Data() + offset) = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EQ::Net::Packet::PutUInt64(size_t offset, uint64_t value)
|
void EQ::Net::Packet::PutUInt64(uint64_t offset, uint64_t value)
|
||||||
{
|
{
|
||||||
if (Length() < offset + 8) {
|
if (Length() < offset + 8) {
|
||||||
if (!Resize(offset + 8)) {
|
if (!Resize(offset + 8)) {
|
||||||
@ -91,7 +91,7 @@ void EQ::Net::Packet::PutUInt64(size_t offset, uint64_t value)
|
|||||||
*(uint64_t*)((char*)Data() + offset) = value;
|
*(uint64_t*)((char*)Data() + offset) = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EQ::Net::Packet::PutFloat(size_t offset, float value)
|
void EQ::Net::Packet::PutFloat(uint64_t offset, float value)
|
||||||
{
|
{
|
||||||
if (Length() < offset + 4) {
|
if (Length() < offset + 4) {
|
||||||
if (!Resize(offset + 4)) {
|
if (!Resize(offset + 4)) {
|
||||||
@ -102,7 +102,7 @@ void EQ::Net::Packet::PutFloat(size_t offset, float value)
|
|||||||
*(float*)((char*)Data() + offset) = value;
|
*(float*)((char*)Data() + offset) = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EQ::Net::Packet::PutDouble(size_t offset, double value)
|
void EQ::Net::Packet::PutDouble(uint64_t offset, double value)
|
||||||
{
|
{
|
||||||
if (Length() < offset + 8) {
|
if (Length() < offset + 8) {
|
||||||
if (!Resize(offset + 8)) {
|
if (!Resize(offset + 8)) {
|
||||||
@ -113,7 +113,7 @@ void EQ::Net::Packet::PutDouble(size_t offset, double value)
|
|||||||
*(double*)((char*)Data() + offset) = value;
|
*(double*)((char*)Data() + offset) = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EQ::Net::Packet::PutString(size_t offset, const std::string &str)
|
void EQ::Net::Packet::PutString(uint64_t offset, const std::string &str)
|
||||||
{
|
{
|
||||||
if (Length() < offset + str.length()) {
|
if (Length() < offset + str.length()) {
|
||||||
if (!Resize(offset + str.length())) {
|
if (!Resize(offset + str.length())) {
|
||||||
@ -124,20 +124,20 @@ void EQ::Net::Packet::PutString(size_t offset, const std::string &str)
|
|||||||
memcpy(((char*)Data() + offset), str.c_str(), str.length());
|
memcpy(((char*)Data() + offset), str.c_str(), str.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EQ::Net::Packet::PutCString(size_t offset, const char *str)
|
void EQ::Net::Packet::PutCString(uint64_t offset, const char *str)
|
||||||
{
|
{
|
||||||
size_t sz = strlen(str);
|
uint64_t sz = strlen(str);
|
||||||
if (Length() < offset + sz + 1) {
|
if (Length() < offset + sz + 1) {
|
||||||
if (!Resize(offset + sz + 1)) {
|
if (!Resize(offset + sz + 1)) {
|
||||||
throw std::out_of_range("Packet::PutCString(), could not resize packet and would of written past the end.");
|
throw std::out_of_range("Packet::PutCString(), could not resize packet and would of written past the end.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(((char*)Data() + offset), str, sz);
|
memcpy(((char*)Data() + offset), str, (size_t)sz);
|
||||||
*((char*)Data() + offset + sz) = 0;
|
*((char*)Data() + offset + sz) = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EQ::Net::Packet::PutPacket(size_t offset, const Packet &p)
|
void EQ::Net::Packet::PutPacket(uint64_t offset, const Packet &p)
|
||||||
{
|
{
|
||||||
if (Length() < offset + p.Length()) {
|
if (Length() < offset + p.Length()) {
|
||||||
if (!Resize(offset + p.Length())) {
|
if (!Resize(offset + p.Length())) {
|
||||||
@ -145,10 +145,10 @@ void EQ::Net::Packet::PutPacket(size_t offset, const Packet &p)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(((char*)Data() + offset), p.Data(), p.Length());
|
memcpy(((char*)Data() + offset), p.Data(), (size_t)p.Length());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EQ::Net::Packet::PutData(size_t offset, void *data, size_t length)
|
void EQ::Net::Packet::PutData(uint64_t offset, void *data, uint64_t length)
|
||||||
{
|
{
|
||||||
if (Length() < offset + length) {
|
if (Length() < offset + length) {
|
||||||
if (!Resize(offset + length)) {
|
if (!Resize(offset + length)) {
|
||||||
@ -156,10 +156,10 @@ void EQ::Net::Packet::PutData(size_t offset, void *data, size_t length)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(((char*)Data() + offset), data, length);
|
memcpy(((char*)Data() + offset), data, (size_t)length);
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t EQ::Net::Packet::GetInt8(size_t offset) const
|
int8_t EQ::Net::Packet::GetInt8(uint64_t offset) const
|
||||||
{
|
{
|
||||||
if (Length() < offset + 1) {
|
if (Length() < offset + 1) {
|
||||||
throw std::out_of_range("Packet read out of range.");
|
throw std::out_of_range("Packet read out of range.");
|
||||||
@ -168,7 +168,7 @@ int8_t EQ::Net::Packet::GetInt8(size_t offset) const
|
|||||||
return *(int8_t*)((char*)Data() + offset);
|
return *(int8_t*)((char*)Data() + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t EQ::Net::Packet::GetInt16(size_t offset) const
|
int16_t EQ::Net::Packet::GetInt16(uint64_t offset) const
|
||||||
{
|
{
|
||||||
if (Length() < offset + 2) {
|
if (Length() < offset + 2) {
|
||||||
throw std::out_of_range("Packet read out of range.");
|
throw std::out_of_range("Packet read out of range.");
|
||||||
@ -177,7 +177,7 @@ int16_t EQ::Net::Packet::GetInt16(size_t offset) const
|
|||||||
return *(int16_t*)((char*)Data() + offset);
|
return *(int16_t*)((char*)Data() + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t EQ::Net::Packet::GetInt32(size_t offset) const
|
int32_t EQ::Net::Packet::GetInt32(uint64_t offset) const
|
||||||
{
|
{
|
||||||
if (Length() < offset + 4) {
|
if (Length() < offset + 4) {
|
||||||
throw std::out_of_range("Packet read out of range.");
|
throw std::out_of_range("Packet read out of range.");
|
||||||
@ -186,7 +186,7 @@ int32_t EQ::Net::Packet::GetInt32(size_t offset) const
|
|||||||
return *(int32_t*)((char*)Data() + offset);
|
return *(int32_t*)((char*)Data() + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t EQ::Net::Packet::GetInt64(size_t offset) const
|
int64_t EQ::Net::Packet::GetInt64(uint64_t offset) const
|
||||||
{
|
{
|
||||||
if (Length() < offset + 8) {
|
if (Length() < offset + 8) {
|
||||||
throw std::out_of_range("Packet read out of range.");
|
throw std::out_of_range("Packet read out of range.");
|
||||||
@ -195,7 +195,7 @@ int64_t EQ::Net::Packet::GetInt64(size_t offset) const
|
|||||||
return *(int64_t*)((char*)Data() + offset);
|
return *(int64_t*)((char*)Data() + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t EQ::Net::Packet::GetUInt8(size_t offset) const
|
uint8_t EQ::Net::Packet::GetUInt8(uint64_t offset) const
|
||||||
{
|
{
|
||||||
if (Length() < offset + 1) {
|
if (Length() < offset + 1) {
|
||||||
throw std::out_of_range("Packet read out of range.");
|
throw std::out_of_range("Packet read out of range.");
|
||||||
@ -204,7 +204,7 @@ uint8_t EQ::Net::Packet::GetUInt8(size_t offset) const
|
|||||||
return *(uint8_t*)((char*)Data() + offset);
|
return *(uint8_t*)((char*)Data() + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t EQ::Net::Packet::GetUInt16(size_t offset) const
|
uint16_t EQ::Net::Packet::GetUInt16(uint64_t offset) const
|
||||||
{
|
{
|
||||||
if (Length() < offset + 2) {
|
if (Length() < offset + 2) {
|
||||||
throw std::out_of_range("Packet read out of range.");
|
throw std::out_of_range("Packet read out of range.");
|
||||||
@ -213,7 +213,7 @@ uint16_t EQ::Net::Packet::GetUInt16(size_t offset) const
|
|||||||
return *(uint16_t*)((char*)Data() + offset);
|
return *(uint16_t*)((char*)Data() + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t EQ::Net::Packet::GetUInt32(size_t offset) const
|
uint32_t EQ::Net::Packet::GetUInt32(uint64_t offset) const
|
||||||
{
|
{
|
||||||
if (Length() < offset + 4) {
|
if (Length() < offset + 4) {
|
||||||
throw std::out_of_range("Packet read out of range.");
|
throw std::out_of_range("Packet read out of range.");
|
||||||
@ -222,7 +222,7 @@ uint32_t EQ::Net::Packet::GetUInt32(size_t offset) const
|
|||||||
return *(uint32_t*)((char*)Data() + offset);
|
return *(uint32_t*)((char*)Data() + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t EQ::Net::Packet::GetUInt64(size_t offset) const
|
uint64_t EQ::Net::Packet::GetUInt64(uint64_t offset) const
|
||||||
{
|
{
|
||||||
if (Length() < offset + 8) {
|
if (Length() < offset + 8) {
|
||||||
throw std::out_of_range("Packet read out of range.");
|
throw std::out_of_range("Packet read out of range.");
|
||||||
@ -231,7 +231,7 @@ uint64_t EQ::Net::Packet::GetUInt64(size_t offset) const
|
|||||||
return *(uint64_t*)((char*)Data() + offset);
|
return *(uint64_t*)((char*)Data() + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
float EQ::Net::Packet::GetFloat(size_t offset) const
|
float EQ::Net::Packet::GetFloat(uint64_t offset) const
|
||||||
{
|
{
|
||||||
if (Length() < offset + 4) {
|
if (Length() < offset + 4) {
|
||||||
throw std::out_of_range("Packet read out of range.");
|
throw std::out_of_range("Packet read out of range.");
|
||||||
@ -240,7 +240,7 @@ float EQ::Net::Packet::GetFloat(size_t offset) const
|
|||||||
return *(float*)((char*)Data() + offset);
|
return *(float*)((char*)Data() + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
double EQ::Net::Packet::GetDouble(size_t offset) const
|
double EQ::Net::Packet::GetDouble(uint64_t offset) const
|
||||||
{
|
{
|
||||||
if (Length() < offset + 8) {
|
if (Length() < offset + 8) {
|
||||||
throw std::out_of_range("Packet read out of range.");
|
throw std::out_of_range("Packet read out of range.");
|
||||||
@ -249,7 +249,7 @@ double EQ::Net::Packet::GetDouble(size_t offset) const
|
|||||||
return *(double*)((char*)Data() + offset);
|
return *(double*)((char*)Data() + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string EQ::Net::Packet::GetString(size_t offset, size_t length) const
|
std::string EQ::Net::Packet::GetString(uint64_t offset, uint64_t length) const
|
||||||
{
|
{
|
||||||
if (Length() < offset + length) {
|
if (Length() < offset + length) {
|
||||||
throw std::out_of_range("Packet read out of range.");
|
throw std::out_of_range("Packet read out of range.");
|
||||||
@ -258,7 +258,7 @@ std::string EQ::Net::Packet::GetString(size_t offset, size_t length) const
|
|||||||
return std::string((char*)Data() + offset, (char*)Data() + offset + length);
|
return std::string((char*)Data() + offset, (char*)Data() + offset + length);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string EQ::Net::Packet::GetCString(size_t offset) const
|
std::string EQ::Net::Packet::GetCString(uint64_t offset) const
|
||||||
{
|
{
|
||||||
if (Length() < offset + 1) {
|
if (Length() < offset + 1) {
|
||||||
throw std::out_of_range("Packet read out of range.");
|
throw std::out_of_range("Packet read out of range.");
|
||||||
@ -281,15 +281,15 @@ std::string EQ::Net::Packet::ToString() const
|
|||||||
return ToString(16);
|
return ToString(16);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string EQ::Net::Packet::ToString(size_t line_length) const
|
std::string EQ::Net::Packet::ToString(uint64_t line_length) const
|
||||||
{
|
{
|
||||||
if (Length() == 0) {
|
if (Length() == 0) {
|
||||||
return fmt::format("{:0>5x} |", 0);
|
return fmt::format("{:0>5x} |", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ret;
|
std::string ret;
|
||||||
size_t lines = Length() / line_length;
|
uint64_t lines = Length() / line_length;
|
||||||
size_t i;
|
uint64_t i;
|
||||||
|
|
||||||
char *data = (char*)Data();
|
char *data = (char*)Data();
|
||||||
|
|
||||||
@ -297,7 +297,7 @@ std::string EQ::Net::Packet::ToString(size_t line_length) const
|
|||||||
ret += fmt::format("{:0>5x} |", i * line_length);
|
ret += fmt::format("{:0>5x} |", i * line_length);
|
||||||
std::string hex;
|
std::string hex;
|
||||||
std::string ascii;
|
std::string ascii;
|
||||||
for (size_t j = 0; j < line_length; ++j) {
|
for (uint64_t j = 0; j < line_length; ++j) {
|
||||||
hex += fmt::format(" {:0>2x}", (uint8_t)data[(i * line_length) + j]);
|
hex += fmt::format(" {:0>2x}", (uint8_t)data[(i * line_length) + j]);
|
||||||
ascii += fmt::format("{}", ToSafePrint(data[(i * line_length) + j]));
|
ascii += fmt::format("{}", ToSafePrint(data[(i * line_length) + j]));
|
||||||
}
|
}
|
||||||
@ -311,17 +311,17 @@ std::string EQ::Net::Packet::ToString(size_t line_length) const
|
|||||||
if (Length() % line_length > 0) {
|
if (Length() % line_length > 0) {
|
||||||
ret += fmt::format("{:0>5x} |", i * line_length);
|
ret += fmt::format("{:0>5x} |", i * line_length);
|
||||||
|
|
||||||
size_t non_blank_count = Length() % line_length;
|
uint64_t non_blank_count = Length() % line_length;
|
||||||
size_t blank_count = line_length - non_blank_count;
|
uint64_t blank_count = line_length - non_blank_count;
|
||||||
std::string hex;
|
std::string hex;
|
||||||
std::string ascii;
|
std::string ascii;
|
||||||
|
|
||||||
for (size_t j = 0; j < non_blank_count; ++j) {
|
for (uint64_t j = 0; j < non_blank_count; ++j) {
|
||||||
hex += fmt::format(" {:0>2x}", (uint8_t)data[(i * line_length) + j]);
|
hex += fmt::format(" {:0>2x}", (uint8_t)data[(i * line_length) + j]);
|
||||||
ascii += fmt::format("{}", ToSafePrint(data[(i * line_length) + j]));
|
ascii += fmt::format("{}", ToSafePrint(data[(i * line_length) + j]));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t j = 0; j < blank_count; ++j) {
|
for (uint64_t j = 0; j < blank_count; ++j) {
|
||||||
hex += " ";
|
hex += " ";
|
||||||
ascii += " ";
|
ascii += " ";
|
||||||
}
|
}
|
||||||
@ -335,11 +335,12 @@ std::string EQ::Net::Packet::ToString(size_t line_length) const
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EQ::Net::StaticPacket::Resize(size_t new_size)
|
bool EQ::Net::StaticPacket::Resize(uint64_t new_size)
|
||||||
{
|
{
|
||||||
if (new_size > m_max_data_length) {
|
if (new_size > m_max_data_length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_data_length = new_size;
|
m_data_length = new_size;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,24 +18,24 @@ namespace EQ {
|
|||||||
|
|
||||||
virtual const void *Data() const = 0;
|
virtual const void *Data() const = 0;
|
||||||
virtual void *Data() = 0;
|
virtual void *Data() = 0;
|
||||||
virtual size_t Length() const = 0;
|
virtual uint64_t Length() const = 0;
|
||||||
virtual size_t Length() = 0;
|
virtual uint64_t Length() = 0;
|
||||||
virtual bool Clear() = 0;
|
virtual bool Clear() = 0;
|
||||||
virtual bool Resize(size_t new_size) = 0;
|
virtual bool Resize(uint64_t new_size) = 0;
|
||||||
virtual void Reserve(size_t new_size) = 0;
|
virtual void Reserve(uint64_t new_size) = 0;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T GetSerialize(size_t offset) const
|
T GetSerialize(uint64_t offset) const
|
||||||
{
|
{
|
||||||
T ret;
|
T ret;
|
||||||
Util::MemoryStreamReader reader(((char*)Data() + offset), Length());
|
Util::MemoryStreamReader reader(((char*)Data() + offset), (size_t)Length());
|
||||||
cereal::BinaryInputArchive input(reader);
|
cereal::BinaryInputArchive input(reader);
|
||||||
input(ret);
|
input(ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void PutSerialize(size_t offset, const T &value) {
|
void PutSerialize(uint64_t offset, const T &value) {
|
||||||
m_stream.clear();
|
m_stream.clear();
|
||||||
cereal::BinaryOutputArchive output(m_stream);
|
cereal::BinaryOutputArchive output(m_stream);
|
||||||
output(value);
|
output(value);
|
||||||
@ -50,36 +50,36 @@ namespace EQ {
|
|||||||
memcpy((char*)Data() + offset, &str[0], str.length());
|
memcpy((char*)Data() + offset, &str[0], str.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
void PutInt8(size_t offset, int8_t value);
|
void PutInt8(uint64_t offset, int8_t value);
|
||||||
void PutInt16(size_t offset, int16_t value);
|
void PutInt16(uint64_t offset, int16_t value);
|
||||||
void PutInt32(size_t offset, int32_t value);
|
void PutInt32(uint64_t offset, int32_t value);
|
||||||
void PutInt64(size_t offset, int64_t value);
|
void PutInt64(uint64_t offset, int64_t value);
|
||||||
void PutUInt8(size_t offset, uint8_t value);
|
void PutUInt8(uint64_t offset, uint8_t value);
|
||||||
void PutUInt16(size_t offset, uint16_t value);
|
void PutUInt16(uint64_t offset, uint16_t value);
|
||||||
void PutUInt32(size_t offset, uint32_t value);
|
void PutUInt32(uint64_t offset, uint32_t value);
|
||||||
void PutUInt64(size_t offset, uint64_t value);
|
void PutUInt64(uint64_t offset, uint64_t value);
|
||||||
void PutFloat(size_t offset, float value);
|
void PutFloat(uint64_t offset, float value);
|
||||||
void PutDouble(size_t offset, double value);
|
void PutDouble(uint64_t offset, double value);
|
||||||
void PutString(size_t offset, const std::string &str);
|
void PutString(uint64_t offset, const std::string &str);
|
||||||
void PutCString(size_t offset, const char *str);
|
void PutCString(uint64_t offset, const char *str);
|
||||||
void PutPacket(size_t offset, const Packet &p);
|
void PutPacket(uint64_t offset, const Packet &p);
|
||||||
void PutData(size_t offset, void *data, size_t length);
|
void PutData(uint64_t offset, void *data, uint64_t length);
|
||||||
|
|
||||||
int8_t GetInt8(size_t offset) const;
|
int8_t GetInt8(uint64_t offset) const;
|
||||||
int16_t GetInt16(size_t offset) const;
|
int16_t GetInt16(uint64_t offset) const;
|
||||||
int32_t GetInt32(size_t offset) const;
|
int32_t GetInt32(uint64_t offset) const;
|
||||||
int64_t GetInt64(size_t offset) const;
|
int64_t GetInt64(uint64_t offset) const;
|
||||||
uint8_t GetUInt8(size_t offset) const;
|
uint8_t GetUInt8(uint64_t offset) const;
|
||||||
uint16_t GetUInt16(size_t offset) const;
|
uint16_t GetUInt16(uint64_t offset) const;
|
||||||
uint32_t GetUInt32(size_t offset) const;
|
uint32_t GetUInt32(uint64_t offset) const;
|
||||||
uint64_t GetUInt64(size_t offset) const;
|
uint64_t GetUInt64(uint64_t offset) const;
|
||||||
float GetFloat(size_t offset) const;
|
float GetFloat(uint64_t offset) const;
|
||||||
double GetDouble(size_t offset) const;
|
double GetDouble(uint64_t offset) const;
|
||||||
std::string GetString(size_t offset, size_t length) const;
|
std::string GetString(uint64_t offset, uint64_t length) const;
|
||||||
std::string GetCString(size_t offset) const;
|
std::string GetCString(uint64_t offset) const;
|
||||||
|
|
||||||
std::string ToString() const;
|
std::string ToString() const;
|
||||||
std::string ToString(size_t line_length) const;
|
std::string ToString(uint64_t line_length) const;
|
||||||
protected:
|
protected:
|
||||||
std::stringstream m_stream;
|
std::stringstream m_stream;
|
||||||
};
|
};
|
||||||
@ -87,7 +87,7 @@ namespace EQ {
|
|||||||
class StaticPacket : public Packet
|
class StaticPacket : public Packet
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
StaticPacket(void *data, size_t size) { m_data = data; m_data_length = size; m_max_data_length = size; }
|
StaticPacket(void *data, uint64_t size) { m_data = data; m_data_length = size; m_max_data_length = size; }
|
||||||
virtual ~StaticPacket() { }
|
virtual ~StaticPacket() { }
|
||||||
StaticPacket(const StaticPacket &o) { m_data = o.m_data; m_data_length = o.m_data_length; }
|
StaticPacket(const StaticPacket &o) { m_data = o.m_data; m_data_length = o.m_data_length; }
|
||||||
StaticPacket& operator=(const StaticPacket &o) { m_data = o.m_data; m_data_length = o.m_data_length; return *this; }
|
StaticPacket& operator=(const StaticPacket &o) { m_data = o.m_data; m_data_length = o.m_data_length; return *this; }
|
||||||
@ -95,16 +95,16 @@ namespace EQ {
|
|||||||
|
|
||||||
virtual const void *Data() const { return m_data; }
|
virtual const void *Data() const { return m_data; }
|
||||||
virtual void *Data() { return m_data; }
|
virtual void *Data() { return m_data; }
|
||||||
virtual size_t Length() const { return m_data_length; }
|
virtual uint64_t Length() const { return m_data_length; }
|
||||||
virtual size_t Length() { return m_data_length; }
|
virtual uint64_t Length() { return m_data_length; }
|
||||||
virtual bool Clear() { return false; }
|
virtual bool Clear() { return false; }
|
||||||
virtual bool Resize(size_t new_size);
|
virtual bool Resize(uint64_t new_size);
|
||||||
virtual void Reserve(size_t new_size) { }
|
virtual void Reserve(uint64_t new_size) { }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void *m_data;
|
void *m_data;
|
||||||
size_t m_data_length;
|
uint64_t m_data_length;
|
||||||
size_t m_max_data_length;
|
uint64_t m_max_data_length;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DynamicPacket : public Packet
|
class DynamicPacket : public Packet
|
||||||
@ -118,11 +118,11 @@ namespace EQ {
|
|||||||
|
|
||||||
virtual const void *Data() const { return &m_data[0]; }
|
virtual const void *Data() const { return &m_data[0]; }
|
||||||
virtual void *Data() { return &m_data[0]; }
|
virtual void *Data() { return &m_data[0]; }
|
||||||
virtual size_t Length() const { return m_data.size(); }
|
virtual uint64_t Length() const { return m_data.size(); }
|
||||||
virtual size_t Length() { return m_data.size(); }
|
virtual uint64_t Length() { return m_data.size(); }
|
||||||
virtual bool Clear() { m_data.clear(); return true; }
|
virtual bool Clear() { m_data.clear(); return true; }
|
||||||
virtual bool Resize(size_t new_size) { m_data.resize(new_size, 0); return true; }
|
virtual bool Resize(uint64_t new_size) { m_data.resize((size_t)new_size, 0); return true; }
|
||||||
virtual void Reserve(size_t new_size) { m_data.reserve(new_size); }
|
virtual void Reserve(uint64_t new_size) { m_data.reserve((size_t)new_size); }
|
||||||
protected:
|
protected:
|
||||||
std::vector<char> m_data;
|
std::vector<char> m_data;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user