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]
			},
			"commands": {
				"PASS": self.passcmd
			}
		}
	
	def cleanup():
		self.ircd.actions.remove(self.passcmd)
		del self.ircd.commands["PASS"]
		del self.passcmd
@@ -149,40 +149,164 @@
 :%0A%09%09
-user.password = data%5B%22password%22%5D
+if self.ircd.server_password and not user.password:%0A%09%09%09user.registered -= 1%0A%09%09user.password = data%5B%22password%22%5D%0A%09%09if user.registered == 0:%0A%09%09%09user.register()
 %0A%09%0A%09
@@ -639,24 +639,158 @@
 ms%5B0%5D%0A%09%09%7D%0A%09%0A
+%09def onConnect(self, user):%0A%09%09if self.ircd.server_password:%0A%09%09%09user.registered += 1 # Make password a required step in registration%0A%09%0A
 %09def onRegis
@@ -1153,24 +1153,24 @@
 %0A%09%09return %7B%0A
-
 %09%09%09%22actions%22
@@ -1169,24 +1169,65 @@
 actions%22: %7B%0A
+%09%09%09%09%22connect%22: %5Bself.passcmd.onConnect%5D,%0A
 %09%09%09%09%22registe

Make the PASS command a required step on connect when there is a server password