summaryrefslogtreecommitdiff
path: root/blabouncer.c
diff options
context:
space:
mode:
Diffstat (limited to 'blabouncer.c')
-rw-r--r--blabouncer.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/blabouncer.c b/blabouncer.c
index a9eab97..5ee48b5 100644
--- a/blabouncer.c
+++ b/blabouncer.c
@@ -136,6 +136,7 @@ int connecttoircserver(SSL_CTX **serverctx, SSL **server_ssl, int *serversockfd,
// ircdstate.reconnecting is not set here as we want to track reconnections separately
// ircdstate.clientchangetime and ircdstate.clientsnonetime not set here as they are set at startup and only changed when clients connect/disconnect
// ircdstate.clientcodes not set here, set on startup and whenever a client sets one
+ // ircdstate->maxchannelcount not set here, set on startup in dochat()
// Populate nicks[0] and username from our configuration file for now, real IRCd may change them later (TODO - Is this true of username?)
strcpy(ircdstate->ircnick, settings->ircnicks[0]);
@@ -435,14 +436,9 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) {
// Struct of channels we're in
struct channel *channels;
channels = malloc(sizeof(struct channel) * MAXCHANNELS);
- // Set initial channel names to empty strings
- for (int i = 0; i < MAXCHANNELS; i++) {
- channels[i].name[0] = '\0';
- // And all the nicks within it
- for (int j = 0; j < MAXCHANNICKS; j++) {
- channels[i].nicks[j][0] = '\0';
- }
- }
+ ircdstate.maxchannelcount = 0;
+ // Each channel struct element is only initialised upon channel creation to avoid consuming lots of memory here.
+ // The memory is never released once a channel is parted - TODO - Can this channel struct memory usage be improved?
// Initialise OpenSSL (used for both client and server)
init_openssl();
@@ -710,14 +706,13 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) {
if (strncmp(outgoingmsg, "listchannels", strlen("listchannels")) == 0) {
printf("STDIN command starting: listchannels\n");
- int channelcount = getchannelcount(channels);
+ int channelcount = getchannelcount(channels, ircdstate.maxchannelcount);
- for (int i = 0; i < channelcount; i++) {
+ for (int i = 0; i < ircdstate.maxchannelcount; i++) {
printf("Checking channel[%d] out of %d.\n", i, channelcount);
- // Skip this one and increment channelcount if it's a blank channel
+ // Skip this one if it's a blank channel
if (!channels[i].name[0]) {
- debugprint(DEBUG_FULL, "Skipping channel[%d], incrementing channelcount.\n", i);
- channelcount++;
+ debugprint(DEBUG_FULL, "Skipping blank channel channel[%d].\n", i);
continue;
}