-------------------------------------------------- -- -- -- This bot is designed to fix the -- -- "*** Your nick is taken" bug when a user is -- -- disconnected from the hub. -- -- -- -- By RabidWombat -- -------------------------------------------------- Bot = {}; Bot.Name = "NickTakenBot"; Bot.Version = "v0.7"; Bot.Author = "RabidWombat"; -- Time to wait for a client to reply Bot.ReplyTimeOut = 10; -- in seconds -- Time to wait to check the client again -- This protects against a flood Bot.NextTryTimeOut = 60; -- in seconds -- Nick used to test a client for activity Bot.TestingNick = "NoNameTester"; -- no user may login with this nick -- This nick name must NOT ever exist in the hub Bot.HelloString = format("$Hello %s|", Bot.TestingNick); Bot.RevConnectToMeString = format("$RevConnectToMe %s ", Bot.TestingNick); Bot.QuitString = format("$Quit %s|", Bot.TestingNick); Bot.SearchString = format(" %s|$", Bot.TestingNick); Bot.NickMessage = "Your nick is already taken, please change to something else!" Bot.Title = Bot.Name.." "..Bot.Version.." by: "..Bot.Author; Bot.Message = "If you were disconnected from the hub, please wait a minute and you should be able to reconnect."; Bot.ClientsBeingTested = {}; Bot.FloodProtect = {}; function Main() frmHub:RegBot(Bot.Name); frmHub:EnableFullData(1); frmHub:EnableSearchData(0); SetTimer(1000); StartTimer(); end function OnTimer() for UserName, TimeToLive in Bot.ClientsBeingTested do -- Has a time out occured? if TimeToLive < 0 then -- Drop the user DisconnectByName(UserName); -- Remove from testing Bot.ClientsBeingTested[UserName] = nil; else -- Decrement the count Bot.ClientsBeingTested[UserName] = TimeToLive - 1; end end for UserName, NextTryTimeOut in Bot.FloodProtect do if NextTryTimeOut < 0 then Bot.FloodProtect[UserName] = nil; else Bot.FloodProtect[UserName] = NextTryTimeOut - 1; 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(Bot.ClientsBeingTested[name]) then -- Client is already being tested return; -- do not do anything else SendToNick(name, Bot.HelloString); -- Check for ghost SendToNick(name, Bot.RevConnectToMeString .. name .. "|"); curUser:SendData("*** "..Bot.NickMessage); -- Do hubs job curUser:SendData("*** "..Bot.Title); -- Inform new user curUser:SendData("*** "..Bot.Message); Bot.ClientsBeingTested[name] = Bot.ReplyTimeOut; -- 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 if Bot.ClientsBeingTested[curUser.sName] then -- Client is alive -- Remove from testing Bot.ClientsBeingTested[curUser.sName] = nil; -- Assign next try timeout Bot.FloodProtect[curUser.sName] = Bot.NextTryTimeOut; -- Tell the client the testing nick disconnected curUser:SendData(Bot.QuitString); if ( strfind(sData, Bot.SearchString) ) then -- The hub doesn't need to do anything with this command return 1; end end end -- Remove a user from testing if they exist -- IN: User Object -- OUT: Nothing function RemoveFromTesting(curUser) if(Bot.ClientsBeingTested[curUser.sName]) then Bot.TriesArray[curUser.sName] = nil; end end NewUserConnected = RemoveFromTesting; OpConnected = RemoveFromTesting; UserDisconnected = RemoveFromTesting; OpDisconnected = RemoveFromTesting;