Tweaks from other branch

This commit is contained in:
KimLS
2019-04-16 01:09:25 -07:00
parent 566f743a88
commit cd8ab727aa
11 changed files with 225 additions and 171 deletions
+2 -2
View File
@@ -27,7 +27,6 @@ struct EQStreamManagerInterfaceOptions
EQStreamManagerInterfaceOptions(int port, bool encoded, bool compressed) {
opcode_size = 2;
track_opcode_stats = false;
//World seems to support both compression and xor zone supports one or the others.
//Enforce one or the other in the convienence construct
@@ -54,8 +53,9 @@ public:
EQStreamManagerInterface(const EQStreamManagerInterfaceOptions &options) { m_options = options; }
virtual ~EQStreamManagerInterface() { };
EQStreamManagerInterfaceOptions GetOptions() { return m_options; }
const EQStreamManagerInterfaceOptions& GetOptions() const { return m_options; }
EQStreamManagerInterfaceOptions& MutateOptions() { return m_options; }
virtual void SetOptions(const EQStreamManagerInterfaceOptions& options) = 0;
protected:
EQStreamManagerInterfaceOptions m_options;
};
+13 -1
View File
@@ -368,6 +368,7 @@ void EQ::Net::DaybreakConnection::QueuePacket(Packet &p, int stream, bool reliab
packet.PutUInt8(0, 0);
packet.PutPacket(1, p);
InternalQueuePacket(packet, stream, reliable);
return;
}
InternalQueuePacket(p, stream, reliable);
@@ -384,7 +385,7 @@ EQ::Net::DaybreakConnectionStats EQ::Net::DaybreakConnection::GetStats()
void EQ::Net::DaybreakConnection::ResetStats()
{
m_stats = DaybreakConnectionStats();
m_stats.Reset();
}
void EQ::Net::DaybreakConnection::Process()
@@ -417,6 +418,7 @@ void EQ::Net::DaybreakConnection::ProcessPacket(Packet &p)
auto opcode = p.GetInt8(1);
if (p.GetInt8(0) == 0 && (opcode == OP_KeepAlive || opcode == OP_OutboundPing)) {
m_stats.bytes_after_decode += p.Length();
return;
}
@@ -425,6 +427,8 @@ void EQ::Net::DaybreakConnection::ProcessPacket(Packet &p)
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));
}
m_stats.bytes_after_decode += p.Length();
return;
}
@@ -453,6 +457,7 @@ void EQ::Net::DaybreakConnection::ProcessPacket(Packet &p)
}
}
m_stats.bytes_after_decode += temp.Length();
ProcessDecodedPacket(StaticPacket(temp.Data(), temp.Length()));
}
else {
@@ -471,10 +476,12 @@ void EQ::Net::DaybreakConnection::ProcessPacket(Packet &p)
}
}
m_stats.bytes_after_decode += temp.Length();
ProcessDecodedPacket(StaticPacket(temp.Data(), temp.Length()));
}
}
else {
m_stats.bytes_after_decode += p.Length();
ProcessDecodedPacket(p);
}
}
@@ -1285,6 +1292,9 @@ void EQ::Net::DaybreakConnection::InternalSend(Packet &p)
};
if (PacketCanBeEncoded(p)) {
m_stats.bytes_before_encode += p.Length();
DynamicPacket out;
out.PutPacket(0, p);
@@ -1332,6 +1342,8 @@ void EQ::Net::DaybreakConnection::InternalSend(Packet &p)
return;
}
m_stats.bytes_before_encode += p.Length();
uv_udp_send_t *send_req = new uv_udp_send_t;
sockaddr_in send_addr;
uv_ip4_addr(m_endpoint.c_str(), m_port, &send_addr);
+20
View File
@@ -91,6 +91,24 @@ namespace EQ
resent_fragments = 0;
resent_full = 0;
datarate_remaining = 0.0;
bytes_after_decode = 0;
bytes_before_encode = 0;
}
void Reset() {
recv_bytes = 0;
sent_bytes = 0;
min_ping = 0xFFFFFFFFFFFFFFFFUL;
max_ping = 0;
avg_ping = 0;
created = Clock::now();
dropped_datarate_packets = 0;
resent_packets = 0;
resent_fragments = 0;
resent_full = 0;
datarate_remaining = 0.0;
bytes_after_decode = 0;
bytes_before_encode = 0;
}
uint64_t recv_bytes;
@@ -111,6 +129,8 @@ namespace EQ
uint64_t resent_fragments;
uint64_t resent_full;
double datarate_remaining;
uint64_t bytes_after_decode;
uint64_t bytes_before_encode;
};
class DaybreakConnectionManager;
+9 -6
View File
@@ -13,6 +13,13 @@ EQ::Net::EQStreamManager::~EQStreamManager()
{
}
void EQ::Net::EQStreamManager::SetOptions(const EQStreamManagerInterfaceOptions &options)
{
m_options = options;
auto &opts = m_daybreak.GetOptions();
opts = options.daybreak_options;
}
void EQ::Net::EQStreamManager::DaybreakNewConnection(std::shared_ptr<DaybreakConnection> connection)
{
std::shared_ptr<EQStream> stream(new EQStream(this, connection));
@@ -65,9 +72,7 @@ void EQ::Net::EQStream::QueuePacket(const EQApplicationPacket *p, bool ack_req)
opcode = p->GetOpcodeBypass();
}
else {
if (m_owner->GetOptions().track_opcode_stats) {
m_packet_sent_count[p->GetOpcode()]++; //Wont bother with bypass tracking of these since those are rare for testing anyway
}
m_packet_sent_count[p->GetOpcode()]++; //Wont bother with bypass tracking of these since those are rare for testing anyway
opcode = (*m_opcode_manager)->EmuToEQ(p->GetOpcode());
}
@@ -117,9 +122,7 @@ EQApplicationPacket *EQ::Net::EQStream::PopPacket() {
}
EmuOpcode emu_op = (*m_opcode_manager)->EQToEmu(opcode);
if (m_owner->GetOptions().track_opcode_stats) {
m_packet_recv_count[emu_op]++;
}
m_packet_recv_count[emu_op]++;
EQApplicationPacket *ret = new EQApplicationPacket(emu_op, (unsigned char*)p->Data() + m_owner->GetOptions().opcode_size, p->Length() - m_owner->GetOptions().opcode_size);
ret->SetProtocolOpcode(opcode);
+1
View File
@@ -19,6 +19,7 @@ namespace EQ
EQStreamManager(const EQStreamManagerInterfaceOptions &options);
~EQStreamManager();
virtual void SetOptions(const EQStreamManagerInterfaceOptions& options);
void OnNewConnection(std::function<void(std::shared_ptr<EQStream>)> func) { m_on_new_connection = func; }
void OnConnectionStateChange(std::function<void(std::shared_ptr<EQStream>, DbProtocolStatus, DbProtocolStatus)> func) { m_on_connection_state_change = func; }
private:
+2 -2
View File
@@ -683,10 +683,10 @@ RULE_CATEGORY_END()
RULE_CATEGORY(Network)
RULE_INT(Network, ResendDelayBaseMS, 100)
RULE_REAL(Network, ResendDelayFactor, 1.5)
RULE_INT(Network, ResendDelayMinMS, 100)
RULE_INT(Network, ResendDelayMinMS, 300)
RULE_INT(Network, ResendDelayMaxMS, 5000)
RULE_REAL(Network, ClientDataRate, 0.0) // KB / sec, 0.0 disabled
RULE_BOOL(Network, TrackOpcodeStats, false)
RULE_BOOL(Network, CompressZoneStream, true)
RULE_CATEGORY_END()
RULE_CATEGORY(QueryServ)
+65 -94
View File
@@ -15,109 +15,80 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Serverinfo.cpp - Server information gathering functions, used in #serverinfo - Windows specific
// I'm not sure quite how to get this exact information in *nix, hopefully someone can fill that in
// -T7g
// Implement preliminary support for *nix variants
// misanthropicfiend
#ifdef _WINDOWS
#include <windows.h>
#include "serverinfo.h"
#include <uv.h>
char Ver_name[100];
DWORD Ver_build, Ver_min, Ver_maj, Ver_pid;
size_t EQ::GetRSS()
{
size_t rss = 0;
int GetOS() {
strcpy(Ver_name, "Unknown operating system");
OSVERSIONINFO Ver_os;
Ver_os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if(!(GetVersionEx(&Ver_os))) return 1;
Ver_build = Ver_os.dwBuildNumber & 0xFFFF;
Ver_min = Ver_os.dwMinorVersion;
Ver_maj = Ver_os.dwMajorVersion;
Ver_pid = Ver_os.dwPlatformId;
if ((Ver_pid == 1) && (Ver_maj == 4))
{
if ((Ver_min < 10) && (Ver_build == 950))
{
strcpy(Ver_name, "Microsoft Windows 95");
}
else if ((Ver_min < 10) &&
((Ver_build > 950) && (Ver_build <= 1080)))
{
strcpy(Ver_name, "Microsoft Windows 95 SP1");
}
else if ((Ver_min < 10) && (Ver_build > 1080))
{
strcpy(Ver_name, "Microsoft Windows 95 OSR2");
}
else if ((Ver_min == 10) && (Ver_build == 1998))
{
strcpy(Ver_name, "Microsoft Windows 98");
}
else if ((Ver_min == 10) &&
((Ver_build > 1998) && (Ver_build < 2183)))
{
strcpy(Ver_name, "Microsoft Windows 98, Service Pack 1");
}
else if ((Ver_min == 10) && (Ver_build >= 2183))
{
strcpy(Ver_name, "Microsoft Windows 98 Second Edition");
}
else if (Ver_min == 90)
{
strcpy(Ver_name, "Microsoft Windows ME");
}
}
else if (Ver_pid == 2)
{
if ((Ver_maj == 3) && (Ver_min == 51))
{
strcpy(Ver_name, "Microsoft Windows NT 3.51");
}
else if ((Ver_maj == 4) && (Ver_min == 0))
{
strcpy(Ver_name, "Microsoft Windows NT 4");
}
else if ((Ver_maj == 5) && (Ver_min == 0))
{
strcpy(Ver_name, "Microsoft Windows 2000");
}
else if ((Ver_maj == 5) && (Ver_min == 1))
{
strcpy(Ver_name, "Microsoft Windows XP");
}
else if ((Ver_maj == 5) && (Ver_min == 2))
{
strcpy(Ver_name, "Microsoft Windows 2003");
}
if (0 != uv_resident_set_memory(&rss)) {
return 0;
}
return 0;
return rss;
}
#else
double EQ::GetUptime()
{
double uptime = 0.0;
#include <sys/utsname.h>
#include <stdio.h>
#include <string.h>
char* GetOS(char* os_string) {
utsname info;
if(uname(&info)==0) {
snprintf(os_string, 99, "%s %s %s %s %s", info.sysname, info.nodename, info.release, info.version, info.machine);
} else {
strncpy(os_string, "Error determining OS & version!", 25);
if (0 != uv_uptime(&uptime)) {
return 0.0;
}
return os_string;
return uptime;
}
#endif
size_t EQ::GetPID()
{
return uv_os_getpid();
}
std::vector<eq_cpu_info_t> EQ::GetCPUs()
{
std::vector<eq_cpu_info_t> ret;
uv_cpu_info_t *cpu_info = nullptr;
int count = 0;
if (0 != uv_cpu_info(&cpu_info, &count)) {
return ret;
}
ret.reserve(count);
for (int i = 0; i < count; ++i) {
eq_cpu_info_t r;
auto &entry = cpu_info[i];
r.model = entry.model;
r.speed = entry.speed / 1000.0;
r.time_user = entry.cpu_times.user;
r.time_sys = entry.cpu_times.sys;
r.time_idle = entry.cpu_times.idle;
r.time_nice = entry.cpu_times.nice;
r.time_irq = entry.cpu_times.irq;
ret.push_back(r);
}
uv_free_cpu_info(cpu_info, count);
return ret;
}
eq_utsname_t EQ::GetOS()
{
eq_utsname_t ret;
uv_utsname_t name;
if (0 != uv_os_uname(&name)) {
return ret;
}
ret.machine = name.machine;
ret.release = name.release;
ret.sysname = name.sysname;
ret.version = name.version;
return ret;
}
+28 -10
View File
@@ -15,15 +15,33 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef SERVERINFO_H
#define SERVERINFO_H
#pragma once
#ifdef _WINDOWS
extern char Ver_name[36];
extern DWORD Ver_build, Ver_min, Ver_maj, Ver_pid;
int GetOS();
#else
char* GetOS(char* os_string);
#endif
#include <string>
#include <vector>
#endif
typedef struct eq_cpu_info_s {
std::string model;
double speed;
uint64_t time_user;
uint64_t time_nice;
uint64_t time_sys;
uint64_t time_idle;
uint64_t time_irq;
} eq_cpu_info_t;
typedef struct eq_utsname_s {
std::string sysname;
std::string release;
std::string version;
std::string machine;
} eq_utsname_t;
namespace EQ
{
size_t GetRSS();
double GetUptime();
size_t GetPID();
std::vector<eq_cpu_info_t> GetCPUs();
eq_utsname_t GetOS();
}