Browse Source

Merge pull request #1745 from gmaxwell/irc_fixes

Misc IRC fixes.
0.8
Jeff Garzik 12 years ago
parent
commit
4445434a2d
  1. 19
      src/irc.cpp

19
src/irc.cpp

@ -207,16 +207,22 @@ void ThreadIRCSeed(void* parg)
void ThreadIRCSeed2(void* parg) void ThreadIRCSeed2(void* parg)
{ {
/* Don't advertise on IRC if we don't allow incoming connections */ // Don't connect to IRC if we won't use IPv4 connections.
if (mapArgs.count("-connect") || fNoListen) if (IsLimited(NET_IPV4))
return; return;
// ... or if we won't make outbound connections and won't accept inbound ones.
if (mapArgs.count("-connect") && fNoListen)
return;
// ... or if IRC is not enabled.
if (!GetBoolArg("-irc", false)) if (!GetBoolArg("-irc", false))
return; return;
printf("ThreadIRCSeed started\n"); printf("ThreadIRCSeed started\n");
int nErrorWait = 10; int nErrorWait = 10;
int nRetryWait = 10; int nRetryWait = 10;
int nNameRetry = 0;
while (!fShutdown) while (!fShutdown)
{ {
@ -251,7 +257,9 @@ void ThreadIRCSeed2(void* parg)
CNetAddr addrIPv4("1.2.3.4"); // arbitrary IPv4 address to make GetLocal prefer IPv4 addresses CNetAddr addrIPv4("1.2.3.4"); // arbitrary IPv4 address to make GetLocal prefer IPv4 addresses
CService addrLocal; CService addrLocal;
string strMyName; string strMyName;
if (GetLocal(addrLocal, &addrIPv4)) // Don't use our IP as our nick if we're not listening
// or if it keeps failing because the nick is already in use.
if (!fNoListen && GetLocal(addrLocal, &addrIPv4) && nNameRetry<3)
strMyName = EncodeAddress(GetLocalAddress(&addrConnect)); strMyName = EncodeAddress(GetLocalAddress(&addrConnect));
if (strMyName == "") if (strMyName == "")
strMyName = strprintf("x%u", GetRand(1000000000)); strMyName = strprintf("x%u", GetRand(1000000000));
@ -267,6 +275,7 @@ void ThreadIRCSeed2(void* parg)
if (nRet == 2) if (nRet == 2)
{ {
printf("IRC name already in use\n"); printf("IRC name already in use\n");
nNameRetry++;
Wait(10); Wait(10);
continue; continue;
} }
@ -276,6 +285,7 @@ void ThreadIRCSeed2(void* parg)
else else
return; return;
} }
nNameRetry = 0;
Sleep(500); Sleep(500);
// Get our external IP from the IRC server and re-nick before joining the channel // Get our external IP from the IRC server and re-nick before joining the channel
@ -283,7 +293,8 @@ void ThreadIRCSeed2(void* parg)
if (GetIPFromIRC(hSocket, strMyName, addrFromIRC)) if (GetIPFromIRC(hSocket, strMyName, addrFromIRC))
{ {
printf("GetIPFromIRC() returned %s\n", addrFromIRC.ToString().c_str()); printf("GetIPFromIRC() returned %s\n", addrFromIRC.ToString().c_str());
if (addrFromIRC.IsRoutable()) // Don't use our IP as our nick if we're not listening
if (!fNoListen && addrFromIRC.IsRoutable())
{ {
// IRC lets you to re-nick // IRC lets you to re-nick
AddLocal(addrFromIRC, LOCAL_IRC); AddLocal(addrFromIRC, LOCAL_IRC);

Loading…
Cancel
Save