Forum

> > CS2D > Scripts > Login , register & Save system ?
Forums overviewCS2D overview Scripts overviewLog in to reply

English Login , register & Save system ?

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

old Login , register & Save system ?

Kirito2K
User Off Offline

Quote
Hi all , i search for a login and register , like the scripts that have been used in some of minecraft game servers , do you know a script like that ?

old Re: Login , register & Save system ?

Kirito2K
User Off Offline

Quote
i did but i didn't find and i found a script on file archive but it's not what i'm looking for , i need if the player didn't register/login then he can't talk or join any team ..

old Re: Login , register & Save system ?

Kirito2K
User Off Offline

Quote
it's simple , i want login and register with save and if i didn't login or register then i can't talk or move or even join a team..
I've been searching for something like that but i didn't find

old Re: Login , register & Save system ?

Talented Doge
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
31
32
33
34
35
36
37
38
39
40
ranking = {}

prefix = "@"
dir = "sys/lua/data/"

addhook("say", "_s")
addhook("join", "_j")

function _s(p, t)
	if t:sub(1,1) == prefix then
		if t:sub(2,6) == "login" then
			local tgt = t:sub(8)
			local file = io.open(dir..tgt..".txt", "r")
			if file then
				local read1 = file:read("*l")
				ranking[p] = read1 or 0
				file:close()
				msg2(p, "\169000255000You've been logged in!")
			else
				msg2(p, "\169255000000Cannot find your account! Please register one!")
			end
		elseif t:sub(2,9) == "register" then
			local tgt = t:sub(11)
			local file = io.open(dir..tgt..".txt", "r")
			if file then
				msg2(p, "\169255000000Account with this password already exists! Please choose another one!")
			else
				local file = io.open(dir..tgt..".txt", "w")
				file:write(ranking[p])
				file:close()
				msg2(p, "\169000255000Registeration succeed! You may now login with your password!")
			end
		end
		return 1
	end
end

function _j(p)
	ranking[p] = "0"
end

Written this, may not be the perfect one though.

old Re: Login , register & Save system ?

Talented Doge
User Off Offline

Quote
That is pretty easy, you could have done by yourself...
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
44
45
46
47
48
ranking = {}

prefix = "@"
dir = "sys/lua/data/"

addhook("say", "_s")
addhook("join", "_j")
addhook("team", "_t")

function _s(p, t)
    if t:sub(1,1) == prefix then
        if t:sub(2,6) == "login" then
            local tgt = t:sub(8)
            local file = io.open(dir..tgt..".txt", "r")
            if file then
                local read1 = file:read("*l")
                ranking[p] = tonumber(read1) or 0
                file:close()
                msg2(p, "\169000255000You've been logged in!")
            else
				msg2(p, "\169255000000Cannot find your account! Please register one!")
            end
        elseif t:sub(2,9) == "register" then
            local tgt = t:sub(11)
            local file = io.open(dir..tgt..".txt", "r")
            if file then
                msg2(p, "\169255000000Account with this password already exists! Please choose another one!")
            else
				ranking[p] = 1
                local file = io.open(dir..tgt..".txt", "w")
                file:write(ranking[p])
                file:close()
                msg2(p, "\169000255000Registeration succeed! You may now login with your password!")
            end
        end
        return 1
	elseif ranking[p] < 1 then
		msg2(p, "\169255000000You must log in to say! Say !register to register if you did not register!") return 1
    end
end

function _j(p)
     ranking[p] = 0
end

function _t(p)
	if ranking[p] < 1 then msg2(p, "\169255000000You must log in to play! Say !register to register if you did not register!") return 1 end
end
By adding totally 6 lines of code you can have the thing you want be done.
edited 3×, last 15.06.15 07:34:30 am

old Re: Login , register & Save system ?

Talented Doge
User Off Offline

Quote
It will need to recognize some unique information from users then. IP won't be efficient, some players got dynamic ips. And there is no other usable unique informations other than ip you can use, that is pointless at the current version.

CS2D has a unique data however, but I don't really know how to fetch it.

old Re: Login , register & Save system ?

Dousea
User Off Offline

Quote
This code was tested and worked. Uses U.S.G.N. to register/login.
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
-- (re)create "passwords.txt" file
io.open("passwords.txt", "w"):close()

logged = {}

addhook("say", "sayhook")

function sayhook(id, message)
	if (player(id, "usgn") > 0) then
		if (message:sub(1, 6) == "!login") then
			if (not logged[player(id, "usgn")]) then
				local file = io.open("passwords.txt", "a+")
				local password = message:sub(8, #message)
				local usgn = {
					string = tostring(player(id, "usgn")),
					wrongpassword = false
				}
				
				for line in file:lines() do
					if (line:sub(1, #usgn.string) == usgn.string) then
						if (line:sub(#usgn.string + 2, #line) == tostring(password)) then
							logged[player(id, "usgn")] = true
						else
							usgn.wrongpassword = true
							
							msg2(id, "\169255000000Wrong password!@C")
							msg2(id, "Please contact the administrator of this server!@C")
						end
						
						break
					end
				end
				
				file:close()
				
				if (not logged[player(id, "usgn")] and not usgn.wrongpassword) then
					msg2(id, "\169255000000You don't have any account!@C")
					msg2(id, "Please register via \"!register <password>\"!@C")
				elseif (logged[player(id, "usgn")]) then
					msg2(id, "You are logged in!@C")
				end
			else
				msg2(id, "\169255000000You already logged in!@C")
			end
			
			return 1
		elseif (message:sub(1, 9) == "!register") then
			local file = io.open("passwords.txt", "a+")
			local password = message:sub(11, #message)
			local usgn = {
				string = tostring(player(id, "usgn")),
				account = false
			}
			
			for line in file:lines() do
				if (line:sub(1, #usgn.string) == usgn.string) then
					usgn.account = true
					
					msg2(id, "\169255000000You already have an account!@C")
					
					if (not logged[player(id, "usgn")]) then
						msg2(id, "Please login via \"!login <password>\"!@C")
					end
					
					break
				end
			end
			
			if (not usgn.account) then
				file:write(tostring(player(id, "usgn")) .. " " .. password)
				
				msg2(id, "You can now login using your registered account!@C")
				msg2(id, "Please login via \"!login <password>\"!@C")
			end
			
			file:close()
			
			return 1
		end
	end
end

old Re: Login , register & Save system ?

Black Wolf
User Off Offline

Quote
He wants it like in cracked minecraft servers.

''!register glix123 glix123'' and when it done you have to login ''!login glix123''. You dont need usgn, you make account in server, is that what you mean?

old Re: Login , register & Save system ?

r4ndxm
User Off Offline

Quote
edit: Tested, so dangerous.

Doesn't add ;new line; (easy to fix)

It's almost perfect, just add....

(encryptionz, some might use their 'USGN' passwords in this script)

--------------

edit: Almost forgot

user Kirito2K has written
if i didn't login or register then i can't talk or move or even join a team
edited 4×, last 16.06.15 04:54:28 am

old Re: Login , register & Save system ?

Kirito2K
User Off Offline

Quote
not same i was wanted , i need also if player used !register then he didn't put any letter then it fail , i tried this in your code i wrote "!register " and it said you have made a account , i want this like terraria or minecraft servers just understand please!

old Re: Login , register & Save system ?

Dousea
User Off Offline

Quote
This code now needs your own username and password, without using U.S.G.N. like you want, even with minor feature such log out. It doesn't allow you to register and login without username and password (or "didn't put any letter") like you want, too. I want to implement "change password" feature but.. nah. Username and password can take any character but space. This code doesn't include your "can't talk, join, etc.". I assume you know Lua language. Please test it!
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
io.open("accounts.txt", "w"):close()

logged = {}

addhook("say", "sayhook")
addhook("leave", "leavehook")

function sayhook(id, message)
	if (message:sub(1, 9) == "!register" or message:sub(1, 6) == "!login") then
		local strings = {}
		
		for string in message:gmatch("[^%s]+") do
			table.insert(strings, string)
		end
		
		local arguments = select("#", unpack(strings))
		
		if (arguments > 3 or arguments < 3) then
			msg2(id, "\169255000000Please insert username and password properly without any whitespace!@C")
			msg2(id, "Use \"<username> <password>\" structure!@C")
			
			return 1
		end
		
		local file = io.open("accounts.txt", "a+")
		
		if (message:sub(1, 9) == "!register") then
			for line in file:lines() do
				if (line:sub(1, #strings[2]) == strings[2]) then
					msg2(id, "\169255000000Account with that username already exists!@C")
					file:close()
					
					return 1
				end
			end
			
			file:write(strings[2] .. " " .. strings[3] .. "\n")
			
			msg2(id, "You can now log in using your registered account!@C")
			msg2(id, "Please log in via \"!login <username> <password>\"!@C")
		elseif (message:sub(1, 6) == "!login") then
			if (not logged[id]) then
				for line in file:lines() do
					if (line:sub(1, #strings[2]) == strings[2]) then
						if (line:sub(#strings[2] + 2, #line) == strings[3]) then
							logged[id] = true
							
							msg2(id, "Welcome, " .. strings[2] .. "!@C")
							file:close()
							
							return 1
						else
							msg2(id, "\169255000000Wrong password!@C")
							msg2(id, "Please contact the administrator of this server!@C")
							file:close()
							
							return 1
						end
					end
				end
				
				msg2(id, "\169255000000Account doesn't exist!@C")
				msg2(id, "Please register via \"!register <username> <password>\"!@C")
			else
				msg2(id, "\169255000000You already logged in!@C")
			end
		end
		
		file:close()
		
		return 1
	elseif (message:sub(1, 7) == "!logout") then
		if (logged[id]) then
			logged[id] = false
			
			msg2(id, "You are logged out!@C")
		else
			msg2(id, "You are not logged in!@C")
		end
		
		return 1
	end
end

function leavehook(id)
	if (logged[id]) then
		logged[id] = false
	end
end
edited 1×, last 16.06.15 08:16:30 am

old Re: Login , register & Save system ?

Dousea
User Off Offline

Quote
user Black Wolf has written
''!register glix123 glix123'' and when it done you have to login ''!login glix123''. You dont need usgn, you make account in server, is that what you mean?

user Kirito2K has written
@user Black Wolf: Yep , that what i want ://..

I was basically confused. Was he trying to answer this?
user Black Wolf has written
He wants it like in cracked minecraft servers.


And what kind of limit you talked about?
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview