PtokaX forum

Development Section => Your Developing Problems => Topic started by: [ES]latinmusic on 20 November, 2003, 12:23:21

Title: Problems unbanning a nick
Post by: [ES]latinmusic on 20 November, 2003, 12:23:21
I have made the following code for test:
botName = "Test"
function Main()
end
function DataArrival(curUser, data)
if strsub(data, 1, 1) ~= "<" then return end
local s, e, cmd, args = strfind(data, "^%b<> %-(%a+)%s*(.*)%|$")
if not s then return end
cmd = strlower(cmd)
if cmd == "ban" then
local s, e, who, why = strfind(args, "^(%S+)%s*(.*)$")
if not s then curUser:SendData(botName,"Syntax: -ban [reason]") return 1 end
local tmp = GetItemByName(who)
if not tmp then curUser:SendData(botName,"The user '"..who.."' is not online.") return 1 end
if why == "" then why = "because: not reason given." else why = "because: "..why end
SendToAll(botName,"Operator "..curUser.sName.." is banning "..tmp.sName.." "..why)
tmp:SendData(botName,"You are being banned by "..curUser.sName.." "..why)
tmp:Ban()
return 1
elseif (cmd=="unban") then
local s,e,_,arg = strfind( data, "%b<>%s+(%S+)%s+(.+)%|$" )
SendToAll(botName,"Arg: >"..arg.."<")
if not s then curUser:SendData(botName,"Syntax: -unban ") return 1 end
if (arg == "" or arg == nil or arg == " ") then curUser:SendData(botName,"Parameter can't be an empty string or contain more than one space beetween the 'command' and the 'parameter'.") return 1 end
Unban(arg)
curUser:SendData(botName,"The user/IP: '"..arg.."' is now unbanned.")
return 1
end
end
When i unban an IP i have not troubles but if i want to unban a nickname there is no way, for instance:
-ban testuser --> testuser is banned, IP: x.x.x.x is banned too.
-unban x.x.x.x --> the user and his IP is unbanned.
-unban testuser does not work :(
What i'm doing wrong here?.
Title:
Post by: [ES]latinmusic on 20 November, 2003, 22:04:42
I still need help here please.
Title:
Post by: plop on 20 November, 2003, 23:13:48
why use a script when ptokax has that command buildin ???

plop
Title:
Post by: [ES]latinmusic on 21 November, 2003, 11:10:02
QuoteOriginally posted by plop
why use a script when ptokax has that command buildin ???
Again this question?.  :(
Because many reasons, there are too many, one is i need the code for one bot i'm making, but this is not the point.
I still need help here...
Title:
Post by: plop on 21 November, 2003, 11:38:19
[11:29] <-Insanety-> youandyou has been added to banlist by [TGA-OP]plop.
[11:30] <[TGA-OP]plop> banip 0.0.0.0
[11:30] <-Insanety-> *** 0.0.0.0 is banned
[11:30] The user/IP: 'youandyou' is now unbanned.
[11:30] Arg: >youandyou<
[11:30] The user/IP: '0.0.0.0' is now unbanned.
[11:30] Arg: >0.0.0.0<

this should make you happy then.  lol
sorry for repeating a question wich has been asked before seemingly a couple times, gues i missed them.
here is the fixed code, i changed the search strings and removed the end pipe in the start before the search.
finaly added the end pipe again on data sending, just 2 be safe.
botName = "Test"

function Main()
end

function DataArrival(curUser, data)
if strsub(data, 1, 1) ~= "<" then return end
   data=strsub(data,1,strlen(data)-1)
local s, e, cmd,args = strfind(data, "%b<>%s%-(%S+)%s*(.*)")
if not s then return end
cmd = strlower(cmd)
if cmd == "ban" then
local s, e, who, why = strfind(args, "(%S+)%s*(.*)")
if not s then curUser:SendData(botName,"Syntax: -ban [reason]|") return 1 end
local tmp = GetItemByName(who)
if not tmp then curUser:SendData(botName,"The user '"..who.."' is not online.|") return 1 end
if why == "" then why = "because: not reason given." else why = "because: "..why end
SendToAll(botName,"Operator "..curUser.sName.." is banning "..tmp.sName.." "..why.."|")
tmp:SendData(botName,"You are being banned by "..curUser.sName.." "..why.."|")
tmp:Ban()
return 1
elseif (cmd=="unban") then
--local s,e,_,arg = strfind( data, "%b<>%s+(%S+)%s+(.+)%|$" )
SendToAll(botName,"Arg: >"..args.."<|")
if not s then curUser:SendData(botName,"Syntax: -unban |") return 1 end
if (args == "" or args == nil or args == " ") then curUser:SendData(botName,"Parameter can't be an empty string or contain more than one space beetween the 'command' and the 'parameter'.|") return 1 end
Unban(args)
curUser:SendData(botName,"The user/IP: '"..args.."' is now unbanned.|")
return 1
end
end
plop
Title:
Post by: [ES]latinmusic on 21 November, 2003, 22:19:51
Yesssssssssssssssssssss!!!!!, finally a totally good answer this time, thanks plop, and you don't need to be surry about the question, the matter is i'm requesting some help for code from time to time, i'm writing a bot now, and also sometimes is to get  some nice code to learn a little more about lua scripting.
Thanks a lot!!!!, i'm totally happy here ;)
Title:
Post by: plop on 22 November, 2003, 03:32:42
yw, enjoy it.
you made me quorius (how that word is spelled is even a bigger mistery).

plop
Title:
Post by: [ES]latinmusic on 22 November, 2003, 12:35:43
Don't work as expected :( the problem is still the same, the code do the same like before.
To clarify:
I want to unban a NICK or
I want to unban the IP
The current code only unban the IP.
-->  -unban 0.0.0.0 works
--> -unban youandyou does not work
QuoteOriginally posted by plop
[11:29] <-Insanety-> youandyou has been added to banlist by [TGA-OP]plop.
[11:30] <[TGA-OP]plop> banip 0.0.0.0
[11:30] <-Insanety-> *** 0.0.0.0 is banned
[11:30] The user/IP: 'youandyou' is now unbanned.
[11:30] Arg: >youandyou<
[11:30] The user/IP: '0.0.0.0' is now unbanned.
[11:30] Arg: >0.0.0.0<
Note: Althougth the messages displayed, the nick must dissappear from permban list in the server.
Title:
Post by: plop on 23 November, 2003, 05:29:05
i tryed it on 0.3.3.0 b15.18 and worked there.
those were the only 2 entry's in my hub and it's cleared now.
if you want you may come and try it here.
send me a pm with username/pw and i'll send you the url.
otherwise i can try it on TD4 2morrow.

plop
Title:
Post by: [ES]latinmusic on 23 November, 2003, 19:00:14
QuoteOriginally posted by plop
i tryed it on 0.3.3.0 b15.18 and worked there.
those were the only 2 entry's in my hub and it's cleared now.
if you want you may come and try it here.
send me a pm with username/pw and i'll send you the url.
otherwise i can try it on TD4 2morrow.

plop
Many thanks for your lot of help plop, really apreciated, here does not work, anyway i will make a second try in a while to be totally sure, in case not work i will send you the pm to you help me to find the problem, thanks for that. Note: Also i'm testing the code with build 15.18.
Title:
Post by: [ES]latinmusic on 24 November, 2003, 21:07:47
Definitivaly does not work here at all, dunno what happend, i'm going to send you your requested pm now, also i have make an screen capture for you ilustrating this, if you send me your email in pm i will send you the picture for you take a look
Title:
Post by: plop on 25 November, 2003, 02:49:47
QuoteOriginally posted by [ES]latinmusic
Definitivaly does not work here at all, dunno what happend, i'm going to send you your requested pm now, also i have make an screen capture for you ilustrating this, if you send me your email in pm i will send you the picture for you take a look
done.

plop
Title:
Post by: plop on 26 November, 2003, 02:37:54
it was [ES]latinmusic day 2day.  lol
this works 100%.
botName = "Test"

function Main()
end

function DataArrival(curUser, data)
if strsub(data, 1, 1) ~= "<" then return end
   data=strsub(data,1,strlen(data)-1)
local s, e, cmd = strfind(data, "%b<>%s%-(%S+)")
if not s then return end
cmd = strlower(cmd)
if cmd == "ban" then
local s, e, who, why = strfind(data, "%b<>%s%S+%s(%S+)%s*(.*)")
if not s then curUser:SendData(botName,"Syntax: -ban [reason]") return 1 end
local tmp = GetItemByName(who)
if not tmp then curUser:SendData(botName,"The user '"..who.."' is not online.") return 1 end
if why == "" then why = "because: not reason given." else why = "because: "..why end
SendToAll(botName,"Operator "..curUser.sName.." is banning "..tmp.sName.." "..why)
tmp:SendData(botName,"You are being banned by "..curUser.sName.." "..why)
tmp:Ban()
return 1
elseif (cmd=="unban") then
local s,e,args = strfind( data, "%b<>%s%S+%s(.+)" )
if not s then curUser:SendData(botName,"Syntax: -unban ") return 1 end
if (args == "" or args == nil or args == " ") then curUser:SendData(botName,"Parameter can't be an empty string or contain more than one space beetween the 'command' and the 'parameter'.") return 1 end
      ip = OpenBanList(args)
      if ip ~= nil then
         Unban(ip)
         return 1
      else
         SendToAll(botName, "not found in the banlist")
      end
end
end

function OpenBanList(args)
   readfrom("../PermBan.dat")
   while 1 do
      local line = read()
      if line ==  nil then
         readfrom()
         break
      end
      s,e,temp, temp2 = strfind(line, "(.+)|(%S*)")
      if temp2 == args or temp == args then
         readfrom()
         break
      end
   end
   return temp
end
plop
Title:
Post by: sebastian on 28 November, 2003, 15:50:55
user:Ban() only bans IP
user:NickBan() only bans nick



function bannick(nick)
nick = GetItemByName(nick)
nick:Ban()
nick:NickBan()
end



insert this function and this will ban both nick and IP making possible to unban both IP and nick
note , bannick(userObject) wll not work
bannick(userObject.sName) will then work
Title:
Post by: plop on 28 November, 2003, 16:20:58
the banlist is an asociative array.
user:Ban()   adds  [ip] = user.sName
user:NickBan()   adds  [user.sName] = -Nickban-

if you do both those bans you have 2 unban the user 2x.
if you do a user:Ban() and want 2 unban the user by the nick you got a tiny problem.
you can only search the array by the key (ip).
thats why i open the permban.dat 2 find the matching ip for the nick wich has 2 be unbanned.
it can be done a little faster because it whill now also search if you unban by giving the ip.
this is for latinmusic 2 find out.

plop
Title:
Post by: plop on 01 December, 2003, 21:29:17
updated/bugfixed/optimized, name it how you like.

botName = "Test"

function Main()
end

function DataArrival(curUser, data)
if strsub(data, 1, 1) ~= "<" then return end
   data=strsub(data,1,strlen(data)-1)
local s, e, cmd = strfind(data, "%b<>%s%-(%S+)")
if not s then return end
cmd = strlower(cmd)
   local why,who,ip
if cmd == "ban" then
local s, e, who, why = strfind(data, "%b<>%s%S+%s(%S+)%s*(.*)")
if not s then curUser:SendData(botName,"Syntax: -ban [reason]") return 1 end
local tmp = GetItemByName(who)
if not tmp then curUser:SendData(botName,"The user '"..who.."' is not online.") return 1 end
if why == "" then why = "because: not reason given." else why = "because: "..why end
SendToAll(botName,"Operator "..curUser.sName.." is banning "..tmp.sName.." "..why)
tmp:SendData(botName,"You are being banned by "..curUser.sName.." "..why)
tmp:Ban()
return 1
elseif (cmd=="unban") then
local s,e,args = strfind( data, "%b<>%s%S+%s(.+)" )
if not s then curUser:SendData(botName,"Syntax: -unban ") return 1 end
if (args == "" or args == nil or args == " ") then curUser:SendData(botName,"Parameter can't be an empty string or contain more than one space beetween the 'command' and the 'parameter'.") return 1 end
      local s,e,number = strfind(args, "%.(%d+)$")
      if number ~= nil then
         Unban(args)
         SendToAll(botName, args.." was found. unbanned by ip.")
         SendToAll(botName, "Banlist not opend as ip was given in unban command.")
         return 1
      else
         SendToAll(botName, "Opening banlist 2 search for the ip")
         ip = OpenBanList(args)
         if ip ~= nil then
            Unban(ip)
            SendToAll(botName, args.." was found. his ip was: "..ip..". he is unbanned now")
            return 1
         else
            SendToAll(botName, args.." was not found in the banlist")
            return 1
         end
      end
end
end

function OpenBanList(args)
   readfrom("../PermBan.dat")
   local temp2, yea
   while 1 do
      local line = read()
      if line ==  nil then
         readfrom()
         break
      end
      s,e,temp, temp2 = strfind(line, "(.+)|(%S*)")
      SendToAll(botName, temp2.." searching banlist")
      if temp2 == args then
         SendToAll(botName, "whe've got a match")
         yea = 1
         readfrom()
         break
      else
         SendToAll(botName, args.." didn't match ".. temp2)
      end
   end
   if yea == 1 then
      SendToAll(botName, "gone return something")
      return temp
   end
end
plop

*still some debugging left and SendToAll should be changed if you use this thingy.