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