Esempio n. 1
0
 def testRemoveUnprintables(self):
     # Remove three ANSI color codes
     cleaned = cleanPlayerInput(self.unprintable)
     assert( (self.unprintableLen - len(cleaned)) is 3 )
     
     # Not sure why this is comes out as 2 since backspace is 1 character?
     cleaned = cleanPlayerInput(self.backspace)
     assert( (self.backspaceLen - len(cleaned)) is 2)
Esempio n. 2
0
def GameParser(player, line):
    """
    GameParser()
    
    Parses information send my client and
    makes decisions based on that information.
    """
    
    line = cleanPlayerInput(line)
    
    # If not playing, don't use main game parser
    if player.status is not PLAYING:
        statusMatrix(player, line)
        return
    
    if player.stats[STUN] is 1:
        character.communicate.sendToPlayer(player, "You are stunned!")
        return
    
    # If just hit enter, display room
    if line == "":
        character.functions.displayRoom(player, player.room)
        return      
    
    
    cmd = line.split()
    
    # If casting a spell.
    if SpellParser(player, cmd):
        return
    
    cmdstr = re.compile(re.escape(cmd[0].lower()))
                        
          
    for each in commands.keys():
        if cmdstr.match(each): 
            if each == "/quit" and len(cmd[0]) > 1:
                player.disconnectClient()
                return
            elif each == "north" and len(cmd) == 1 and len(cmd[0]) != 2:
                character.functions.movePlayer(player, NORTH)
                return
            elif (each == "ne" and len(cmd) == 1 and len(cmd[0]) == 2):
                character.functions.movePlayer(player, NE)
                return
            elif (each == "northeast" and len(cmd) == 1 and len(cmd[0]) > 5 ):
                character.functions.movePlayer(player, NE)
                return
            elif each == "east" and len(cmd) == 1 and len(cmd[0]) != 2:
                character.functions.movePlayer(player, EAST)
                return
            elif (each == "se" and len(cmd) == 1 and len(cmd[0]) == 2):
                character.functions.movePlayer(player, SE)
                return
            elif (each == "southeast" and len(cmd) == 1 and len(cmd[0]) > 5):
                character.functions.movePlayer(player, SE)
                return
            elif each == "south" and len(cmd) == 1 and len(cmd[0]) != 2:
                character.functions.movePlayer(player, SOUTH)
                return
            elif (each == "sw" and len(cmd) == 1 and len(cmd[0]) == 2):
                character.functions.movePlayer(player, SW)
                return
            elif (each == "southwest" and len(cmd) == 1 and len(cmd[0]) > 5 ):
                character.functions.movePlayer(player, SW)
                return
            elif each == "west" and len(cmd) == 1 and len(cmd[0]) != 2:
                character.functions.movePlayer(player, WEST)
                return
            elif (each == "nw" and len(cmd) == 1 and len(cmd[0]) == 2):
                character.functions.movePlayer(player, NW)
                return
            elif (each == "northwest" and len(cmd) == 1 and len(cmd[0]) > 5 ):
                character.functions.movePlayer(player, NW)
                return
            elif each == "up" and len(cmd) == 1 and len(cmd[0]) != 2:
                character.functions.movePlayer(player, UP)
                return
            elif each == "down" and len(cmd) == 1 and len(cmd[0]) != 2:
                character.functions.movePlayer(player, DOWN)
                return
            elif each == "rest" and len(cmd) == 1 and len(cmd[0]) == 4:
                character.functions.rest(player)
                return                            
            elif each == "map" and len(cmd) == 1 and len(cmd[0]) == 3:
                commands[each](player)
                return
            elif each == "level" and len(cmd) == 1 and len(cmd[0]) == 5:
                commands[each](player)
                return    
            elif each == "attack" and len(cmd) == 2:
                combat.functions.attack(player, cmd[1])
                return                
            elif each == "break" and len(cmd) == 1 and len(cmd[0]) > 2:
                commands[each](player)
                return
            elif each == "gossip" and len(cmd) > 1 and len(cmd[0]) > 2:
                character.communicate.gossip(player, line[(len(cmd[0]) + 1):])
                return            
            elif each == "look" and len(cmd) > 1:
                look(player, line[(len(cmd[0]) + 1):])
                return
            elif each == "who" and len(cmd) is 1:
                utils.playercommands.who(player)
                return  
            elif each == "sneak" and len(cmd) is 1 and len(cmd[0]) > 1:
                utils.playercommands.Sneak(player)
                return
            elif each == "reloadspells" and len(cmd) is 1:
                world.maps.World.CastableSpells = world.magic.loadPlayerSpells()
                return
            elif each == "admin" and len(cmd) > 1 and len(cmd[0]) > 2:
                utils.playercommands.requestAdmin(player, line[(len(cmd[0]) + 1):])
                return
            elif each == "spells" and len(cmd) == 1 and len(cmd[0]) == 6:
                commands[each](player)            
                return      
            elif each == "whois" and len(cmd) == 2:
                utils.playercommands.whoIs(player, cmd[1])
                return
            
            
    from character.communicate import say
    player.setAttr(SNEAKING, False)
    say( player, line )
Esempio n. 3
0
 def testAllCharsPrintable(self):
     cleaned = cleanPlayerInput(self.unprintable) + cleanPlayerInput(self.backspace)
     for each in cleaned:
         assert(each in string.printable)