summaryrefslogtreecommitdiff
path: root/functions.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2022-09-02 18:09:03 +0100
committerLuke Bratch <luke@bratch.co.uk>2022-09-02 18:09:03 +0100
commitd754d919565946442d0d83da0c88986b166d386d (patch)
treea16d41f619e13d473e7ff0854ea2c2570ea7ffba /functions.c
parent44bcab7c9cc9edf0894ca710da34beca63517b03 (diff)
Deal with servers only sending a nick rather than nick!user@host as the last token of greeting 001.
Diffstat (limited to 'functions.c')
-rw-r--r--functions.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/functions.c b/functions.c
index 6d0e8a1..6bd8a9c 100644
--- a/functions.c
+++ b/functions.c
@@ -324,8 +324,13 @@ void updatenickuserhost(char *nickuserhost, char *nick) {
}
}
+ // No bang found...
if (bangpos == -1) {
- debugprint(DEBUG_FULL, "updatenickuserhost(): no bang found in existing nickuserhost, returning!\n");
+ // ...assume the old nickuserhost was just the nick (e.g. if the server's greeting
+ // 001 ended with nick rather than nick!user@host) then just update it directly
+ debugprint(DEBUG_FULL, "updatenickuserhost(): no bang found in existing nickuserhost, assuming a nick only nickuserhost\n");
+ strcpy(nickuserhost, nick);
+ debugprint(DEBUG_FULL, "updatenickuserhost(): new (nick only) nickuserhost '%s', length '%ld'.\n", nickuserhost, strlen(nickuserhost));
return;
}
@@ -344,6 +349,13 @@ void updatenickuserhost(char *nickuserhost, char *nick) {
void updategreetings(char *greeting001, char *greeting002, char *greeting003, char *greeting004, char *greeting005a, char *greeting005b,
char *greeting005c, char *newnickuserhost, char *oldnickuserhost, char *newnick, char *oldnick) {
debugprint(DEBUG_FULL, "updategreetings(): updating greetings with new nickuserhost '%s' and nick '%s'.\n", newnickuserhost, newnick);
+ debugprint(DEBUG_FULL, "updategreetings(): existing greeting001: '%s'.\n", greeting001);
+ debugprint(DEBUG_FULL, "updategreetings(): existing greeting002: '%s'.\n", greeting002);
+ debugprint(DEBUG_FULL, "updategreetings(): existing greeting003: '%s'.\n", greeting003);
+ debugprint(DEBUG_FULL, "updategreetings(): existing greeting004: '%s'.\n", greeting004);
+ debugprint(DEBUG_FULL, "updategreetings(): existing greeting005a: '%s'.\n", greeting005a);
+ debugprint(DEBUG_FULL, "updategreetings(): existing greeting005b: '%s'.\n", greeting005b);
+ debugprint(DEBUG_FULL, "updategreetings(): existing greeting005c: '%s'.\n", greeting005c);
// nickuserhost and greeting001's final component first
// (final component as in ":servername 001 nick :Blablabla final!com@ponent"
@@ -361,6 +373,16 @@ void updategreetings(char *greeting001, char *greeting002, char *greeting003, ch
ret = strstr(greeting001, oldnickuserhostcpy);
int pos = ret - greeting001;
+ // Ensure that was the last occurrence in the greeting
+ debugprint(DEBUG_FULL, "updategreetings(): entering last occurrence check loop...\n");
+ while (ret) {
+ ret = strstr(greeting001 + pos + strlen(oldnickuserhostcpy), oldnickuserhostcpy);
+ if (!ret) {
+ break;
+ }
+ pos = ret - greeting001;
+ }
+
// Terminate greeting001 where the nickuserhost begins
greeting001[pos] = '\0';