Leviathan  0.8.0.0
Leviathan game engine
CommandHandler.h
Go to the documentation of this file.
1 // Leviathan Game Engine
2 // Copyright (c) 2012-2017 Henri Hyyryläinen
3 #pragma once
4 // ------------------------------------ //
5 #include "Define.h"
6 // ------------------------------------ //
7 #include "CustomCommandHandler.h"
8 
9 #include <list>
10 #include <memory>
11 #include <vector>
12 
13 
14 namespace Leviathan{
15 
19 };
20 
25 public:
26 
29  DLLEXPORT virtual const std::string& GetUniqueName() = 0;
30 
33  DLLEXPORT virtual const std::string& GetNickname() = 0;
34 
35 
38 
41  DLLEXPORT virtual void SendPrivateMessage(const std::string &message);
42 
43 
50  DLLEXPORT virtual void StartOwnership(CommandHandler* commander);
51 
52 
55  DLLEXPORT virtual void EndOwnership(CommandHandler* which);
56 
57 protected:
58 
62 
63 
67  DLLEXPORT virtual bool _OnSendPrivateMessage(const std::string &message) = 0;
68 
69 
72  std::list<CommandHandler*> CommandHandlersToNotify;
73 };
74 
75 
78 public:
81  DLLEXPORT virtual ~CommandHandler();
82 
83 
84 
86  DLLEXPORT virtual void QueueCommand(const std::string &command, CommandSender* issuer);
87 
88 
93  DLLEXPORT virtual void UpdateStatus();
94 
95 
98  DLLEXPORT virtual void RemoveMe(CommandSender* object);
99 
100 
105  DLLEXPORT virtual bool IsSenderStillValid(CommandSender* checkthis);
106 
107 
110  DLLEXPORT virtual void SenderNoLongerRequired(CommandSender* checkthis);
111 
112 
117  DLLEXPORT virtual bool RegisterCustomCommandHandler(
118  std::shared_ptr<CustomCommandHandler> handler);
119 
120 
121  // ------------------ The default command handler part ------------------ //
122 
124  DLLEXPORT virtual bool IsThisDefaultCommand(const std::string &firstword) const;
125 
126 
127  DLLEXPORT static CommandHandler* Get();
128 
129 protected:
130 
132  void _LetGoOfAll();
133 
135  void _AddSender(CommandSender* object);
136 
137  // ------------------------------------ //
138 
139 
141  std::list<CommandSender*> SendersInUse;
142 
143 
146 
147 
149  std::vector<std::shared_ptr<CustomCommandHandler>> CustomHandlers;
150 
151 
153  static CommandHandler* Staticaccess;
154 };
155 
156 }
157 
158 #ifdef LEAK_INTO_GLOBAL
161 #endif
162 
virtual DLLEXPORT void EndOwnership(CommandHandler *which)
Marks the end of ownership, it is no longer required to report that this object is released...
virtual DLLEXPORT void StartOwnership(CommandHandler *commander)
Marks the start of a time period during which this object needs to report if it is released...
COMMANDSENDER_PERMISSIONMODE
virtual DLLEXPORT void _OnReleaseParentCommanders()
Call when releasing, this is only required if StartOwnership and EndOwnership aren&#39;t overloaded...
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 na...
std::list< CommandHandler * > CommandHandlersToNotify
static CommandHandler * Staticaccess
A static access member for command executing functions.
NetworkServerInterface * Owner
Pointer to the owning interface for fetching various other things.
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...
Represents an entity that can execute commands.
virtual DLLEXPORT COMMANDSENDER_PERMISSIONMODE GetPermissionMode()=0
Returns the permissions model used by this object.
std::vector< std::shared_ptr< CustomCommandHandler > > CustomHandlers
All the custom command providers.
std::list< CommandSender * > SendersInUse
Holds all the command dispatchers who are currently executing commands.
#define DLLEXPORT
Definition: Include.h:118
Class that encapsulates common networking functionality required by server programs.
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
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.
Handles all commands sent by the players on the server.