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
10
points ]
 (1 vote)
Created 2019-10-16 01:26
5 days 22 hours ago
15
points ]
 (2 votes)
Created 2019-10-11 23:29
1 week 2 days ago
Gangler
17
points ]
 (2 votes)
Created 2019-10-10 16:26
1 week 4 days ago
26
points ]
 (3 votes)
Created 2019-10-08 02:25
1 week 6 days ago
5
points ]
 (1 vote)
Created 2019-10-08 13:32
1 week 6 days ago
Gangler
42
points ]
 (5 votes)
Created 2019-09-23 23:48
3 weeks 6 days ago
Fatality
39
points ]
 (4 votes)
Created 2019-09-28 02:57
3 weeks 2 days ago
Fatality
39
points ]
 (5 votes)
Created 2019-08-13 23:33
9 weeks 5 days ago
Fatality
55
points ]
 (6 votes)
Created 2019-08-13 23:36
9 weeks 5 days ago
RaZgRiZ
40
points ]
 (4 votes)
Created 2019-08-05 17:12
11 weeks 6 hours ago
27
points ]
 (3 votes)
Created 2018-02-13 11:00
1 year 35 weeks ago
87
points ]
 (9 votes)
Created 2011-09-04 02:41
8 years 7 weeks ago
20
points ]
 (2 votes)
Created 2019-06-25 17:55
16 weeks 6 days ago
30
points ]
 (3 votes)
Created 2019-05-17 21:51
22 weeks 3 days ago
Kretrens
44
points ]
 (5 votes)
Created 2019-05-08 05:38
23 weeks 5 days ago
Sauce
45
points ]
 (5 votes)
Created 2018-08-22 19:15
1 year 8 weeks ago
65
points ]
 (8 votes)
Created 2018-07-12 17:59
1 year 14 weeks ago
7YearBitch
47
points ]
 (6 votes)
Created 2019-03-07 23:20
32 weeks 4 days ago
Ao1 Pointblank
57
points ]
 (6 votes)
Created 2019-04-28 17:57
25 weeks 1 day ago
17
points ]
 (2 votes)
Created 2018-12-04 15:42
45 weeks 6 days ago
Who's new
  • Antknee55
  • gmiz
  • impala97
  • Fixxxer
  • Gangler