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/raknet8.xml 8 */ 9 module sul.protocol.raknet8.unconnected; 10 11 import std.bitmanip : write, peek; 12 static import std.conv; 13 import std.system : Endian; 14 import std.typetuple : TypeTuple; 15 import std.typecons : Tuple; 16 import std.uuid : UUID; 17 18 import sul.utils.buffer; 19 import sul.utils.var; 20 21 static import sul.protocol.raknet8.types; 22 23 static if(__traits(compiles, { import sul.metadata.raknet8; })) import sul.metadata.raknet8; 24 25 alias Packets = TypeTuple!(Ping, Pong, OpenConnectionRequest1, OpenConnectionReply1, OpenConnectionRequest2, OpenConnectionReply2); 26 27 class Ping : Buffer { 28 29 public enum ubyte ID = 1; 30 31 public enum bool CLIENTBOUND = false; 32 public enum bool SERVERBOUND = true; 33 34 public enum string[] FIELDS = ["pingId", "magic", "guid"]; 35 36 public long pingId; 37 public ubyte[16] magic; 38 public long guid; 39 40 public pure nothrow @safe @nogc this() {} 41 42 public pure nothrow @safe @nogc this(long pingId, ubyte[16] magic=(ubyte[16]).init, long guid=long.init) { 43 this.pingId = pingId; 44 this.magic = magic; 45 this.guid = guid; 46 } 47 48 public pure nothrow @safe ubyte[] encode(bool writeId=true)() { 49 _buffer.length = 0; 50 static if(writeId){ writeBigEndianUbyte(ID); } 51 writeBigEndianLong(pingId); 52 writeBytes(magic); 53 writeBigEndianLong(guid); 54 return _buffer; 55 } 56 57 public pure nothrow @safe void decode(bool readId=true)() { 58 static if(readId){ ubyte _id; _id=readBigEndianUbyte(); } 59 pingId=readBigEndianLong(); 60 if(_buffer.length>=_index+magic.length){ magic=_buffer[_index.._index+magic.length].dup; _index+=magic.length; } 61 guid=readBigEndianLong(); 62 } 63 64 public static pure nothrow @safe Ping fromBuffer(bool readId=true)(ubyte[] buffer) { 65 Ping ret = new Ping(); 66 ret._buffer = buffer; 67 ret.decode!readId(); 68 return ret; 69 } 70 71 public override string toString() { 72 return "Ping(pingId: " ~ std.conv.to!string(this.pingId) ~ ", magic: " ~ std.conv.to!string(this.magic) ~ ", guid: " ~ std.conv.to!string(this.guid) ~ ")"; 73 } 74 75 } 76 77 class Pong : Buffer { 78 79 public enum ubyte ID = 28; 80 81 public enum bool CLIENTBOUND = true; 82 public enum bool SERVERBOUND = false; 83 84 public enum string[] FIELDS = ["pingId", "serverId", "magic", "status"]; 85 86 public long pingId; 87 public long serverId; 88 public ubyte[16] magic; 89 public string status; 90 91 public pure nothrow @safe @nogc this() {} 92 93 public pure nothrow @safe @nogc this(long pingId, long serverId=long.init, ubyte[16] magic=(ubyte[16]).init, string status=string.init) { 94 this.pingId = pingId; 95 this.serverId = serverId; 96 this.magic = magic; 97 this.status = status; 98 } 99 100 public pure nothrow @safe ubyte[] encode(bool writeId=true)() { 101 _buffer.length = 0; 102 static if(writeId){ writeBigEndianUbyte(ID); } 103 writeBigEndianLong(pingId); 104 writeBigEndianLong(serverId); 105 writeBytes(magic); 106 writeBigEndianUshort(cast(ushort)status.length); writeString(status); 107 return _buffer; 108 } 109 110 public pure nothrow @safe void decode(bool readId=true)() { 111 static if(readId){ ubyte _id; _id=readBigEndianUbyte(); } 112 pingId=readBigEndianLong(); 113 serverId=readBigEndianLong(); 114 if(_buffer.length>=_index+magic.length){ magic=_buffer[_index.._index+magic.length].dup; _index+=magic.length; } 115 ushort crdv=readBigEndianUshort(); status=readString(crdv); 116 } 117 118 public static pure nothrow @safe Pong fromBuffer(bool readId=true)(ubyte[] buffer) { 119 Pong ret = new Pong(); 120 ret._buffer = buffer; 121 ret.decode!readId(); 122 return ret; 123 } 124 125 public override string toString() { 126 return "Pong(pingId: " ~ std.conv.to!string(this.pingId) ~ ", serverId: " ~ std.conv.to!string(this.serverId) ~ ", magic: " ~ std.conv.to!string(this.magic) ~ ", status: " ~ std.conv.to!string(this.status) ~ ")"; 127 } 128 129 } 130 131 class OpenConnectionRequest1 : Buffer { 132 133 public enum ubyte ID = 5; 134 135 public enum bool CLIENTBOUND = false; 136 public enum bool SERVERBOUND = true; 137 138 public enum string[] FIELDS = ["magic", "protocol", "mtu"]; 139 140 public ubyte[16] magic; 141 public ubyte protocol; 142 public ubyte[] mtu; 143 144 public pure nothrow @safe @nogc this() {} 145 146 public pure nothrow @safe @nogc this(ubyte[16] magic, ubyte protocol=ubyte.init, ubyte[] mtu=(ubyte[]).init) { 147 this.magic = magic; 148 this.protocol = protocol; 149 this.mtu = mtu; 150 } 151 152 public pure nothrow @safe ubyte[] encode(bool writeId=true)() { 153 _buffer.length = 0; 154 static if(writeId){ writeBigEndianUbyte(ID); } 155 writeBytes(magic); 156 writeBigEndianUbyte(protocol); 157 writeBytes(mtu); 158 return _buffer; 159 } 160 161 public pure nothrow @safe void decode(bool readId=true)() { 162 static if(readId){ ubyte _id; _id=readBigEndianUbyte(); } 163 if(_buffer.length>=_index+magic.length){ magic=_buffer[_index.._index+magic.length].dup; _index+=magic.length; } 164 protocol=readBigEndianUbyte(); 165 mtu=_buffer[_index..$].dup; _index=_buffer.length; 166 } 167 168 public static pure nothrow @safe OpenConnectionRequest1 fromBuffer(bool readId=true)(ubyte[] buffer) { 169 OpenConnectionRequest1 ret = new OpenConnectionRequest1(); 170 ret._buffer = buffer; 171 ret.decode!readId(); 172 return ret; 173 } 174 175 public override string toString() { 176 return "OpenConnectionRequest1(magic: " ~ std.conv.to!string(this.magic) ~ ", protocol: " ~ std.conv.to!string(this.protocol) ~ ", mtu: " ~ std.conv.to!string(this.mtu) ~ ")"; 177 } 178 179 } 180 181 class OpenConnectionReply1 : Buffer { 182 183 public enum ubyte ID = 6; 184 185 public enum bool CLIENTBOUND = true; 186 public enum bool SERVERBOUND = false; 187 188 public enum string[] FIELDS = ["magic", "serverId", "security", "mtuLength"]; 189 190 public ubyte[16] magic; 191 public long serverId; 192 public bool security; 193 public ushort mtuLength; 194 195 public pure nothrow @safe @nogc this() {} 196 197 public pure nothrow @safe @nogc this(ubyte[16] magic, long serverId=long.init, bool security=bool.init, ushort mtuLength=ushort.init) { 198 this.magic = magic; 199 this.serverId = serverId; 200 this.security = security; 201 this.mtuLength = mtuLength; 202 } 203 204 public pure nothrow @safe ubyte[] encode(bool writeId=true)() { 205 _buffer.length = 0; 206 static if(writeId){ writeBigEndianUbyte(ID); } 207 writeBytes(magic); 208 writeBigEndianLong(serverId); 209 writeBigEndianBool(security); 210 writeBigEndianUshort(mtuLength); 211 return _buffer; 212 } 213 214 public pure nothrow @safe void decode(bool readId=true)() { 215 static if(readId){ ubyte _id; _id=readBigEndianUbyte(); } 216 if(_buffer.length>=_index+magic.length){ magic=_buffer[_index.._index+magic.length].dup; _index+=magic.length; } 217 serverId=readBigEndianLong(); 218 security=readBigEndianBool(); 219 mtuLength=readBigEndianUshort(); 220 } 221 222 public static pure nothrow @safe OpenConnectionReply1 fromBuffer(bool readId=true)(ubyte[] buffer) { 223 OpenConnectionReply1 ret = new OpenConnectionReply1(); 224 ret._buffer = buffer; 225 ret.decode!readId(); 226 return ret; 227 } 228 229 public override string toString() { 230 return "OpenConnectionReply1(magic: " ~ std.conv.to!string(this.magic) ~ ", serverId: " ~ std.conv.to!string(this.serverId) ~ ", security: " ~ std.conv.to!string(this.security) ~ ", mtuLength: " ~ std.conv.to!string(this.mtuLength) ~ ")"; 231 } 232 233 } 234 235 class OpenConnectionRequest2 : Buffer { 236 237 public enum ubyte ID = 7; 238 239 public enum bool CLIENTBOUND = false; 240 public enum bool SERVERBOUND = true; 241 242 public enum string[] FIELDS = ["magic", "serverAddress", "mtuLength", "clientId"]; 243 244 public ubyte[16] magic; 245 public sul.protocol.raknet8.types.Address serverAddress; 246 public ushort mtuLength; 247 public long clientId; 248 249 public pure nothrow @safe @nogc this() {} 250 251 public pure nothrow @safe @nogc this(ubyte[16] magic, sul.protocol.raknet8.types.Address serverAddress=sul.protocol.raknet8.types.Address.init, ushort mtuLength=ushort.init, long clientId=long.init) { 252 this.magic = magic; 253 this.serverAddress = serverAddress; 254 this.mtuLength = mtuLength; 255 this.clientId = clientId; 256 } 257 258 public pure nothrow @safe ubyte[] encode(bool writeId=true)() { 259 _buffer.length = 0; 260 static if(writeId){ writeBigEndianUbyte(ID); } 261 writeBytes(magic); 262 serverAddress.encode(bufferInstance); 263 writeBigEndianUshort(mtuLength); 264 writeBigEndianLong(clientId); 265 return _buffer; 266 } 267 268 public pure nothrow @safe void decode(bool readId=true)() { 269 static if(readId){ ubyte _id; _id=readBigEndianUbyte(); } 270 if(_buffer.length>=_index+magic.length){ magic=_buffer[_index.._index+magic.length].dup; _index+=magic.length; } 271 serverAddress.decode(bufferInstance); 272 mtuLength=readBigEndianUshort(); 273 clientId=readBigEndianLong(); 274 } 275 276 public static pure nothrow @safe OpenConnectionRequest2 fromBuffer(bool readId=true)(ubyte[] buffer) { 277 OpenConnectionRequest2 ret = new OpenConnectionRequest2(); 278 ret._buffer = buffer; 279 ret.decode!readId(); 280 return ret; 281 } 282 283 public override string toString() { 284 return "OpenConnectionRequest2(magic: " ~ std.conv.to!string(this.magic) ~ ", serverAddress: " ~ std.conv.to!string(this.serverAddress) ~ ", mtuLength: " ~ std.conv.to!string(this.mtuLength) ~ ", clientId: " ~ std.conv.to!string(this.clientId) ~ ")"; 285 } 286 287 } 288 289 class OpenConnectionReply2 : Buffer { 290 291 public enum ubyte ID = 8; 292 293 public enum bool CLIENTBOUND = true; 294 public enum bool SERVERBOUND = false; 295 296 public enum string[] FIELDS = ["magic", "serverId", "clientAddress", "mtuLength", "security"]; 297 298 public ubyte[16] magic; 299 public long serverId; 300 public sul.protocol.raknet8.types.Address clientAddress; 301 public ushort mtuLength; 302 public bool security; 303 304 public pure nothrow @safe @nogc this() {} 305 306 public pure nothrow @safe @nogc this(ubyte[16] magic, long serverId=long.init, sul.protocol.raknet8.types.Address clientAddress=sul.protocol.raknet8.types.Address.init, ushort mtuLength=ushort.init, bool security=bool.init) { 307 this.magic = magic; 308 this.serverId = serverId; 309 this.clientAddress = clientAddress; 310 this.mtuLength = mtuLength; 311 this.security = security; 312 } 313 314 public pure nothrow @safe ubyte[] encode(bool writeId=true)() { 315 _buffer.length = 0; 316 static if(writeId){ writeBigEndianUbyte(ID); } 317 writeBytes(magic); 318 writeBigEndianLong(serverId); 319 clientAddress.encode(bufferInstance); 320 writeBigEndianUshort(mtuLength); 321 writeBigEndianBool(security); 322 return _buffer; 323 } 324 325 public pure nothrow @safe void decode(bool readId=true)() { 326 static if(readId){ ubyte _id; _id=readBigEndianUbyte(); } 327 if(_buffer.length>=_index+magic.length){ magic=_buffer[_index.._index+magic.length].dup; _index+=magic.length; } 328 serverId=readBigEndianLong(); 329 clientAddress.decode(bufferInstance); 330 mtuLength=readBigEndianUshort(); 331 security=readBigEndianBool(); 332 } 333 334 public static pure nothrow @safe OpenConnectionReply2 fromBuffer(bool readId=true)(ubyte[] buffer) { 335 OpenConnectionReply2 ret = new OpenConnectionReply2(); 336 ret._buffer = buffer; 337 ret.decode!readId(); 338 return ret; 339 } 340 341 public override string toString() { 342 return "OpenConnectionReply2(magic: " ~ std.conv.to!string(this.magic) ~ ", serverId: " ~ std.conv.to!string(this.serverId) ~ ", clientAddress: " ~ std.conv.to!string(this.clientAddress) ~ ", mtuLength: " ~ std.conv.to!string(this.mtuLength) ~ ", security: " ~ std.conv.to!string(this.security) ~ ")"; 343 } 344 345 } 346