IT WORKS AND LOGS IN!!!!

This commit is contained in:
Kitteh 2021-06-02 18:57:07 +01:00
parent 86286c9afd
commit fbb68deb7f
4 changed files with 37 additions and 5 deletions

View file

@ -12,5 +12,5 @@ pub fn main() !void {
var client = initClient(allocator, &sock); var client = initClient(allocator, &sock);
try client.handshake(); try client.handshake();
try client.quassel_init_packet(); try client.quassel_init_packet();
try client.quassel_login("z", "PASSWORD"); try client.quassel_login("z", "password");
} }

View file

@ -9,6 +9,7 @@ pub const QVariant = union(enum) {
string: []const u8, string: []const u8,
stringlist: std.ArrayList([]const u8), stringlist: std.ArrayList([]const u8),
qmap: std.StringHashMap(QVariant), qmap: std.StringHashMap(QVariant),
qvarlist: std.ArrayList(QVariant),
empty: bool, empty: bool,
}; };
@ -18,6 +19,7 @@ pub const QVariantTypes = enum(u32) {
int_1 = 2, int_1 = 2,
int_2 = 3, int_2 = 3,
qmap = 8, qmap = 8,
qvarlist = 9,
string = 10, string = 10,
stringlist = 11, stringlist = 11,
bytearray = 12, bytearray = 12,
@ -35,6 +37,9 @@ pub fn qvariant_type_id(variant: QVariant) !u32 {
.qmap => { .qmap => {
return @enumToInt(QVariantTypes.qmap); return @enumToInt(QVariantTypes.qmap);
}, },
.qvarlist => {
return @enumToInt(QVariantTypes.qvarlist);
},
.string => { .string => {
return @enumToInt(QVariantTypes.string); return @enumToInt(QVariantTypes.string);
}, },
@ -81,6 +86,15 @@ pub fn pretty_print_variant(variant: QVariant, indentLevel: u64) void {
pretty_print_variant(v.value, indentLevel + 2); pretty_print_variant(v.value, indentLevel + 2);
} }
}, },
.qvarlist => |l| {
std.debug.print("QVarList:\n", .{});
for (l.items) |varient, i| {
print_indent_level(indentLevel + 1);
std.debug.print("Item #{d}\n", .{i});
pretty_print_variant(varient, indentLevel + 2);
}
},
.string => |s| { .string => |s| {
std.debug.print("String: \"{s}\"\n", .{s}); std.debug.print("String: \"{s}\"\n", .{s});
}, },

View file

@ -56,6 +56,17 @@ pub fn get_string(reader: anytype, allocator: *std.mem.Allocator) ![]u8 {
return ut8Str; return ut8Str;
} }
pub fn get_qvarlist(reader: anytype, allocator: *std.mem.Allocator) !std.ArrayList(qvar.QVariant) {
var varlist = std.ArrayList(qvar.QVariant).init(allocator);
var size = try get_int(reader);
var i: u32 = 0;
while (i < size) {
try varlist.append(try get_variant(reader, allocator));
i = i + 1;
}
return varlist;
}
pub fn get_stringlist(reader: anytype, allocator: *std.mem.Allocator) !std.ArrayList([]const u8) { pub fn get_stringlist(reader: anytype, allocator: *std.mem.Allocator) !std.ArrayList([]const u8) {
var strList = std.ArrayList([]const u8).init(allocator); var strList = std.ArrayList([]const u8).init(allocator);
var size = try get_int(reader); var size = try get_int(reader);
@ -81,6 +92,10 @@ pub fn get_variant_t(reader: anytype, type_id: u32, allocator: *std.mem.Allocato
var map = try get_qvariantmap(reader, allocator); var map = try get_qvariantmap(reader, allocator);
return qvar.QVariant{ .qmap = map }; return qvar.QVariant{ .qmap = map };
}, },
@enumToInt(qvar.QVariantTypes.qvarlist) => {
var list = try get_qvarlist(reader, allocator);
return qvar.QVariant{ .qvarlist = list };
},
@enumToInt(qvar.QVariantTypes.string) => { @enumToInt(qvar.QVariantTypes.string) => {
var str = try get_string(reader, allocator); var str = try get_string(reader, allocator);
return qvar.QVariant{ .string = str }; return qvar.QVariant{ .string = str };
@ -97,7 +112,10 @@ pub fn get_variant_t(reader: anytype, type_id: u32, allocator: *std.mem.Allocato
var short = try get_short(reader); var short = try get_short(reader);
return qvar.QVariant{ .short = short }; return qvar.QVariant{ .short = short };
}, },
else => {}, else => {
@panic("Unsupported!");
},
} }
return qvar.QVariant{ .empty = true }; return qvar.QVariant{ .empty = true };
} }

View file

@ -39,8 +39,8 @@ pub fn add_stringlist(writer: anytype, allocator: *std.mem.Allocator, strList: s
pub fn add_variantlist(writer: anytype, allocator: *std.mem.Allocator, varList: std.ArrayList([]qvar.QVariant)) !void { pub fn add_variantlist(writer: anytype, allocator: *std.mem.Allocator, varList: std.ArrayList([]qvar.QVariant)) !void {
try add_int(writer, @intCast(u32, varList.items.len)); try add_int(writer, @intCast(u32, varList.items.len));
for (varList.items) |var| { for (varList.items) |v| {
try add_variant(writer, allocator, varList); try add_variant(writer, allocator, v);
} }
} }
@ -75,7 +75,7 @@ pub fn add_qvariant(writer: anytype, allocator: *std.mem.Allocator, variant: qva
try add_short(writer, out); try add_short(writer, out);
}, },
else => { else => {
return; @panic("Unsupported!");
}, },
} }
} }