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/java340.xml 8 */ 9 module sul.protocol.java340.login; 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.java340.types; 22 23 static if(__traits(compiles, { import sul.metadata.java340; })) import sul.metadata.java340; 24 25 alias Packets = TypeTuple!(Disconnect, LoginStart, EncryptionRequest, EncryptionResponse, LoginSuccess, SetCompression); 26 27 class Disconnect : Buffer { 28 29 public enum uint ID = 0; 30 31 public enum bool CLIENTBOUND = true; 32 public enum bool SERVERBOUND = false; 33 34 public enum string[] FIELDS = ["reason"]; 35 36 public string reason; 37 38 public pure nothrow @safe @nogc this() {} 39 40 public pure nothrow @safe @nogc this(string reason) { 41 this.reason = reason; 42 } 43 44 public pure nothrow @safe ubyte[] encode(bool writeId=true)() { 45 _buffer.length = 0; 46 static if(writeId){ writeBytes(varuint.encode(ID)); } 47 writeBytes(varuint.encode(cast(uint)reason.length)); writeString(reason); 48 return _buffer; 49 } 50 51 public pure nothrow @safe void decode(bool readId=true)() { 52 static if(readId){ uint _id; _id=varuint.decode(_buffer, &_index); } 53 uint cvc9=varuint.decode(_buffer, &_index); reason=readString(cvc9); 54 } 55 56 public static pure nothrow @safe Disconnect fromBuffer(bool readId=true)(ubyte[] buffer) { 57 Disconnect ret = new Disconnect(); 58 ret._buffer = buffer; 59 ret.decode!readId(); 60 return ret; 61 } 62 63 public override string toString() { 64 return "Disconnect(reason: " ~ std.conv.to!string(this.reason) ~ ")"; 65 } 66 67 } 68 69 class LoginStart : Buffer { 70 71 public enum uint ID = 0; 72 73 public enum bool CLIENTBOUND = false; 74 public enum bool SERVERBOUND = true; 75 76 public enum string[] FIELDS = ["username"]; 77 78 public string username; 79 80 public pure nothrow @safe @nogc this() {} 81 82 public pure nothrow @safe @nogc this(string username) { 83 this.username = username; 84 } 85 86 public pure nothrow @safe ubyte[] encode(bool writeId=true)() { 87 _buffer.length = 0; 88 static if(writeId){ writeBytes(varuint.encode(ID)); } 89 writeBytes(varuint.encode(cast(uint)username.length)); writeString(username); 90 return _buffer; 91 } 92 93 public pure nothrow @safe void decode(bool readId=true)() { 94 static if(readId){ uint _id; _id=varuint.decode(_buffer, &_index); } 95 uint dnc5bu=varuint.decode(_buffer, &_index); username=readString(dnc5bu); 96 } 97 98 public static pure nothrow @safe LoginStart fromBuffer(bool readId=true)(ubyte[] buffer) { 99 LoginStart ret = new LoginStart(); 100 ret._buffer = buffer; 101 ret.decode!readId(); 102 return ret; 103 } 104 105 public override string toString() { 106 return "LoginStart(username: " ~ std.conv.to!string(this.username) ~ ")"; 107 } 108 109 } 110 111 class EncryptionRequest : Buffer { 112 113 public enum uint ID = 1; 114 115 public enum bool CLIENTBOUND = true; 116 public enum bool SERVERBOUND = false; 117 118 public enum string[] FIELDS = ["serverId", "publicKey", "verifyToken"]; 119 120 public string serverId; 121 public ubyte[] publicKey; 122 public ubyte[] verifyToken; 123 124 public pure nothrow @safe @nogc this() {} 125 126 public pure nothrow @safe @nogc this(string serverId, ubyte[] publicKey=(ubyte[]).init, ubyte[] verifyToken=(ubyte[]).init) { 127 this.serverId = serverId; 128 this.publicKey = publicKey; 129 this.verifyToken = verifyToken; 130 } 131 132 public pure nothrow @safe ubyte[] encode(bool writeId=true)() { 133 _buffer.length = 0; 134 static if(writeId){ writeBytes(varuint.encode(ID)); } 135 writeBytes(varuint.encode(cast(uint)serverId.length)); writeString(serverId); 136 writeBytes(varuint.encode(cast(uint)publicKey.length)); writeBytes(publicKey); 137 writeBytes(varuint.encode(cast(uint)verifyToken.length)); writeBytes(verifyToken); 138 return _buffer; 139 } 140 141 public pure nothrow @safe void decode(bool readId=true)() { 142 static if(readId){ uint _id; _id=varuint.decode(_buffer, &_index); } 143 uint cvdvsq=varuint.decode(_buffer, &_index); serverId=readString(cvdvsq); 144 publicKey.length=varuint.decode(_buffer, &_index); if(_buffer.length>=_index+publicKey.length){ publicKey=_buffer[_index.._index+publicKey.length].dup; _index+=publicKey.length; } 145 verifyToken.length=varuint.decode(_buffer, &_index); if(_buffer.length>=_index+verifyToken.length){ verifyToken=_buffer[_index.._index+verifyToken.length].dup; _index+=verifyToken.length; } 146 } 147 148 public static pure nothrow @safe EncryptionRequest fromBuffer(bool readId=true)(ubyte[] buffer) { 149 EncryptionRequest ret = new EncryptionRequest(); 150 ret._buffer = buffer; 151 ret.decode!readId(); 152 return ret; 153 } 154 155 public override string toString() { 156 return "EncryptionRequest(serverId: " ~ std.conv.to!string(this.serverId) ~ ", publicKey: " ~ std.conv.to!string(this.publicKey) ~ ", verifyToken: " ~ std.conv.to!string(this.verifyToken) ~ ")"; 157 } 158 159 } 160 161 class EncryptionResponse : Buffer { 162 163 public enum uint ID = 1; 164 165 public enum bool CLIENTBOUND = false; 166 public enum bool SERVERBOUND = true; 167 168 public enum string[] FIELDS = ["sharedSecret", "verifyToken"]; 169 170 public ubyte[] sharedSecret; 171 public ubyte[] verifyToken; 172 173 public pure nothrow @safe @nogc this() {} 174 175 public pure nothrow @safe @nogc this(ubyte[] sharedSecret, ubyte[] verifyToken=(ubyte[]).init) { 176 this.sharedSecret = sharedSecret; 177 this.verifyToken = verifyToken; 178 } 179 180 public pure nothrow @safe ubyte[] encode(bool writeId=true)() { 181 _buffer.length = 0; 182 static if(writeId){ writeBytes(varuint.encode(ID)); } 183 writeBytes(varuint.encode(cast(uint)sharedSecret.length)); writeBytes(sharedSecret); 184 writeBytes(varuint.encode(cast(uint)verifyToken.length)); writeBytes(verifyToken); 185 return _buffer; 186 } 187 188 public pure nothrow @safe void decode(bool readId=true)() { 189 static if(readId){ uint _id; _id=varuint.decode(_buffer, &_index); } 190 sharedSecret.length=varuint.decode(_buffer, &_index); if(_buffer.length>=_index+sharedSecret.length){ sharedSecret=_buffer[_index.._index+sharedSecret.length].dup; _index+=sharedSecret.length; } 191 verifyToken.length=varuint.decode(_buffer, &_index); if(_buffer.length>=_index+verifyToken.length){ verifyToken=_buffer[_index.._index+verifyToken.length].dup; _index+=verifyToken.length; } 192 } 193 194 public static pure nothrow @safe EncryptionResponse fromBuffer(bool readId=true)(ubyte[] buffer) { 195 EncryptionResponse ret = new EncryptionResponse(); 196 ret._buffer = buffer; 197 ret.decode!readId(); 198 return ret; 199 } 200 201 public override string toString() { 202 return "EncryptionResponse(sharedSecret: " ~ std.conv.to!string(this.sharedSecret) ~ ", verifyToken: " ~ std.conv.to!string(this.verifyToken) ~ ")"; 203 } 204 205 } 206 207 class LoginSuccess : Buffer { 208 209 public enum uint ID = 2; 210 211 public enum bool CLIENTBOUND = true; 212 public enum bool SERVERBOUND = false; 213 214 public enum string[] FIELDS = ["uuid", "username"]; 215 216 public string uuid; 217 public string username; 218 219 public pure nothrow @safe @nogc this() {} 220 221 public pure nothrow @safe @nogc this(string uuid, string username=string.init) { 222 this.uuid = uuid; 223 this.username = username; 224 } 225 226 public pure nothrow @safe ubyte[] encode(bool writeId=true)() { 227 _buffer.length = 0; 228 static if(writeId){ writeBytes(varuint.encode(ID)); } 229 writeBytes(varuint.encode(cast(uint)uuid.length)); writeString(uuid); 230 writeBytes(varuint.encode(cast(uint)username.length)); writeString(username); 231 return _buffer; 232 } 233 234 public pure nothrow @safe void decode(bool readId=true)() { 235 static if(readId){ uint _id; _id=varuint.decode(_buffer, &_index); } 236 uint dvz=varuint.decode(_buffer, &_index); uuid=readString(dvz); 237 uint dnc5bu=varuint.decode(_buffer, &_index); username=readString(dnc5bu); 238 } 239 240 public static pure nothrow @safe LoginSuccess fromBuffer(bool readId=true)(ubyte[] buffer) { 241 LoginSuccess ret = new LoginSuccess(); 242 ret._buffer = buffer; 243 ret.decode!readId(); 244 return ret; 245 } 246 247 public override string toString() { 248 return "LoginSuccess(uuid: " ~ std.conv.to!string(this.uuid) ~ ", username: " ~ std.conv.to!string(this.username) ~ ")"; 249 } 250 251 } 252 253 class SetCompression : Buffer { 254 255 public enum uint ID = 3; 256 257 public enum bool CLIENTBOUND = true; 258 public enum bool SERVERBOUND = false; 259 260 public enum string[] FIELDS = ["thresold"]; 261 262 public uint thresold; 263 264 public pure nothrow @safe @nogc this() {} 265 266 public pure nothrow @safe @nogc this(uint thresold) { 267 this.thresold = thresold; 268 } 269 270 public pure nothrow @safe ubyte[] encode(bool writeId=true)() { 271 _buffer.length = 0; 272 static if(writeId){ writeBytes(varuint.encode(ID)); } 273 writeBytes(varuint.encode(thresold)); 274 return _buffer; 275 } 276 277 public pure nothrow @safe void decode(bool readId=true)() { 278 static if(readId){ uint _id; _id=varuint.decode(_buffer, &_index); } 279 thresold=varuint.decode(_buffer, &_index); 280 } 281 282 public static pure nothrow @safe SetCompression fromBuffer(bool readId=true)(ubyte[] buffer) { 283 SetCompression ret = new SetCompression(); 284 ret._buffer = buffer; 285 ret.decode!readId(); 286 return ret; 287 } 288 289 public override string toString() { 290 return "SetCompression(thresold: " ~ std.conv.to!string(this.thresold) ~ ")"; 291 } 292 293 } 294