1 /* 2 * This file was automatically generated by sel-utils and 3 * released under the MIT License. 4 * 5 * License: https://github.com/sel-project/sel-utils/blob/master/LICENSE 6 * Repository: https://github.com/sel-project/sel-utils 7 * Generated from https://github.com/sel-project/sel-utils/blob/master/xml/protocol/externalconsole1.xml 8 */ 9 /** 10 * Packets about the informations and the usage of the server. 11 */ 12 module sul.protocol.externalconsole1.status; 13 14 import std.bitmanip : write, peek; 15 static import std.conv; 16 import std.system : Endian; 17 import std.typetuple : TypeTuple; 18 import std.typecons : Tuple; 19 import std.uuid : UUID; 20 21 import sul.utils.buffer; 22 import sul.utils.var; 23 24 static import sul.protocol.externalconsole1.types; 25 26 static if(__traits(compiles, { import sul.metadata.externalconsole1; })) import sul.metadata.externalconsole1; 27 28 alias Packets = TypeTuple!(KeepAlive, UpdateNodes, RequestStats, UpdateStats); 29 30 /** 31 * Keeps the connection alive and/or calculates the latency. This packet should be 32 * sent at least every 5 seconds to avoid the disconnection caused by timeout and update 33 * the latency. The external console can send this packet whenever it wants it and 34 * the server must reply with the same packet with the same field's value. 35 */ 36 class KeepAlive : Buffer { 37 38 public enum ubyte ID = 0; 39 40 public enum bool CLIENTBOUND = true; 41 public enum bool SERVERBOUND = true; 42 43 public enum string[] FIELDS = ["count"]; 44 45 /** 46 * An identifier chosen by the external console to uniquely identify the packet. 47 */ 48 public uint count; 49 50 public pure nothrow @safe @nogc this() {} 51 52 public pure nothrow @safe @nogc this(uint count) { 53 this.count = count; 54 } 55 56 public pure nothrow @safe ubyte[] encode(bool writeId=true)() { 57 _buffer.length = 0; 58 static if(writeId){ writeBigEndianUbyte(ID); } 59 writeBigEndianUint(count); 60 return _buffer; 61 } 62 63 public pure nothrow @safe void decode(bool readId=true)() { 64 static if(readId){ ubyte _id; _id=readBigEndianUbyte(); } 65 count=readBigEndianUint(); 66 } 67 68 public static pure nothrow @safe KeepAlive fromBuffer(bool readId=true)(ubyte[] buffer) { 69 KeepAlive ret = new KeepAlive(); 70 ret._buffer = buffer; 71 ret.decode!readId(); 72 return ret; 73 } 74 75 public override string toString() { 76 return "KeepAlive(count: " ~ std.conv.to!string(this.count) ~ ")"; 77 } 78 79 } 80 81 /** 82 * Updates the list of the nodes connected to the hub, adding or removing one. 83 * If the server isn't built on the hub-node layout this packet is never sent. 84 */ 85 class UpdateNodes : Buffer { 86 87 public enum ubyte ID = 1; 88 89 public enum bool CLIENTBOUND = true; 90 public enum bool SERVERBOUND = false; 91 92 // action 93 public enum ubyte ADD = 0; 94 public enum ubyte REMOVE = 1; 95 96 public enum string[] FIELDS = ["action", "node"]; 97 98 /** 99 * Whether the node should be added or removed from the list of connected nodes. 100 */ 101 public ubyte action; 102 103 /** 104 * Name of the node. 105 */ 106 public string node; 107 108 public pure nothrow @safe @nogc this() {} 109 110 public pure nothrow @safe @nogc this(ubyte action, string node=string.init) { 111 this.action = action; 112 this.node = node; 113 } 114 115 public pure nothrow @safe ubyte[] encode(bool writeId=true)() { 116 _buffer.length = 0; 117 static if(writeId){ writeBigEndianUbyte(ID); } 118 writeBigEndianUbyte(action); 119 writeBigEndianUshort(cast(ushort)node.length); writeString(node); 120 return _buffer; 121 } 122 123 public pure nothrow @safe void decode(bool readId=true)() { 124 static if(readId){ ubyte _id; _id=readBigEndianUbyte(); } 125 action=readBigEndianUbyte(); 126 ushort b9z=readBigEndianUshort(); node=readString(b9z); 127 } 128 129 public static pure nothrow @safe UpdateNodes fromBuffer(bool readId=true)(ubyte[] buffer) { 130 UpdateNodes ret = new UpdateNodes(); 131 ret._buffer = buffer; 132 ret.decode!readId(); 133 return ret; 134 } 135 136 public override string toString() { 137 return "UpdateNodes(action: " ~ std.conv.to!string(this.action) ~ ", node: " ~ std.conv.to!string(this.node) ~ ")"; 138 } 139 140 } 141 142 /** 143 * Requests an UpdateStats packet to the server, which should sent it immediately instead 144 * of waiting for the next automatic update (if the server does one). 145 */ 146 class RequestStats : Buffer { 147 148 public enum ubyte ID = 2; 149 150 public enum bool CLIENTBOUND = false; 151 public enum bool SERVERBOUND = true; 152 153 public enum string[] FIELDS = []; 154 155 public pure nothrow @safe ubyte[] encode(bool writeId=true)() { 156 _buffer.length = 0; 157 static if(writeId){ writeBigEndianUbyte(ID); } 158 return _buffer; 159 } 160 161 public pure nothrow @safe void decode(bool readId=true)() { 162 static if(readId){ ubyte _id; _id=readBigEndianUbyte(); } 163 } 164 165 public static pure nothrow @safe RequestStats fromBuffer(bool readId=true)(ubyte[] buffer) { 166 RequestStats ret = new RequestStats(); 167 ret._buffer = buffer; 168 ret.decode!readId(); 169 return ret; 170 } 171 172 public override string toString() { 173 return "RequestStats()"; 174 } 175 176 } 177 178 /** 179 * Updates the statistics about the usage of the server and, eventually, the connected 180 * nodes. 181 * This packet is sent in response to RequestStats and every time the server retains 182 * that the stats should be updated (usually in a range of 5 to 30 seconds). 183 */ 184 class UpdateStats : Buffer { 185 186 public enum ubyte ID = 3; 187 188 public enum bool CLIENTBOUND = true; 189 public enum bool SERVERBOUND = false; 190 191 public enum string[] FIELDS = ["onlinePlayers", "maxPlayers", "uptime", "upload", "download", "nodes"]; 192 193 /** 194 * Number of players currently online on the server. Players that are performing authentication 195 * are not included in the count. 196 */ 197 public uint onlinePlayers; 198 199 /** 200 * Highest number of players that can join the server simultaneously. If 0, there is 201 * not maximum number of players. 202 */ 203 public uint maxPlayers; 204 205 /** 206 * Milliseconds since the server has started. 207 */ 208 public uint uptime; 209 210 /** 211 * Average amount of bytes sent every second. 212 */ 213 public uint upload; 214 215 /** 216 * Average amount of bytes sent every second. 217 */ 218 public uint download; 219 220 /** 221 * Resources usage of the connected nodes, if the server uses the hub-node layout, 222 * or an empty list. 223 */ 224 public sul.protocol.externalconsole1.types.NodeStats[] nodes; 225 226 public pure nothrow @safe @nogc this() {} 227 228 public pure nothrow @safe @nogc this(uint onlinePlayers, uint maxPlayers=uint.init, uint uptime=uint.init, uint upload=uint.init, uint download=uint.init, sul.protocol.externalconsole1.types.NodeStats[] nodes=(sul.protocol.externalconsole1.types.NodeStats[]).init) { 229 this.onlinePlayers = onlinePlayers; 230 this.maxPlayers = maxPlayers; 231 this.uptime = uptime; 232 this.upload = upload; 233 this.download = download; 234 this.nodes = nodes; 235 } 236 237 public pure nothrow @safe ubyte[] encode(bool writeId=true)() { 238 _buffer.length = 0; 239 static if(writeId){ writeBigEndianUbyte(ID); } 240 writeBigEndianUint(onlinePlayers); 241 writeBigEndianUint(maxPlayers); 242 writeBigEndianUint(uptime); 243 writeBigEndianUint(upload); 244 writeBigEndianUint(download); 245 writeBigEndianUshort(cast(ushort)nodes.length); foreach(b9zm;nodes){ b9zm.encode(bufferInstance); } 246 return _buffer; 247 } 248 249 public pure nothrow @safe void decode(bool readId=true)() { 250 static if(readId){ ubyte _id; _id=readBigEndianUbyte(); } 251 onlinePlayers=readBigEndianUint(); 252 maxPlayers=readBigEndianUint(); 253 uptime=readBigEndianUint(); 254 upload=readBigEndianUint(); 255 download=readBigEndianUint(); 256 nodes.length=readBigEndianUshort(); foreach(ref b9zm;nodes){ b9zm.decode(bufferInstance); } 257 } 258 259 public static pure nothrow @safe UpdateStats fromBuffer(bool readId=true)(ubyte[] buffer) { 260 UpdateStats ret = new UpdateStats(); 261 ret._buffer = buffer; 262 ret.decode!readId(); 263 return ret; 264 } 265 266 public override string toString() { 267 return "UpdateStats(onlinePlayers: " ~ std.conv.to!string(this.onlinePlayers) ~ ", maxPlayers: " ~ std.conv.to!string(this.maxPlayers) ~ ", uptime: " ~ std.conv.to!string(this.uptime) ~ ", upload: " ~ std.conv.to!string(this.upload) ~ ", download: " ~ std.conv.to!string(this.download) ~ ", nodes: " ~ std.conv.to!string(this.nodes) ~ ")"; 268 } 269 270 } 271