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!