1 /* 2 * Copyright (c) 2017-2019 sel-project 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a copy 5 * of this software and associated documentation files (the "Software"), to deal 6 * in the Software without restriction, including without limitation the rights 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 * copies of the Software, and to permit persons to whom the Software is 9 * furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in all 12 * copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 * SOFTWARE. 21 * 22 */ 23 /** 24 * Copyright: Copyright (c) 2017-2019 sel-project 25 * License: MIT 26 * Authors: Kripth 27 * Source: $(HTTP github.com/sel-project/selery/source/selery/hncom/status.d, selery/hncom/status.d) 28 */ 29 module selery.hncom.status; 30 31 import std.socket : Address; 32 33 import selery.hncom.about; 34 import selery.hncom.io; 35 36 import xpacket : Custom; 37 38 /** 39 * Used to calculate latency by both the hub and the node. 40 * When this packet is received it should be immeditaly sent back to the sender 41 * without any change. 42 */ 43 @clientbound @serverbound class Latency : HncomPacket { 44 45 enum ubyte ID = 5; 46 47 /** 48 * Id of the ping/pong. Should be unique for the session. 49 */ 50 uint id; 51 52 mixin Make; 53 54 } 55 56 /** 57 * Sends a logged message to the hub. 58 */ 59 @serverbound class Log : HncomPacket { 60 61 enum ubyte ID = 6; 62 63 struct Message { bool translation; string message; string[] params; } 64 65 enum int NO_COMMAND = -1; 66 67 enum int NO_WORLD = -1; 68 69 /** 70 * Logged message or translation. It may contain Minecraft formatting codes. 71 */ 72 Message[] message; 73 74 /** 75 * Unix time (in milliseconds) that indicates the exact creation time of the 76 * log (for ordering purposes). 77 */ 78 ulong timestamp; 79 80 /** 81 * Identifier of the command that has generated the log or -1 if the 82 * log wasn't generated by a command. 83 */ 84 int commandId = NO_COMMAND; 85 86 /** 87 * Id of the world that has generated the log, if the log comes from a world, -1 otherwise. 88 */ 89 int worldId = NO_WORLD; 90 91 mixin Make; 92 93 } 94 95 /** 96 * Executes a command on the node. 97 */ 98 @clientbound class RemoteCommand : HncomPacket { 99 100 enum ubyte ID = 7; 101 102 enum : ubyte { 103 104 HUB = 0, 105 WEB_ADMIN = 1, 106 RCON = 2, 107 108 } 109 110 /** 111 * Origin of the command. It could be the hub itself or an external source. 112 */ 113 ubyte origin; 114 115 /** 116 * Address of the sender if the command has been sent from an external source. 117 * It's `null` when the hub is the sender. 118 */ 119 @Custom!HncomAddress Address sender; 120 121 /** 122 * Commands and arguments that should be executed on the node. 123 * For example `say hello world` or `kill @a`. 124 */ 125 string command; 126 127 /** 128 * Identifier of the command. It's sent back in Log's commandId field 129 * when the command generates output. 130 */ 131 uint commandId; 132 133 mixin Make; 134 135 } 136 137 /** 138 * Notifies the node that another node (that is not the receiver) has connected to the hub. 139 */ 140 @clientbound class AddNode : HncomPacket { 141 142 enum ubyte ID = 8; 143 144 /** 145 * Identifier given by the hub to uniquey identify the node. 146 */ 147 uint hubId; 148 149 /** 150 * Node's name used for displaying and identification purposes. 151 */ 152 string name; 153 154 /** 155 * Whether the node is a main node. 156 */ 157 bool main; 158 159 /** 160 * Indicates the games and protocols accepted by the node. 161 */ 162 uint[][ubyte] acceptedGames; 163 164 mixin Make; 165 166 } 167 168 /** 169 * Notifies the node that another node, previously added with AddNode, 170 * has disconnected from the hub. 171 */ 172 @clientbound class RemoveNode : HncomPacket { 173 174 enum ubyte ID = 9; 175 176 /** 177 * Node's id given by the hub. 178 */ 179 uint hubId; 180 181 mixin Make; 182 183 } 184 185 /** 186 * Receives a binary message sent by another node using SendMessage. 187 */ 188 @clientbound class ReceiveMessage : HncomPacket { 189 190 enum ubyte ID = 10; 191 192 /** 193 * Id of the node that has sent the message. 194 */ 195 uint sender; 196 197 /** 198 * Indicates whether the message was broadcasted to every connected node. 199 */ 200 bool broadcasted; 201 202 /** 203 * Bytes received. It could be serialised data or a plugin-defined packet. 204 */ 205 ubyte[] payload; 206 207 mixin Make; 208 209 } 210 211 /** 212 * Sends a binary message to some selected nodes or broadcast it. 213 */ 214 @serverbound class SendMessage : HncomPacket { 215 216 enum ubyte ID = 11; 217 218 /** 219 * Addressees of the message. If the array is empty the message is 220 * broadcasted to every connected node but the sender. 221 */ 222 uint[] addressees; 223 224 /** 225 * Bytes to be sent/broadcasted. It may be serialised data or a plugin-defined packet. 226 */ 227 ubyte[] payload; 228 229 mixin Make; 230 231 } 232 233 /** 234 * Updates the server's display name. 235 */ 236 @clientbound class UpdateDisplayName : HncomPacket { 237 238 enum ubyte ID = 12; 239 240 string displayName; 241 242 mixin Make; 243 244 } 245 246 /** 247 * Updates the MOTD of one of the supported games. 248 */ 249 @clientbound class UpdateMOTD : HncomPacket { 250 251 enum ubyte ID = 13; 252 253 ubyte type; 254 255 string motd; 256 257 mixin Make; 258 259 } 260 261 /** 262 * Updates the number of players on the server. 263 */ 264 @clientbound class UpdatePlayers : HncomPacket { 265 266 enum ubyte ID = 14; 267 268 enum int UNLIMITED = -1; 269 270 /** 271 * Players currently online in the whole server (connected to a node). 272 */ 273 uint online; 274 275 /** 276 * Maximum number of players that can connect to server, which is the sum of 277 * the max players of every connected node. 278 */ 279 int max; 280 281 mixin Make; 282 283 } 284 285 /** 286 * Updates the number of players that can be accepted by the node. 287 * If the given number is smaller than the players currently connected 288 * to the node no player should be kicked. 289 */ 290 @serverbound class UpdateMaxPlayers : HncomPacket { 291 292 enum ubyte ID = 15; 293 294 enum uint UNLIMITED = 0; 295 296 /** 297 * Maximum number of players accepted by node. 298 */ 299 uint max; 300 301 mixin Make; 302 303 } 304 305 /** 306 * Updates the accepted protocols for one of the supported games. 307 */ 308 @clientbound class UpdateSupportedProtocols : HncomPacket { 309 310 enum ubyte ID = 16; 311 312 ubyte game; 313 314 uint[] protocols; 315 316 mixin Make; 317 318 } 319 320 /** 321 * Updates the usage of the system's resources of the node. 322 */ 323 @serverbound class UpdateUsage : HncomPacket { 324 325 enum ubyte ID = 17; 326 327 /** 328 * Kibibytes of RAM used by the node. 329 */ 330 uint ram; 331 332 /** 333 * Percentage of CPU used by the node. It may be higher than 100 334 * if the node has more than 1 CPU 335 */ 336 float cpu; 337 338 mixin Make; 339 340 } 341 342 /** 343 * Updates the language files. The content of this packet is usually 344 * readed from plugins' language files. 345 */ 346 @serverbound class UpdateLanguageFiles : HncomPacket { 347 348 enum ubyte ID = 18; 349 350 string language; 351 352 string[string] messages; 353 354 mixin Make; 355 356 } 357 358 /** 359 * Adds a plugin that has been loaded at runtime. 360 */ 361 @serverbound class AddPlugin : HncomPacket { 362 363 enum ubyte ID = 19; 364 365 /** 366 * Plugin's id given by the node. It must be unique. 367 */ 368 uint id; 369 370 string name; 371 372 string version_; 373 374 mixin Make; 375 376 } 377 378 /** 379 * Removes a plugin that has been unloaded at runtime. 380 */ 381 @serverbound class RemovePlugin : HncomPacket { 382 383 enum ubyte ID = 20; 384 385 /** 386 * Plugin's id given in the NodeInfo packet or in the AddPlugin packet. 387 */ 388 uint id; 389 390 mixin Make; 391 392 } 393 394 /** 395 * Notifies the hub that a new world has been created on the node. 396 */ 397 @serverbound class AddWorld : HncomPacket { 398 399 enum ubyte ID = 21; 400 401 /** 402 * Id of the world. Must be unique on the node. 403 */ 404 uint worldId; 405 406 /** 407 * World's group id. Similar worlds can be grouped together 408 * and removed with the RemoveWorldGroup packet. 409 * If the world is independent and has no group the group id must be the same 410 * as the world id. 411 */ 412 uint groupId; 413 414 /** 415 * Name of the world, it doesn't need to be unique. 416 */ 417 string name; 418 419 /** 420 * World's dimension in the MCPE format (0: overworld, 1: nether, 2: end). 421 */ 422 ubyte dimension; 423 424 /** 425 * Indicates whether the world is the node's default (the one where new players 426 * are spawned into if not handled by plugins). 427 * If the node does not support default worlds or it simply doesn't have one 428 * this field should be left to its default value (false). 429 * If the hub receives more than one default world it should consider the last 430 * received one as the default world. 431 */ 432 bool default_; 433 434 mixin Make; 435 436 } 437 438 /** 439 * Notifies the hub that a world has been removed from the node. 440 */ 441 @serverbound class RemoveWorld : HncomPacket { 442 443 enum ubyte ID = 22; 444 445 /** 446 * Id of the world that has been removed, previosly added using the 447 * AddWorld packet. 448 */ 449 uint worldId; 450 451 mixin Make; 452 453 } 454 455 /** 456 * Removes a group of worlds. 457 */ 458 @serverbound class RemoveWorldGroup : HncomPacket { 459 460 enum ubyte ID = 23; 461 462 uint groupId; 463 464 mixin Make; 465 466 }