Leviathan  0.8.0.0
Leviathan game engine
Leviathan::CommandSender Class Referenceabstract

Represents an entity that can execute commands. More...

#include <CommandHandler.h>

+ Inheritance diagram for Leviathan::CommandSender:

Public Member Functions

virtual DLLEXPORT const std::string & GetUniqueName ()=0
 Returns the unique name of this entity, this can be something like a steam id or some other static name. More...
 
virtual DLLEXPORT const std::string & GetNickname ()=0
 Returns a friendly name, nickname used to represent this entity. More...
 
virtual DLLEXPORT COMMANDSENDER_PERMISSIONMODE GetPermissionMode ()=0
 Returns the permissions model used by this object. More...
 
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

virtual DLLEXPORT void _OnReleaseParentCommanders ()
 Call when releasing, this is only required if StartOwnership and EndOwnership aren't overloaded. More...
 
virtual DLLEXPORT bool _OnSendPrivateMessage (const std::string &message)=0
 Should be the actual implementation of SendPrivateMessage. More...
 

Protected Attributes

std::list< CommandHandler * > CommandHandlersToNotify
 

Detailed Description

Represents an entity that can execute commands.

All player objects, console etc. should implement this

Definition at line 24 of file CommandHandler.h.

Member Function Documentation

◆ _OnReleaseParentCommanders()

DLLEXPORT void Leviathan::CommandSender::_OnReleaseParentCommanders ( )
protectedvirtual

Call when releasing, this is only required if StartOwnership and EndOwnership aren't overloaded.

Definition at line 226 of file CommandHandler.cpp.

226  {
227 
228  auto end = CommandHandlersToNotify.end();
229  for(auto iter = CommandHandlersToNotify.begin(); iter != end; ++iter){
230 
231  (*iter)->RemoveMe(this);
232  }
233 
234  // Clear all at once for hopefully better performance //
235  CommandHandlersToNotify.clear();
236 }
std::list< CommandHandler * > CommandHandlersToNotify

◆ _OnSendPrivateMessage()

virtual DLLEXPORT bool Leviathan::CommandSender::_OnSendPrivateMessage ( const std::string &  message)
protectedpure virtual

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)

Implemented in Leviathan::ConnectedPlayer.

◆ EndOwnership()

DLLEXPORT void Leviathan::CommandSender::EndOwnership ( CommandHandler which)
virtual

Marks the end of ownership, it is no longer required to report that this object is released.

Definition at line 211 of file CommandHandler.cpp.

211  {
212 
213  // Find the right one and remove it //
214  auto end = CommandHandlersToNotify.end();
215  for(auto iter = CommandHandlersToNotify.begin(); iter != end; ++iter){
216 
217  if(*iter == which){
218 
219  // Remove the match //
220  CommandHandlersToNotify.erase(iter);
221  return;
222  }
223  }
224 }
std::list< CommandHandler * > CommandHandlersToNotify

◆ GetNickname()

virtual DLLEXPORT const std::string& Leviathan::CommandSender::GetNickname ( )
pure virtual

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

Note
This doesn't have to be unique

Implemented in Leviathan::ConnectedPlayer.

◆ GetPermissionMode()

virtual DLLEXPORT COMMANDSENDER_PERMISSIONMODE Leviathan::CommandSender::GetPermissionMode ( )
pure virtual

Returns the permissions model used by this object.

Implemented in Leviathan::ConnectedPlayer.

◆ GetUniqueName()

virtual DLLEXPORT const std::string& Leviathan::CommandSender::GetUniqueName ( )
pure virtual

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

Implemented in Leviathan::ConnectedPlayer.

◆ SendPrivateMessage()

DLLEXPORT void Leviathan::CommandSender::SendPrivateMessage ( const std::string &  message)
virtual

This should send a message to this entity for them to see what happened when they executed a command.

Definition at line 238 of file CommandHandler.cpp.

238  {
239  if(!_OnSendPrivateMessage(message)){
240  // Print to the log as a backup //
241  Logger::Get()->Write("[MESSAGE] => "+GetNickname()+": "+message);
242  }
243 }
DLLEXPORT void Write(const std::string &data) override
Definition: Logger.cpp:113
static DLLEXPORT Logger * Get()
Definition: Logger.cpp:106
virtual DLLEXPORT bool _OnSendPrivateMessage(const std::string &message)=0
Should be the actual implementation of SendPrivateMessage.
virtual DLLEXPORT const std::string & GetNickname()=0
Returns a friendly name, nickname used to represent this entity.

◆ StartOwnership()

DLLEXPORT void Leviathan::CommandSender::StartOwnership ( CommandHandler commander)
virtual

Marks the start of a time period during which this object needs to report if it is released.

Warning
It needs to be notified that calls with the same commander may NOT be ignored as the EndOwnership call of first would end the ownership when in reality the single command handler still wants this object

Definition at line 205 of file CommandHandler.cpp.

205  {
206 
207  // Just add to the list //
208  CommandHandlersToNotify.push_back(commander);
209 }
std::list< CommandHandler * > CommandHandlersToNotify

Member Data Documentation

◆ CommandHandlersToNotify

std::list<CommandHandler*> Leviathan::CommandSender::CommandHandlersToNotify
protected

Holds the command handler parents that we need to notify

Note
This might hold multiple instances

Definition at line 72 of file CommandHandler.h.


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