Add dumpDebug()

This commit is contained in:
Kitteh 2021-06-02 12:29:51 +01:00
parent 655363a79e
commit c3589cd74f
2 changed files with 22 additions and 4 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
material material
zig-cache zig-cache
*.bin

View file

@ -3,6 +3,17 @@ const read = @import("./qtshit/read.zig");
const write = @import("./qtshit/write.zig"); const write = @import("./qtshit/write.zig");
const qvar = @import("./qtshit/qvariant.zig"); const qvar = @import("./qtshit/qvariant.zig");
fn dumpDebug(name: []const u8, list: std.ArrayList(u8)) !void {
const file = try std.fs.cwd().createFile(
name,
.{ .read = true },
);
defer file.close();
try file.writeAll(list.items);
try file.seekTo(0);
}
pub const Client = struct { pub const Client = struct {
allocator: *std.mem.Allocator, allocator: *std.mem.Allocator,
stream: *std.net.Stream, stream: *std.net.Stream,
@ -25,9 +36,11 @@ pub const Client = struct {
if (((resp >> 24) & 2) != 0) { if (((resp >> 24) & 2) != 0) {
@panic("No support 4 compression."); @panic("No support 4 compression.");
} }
std.debug.print("handshake Success!\n", .{}); std.debug.print("Handshake Success!\n", .{});
} }
pub fn quassel_init_packet(s: *Client) !void { pub fn quassel_init_packet(s: *Client) !void {
var list = std.ArrayList(u8).init(s.allocator);
var map = std.StringHashMap(qvar.QVariant).init(s.allocator); var map = std.StringHashMap(qvar.QVariant).init(s.allocator);
try map.put("UseSSL", .{ .byte = 0 }); try map.put("UseSSL", .{ .byte = 0 });
try map.put("UseCompression", .{ .byte = 0 }); try map.put("UseCompression", .{ .byte = 0 });
@ -36,14 +49,18 @@ pub const Client = struct {
try map.put("ClientVersion", .{ .string = "0.1 (quasselclient)" }); try map.put("ClientVersion", .{ .string = "0.1 (quasselclient)" });
try map.put("ClientDate", .{ .string = "0" }); try map.put("ClientDate", .{ .string = "0" });
try write.add_qvariantmap(s.stream.writer(), map); try write.add_qvariantmap(list.writer(), map);
try dumpDebug("ClientInit.bin", list);
try s.stream.writer().writeAll(list.items);
} }
pub fn quassel_login(s: *Client, username: []const u8, password: []const u8) !void { pub fn quassel_login(s: *Client, username: []const u8, password: []const u8) !void {
var map = std.StringHashMap(qvar.QVariant).init(s.allocator); var map = std.StringHashMap(qvar.QVariant).init(s.allocator);
try map.put("MsgType", .{ .string = "ClientLogin" }); try map.put("MsgType", .{ .string = "ClientLogin" });
try map.put("User", .{ .string = username }); try map.put("User", .{ .string = username });
try map.put("Password", .{ .string = password}); try map.put("Password", .{ .string = password });
try write.add_qvariantmap(s.stream.writer(), map); try write.add_qvariantmap(s.stream.writer(), map);
} }