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/hncom2.xml 8 */ 9 module sul.protocol.hncom2.types; 10 11 import std.bitmanip : write, peek; 12 static import std.conv; 13 import std.system : Endian; 14 import std.typecons : Tuple; 15 import std.uuid : UUID; 16 17 import sul.utils.buffer; 18 import sul.utils.var; 19 20 static if(__traits(compiles, { import sul.metadata.hncom2; })) import sul.metadata.hncom2; 21 22 /** 23 * Internet protocol address. Could be either version 4 or 6. 24 */ 25 struct Address { 26 27 public enum string[] FIELDS = ["bytes", "port"]; 28 29 /** 30 * Bytes of the address. The length may be 4 (for ipv4 addresses) or 16 (for ipv6 addresses). 31 * The byte order is always big-endian (network order). 32 */ 33 public ubyte[] bytes; 34 35 /** 36 * Port of the address. 37 */ 38 public ushort port; 39 40 public pure nothrow @safe void encode(Buffer buffer) { 41 with(buffer) { 42 writeBytes(varuint.encode(cast(uint)bytes.length)); writeBytes(bytes); 43 writeBigEndianUshort(port); 44 } 45 } 46 47 public pure nothrow @safe void decode(Buffer buffer) { 48 with(buffer) { 49 bytes.length=varuint.decode(_buffer, &_index); if(_buffer.length>=_index+bytes.length){ bytes=_buffer[_index.._index+bytes.length].dup; _index+=bytes.length; } 50 port=readBigEndianUshort(); 51 } 52 } 53 54 public string toString() { 55 return "Address(bytes: " ~ std.conv.to!string(this.bytes) ~ ", port: " ~ std.conv.to!string(this.port) ~ ")"; 56 } 57 58 } 59 60 /** 61 * Indicates a game and informations about its accepted protocols. 62 */ 63 struct Game { 64 65 // type 66 public enum ubyte POCKET = 1; 67 public enum ubyte MINECRAFT = 2; 68 public enum ubyte CONSOLE = 3; 69 70 public enum string[] FIELDS = ["type", "protocols"]; 71 72 /** 73 * Identifier of the game. 74 */ 75 public ubyte type; 76 77 /** 78 * Protocols accepted by the server for the game. They should be ordered from oldest 79 * to newest. 80 */ 81 public uint[] protocols; 82 83 public pure nothrow @safe void encode(Buffer buffer) { 84 with(buffer) { 85 writeBigEndianUbyte(type); 86 writeBytes(varuint.encode(cast(uint)protocols.length)); foreach(cjd9bx;protocols){ writeBytes(varuint.encode(cjd9bx)); } 87 } 88 } 89 90 public pure nothrow @safe void decode(Buffer buffer) { 91 with(buffer) { 92 type=readBigEndianUbyte(); 93 protocols.length=varuint.decode(_buffer, &_index); foreach(ref cjd9bx;protocols){ cjd9bx=varuint.decode(_buffer, &_index); } 94 } 95 } 96 97 public string toString() { 98 return "Game(type: " ~ std.conv.to!string(this.type) ~ ", protocols: " ~ std.conv.to!string(this.protocols) ~ ")"; 99 } 100 101 } 102 103 /** 104 * Indicates a game and informations about it. 105 */ 106 struct GameInfo { 107 108 public enum string[] FIELDS = ["game", "motd", "onlineMode", "port"]; 109 110 /** 111 * Informations about the the game and the protocols used. 112 */ 113 public sul.protocol.hncom2.types.Game game; 114 115 /** 116 * "Message of the day" which is displayed in the game's server list. It may contain 117 * Minecraft formatting codes. 118 */ 119 public string motd; 120 121 /** 122 * Indicates whether the players are authenticated using the games' official authentication 123 * services and their identity should be trusted. 124 */ 125 public bool onlineMode; 126 127 /** 128 * Port, or main port if the server allows the connection from multiple ports, where 129 * the socket is listening for connections. 130 */ 131 public ushort port; 132 133 public pure nothrow @safe void encode(Buffer buffer) { 134 with(buffer) { 135 game.encode(bufferInstance); 136 writeBytes(varuint.encode(cast(uint)motd.length)); writeString(motd); 137 writeBigEndianBool(onlineMode); 138 writeBigEndianUshort(port); 139 } 140 } 141 142 public pure nothrow @safe void decode(Buffer buffer) { 143 with(buffer) { 144 game.decode(bufferInstance); 145 uint b9z=varuint.decode(_buffer, &_index); motd=readString(b9z); 146 onlineMode=readBigEndianBool(); 147 port=readBigEndianUshort(); 148 } 149 } 150 151 public string toString() { 152 return "GameInfo(game: " ~ std.conv.to!string(this.game) ~ ", motd: " ~ std.conv.to!string(this.motd) ~ ", onlineMode: " ~ std.conv.to!string(this.onlineMode) ~ ", port: " ~ std.conv.to!string(this.port) ~ ")"; 153 } 154 155 } 156 157 /** 158 * A plugin loaded on the node. It may be used by the hub to display the plugins loaded 159 * on the server in queries. 160 */ 161 struct Plugin { 162 163 public enum string[] FIELDS = ["name", "vers"]; 164 165 /** 166 * Name of the plugin. 167 */ 168 public string name; 169 170 /** 171 * Version of the plugin, usually in the format `major.minor[.release] [alpha|beta]`. 172 */ 173 public string vers; 174 175 public pure nothrow @safe void encode(Buffer buffer) { 176 with(buffer) { 177 writeBytes(varuint.encode(cast(uint)name.length)); writeString(name); 178 writeBytes(varuint.encode(cast(uint)vers.length)); writeString(vers); 179 } 180 } 181 182 public pure nothrow @safe void decode(Buffer buffer) { 183 with(buffer) { 184 uint bfz=varuint.decode(_buffer, &_index); name=readString(bfz); 185 uint dvc=varuint.decode(_buffer, &_index); vers=readString(dvc); 186 } 187 } 188 189 public string toString() { 190 return "Plugin(name: " ~ std.conv.to!string(this.name) ~ ", vers: " ~ std.conv.to!string(this.vers) ~ ")"; 191 } 192 193 } 194 195 struct Motd { 196 197 // type 198 public enum ubyte POCKET = 1; 199 public enum ubyte MINECRAFT = 2; 200 public enum ubyte CONSOLE = 3; 201 202 public enum string[] FIELDS = ["type", "motd"]; 203 204 public ubyte type; 205 public string motd; 206 207 public pure nothrow @safe void encode(Buffer buffer) { 208 with(buffer) { 209 writeBigEndianUbyte(type); 210 writeBytes(varuint.encode(cast(uint)motd.length)); writeString(motd); 211 } 212 } 213 214 public pure nothrow @safe void decode(Buffer buffer) { 215 with(buffer) { 216 type=readBigEndianUbyte(); 217 uint b9z=varuint.decode(_buffer, &_index); motd=readString(b9z); 218 } 219 } 220 221 public string toString() { 222 return "Motd(type: " ~ std.conv.to!string(this.type) ~ ", motd: " ~ std.conv.to!string(this.motd) ~ ")"; 223 } 224 225 } 226 227 /** 228 * Player's skin that will be sent to Minecraft: Pocket Edition clients. 229 * If the server only allows Minecraft players this type's fields should be empty. 230 */ 231 struct Skin { 232 233 public enum string[] FIELDS = ["name", "data"]; 234 235 /** 236 * Name of the skin. 237 */ 238 public string name; 239 240 /** 241 * RGBA map of the skin colours. Length should be, if the skin is not empty, 8192 (64x32) 242 * or 16384 (64x64) bytes. 243 */ 244 public ubyte[] data; 245 246 public pure nothrow @safe void encode(Buffer buffer) { 247 with(buffer) { 248 writeBytes(varuint.encode(cast(uint)name.length)); writeString(name); 249 writeBytes(varuint.encode(cast(uint)data.length)); writeBytes(data); 250 } 251 } 252 253 public pure nothrow @safe void decode(Buffer buffer) { 254 with(buffer) { 255 uint bfz=varuint.decode(_buffer, &_index); name=readString(bfz); 256 data.length=varuint.decode(_buffer, &_index); if(_buffer.length>=_index+data.length){ data=_buffer[_index.._index+data.length].dup; _index+=data.length; } 257 } 258 } 259 260 public string toString() { 261 return "Skin(name: " ~ std.conv.to!string(this.name) ~ ", data: " ~ std.conv.to!string(this.data) ~ ")"; 262 } 263 264 } 265 266 struct Property { 267 268 public enum string[] FIELDS = []; 269 270 public pure nothrow @safe void encode(Buffer buffer) { 271 with(buffer) { 272 } 273 } 274 275 public pure nothrow @safe void decode(Buffer buffer) { 276 with(buffer) { 277 } 278 } 279 280 public string toString() { 281 return "Property()"; 282 } 283 284 } 285