def format(world, raw_data):
    """Deserialize a player character saved in ShinyFormat and adds it to 
    the world.
    
    raw_data - the data to be deserialized into a player object.
    world - The World instance
    """
    pc = json.loads(_match_shiny_tag('Player', raw_data))
    items = json.loads(_match_shiny_tag('Inv Items', raw_data))
    # Build the area from the assembled dictionary data
    try:
        new_pc = Player(('foo', 'bar'))
        new_pc.playerize(pc)
        new_pc.save()
        # Inventory time!
        containers = {}  # old_container_dbid : [new_containee1, ...]
        old_new = {}  # old dbid's mapped to their new ones

        for item in items:
            my_container = item[0].get('container')
            old_dbid = item[0]['dbid']
            del item[0]['dbid']
            if item[0].get('owner'):
                item[0]['owner'] = new_pc.dbid
            else:
                del item[0]['container']
            i = GameItem(item[0])
            i.save()
            load_item_types(i, item[1])
            old_new[old_dbid] = i.dbid
            if my_container:
                if containers.get(my_container):
                    containers[my_container].append(i)
                else:
                    containers[my_container] = [i]

        for old_container_dbid, containees_list in containers.items():
            for containee in containees_list:
                containee.container = old_new.get(old_container_dbid)
                containee.save()

    except Exception as e:
        # if anything went wrong, make sure we destroy any leftover character
        # data. This way, we won't run into problems if they try to import it
        # again, and we won't leave orphaned or erroneous data in the db.
        world.log.error(traceback.format_exc())
        try:
            new_pc.destruct()
        except:
            # if something goes wrong destroying the pc, it probably means we
            # didn't get far enough to have anything to destroy. Just ignore any
            # errors.
            pass

        raise SportError('There was a horrible error on import! '
                         'Aborting! Check logfile for details.')

    return 'Character "%s" has been successfully imported.' % new_pc.fancy_name(
    )
def format(world, raw_data):
    """Deserialize a player character saved in ShinyFormat and adds it to 
    the world.
    
    raw_data - the data to be deserialized into a player object.
    world - The World instance
    """
    pc = json.loads(_match_shiny_tag('Player', raw_data))
    items = json.loads(_match_shiny_tag('Inv Items', raw_data))
    # Build the area from the assembled dictionary data
    try:
        new_pc = Player(('foo', 'bar'))
        new_pc.playerize(pc)
        new_pc.save()
        # Inventory time!
        containers = {} # old_container_dbid : [new_containee1, ...]
        old_new = {} # old dbid's mapped to their new ones
        
        for item in items:
            my_container = item[0].get('container')
            old_dbid = item[0]['dbid']
            del item[0]['dbid']
            if item[0].get('owner'):
                item[0]['owner'] = new_pc.dbid
            else:
                del item[0]['container']
            i = GameItem(item[0])
            i.save()
            load_item_types(i, item[1])
            old_new[old_dbid] = i.dbid
            if my_container:
                if containers.get(my_container):
                    containers[my_container].append(i)
                else:
                    containers[my_container] = [i]
        
        for old_container_dbid, containees_list in containers.items():
            for containee in containees_list:
                containee.container = old_new.get(old_container_dbid)
                containee.save()
            
    except Exception as e:
        # if anything went wrong, make sure we destroy any leftover character
        # data. This way, we won't run into problems if they try to import it
        # again, and we won't leave orphaned or erroneous data in the db.
        world.log.error(traceback.format_exc())
        try:
            new_pc.destruct()
        except:
            # if something goes wrong destroying the pc, it probably means we
            # didn't get far enough to have anything to destroy. Just ignore any
            # errors.
            pass
        
        raise SportError('There was a horrible error on import! '
                         'Aborting! Check logfile for details.')
    
    return 'Character "%s" has been successfully imported.' % new_pc.fancy_name()
Beispiel #3
0
def create_god(world):
    """Create a god character and save it to this MUD's db."""
    from shinymud.models.player import Player

    save = {'permissions': GOD | PLAYER}
    player = Player(('foo', 'bar'))

    save['name'] = ''
    print "Please choose a name for your character. It should contain \n" +\
          "alphanumeric characters (letters and numbers) ONLY."
    while not save['name']:
        playername = (raw_input("Name: ")).strip()
        if not playername.isalpha():
            print "That is not a valid name. Please choose another."
        else:
            row = player.world.db.select(
                'password,dbid FROM player WHERE name=?', [playername])
            if row:
                print "A player with that name already exists. Please choose Another."
            else:
                print "You're sure you want your name to be '%s'?" % playername
                choice = (raw_input("Yes/No: ")).strip()
                if choice.lower().startswith('y'):
                    save['name'] = playername
                else:
                    print "Ok, we'll start over. Which name do you REALLY want?"

    save['password'] = ''
    while not save['password']:
        passwd1 = (raw_input(CLEAR + "Choose a password: "******"Re-enter password to confirm: " +
                             CONCEAL)).strip()
        if passwd1 == passwd2:
            save['password'] = hashlib.sha1(passwd1).hexdigest()
            print CLEAR
        else:
            print CLEAR + "Your passwords did not match. Please try again."

    save['gender'] = ''
    print "What gender shall your character be?"
    while not save['gender']:
        print "Choose from: neutral, female, or male."
        gender = (raw_input('Gender: ')).strip()
        if len(gender) and gender[0].lower() in ['m', 'f', 'n']:
            save['gender'] = {
                'm': 'male',
                'f': 'female',
                'n': 'neutral'
            }[gender[0].lower()]
        else:
            print "That's not a valid gender."

    player.playerize(save)
    player.save()
    print 'Your character, %s, has been created.' % player.fancy_name()
Beispiel #4
0
def create_god(world):
    """Create a god character and save it to this MUD's db."""
    from shinymud.models.player import Player
    
    save = {'permissions': GOD | PLAYER}
    player = Player(('foo', 'bar'))
    
    save['name'] = ''
    print "Please choose a name for your character. It should contain \n" +\
          "alphanumeric characters (letters and numbers) ONLY."
    while not save['name']:
        playername = (raw_input("Name: ")).strip()
        if not playername.isalpha():
            print "That is not a valid name. Please choose another."
        else:
            row = player.world.db.select('password,dbid FROM player WHERE name=?', [playername])
            if row:
                print "A player with that name already exists. Please choose Another."
            else:
                print "You're sure you want your name to be '%s'?" % playername
                choice = (raw_input("Yes/No: ")).strip()
                if choice.lower().startswith('y'):
                    save['name'] = playername
                else:
                    print "Ok, we'll start over. Which name do you REALLY want?"
    
    save['password'] = ''
    while not save['password']:
        passwd1 = (raw_input(CLEAR + "Choose a password: "******"Re-enter password to confirm: " + CONCEAL)).strip()
        if passwd1 == passwd2:
            save['password'] = hashlib.sha1(passwd1).hexdigest()
            print CLEAR
        else:
            print CLEAR + "Your passwords did not match. Please try again."
    
    save['gender'] = ''
    print "What gender shall your character be?"
    while not save['gender']:
        print "Choose from: neutral, female, or male."
        gender = (raw_input('Gender: ')).strip()
        if len(gender) and gender[0].lower() in ['m', 'f', 'n']:
            save['gender'] = {'m':'male', 'f':'female', 'n':'neutral'}[gender[0].lower()]
        else:
            print "That's not a valid gender."
    
    player.playerize(save)
    player.save()
    print 'Your character, %s, has been created.' % player.fancy_name()