PtokaX forum

Archive => Archived 4.0 boards => Finished Lua 4 scripts => Topic started by: NotRabidWombat on 31 May, 2004, 07:53:03

Title: NickNameTaken
Post by: NotRabidWombat on 31 May, 2004, 07:53:03
After a year of neglect, I finally took some time to fix this script up to make it work *very* well. Did some basic testing and it seems to work just as expected.
--------------------------------------------------
-- --
-- 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;
I use:
S > C : $Hello TestingNick
S > C : $RevConnectToMe TestingNick TargetNick
I expect :
C > S : $ConnectToMe ....
or
C > S : $RevConnectToMe ...

This was the best thing I could find that was the equivalent to a ping.

-NotRabidWombat
Title:
Post by: chill on 31 May, 2004, 10:00:39
thats really a good one IMAO :).
Title:
Post by: NotRabidWombat on 01 June, 2004, 00:52:49
What is IMAO? Is it a combination of LMAO and IMHO? ;-)

-NotRabidWombat
Title:
Post by: chill on 01 June, 2004, 09:48:33
no it should be

In My Arrogant Opinion

if google's results searched for "acronym IMAO"
are correct ;)
Title:
Post by: NotRabidWombat on 01 June, 2004, 12:18:39
Hah! Google, correct? Never!

-NotRabidWombat
Title:
Post by: NotRabidWombat on 08 June, 2004, 18:02:49
Any validation or bug reports?

-NotRabidWombat
Title:
Post by: blackwings on 24 June, 2004, 00:22:54
QuoteOriginally posted by NotRabidWombat
Any validation or bug reports?

-NotRabidWombat

I have ptokax 0.3.3.0 build 15.25 and get these errors =

Syntax error: attempt to index field `TriesArray' (a nil value)
stack traceback:
   1:  function `OpDisconnected' at line 121 [file `C:\ptokax\scripts\NickTakenBot07.lua']]
   2:  function `DisconnectByName' [C]
   3:  function `OnTimer' at line 53 [file `C:\ptokax\scripts\NickTakenBot07.lua']

Syntax error: bad argument #1 to `strlen' (string expected, got nil)
stack traceback:
   1:  function `strlen' [C]
   2:  function `DataArrival' at line 74 [file `C:\ptokax\scripts\NickTakenBot07.lua']

Syntax error: attempt to index field `TriesArray' (a nil value)
stack traceback:
   1:  function `OpDisconnected' at line 121 [file `C:\ptokax\scripts\NickTakenBot07.lua']
Title:
Post by: NotRabidWombat on 28 June, 2004, 21:20:15
Yup, you're right. I actually posted the wrong version. Guess not many people use this anymore. *EDIT* and added a fix for the nil problem */EDIT*
--------------------------------------------------
-- --
-- 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.8";
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 == "" then
local s, e, name = strfind(sData, "$ValidateNick%s+(%S+)");
if not name then return; end

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.ClientsBeingTested[curUser.sName] = nil;
end
end

NewUserConnected = RemoveFromTesting;
OpConnected = RemoveFromTesting;
UserDisconnected = RemoveFromTesting;
OpDisconnected = RemoveFromTesting;

-NotRabidWombat