summaryrefslogtreecommitdiff
path: root/functions.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2019-05-16 23:40:43 +0100
committerLuke Bratch <luke@bratch.co.uk>2019-05-16 23:40:43 +0100
commit93e530320e024e9119fb8717459ef618086c5839 (patch)
tree779e015cba061c55362f650638e5b92d8f53dc63 /functions.c
parent57faf310db4c7d7d07a5695fb305c481e040e4fb (diff)
Correctly handle nicks changing and actually track users PARTing channels.
Also change nickuserhost to store the leading colon (:) since it's always needed (so far).
Diffstat (limited to 'functions.c')
-rw-r--r--functions.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/functions.c b/functions.c
index e43f31c..6034250 100644
--- a/functions.c
+++ b/functions.c
@@ -150,3 +150,35 @@ void extractnickfromprefix(char *string) {
printf("extractnickfromprefix(): finishing with '%s', strlen: %zd.\n", string, strlen(string));
}
+
+// Update an existing nickuserhost string with a new nick
+void updatenickuserhost(char *nickuserhost, char *nick) {
+ printf("updatenickuserhost(): updating '%s' with '%s'.\n", nickuserhost, nick);
+
+ // Position of bang
+ int bangpos = -1;
+
+ // Find the bang
+ for (size_t i = 0; i < strlen(nickuserhost); i++) {
+ if (nickuserhost[i] == '!') {
+ printf("Found bang at position %ld!\n", i);
+ bangpos = i;
+ break;
+ }
+ }
+
+ if (bangpos == -1) {
+ printf("No bang found in existing nickuserhost, quitting!\n");
+ return;
+ }
+
+ // Make a new string combining the nick nick and the old nickuserhost + the offset of the bang
+ char newstr[MAXDATASIZE];
+ snprintf(newstr, MAXDATASIZE, "%s%s", nick, nickuserhost + bangpos);
+ newstr[strlen(nickuserhost) - bangpos + strlen(nick)] = '\0';
+
+ // Copy back to source string
+ strcpy(nickuserhost, newstr);
+
+ printf("updatenickuserhost(): new nickuserhost '%s', length '%ld'.\n", nickuserhost, strlen(nickuserhost));
+}