I don't know much about lua...only want to know how this works....it sends a message to the "online" user...to test the conecction? if the TCP conecction is pointing to nothing then the socket closes when it receibes this message?
-- --
-- This bot is designed to fix the --
-- "*** Your nick is taken" bug when a user is --
-- disconnected from the hub. --
-- --
-- For more details go to: --
-- http://students.dwc.edu/cbarber/nickbug.html --
-- --
-- By RabidWombat --
--------------------------------------------------
BotName = "NickTakenBot";
BotVersion = "v0.6";
BotAuthor = "RabidWombat";
NickMessage = "Your nick is already taken, please change to something else!"
Title = BotName.." "..BotVersion.." by: "..BotAuthor;
Message = "If you were disconnected from the hub, please wait a minute and you should be able to reconnect.";
TriesArray = {};
TimeToWait = 20; -- in seconds
MaxTries = 3;
function Main()
frmHub:RegBot(BotName);
frmHub:EnableFullData(1);
frmHub:EnableSearchData(0);
SetTimer(1000);
StartTimer();
end
function OnTimer()
-- This is designed so old entries will be removed from the table
for UserName,TryTable in TriesArray do
if(TryTable[0] == nil or TryTable[1] == nil) then
TriesArray[UserName] = nil; -- set entry to be removed
return;
end
TryTable[1] = TryTable[1] - 1; -- decrement time count
if(TryTable[1] <= 0) then -- less than just in case
TryTable[1] = TimeToWait; -- reset time count for next decrement
TryTable[0] = TryTable[0] - 1; -- decrement try count
if(TryTable[0] <= 0) then -- less than just in case
TriesArray[UserName] = nil; -- set entry to be removed
end
end
end
end
function DataArrival(curUser, sData)
if curUser.sName == "" and strsub(sData, 1, 13) == "$ValidateNick" then
local s, e, name = strfind(sData, "$ValidateNick (%S+)");
name = strsub(name, 1, strlen(name) - 1);
if(GetItemByName(name)) then
if(TriesArray[name] and TriesArray[name][0]) then
TriesArray[name][0] = TriesArray[name][0] + 1; -- increment tries
if(TriesArray[name][0] > MaxTries) then
TriesArray[name][1] = TimeToWait; -- reset time count
return; -- do not send message
end
else
TriesArray[name] = {1, TimeToWait};
end
SendToNick(name, "testing this connection|"); -- Check for ghost
curUser:SendData("*** "..NickMessage); -- Do hubs job
curUser:SendData("*** "..Title); -- Inform new user
curUser:SendData("*** "..Message);
-- Disconnect user before $ValidateDenide is sent
-- Some clients do not reconnect automatically correctly when this message is sent
curUser:Disconnect();
return 1;
end
end
end
function OnNewUserConnected(curUser) -- Remove entry if user connects
if(TriesArray[curUser.sName]) then
TriesArray[curUser.sName] = nil;
end
end
function OnNewOpConnected(curUser) -- Remove entry if op connects
if(TriesArray[curUser.sName]) then
TriesArray[curUser.sName] = nil;
end
end
yep, if you get the msg "your nick has been taken" it trys 2 send a msg 2 that nick wich is in the hub.
this is mostly enough 2 make ptokax drop the ghost.
plop