mirror of
https://github.com/EQEmu/Server.git
synced 2026-09-03 13:36:36 +00:00
Streams work on all of the servers now
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef EQSTREAMIDENT_H_
|
||||
#define EQSTREAMIDENT_H_
|
||||
|
||||
#include "eq_stream.h"
|
||||
#include "eq_stream_intf.h"
|
||||
#include "timer.h"
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <string>
|
||||
#include "emu_versions.h"
|
||||
#include "eq_packet.h"
|
||||
|
||||
typedef enum {
|
||||
ESTABLISHED,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
|
||||
#include "global_define.h"
|
||||
#include "eq_stream_proxy.h"
|
||||
#include "eq_stream.h"
|
||||
#include "struct_strategy.h"
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
#include "types.h"
|
||||
#include "eq_stream_intf.h"
|
||||
#include "eq_stream.h"
|
||||
#include <memory>
|
||||
|
||||
class StructStrategy;
|
||||
|
||||
@@ -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::DaybreakConnection> 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<std::chrono::milliseconds>(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<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) {
|
||||
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<std::chrono::milliseconds>(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<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) {
|
||||
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<std::chrono::milliseconds>(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)
|
||||
|
||||
@@ -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<DaybreakConnection> 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;
|
||||
};
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#include <stdarg.h>
|
||||
#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) {
|
||||
|
||||
@@ -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 <map>
|
||||
#include <memory>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user