From b1829e929e641d5f9f0a96a353f368b521d4f2c1 Mon Sep 17 00:00:00 2001 From: Uleat Date: Fri, 12 Jun 2015 19:25:43 -0400 Subject: [PATCH] Updated SessionStats methodology --- changelog.txt | 3 +++ common/eq_stream.cpp | 42 ++++++++++++++++++++++++++---------------- common/eq_stream.h | 20 +++++++++++++++++++- 3 files changed, 48 insertions(+), 17 deletions(-) diff --git a/changelog.txt b/changelog.txt index d97f20459..6c42a23ca 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,8 @@ EQEMu Changelog (Started on Sept 24, 2003 15:50) ------------------------------------------------------- +== 06/12/2015 == +Uleat: Adjusted SessionStats to better reflect a sister implementation + == 06/07/2015 == Uleat: Implemented optional rule for using disenchanted bags. Action triggers at the same point that temporary items are removed. Optional SQL: utils/sql/git/optional/2015_06_07_TransformSummonedBagsRule.sql diff --git a/common/eq_stream.cpp b/common/eq_stream.cpp index c48cba0fd..3438f533c 100644 --- a/common/eq_stream.cpp +++ b/common/eq_stream.cpp @@ -72,6 +72,8 @@ void EQStream::init(bool resetSession) { RateThreshold=RATEBASE/250; DecayRate=DECAYBASE/250; BytesWritten=0; + sent_packet_count = 0; + received_packet_count = 0; SequencedBase = 0; NextSequencedSend = 0; @@ -464,37 +466,45 @@ void EQStream::ProcessPacket(EQProtocolPacket *p) } break; case OP_SessionStatRequest: { - if(p->Size() < sizeof(SessionStats)) + if(p->Size() < sizeof(ClientSessionStats)) { Log.Out(Logs::Detail, Logs::Netcode, _L "Received OP_SessionStatRequest that was of malformed size" __L); break; } #ifndef COLLECTOR - SessionStats *Stats=(SessionStats *)p->pBuffer; + ClientSessionStats *ClientStats=(ClientSessionStats *)p->pBuffer; Log.Out(Logs::Detail, Logs::Netcode, _L "Received Stats: %lu packets received, %lu packets sent, Deltas: local %lu, (%lu <- %lu -> %lu) remote %lu" __L, - (unsigned long)ntohl(Stats->packets_received), (unsigned long)ntohl(Stats->packets_sent), (unsigned long)ntohl(Stats->last_local_delta), - (unsigned long)ntohl(Stats->low_delta), (unsigned long)ntohl(Stats->average_delta), - (unsigned long)ntohl(Stats->high_delta), (unsigned long)ntohl(Stats->last_remote_delta)); - uint64 x=Stats->packets_received; - Stats->packets_received=Stats->packets_sent; - Stats->packets_sent=x; - NonSequencedPush(new EQProtocolPacket(OP_SessionStatResponse,p->pBuffer,p->size)); - AdjustRates(ntohl(Stats->average_delta)); + (unsigned long)ntohl(ClientStats->packets_received), (unsigned long)ntohl(ClientStats->packets_sent), (unsigned long)ntohl(ClientStats->last_local_delta), + (unsigned long)ntohl(ClientStats->low_delta), (unsigned long)ntohl(ClientStats->average_delta), + (unsigned long)ntohl(ClientStats->high_delta), (unsigned long)ntohl(ClientStats->last_remote_delta)); + + AdjustRates(ntohl(ClientStats->average_delta)); if(GetExecutablePlatform() == ExePlatformWorld || GetExecutablePlatform() == ExePlatformZone) { - if(RETRANSMIT_TIMEOUT_MULT && ntohl(Stats->average_delta)) { + if (RETRANSMIT_TIMEOUT_MULT && ntohl(ClientStats->average_delta)) { //recalculate retransmittimeout using the larger of the last rtt or average rtt, which is multiplied by the rule value - if((ntohl(Stats->last_local_delta) + ntohl(Stats->last_remote_delta)) > (ntohl(Stats->average_delta) * 2)) { - retransmittimeout = (ntohl(Stats->last_local_delta) + ntohl(Stats->last_remote_delta)) + if ((ntohl(ClientStats->last_local_delta) + ntohl(ClientStats->last_remote_delta)) > (ntohl(ClientStats->average_delta) * 2)) { + retransmittimeout = (ntohl(ClientStats->last_local_delta) + ntohl(ClientStats->last_remote_delta)) * RETRANSMIT_TIMEOUT_MULT; } else { - retransmittimeout = ntohl(Stats->average_delta) * 2 * RETRANSMIT_TIMEOUT_MULT; + retransmittimeout = ntohl(ClientStats->average_delta) * 2 * RETRANSMIT_TIMEOUT_MULT; } if(retransmittimeout > RETRANSMIT_TIMEOUT_MAX) retransmittimeout = RETRANSMIT_TIMEOUT_MAX; Log.Out(Logs::Detail, Logs::Netcode, _L "Retransmit timeout recalculated to %dms" __L, retransmittimeout); } } + + ServerSessionStats *ServerStats = (ServerSessionStats *)p->pBuffer; + + //ServerStats->RequestID = ClientStats->RequestID; // no change + ServerStats->ServerTime = htonl(Timer::GetCurrentTime()); + ServerStats->packets_sent_echo = ClientStats->packets_sent; // still in htonll format + ServerStats->packets_received_echo = ClientStats->packets_received; // still in htonll format + ServerStats->packets_sent = htonll(GetPacketsSent()); + ServerStats->packets_received = htonll(GetPacketsReceived()); + + NonSequencedPush(new EQProtocolPacket(OP_SessionStatResponse, p->pBuffer, p->size)); #endif } break; @@ -1103,8 +1113,8 @@ EQProtocolPacket *p=nullptr; void EQStream::Process(const unsigned char *buffer, const uint32 length) { -static unsigned char newbuffer[2048]; -uint32 newlength=0; + static unsigned char newbuffer[2048]; + uint32 newlength=0; if (EQProtocolPacket::ValidateCRC(buffer,length,Key)) { if (compressed) { newlength=EQProtocolPacket::Decompress(buffer,length,newbuffer,2048); diff --git a/common/eq_stream.h b/common/eq_stream.h index 72eb53cdd..0bdfeab53 100644 --- a/common/eq_stream.h +++ b/common/eq_stream.h @@ -71,7 +71,7 @@ struct SessionResponse { }; //Deltas are in ms, representing round trip times -struct SessionStats { +struct ClientSessionStats { /*000*/ uint16 RequestID; /*002*/ uint32 last_local_delta; /*006*/ uint32 average_delta; @@ -83,6 +83,16 @@ struct SessionStats { /*038*/ }; +struct ServerSessionStats { +/*000*/ uint16 RequestID; +/*002*/ uint32 ServerTime; +/*006*/ uint64 packets_sent_echo; +/*014*/ uint64 packets_received_echo; +/*022*/ uint64 packets_sent; +/*030*/ uint64 packets_received; +/*038*/ +}; + #pragma pack() class OpcodeManager; @@ -158,6 +168,9 @@ class EQStream : public EQStreamInterface { int32 BytesWritten; + uint64 sent_packet_count; + uint64 received_packet_count; + Mutex MRate; int32 RateThreshold; int32 DecayRate; @@ -265,11 +278,13 @@ class EQStream : public EQStreamInterface { void AddBytesSent(uint32 bytes) { bytes_sent += bytes; + ++sent_packet_count; } void AddBytesRecv(uint32 bytes) { bytes_recv += bytes; + ++received_packet_count; } virtual const uint32 GetBytesSent() const { return bytes_sent; } @@ -288,6 +303,9 @@ class EQStream : public EQStreamInterface { return bytes_recv / (Timer::GetTimeSeconds() - create_time); } + const uint64 GetPacketsSent() { return sent_packet_count; } + const uint64 GetPacketsReceived() { return received_packet_count; } + //used for dynamic stream identification class Signature { public: