Thread: Need help with IRC networking.

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    2

    Need help with IRC networking.

    Hi
    I have the following problem:

    For the last years I have been using a simple C based program to help me keep channels in my friends IRCnet. It is a totally client based program, has not much anything related to the IRCD. I execute it, it runs in the back and it keeps ops in channels and tells jokes and stuff like that. I have had this following problem for many months now but now im searching for a way to fix it.

    One of those ircserver programs(ircd) crashes from time to time on these servers and then my channel bot needs to connect to another server. Problem is that it doesnt know how to connect. Well actually it can connect but not good (details come later in the post).

    I didnt code this channelbot originally but in the source i have the following:

    server1: IP <- works.
    server2: IP <- works only if server1 address cannot be resolved. For example if the server1 ip is 100.100.100.100, well it cannot resolve it and after 15 seconds, it connects to server2.

    Well this doesnt apply in my case because the IP of the IRCD is resolvable. And many times the computer is up there. Just the IRCD crashes. But when the ircd crashes on server1, my bot keeps looping and looping and it tries to connect to server1 for forever.

    Sometimes the server is coming back up but its totally laggy and not linked to other servers and in those cases the IRCD doesnt allow any channels to be created. Thats why its best if it could just go straight to server2 if it cannot join server1, channel 1.
    So im asking for some help from someone who knows this irc stuff if you could help me add some lines to my channelbot, so that for example:

    If bot has not joined channel1 in server1 after 5 minutes of trying, then go to server2 and channel 2 (which is the same channel).

    Here is a part of the code that I believe is responsible for the channelbot behaviour when it connects to IRC.

    Code:
       // copy settings into main irc structure
        strncpy(mainirc.host, server, sizeof(mainirc.host)-1);
        mainirc.port = port;
        strncpy(mainirc.channel, channel, sizeof(mainirc.channel)-1);
        strncpy(mainirc.chanpass, chanpass, sizeof(mainirc.chanpass)-1);
        mainirc.spy = 0;
    
        while (1) {
            for (i = 0; i < 6; i++) {
                #ifndef NO_CHECKCONNECTION
                // check if we're connected to the internet... if not, then wait 5mins and try again
                if (!noigcs) if (fInternetGetConnectedState(&cstat, 0) == FALSE) {
                    Sleep(30000);
                    continue;
                }
                #endif
    
                err = irc_connect((void *)&mainirc);
                success = FALSE;
                if (err == 2) break; // break out of the loop
    
                if (success) i--; // if we're successful in connecting, decrease i by 1;
    
                // irc_connect didn't return 2, so we need to sleep then reconnect
                Sleep(3000);
            }
    
            if (err == 2) break; // break out of the loop and close
    
            if (bkpserver) {
                strncpy(mainirc.host, server, sizeof(mainirc.host)-1);
                mainirc.port = port;
                strncpy(mainirc.channel, channel, sizeof(mainirc.channel)-1);
                strncpy(mainirc.chanpass, chanpass, sizeof(mainirc.chanpass)-1);
                bkpserver = FALSE;
            }
            else if (!bkpserver && server2[0] != '\0') {
                strncpy(mainirc.host, server2, sizeof(mainirc.host)-1);
                mainirc.port = port2;
                strncpy(mainirc.channel, channel2, sizeof(mainirc.channel)-1);
                strncpy(mainirc.chanpass, chanpass2, sizeof(mainirc.chanpass)-1);
                bkpserver = TRUE;
            }
        }
    
        // cleanup;
        for (i = 0; i < 64; i++) closesocket(csock[i]);
        WSACleanup();
    
        return 0;
     }
    In the configuration area I have:
    Code:
     const char server[19] = "ircserver1.isp.com"; 
     const char channel[6] = "#help";
     const  int port = 6667;
    
     const char server2[19] = "ircserver2.isp.com"; 
     const char channel2[6] = "#help";
     const  int port2 = 6667;
    and in one other area i have also a mentioning about bkpserver
    Code:
     BOOL bkpserver = FALSE;
    I have tested many times the scenarios where it connects to server2. It goes to server2 only when server1 address cannot be resolved. If I put 127.0.0.1 it loops it also forever even if there is nothing there.

    IF someone can help me even a little bit, then thank you very much!
    http://www.sherv.net/cm/emo/christmas/snowman.gif http://89.184.166.90/content/emotico...0x80/50181.gif
    merry christmas!
    Last edited by Jurassic_Isla; 12-26-2008 at 07:16 AM.

  2. #2
    Registered User
    Join Date
    Dec 2008
    Posts
    2
    ok here is an update:
    i found an old fix on my hard drive that i never implemented on this joke bot. i had used it on other program but i just tried it on this and it works.

    i replaced

    Code:

    Code:
    sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
    		csock[irc.threadnum] = sock;
    		err = connect(sock, (LPSOCKADDR)&ssin, sizeof(SOCKADDR_IN));
    		if (err == SOCKET_ERROR) {
    			closesocket(sock);
    			Sleep(2000);
    			continue;
    with


    Code:
    sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
    		csock[irc.threadnum] = sock;
    		err = connect(sock, (LPSOCKADDR)&ssin, sizeof(SOCKADDR_IN));
    		if (err == SOCKET_ERROR) {
    			closesocket(sock);
    			rval = 0;
    			break;
    Now it connects to server2 when server1 is 1.1.1.1 or 127.0.0.1.

    So now it connects to server2 if server1 is unresolvable and the new thing: if its not an irc server.

    But it would be great if there could still be a fix for the bot on how to go server2 if server1 channel1 is unjoinable.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    396
    I didnt code this channelbot originally
    you should try to contact the guys who developed this bot originally and discuss the problem with them so that it can be fixed properly... assuming this thing is still maintained. obviously.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. IRC, reading the stream
    By Iyouboushi in forum C# Programming
    Replies: 6
    Last Post: 08-03-2006, 05:34 PM
  2. Networking...
    By Coder87C in forum Networking/Device Communication
    Replies: 4
    Last Post: 03-02-2006, 01:24 AM
  3. Some help needed with IRC
    By SaintK in forum C++ Programming
    Replies: 2
    Last Post: 04-04-2004, 07:27 AM
  4. Beyond MFC : COM || Networking
    By kuphryn in forum Windows Programming
    Replies: 5
    Last Post: 04-25-2002, 04:28 PM
  5. C++: Reference Book, GUI, Networking & Beyond
    By kuphryn in forum C++ Programming
    Replies: 4
    Last Post: 11-10-2001, 08:03 PM