Cuberite
A lightweight, fast and extensible game server for Minecraft
Root.h
Go to the documentation of this file.
1 
2 #pragma once
3 
5 #include "Protocol/MojangAPI.h"
6 #include "HTTP/HTTPServer.h"
7 #include "Defines.h"
8 #include "FunctionRef.h"
9 #include "RankManager.h"
10 #include "BlockTypeRegistry.h"
11 
12 
13 
14 
15 
16 // fwd:
17 class cMonsterConfig;
18 class cBrewingRecipes;
19 class cCraftingRecipes;
20 class cFurnaceRecipe;
21 class cWebAdmin;
22 class cPluginManager;
23 class cServer;
24 class cWorld;
25 class cPlayer;
27 class cCompositeChat;
29 class cDeadlockDetect;
30 class cUUID;
31 class BlockTypePalette;
32 class ProtocolPalettes;
33 
36 
37 namespace Json
38 {
39  class Value;
40 }
41 
42 
43 
44 
45 
47 // tolua_begin
48 class cRoot
49 {
50 public:
51  static cRoot * Get() { return s_Root; }
52  // tolua_end
53 
55  static bool m_RunAsService;
56 
59 
60  cRoot(void);
61  ~cRoot();
62 
63  void Start(std::unique_ptr<cSettingsRepositoryInterface> a_OverridesRepo);
64 
66  void StopServer();
67 
68  // tolua_begin
69  cServer * GetServer(void) { return m_Server; }
70  cWorld * GetDefaultWorld(void);
71 
73  cWorld * GetWorld(const AString & a_WorldName);
74 
76  int GetServerUpTime(void)
77  {
78  return static_cast<int>(std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now() - m_StartTime).count());
79  }
80  // tolua_end
81 
83  bool ForEachWorld(cWorldListCallback a_Callback); // >> Exported in ManualBindings <<
84 
86  void LogChunkStats(cCommandOutputCallback & a_Output);
87 
88  cMonsterConfig * GetMonsterConfig(void) { return m_MonsterConfig; }
89 
90  cCraftingRecipes * GetCraftingRecipes(void) { return m_CraftingRecipes; } // tolua_export
91  cFurnaceRecipe * GetFurnaceRecipe (void) { return m_FurnaceRecipe; } // Exported in ManualBindings.cpp with quite a different signature
92  cBrewingRecipes * GetBrewingRecipes (void) { return m_BrewingRecipes.get(); } // Exported in ManualBindings.cpp
93 
95  BlockTypeRegistry & GetBlockTypeRegistry() { return m_BlockTypeRegistry; }
96 
98  const BlockTypePalette & GetUpgradeBlockTypePalette() const { return *m_UpgradeBlockTypePalette; }
99 
101  ProtocolPalettes & GetProtocolPalettes() const { return *m_ProtocolPalettes; }
102 
104  static int GetFurnaceFuelBurnTime(const cItem & a_Fuel); // tolua_export
105 
108  AStringVector GetPlayerTabCompletionMultiWorld(const AString & a_Text);
109 
111  std::chrono::steady_clock::time_point m_StartTime;
112 
113  cWebAdmin * GetWebAdmin (void) { return m_WebAdmin; } // tolua_export
114  cPluginManager * GetPluginManager (void) { return m_PluginManager; } // tolua_export
115  cAuthenticator & GetAuthenticator (void) { return m_Authenticator; }
116  cMojangAPI & GetMojangAPI (void) { return *m_MojangAPI; }
117  cRankManager * GetRankManager (void) { return m_RankManager.get(); }
118 
124  void QueueExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallback & a_Output);
125 
131  void QueueExecuteConsoleCommand(const AString & a_Cmd); // tolua_export
132 
134  void ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallback & a_Output);
135 
137  void KickUser(int a_ClientID, const AString & a_Reason);
138 
140  void AuthenticateUser(int a_ClientID, const AString & a_Name, const cUUID & a_UUID, const Json::Value & a_Properties);
141 
143  void TickCommands(void);
144 
146  int GetTotalChunkCount(void); // tolua_export
147 
149  void SaveAllChunks(void); // tolua_export
150 
152  void SetSavingEnabled(bool a_SavingEnabled); // tolua_export
153 
155  bool ForEachPlayer(cPlayerListCallback a_Callback); // >> EXPORTED IN MANUALBINDINGS <<
156 
158  bool FindAndDoWithPlayer(const AString & a_PlayerName, cPlayerListCallback a_Callback); // >> EXPORTED IN MANUALBINDINGS <<
159 
161  bool DoWithPlayerByUUID(const cUUID & a_PlayerUUID, cPlayerListCallback a_Callback); // >> EXPORTED IN MANUALBINDINGS <<
162 
164  bool DoWithPlayer(const AString & a_PlayerName, cPlayerListCallback a_Callback);
165 
167  void SendPlayerLists(cPlayer * a_DestPlayer);
168 
170  void BroadcastPlayerListsAddPlayer(const cPlayer & a_Player, const cClientHandle * a_Exclude = nullptr);
171 
173  void BroadcastPlayerListsRemovePlayer(const cPlayer & a_Player, const cClientHandle * a_Exclude = nullptr);
174 
175  // tolua_begin
176 
178  void BroadcastChat (const AString & a_Message, eMessageType a_ChatPrefix = mtCustom);
179  void BroadcastChat (const cCompositeChat & a_Message);
180  void BroadcastChatDeath (const AString & a_Message) { BroadcastChat(a_Message, mtDeath); }
181  void BroadcastChatFailure(const AString & a_Message) { BroadcastChat(a_Message, mtFailure); }
182  void BroadcastChatFatal (const AString & a_Message) { BroadcastChat(a_Message, mtFailure); }
183  void BroadcastChatInfo (const AString & a_Message) { BroadcastChat(a_Message, mtInformation); }
184  void BroadcastChatJoin (const AString & a_Message) { BroadcastChat(a_Message, mtJoin); }
185  void BroadcastChatLeave (const AString & a_Message) { BroadcastChat(a_Message, mtLeave); }
186  void BroadcastChatSuccess(const AString & a_Message) { BroadcastChat(a_Message, mtSuccess); }
187  void BroadcastChatWarning(const AString & a_Message) { BroadcastChat(a_Message, mtWarning); }
188 
190  static AString GetProtocolVersionTextFromInt(int a_ProtocolVersionNum);
191 
193  static int GetVirtualRAMUsage(void);
194 
196  static int GetPhysicalRAMUsage(void);
197 
198  // tolua_end
199 
200 private:
201  class cCommand
202  {
203  public:
204  cCommand(const AString & a_Command, cCommandOutputCallback * a_Output) :
205  m_Command(a_Command),
206  m_Output(a_Output)
207  {
208  }
209 
212  } ;
213 
214  typedef std::map<AString, cWorld *> WorldMap;
215  typedef std::vector<cCommand> cCommandQueue;
216 
218  WorldMap m_WorldsByName;
219 
221  cCommandQueue m_PendingCommands;
222 
223  std::thread m_InputThread;
225  std::atomic_flag m_InputThreadRunFlag;
226 
229 
232  std::unique_ptr<cBrewingRecipes> m_BrewingRecipes;
237 
238  std::unique_ptr<cRankManager> m_RankManager;
239 
241 
244 
246  std::unique_ptr<BlockTypePalette> m_UpgradeBlockTypePalette;
247 
249  std::unique_ptr<ProtocolPalettes> m_ProtocolPalettes;
250 
251 
252  void LoadGlobalSettings();
253 
256  void LoadPalettes(const AString & aProtocolFolder);
257 
259  void LoadWorlds(cDeadlockDetect & a_dd, cSettingsRepositoryInterface & a_Settings, bool a_IsNewIniFile);
260 
262  void StartWorlds(cDeadlockDetect & a_DeadlockDetect);
263 
265  void StopWorlds(cDeadlockDetect & a_DeadlockDetect);
266 
268  void UnloadWorlds(void);
269 
271  void DoExecuteConsoleCommand(const AString & a_Cmd);
272 
273  static cRoot * s_Root;
274 
275  static void InputThread(cRoot & a_Params);
276 }; // tolua_export
277 
278 
279 
280 
281 
cAuthenticator m_Authenticator
Definition: Root.h:235
BlockTypeRegistry m_BlockTypeRegistry
The storage for all registered block types.
Definition: Root.h:243
cCriticalSection m_CSPendingCommands
Definition: Root.h:220
std::unique_ptr< cRankManager > m_RankManager
Definition: Root.h:238
Stores information on all known block types.
cHTTPServer m_HTTPServer
Definition: Root.h:240
cMonsterConfig * m_MonsterConfig
Definition: Root.h:228
void BroadcastChatInfo(const AString &a_Message)
Definition: Root.h:183
cPluginManager * m_PluginManager
Definition: Root.h:234
std::vector< cCommand > cCommandQueue
Definition: Root.h:215
AString m_SettingsFilename
which ini file to load settings from, default is settings.ini
Definition: Root.h:58
Definition: Event.h:17
Definition: Player.h:27
void BroadcastChatFailure(const AString &a_Message)
Definition: Root.h:181
cEvent m_StopEvent
Definition: Root.h:224
ProtocolPalettes & GetProtocolPalettes() const
Returns the per-protocol palettes manager.
Definition: Root.h:101
cWebAdmin * m_WebAdmin
Definition: Root.h:233
cRankManager * GetRankManager(void)
Definition: Root.h:117
AString m_Command
Definition: Root.h:210
static cRoot * s_Root
Definition: Root.h:273
cWorld * m_pDefaultWorld
Definition: Root.h:217
Definition: Inventory.h:10
std::thread m_InputThread
Definition: Root.h:223
cBrewingRecipes * GetBrewingRecipes(void)
Definition: Root.h:92
Holds a palette that maps between block type + state and numbers.
Definition: UUID.h:10
Definition: Server.h:55
void BroadcastChatWarning(const AString &a_Message)
Definition: Root.h:187
static bool m_TerminateEventRaised
If something has told the server to stop; checked periodically in cRoot.
Definition: Root.h:54
std::vector< AString > AStringVector
Definition: StringUtils.h:14
static bool m_RunAsService
If set to true, binary will attempt to run as a service on Windows.
Definition: Root.h:55
void BroadcastChatFatal(const AString &a_Message)
Definition: Root.h:182
Container for a single chat message composed of multiple functional parts.
Definition: CompositeChat.h:31
void BroadcastChatSuccess(const AString &a_Message)
Definition: Root.h:186
Definition: World.h:65
const BlockTypePalette & GetUpgradeBlockTypePalette() const
Returns the block type palette used for upgrading blocks from pre-1.13 data.
Definition: Root.h:98
std::map< AString, cWorld * > WorldMap
Definition: Root.h:214
cFurnaceRecipe * m_FurnaceRecipe
Definition: Root.h:231
cCraftingRecipes * m_CraftingRecipes
Definition: Root.h:230
Loads the protocol-specific palettes on startup and provides them to the individual protocol instance...
cMojangAPI & GetMojangAPI(void)
Definition: Root.h:116
void BroadcastChatJoin(const AString &a_Message)
Definition: Root.h:184
BlockTypeRegistry & GetBlockTypeRegistry()
Returns the (read-write) storage for registered block types.
Definition: Root.h:95
cCommandOutputCallback * m_Output
Definition: Root.h:211
int GetServerUpTime(void)
Returns the up time of the server in seconds.
Definition: Root.h:76
The root of the object hierarchy.
Definition: Root.h:48
void BroadcastChatLeave(const AString &a_Message)
Definition: Root.h:185
cCraftingRecipes * GetCraftingRecipes(void)
Definition: Root.h:90
std::atomic_flag m_InputThreadRunFlag
Definition: Root.h:225
cMojangAPI * m_MojangAPI
Definition: Root.h:236
std::string AString
Definition: StringUtils.h:13
std::chrono::steady_clock::time_point m_StartTime
The current time where the startup of the server has been completed.
Definition: Root.h:111
cMonsterConfig * GetMonsterConfig(void)
Definition: Root.h:88
cServer * GetServer(void)
Definition: Root.h:69
WorldMap m_WorldsByName
Definition: Root.h:218
cCommand(const AString &a_Command, cCommandOutputCallback *a_Output)
Definition: Root.h:204
void BroadcastChatDeath(const AString &a_Message)
Definition: Root.h:180
std::unique_ptr< ProtocolPalettes > m_ProtocolPalettes
The per-protocol palettes manager.
Definition: Root.h:249
static cRoot * Get()
Definition: Root.h:51
cAuthenticator & GetAuthenticator(void)
Definition: Root.h:115
cWebAdmin * GetWebAdmin(void)
Definition: Root.h:113
cFurnaceRecipe * GetFurnaceRecipe(void)
Definition: Root.h:91
eMessageType
Definition: Defines.h:976
cServer * m_Server
Definition: Root.h:227
std::unique_ptr< cBrewingRecipes > m_BrewingRecipes
Definition: Root.h:232
Interface for a callback that receives command output The Out() function is called for any output the...
Definition: CommandOutput.h:13
std::unique_ptr< BlockTypePalette > m_UpgradeBlockTypePalette
The upgrade palette for pre-1.13 blocks.
Definition: Root.h:246
Definition: Item.h:36
cCommandQueue m_PendingCommands
Definition: Root.h:221
cPluginManager * GetPluginManager(void)
Definition: Root.h:114