Forum

> > CS2D > Scripts > Double Usgn login
Forums overviewCS2D overview Scripts overviewLog in to reply

English Double Usgn login

7 replies
To the start Previous 1 Next To the start

old Double Usgn login

G3tWr3ck3d
User Off Offline

Quote
My double usgn login is not working anymore i couldn't find the problem yet.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
addhook("join","_join")
addhook("leave","_leave")

usgns = {}

function check_usgn(usgn)
	if usgn == 0 then 
		return false
	end
	for _,id in pairs(usgns) do
		if id==usgn then 
		return true
		end
	end
	return false
end

function _join(id)
	if check_usgn(player(id,"usgn")) then
		timer(50,"parse","kick "..id.." \"Double USGN numbers detected!\"")
		table.insert(usgns,player(id,"usgn"))	
	end	
end

function _leave(p)
    if player(p,"usgn")>0 then
        for n,p in pairs(usgns) do
            if p==player(p,"usgn") then 
				table.remove(usgns,n)
				break
			end
		end
	end
end

old Re: Double Usgn login

_Yank
User Off Offline

Quote
If you want to prevent 2 players with same USGN from connecting, you're doing everything wrong. First, you add the player to the USGN list only if his USGN is already there (which is impossible) (line 21). Second, you name 2 values equally (line 25 and 27, the p value). Third, you should not rely on leave hook as players connection can timeout, drop or crash and the hook doesn't gets called. Thus, you could do this in a much shorter way.

1
2
3
4
5
6
7
8
9
10
11
12
13
addhook("join", "stopDoubleUSGN")
function stopDoubleUSGN(id)
	local list = {}
	for _, id2 in ipairs(player(0, "table")) do
		if id2 ≃ id then list["ID"..player(id2, "usgn")] end
	end

	if player(id, "usgn") > 0 then
		if list["ID"..player(id, "usgn")] then
			timer(player(id, "ping") + 10, "parse", "kick "..id.." \"You're already connected with this USGN!\"")
		end
	end
end
you may ask why I used a string for the key and not just a number, I did that to avoid lua "smart" array memory management that tends to pre-allocate memory for further values since USGN numbers are somewhat high.
edited 1×, last 20.09.15 10:38:48 pm

old Re: Double Usgn login

DC
Admin Off Offline

Quote
Not sure why he used it (@user _Yank: does it work with that symbol too?). The more common way to write it would be
1
~=
So just Lua's inequality operator.

old Re: Double Usgn login

Starkkz
Moderator Off Offline

Quote
I don't know why you added a string "ID" prefix, using key strings slows down the iteration process.

old Re: Double Usgn login

Yates
Reviewer Off Offline

Quote
How about we simply this eh?:

1
2
3
4
5
for _,all in pairs(player(0,"table")) do
	if id ~= all and player(id,"usgn") == player(all,"usgn") then
		parse("kick "..id)
	end
end

Call this using a timer on the join hook, make sure it executes after 2 seconds at least. CS2D doesn't like kicking people on join.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview