login.sk

Created by Pikachu

Just so you know, we don't know the file format for every file. If it's just a bunch of random characters, it's probably a .zip or .jar.

# do whatever you want with this, just don't post it elsewhere as your own unless you've changed ~80% of the skript
options:
	# messages
	prefix: <orange>Login <dark grey>ยป<light grey>
	specifyapassword: You must specify a password
	mustregister: You have to register with ""/register <password>"" before you can login # remember to double quotes
	alreadyloggedin: You are already logged in
	alreadyhavepass: You already have a password
	passwordset: Your password has been set
	incorrectpass: You entered an incorrect password
	havetologin: Login with ""/login <password>"" # remember to double quotes
	nowloggedin: You are now logged in
	nopassword: Please create a password with ""/register <password>"" # remember to double quotes
	toomanytries: You were kicked for entering an incorrect password too many times
	noperm: You do not have permission to use this
	passwordreset: Your password has been reset
	resetmsg: %arg-1%'s password was reset
	# settings
	ipchange: true # whether or not to log someone out if their ip changes between logins
	kickfortries: true # whether or not to kick for incorrectly entering a password x amount of times
	maxtries: 5 # the amount of tries the player gets to enter the correct password before being kicked, if kickfortries is enabled
	resetperm: reset.password
	gravity: false # whether or not the armour stand should be effected by gravity. Potentially abusable to stop fall damage, but I reccomend keeping it on. True = gravity on, false = gravity off
	# slighty more "advanced" options below here
	timeout: 180 #The time, in seconds, a user has to be logged off before they have to log in again when they rejoin (set to 0 for none)
	list: logindetails #name of the list variable
#the actual skript
function loginVehicle(p: player):
	make {_p} dismount
	spawn 1 armor stand at location of {_p}
	set {_s} to last spawned entity
	add "{Invisible:1}" to nbt of {_s}
	if {@gravity} is false:
		add "{NoGravity:1}" to nbt of {_s}
	make {_p} ride {_s}
	set metadata value "loginStand" of {_s} to true
function loginstartsWith(s: string, t: string) :: boolean:
	return (check [subtext of {_s} from characters 1 to length of {_t} is {_t}] == true ? true : false)
command /resetpass <offline player>:
	trigger:
		if player has permission "{@resetperm}":
			set {_u} to arg-1's uuid
			delete {{@list}::%{_u}%::*}
			message "{@prefix} {@resetmsg}" to player
			kick arg-1 due to "{@prefix} {@passwordreset}"
		else:
			message "{@prefix} {@noperm}" to player
on command:
	if command executor is player:
		if {{@list}::%player's uuid%::status} is not set:
			cancel the event
			message "{@prefix} {@havetologin}" to player
on packet:
	if event-string is "PacketPlayInChat":
		if {{@list}::%player's uuid%::status} is not set:
			cancel the event
		set {_m} to "%packet field ""a""%"
		if "%loginstartsWith({_m}, ""/login"")% %loginstartsWith({_m}, ""/login "")%" contains "true":
			cancel the event
			if loginstartsWith({_m}, "/login "):
				replace all "/login " in {_m} with ""
				if {{@list}::%player's uuid%::password} is set:
					if {{@list}::%player's uuid%::status} is not set:
						if {{@list}::%player's uuid%::password} is hashed "%{{@list}::%player's uuid%::salt}%%{_m}%":
							set {{@list}::%player's uuid%::status} to true
							delete player's vehicle
							delete {{@list}::%player's uuid%::tries}
							sync:
								teleport player to {{@list}::%player's uuid%::location}
							message "{@prefix} {@nowloggedin}" to player
						else:
							message "{@prefix} {@incorrectpass}" to player
							if {@kickfortries} is true:
								if {{@list}::%player's uuid%::tries} is not set:
									set {{@list}::%player's uuid%::tries} to 1
								else:
									add 1 to {{@list}::%player's uuid%::tries}
								if {{@list}::%player's uuid%::tries} is greater than or equal to {@maxtries}:
									sync:
										kick {_p} due to "{@prefix} {@toomanytries}"
					else:
						message "{@prefix} {@alreadyloggedin}"
				else:
					message "{@prefix} {@mustregister}"
			else:
				message "{@prefix} {@specifyapassword}"
		else if "%loginstartsWith({_m}, ""/register"")% %loginstartsWith({_m}, ""/register "")%" contains "true":
			cancel the event
			if loginstartsWith({_m}, "/register "):
				if {{@list}::%player's uuid%::password} is not set:
					replace all "/register " in {_m} with ""
					set {{@list}::%player's uuid%::salt} to random 20 char string from `a-zA-Z0-9`
					set {{@list}::%player's uuid%::password} to hashed "%{{@list}::%player's uuid%::salt}%%{_m}%"
					message "{@prefix} {@passwordset}"
					set {{@list}::%player's uuid%::status} to true
					delete player's vehicle
				else:
					message "{@prefix} {@alreadyhavepass}"
			else:
				message "{@prefix} {@specifyapassword}"
on quit:
	delete {{@list}::%player's uuid%::tries}
	set {{@list}::%player's uuid%::lastlogin} to now
	set {{@list}::%player's uuid%::lastip} to hashed player's ip
	if metadata value "loginStand" of player's vehicle is true:
		delete player's vehicle
on join:
	if difference between {{@list}::%player's uuid%::lastlogin} and now is greater than or equal to {@timeout} seconds:
		delete {{@list}::%player's uuid%::status}
	else if hashed player's ip is not {{@list}::%player's uuid%::lastip}:
		if {@ipchange} is true:
			delete {{@list}::%player's uuid%::status}
	if {{@list}::%player's uuid%::status} is not set:
		set {{@list}::%player's uuid%::location} to location of player
		wait 20 ticks
		loginVehicle(player)
		if {{@list}::%player's uuid%::password} is not set:
			message "{@prefix} {@nopassword}" to player
		else:
			message "{@prefix} {@havetologin}" to player
on click:
	if {{@list}::%player's uuid%::status} is not set:
		cancel the event
		message "{@prefix} {@havetologin}" to player
on drop:
	if {{@list}::%player's uuid%::status} is not set:
		cancel the event
		message "{@prefix} {@havetologin}" to player
on pick up:
	if {{@list}::%player's uuid%::status} is not set:
		cancel the event
		message "{@prefix} {@havetologin}" to player
on damage:
	if attacker is a player:
		if {{@list}::%attacker's uuid%::status} is not set:
			cancel the event
on damage of player:
	if {{@list}::%victim's uuid%::status} is not set:
		cancel the event
on entity target:
	if targeted entity is a player:
		if {{@list}::%targeted entity's uuid%::status} is not set:
			cancel the event
on packet:
	if event-string is "PacketPlayInSteerVehicle" where [metadata value "loginStand" of player's vehicle is true]:
		cancel the event