Leviathan  0.8.0.0
Leviathan game engine
Leviathan::ConnectedPlayer Class Reference

A class that represents a human player. More...

#include <ConnectedPlayer.h>

+ Inheritance diagram for Leviathan::ConnectedPlayer:

Public Member Functions

DLLEXPORT ConnectedPlayer (std::shared_ptr< Connection > connection, NetworkServerInterface *owninginstance, int plyid)
 
DLLEXPORT ~ConnectedPlayer ()
 Empty destructor for exporting. More...
 
DLLEXPORT bool IsConnectionYours (Connection *checkconnection)
 Checks is the given connection same as ours. More...
 
DLLEXPORT bool IsConnectionClosed () const
 
DLLEXPORT void OnKicked (const std::string &reason)
 Call this when the player is kicked. More...
 
DLLEXPORT void StartHeartbeats ()
 Starts requiring the player to send heartbeats. More...
 
DLLEXPORT void HeartbeatReceived ()
 Call this when a heartbeat is received. More...
 
DLLEXPORT void UpdateHeartbeats ()
 Call this at any appropriate time to update heartbeat statistics. More...
 
std::shared_ptr< ConnectionGetConnection ()
 
int GetID () const
 Gets the unique identifier of the player, valid for this session. More...
 
DLLEXPORT ObjectID GetPositionInWorld (GameWorld *world) const
 Returns the object that contains this players position in a certain world or 0. More...
 
const std::string & GetUniqueName () override
 Returns the unique name of this entity, this can be something like a steam id or some other static name. More...
 
const std::string & GetNickname () override
 Returns a friendly name, nickname used to represent this entity. More...
 
DLLEXPORT COMMANDSENDER_PERMISSIONMODE GetPermissionMode () override
 Returns the permissions model used by this object. More...
 
- Public Member Functions inherited from Leviathan::CommandSender
virtual DLLEXPORT void SendPrivateMessage (const std::string &message)
 This should send a message to this entity for them to see what happened when they executed a command. More...
 
virtual DLLEXPORT void StartOwnership (CommandHandler *commander)
 Marks the start of a time period during which this object needs to report if it is released. More...
 
virtual DLLEXPORT void EndOwnership (CommandHandler *which)
 Marks the end of ownership, it is no longer required to report that this object is released. More...
 

Protected Member Functions

DLLEXPORT bool _OnSendPrivateMessage (const std::string &message) override
 Should be the actual implementation of SendPrivateMessage. More...
 
- Protected Member Functions inherited from Leviathan::CommandSender
virtual DLLEXPORT void _OnReleaseParentCommanders ()
 Call when releasing, this is only required if StartOwnership and EndOwnership aren't overloaded. More...
 

Protected Attributes

std::shared_ptr< ConnectionCorrespondingConnection
 
NetworkServerInterfaceOwner
 
bool UsingHeartbeats
 Marks whether heartbeats are in use. More...
 
std::string UniqueName
 The unique identifier of the player, might be a steam id or something else. More...
 
std::string DisplayName
 The display name of the player. More...
 
bool IsControlLost
 
float SecondsWithoutConnection
 How long it has been since a heartbeat. More...
 
WantedClockType::time_point LastSentHeartbeat
 The last time a heartbeat was sent. More...
 
WantedClockType::time_point LastReceivedHeartbeat
 The last time a heartbeat packet was received. More...
 
int ID
 The unique identifier for this player, lasts only this session. More...
 
- Protected Attributes inherited from Leviathan::CommandSender
std::list< CommandHandler * > CommandHandlersToNotify
 

Detailed Description

A class that represents a human player.

Todo:
Add a kick method and use it in NetworkServerInterface::CloseDownServer

Definition at line 17 of file ConnectedPlayer.h.

Constructor & Destructor Documentation

◆ ConnectedPlayer()

ConnectedPlayer::ConnectedPlayer ( std::shared_ptr< Connection connection,
NetworkServerInterface owninginstance,
int  plyid 
)

Definition at line 8 of file ConnectedPlayer.cpp.

9  :
10  CorrespondingConnection(connection), Owner(owninginstance), UsingHeartbeats(false),
11  IsControlLost(false), SecondsWithoutConnection(0.f), ID(plyid)
12 {
13 }
NetworkServerInterface * Owner
float SecondsWithoutConnection
How long it has been since a heartbeat.
int ID
The unique identifier for this player, lasts only this session.
bool UsingHeartbeats
Marks whether heartbeats are in use.
std::shared_ptr< Connection > CorrespondingConnection

◆ ~ConnectedPlayer()

DLLEXPORT ConnectedPlayer::~ConnectedPlayer ( )

Empty destructor for exporting.

Definition at line 15 of file ConnectedPlayer.cpp.

15  {
16 
18 }
virtual DLLEXPORT void _OnReleaseParentCommanders()
Call when releasing, this is only required if StartOwnership and EndOwnership aren&#39;t overloaded...

Member Function Documentation

◆ _OnSendPrivateMessage()

DLLEXPORT bool ConnectedPlayer::_OnSendPrivateMessage ( const std::string &  message)
overrideprotectedvirtual

Should be the actual implementation of SendPrivateMessage.

Returns
Return false when unable to send (the message will them appear in the server log where someone hopefully will see it)

Implements Leviathan::CommandSender.

Definition at line 105 of file ConnectedPlayer.cpp.

105  {
106 
107  Logger::Get()->Write("Probably should implement a ChatManager");
108  return false;
109 }
DLLEXPORT void Write(const std::string &data) override
Definition: Logger.cpp:113
static DLLEXPORT Logger * Get()
Definition: Logger.cpp:106

◆ GetConnection()

std::shared_ptr<Connection> Leviathan::ConnectedPlayer::GetConnection ( )
inline

Definition at line 45 of file ConnectedPlayer.h.

45  {
47  }
std::shared_ptr< Connection > CorrespondingConnection

◆ GetID()

int Leviathan::ConnectedPlayer::GetID ( ) const
inline

Gets the unique identifier of the player, valid for this session.

Definition at line 50 of file ConnectedPlayer.h.

50  {
51  return ID;
52  }
int ID
The unique identifier for this player, lasts only this session.

◆ GetNickname()

const std::string& Leviathan::ConnectedPlayer::GetNickname ( )
inlineoverridevirtual

Returns a friendly name, nickname used to represent this entity.

Note
This doesn't have to be unique

Implements Leviathan::CommandSender.

Definition at line 63 of file ConnectedPlayer.h.

63  {
64  return DisplayName;
65  }
std::string DisplayName
The display name of the player.

◆ GetPermissionMode()

DLLEXPORT COMMANDSENDER_PERMISSIONMODE ConnectedPlayer::GetPermissionMode ( )
overridevirtual

Returns the permissions model used by this object.

Implements Leviathan::CommandSender.

Definition at line 101 of file ConnectedPlayer.cpp.

◆ GetPositionInWorld()

DLLEXPORT ObjectID ConnectedPlayer::GetPositionInWorld ( GameWorld world) const

Returns the object that contains this players position in a certain world or 0.

Definition at line 111 of file ConnectedPlayer.cpp.

113 {
114  // Not found for that world //
115  return 0;
116 }

◆ GetUniqueName()

const std::string& Leviathan::ConnectedPlayer::GetUniqueName ( )
inlineoverridevirtual

Returns the unique name of this entity, this can be something like a steam id or some other static name.

Implements Leviathan::CommandSender.

Definition at line 59 of file ConnectedPlayer.h.

59  {
60  return UniqueName;
61  }
std::string UniqueName
The unique identifier of the player, might be a steam id or something else.

◆ HeartbeatReceived()

DLLEXPORT void ConnectedPlayer::HeartbeatReceived ( )

Call this when a heartbeat is received.

Definition at line 59 of file ConnectedPlayer.cpp.

59  {
60  // Reset all timers //
61 
63 
64  // Re-acquire controls, if lost in the first place //
65  if(IsControlLost){
66 
67 
68  IsControlLost = false;
69  }
70 
71 }
static DLLEXPORT WantedClockType::time_point GetThreadSafeSteadyTimePoint()
WantedClockType::time_point LastReceivedHeartbeat
The last time a heartbeat packet was received.

◆ IsConnectionClosed()

DLLEXPORT bool ConnectedPlayer::IsConnectionClosed ( ) const
Returns
True if this player's connection is closed and this object should be disposed of

Definition at line 25 of file ConnectedPlayer.cpp.

25  {
26  return CorrespondingConnection ? !CorrespondingConnection->IsValidForSend() : true;
27 }
std::shared_ptr< Connection > CorrespondingConnection

◆ IsConnectionYours()

DLLEXPORT bool Leviathan::ConnectedPlayer::IsConnectionYours ( Connection checkconnection)

Checks is the given connection same as ours.

Definition at line 20 of file ConnectedPlayer.cpp.

20  {
21 
22  return CorrespondingConnection.get() == checkconnection;
23 }
std::shared_ptr< Connection > CorrespondingConnection

◆ OnKicked()

DLLEXPORT void ConnectedPlayer::OnKicked ( const std::string &  reason)

Call this when the player is kicked.

Todo:
Add the reason to the packet

Definition at line 29 of file ConnectedPlayer.cpp.

29  {
30 
31  // Send a close connection packet //
32 
34 
35  // \todo Add the reason here
36  CorrespondingConnection->SendCloseConnectionPacket();
37  }
38 
39 
40  // Broadcast a kick message on the server here //
41 
42 }
std::shared_ptr< Connection > CorrespondingConnection

◆ StartHeartbeats()

DLLEXPORT void ConnectedPlayer::StartHeartbeats ( )

Starts requiring the player to send heartbeats.

Definition at line 44 of file ConnectedPlayer.cpp.

44  {
45 
46  // Send a start packet //
47 
48  DEBUG_BREAK;
49  //ResponseStartHeartbeats;
50 
51  // Reset our variables //
52  UsingHeartbeats = true;
53 
57 }
static DLLEXPORT WantedClockType::time_point GetThreadSafeSteadyTimePoint()
float SecondsWithoutConnection
How long it has been since a heartbeat.
WantedClockType::time_point LastSentHeartbeat
The last time a heartbeat was sent.
bool UsingHeartbeats
Marks whether heartbeats are in use.
WantedClockType::time_point LastReceivedHeartbeat
The last time a heartbeat packet was received.

◆ UpdateHeartbeats()

DLLEXPORT void ConnectedPlayer::UpdateHeartbeats ( )

Call this at any appropriate time to update heartbeat statistics.

Definition at line 73 of file ConnectedPlayer.cpp.

73  {
74  // Skip if not used //
75  if(!UsingHeartbeats)
76  return;
77 
78  // Check do we need to send one //
79  auto timenow = Time::GetThreadSafeSteadyTimePoint();
80 
82 
83  // Send one //
84  //ResponseHeartbeat
85  //CorrespondingConnection
86 
87  LastSentHeartbeat = timenow;
88  }
89 
90  // Update the time without a response //
92 
93  // Do something if the time is too high //
94  if(SecondsWithoutConnection >= 2.f){
95 
96 
97  IsControlLost = true;
98  }
99 }
std::chrono::duration< int64_t, std::milli > MillisecondDuration
Definition: TimeIncludes.h:11
static DLLEXPORT WantedClockType::time_point GetThreadSafeSteadyTimePoint()
float SecondsWithoutConnection
How long it has been since a heartbeat.
WantedClockType::time_point LastSentHeartbeat
The last time a heartbeat was sent.
bool UsingHeartbeats
Marks whether heartbeats are in use.
constexpr auto HEARTBEATS_MILLISECOND
Definition: Define.h:28
WantedClockType::time_point LastReceivedHeartbeat
The last time a heartbeat packet was received.
std::chrono::duration< float, std::ratio< 1 > > SecondDuration
Definition: TimeIncludes.h:13

Member Data Documentation

◆ CorrespondingConnection

std::shared_ptr<Connection> Leviathan::ConnectedPlayer::CorrespondingConnection
protected

Definition at line 74 of file ConnectedPlayer.h.

◆ DisplayName

std::string Leviathan::ConnectedPlayer::DisplayName
protected

The display name of the player.

Definition at line 84 of file ConnectedPlayer.h.

◆ ID

int Leviathan::ConnectedPlayer::ID
protected

The unique identifier for this player, lasts only this session.

Definition at line 100 of file ConnectedPlayer.h.

◆ IsControlLost

bool Leviathan::ConnectedPlayer::IsControlLost
protected

Gets set when a heartbeat hasn't been received for a while, this will be set before the player is kicked

Definition at line 88 of file ConnectedPlayer.h.

◆ LastReceivedHeartbeat

WantedClockType::time_point Leviathan::ConnectedPlayer::LastReceivedHeartbeat
protected

The last time a heartbeat packet was received.

Definition at line 97 of file ConnectedPlayer.h.

◆ LastSentHeartbeat

WantedClockType::time_point Leviathan::ConnectedPlayer::LastSentHeartbeat
protected

The last time a heartbeat was sent.

Definition at line 94 of file ConnectedPlayer.h.

◆ Owner

NetworkServerInterface* Leviathan::ConnectedPlayer::Owner
protected

Definition at line 75 of file ConnectedPlayer.h.

◆ SecondsWithoutConnection

float Leviathan::ConnectedPlayer::SecondsWithoutConnection
protected

How long it has been since a heartbeat.

Definition at line 91 of file ConnectedPlayer.h.

◆ UniqueName

std::string Leviathan::ConnectedPlayer::UniqueName
protected

The unique identifier of the player, might be a steam id or something else.

Definition at line 81 of file ConnectedPlayer.h.

◆ UsingHeartbeats

bool Leviathan::ConnectedPlayer::UsingHeartbeats
protected

Marks whether heartbeats are in use.

Definition at line 78 of file ConnectedPlayer.h.


The documentation for this class was generated from the following files: