hgoijreiriureo

This commit is contained in:
Kitteh 2021-06-02 18:42:46 +01:00
parent b35d589456
commit 86286c9afd
5 changed files with 67 additions and 16 deletions

View file

@ -36,6 +36,7 @@ pub const Client = struct {
var map = std.StringHashMap(qvar.QVariant).init(s.allocator);
try map.put("MsgType", .{ .string = "ClientInit" });
try map.put("ProtocolVersion", .{ .int = 10 });
try map.put("ClientVersion", .{ .string = "0.1 (quasselclient)" });
try map.put("ClientDate", .{ .string = "Wed, 02 Jun 2021 17:30:30 +0100" });
try map.put("Features", .{ .int = 0 });
@ -46,16 +47,21 @@ pub const Client = struct {
try dumpDebug("ClientInit.bin", list);
try s.stream.writer().writeAll(list.items);
std.debug.print("meow \n", .{});
std.debug.print("\n\nInitPacket: \n", .{});
qvar.pretty_print_variant(.{.qmap = map}, 0);
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});
//std.debug.print("InitResp: size={d} \n", .{size});
std.debug.print("\n\nInitResponse: \n", .{});
var varient = try read.get_variant(s.stream.reader(), s.allocator);
qvar.pretty_print_variant(varient, 0);
//std.debug.print("InitResp: type={s} \n", .{varient.qmap.get("MsgType").?.string});
}
pub fn quassel_login(s: *Client, username: []const u8, password: []const u8) !void {
var list = std.ArrayList(u8).init(s.allocator);
@ -65,7 +71,6 @@ pub const Client = struct {
try map.put("User", .{ .string = username });
try map.put("Password", .{ .string = password });
try write.add_message(list.writer(), s.allocator, map);
try dumpDebug("ClientLogin.bin", list);

View file

@ -7,7 +7,7 @@ const initClient = @import("./client.zig").initClient;
pub fn main() !void {
const allocator = std.heap.page_allocator;
var sock = try std.net.tcpConnectToHost(allocator, "109.70.144.142", 4242);
var sock = try std.net.tcpConnectToHost(allocator, "127.0.0.1", 64242);
var client = initClient(allocator, &sock);
try client.handshake();

View file

@ -1,4 +1,5 @@
const std = @import("std");
const range = @import("./rangeiter.zig").range;
pub const QVariant = union(enum) {
int: u32,
@ -51,3 +52,43 @@ pub fn qvariant_type_id(variant: QVariant) !u32 {
},
}
}
pub fn print_indent_level(indentLevel: u64) void {
var iter = range(u64, 0, indentLevel);
while (iter.next()) |i| {
std.debug.print(" ", .{});
}
}
pub fn pretty_print_variant(variant: QVariant, indentLevel: u64) void {
print_indent_level(indentLevel);
switch (variant) {
.byte => |b| {
std.debug.print("Byte: {d}\n", .{b});
},
.int => |i| {
std.debug.print("Int: {d}\n", .{i});
},
.qmap => |q| {
std.debug.print("QMap:\n", .{});
var qMapIter = q.iterator();
while (qMapIter.next()) |v| {
print_indent_level(indentLevel + 1);
std.debug.print("Key: \"{s}\"\n", .{v.key});
print_indent_level(indentLevel + 1);
std.debug.print("Value:\n", .{});
pretty_print_variant(v.value, indentLevel + 2);
}
},
.string => |s| {
std.debug.print("String: \"{s}\"\n", .{s});
},
.stringlist => {},
.bytearray => {},
.short => |s| {
std.debug.print("Short: \"{d}\"\n", .{s});
},
else => {},
}
}

View file

@ -38,15 +38,13 @@ pub fn get_string(reader: anytype, allocator: *std.mem.Allocator) ![]u8 {
var length = try reader.readIntBig(i32);
var chars = @divTrunc(length, 2);
// std.debug.print("get_lenchars: {d} {d} \n", .{length, chars});
var index: usize = 0;
while (true) {
if (index == chars) break;
const byte = try reader.readIntBig(u16);
try data.append(@intCast(u8, byte));
try data.append(@truncate(u8, byte));
index += 1;
}

View file

@ -37,6 +37,13 @@ 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 {
try add_int(writer, @intCast(u32, varList.items.len));
for (varList.items) |var| {
try add_variant(writer, allocator, varList);
}
}
// Call this and Then write your type
pub fn add_qvariant_with_id(writer: anytype, type_id: u32) !void {
try add_int(writer, type_id);