Author Topic: clearing a table  (Read 1737 times)

0 Members and 1 Guest are viewing this topic.

Offline ??Empie??

  • Junior Member
  • **
  • Posts: 11
  • Karma: +0/-0
clearing a table
« on: 03 February, 2004, 00:39:48 »
Hi all

I just wrote my first bot totally from scratch. It seemed to work like a charm but it seems that ptokax doesnt clear the table on a hub reboot or script reboot...

The problem lies at the clone detection. I have a list which stores IP's. Here's a stripped example of the problem:


Code: [Select]
tIPList = {}

function NewUserConnected(curUser)
if(tIPList[curUser.sIP]) and not curUser.bOperator then
local CloneUser = GetItemByName(tIPList[curUser.sIP])
CloneUser:SendData(Bot,"No clones allowed. Only 1 login per IP")
CloneUser:Disconnect()
tIPList[curUser.sIP] = curUser.sName
else
tIPList[curUser.sIP] = curUser.sName
end
end


function UserDisconnected(curUser)
tIPList[curUser.sIP] = nil;
end

It simply stores every the ip of every connecting in tIPList, and when the user disconnects it removes the entry again. Whenever a user connects for the 2nd time the first connection is disconnected and the ip is stored in the list again (becouse on the disconnect it removes the ip from the list so a 3rd connection would be possible).

but now whenever I restart the script or the hub without restarting the pc the list gets saves so lots of ppl cant get in.

Can I clear or reset the table in the main funcion? so to say whenever the script starts?

lots of thx in advance!

? Empie ?

Killua Anime - Akira's Fiction 1 - Killua.student.utwente.nl

PtokaX forum

clearing a table
« on: 03 February, 2004, 00:39:48 »

Offline kepp

  • Scripter
  • King
  • ******
  • Posts: 790
  • Karma: +2/-0
(No subject)
« Reply #1 on: 03 February, 2004, 03:23:11 »
Wouldn't that delete all entries?

Im not sure but you could try in main

function Main()
tIPList = nil;
tIPList = {}
end

??

You also check "and if not user.bOperator" which i don't think is needed since you use NewUserConnected() that only proceed data with an index below OP's
« Last Edit: 03 February, 2004, 03:32:36 by kepp »
Guarding    

Offline plop

  • Forum God
  • ****
  • Posts: 2 464
  • Karma: +37/-0
(No subject)
« Reply #2 on: 03 February, 2004, 03:36:42 »
should be no need 2 save it anymore with this modifications.
Code: [Select]
tIPList = {}

function NewUserConnected(curUser)
if(tIPList[curUser.sIP]) then
curUser:SendData(Bot,"No clones allowed. Only 1 login per IP")
curUser:Disconnect()
else
tIPList[curUser.sIP] = curUser.sName
end
end


function UserDisconnected(curUser)
   if curUser.sName == tIPList[curUser.sIP] then
      tIPList[curUser.sIP] = nil
   end
end

function DataArrival(curUser, data)
   if curUser.bOperator == nil then
      if tIPList[curUser.sIP] == nil then
         tIPList[curUser.sIP] = curUser.sName
      elseif tIPList[curUser.sIP] ~= curUser.sName then
         curUser:SendData(Bot,"No clones allowed. Only 1 login per IP")
         curUser:Disconnect()
      end
   end
end
removed the disconnecting of the clone as you can better disconnect the 2de ip.
some isp's put multiple users on 1 ip, your way would be really irritating for them.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Offline ??Empie??

  • Junior Member
  • **
  • Posts: 11
  • Karma: +0/-0
(No subject)
« Reply #3 on: 04 February, 2004, 02:58:16 »
Quote
Originally posted by plop
removed the disconnecting of the clone as you can better disconnect the 2de ip.
some isp's put multiple users on 1 ip, your way would be really irritating for them.
plop

Yeah, I see what you mean but I'm going to stick to the kicking of the first one..

Sometimes a "ghost clone" stays in the hub for some reason, and it would mean that that user couldnt log in...

about ISP's giving 2 ppl the same IP... I have never heard of that. It is true that a lot of people share their internetconnection, and those people would have 1 IP, thats true, but at the same time they also have only 1 upload, so I dont mind that only one of them can connect.

In the two days that I had the script running (in a 1000+ user hub) only 1 person came to me with that problem. I explained it to him and he totally understood :).

still much thanx for the help Kepp and plop, Im going to dig into the script now ^_^

? Empie ?

Offline plop

  • Forum God
  • ****
  • Posts: 2 464
  • Karma: +37/-0
(No subject)
« Reply #4 on: 04 February, 2004, 04:01:11 »
NGT from norway is 1 of those isp's, all of them are passive users.
the record i found was 8 users on 1 ip.
it's a lame trick as they need 2 pay extra for a own ip.
nearly all don't know about this untill they complained 2 the isp.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

PtokaX forum

(No subject)
« Reply #4 on: 04 February, 2004, 04:01:11 »