diff options
Diffstat (limited to 'client_network.c')
-rw-r--r-- | client_network.c | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/client_network.c b/client_network.c index 90a406a..0050812 100644 --- a/client_network.c +++ b/client_network.c @@ -29,6 +29,7 @@ #include <gnutls/gnutls.h> #include <netdb.h> #include <arpa/inet.h> +#include <errno.h> #include <sys/types.h> #include <netinet/in.h> #include <sys/socket.h> @@ -156,10 +157,6 @@ int add_local_client(struct string uid, struct string nick_arg, struct string vh SEND(NULSTR(string_time)); SEND(STRING(" +k :")); SEND(realname); - SEND(STRING("\n:")); - SEND(uid); - SEND(STRING(" OPERTYPE ")); - SEND(opertype); SEND(STRING("\n")); if (fake_cert) { SEND(STRING(":1HC METADATA ")); @@ -168,6 +165,13 @@ int add_local_client(struct string uid, struct string nick_arg, struct string vh SEND(client_cert); SEND(STRING("\n")); } + if (!STRING_EQ(uid, STRING("1HC000000"))) { // Don't oper haxserv, because echo is unprivileged + SEND(STRING(":")); + SEND(uid); + SEND(STRING(" OPERTYPE ")); + SEND(opertype); + SEND(STRING("\n")); + } return 0; @@ -469,7 +473,7 @@ int client_privmsg_handler(uint64_t argc, struct string *argv) { client_nick, STRING(" executes `"), argv[1], - STRING("'\n"), + STRING("'"), }; privmsg(STRING("1HC000000"), log_channel, sizeof(message)/sizeof(*message), message); @@ -479,7 +483,8 @@ int client_privmsg_handler(uint64_t argc, struct string *argv) { if (argv[0].data[0] == '#') { SEND(STRING(":1HC000000 NOTICE ")); SEND(argv[0]); - SEND(STRING(" :Unknown command: " "\x03" "04")); + SEND(STRING(" :Unknown command: ")); + SEND(command_prefix); SEND(command_argv[0]); SEND(STRING("\n")); } @@ -531,6 +536,10 @@ int client_mode_handler(uint64_t argc, struct string *argv) { int client_fd = -1; int client_listen_fd; +int client_listen_fd_ready = 0; +struct sockaddr_in client_listen_fd_bind_addr = { + .sin_family = AF_INET, +}; int initclientnetwork(void) { client_network_commands.array = malloc(0); @@ -551,21 +560,26 @@ int initclientnetwork(void) { int one = 1; setsockopt(client_listen_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); - struct sockaddr_in localhost = { - .sin_family = AF_INET, - .sin_port = htons(6667), - }; - inet_pton(AF_INET, "127.0.0.1", &localhost.sin_addr); // this is indeed localhost for mine, and I have no intent to change this - bind(client_listen_fd, (struct sockaddr*)&localhost, sizeof(localhost)); + client_listen_fd_bind_addr.sin_port = htons(6667); - listen(client_listen_fd, 1); + inet_pton(AF_INET, "127.0.0.1", &client_listen_fd_bind_addr.sin_addr); // this is indeed localhost for mine, and I have no intent to change this + + if (bind(client_listen_fd, (struct sockaddr*)&client_listen_fd_bind_addr, sizeof(client_listen_fd_bind_addr)) == -1) { + if (errno != EADDRINUSE) { + close(client_listen_fd); + return 1; + } + } else { + listen(client_listen_fd, 1); + client_listen_fd_ready = 1; + } return 0; } #if LOGALL ssize_t SENDCLIENT(struct string msg) { - if (msg.len == 0) + if (msg.len == 0 || client_fd == -1) return 0; static char printprefix = 1; |