Finished implementing, now for the testing phase.
This commit is contained in:
183
src/io/socket/ehc/NetChannel.cpp
Normal file
183
src/io/socket/ehc/NetChannel.cpp
Normal file
@@ -0,0 +1,183 @@
|
||||
#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");
|
||||
|
||||
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->GetHashId() == internalSys)
|
||||
return false;
|
||||
|
||||
if (HasSystem(sys->GetHashId()))
|
||||
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 sysHashId) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < systems.Size(); ++i)
|
||||
if (systems[i]->GetHashId() == sysHashId)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NetChannel::HasSystem(const Str_8& sysId) const
|
||||
{
|
||||
return HasSystem(sysId.Hash_64());
|
||||
}
|
||||
|
||||
NetSys* NetChannel::GetSystem(const UInt_64 sysHashId) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < systems.Size(); ++i)
|
||||
if (systems[i]->GetHashId() == sysHashId)
|
||||
return systems[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NetSys* NetChannel::GetSystem(const Str_8& sysId) const
|
||||
{
|
||||
return GetSystem(sysId.Hash_64());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user