63 lines
1.9 KiB
Zig
63 lines
1.9 KiB
Zig
const std = @import("std");
|
|
|
|
const DebugAllocator = @import("./debug_allocator.zig");
|
|
const write = @import("./qtshit/write.zig");
|
|
const initClient = @import("./client.zig").initClient;
|
|
|
|
pub fn realMain(allocator: *std.mem.Allocator) !void {
|
|
var argIter = std.process.args();
|
|
|
|
allocator.free(try argIter.next(allocator).?);
|
|
|
|
var host = try argIter.next(allocator).?;
|
|
defer allocator.free(host);
|
|
var port = try argIter.next(allocator).?;
|
|
defer allocator.free(port);
|
|
var portInt = try std.fmt.parseInt(u16, port, 10);
|
|
var username = try argIter.next(allocator).?;
|
|
defer allocator.free(username);
|
|
var password = try argIter.next(allocator).?;
|
|
defer allocator.free(password);
|
|
|
|
std.debug.print("host={s} port={d}\n", .{ host, portInt });
|
|
|
|
var sock = try std.net.tcpConnectToHost(allocator, host, portInt);
|
|
|
|
var client = initClient(allocator, &sock);
|
|
defer client.deinit();
|
|
|
|
try client.handshake();
|
|
try client.quassel_init_packet();
|
|
try client.quassel_login(username, password);
|
|
|
|
//var bufferInfo = try client.bufferManager.getFirstByName("z_is_stimky");
|
|
//try client.send_message(bufferInfo.?, "uwu, owo, uwu");
|
|
|
|
while (true) {
|
|
std.time.sleep(100 * std.time.ns_per_ms);
|
|
|
|
client.read_quassel_packet() catch |err| {
|
|
if (err == error.DecodeError) {
|
|
std.debug.print("Decode Error.\n", .{});
|
|
} else if (err == error.EndOfStream) {
|
|
std.debug.print("EOS.\n", .{});
|
|
//std.time.sleep(1000 * std.time.ns_per_ms);
|
|
return;
|
|
} else {
|
|
return err;
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
pub fn main() !void {
|
|
var gpalloc = std.heap.GeneralPurposeAllocator(.{
|
|
.stack_trace_frames = 20,
|
|
}){};
|
|
defer std.debug.assert(!gpalloc.deinit());
|
|
|
|
const alloc = &gpalloc.allocator;
|
|
|
|
try realMain(alloc);
|
|
}
|