193 lines
4.1 KiB
C++
193 lines
4.1 KiB
C++
#include "ehs/io/socket/ehc/NetChannel.h"
|
|
#include "ehs/io/socket/ehc/NetEnd.h"
|
|
#include "ehs/io/socket/ehc/NetSys.h"
|
|
#include "ehs/io/socket/EHC.h"
|
|
#include "ehs/PRNG.h"
|
|
|
|
namespace ehs
|
|
{
|
|
const UInt_64 NetChannel::internalSys = Str_8::Hash_64("Internal");
|
|
const UInt_64 NetChannel::connectOp = Str_8::Hash_64("Connect");
|
|
const UInt_64 NetChannel::connectedOp = Str_8::Hash_64("Connected");
|
|
const UInt_64 NetChannel::rejectedOp = Str_8::Hash_64("Rejected");
|
|
const UInt_64 NetChannel::disconnectOp = Str_8::Hash_64("Disconnect");
|
|
const UInt_64 NetChannel::disconnectedOp = Str_8::Hash_64("Disconnected");
|
|
const UInt_64 NetChannel::statusUpdateOp = Str_8::Hash_64("StatusUpdate");
|
|
const UInt_64 NetChannel::pingOp = Str_8::Hash_64("Ping");
|
|
const UInt_64 NetChannel::pongOp = Str_8::Hash_64("Pong");
|
|
const UInt_64 NetChannel::latencyOp = Str_8::Hash_64("Latency");
|
|
const UInt_64 NetChannel::receivedOp = Str_8::Hash_64("Received");
|
|
|
|
NetChannel::~NetChannel()
|
|
{
|
|
}
|
|
|
|
NetChannel::NetChannel()
|
|
: owner(nullptr), id(0), maxTimeout(5.0f), resendRate(0.5f)
|
|
{
|
|
}
|
|
|
|
NetChannel::NetChannel(Str_8 name, const Version &version)
|
|
: owner(nullptr), id(name.Hash_64()), name((Str_8 &&)name), version(version), maxTimeout(5.0f),
|
|
resendRate(0.5f)
|
|
{
|
|
}
|
|
|
|
NetChannel::NetChannel(NetChannel &&channel) noexcept
|
|
: owner(channel.owner), id(channel.id), name((Str_8 &&)channel.name), version(channel.version),
|
|
maxTimeout(channel.maxTimeout), resendRate(channel.resendRate)
|
|
{
|
|
channel.owner = nullptr;
|
|
channel.id = 0;
|
|
channel.version = {};
|
|
channel.maxTimeout = 5.0f;
|
|
channel.resendRate = 0.5f;
|
|
}
|
|
|
|
NetChannel::NetChannel(const NetChannel &channel)
|
|
: owner(nullptr), id(channel.id), name(channel.name), version(channel.version),
|
|
maxTimeout(channel.maxTimeout), resendRate(channel.resendRate)
|
|
{
|
|
}
|
|
|
|
NetChannel &NetChannel::operator=(NetChannel &&channel) noexcept
|
|
{
|
|
if (this == &channel)
|
|
return *this;
|
|
|
|
owner = channel.owner;
|
|
id = channel.id;
|
|
name = (Str_8 &&)channel.name;
|
|
version = channel.version;
|
|
maxTimeout = channel.maxTimeout;
|
|
resendRate = channel.resendRate;
|
|
|
|
channel.owner = nullptr;
|
|
channel.id = 0;
|
|
channel.version = {};
|
|
channel.maxTimeout = 5.0f;
|
|
channel.resendRate = 0.5f;
|
|
|
|
return *this;
|
|
}
|
|
|
|
NetChannel &NetChannel::operator=(const NetChannel &channel)
|
|
{
|
|
if (this == &channel)
|
|
return *this;
|
|
|
|
owner = nullptr;
|
|
id = channel.id;
|
|
name = channel.name;
|
|
version = channel.version;
|
|
maxTimeout = channel.maxTimeout;
|
|
resendRate = channel.resendRate;
|
|
|
|
return *this;
|
|
}
|
|
|
|
EHC *NetChannel::GetOwner() const
|
|
{
|
|
return owner;
|
|
}
|
|
|
|
UInt_64 NetChannel::GetId() const
|
|
{
|
|
return id;
|
|
}
|
|
|
|
Str_8 NetChannel::GetName() const
|
|
{
|
|
return name;
|
|
}
|
|
|
|
Version NetChannel::GetVersion() const
|
|
{
|
|
return version;
|
|
}
|
|
|
|
void NetChannel::SetMaxTimeout(const float seconds)
|
|
{
|
|
maxTimeout = seconds;
|
|
}
|
|
|
|
float NetChannel::GetMaxTimeout() const
|
|
{
|
|
return maxTimeout;
|
|
}
|
|
|
|
void NetChannel::SetResendRate(const float seconds)
|
|
{
|
|
resendRate = seconds;
|
|
}
|
|
|
|
float NetChannel::GetResendRate() const
|
|
{
|
|
return resendRate;
|
|
}
|
|
|
|
void NetChannel::EnableDropPackets(const bool enable)
|
|
{
|
|
dropPackets = enable;
|
|
}
|
|
|
|
bool NetChannel::IsDropPacketsEnabled() const
|
|
{
|
|
return dropPackets;
|
|
}
|
|
|
|
bool NetChannel::AddSystem(NetSys *sys)
|
|
{
|
|
if (sys->GetId() == internalSys)
|
|
return false;
|
|
|
|
if (HasSystem(sys->GetId()))
|
|
return false;
|
|
|
|
systems.Push(sys);
|
|
|
|
return true;
|
|
}
|
|
|
|
bool NetChannel::IsValid() const
|
|
{
|
|
return owner && id;
|
|
}
|
|
|
|
void NetChannel::Process(const float &delta, const Endpoint &endpoint, const Header &header, Serializer<UInt_64> &payload)
|
|
{
|
|
|
|
}
|
|
|
|
void NetChannel::Poll(const float &delta)
|
|
{
|
|
}
|
|
|
|
bool NetChannel::HasSystem(const UInt_64 sysId) const
|
|
{
|
|
for (UInt_64 i = 0; i < systems.Size(); ++i)
|
|
if (systems[i]->GetId() == sysId)
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
bool NetChannel::HasSystem(const Str_8& sysName) const
|
|
{
|
|
return HasSystem(sysName.Hash_64());
|
|
}
|
|
|
|
NetSys* NetChannel::GetSystem(const UInt_64 sysId) const
|
|
{
|
|
for (UInt_64 i = 0; i < systems.Size(); ++i)
|
|
if (systems[i]->GetId() == sysId)
|
|
return systems[i];
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
NetSys* NetChannel::GetSystem(const Str_8& sysName) const
|
|
{
|
|
return GetSystem(sysName.Hash_64());
|
|
}
|
|
} |