From 4766792492a08cb8872594460b87bfae8975d87d Mon Sep 17 00:00:00 2001 From: Kitteh Date: Wed, 2 Jun 2021 17:25:05 +0100 Subject: [PATCH] iepkri --- src/client.zig | 40 ++++++++++++++++++++++------------------ src/main.zig | 4 ++-- src/qtshit/read.zig | 4 ++++ src/qtshit/write.zig | 2 +- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/client.zig b/src/client.zig index 2594e39..1e59976 100644 --- a/src/client.zig +++ b/src/client.zig @@ -23,37 +23,41 @@ pub const Client = struct { const magic = 0x42b33f00; try write.add_int(s.stream.writer(), magic); - try write.add_int(s.stream.writer(), 2); - try write.add_int(s.stream.writer(), 1 << 31); - var resp = try read.get_int(s.stream.reader()); - if ((resp & 0xff) != 1) { - @panic("No support 4 legacy protocol."); - } + try write.add_int(s.stream.writer(), 0x80000002); + var flags = try read.get_byte(s.stream.reader()); + var extra = try read.get_short(s.stream.reader()); + var version = try read.get_signed_byte(s.stream.reader()); - if (((resp >> 24) & 1) != 0) { - @panic("No support 4 ssl protocol."); - } - - if (((resp >> 24) & 2) != 0) { - @panic("No support 4 compression."); - } - std.debug.print("Handshake Success!\n", .{}); + std.debug.print("Handshake: flags={d} extra={d} version={d} \n", .{flags, extra, version}); } 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); - try map.put("UseSSL", .{ .byte = 0 }); - try map.put("UseCompression", .{ .byte = 0 }); - try map.put("ProtocolVersion", .{ .int = 10 }); + //try map.put("UseSSL", .{ .byte = 0 }); + //try map.put("UseCompression", .{ .byte = 0 }); + //try map.put("ProtocolVersion", .{ .int = 10 }); try map.put("MsgType", .{ .string = "ClientInit" }); try map.put("ClientVersion", .{ .string = "0.1 (quasselclient)" }); - try map.put("ClientDate", .{ .string = "0" }); + try map.put("BuildDate", .{ .string = "0" }); + try map.put("ClientFeatures", .{ .int = 0 }); + var empty = std.ArrayList([]const u8).init(s.allocator); + try map.put("FeatureList", .{ .stringlist = empty }); try write.add_message(list.writer(), s.allocator, map); try dumpDebug("ClientInit.bin", list); try s.stream.writer().writeAll(list.items); + + std.debug.print("meow \n", .{}); + + var size = read.get_int(s.stream.reader()); + std.debug.print("InitResp: size={d} \n", .{size}); + + var varient = read.get_variant(s.stream.reader(), s.allocator); + std.debug.print("InitResp: varient={d} \n", .{varient}); + + } pub fn quassel_login(s: *Client, username: []const u8, password: []const u8) !void { var list = std.ArrayList(u8).init(s.allocator); diff --git a/src/main.zig b/src/main.zig index a6105b8..8c37d30 100644 --- a/src/main.zig +++ b/src/main.zig @@ -7,10 +7,10 @@ const initClient = @import("./client.zig").initClient; pub fn main() !void { const allocator = std.heap.page_allocator; - var sock = try std.net.tcpConnectToHost(allocator, "127.0.0.1", 4242); + var sock = try std.net.tcpConnectToHost(allocator, "109.70.144.142", 4242); var client = initClient(allocator, &sock); try client.handshake(); try client.quassel_init_packet(); - try client.quassel_login("z", "password"); + //try client.quassel_login("z", "PASSWORD"); } diff --git a/src/qtshit/read.zig b/src/qtshit/read.zig index e5dee80..0080897 100644 --- a/src/qtshit/read.zig +++ b/src/qtshit/read.zig @@ -14,6 +14,10 @@ pub fn get_byte(reader: anytype) !u8 { return try reader.readByte(); } +pub fn get_signed_byte(reader: anytype) !i8 { + return try reader.readIntBig(i8); +} + pub fn get_bytearray(reader: anytype, allocator: *std.mem.Allocator) !std.ArrayList(u8) { var byteList = std.ArrayList(u8).init(allocator); var length = try get_int(reader); diff --git a/src/qtshit/write.zig b/src/qtshit/write.zig index 518a70d..314edc5 100644 --- a/src/qtshit/write.zig +++ b/src/qtshit/write.zig @@ -94,7 +94,7 @@ pub fn add_message(writer: anytype, allocator: *std.mem.Allocator, map: std.Stri var data = std.ArrayList(u8).init(allocator); try add_qvariantmap(data.writer(), allocator, map); - try add_int(writer, @intCast(u32, data.items.len * 8)); + try add_int(writer, @intCast(u32, data.items.len)); try writer.writeAll(data.items); return;