diff options
Diffstat (limited to 'functions.c')
-rw-r--r-- | functions.c | 32 |
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)); +} |