diff options
-rw-r--r-- | blabouncer.c | 139 |
1 files changed, 6 insertions, 133 deletions
diff --git a/blabouncer.c b/blabouncer.c index fffc164..f250959 100644 --- a/blabouncer.c +++ b/blabouncer.c @@ -2,7 +2,6 @@ // - Should replay log do more than PRIVMSGs? // - Perhaps rename clients.ssl and server_ssl since they may not even be OpenSSL sockets // - Is it possible to replay JOINs/PARTs accurately? -// - Remove any old channel name/mode/prefix code that isn't needed any more // - Move debug output into some debug function // "server" means the real IRC server @@ -59,8 +58,6 @@ struct channel { // TODO - Make this Year 2038 proof // TODO - Make this an int? It's just going to arrive and leave as a string every time anyway... char topicwhen[11]; // 32-bit unixtime is up to 10 characters (+1 for null char) We use "0" to mean "not set". - char nicks[MAXCHANUSERS][MAXNICKLENGTH]; // TODO - Need to modify this as people leave/join, not just when we first join - char namestype[2]; // Single character (@/*/=) (+1 for null char) // TODO - Is this a sensible name? int gotnames; // Have we finished getting the RPL_NAMREPLYs for this channel yet? }; @@ -300,8 +297,8 @@ int disconnectclient(int fd, struct client *clients, struct ircdstrings *ircdstr return 0; } -int createchannel(struct channel *channels, char *name, char *topic, char *topicwho, char *topicwhen, char *namestype) { - printf("createchannel(): given \"%s\", \"%s\", \"%s\", \"%s\", and \"%s\".\n", name, topic, topicwho, topicwhen, namestype); +int createchannel(struct channel *channels, char *name, char *topic, char *topicwho, char *topicwhen) { + printf("createchannel(): given \"%s\", \"%s\", \"%s\", and \"%s\".\n", name, topic, topicwho, topicwhen); // Make sure the channel doesn't already exist for (int i = 0; i < MAXCHANNELS; i++) { @@ -328,8 +325,6 @@ int createchannel(struct channel *channels, char *name, char *topic, char *topic channels[i].topicwho[strlen(topicwho)] = '\0'; strncpy(channels[i].topicwhen, topicwhen, strlen(topicwhen)); channels[i].topicwhen[strlen(topicwhen)] = '\0'; - strncpy(channels[i].namestype, topic, strlen(namestype)); - channels[i].namestype[strlen(namestype)] = '\0'; channels[i].gotnames = 0; return 1; break; // TODO - This should be safe to remove since return is hit first @@ -342,73 +337,6 @@ int createchannel(struct channel *channels, char *name, char *topic, char *topic return 0; } -int addusertochannel(struct channel *channels, char *channelname, char *nick) { - printf("addusertochannel(): given \"%s\" and \"%s\".\n", channelname, nick); - - for (int i = 0; i < MAXCHANNELS; i++) { - if (strncmp(channels[i].name, channelname, strlen(channelname)) == 0) { - // Looking for free user slot... - for (int j = 0; j < MAXCHANUSERS; j++) { - if (!channels[i].nicks[j][0]) { - // ...and adding user - strncpy(channels[i].nicks[j], nick, strlen(nick)); - channels[i].nicks[j][strlen(nick)] = '\0'; - return 1; - } - } - break; - } - } - - // TODO - Make a failed return do something to callers - return 0; -} - -int removeuserfromchannel(struct channel *channels, char *channelname, char *nick) { - printf("removeuserfromchannel(): given \"%s\" and \"%s\".\n", channelname, nick); - - // Go through all the channels - for (int i = 0; i < MAXCHANNELS; i++) { - // Until we find the channel - if (strncmp(channels[i].name, channelname, strlen(channelname)) == 0) { - // Go through all the users in the channel - for (int j = 0; j < MAXCHANUSERS; j++) { - // And remove the user if found - if (strncmp(channels[i].nicks[j], nick, strlen(nick)) == 0) { - channels[i].nicks[j][0] = '\0'; - return 1; - } - } - // We failed - return 0; - } - } - - // TODO - Make a failed return do something to callers - return 0; -} - -// Update any instance of oldnick with newnick in all channels, -// for instance of a new changed their nick. -int updatechannelnicks(struct channel *channels, char *oldnick, char *newnick) { - printf("updatechannelnicks(): given '%s' and '%s'.\n", oldnick, newnick); - - // Go through all the channels - for (int i = 0; i < MAXCHANNELS; i++) { - // Go through all the users in the channel - for (int j = 0; j < MAXCHANUSERS; j++) { - // And update the nick if found - if (strncmp(channels[i].nicks[j], oldnick, strlen(oldnick)) == 0) { - printf("Updating '%s' to '%s' in '%s'.\n", channels[i].nicks[j], newnick, channels[i].name); - strcpy(channels[i].nicks[j], newnick); - } - } - } - - // TODO - Detect failing to update anything and tell the caller - return 1; -} - int setchanneltopicwhotime(struct channel *channels, char *channelname, char *who, char *when) { printf("setchanneltopicwhotime(): given \"%s\", \"%s\", and \"%s\".\n", channelname, who, when); @@ -458,27 +386,6 @@ int getchannelcount(struct channel *channels) { return count; } -int getchannelnamescount(struct channel *channels, char *channelname) { - int count = 0; - - // Find channel - for (int i = 0; i < MAXCHANNELS; i++) { - if (strncmp(channels[i].name, channelname, strlen(channelname)) == 0) { - // Count nicks - for (int j = 0; j < MAXCHANUSERS; j++) { - // If not null character then it's a nick - if (channels[i].nicks[j][0]) { - count++; - } - } - break; - } - } - - printf("getchannelnamescount(): counted %d names for channel '%s'.\n", count, channelname); - return count; -} - int removechannel(struct channel *channels, char *name) { printf("removechannel(): given \"%s\".\n", name); @@ -491,11 +398,6 @@ int removechannel(struct channel *channels, char *name) { // ..and NULL its name (0th character = '\0') channels[i].name[0] = '\0'; printf("removechannel(): channel '%s' removed and topicwhen set to '%s'.\n", name, channels[i].topicwhen); - // Finally clear all its users - for (int j = 0; j < MAXCHANUSERS; j++) { - channels[i].nicks[j][0] = '\0'; - } - printf("removechannel(): channel '%s' users cleared.\n", name); return 1; } } @@ -750,13 +652,7 @@ int processircmessage(SSL *server_ssl, char *str, int source, struct client *cli printf("Server JOIN: nickuserhost is ours ('%s' vs '%s').\n", prefixcopy, ircdstrings->nickuserhost); // TODO - Saner way to initialise this since we don't have the variables yet? // TODO - Defaulting to type '=' which is "public" since I don't know what else to guess. - createchannel(channels, tokens[2], "TOPIC", "TOPICWHO", "0", "="); - // If the user JOINing is not us, record the user in our channel array. - } else { - printf("Server JOIN: nickuserhost is NOT ours ('%s' vs '%s').\n", prefixcopy, ircdstrings->nickuserhost); - extractnickfromprefix(prefixcopy); - printf("Server JOIN: adding user '%s' to channel '%s'.\n", prefixcopy, tokens[2]); - addusertochannel(channels, tokens[2], prefixcopy); + createchannel(channels, tokens[2], "TOPIC", "TOPICWHO", "0"); } // And then send to all clients @@ -777,10 +673,6 @@ int processircmessage(SSL *server_ssl, char *str, int source, struct client *cli if (strncmp(prefixcopy, ircdstrings->nickuserhost, strlen(tokens[0])) == 0) { printf("Server PART: nickuserhost is ours ('%s' vs '%s').\n", prefixcopy, ircdstrings->nickuserhost); removechannel(channels, tokens[2]); - } else { - printf("Server PART: nickuserhost is NOT ours ('%s' vs '%s').\n", prefixcopy, ircdstrings->nickuserhost); - extractnickfromprefix(tokens[0]); - removeuserfromchannel(channels, tokens[2], tokens[0]); } // And then send to all clients @@ -890,6 +782,7 @@ int processircmessage(SSL *server_ssl, char *str, int source, struct client *cli // And then finally relay to all clients sendtoallclients(clients, str, sourcefd, settings); free(topiccopy); + free(prefixcopy); free(strcopyPtr); return 1; } @@ -916,8 +809,7 @@ int processircmessage(SSL *server_ssl, char *str, int source, struct client *cli // Server NICK received? // 1. Find out if it was us and change ircnick and nickuserhost if so - // 2. Either way, update our records of nicks in channels - // 3. Either way, relay to all clients + // 2. Either way, relay to all clients if (strncmp(tokens[1], "NICK", strlen(tokens[1])) == 0) { printf("Server NICK found and it is: %s with length %zd! Next token is '%s'. Updating records and relaying to all clients.\n", tokens[0], strlen(tokens[0]), tokens[2]); @@ -941,11 +833,6 @@ int processircmessage(SSL *server_ssl, char *str, int source, struct client *cli free(nickuserhostcpy); } - // Update all nicks in channels - extractnickfromprefix(tokens[0]); - stripprefix(tokens[2]); - updatechannelnicks(channels, tokens[0], tokens[2]); - // Relay to all clients sendtoallclients(clients, str, sourcefd, settings); @@ -1796,12 +1683,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 and their nicks to empty strings + // Set initial channel names to empty strings for (int i = 0; i < MAXCHANNELS; i++) { channels[i].name[0] = '\0'; - for (int j = 0; j < MAXCHANUSERS; j++) { - channels[i].nicks[j][0] = '\0'; - } } // =============================================> @@ -1896,17 +1780,6 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) { } printf("Found channel '%s'.\n", channels[i].name); - // Store count of names so we can increment it in the loop if we encounter gaps in the names array - int namescount = getchannelnamescount(channels, channels[i].name); - // Go through each name... - for (int j = 0; j < namescount; j++) { - if (!channels[i].nicks[j][0]) { - // Skip this one and increment namescount so we find it later on instead - namescount++; - continue; - } - printf(" --> '%s' '%s' '%s'.\n", channels[i].namestype, channels[i].name, channels[i].nicks[j]); - } } printf("STDIN command complete: listchannels\n"); |