diff options
Diffstat (limited to 'blabouncer.c')
-rw-r--r-- | blabouncer.c | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/blabouncer.c b/blabouncer.c index 80d6940..ba9dca0 100644 --- a/blabouncer.c +++ b/blabouncer.c @@ -8,6 +8,7 @@ // - Add blabouncer MOTD (375, 372, 376) // - "01:53:47 -!- ServerMode/#test [b] by irc.tghost.co.uk" on existing clients when new client connects // - Keep track of changing user nicks/modes +// - Relay log can just be "log/resend everything that ever hit sendto[all]client[s]()" // // Example WHOIS reply: // BOUNCER-SERVER RECEIVED: :irc.tghost.co.uk 307 blabounce l_bratch :is identified for this nick @@ -30,6 +31,7 @@ #include "functions.h" #include "sockets.h" +#include "config.h" #define SOURCE_SERVER 0 #define SOURCE_CLIENT 1 @@ -44,10 +46,8 @@ #define MAXCHANLENGTH 50 // 50 according to RFC 2811 and RFC 2822 #define MAXCHANUSERS 8192 // Randomly picked (TODO - is there an actual maximum number of users per channel?) #define MAXNICKLENGTH 64 // Randomly picked (TODO - is there an actual maximum number (ignoring the RFC preference of 9)?) - -#define IRCNICK "blabounce" // TODO: change this to a config option! -#define IRCUSER "blabounce" // TODO: change this to a config option! -#define IRCREALNAME "Mr Bla Bouncer" // TODO: change this to a config option! +#define MAXUSERNAMELEN 64 // Randomly picked (TODO - is there an actual maximum username length?) +#define MAXREALNAMELEN 128 // Randomly picked (TODO - is there an actual maximum real name length?) struct channel { char name[MAXCHANLENGTH]; @@ -68,6 +68,9 @@ struct ircdstrings { char greeting004[MAXDATASIZE]; char ircdname[MAXDATASIZE]; char nickuserhost[MAXDATASIZE]; // TODO - Make sure this changes when nick changes, if that's meant to happen. + char ircnick[MAXNICKLENGTH]; // TODO - Make sure this changes when nick changes + char ircusername[MAXUSERNAMELEN]; + char ircrealname[MAXREALNAMELEN]; }; int debugmode = 0; @@ -589,7 +592,7 @@ int processircmessage(int *serversockfd, int *clientsockfd, char *str, int sourc // If there isn't one set (we guess this if topic timestamp is 0), send 331 RPL_NOTOPIC if (strncmp(channels[i].topicwhen, "0", 1) == 0) { // Prepare the no topic message... - if (!snprintf(outgoingmsg, MAXDATASIZE, ":%s 331 %s %s :No topic is set.", ircdstrings->ircdname, IRCNICK, channels[i].name)) { + if (!snprintf(outgoingmsg, MAXDATASIZE, ":%s 331 %s %s :No topic is set.", ircdstrings->ircdname, ircdstrings->ircnick, channels[i].name)) { fprintf(stderr, "Error while preparing USER just connected, channel JOIN responses, 331 RPL_NOTOPIC!\n"); exit(1); } @@ -598,7 +601,7 @@ int processircmessage(int *serversockfd, int *clientsockfd, char *str, int sourc // If there is one set, send 332 RPL_TOPIC and 333 RPL_TOPICWHOTIME } else { // Prepare the topic message... - if (!snprintf(outgoingmsg, MAXDATASIZE, ":%s 332 %s %s :%s", ircdstrings->ircdname, IRCNICK, channels[i].name, channels[i].topic)) { + if (!snprintf(outgoingmsg, MAXDATASIZE, ":%s 332 %s %s :%s", ircdstrings->ircdname, ircdstrings->ircnick, channels[i].name, channels[i].topic)) { fprintf(stderr, "Error while preparing USER just connected, channel JOIN responses, 332 RPL_TOPIC!\n"); exit(1); } @@ -606,7 +609,7 @@ int processircmessage(int *serversockfd, int *clientsockfd, char *str, int sourc sendtoclient(sourcefd, outgoingmsg); // Next prepare the topic who/when message... - if (!snprintf(outgoingmsg, MAXDATASIZE, ":%s 333 %s %s %s %s", ircdstrings->ircdname, IRCNICK, channels[i].name, channels[i].topicwho, channels[i].topicwhen)) { + if (!snprintf(outgoingmsg, MAXDATASIZE, ":%s 333 %s %s %s %s", ircdstrings->ircdname, ircdstrings->ircnick, channels[i].name, channels[i].topicwho, channels[i].topicwhen)) { fprintf(stderr, "Error while preparing USER just connected, channel JOIN responses, 333 RPL_TOPICWHOTIME!\n"); exit(1); } @@ -627,7 +630,7 @@ int processircmessage(int *serversockfd, int *clientsockfd, char *str, int sourc continue; } // If there was a nick found, send it to the client (one per line at the moment - TODO - batch them up into fewer lines) - if (!snprintf(outgoingmsg, MAXDATASIZE, ":%s 353 %s %s %s :%s", ircdstrings->ircdname, IRCNICK, channels[i].namestype, channels[i].name, channels[i].nicks[j])) { + if (!snprintf(outgoingmsg, MAXDATASIZE, ":%s 353 %s %s %s :%s", ircdstrings->ircdname, ircdstrings->ircnick, channels[i].namestype, channels[i].name, channels[i].nicks[j])) { fprintf(stderr, "Error while preparing USER just connected, channel NAMES responses!\n"); exit(1); } @@ -635,7 +638,7 @@ int processircmessage(int *serversockfd, int *clientsockfd, char *str, int sourc } // Once all names are sent, send the "end of /NAMES" 366 (RPL_ENDOFNAMES) message - if (!snprintf(outgoingmsg, MAXDATASIZE, ":%s 366 %s %s :End of /NAMES list.", ircdstrings->ircdname, IRCNICK, channels[i].name)) { + if (!snprintf(outgoingmsg, MAXDATASIZE, ":%s 366 %s %s :End of /NAMES list.", ircdstrings->ircdname, ircdstrings->ircnick, channels[i].name)) { fprintf(stderr, "Error while preparing USER just connected, end of NAMES response!\n"); exit(1); } @@ -852,29 +855,35 @@ void dochat(int *serversockfd, int *clientsockfd) { // Registered with the IRCd yet? ////////////// int registered = 0; + // Struct of various strings from and for the real IRCd (such as the greeting strings, the real IRCd's name, + // our nick!user@host string, our nick, username, real name, etc.) + struct ircdstrings ircdstrings; + // Set them to zero-length strings for now + ircdstrings.greeting001[0] = '\0'; + ircdstrings.greeting002[0] = '\0'; + ircdstrings.greeting003[0] = '\0'; + ircdstrings.greeting004[0] = '\0'; + ircdstrings.ircdname[0] = '\0'; + ircdstrings.nickuserhost[0] = '\0'; + ircdstrings.ircnick[0] = '\0'; + ircdstrings.ircusername[0] = '\0'; + ircdstrings.ircrealname[0] = '\0'; + + // Read required things from configuration file + readnames(ircdstrings.ircnick, ircdstrings.ircusername, ircdstrings.ircrealname); + // Send our NICK - snprintf(outgoingmsg, MAXDATASIZE, "NICK %s", IRCNICK); // TODO - Check for success (with return code) + snprintf(outgoingmsg, MAXDATASIZE, "NICK %s", ircdstrings.ircnick); // TODO - Check for success (with return code) sendtoserver(serversockfd, outgoingmsg, strlen(outgoingmsg)); // Send our USER - snprintf(outgoingmsg, MAXDATASIZE, "USER %s 8 * : %s", IRCUSER, IRCREALNAME); // TODO - Check for success (with return code) + snprintf(outgoingmsg, MAXDATASIZE, "USER %s 8 * : %s", ircdstrings.ircusername, ircdstrings.ircrealname); // TODO - Check for success (with return code) // TODO - Send a more intelligent/correct USER string sendtoserver(serversockfd, outgoingmsg, strlen(outgoingmsg)); // Struct of channels we're in struct channel *channels; channels = malloc(sizeof(struct channel) * MAXCHANNELS); - - // Struct of various strings from the real IRCd (such as the greeting strings, the real IRCd's name, our nick!user@host string, etc.) - struct ircdstrings ircdstrings; - // Set them to zero-length strings for now - ircdstrings.greeting001[0] = '\0'; - ircdstrings.greeting002[0] = '\0'; - ircdstrings.greeting003[0] = '\0'; - ircdstrings.greeting004[0] = '\0'; - ircdstrings.ircdname[0] = '\0'; - ircdstrings.nickuserhost[0] = '\0'; - // =============================================> while (1) { |