1 module draklib.protocol.unconnected;
2 import draklib.core : RakNetInfo;
3 import draklib.bytestream : ByteStream;
4 import draklib.protocol.packet;
5 
6 class UnconnectedPingPacket1 : Packet {
7 	long time;
8 
9 	override {
10 		protected void _encode(ref ByteStream stream) {
11 			stream.writeLong(time);
12 			stream.writeU(RakNetInfo.RAKNET_MAGIC);
13 		}
14 
15 		protected void _decode(ref ByteStream stream) {
16 			time = stream.readLong();
17 			// MAGIC
18 		}
19 
20 		ubyte getID() {
21 			return RakNetInfo.UNCONNECTED_PING_1;
22 		}
23 
24 		uint getSize() {
25 			return 25;
26 		}
27 	}
28 }
29 
30 class UnconnectedPingPacket2 : UnconnectedPingPacket1 {
31 	override {
32 		ubyte getID() {
33 			return RakNetInfo.UNCONNECTED_PING_2;
34 		}
35 	}
36 }
37 
38 class UnconnectedPongPacket : Packet {
39 	long time;
40 	long serverGUID;
41 	string serverInfo;
42 	
43 	override {
44 		protected void _encode(ref ByteStream stream) {
45 			stream.writeLong(time);
46 			stream.writeLong(serverGUID);
47 			stream.writeU(RakNetInfo.RAKNET_MAGIC);
48 			stream.writeStrUTF8(serverInfo);
49 		}
50 		
51 		protected void _decode(ref ByteStream stream) {
52 			time = stream.readLong();
53 			serverGUID = stream.readLong();
54 			stream.skip(RakNetInfo.RAKNET_MAGIC.length);
55 			serverInfo = stream.readStrUTF8();
56 		}
57 
58 		ubyte getID() {
59 			return RakNetInfo.UNCONNECTED_PONG;
60 		}
61 		
62 		uint getSize() {
63 			return cast(uint) (35 + (cast(byte[]) serverInfo).length);
64 		}
65 	}
66 }
67 
68 class AdvertiseSystemPacket : UnconnectedPongPacket {
69 	override {
70 		ubyte getID() {
71 			return RakNetInfo.ADVERTISE_SYSTEM;
72 		}
73 	}
74 }