Enzo | 2012-10-10 22:09
Nick protection script 0.1 (irc-style #register and #identify commands)
This is a server-side cubescript implementation of irc-style #register and #identify commands.

//IRC-style register and identify commands
//prerequisites: server-side scripting and sqlite support
//Creator: Enzo - find me on quakenet in #sauerbraten
// release 10/10/2012

Identifying results in unspec, so this works best in locked mastermode.

//IRC-style register and identify commands
//prerequisites:   server-side scripting and sqlite support
//Creator: Enzo - find me on quakenet in #sauerbraten
// release 10/10/2012

defaultvalue "user_db" "default" // database for use if empty dont use databse
users_table = "users" // hardcoded table name with authkeys

sanitize__string = [
	//this doesn't really work for some reason
	feedback = (format "sanitizing %1" $arg2)
	echo $feedback

	s = $arg2
	s = (strreplace $s "^"" "")
	s = (strreplace $s "'" "")
	result $s
]

user__exist = [

	db_init $user_db
	nick = $arg1	//for reasons I can't fathom, sanitize_string screws up the nick

	//feedback = (format "user__exist: postsanitization testing if user exists arg1=%1 nick=%2" $arg1 $nick)
	//echo $feedback

	query = (format "SELECT nick FROM %1 WHERE nick=':0'" $users_table)
	qh = (db_pquery $query $nick $user_db)
	res = ""
	// check for errors
	if (= $qh -1) [
		db_error $user_db
		pm $arg1 "user_exist: Database error"
		res = 0
	] [
		res = (db_getrow $qh $user_db)
		(db_finalize $qh $user_db)
		
		if (=s $res "") [
			res = 0
			
			//err = (format "user__exist: user %1 not found in db." $nick)
			//echo $err	
		] [
			res = 1
			//err = (format "user__exist: user %1     found in db." $nick)
			//echo $err	
			//(format "^f1Player ^f0%1 ^f1was connected from ip ^f0%2 ^f1at ^f0%3" $arg1 (int2ip (at $res 0)) (timef (at $res 1) "%d.%m.%Y, %X"))
		]
		
	]
	result $res
]

cmd_userexist = [
	//untested, but should work
	nick = (sanitize__string $arg2)

	if (= (user__exist $nick) 0) [
		pm $arg1 "$nick is not in the user database."
	] [
		pm $arg1 "$nick is in the user database."
	]
]

registercommand "userexist" cmd_userexist 1 "s" "userexist ^f1Check to see if a user has registered.  #userexist "

password__match = [
	db_init $user_db

	nick = $arg1
	password = $arg2
	
	query = (format "SELECT nick FROM %1 WHERE nick=':0' AND password=':1'" $users_table)
	qh = (db_pquery $query (concat $nick $password) $user_db)
	res = ""
	// check for errors
	if (= $qh -1) [
		db_error $user_db
		pm $arg1 "user_exist: Database error"
		res = 0
	] [
		res = (db_getrow $qh $user_db)
		(db_finalize $qh $user_db)
		
		if (=s $res "") [
			res = 0

			//err = (format "user__exist: passwords do not match." $nick)
			//echo $err	
			//(format "^f1Player ^f0%1 ^f1have never connected" $arg1)	
		] [
			res = 1

			//err = (format "user__exist: passwords do     match!" $nick)
			//echo $err	

			//(format "^f1Player ^f0%1 ^f1was connected from ip ^f0%2 ^f1at ^f0%3" $arg1 (int2ip (at $res 0)) (timef (at $res 1) "%d.%m.%Y, %X"))
		]
		
	]
	result $res

]

cmd_identify = [
	nick =  (getname $arg1)
	password = (sanitize__string $arg2)
	ipaddress = (getip $arg1)

	if (= (user__exist $nick) 1) [
		if (= (password__match $nick $password) 1) [
			welcomemsg = (format "Welcome back %1! Unspecing..." (getname $arg1))
			pm $arg1 $welcomemsg
			spectator $arg1 0				//unspec player

		] [
			pm $arg1 "Invalid password."
		]
	] [
		pm $arg1 "Your nick has not been registered. Register your nick first using #register "
	]
]

registercommand "identify" cmd_identify 1 "s" "identify ^f1Identify yourself, #identify "

cmd_register = [
	nick = (getname $arg1)

	//feedback = (format "pre-sanitized register nick=%1 arg2=%2" $nick $arg2)
	//echo $feedback

	password = (sanitize__string $arg2)
	ipaddress = (getip $arg1)

	//feedback = (format "postsanitized register nick=%1 password=%2" $nick $password)
	//echo $feedback
	

	// load keys from database if needed
	if (= (user__exist $nick) 0) [
		db_init $user_db

		//create table users(nick text, password text, email text, ip text, status integer);

		//qh = (db_insert_replace $users_table "VALUES(':0',':1','',':2',1)" (concat $nick $password $ipaddress) $adduser_query $user_db)
		qh = (db_insert_replace $users_table "VALUES(':0',':1','',':2',1)" (concat $nick $password $ipaddress) $user_db)
		
		// check for errors
		if (= $qh -1) [
			pm $arg1 "Database error, unable to add user."
			db_error $user_db
		] [
			pm $arg1 "User successfully added. Welcome!"
			spectator $arg1 0				//unspec player
			// no errors
			//authcount = 0
			//while [row = (db_getrow $qh $auth_db); result (!=s $row "")] [
			//	// row format "degrave 23abc54bca4b3c5bc 0"
			//	adduser (at $row 0) (at $row 1)
			//	authcount = (+ 1 $authcount)
			//	//echo (format "adduser %1 %2" (at $row 0) (at $row 1))
			//]
			//syncmsg = (format "Authkeys reloaded, %1 authkeys were loaded from database" $authcount)
			db_finalize $qh $user_db
		]
	
	] [
		pm $arg1 "User already exists."
	]

	
]

// register our command, for admins only
registercommand "register" cmd_register 1 "s" "register ^f1Register yourself, #register "
cmd_register.cfg (3.16 KB)
0
points
 (0 votes)
User login
Users on Quadropolis
1 guest & no users online
vampirefrog
Created 2024-04-11 22:25
1 week 5 days ago
vampirefrog
29
points ]
 (4 votes)
Created 2010-05-30 10:00
13 years 47 weeks ago
Gangler
36
points ]
 (4 votes)
Created 2020-10-22 00:50
3 years 26 weeks ago
Zoocata
10
points ]
 (1 vote)
Created 2024-02-11 21:20
10 weeks 2 days ago
vampirefrog
10
points ]
 (1 vote)
Created 2023-07-23 20:02
39 weeks 3 days ago
36
points ]
 (4 votes)
Created 2020-12-10 12:49
3 years 19 weeks ago
Created 2023-12-12 23:34
19 weeks 21 hours ago
Zoocata
Created 2023-11-27 23:00
21 weeks 1 day ago
20
points ]
 (2 votes)
Created 2023-10-01 15:21
29 weeks 3 days ago
20
points ]
 (2 votes)
Created 2021-05-24 00:01
2 years 48 weeks ago
9
points ]
 (1 vote)
Created 2023-06-13 17:54
45 weeks 1 day ago
Zoocata
27
points ]
 (3 votes)
Created 2023-05-05 20:58
50 weeks 5 days ago
Zoocata
18
points ]
 (2 votes)
Created 2023-03-02 01:40
1 year 7 weeks ago
Getridou
Created 2023-01-29 23:27
1 year 12 weeks ago
Created 2023-01-19 19:36
1 year 13 weeks ago
Getridou
Created 2023-01-10 17:10
1 year 15 weeks ago
Getridou
Created 2023-01-01 14:30
1 year 16 weeks ago
Getridou
10
points ]
 (1 vote)
Created 2023-01-01 10:58
1 year 16 weeks ago
Getridou
Created 2023-01-01 10:49
1 year 16 weeks ago
afroninja
17
points ]
 (2 votes)
Created 2023-01-01 06:32
1 year 16 weeks ago
Who's new
  • ColdIV
  • Aidan
  • Hunk
  • letic86
  • BATMAN