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
20
points ]
 (2 votes)
Created 2020-12-03 17:12
1 day 6 hours ago
20
points ]
 (2 votes)
Created 2020-12-04 12:05
11 hours 59 min ago
30
points ]
 (3 votes)
Created 2020-06-13 21:05
24 weeks 6 days ago
30
points ]
 (3 votes)
Created 2020-11-30 04:00
4 days 20 hours ago
50
points ]
 (5 votes)
Created 2020-01-23 12:57
45 weeks 1 day ago
68
points ]
 (7 votes)
Created 2020-10-11 13:46
7 weeks 5 days ago
64
points ]
 (7 votes)
Created 2018-12-04 15:12
2 years 1 day ago
Gangler
36
points ]
 (4 votes)
Created 2020-10-22 00:50
6 weeks 1 day ago
LURKing
13
points ]
 (2 votes)
Created 2020-11-22 21:21
1 week 5 days ago
LURKing
37
points ]
 (4 votes)
Created 2020-11-18 21:08
2 weeks 2 days ago
Shuzomi
30
points ]
 (3 votes)
Created 2020-11-15 18:16
2 weeks 5 days ago
Im_Percynator
Created 2020-11-15 07:21
2 weeks 5 days ago
micai
24
points ]
 (3 votes)
Created 2020-11-11 18:27
3 weeks 2 days ago
afroninja
56
points ]
 (6 votes)
Created 2020-01-15 07:47
46 weeks 2 days ago
LURKing
30
points ]
 (4 votes)
Created 2020-10-15 20:38
7 weeks 1 day ago
31
points ]
 (4 votes)
Created 2020-10-15 20:20
7 weeks 1 day ago
10
points ]
 (1 vote)
Created 2020-09-15 02:22
11 weeks 3 days ago
8
points ]
 (2 votes)
Created 2020-09-12 23:14
11 weeks 6 days ago
21
points ]
 (3 votes)
Created 2020-09-09 19:44
12 weeks 2 days ago
51
points ]
 (11 votes)
Created 2011-12-26 12:13
8 years 49 weeks ago
Who's new
  • WASP
  • Im_Percynator
  • micai
  • Hypercycle
  • Getridou