This commit is contained in:
Kitteh 2021-06-02 17:25:05 +01:00
parent 52bee8473d
commit 4766792492
4 changed files with 29 additions and 21 deletions

View file

@ -23,37 +23,41 @@ pub const Client = struct {
const magic = 0x42b33f00; const magic = 0x42b33f00;
try write.add_int(s.stream.writer(), magic); try write.add_int(s.stream.writer(), magic);
try write.add_int(s.stream.writer(), 2); try write.add_int(s.stream.writer(), 0x80000002);
try write.add_int(s.stream.writer(), 1 << 31); var flags = try read.get_byte(s.stream.reader());
var resp = try read.get_int(s.stream.reader()); var extra = try read.get_short(s.stream.reader());
if ((resp & 0xff) != 1) { var version = try read.get_signed_byte(s.stream.reader());
@panic("No support 4 legacy protocol.");
}
if (((resp >> 24) & 1) != 0) { std.debug.print("Handshake: flags={d} extra={d} version={d} \n", .{flags, extra, version});
@panic("No support 4 ssl protocol.");
}
if (((resp >> 24) & 2) != 0) {
@panic("No support 4 compression.");
}
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 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 });
try map.put("ProtocolVersion", .{ .int = 10 }); //try map.put("ProtocolVersion", .{ .int = 10 });
try map.put("MsgType", .{ .string = "ClientInit" }); try map.put("MsgType", .{ .string = "ClientInit" });
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("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 write.add_message(list.writer(), s.allocator, map);
try dumpDebug("ClientInit.bin", list); try dumpDebug("ClientInit.bin", list);
try s.stream.writer().writeAll(list.items); 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 { pub fn quassel_login(s: *Client, username: []const u8, password: []const u8) !void {
var list = std.ArrayList(u8).init(s.allocator); var list = std.ArrayList(u8).init(s.allocator);

View file

@ -7,10 +7,10 @@ const initClient = @import("./client.zig").initClient;
pub fn main() !void { pub fn main() !void {
const allocator = std.heap.page_allocator; 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); 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

@ -14,6 +14,10 @@ pub fn get_byte(reader: anytype) !u8 {
return try reader.readByte(); 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) { pub fn get_bytearray(reader: anytype, allocator: *std.mem.Allocator) !std.ArrayList(u8) {
var byteList = std.ArrayList(u8).init(allocator); var byteList = std.ArrayList(u8).init(allocator);
var length = try get_int(reader); var length = try get_int(reader);

View file

@ -94,7 +94,7 @@ pub fn add_message(writer: anytype, allocator: *std.mem.Allocator, map: std.Stri
var data = std.ArrayList(u8).init(allocator); var data = std.ArrayList(u8).init(allocator);
try add_qvariantmap(data.writer(), allocator, map); 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); try writer.writeAll(data.items);
return; return;