summaryrefslogtreecommitdiff
path: root/userland
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-04-26 17:25:13 +0200
committerAnton Kling <anton@kling.gg>2024-04-26 17:25:13 +0200
commit2e2805c88789c148cce0118d3a4ff0212458bb86 (patch)
tree46c74f35fd02f00d555818aa71ebbefa0a5eb9cf /userland
parentd89fae4f826ad6b236abb3b04a666d2be7dcf3ea (diff)
IRC: Add PING command
Diffstat (limited to 'userland')
-rw-r--r--userland/irc/irc.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/userland/irc/irc.c b/userland/irc/irc.c
index 9aa962f..a80a4dd 100644
--- a/userland/irc/irc.c
+++ b/userland/irc/irc.c
@@ -227,6 +227,9 @@ void handle_msg(struct irc_server *server, struct sv msg) {
irc_add_message(server, channel, C_TO_SV("*"), SB_TO_SV(join_message));
sb_free(&join_message);
}
+ HANDLE_CMD(C_TO_SV("PING")) {
+ tcp_write(server->socket, "PONG", 4, NULL);
+ }
HANDLE_CMD(C_TO_SV("PRIVMSG")) {
struct sv channel = sv_split_delim(command_parameters, &msg, ' ');
struct sv nick = sv_trim_left(message_origin, 1);
@@ -412,7 +415,6 @@ int irc_connect_server(struct irc_server *server, u32 ip, u16 port) {
int err;
u32 socket = tcp_connect_ipv4(ip, port, &err);
if (err) {
- assert(0);
return 0;
}
server->socket = socket;
@@ -426,8 +428,6 @@ void refresh_screen(void) {
}
int main(void) {
- clear_screen();
-
u32 id;
queue_create(&id);
@@ -438,7 +438,12 @@ int main(void) {
u32 ip = gen_ipv4(10, 0, 2, 2);
struct irc_server server_ctx;
- irc_connect_server(&server_ctx, ip, 6667);
+ if (!irc_connect_server(&server_ctx, ip, 6667)) {
+ printf("Failed to connect to the irc server\n");
+ return 1;
+ }
+
+ clear_screen();
selected_channel = &server_ctx.channels[0];