Ejemplo n.º 1
0
	def realHandle(self, command):
		command = command.strip()
		cmdList = command.split(' ')
		if self.place == "Welcome":
			self.username = command
			self.place = "Password"
			self.look()
		elif self.place == "Password":
			password = SI.getPasswordHash(self.cursor, self.username)
			if password == sha.new(command).hexdigest():
				thread = SI.getThreadID(self.cursor, self.username)
				if thread:
					self.write("Sorry, You are already logged in.")
					print "User tried to log in who was already "\
							"connected on thread %s'" % repr(thread)
					self.finish()
					return
				self.fullname = \
					SI.getUserData(self.cursor, self.username, DC.FullName)
				self.nickname = \
					SI.getUserData(self.cursor, self.username, DC.NickName)
				self.userlevel = \
					SI.getUserData(self.cursor, self.username, DC.UserLevel)
				self.place = "InGame"
				SI.setThreadID(self.cursor, self.username, self.threadid)
				room = SI.getLocation(self.cursor, self.username)
				area = SI.getArea(self.cursor, room)
				self.realMove(area, room, DBUpdate = 0)
				self.sendToSelf(SI.motd())
				self.look()
				return
			self.username = ""
			self.write("Incorrect username or password. Please try again.")
			self.place = "Welcome"
			self.look()
		else:
			firstCommand = lower(cmdList[0])
			if firstCommand in valid_commands.keys():
				function = getattr(self, valid_commands[firstCommand])
				function(cmdList)
			elif firstCommand in combatActions.keys():
				# Combat actions need a target.
				self.server.performAction(self.username, firstCommand,\
						(self.username, cmdList[1], self.threadid, self.room,\
						None))
			elif firstCommand in skillActions.keys():
				# Skill actions need a target, potentially.
				if len(cmdList) == 2:
					target = cmdList[1]
				else:
					target = None
				self.server.performAction(self.username, firstCommand,\
						(self.username, target, self.room, None))
			elif firstCommand in self.exits.keys():
				self.move(["go", firstCommand])
			elif not firstCommand.strip():
				# User just hit enter.
				return
			else:
				self.write("Unknown command.")
Ejemplo n.º 2
0
    def realHandle(self, command):
        """
		Grunt work is done here. This is called every time a complete line
		(terminating in a \r\n) is received by the handler loop. 'command' is
		a full-line string, with no trailing newline characters.
		"""
        command = command.strip()
        cmdList = command.split(' ')
        if self.state == USERNAME:
            # No username as yet, let's get one.
            self.username = command
            self.state = PASSWORD
            self.look()

        elif self.state == PASSWORD:
            # No password, let's get one.
            password = SI.getPasswordHash(self.cursor, self.username)
            if password == sha.new(command).hexdigest():
                thread = SI.getThreadID(self.cursor, self.username)
                if thread:
                    self.write("Sorry, You are already logged in.")
                    print "User tried to log in who was already "\
                      "connected on thread %s'" % repr(thread)
                    self.finish()
                    return
                self.fullname = \
                 SI.getUserData(self.cursor, self.username, DC.FullName)
                self.nickname = \
                 SI.getUserData(self.cursor, self.username, DC.NickName)
                self.userlevel = \
                 SI.getUserData(self.cursor, self.username, DC.UserLevel)
                self.state = INGAME
                SI.setThreadID(self.cursor, self.username, self.threadid)
                room = SI.getUserLocation(self.cursor, self.username)
                area = SI.getArea(self.cursor, room)
                self.realMove(area, room, DBUpdate=0)
                self.look()
                return
            self.username = ""
            self.write("Incorrect username or password. Please try again.")
            self.state = USERNAME
            self.look()
        elif self.state == INGAME:
            # We are in-game. Process the full command.
            firstCommand = lower(cmdList[0])
            if firstCommand in valid_commands.keys():
                function = getattr(self, valid_commands[firstCommand])
                function(cmdList)
            elif firstCommand in combatActions.keys():
                # Combat actions need a target.
                self.server.performAction(self.username, firstCommand,\
                  (self.username, cmdList[1], self.threadid, self.room,\
                  None))
            elif firstCommand in skillActions.keys():
                # Skill actions need a target, potentially.
                if len(cmdList) == 2:
                    target = cmdList[1]
                else:
                    target = None
                self.server.performAction(self.username, firstCommand,\
                  (self.username, target, self.room, None))
            elif firstCommand in self.exits.keys():
                self.move(["go", firstCommand])
            elif not firstCommand.strip():
                # User just hit enter.
                return
            else:
                self.write("Unknown command.")
Ejemplo n.º 3
0
 def handle_exit(self):
     if self.username:
         SI.setThreadID(self.cursor, self.username, '')
     self.server.child_unregister(self.threadid)
Ejemplo n.º 4
0
	def handle_exit(self):
		if self.username:
			SI.setThreadID(self.cursor, self.username, '')
		self.server.child_unregister(self.threadid)