aboutsummaryrefslogtreecommitdiff
path: root/general_network.c
diff options
context:
space:
mode:
authorTest_User <hax@andrewyu.org>2024-07-18 20:12:29 -0400
committerTest_User <hax@andrewyu.org>2024-07-18 20:32:10 -0400
commite755e8b341eea1b37ef82584cd65a05edf8fdbaa (patch)
tree63862f2609e7470ec3cb432b416626b90fe6f3f8 /general_network.c
parent925da4ee0c7364900e67c1c6ce4a1323166d5198 (diff)
downloadhaxircd-e755e8b341eea1b37ef82584cd65a05edf8fdbaa.tar.gz
haxircd-e755e8b341eea1b37ef82584cd65a05edf8fdbaa.zip
Partial nickname enforcement implemented
Diffstat (limited to 'general_network.c')
-rw-r--r--general_network.c48
1 files changed, 32 insertions, 16 deletions
diff --git a/general_network.c b/general_network.c
index f5ce1e3..d04dbcd 100644
--- a/general_network.c
+++ b/general_network.c
@@ -374,38 +374,54 @@ int add_user(struct string from, struct string attached_to, struct string uid, s
return 1;
}
-int rename_user(struct string from, struct user_info *user, struct string nick, size_t timestamp) {
+int rename_user(struct string from, struct user_info *user, struct string nick, size_t timestamp, char forced, char immediate) {
struct string timestamp_str;
if (unsigned_to_str(timestamp, &timestamp_str) != 0)
return 1;
- void *tmp = malloc(nick.len);
- if (!tmp) {
- free(timestamp_str.data);
- return 1;
+ if (forced && !immediate && STRING_EQ(user->server, SID))
+ immediate = 1;
+
+ void *tmp;
+ if (immediate) {
+ tmp = malloc(nick.len);
+ if (!tmp) {
+ free(timestamp_str.data);
+ return 1;
+ }
}
#ifdef USE_SERVER
- if (protocols_handle_rename_user(from, user, nick, timestamp, timestamp_str) != 0) {
- free(tmp);
- free(timestamp_str.data);
+ if (protocols_handle_rename_user(from, user, nick, timestamp, timestamp_str, forced, immediate) != 0) {
+ if (immediate) {
+ free(tmp);
+ free(timestamp_str.data);
+ }
return 1;
}
- protocols_propagate_rename_user(from, user, nick, timestamp, timestamp_str);
+ protocols_propagate_rename_user(from, user, nick, timestamp, timestamp_str, forced, immediate);
#endif
#ifdef USE_PSEUDOCLIENTS
- pseudoclients_handle_rename_user(from, user, nick, timestamp);
+ pseudoclients_handle_rename_user(from, user, nick, timestamp, forced, immediate);
+
+ size_t old_timestamp = user->nick_ts;
#endif
- free(user->nick.data);
- user->nick.data = tmp;
- memcpy(user->nick.data, nick.data, nick.len);
- user->nick.len = nick.len;
+ if (immediate) {
+ free(user->nick.data);
+ user->nick.data = tmp;
+ memcpy(user->nick.data, nick.data, nick.len);
+ user->nick.len = nick.len;
+
+ user->nick_ts_str = timestamp_str;
+ user->nick_ts = timestamp;
+ }
- user->nick_ts_str = timestamp_str;
- user->nick_ts = timestamp;
+#ifdef USE_PSEUDOCLIENTS
+ pseudoclients_handle_post_rename_user(from, user, nick, old_timestamp, forced, immediate);
+#endif
return 0;
}