diff options
author | Luke Bratch <luke@bratch.co.uk> | 2019-06-11 19:50:17 +0100 |
---|---|---|
committer | Luke Bratch <luke@bratch.co.uk> | 2019-06-11 19:50:17 +0100 |
commit | 9db9fb396aaf601bd00f2b62face2693307a0e16 (patch) | |
tree | 2c5603a723899c0f5a4ec129cdaee1e5b1f6b556 /functions.c | |
parent | f660bbd1bfed3fbd36d684cd2f09ca1520520557 (diff) |
Refactoring - rename ircdstrings struct to ircdstate since it doesn't just contain strings.
Diffstat (limited to 'functions.c')
-rw-r--r-- | functions.c | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/functions.c b/functions.c index c23366d..93fd52b 100644 --- a/functions.c +++ b/functions.c @@ -521,12 +521,12 @@ int sendtoserver(SSL *server_ssl, char *strsrc, int str_len, int clientfd, struc // it from the array of clients. // Also set its authentication and registration statuses to 0. // Also set the pending statuses to 0 -int disconnectclient(int fd, struct client *clients, struct ircdstrings *ircdstrings, struct settings *settings) { +int disconnectclient(int fd, struct client *clients, struct ircdstate *ircdstate, struct settings *settings) { debugprint(DEBUG_SOME, "disconnectclient(): disconnecting client fd '%d'\n", fd); // Alert other clients about the disconnection (don't send yet, we haven't removed from the clients array yet) char alertmsg[MAXDATASIZE]; - if (!snprintf(alertmsg, MAXDATASIZE, "NOTICE %s :blabouncer: client with fd %d has disconnected.", ircdstrings->ircnick, fd)) { + if (!snprintf(alertmsg, MAXDATASIZE, "NOTICE %s :blabouncer: client with fd %d has disconnected.", ircdstate->ircnick, fd)) { fprintf(stderr, "Error while preparing authentication failure NOTICE!\n"); debugprint(DEBUG_CRIT, "Error while preparing authentication failure NOTICE!\n"); alertmsg[0] = '\0'; @@ -738,7 +738,7 @@ int channelindex(struct channel *channels, char *name) { // 'sourcefd' is the client to send to, and replayseconds is the number of // seconds of replay to replay. // Returns 1 for success or 0 for failure. -int doreplay(int sourcefd, int replayseconds, struct client *clients, struct settings *settings, struct ircdstrings *ircdstrings, struct channel *channels) { +int doreplay(int sourcefd, int replayseconds, struct client *clients, struct settings *settings, struct ircdstate *ircdstate, struct channel *channels) { char outgoingmsg[MAXDATASIZE]; // Figure out how many lines to replay @@ -749,13 +749,13 @@ int doreplay(int sourcefd, int replayseconds, struct client *clients, struct set debugprint(DEBUG_CRIT, "Error getting number of replay lines.\n"); return 0; } else if (numlines == 0) { - snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :0 replay log lines found in the time requested, nothing to send.", ircdstrings->ircnick); + snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :0 replay log lines found in the time requested, nothing to send.", ircdstate->ircnick); sendtoclient(sourcefd, outgoingmsg, clients, settings, 0); return 1; } // Announce the start - snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Starting log replay....", ircdstrings->ircnick); + snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Starting log replay....", ircdstate->ircnick); sendtoclient(sourcefd, outgoingmsg, clients, settings, 0); // Replay those lines! @@ -802,7 +802,7 @@ int doreplay(int sourcefd, int replayseconds, struct client *clients, struct set extractnickfromprefix(tokens[0]); // Check if we're currently in this channel or if the log line is from us - if (!inchannel(channels, tokens[2] + offset) || strncmp(tokens[0], ircdstrings->ircnick, strlen(tokens[0])) == 0) { + if (!inchannel(channels, tokens[2] + offset) || strncmp(tokens[0], ircdstate->ircnick, strlen(tokens[0])) == 0) { debugprint(DEBUG_FULL, "Not sending '%s' replay line '%s'.\n", tokens[1], outgoingmsg); free(strcopyPtr); continue; @@ -816,7 +816,7 @@ int doreplay(int sourcefd, int replayseconds, struct client *clients, struct set } // Announce the end - snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Log replay complete.", ircdstrings->ircnick); + snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Log replay complete.", ircdstate->ircnick); sendtoclient(sourcefd, outgoingmsg, clients, settings, 0); return 1; @@ -888,56 +888,56 @@ int joinautochannels(SSL *server_ssl, struct client *clients, struct settings *s // Try to make a new nick if no configured are available or liked by the server // Do this by sticking a number on the end of the current nick and trying numbers // 1 through to 9. -void tryautonick(struct ircdstrings *ircdstrings) { +void tryautonick(struct ircdstate *ircdstate) { // Increment the attempts counter - ircdstrings->autonicknum++; + ircdstate->autonicknum++; - if (ircdstrings->autonicknum == 10) { + if (ircdstate->autonicknum == 10) { // We've already tried 9 nicks and failed, give up printf("tryautonick(): Tried 9 automatic nicks and the server didn't like any, giving up.\n"); debugprint(DEBUG_CRIT, "tryautonick(): Tried 9 automatic nicks and the server didn't like any, giving up.\n"); exit(1); } - int oldlen = strlen(ircdstrings->ircnick); + int oldlen = strlen(ircdstate->ircnick); // If we've already started trying autonick, just replace the last character a the new number - if (ircdstrings->autonicknum > 1) { - debugprint(DEBUG_FULL, "tryautonick(): already started autonick, starting with '%s' length '%ld'.\n", ircdstrings->ircnick, strlen(ircdstrings->ircnick)); - ircdstrings->ircnick[oldlen - 1] = ircdstrings->autonicknum + '0'; + if (ircdstate->autonicknum > 1) { + debugprint(DEBUG_FULL, "tryautonick(): already started autonick, starting with '%s' length '%ld'.\n", ircdstate->ircnick, strlen(ircdstate->ircnick)); + ircdstate->ircnick[oldlen - 1] = ircdstate->autonicknum + '0'; // And null terminate - ircdstrings->ircnick[oldlen] = '\0'; + ircdstate->ircnick[oldlen] = '\0'; // If the nick is longer than or equal to the RFC 1459 max nick // length then try sticking the number at the end } else if (oldlen >= MAXRFCNICKLEN) { - debugprint(DEBUG_FULL, "tryautonick(): long old nick, starting with '%s' length '%ld'.\n", ircdstrings->ircnick, strlen(ircdstrings->ircnick)); + debugprint(DEBUG_FULL, "tryautonick(): long old nick, starting with '%s' length '%ld'.\n", ircdstate->ircnick, strlen(ircdstate->ircnick)); // (+ '0' to make char from int) - ircdstrings->ircnick[MAXRFCNICKLEN] = ircdstrings->autonicknum + '0'; + ircdstate->ircnick[MAXRFCNICKLEN] = ircdstate->autonicknum + '0'; // And null terminate - ircdstrings->ircnick[MAXRFCNICKLEN + 1] = '\0'; + ircdstate->ircnick[MAXRFCNICKLEN + 1] = '\0'; // Otherwise, just stick it on the end (+ '0' to make char from int) } else { - debugprint(DEBUG_FULL, "tryautonick(): short old nick, starting with '%s' length '%ld'.\n", ircdstrings->ircnick, strlen(ircdstrings->ircnick)); - ircdstrings->ircnick[oldlen] = ircdstrings->autonicknum + '0'; + debugprint(DEBUG_FULL, "tryautonick(): short old nick, starting with '%s' length '%ld'.\n", ircdstate->ircnick, strlen(ircdstate->ircnick)); + ircdstate->ircnick[oldlen] = ircdstate->autonicknum + '0'; // And null terminate - ircdstrings->ircnick[oldlen + 1] = '\0'; + ircdstate->ircnick[oldlen + 1] = '\0'; } - debugprint(DEBUG_FULL, "tryautonick(): set irdstrings->ircnick to '%s'.\n", ircdstrings->ircnick); + debugprint(DEBUG_FULL, "tryautonick(): set irdstrings->ircnick to '%s'.\n", ircdstate->ircnick); } // Exit the program cleanly - tell clients, tell the server, then exit(0) // Optional quit message string "quitmsg" // "sourcefd" of 0 means the request didn't come from a client -void cleanexit(SSL *server_ssl, struct client *clients, int sourcefd, struct ircdstrings *ircdstrings, struct settings *settings, char *quitmsg) { +void cleanexit(SSL *server_ssl, struct client *clients, int sourcefd, struct ircdstate *ircdstate, struct settings *settings, char *quitmsg) { char outgoingmsg[MAXDATASIZE]; // Tell clients and debug log if (sourcefd) { - snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Exiting on request from client with fd '%d', message '%s'.", ircdstrings->ircnick, sourcefd, quitmsg); + snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Exiting on request from client with fd '%d', message '%s'.", ircdstate->ircnick, sourcefd, quitmsg); debugprint(DEBUG_CRIT, "Exiting on request from client with fd '%d', message '%s'.\n", sourcefd, quitmsg); } else { - snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Exiting on request (not from a client), message '%s'.", ircdstrings->ircnick, quitmsg); + snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Exiting on request (not from a client), message '%s'.", ircdstate->ircnick, quitmsg); debugprint(DEBUG_CRIT, "Exiting on request (not from a client), message '%s'.\n", quitmsg); } sendtoallclients(clients, outgoingmsg, EXCEPT_NONE, settings); |