def make_player(item): """Create a character/user/player""" permissions = ev.settings.PERMISSION_PLAYER_DEFAULT typeclass = ev.settings.BASE_PLAYER_TYPECLASS # Create the character. if item["db"] == 1: superuser = True email = ['*****@*****.**'] else: superuser = False # Email is special. email = [ prop['propval'] for prop in item['props'] if prop['propname'] == '@/email'] try: email = email[0] print email is_active = True except: email=None is_active = False player = ev.create_player(item["name"], email, "testpass", typeclass=typeclass, permissions=permissions, is_superuser = superuser) character = ev.create_object(typeclass=settings.BASE_CHARACTER_TYPECLASS, key=item["name"], permissions=permissions) local_tz = pytz.timezone("America/Chicago") utc_dt = datetime.utcfromtimestamp(item["createdtime"]).replace(tzinfo=pytz.utc) player.dbobj.db_date_created = utc_dt character.dbobj.db_date_created = utc_dt player.dbobj.is_active = is_active character.db.spirit = player player.db.avatar = character print character.name + " was born!" permissions_list = { "MAGE" : "PlayerHelpers", "WIZARD" : "Wizards", "ARCHWIZARD" : "Immortals", "BOY" : "Immortals" } for flag in item["flags"]: if flag in permissions_list: # These properties are special. When we assign things to them, they # trigger effects down the line. They're meant to be set and pulled # from, but not modified directly, which is why we don't append to # the property. For more info, see # http://docs.python.org/reference/datamodel.html#object.__setattr__ permission = character.permissions permission.append(permissions_list[flag]) character.permissions = permission # The Player objects should have these permissions, too. permission = player.permissions permission.append(permissions_list[flag]) player.permissions = permission print character.name + " was added to group '" + permissions_list[flag] + "'." if "WIZARD" in item["flags"] or "ARCHWIZARD" in item["flags"] or "BOY" in item["flags"]: character.locks.add('delete:superuser()') player.is_staff = True player.save() if "STAFF" in item["flags"]: player.is_staff = True player.save() repassword_player(player, item["password"]) character.save() player.save()
def func(self): "Execute the command" password = self.args self.caller.msg(echo=False) if not hasattr(self.menutree, 'playername'): self.caller.msg( "{rSomething went wrong! Playername not remembered from previous step!{n" ) self.menutree.goto("node2a") return playername = self.menutree.playername if len(password) < 3: # too short password string = "{rYour password must be at least 3 characters or longer." string += "\n\rFor best security, make it at least 8 characters " string += "long, avoid making it a real word and mix numbers " string += "into it.{n" self.caller.msg(string) self.menutree.goto("node2b") return # everything's ok. Create the new player account. Don't create # a Character here. try: permissions = settings.PERMISSION_PLAYER_DEFAULT typeclass = settings.BASE_PLAYER_TYPECLASS new_player = create_player(playername, None, password, typeclass=typeclass, permissions=permissions) if not new_player: self.msg( "There was an error creating the Player. This error was logged. Contact an admin." ) self.menutree.goto("START") return utils.init_new_player(new_player) # join the new player to the public channel pchanneldef = settings.CHANNEL_PUBLIC if pchanneldef: pchannel = managers.channels.get_channel(pchanneldef[0]) if not pchannel.connect(new_player): string = "New player '%s' could not connect to public channel!" % new_player.key logger.log_errmsg(string) # tell the caller everything went well. string = "{gA new account '%s' was created. Now go log in from the menu!{n" self.caller.msg(string % (playername)) self.menutree.goto("START") except Exception: # We are in the middle between logged in and -not, so we have # to handle tracebacks ourselves at this point. If we don't, we # won't see any errors at all. string = "%s\nThis is a bug. Please e-mail an admin if the problem persists." self.caller.msg(string % (traceback.format_exc())) logger.log_errmsg(traceback.format_exc())
def _register(caller, username, password): # Create the new player account and character here. if not caller: return if not username: return if not password: return try: permissions = settings.PERMISSION_PLAYER_DEFAULT typeclass = settings.BASE_PLAYER_TYPECLASS new_player = create_player(username, None, password, typeclass=typeclass, permissions=permissions) if not new_player: caller.msg("\n在注册中有错误发生,该错误已被记录,请与管理员联系。", type="text") caller.msg(_create_menu(caller)) return utils.init_new_player(new_player) if settings.MULTISESSION_MODE < 2: session = caller default_home = ObjectDB.objects.get_id(settings.DEFAULT_HOME) character_typeclass = settings.BASE_CHARACTER_TYPECLASS start_location = ObjectDB.objects.get_id(settings.START_LOCATION) _create_character(session, new_player, character_typeclass, start_location, default_home, permissions) # join the new player to the public channel pchanneldef = settings.CHANNEL_PUBLIC if pchanneldef: pchannel = managers.channels.get_channel(pchanneldef[0]) if not pchannel.connect(new_player): string = "\n新玩家“%s”无法连接到公共频道!" % new_player.key logger.log_errmsg(string) # tell the caller everything went well. string = "\n{g新账号“%s”已建立,正在登入……{n" % username caller.msg(string) #caller.session_login(player) caller.sessionhandler.login(caller, new_player) except Exception: # We are in the middle between logged in and -not, so we have # to handle tracebacks ourselves at this point. If we don't, we # won't see any errors at all. string = "\n%s\n有错误发生,请与管理员联系。" caller.msg(string % (traceback.format_exc())) logger.log_errmsg(traceback.format_exc()) caller.msg(_create_menu(caller))
def func(self): "Execute the command" password = self.args self.caller.msg(echo=False) if not hasattr(self.menutree, 'playername'): self.caller.msg("{rSomething went wrong! Playername not remembered from previous step!{n") self.menutree.goto("node2a") return playername = self.menutree.playername if len(password) < 3: # too short password string = "{rYour password must be at least 3 characters or longer." string += "\n\rFor best security, make it at least 8 characters " string += "long, avoid making it a real word and mix numbers " string += "into it.{n" self.caller.msg(string) self.menutree.goto("node2b") return # everything's ok. Create the new player account. Don't create # a Character here. try: permissions = settings.PERMISSION_PLAYER_DEFAULT typeclass = settings.BASE_PLAYER_TYPECLASS new_player = create_player(playername, None, password, typeclass=typeclass, permissions=permissions) if not new_player: self.msg("There was an error creating the Player. This error was logged. Contact an admin.") self.menutree.goto("START") return utils.init_new_player(new_player) # join the new player to the public channel pchanneldef = settings.CHANNEL_PUBLIC if pchanneldef: pchannel = managers.channels.get_channel(pchanneldef[0]) if not pchannel.connect(new_player): string = "New player '%s' could not connect to public channel!" % new_player.key logger.log_errmsg(string) # tell the caller everything went well. string = "{gA new account '%s' was created. Now go log in from the menu!{n" self.caller.msg(string % (playername)) self.menutree.goto("START") except Exception: # We are in the middle between logged in and -not, so we have # to handle tracebacks ourselves at this point. If we don't, we # won't see any errors at all. string = "%s\nThis is a bug. Please e-mail an admin if the problem persists." self.caller.msg(string % (traceback.format_exc())) logger.log_errmsg(traceback.format_exc())