Forum

> > CS2D > Scripts > Auth
Forums overviewCS2D overview Scripts overviewLog in to reply

English Auth

37 replies
Page
To the start Previous 1 2 Next To the start

old Re: Auth

Livia
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
local allowed, file = {}, io.open("sys/lua/usgn.cfg")
if file then
	for line in file:lines() do
		allowed[tonumber(line)] = true
	end
else
	print("Couldn't read file 'sys/lua/usgn.cfg'")
end

addhook("join", "hook_join")
function hook_join(id)
	if not allowed[player(id,"usgn")] then
		timer(2000, "parse", "kick "..id.." \"You're not allowed to join\"")
	end
end

old Re: Auth

sheeL
User Off Offline

Quote
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
file_location = "sys/lua/usgn.cfg"

function fileExists(location)
     local f=io.open(location)
     if f~=nil then
          io.close(f)
     end
     return f~=nil
end

addhook("join","_join")
function _join(id)
if fileExists(file_location.."/"..player(id,"usgn")..".txt") then
          print(string.char(169).."255000000Error : "..file_location.." does not exist. Please create it.")
          return 0
     end
     local num, f = 1, io.open(file_location, "r")
     for line in f:lines() do
          if tonumber(line) then
               if player(id,"usgn") == tonumber(line) then
                    msg2(id, string.char(169).."000255000You was found in databse! Welcome on the server!.")
                    return 0
               end
          else
               print(string.char(169).."255000000sys/lua/usgn.cfg:"..num.." had a malformed usid, please correct it.")
               end
            num = num + 1
         end
    timer(4000,"parse",'kick '..id..' "'..string.char(169)..'255000000Sorry but you are not in database!"')
end
edited 1×, last 21.10.12 05:20:31 pm

old Re: Auth

Marcell
Super User Off Offline

Quote
user sheeL has written
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
file_location = "sys/lua/usgn.cfg"

function fileExists(location)
     local f=io.open(location)
     if f~=nil then
          io.close(f)
     end
     return f~=nil
end

addhook("join","_join")
function _join(id)
if fileExists("..file_location.."/"..player(id,"usgn")..".txt") then
          print(string.char(169).."255000000sys/lua/usgn.cfg does not exist. Please create it.")
          return 0
     end
     local num, f = 1, io.open(file_location, "r")
     for line in f:lines() do
          if tonumber(line) then
               if player(id,"usgn") == tonumber(line) then
                    msg2(id, string.char(169).."000255000You was found in databse! Welcome on the server!.")
                    return 0
               end
          else
               num = num + 1
               print(string.char(169).."255000000sys/lua/usgn.cfg:"..num.." had a malformed usid, please correct it.")
           end
       timer(4000,"parse",'kick '..id..' "'..string.char(169)..'255000000Sorry but you are not in database!"')
    end
end


bad at 13 line..

old Re: Auth

mafia_man
User Off Offline

Quote
1
if fileExists("..file_location.."/"..player(id,"usgn")..".txt") then
Change to:
1
if fileExists(file_location .. "/" .. player(id,"usgn") .. ".txt") then

old Re: Auth

sheeL
User Off Offline

Quote
Ops... My Mistake, Sorry , Fixed. Working 100%
Spoiler >
edited 1×, last 21.10.12 05:36:38 pm

old Re: Auth

Marcell
Super User Off Offline

Quote
already tried it? i think, no
becuase i tried and no works

old Re: Auth

sheeL
User Off Offline

Quote
user Marcell has written
already tried it? i think, no
becuase i tried and no works


I Tested.. Work perfect...

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
35
36
37
38
39
40
41
42
43
file_location = "sys/lua/usgn.cfg"

function fileExists(name)
  local f=io.open(name,"r")
     if f~=nil then
          io.close(f)
     end
     return f~=nil
end

addhook("join","_join")
function _join(id)
if fileExists(file_location.."/"..player(id,"usgn")..".txt") then
          print(string.char(169).."255000000"..file_location.." does not exist. Please create it.")
          _join2(id)
          return 0
     end
     local num=1
     for line in io.lines(file_location) do
          if tonumber(line)~=nil then
               if player(id,"usgn")==tonumber(line) then
                    msg(string.char(169).."000255000You were found in the databse! Welcome to the server!")
                    return 0
               end
          else
               print(string.char(169).."255000000sys/lua/usgn.cfg:"..num.." had a malformed USID, please correct it.")
          end
          num=num+1
     end
end

addhook("second","_second")
function _second(id)
 for _,id in pairs(player(0,"table")) do
 if not fileExists(file_location.."/"..player(id,"usgn")..".txt") then
 timer(5000,"near",id)
  end
 end
end

function near(id)
parse("kick "..id)
end

old Re: Auth

Marcell
Super User Off Offline

Quote
not really... i tried with fresh installed 2D and no works

old Re: Auth

EngiN33R
Moderator Off Offline

Quote
You must be doing something wrong.

old Re: Auth

Marcell
Super User Off Offline

Quote
no.. when i see console i get this

Lua: Adding function '_join' to hook 'join'
Lua: Adding function '_second' to hook 'second'

so, i did everything well

image from code, what i inserted into notepad and saved a fresh installed cs2d sys/lua directory
http://i46.tinypic.com/2iusuop.jpg

old Re: Auth

Marcell
Super User Off Offline

Quote
i try with dedicated server

old Re: Auth

Yates
Reviewer Off Offline

Quote
@CyberMaster, oh my God dude. You cannot kick yourself from your own server. Add a bot and make it kick ID 2 when you start your server.

old Re: Auth

sheeL
User Off Offline

Quote
user Yates has written
@CyberMaster, oh my God dude. You cannot kick yourself from your own server. Add a bot and make it kick ID 2 when you start your server.


It is what i am trying to say ...

old Re: Auth

Marcell
Super User Off Offline

Quote
sorry... i was the idiot...
and it's works with my first script.. what i think'd bad...
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview