2024-10-06 20:08:22 -07:00
# pragma once
2024-10-06 22:54:29 -07:00
# include "NetUtils.h"
2025-01-26 21:43:17 -08:00
# include "NetFrag.h"
2024-10-06 20:08:22 -07:00
2024-10-06 22:54:29 -07:00
# include "ehs/Str.h"
# include "ehs/Vector.h"
# include "ehs/Serializer.h"
# include "ehs/io/socket/Socket.h"
2024-10-06 20:08:22 -07:00
namespace ehs
{
2025-01-26 21:43:17 -08:00
class NetServerCh ;
2024-10-06 20:08:22 -07:00
class NetEnd
{
private :
2025-01-26 21:43:17 -08:00
friend class NetServerCh ;
2024-10-06 20:08:22 -07:00
2025-01-26 21:43:17 -08:00
NetServerCh * owner ;
UInt_64 id ;
2024-10-06 20:08:22 -07:00
Str_8 name ;
2025-01-26 21:43:17 -08:00
NetStatus status ;
2024-10-06 20:08:22 -07:00
Char_8 token [ 64 ] ;
UInt_64 nextSendId ;
Vector < Insurance > sent ;
UInt_64 nextRecvId ;
2025-01-26 21:43:17 -08:00
Vector < NetFrag > received ;
Endpoint endpoint ;
2024-10-06 20:08:22 -07:00
float deltaDuration ;
float deltaRate ;
float timeout ;
float lastPing ;
float oldLatency ;
float latency ;
UInt_64 queueSlot ;
public :
NetEnd ( ) ;
2025-01-26 21:43:17 -08:00
NetEnd ( Str_8 id , Endpoint endpoint ) ;
2024-10-06 20:08:22 -07:00
2025-01-26 21:43:17 -08:00
NetEnd ( Endpoint endpoint ) ;
2024-10-06 20:08:22 -07:00
NetEnd ( NetEnd & & end ) noexcept ;
NetEnd ( const NetEnd & end ) ;
NetEnd & operator = ( NetEnd & & end ) noexcept ;
NetEnd & operator = ( const NetEnd & end ) ;
2025-01-26 21:43:17 -08:00
UInt_64 GetId ( ) const ;
2024-10-06 20:08:22 -07:00
Str_8 GetName ( ) const ;
2025-01-26 21:43:17 -08:00
NetStatus GetStatus ( ) const ;
2024-10-06 20:08:22 -07:00
UInt_64 GetNextSendId ( ) const ;
/// Sends data to the remote endpoint.
/// @param [in] deltaLocked Whether or not to match the remote endpoint's delta time to prevent overloading the client. This will drop data if delta time does not match.
2024-10-06 22:54:29 -07:00
/// @param [in] encHashId The hash id of the encryption to use. Can be zero for none.
2024-10-06 20:08:22 -07:00
/// @param [in] ensure Whether or not to ensure the data was received by the remote endpoint.
/// @param [in] sys The system hash id to execute an operation from.
/// @param [in] op The operation hash id in the system to execute.
/// @param [in] payload Additional parameters and data to send to the remote endpoint.
2025-01-26 21:43:17 -08:00
void Send ( bool deltaLocked , UInt_64 encId , bool ensure , UInt_64 sysId , UInt_64 opId , const Serializer < UInt_64 > & payload ) ;
2024-10-06 20:08:22 -07:00
/// Sends data to the remote endpoint.
/// @param [in] deltaLocked Whether or not to match the remote endpoint's delta time to prevent overloading the client. This will drop data if delta time does not match.
2024-10-06 22:54:29 -07:00
/// @param [in] encId The id of the encryption to use. Can be empty for none.
2024-10-06 20:08:22 -07:00
/// @param [in] ensure Whether or not to ensure the data was received by the remote endpoint.
/// @param [in] sys The system string id to execute an operation from.
/// @param [in] op The operation string id in the system to execute.
/// @param [in] payload Additional parameters and data to send to the remote endpoint.
2025-01-26 21:43:17 -08:00
void Send ( bool deltaLocked , const Str_8 & encName , bool ensure , const Str_8 & sysName , const Str_8 & opName , const Serializer < UInt_64 > & payload ) ;
2024-10-06 20:08:22 -07:00
UInt_64 GetNextRecvId ( ) const ;
2025-01-26 21:43:17 -08:00
Endpoint GetEndpoint ( ) const ;
2024-10-06 20:08:22 -07:00
void SetDeltaRate ( float newDeltaRate ) ;
float GetDeltaRate ( ) const ;
float GetTimeout ( ) const ;
float GetLastPing ( ) const ;
void SendLatency ( ) ;
float GetLatency ( ) const ;
UInt_64 GetQueueSlot ( ) const ;
private :
void Poll ( float delta ) ;
2025-01-26 21:43:17 -08:00
void SetStatus ( NetStatus newStatus ) ;
2024-10-06 20:08:22 -07:00
void RemoveInsurance ( UInt_64 msgId , UInt_64 fragment ) ;
void AddReceived ( const Header & header , const Serializer < > & payload ) ;
2025-01-26 21:43:17 -08:00
Vector < NetFrag > * GetReceived ( ) ;
2024-10-06 20:08:22 -07:00
void Ping ( float delta ) ;
void SetLatency ( float newLatency ) ;
void SetQueueSlot ( UInt_64 slot ) ;
2025-01-26 21:43:17 -08:00
NetFrag FragmentData ( const Header & header , const Serializer < > & data ) ;
2024-10-06 20:08:22 -07:00
void Send ( const Header & header , const Serializer < > & payload ) ;
bool SortingNeeded ( ) const ;
void SortReceived ( ) ;
} ;
}