<commit_before>from twisted.words.protocols import irc
from txircd.modbase import Command, Module

class PassCommand(Command, Module):
	def onUse(self, user, data):
		user.password = data["password"]
	
	def processParams(self, user, params):
		if user.registered == 0:
			user.sendMessage(irc.ERR_ALREADYREGISTRED, ":Unauthorized command (already registered)")
			return {}
		if not params:
			user.sendMessage(irc.ERR_NEEDMOREPARAMS, "PASS", ":Not enough parameters")
			return {}
		return {
			"user": user,
			"password": params[0]
		}
	
	def onRegister(self, user):
		if self.ircd.server_password and self.ircd.server_password != user.password:
			user.sendMessage("ERROR", ":Closing link: ({}@{}) [Access denied]".format(user.username, user.hostname), to=None, prefix=None)
			return False

def Spawner(object):
	def __init__(self, ircd):
		self.ircd = ircd
		self.passcmd = PassCommand()
	
	def spawn():
		return {
			"actions": {
				"register": [self.passcmd.onRegister]
			},<commit_msg>Make the PASS command a required step on connect when there is a server password<commit_after>from twisted.words.protocols import irc
from txircd.modbase import Command, Module

class PassCommand(Command, Module):
	def onUse(self, user, data):
		if self.ircd.server_password and not user.password:
			user.registered -= 1
		user.password = data["password"]
		if user.registered == 0:
			user.register()
	
	def processParams(self, user, params):
		if user.registered == 0:
			user.sendMessage(irc.ERR_ALREADYREGISTRED, ":Unauthorized command (already registered)")
			return {}
		if not params:
			user.sendMessage(irc.ERR_NEEDMOREPARAMS, "PASS", ":Not enough parameters")
			return {}
		return {
			"user": user,
			"password": params[0]
		}
	
	def onConnect(self, user):
		if self.ircd.server_password:
			user.registered += 1 # Make password a required step in registration
	
	def onRegister(self, user):
		if self.ircd.server_password and self.ircd.server_password != user.password:
			user.sendMessage("ERROR", ":Closing link: ({}@{}) [Access denied]".format(user.username, user.hostname), to=None, prefix=None)
			return False

def Spawner(object):
	def __init__(self, ircd):
		self.ircd = ircd
		self.passcmd = PassCommand()
	
	def spawn():
		return {
			"actions": {
				"connect": [self.passcmd.onConnect],
				"register": [self.passcmd.onRegister]
			},
{'fraction_non_alphanumeric': 0.131891433418151, 'fraction_numerical': 0.0029686174724342664, 'mean_word_length': 4.435483870967742, 'pattern_counts': {'":': 15, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4523667', 'n_tokens_mistral': 860, 'n_tokens_neox': 757, 'n_words': 197}