aboutsummaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorTest_User <hax@andrewyu.org>2024-06-13 01:36:55 -0400
committerTest_User <hax@andrewyu.org>2024-06-13 01:36:55 -0400
commitd20eea410dafb444e3bdfa5fab44d166ea588304 (patch)
tree35ccda5d6495b630956b9243dacb39959c06e274 /protocols
parent74937a810bff43ba7ce20a8a64149ffd3ab896e9 (diff)
downloadhaxircd-d20eea410dafb444e3bdfa5fab44d166ea588304.tar.gz
haxircd-d20eea410dafb444e3bdfa5fab44d166ea588304.zip
nick and kill support
Diffstat (limited to 'protocols')
-rw-r--r--protocols/inspircd2.c177
-rw-r--r--protocols/inspircd2.h6
2 files changed, 137 insertions, 46 deletions
diff --git a/protocols/inspircd2.c b/protocols/inspircd2.c
index 46c9f8b..2d6fe96 100644
--- a/protocols/inspircd2.c
+++ b/protocols/inspircd2.c
@@ -132,8 +132,9 @@ int init_inspircd2_protocol(void) {
set_table_index(&inspircd2_protocol_commands, STRING("RSQUIT"), &inspircd2_protocol_handle_rsquit);
set_table_index(&inspircd2_protocol_commands, STRING("UID"), &inspircd2_protocol_handle_uid);
+ set_table_index(&inspircd2_protocol_commands, STRING("NICK"), &inspircd2_protocol_handle_nick);
set_table_index(&inspircd2_protocol_commands, STRING("QUIT"), &inspircd2_protocol_handle_quit);
-// set_table_index(&inspircd2_protocol_commands, STRING("KILL"), &inspircd2_protocol_handle_kill);
+ set_table_index(&inspircd2_protocol_commands, STRING("KILL"), &inspircd2_protocol_handle_kill);
return 0;
}
@@ -505,7 +506,7 @@ void inspircd2_protocol_propagate_new_server(struct string from, struct string a
}
}
-void inspircd2_protocol_propagate_unlink(struct string from, struct server_info *a, struct server_info *b, size_t protocol) {
+void inspircd2_protocol_propagate_unlink_server(struct string from, struct server_info *a, struct server_info *b, size_t protocol) {
struct server_info *source;
struct server_info *target;
if (a->distance == 0 && !STRING_EQ(a->sid, SID)) {
@@ -567,6 +568,24 @@ void inspircd2_protocol_propagate_new_user(struct string from, struct user_info
}
}
+void inspircd2_protocol_propagate_rename_user(struct string from, struct user_info *user, struct string nick, size_t timestamp, struct string timestamp_str) {
+ struct server_info *self = get_table_index(server_list, SID);
+
+ for (size_t i = 0; i < self->connected_to.len; i++) {
+ struct server_info *adjacent = self->connected_to.array[i].ptr;
+ if (adjacent->protocol != INSPIRCD2_PROTOCOL || STRING_EQ(from, adjacent->sid))
+ continue;
+
+ networks[adjacent->net].send(adjacent->handle, STRING(":"));
+ networks[adjacent->net].send(adjacent->handle, user->uid);
+ networks[adjacent->net].send(adjacent->handle, STRING(" NICK "));
+ networks[adjacent->net].send(adjacent->handle, nick);
+ networks[adjacent->net].send(adjacent->handle, STRING(" "));
+ networks[adjacent->net].send(adjacent->handle, timestamp_str);
+ networks[adjacent->net].send(adjacent->handle, STRING("\n"));
+ }
+}
+
void inspircd2_protocol_propagate_remove_user(struct string from, struct user_info *info, struct string reason) {
struct server_info *self = get_table_index(server_list, SID);
@@ -583,6 +602,24 @@ void inspircd2_protocol_propagate_remove_user(struct string from, struct user_in
}
}
+void inspircd2_protocol_propagate_kill_user(struct string from, struct string source, struct user_info *info, struct string reason) {
+ struct server_info *self = get_table_index(server_list, SID);
+
+ for (size_t i = 0; i < self->connected_to.len; i++) {
+ struct server_info *adjacent = self->connected_to.array[i].ptr;
+ if (adjacent->protocol != INSPIRCD2_PROTOCOL || STRING_EQ(from, adjacent->sid))
+ continue;
+
+ networks[adjacent->net].send(adjacent->handle, STRING(":"));
+ networks[adjacent->net].send(adjacent->handle, source);
+ networks[adjacent->net].send(adjacent->handle, STRING(" KILL "));
+ networks[adjacent->net].send(adjacent->handle, info->uid);
+ networks[adjacent->net].send(adjacent->handle, STRING(" :"));
+ networks[adjacent->net].send(adjacent->handle, reason);
+ networks[adjacent->net].send(adjacent->handle, STRING("\n"));
+ }
+}
+
void inspircd2_protocol_do_unlink_inner(struct string from, struct server_info *target, struct string reason) {
target->distance = 1; // Reusing distance for `have passed`, since its set to 0 bc severed anyways
@@ -654,6 +691,30 @@ void inspircd2_protocol_introduce_servers_to(size_t net, void *handle) {
}
}
+void inspircd2_protocol_introduce_user_to(size_t net, void *handle, struct user_info *user) {
+ networks[net].send(handle, STRING(":"));
+ networks[net].send(handle, user->server);
+ networks[net].send(handle, STRING(" UID "));
+ networks[net].send(handle, user->uid);
+ networks[net].send(handle, STRING(" "));
+ networks[net].send(handle, user->user_ts_str);
+ networks[net].send(handle, STRING(" "));
+ networks[net].send(handle, user->nick);
+ networks[net].send(handle, STRING(" "));
+ networks[net].send(handle, user->host);
+ networks[net].send(handle, STRING(" "));
+ networks[net].send(handle, user->vhost);
+ networks[net].send(handle, STRING(" "));
+ networks[net].send(handle, user->ident);
+ networks[net].send(handle, STRING(" "));
+ networks[net].send(handle, user->address);
+ networks[net].send(handle, STRING(" "));
+ networks[net].send(handle, user->nick_ts_str);
+ networks[net].send(handle, STRING(" + :"));
+ networks[net].send(handle, user->fullname);
+ networks[net].send(handle, STRING("\n"));
+}
+
// CAPAB <type> [<args> [, ...]]
int inspircd2_protocol_init_handle_capab(struct string source, size_t argc, struct string *argv, size_t net, void *handle, struct server_config **config, char is_incoming) {
if (argc < 1) {
@@ -730,48 +791,8 @@ int inspircd2_protocol_init_handle_server(struct string source, size_t argc, str
inspircd2_protocol_introduce_servers_to(net, handle);
- for (size_t i = 0; i < user_list.len; i++) {
- struct user_info *user = user_list.array[i].ptr;
-
- networks[net].send(handle, STRING(":"));
- networks[net].send(handle, user->server);
- networks[net].send(handle, STRING(" UID "));
- networks[net].send(handle, user->uid);
- networks[net].send(handle, STRING(" "));
-
- struct string timestamp;
- char err = unsigned_to_str(user->nick_ts, &timestamp);
-
- if (err) {
- return -1;
- }
- networks[net].send(handle, timestamp);
- free(timestamp.data);
-
- networks[net].send(handle, STRING(" "));
- networks[net].send(handle, user->nick);
- networks[net].send(handle, STRING(" "));
- networks[net].send(handle, user->host);
- networks[net].send(handle, STRING(" "));
- networks[net].send(handle, user->vhost);
- networks[net].send(handle, STRING(" "));
- networks[net].send(handle, user->ident);
- networks[net].send(handle, STRING(" "));
- networks[net].send(handle, user->address);
- networks[net].send(handle, STRING(" "));
-
- err = unsigned_to_str(user->nick_ts, &timestamp);
-
- if (err) {
- return -1;
- }
- networks[net].send(handle, timestamp);
- free(timestamp.data);
-
- networks[net].send(handle, STRING(" + :"));
- networks[net].send(handle, user->fullname);
- networks[net].send(handle, STRING("\n"));
- }
+ for (size_t i = 0; i < user_list.len; i++)
+ inspircd2_protocol_introduce_user_to(net, handle, user_list.array[i].ptr);
networks[net].send(handle, STRING(":"));
networks[net].send(handle, SID);
@@ -965,7 +986,31 @@ int inspircd2_protocol_handle_uid(struct string source, size_t argc, struct stri
return 0;
}
-// :source QUIT <reason>
+// :source NICK <nick> <timestamp>
+int inspircd2_protocol_handle_nick(struct string source, size_t argc, struct string *argv, size_t net, void *handle, struct server_config *config, char is_incoming) {
+ if (argc < 2) {
+ WRITES(2, STRING("[InspIRCd v2] Invalid NICK recieved! (Missing parameters)\r\n"));
+ return -1;
+ }
+
+ char err;
+ size_t nick_ts = str_to_unsigned(argv[1], &err);
+ if (err) {
+ WRITES(2, STRING("[InspIRCd v2] Invalid NICK recieved! (Invalid timestamp)\r\n"));
+ return -1;
+ }
+
+ struct user_info *user = get_table_index(user_list, source);
+ if (!user)
+ return 0; // KILL timings, etc
+
+ if (rename_user(config->sid, user, argv[0], nick_ts) != 0)
+ return -1;
+
+ return 0;
+}
+
+// :source QUIT [<reason>?]
int inspircd2_protocol_handle_quit(struct string source, size_t argc, struct string *argv, size_t net, void *handle, struct server_config *config, char is_incoming) {
struct string reason;
if (argc < 1)
@@ -986,3 +1031,45 @@ int inspircd2_protocol_handle_quit(struct string source, size_t argc, struct str
return 0;
}
+
+// [:source] KILL <target> [<reason>?]
+int inspircd2_protocol_handle_kill(struct string source, size_t argc, struct string *argv, size_t net, void *handle, struct server_config *config, char is_incoming) {
+ if (argc < 1) {
+ WRITES(2, STRING("[InspIRCd v2] Invalid KILL recieved! (Missing parameters)\r\n"));
+ return -1;
+ }
+
+ struct user_info *user = get_table_index(user_list, argv[0]);
+ if (!user) {
+ for (size_t i = 0; i < user_list.len; i++) {
+ struct user_info *tmp = user_list.array[i].ptr;
+ if (STRING_EQ(tmp->nick, argv[0])) {
+ user = tmp;
+ break;
+ }
+ }
+
+ if (!user)
+ return 0;
+ }
+
+ if (STRING_EQ(user->server, SID)) {
+ if (config->ignore_local_kills) {
+ inspircd2_protocol_introduce_user_to(net, handle, user);
+ } else {
+ if (argc > 1)
+ kill_user(config->sid, source, user, argv[1]);
+ else
+ kill_user(config->sid, source, user, STRING(""));
+ }
+ } else if (config->ignore_remote_kills) {
+ inspircd2_protocol_introduce_user_to(net, handle, user);
+ } else {
+ if (argc > 1)
+ kill_user(config->sid, source, user, argv[1]);
+ else
+ kill_user(config->sid, source, user, STRING(""));
+ }
+
+ return 0;
+}
diff --git a/protocols/inspircd2.h b/protocols/inspircd2.h
index 03963b6..0a19964 100644
--- a/protocols/inspircd2.h
+++ b/protocols/inspircd2.h
@@ -42,9 +42,12 @@ void * inspircd2_protocol_autoconnect(void *type);
void inspircd2_protocol_update_propagations(void);
void inspircd2_protocol_propagate_new_server(struct string from, struct string attached_to, struct server_info *info);
-void inspircd2_protocol_propagate_unlink(struct string from, struct server_info *a, struct server_info *b, size_t protocol);
+void inspircd2_protocol_propagate_unlink_server(struct string from, struct server_info *a, struct server_info *b, size_t protocol);
+
void inspircd2_protocol_propagate_new_user(struct string from, struct user_info *info);
+void inspircd2_protocol_propagate_rename_user(struct string from, struct user_info *info, struct string nick, size_t timestamp, struct string timestamp_str);
void inspircd2_protocol_propagate_remove_user(struct string from, struct user_info *info, struct string reason);
+void inspircd2_protocol_propagate_kill_user(struct string from, struct string source, struct user_info *info, struct string reason);
void inspircd2_protocol_do_unlink(struct string from, struct server_info *a, struct server_info *b);
@@ -61,6 +64,7 @@ int inspircd2_protocol_handle_squit(struct string source, size_t argc, struct st
int inspircd2_protocol_handle_rsquit(struct string source, size_t argc, struct string *argv, size_t net, void *handle, struct server_config *config, char is_incoming);
int inspircd2_protocol_handle_uid(struct string source, size_t argc, struct string *argv, size_t net, void *handle, struct server_config *config, char is_incoming);
+int inspircd2_protocol_handle_nick(struct string source, size_t argc, struct string *argv, size_t net, void *handle, struct server_config *config, char is_incoming);
int inspircd2_protocol_handle_quit(struct string source, size_t argc, struct string *argv, size_t net, void *handle, struct server_config *config, char is_incoming);
int inspircd2_protocol_handle_kill(struct string source, size_t argc, struct string *argv, size_t net, void *handle, struct server_config *config, char is_incoming);