PtokaX forum

Archive => Archived 4.0 boards => Finished Lua 4 scripts => Topic started by: [ES]latinmusic on 11 October, 2003, 18:49:53

Title: Nick Already Taken
Post by: [ES]latinmusic on 11 October, 2003, 18:49:53
-- --
-- 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
-- --
Title:
Post by: c h i l l a on 16 October, 2003, 14:52:22
another solution, the idea also from

http://students.dwc.edu/cbarber/nickbug.html (http://students.dwc.edu/cbarber/nickbug.html)


-- Nick Already taken fix V.1

function DataArrival(curUser,data)
if (strsub(data,1,13) == "$ValidateNick") then
local _,_,curNick = strfind(data,"$ValidateNick%s+(%S+)|")
if curNick and GetItemByName(curNick) then
GetItemByName(curNick):SendData(" NickCorrelation, somebody is trying to connect with your Nick.")
curUser:SendData(" Either your Nick "..format('%q',curNick).." is already taken or try to reconnect in a few seconds.")
curUser:Disconnect()
elseif not curNick then
curUser:Disconnect()
end
end
end
Title:
Post by: Alexei on 18 October, 2003, 23:34:27
Solution nr 3!

Just get a newest version of a main-bot and a hub-soft...
 :D  :P