an experimental irc client

config: accept an optional server port number

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>

+24 -2
+2
docs/comlink.3.scd
··· 37 38 The following optional fields are available: 39 40 - *tls*: boolean (default=true), when true, use an encrypted connection 41 42 *comlink.log*
··· 37 38 The following optional fields are available: 39 40 + - *port*: uint16 (default=6697 (tls) or 6667), port to use for 41 + connection 42 - *tls*: boolean (default=true), when true, use an encrypted connection 43 44 *comlink.log*
+1
docs/comlink.lua
··· 13 ---@field password string Password for server 14 ---@field real_name string Real name of user 15 ---@field tls? boolean Whether to encrypt connections 16 17 ---A connection to a server 18 ---
··· 13 ---@field password string Password for server 14 ---@field real_name string Real name of user 15 ---@field tls? boolean Whether to encrypt connections 16 + ---@field port? number Optional port to use for server connection. Defaults to 6697 for TLS connections and 6667 for plaintext connections 17 18 ---A connection to a server 19 ---
+5 -2
src/irc.zig
··· 444 password: []const u8, 445 real_name: []const u8, 446 server: []const u8, 447 network_id: ?[]const u8 = null, 448 name: ?[]const u8 = null, 449 tls: bool = true, ··· 676 677 pub fn connect(self: *Client) !void { 678 if (self.config.tls) { 679 - self.stream = try std.net.tcpConnectToHost(self.alloc, self.config.server, 6697); 680 self.client = try tls.client(self.stream, .{ 681 .host = self.config.server, 682 .root_ca = self.app.bundle, 683 }); 684 } else { 685 - self.stream = try std.net.tcpConnectToHost(self.alloc, self.config.server, 6667); 686 } 687 688 var buf: [4096]u8 = undefined;
··· 444 password: []const u8, 445 real_name: []const u8, 446 server: []const u8, 447 + port: ?u16, 448 network_id: ?[]const u8 = null, 449 name: ?[]const u8 = null, 450 tls: bool = true, ··· 677 678 pub fn connect(self: *Client) !void { 679 if (self.config.tls) { 680 + const port: u16 = self.config.port orelse 6697; 681 + self.stream = try std.net.tcpConnectToHost(self.alloc, self.config.server, port); 682 self.client = try tls.client(self.stream, .{ 683 .host = self.config.server, 684 .root_ca = self.app.bundle, 685 }); 686 } else { 687 + const port: u16 = self.config.port orelse 6667; 688 + self.stream = try std.net.tcpConnectToHost(self.alloc, self.config.server, port); 689 } 690 691 var buf: [4096]u8 = undefined;
+16
src/lua.zig
··· 315 else => lua.raiseErrorStr("expected a boolean for field 'tls'", .{}), 316 }; 317 318 // Ref the config table so it doesn't get garbage collected 319 _ = lua.ref(registry_index) catch lua.raiseErrorStr("couldn't ref config table", .{}); // [] 320 ··· 331 .real_name = real_name, 332 .tls = tls, 333 .lua_table = table_ref, 334 }; 335 336 const loop = getLoop(lua); // []
··· 315 else => lua.raiseErrorStr("expected a boolean for field 'tls'", .{}), 316 }; 317 318 + lua_type = lua.getField(1, "port"); // [table, int|nil] 319 + lua.argCheck(lua_type == .nil or lua_type == .number, 1, "expected a number or nil"); 320 + const port: ?u16 = switch (lua_type) { 321 + .nil => blk: { 322 + lua.pop(1); // [table] 323 + break :blk null; 324 + }, 325 + .number => blk: { 326 + const val = lua.toNumber(-1) catch unreachable; 327 + lua.pop(1); // [table] 328 + break :blk @intFromFloat(val); 329 + }, 330 + else => lua.raiseErrorStr("expected a boolean for field 'tls'", .{}), 331 + }; 332 + 333 // Ref the config table so it doesn't get garbage collected 334 _ = lua.ref(registry_index) catch lua.raiseErrorStr("couldn't ref config table", .{}); // [] 335 ··· 346 .real_name = real_name, 347 .tls = tls, 348 .lua_table = table_ref, 349 + .port = port, 350 }; 351 352 const loop = getLoop(lua); // []