def setUp(self): "sets up testing environment" settings.DEFAULT_HOME = "#2" #print "creating player %i: %s" % (self.CID, self.__class__.__name__) self.player = create.create_player("TestPlayer%i" % self.CID, "*****@*****.**", "testpassword", typeclass=TestPlayerClass) self.player2 = create.create_player("TestPlayer%ib" % self.CID, "*****@*****.**", "testpassword", typeclass=TestPlayerClass) self.room1 = create.create_object("src.objects.objects.Room", key="Room%i"%self.CID, nohome=True) self.room1.db.desc = "room_desc" self.room2 = create.create_object("src.objects.objects.Room", key="Room%ib" % self.CID) self.obj1 = create.create_object(TestObjectClass, key="Obj%i" % self.CID, location=self.room1, home=self.room1) self.obj2 = create.create_object(TestObjectClass, key="Obj%ib" % self.CID, location=self.room1, home=self.room1) self.char1 = create.create_object(TestCharacterClass, key="Char%i" % self.CID, location=self.room1, home=self.room1) self.char1.permissions.add("Immortals") self.char2 = create.create_object(TestCharacterClass, key="Char%ib" % self.CID, location=self.room1, home=self.room1) self.char1.player = self.player self.char2.player = self.player2 self.script = create.create_script("src.scripts.scripts.Script", key="Script%i" % self.CID) self.player.permissions.add("Immortals") # set up a fake session global SESSIONS session = ServerSession() session.init_session("telnet", ("localhost", "testmode"), SESSIONS) session.sessid = self.CID SESSIONS.portal_connect(session.get_sync_data()) SESSIONS.login(SESSIONS.session_from_sessid(self.CID), self.player, testmode=True)
def setUp(self): "sets up testing environment" settings.DEFAULT_HOME = "#2" # print "creating player %i: %s" % (self.CID, self.__class__.__name__) self.player = create.create_player( "TestPlayer%i" % self.CID, "*****@*****.**", "testpassword", typeclass=TestPlayerClass ) self.player2 = create.create_player( "TestPlayer%ib" % self.CID, "*****@*****.**", "testpassword", typeclass=TestPlayerClass ) self.room1 = create.create_object("src.objects.objects.Room", key="Room%i" % self.CID, nohome=True) self.room1.db.desc = "room_desc" self.room2 = create.create_object("src.objects.objects.Room", key="Room%ib" % self.CID) self.obj1 = create.create_object(TestObjectClass, key="Obj%i" % self.CID, location=self.room1, home=self.room1) self.obj2 = create.create_object(TestObjectClass, key="Obj%ib" % self.CID, location=self.room1, home=self.room1) self.char1 = create.create_object( TestCharacterClass, key="Char%i" % self.CID, location=self.room1, home=self.room1 ) self.char1.permissions.add("Immortals") self.char2 = create.create_object( TestCharacterClass, key="Char%ib" % self.CID, location=self.room1, home=self.room1 ) self.char1.player = self.player self.char2.player = self.player2 self.script = create.create_script("src.scripts.scripts.Script", key="Script%i" % self.CID) self.player.permissions.add("Immortals") # set up a fake session global SESSIONS session = ServerSession() session.init_session("telnet", ("localhost", "testmode"), SESSIONS) session.sessid = self.CID SESSIONS.portal_connect(session.get_sync_data()) SESSIONS.login(SESSIONS.session_from_sessid(self.CID), self.player, testmode=True)
def save_formset(self, request, form, formset, change): "Run all hooks on the player object" super(UserAdmin, self).save_formset(request, form, formset, change) playerdb = form.instance.get_profile() if not change: create.create_player("", "", "", typeclass=playerdb.db_typeclass_path, create_character=False, player_dbobj=playerdb) if playerdb.db_obj: playerdb.db_obj.db_player = playerdb playerdb.db_obj.save()
def save_formset(self, request, form, formset, change): "Run all hooks on the player object" super(PlayerDBAdmin, self).save_formset(request, form, formset, change) userobj = form.instance userobj.name = userobj.username if not change: #uname, passwd, email = str(request.POST.get(u"username")), \ # str(request.POST.get(u"password1")), str(request.POST.get(u"email")) typeclass = str(request.POST.get(u"playerdb_set-0-db_typeclass_path")) create.create_player("", "", "", user=userobj, typeclass=typeclass, player_dbobj=userobj)
def setUp(self): "sets up testing environment" self.room1 = create.create_object("src.objects.objects.Room", key="Room%i"%self.CID) self.room1.db.desc = "room_desc" self.room2 = create.create_object("src.objects.objects.Room", key="Room%ib" % self.CID) self.obj1 = create.create_object("src.objects.objects.Object", key="Obj%i" % self.CID, location=self.room1, home=self.room1) self.obj2 = create.create_object("src.objects.objects.Object", key="Obj%ib" % self.CID, location=self.room1, home=self.room1) self.char1 = create.create_object("src.objects.objects.Character", key="Char%i" % self.CID, location=self.room1, home=self.room1) self.char2 = create.create_object("src.objects.objects.Character", key="Char%ib" % self.CID, location=self.room1, home=self.room1) self.script = create.create_script("src.scripts.scripts.Script", key="Script%i" % self.CID) self.player = create.create_player("TestPlayer%i" % self.CID, "*****@*****.**", "testpassword", typeclass=TestPlayerClass) self.player2 = create.create_player("TestPlayer%ib" % self.CID, "*****@*****.**", "testpassword", typeclass=TestPlayerClass) self.player.permissions = "Immortals" self.char1.player = self.player self.char1.sessid = 1
def save_formset(self, request, form, formset, change): "Run all hooks on the player object" super(PlayerDBAdmin, self).save_formset(request, form, formset, change) userobj = form.instance userobj.name = userobj.username if not change: #uname, passwd, email = str(request.POST.get(u"username")), \ # str(request.POST.get(u"password1")), str(request.POST.get(u"email")) typeclass = str( request.POST.get(u"playerdb_set-0-db_typeclass_path")) create.create_player("", "", "", user=userobj, typeclass=typeclass, player_dbobj=userobj)
def setUp(self): "sets up testing environment" self.room1 = create.create_object("src.objects.objects.Room", key="Room%i"%self.CID) self.room1.db.desc = "room_desc" self.room2 = create.create_object("src.objects.objects.Room", key="Room%ib"%self.CID) self.obj1 = create.create_object("src.objects.objects.Object", key="Obj%i"%self.CID, location=self.room1, home=self.room1) self.obj2 = create.create_object("src.objects.objects.Object", key="Obj%ib"%self.CID, location=self.room1, home=self.room1) self.player = create.create_player("TestPlayer%i"%self.CID, "*****@*****.**", "testpassword", typeclass=TestPlayer, create_character=False) self.caller = create.create_player("Caller%i"%self.CID, "*****@*****.**", "testpassword", player_dbobj=self.player.dbobj, character_typeclass="src.objects.objects.Character", permissions=["Immortals"], character_home=self.room1, character_location=self.room1) self.caller.player = self.player self.char = create.create_player("Char%i"%self.CID, "*****@*****.**", "testpassword2", typeclass=TestPlayer, character_typeclass="src.objects.objects.Character", permissions=["Immortals"], character_home=self.room1, character_location=self.room1) self.char = create.create_script("src.scripts.scripts.Script", key="Script%i"%self.CID)
def create_objects(): """ Creates the #1 player and Limbo room. """ print " Creating objects (Player #1 and Limbo room) ..." # Set the initial User's account object's username on the #1 object. # This object is pure django and only holds name, email and password. god_user = get_god_user() # Create a Player 'user profile' object to hold eventual # mud-specific settings for the bog standard User object. This is # accessed by user.get_profile() and can also store attributes. # It also holds mud permissions, but for a superuser these # have no effect anyhow. character_typeclass = settings.BASE_CHARACTER_TYPECLASS # Create the Player object as well as the in-game god-character # for user #1. We can't set location and home yet since nothing # exists. Also, all properties (name, email, password, is_superuser) # is inherited from the user so we don't specify it again here. god_player = create.create_player(god_user.username, None, None, user=god_user) god_character = create.create_object(character_typeclass, key=god_user.username) god_character.id = 1 god_character.db.desc = _('This is User #1.') god_character.locks.add("examine:perm(Immortals);edit:false();delete:false();boot:false();msg:all();puppet:false()") god_character.permissions = "Immortals" god_character.save() god_player.set_attribute("_first_login", True) god_player.set_attribute("_last_puppet", god_character) god_player.db._playable_characters.append(god_character) # Limbo is the default "nowhere" starting room room_typeclass = settings.BASE_ROOM_TYPECLASS limbo_obj = create.create_object(room_typeclass, _('Limbo')) limbo_obj.id = 2 string = " ".join([ "Welcome to your new {wEvennia{n-based game. From here you are ready to begin development.", "Visit http://evennia.com if you should need help or would like to participate in community discussions.", "If you are logged in as User #1 you can create a demo/tutorial area with '@batchcommand contrib.tutorial_world.build'.", "Log out and create a new non-admin account at the login screen to play the tutorial properly."]) string = _(string) limbo_obj.db.desc = string limbo_obj.save() # Now that Limbo exists, try to set the user up in Limbo (unless # the creation hooks already fixed this). if not god_character.location: god_character.location = limbo_obj if not god_character.home: god_character.home = limbo_obj
def new_player(name, email, password, context): """ Easier front-end for creating a new player. Also sends reg email. """ character = create_player(name=name, email=email, password=password, permissions=settings.PERMISSION_PLAYER_DEFAULT, typeclass=settings.BASE_PLAYER_TYPECLASS, character_home=settings.CHARACTER_DEFAULT_HOME) character.player.user.is_active = False character.player.user.save() send_activation_email(character, context)
def _create_player(session, playername, password, default_home, permissions, typeclass=None): """ Helper function, creates a player of the specified typeclass. """ try: new_player = create.create_player(playername, None, password, permissions=permissions, typeclass=typeclass) except Exception, e: session.msg("There was an error creating the Player:\n%s\n If this problem persists, contact an admin." % e) logger.log_trace() return False
def new_player(name, email, password, request): """ Easier front-end for creating a new player. Also sends reg email. """ player = create_player(key=name, email=email, password=password, permissions=settings.PERMISSION_PLAYER_DEFAULT, typeclass=settings.BASE_PLAYER_TYPECLASS) player.is_active = False player.save() character = create_object(typeclass=settings.BASE_CHARACTER_TYPECLASS, key=name, permissions=settings.PERMISSION_PLAYER_DEFAULT, home=settings.CHARACTER_DEFAULT_HOME) character.db.spirit = player player.db.avatar = character player.db._last_puppet = character player.db._playable_characters = [ character ] character.locks.add("puppet:id(%i) or pid(%i) or perm(Immortals) or pperm(Immortals)" % (character.id, player.id)) character.new_character() send_activation_email(player, request)
def new_player(name, email, password, request): """ Easier front-end for creating a new player. Also sends reg email. """ player = create_player(name=name, email=email, password=password, permissions=settings.PERMISSION_PLAYER_DEFAULT, typeclass=settings.BASE_PLAYER_TYPECLASS) player.user.is_active = False player.user.save() character = create_object(typeclass=settings.BASE_CHARACTER_TYPECLASS, key=name, permissions=settings.PERMISSION_PLAYER_DEFAULT, home=settings.CHARACTER_DEFAULT_HOME) character.db.spirit = player player.db.avatar = character player.db._last_puppet = character player.db._playable_characters = [character] character.locks.add( "puppet:id(%i) or pid(%i) or perm(Immortals) or pperm(Immortals)" % (character.id, player.id)) character.new_character() send_activation_email(player, request)
def func(self): "Setup the rss-channel mapping" # checking we have all we need if not settings.RSS_ENABLED: string = """RSS is not enabled. You need to activate it in game/settings.py.""" self.msg(string) return try: import feedparser feedparser # to avoid checker error of not being used except ImportError: string = ( "RSS requires python-feedparser (https://pypi.python.org/pypi/feedparser). " "Install before continuing.") self.msg(string) return if 'list' in self.switches: # show all connections rssbots = [ bot.typeclass for bot in PlayerDB.objects.filter( db_is_bot=True, username__startswith="rssbot-") ] if rssbots: from src.utils.evtable import EvTable table = EvTable("{wdbid{n", "{wupdate rate{n", "{wev-channel", "{wRSS feed URL{n", border="cells", maxwidth=78) for rssbot in rssbots: table.add_row(rssbot.id, rssbot.db.rss_rate, rssbot.db.ev_channel, rssbot.db.rss_url) self.caller.msg(table) else: self.msg("No rss bots found.") return if ('disconnect' in self.switches or 'remove' in self.switches or 'delete' in self.switches): botname = "rssbot-%s" % self.lhs matches = PlayerDB.objects.filter(db_is_bot=True, db_key=botname) if not matches: # try dbref match matches = PlayerDB.objects.filter(db_is_bot=True, id=self.args.lstrip("#")) if matches: matches[0].delete() self.msg("RSS connection destroyed.") else: self.msg( "RSS connection/bot could not be removed, does it exist?") return if not self.args or not self.rhs: string = "Usage: @rss2chan[/switches] <evennia_channel> = <rss url>" self.msg(string) return channel = self.lhs url = self.rhs botname = "rssbot-%s" % url # create a new bot bot = PlayerDB.objects.filter(username__iexact=botname) if bot: # re-use existing bot bot = bot[0].typeclass if not bot.is_bot: self.msg("Player '%s' already exists and is not a bot." % botname) return else: bot = create.create_player(botname, None, None, typeclass=bots.RSSBot) bot.start(ev_channel=channel, rss_url=url, rss_rate=10) self.msg("RSS reporter created. Fetching RSS.")
def func(self): "Setup the irc-channel mapping" if not settings.IRC_ENABLED: string = """IRC is not enabled. You need to activate it in game/settings.py.""" self.msg(string) return if 'list' in self.switches: # show all connections ircbots = [ bot.typeclass for bot in PlayerDB.objects.filter( db_is_bot=True, username__startswith="ircbot-") ] if ircbots: from src.utils.evtable import EvTable table = EvTable("{wdbid{n", "{wbotname{n", "{wev-channel{n", "{wirc-channel{n", maxwidth=78) for ircbot in ircbots: ircinfo = "%s (%s:%s)" % (ircbot.db.irc_channel, ircbot.db.irc_network, ircbot.db.irc_port) table.add_row(ircbot.id, ircbot.db.irc_botname, ircbot.db.ev_channel, ircinfo) self.caller.msg(table) else: self.msg("No irc bots found.") return if ('disconnect' in self.switches or 'remove' in self.switches or 'delete' in self.switches): botname = "ircbot-%s" % self.lhs matches = PlayerDB.objects.filter(db_is_bot=True, username=botname) dbref = utils.dbref(self.lhs) if not matches and dbref: # try dbref match matches = PlayerDB.objects.filter(db_is_bot=True, id=dbref) if matches: matches[0].delete() self.msg("IRC connection destroyed.") else: self.msg( "IRC connection/bot could not be removed, does it exist?") return if not self.args or not self.rhs: string = "Usage: @irc2chan[/switches] <evennia_channel> = <ircnetwork> <port> <#irchannel> <botname>" self.msg(string) return channel = self.lhs self.rhs = self.rhs.replace('#', ' ') # to avoid Python comment issues try: irc_network, irc_port, irc_channel, irc_botname = \ [part.strip() for part in self.rhs.split(None, 3)] irc_channel = "#%s" % irc_channel except Exception: string = "IRC bot definition '%s' is not valid." % self.rhs self.msg(string) return botname = "ircbot-%s" % irc_botname # create a new bot bot = PlayerDB.objects.filter(username__iexact=botname) if bot: # re-use an existing bot bot = bot[0].typeclass if not bot.is_bot: self.msg("Player '%s' already exists and is not a bot." % botname) return else: bot = create.create_player(botname, None, None, typeclass=bots.IRCBot) bot.start(ev_channel=channel, irc_botname=irc_botname, irc_channel=irc_channel, irc_network=irc_network, irc_port=irc_port) self.msg("Connection created. Starting IRC bot.")
def func(self): "Do checks and create account" session = self.caller args = self.args.strip() # extract quoted parts parts = [part.strip() for part in re.split(r"\"|\'", args) if part.strip()] if len(parts) == 1: # this was (hopefully) due to no quotes being found parts = parts[0].split(None, 1) if len(parts) != 2: string = "\n Usage (without <>): create <name> <password>" string += "\nIf <name> or <password> contains spaces, enclose it in quotes." session.msg(string) return playername, password = parts print "playername '%s', password: '******'" % (playername, password) # sanity checks if not re.findall('^[\w. @+-]+$', playername) or not (0 < len(playername) <= 30): # this echoes the restrictions made by django's auth module (except not # allowing spaces, for convenience of logging in). string = "\n\r Playername can max be 30 characters or fewer. Letters, spaces, digits and @/./+/-/_ only." session.msg(string) return # strip excessive spaces in playername playername = re.sub(r"\s+", " ", playername).strip() if PlayerDB.objects.filter(user__username__iexact=playername) or PlayerDB.objects.filter(username__iexact=playername): # player already exists (we also ignore capitalization here) session.msg("Sorry, there is already a player with the name '%s'." % playername) return if not re.findall('^[\w. @+-]+$', password) or not (3 < len(password)): string = "\n\r Password should be longer than 3 characers. Letters, spaces, digits and @\.\+\-\_ only." string += "\nFor best security, make it longer than 8 characters. You can also use a phrase of" string += "\nmany words if you enclose the password in quotes." session.msg(string) return # everything's ok. Create the new player account. try: default_home = ObjectDB.objects.get_id(settings.CHARACTER_DEFAULT_HOME) typeclass = settings.BASE_CHARACTER_TYPECLASS permissions = settings.PERMISSION_PLAYER_DEFAULT try: new_character = create.create_player(playername, None, password, permissions=permissions, character_typeclass=typeclass, character_location=default_home, character_home=default_home) except Exception: session.msg("There was an error creating the default Character/Player:\n%s\n If this problem persists, contact an admin.") return new_player = new_character.player # This needs to be called so the engine knows this player is logging in for the first time. # (so it knows to call the right hooks during login later) utils.init_new_player(new_player) # join the new player to the public channel pchanneldef = settings.CHANNEL_PUBLIC if pchanneldef: pchannel = Channel.objects.get_channel(pchanneldef[0]) if not pchannel.connect_to(new_player): string = "New player '%s' could not connect to public channel!" % new_player.key logger.log_errmsg(string) # allow only the character itself and the player to puppet this character (and Immortals). new_character.locks.add("puppet:id(%i) or pid(%i) or perm(Immortals) or pperm(Immortals)" % (new_character.id, new_player.id)) # If no description is set, set a default description if not new_character.db.desc: new_character.db.desc = "This is a Player." # tell the caller everything went well. string = "A new account '%s' was created. Welcome!" if " " in playername: string += "\n\nYou can now log in with the command 'connect \"%s\" <your password>'." else: string += "\n\nYou can now log with the command 'connect %s <your password>'." session.msg(string % (playername, playername)) 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." session.msg(string % (traceback.format_exc())) logger.log_errmsg(traceback.format_exc())
def func(self): "Do checks and create account" session = self.caller args = self.args.strip() # extract quoted parts parts = [part.strip() for part in re.split(r"\"|\'", args) if part.strip()] if len(parts) == 1: # this was (hopefully) due to no quotes being found parts = parts[0].split(None, 1) if len(parts) != 2: string = "\n Usage (without <>): create <name> <password>" string += "\nIf <name> or <password> contains spaces, enclose it in quotes." session.msg(string) return playername, password = parts # sanity checks if not re.findall('^[\w. @+-]+$', playername) or not (0 < len(playername) <= 30): # this echoes the restrictions made by django's auth # module (except not allowing spaces, for convenience of # logging in). string = "\n\r Playername can max be 30 characters or fewer. Letters, spaces, digits and @/./+/-/_ only." session.msg(string) return # strip excessive spaces in playername playername = re.sub(r"\s+", " ", playername).strip() if PlayerDB.objects.filter(username__iexact=playername): # player already exists (we also ignore capitalization here) session.msg("Sorry, there is already a player with the name '%s'." % playername) return if not re.findall('^[\w. @+-]+$', password) or not (3 < len(password)): string = "\n\r Password should be longer than 3 characers. Letters, spaces, digits and @\.\+\-\_ only." string += "\nFor best security, make it longer than 8 characters. You can also use a phrase of" string += "\nmany words if you enclose the password in quotes." session.msg(string) return # everything's ok. Create the new player account. try: default_home = ObjectDB.objects.get_id(settings.DEFAULT_HOME) typeclass = settings.BASE_CHARACTER_TYPECLASS permissions = settings.PERMISSION_PLAYER_DEFAULT try: new_player = create.create_player(playername, None, password, permissions=permissions) except Exception, e: session.msg("There was an error creating the default Player/Character:\n%s\n If this problem persists, contact an admin." % e) logger.log_trace() return # This needs to be called so the engine knows this player is # logging in for the first time. (so it knows to call the right # hooks during login later) utils.init_new_player(new_player) # join the new player to the public channel pchanneldef = settings.CHANNEL_PUBLIC if pchanneldef: pchannel = ChannelDB.objects.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) if MULTISESSION_MODE < 2: # if we only allow one character, create one with the same name as Player # (in mode 2, the character must be created manually once logging in) start_location = ObjectDB.objects.get_id(settings.START_LOCATION) if not start_location: start_location = default_home # fallback new_character = create.create_object(typeclass, key=playername, location=start_location, home=default_home, permissions=permissions) # set playable character list new_player.db._playable_characters.append(new_character) # allow only the character itself and the player to puppet this character (and Immortals). new_character.locks.add("puppet:id(%i) or pid(%i) or perm(Immortals) or pperm(Immortals)" % (new_character.id, new_player.id)) # If no description is set, set a default description if not new_character.db.desc: new_character.db.desc = "This is a Player." # We need to set this to have @ic auto-connect to this character new_player.db._last_puppet = new_character # tell the caller everything went well. string = "A new account '%s' was created. Welcome!" if " " in playername: string += "\n\nYou can now log in with the command 'connect \"%s\" <your password>'." else: string += "\n\nYou can now log with the command 'connect %s <your password>'." session.msg(string % (playername, playername))
def func(self): "Do checks and create account" session = self.caller args = self.args.strip() # extract quoted parts parts = [part.strip() for part in re.split(r"\"|\'", args) if part.strip()] if len(parts) == 1: # this was (hopefully) due to no quotes being found parts = parts[0].split(None, 1) if len(parts) != 2: string = "\n Usage (without <>): create <name> <password>" string += "\nIf <name> or <password> contains spaces, enclose it in quotes." session.msg(string) return playername, password = parts # sanity checks if not re.findall('^[\w. @+-]+$', playername) or not (0 < len(playername) <= 30): # this echoes the restrictions made by django's auth # module (except not allowing spaces, for convenience of # logging in). string = "\n\r Playername can max be 30 characters or fewer. Letters, spaces, digits and @/./+/-/_ only." session.msg(string) return # strip excessive spaces in playername playername = re.sub(r"\s+", " ", playername).strip() if PlayerDB.objects.filter(username__iexact=playername): # player already exists (we also ignore capitalization here) session.msg("Sorry, there is already a player with the name '%s'." % playername) return if not re.findall('^[\w. @+-]+$', password) or not (3 < len(password)): string = "\n\r Password should be longer than 3 characers. Letters, spaces, digits and @\.\+\-\_ only." string += "\nFor best security, make it longer than 8 characters. You can also use a phrase of" string += "\nmany words if you enclose the password in quotes." session.msg(string) return # everything's ok. Create the new player account. try: default_home = ObjectDB.objects.get_id(settings.DEFAULT_HOME) typeclass = settings.BASE_CHARACTER_TYPECLASS permissions = settings.PERMISSION_PLAYER_DEFAULT try: new_player = create.create_player(playername, None, password, permissions=permissions) except Exception, e: session.msg("There was an error creating the default Player/Character:\n%s\n If this problem persists, contact an admin." % e) logger.log_trace() return # This needs to be called so the engine knows this player is # logging in for the first time. (so it knows to call the right # hooks during login later) utils.init_new_player(new_player) # join the new player to the public channel pchanneldef = settings.CHANNEL_PUBLIC if pchanneldef: pchannel = ChannelDB.objects.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) if MULTISESSION_MODE < 2: # if we only allow one character, create one with the same name as Player # (in mode 2, the character must be created manually once logging in) start_location = settings.START_LOCATION new_character = create.create_object(typeclass, key=playername, location=start_location, home=default_home, permissions=permissions) # set playable character list new_player.db._playable_characters.append(new_character) # allow only the character itself and the player to puppet this character (and Immortals). new_character.locks.add("puppet:id(%i) or pid(%i) or perm(Immortals) or pperm(Immortals)" % (new_character.id, new_player.id)) # If no description is set, set a default description if not new_character.db.desc: new_character.db.desc = "This is a Player." # We need to set this to have @ic auto-connect to this character new_player.db._last_puppet = new_character # tell the caller everything went well. string = "A new account '%s' was created. Welcome!" if " " in playername: string += "\n\nYou can now log in with the command 'connect \"%s\" <your password>'." else: string += "\n\nYou can now log with the command 'connect %s <your password>'." session.msg(string % (playername, playername))
def func(self): "Do checks and create account" session = self.caller try: playername, email, password = self.playerinfo except ValueError: string = "\n\r Usage (without <>): create \"<playername>\" <email> <password>" session.msg(string) return if not re.findall('^[\w. @+-]+$', playername) or not (0 < len(playername) <= 30): session.msg("\n\r Playername can max be 30 characters or fewer. Letters, spaces, dig\ its and @/./+/-/_ only.") # this echoes the restrictions made by django's auth module. return if not email or not password: session.msg("\n\r You have to supply an e-mail address followed by a password." ) return if not utils.validate_email_address(email): # check so the email at least looks ok. session.msg("'%s' is not a valid e-mail address." % email) return # Run sanity and security checks if PlayerDB.objects.get_player_from_name(playername) or User.objects.filter(username=playername): # player already exists session.msg("Sorry, there is already a player with the name '%s'." % playername) return if PlayerDB.objects.get_player_from_email(email): # email already set on a player session.msg("Sorry, there is already a player with that email address.") return if len(password) < 3: # too short password string = "Your password must be at least 3 characters or longer." string += "\n\rFor best security, make it at least 8 characters long, " string += "avoid making it a real word and mix numbers into it." session.msg(string) return # everything's ok. Create the new player account. try: default_home = ObjectDB.objects.get_id(settings.CHARACTER_DEFAULT_HOME) typeclass = settings.BASE_CHARACTER_TYPECLASS permissions = settings.PERMISSION_PLAYER_DEFAULT try: new_character = create.create_player(playername, email, password, permissions=permissions, character_typeclass=typeclass, character_location=default_home, character_home=default_home) except Exception: session.msg("There was an error creating the default Character/Player:\n%s\n If this problem persists, contact an admin.") return new_player = new_character.player # This needs to be called so the engine knows this player is # logging in for the first time. # (so it knows to call the right hooks during login later) utils.init_new_player(new_player) # join the new player to the public channel pchanneldef = settings.CHANNEL_PUBLIC if pchanneldef: pchannel = ChannelDB.objects.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) # allow only the character itself and the player to puppet # this character (and Immortals). new_character.locks.add("puppet:id(%i) or pid(%i) or perm(Immortals) or pperm(Immortals)" % (new_character.id, new_player.id)) # set a default description new_character.db.desc = "This is a Player." # tell the caller everything went well. string = "A new account '%s' was created with the email address %s. Welcome!" string += "\n\nYou can now log with the command 'connect %s <your password>'." session.msg(string % (playername, email, email)) 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." session.msg(string % (traceback.format_exc())) logger.log_errmsg(traceback.format_exc())
def func(self): "Do checks and create account" session = self.caller args = self.args.strip() # extract quoted parts parts = [ part.strip() for part in re.split(r"\"|\'", args) if part.strip() ] if len(parts) == 1: # this was (hopefully) due to no quotes being found parts = parts[0].split(None, 1) if len(parts) != 2: string = "\n Usage (without <>): create <name> <password>" string += "\nIf <name> or <password> contains spaces, enclose it in quotes." session.msg(string) return playername, password = parts print "playername '%s', password: '******'" % (playername, password) # sanity checks if not re.findall('^[\w. @+-]+$', playername) or not (0 < len(playername) <= 30): # this echoes the restrictions made by django's auth module (except not # allowing spaces, for convenience of logging in). string = "\n\r Playername can max be 30 characters or fewer. Letters, spaces, digits and @/./+/-/_ only." session.msg(string) return # strip excessive spaces in playername playername = re.sub(r"\s+", " ", playername).strip() if PlayerDB.objects.filter( user__username__iexact=playername) or User.objects.filter( username__iexact=playername): # player already exists (we also ignore capitalization here) session.msg( "Sorry, there is already a player with the name '%s'." % playername) return if not re.findall('^[\w. @+-]+$', password) or not (3 < len(password)): string = "\n\r Password should be longer than 3 characers. Letters, spaces, digits and @\.\+\-\_ only." string += "\nFor best security, make it longer than 8 characters. You can also use a phrase of" string += "\nmany words if you enclose the password in quotes." session.msg(string) return # everything's ok. Create the new player account. try: default_home = ObjectDB.objects.get_id( settings.CHARACTER_DEFAULT_HOME) typeclass = settings.BASE_CHARACTER_TYPECLASS permissions = settings.PERMISSION_PLAYER_DEFAULT try: new_character = create.create_player( playername, None, password, permissions=permissions, character_typeclass=typeclass, character_location=default_home, character_home=default_home) except Exception: session.msg( "There was an error creating the default Character/Player:\n%s\n If this problem persists, contact an admin." ) return new_player = new_character.player # This needs to be called so the engine knows this player is logging in for the first time. # (so it knows to call the right hooks during login later) utils.init_new_player(new_player) # join the new player to the public channel pchanneldef = settings.CHANNEL_PUBLIC if pchanneldef: pchannel = Channel.objects.get_channel(pchanneldef[0]) if not pchannel.connect_to(new_player): string = "New player '%s' could not connect to public channel!" % new_player.key logger.log_errmsg(string) # allow only the character itself and the player to puppet this character (and Immortals). new_character.locks.add( "puppet:id(%i) or pid(%i) or perm(Immortals) or pperm(Immortals)" % (new_character.id, new_player.id)) # If no description is set, set a default description if not new_character.db.desc: new_character.db.desc = "This is a Player." # tell the caller everything went well. string = "A new account '%s' was created. Welcome!" if " " in playername: string += "\n\nYou can now log in with the command 'connect \"%s\" <your password>'." else: string += "\n\nYou can now log with the command 'connect %s <your password>'." session.msg(string % (playername, playername)) 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." session.msg(string % (traceback.format_exc())) logger.log_errmsg(traceback.format_exc())
def func(self): "Do checks and create account" session = self.caller args = self.args.strip() # extract quoted parts parts = [part.strip() for part in re.split(r"\"|\'", args) if part.strip()] if len(parts) == 1: # this was (hopefully) due to no quotes being found parts = parts[0].split(None, 1) if len(parts) != 2: string = "\n Usage (without <>): create <name> <password>" string += "\nIf <name> or <password> contains spaces, enclose it in quotes." session.msg(string) return playername, password = parts # Drop the player name to lowercase playername = playername.lower() # sanity checks if re.search('[^a-zA-Z0-9._-]', playername) or not (3 <= len(playername) <= 20): session.msg('{RPlayer names must be between 3 and 20 characters, and only contain english letters, numbers, dot (.), underscore (_), or dash(-)') return # Verify this player doesn't already exist if PlayerDB.objects.filter(user__username__iexact=playername) or User.objects.filter(username__iexact=playername): # player already exists (we also ignore capitalization here) session.msg("Sorry, there is already a player with the name '%s'." % playername) return # Verify that this player name does not match an existing character name for existing_object in search_object(playername, attribute_name='key'): if utils.inherits_from(existing_object, "src.objects.objects.Character"): session.msg("Sorry, there is already a character with the name '%s'." % playername) return # Security check the password if not re.findall('^[\w. @+-]+$', password) or not (3 < len(password)): string = "\n\r Password should be longer than 3 characers. Letters, spaces, digits and @\.\+\-\_ only." string += "\nFor best security, make it longer than 8 characters. You can also use a phrase of" string += "\nmany words if you enclose the password in quotes." session.msg(string) return # everything's ok. Create the new player account. try: default_home = ObjectDB.objects.get_id(settings.CHARACTER_DEFAULT_HOME) typeclass = settings.BASE_CHARACTER_TYPECLASS permissions = settings.PERMISSION_PLAYER_DEFAULT try: new_player = create.create_player(playername, None, password, permissions=permissions) except Exception, e: session.msg("There was an error creating the default Player/Character:\n%s\n If this problem persists, contact an admin." % e) return # This needs to be called so the engine knows this player is logging in for the first time. # (so it knows to call the right hooks during login later) utils.init_new_player(new_player) # join the new player to the public channel pchanneldef = settings.CHANNEL_PUBLIC if pchanneldef: pchannel = Channel.objects.get_channel(pchanneldef[0]) if not pchannel.connect_to(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 = "A new account '%s' was created. Welcome!" if " " in playername: string += "\n\nYou can now log in with the command 'connect \"%s\" <your password>'." else: string += "\n\nYou can now log with the command 'connect %s <your password>'." session.msg(string % (playername, playername))
def func(self): "Do checks and create account" session = self.caller try: playername, email, password = self.playerinfo except ValueError: string = "\n\r Usage (without <>): create \"<playername>\" <email> <password>" session.msg(string) return if not re.findall('^[\w. @+-]+$', playername) or not (0 < len(playername) <= 30): session.msg( "\n\r Playername can max be 30 characters or fewer. Letters, spaces, dig\ its and @/./+/-/_ only." ) # this echoes the restrictions made by django's auth module. return if not email or not password: session.msg( "\n\r You have to supply an e-mail address followed by a password." ) return if not utils.validate_email_address(email): # check so the email at least looks ok. session.msg("'%s' is not a valid e-mail address." % email) return # Run sanity and security checks if PlayerDB.objects.filter(username=playername): # player already exists session.msg( "Sorry, there is already a player with the name '%s'." % playername) return if PlayerDB.objects.get_player_from_email(email): # email already set on a player session.msg( "Sorry, there is already a player with that email address.") return if len(password) < 3: # too short password string = "Your password must be at least 3 characters or longer." string += "\n\rFor best security, make it at least 8 characters long, " string += "avoid making it a real word and mix numbers into it." session.msg(string) return # everything's ok. Create the new player account. try: default_home = ObjectDB.objects.get_id(settings.DEFAULT_HOME) typeclass = settings.BASE_CHARACTER_TYPECLASS permissions = settings.PERMISSION_PLAYER_DEFAULT try: new_player = create.create_player(playername, email, password, permissions=permissions) except Exception, e: session.msg( "There was an error creating the default Player/Character:\n%s\n If this problem persists, contact an admin." % e) logger.log_trace() return # This needs to be called so the engine knows this player is # logging in for the first time. (so it knows to call the right # hooks during login later) utils.init_new_player(new_player) # join the new player to the public channel pchanneldef = settings.CHANNEL_PUBLIC if pchanneldef: pchannel = ChannelDB.objects.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) if MULTISESSION_MODE < 2: # if we only allow one character, create one with the same name as Player # (in mode 2, the character must be created manually once logging in) new_character = create.create_object(typeclass, key=playername, location=default_home, home=default_home, permissions=permissions) # set playable character list new_player.db._playable_characters.append(new_character) # allow only the character itself and the player to puppet this character (and Immortals). new_character.locks.add( "puppet:id(%i) or pid(%i) or perm(Immortals) or pperm(Immortals)" % (new_character.id, new_player.id)) # If no description is set, set a default description if not new_character.db.desc: new_character.db.desc = "This is a Player." # We need to set this to have @ic auto-connect to this character new_player.db._last_puppet = new_character # tell the caller everything went well. string = "A new account '%s' was created. Welcome!" if " " in playername: string += "\n\nYou can now log in with the command 'connect %s <your password>'." else: string += "\n\nYou can now log with the command 'connect %s <your password>'." session.msg(string % (playername, email))
def func(self): "Setup the irc-channel mapping" if not settings.IRC_ENABLED: string = """IRC is not enabled. You need to activate it in game/settings.py.""" self.msg(string) return if 'list' in self.switches: # show all connections ircbots = [bot.typeclass for bot in PlayerDB.objects.filter(db_is_bot=True, username__startswith="ircbot-")] if ircbots: from src.utils.evtable import EvTable table = EvTable("{wdbid{n", "{wbotname{n", "{wev-channel{n", "{wirc-channel{n", maxwidth=78) for ircbot in ircbots: ircinfo = "%s (%s:%s)" % (ircbot.db.irc_channel, ircbot.db.irc_network, ircbot.db.irc_port) table.add_row(ircbot.id, ircbot.db.irc_botname, ircbot.db.ev_channel, ircinfo) self.caller.msg(table) else: self.msg("No irc bots found.") return if('disconnect' in self.switches or 'remove' in self.switches or 'delete' in self.switches): botname = "ircbot-%s" % self.lhs matches = PlayerDB.objects.filter(db_is_bot=True, db_key=botname) if not matches: # try dbref match matches = PlayerDB.objects.filter(db_is_bot=True, id=self.args.lstrip("#")) if matches: matches[0].delete() self.msg("IRC connection destroyed.") else: self.msg("IRC connection/bot could not be removed, does it exist?") return if not self.args or not self.rhs: string = "Usage: @irc2chan[/switches] <evennia_channel> = <ircnetwork> <port> <#irchannel> <botname>" self.msg(string) return channel = self.lhs self.rhs = self.rhs.replace('#', ' ') # to avoid Python comment issues try: irc_network, irc_port, irc_channel, irc_botname = \ [part.strip() for part in self.rhs.split(None, 3)] irc_channel = "#%s" % irc_channel except Exception: string = "IRC bot definition '%s' is not valid." % self.rhs self.msg(string) return botname = "ircbot-%s" % irc_botname # create a new bot bot = PlayerDB.objects.filter(username__iexact=botname) if bot: # re-use an existing bot bot = bot[0].typeclass if not bot.is_bot: self.msg("Player '%s' already exists and is not a bot." % botname) return else: bot = create.create_player(botname, None, None, typeclass=bots.IRCBot) bot.start(ev_channel=channel, irc_botname=irc_botname, irc_channel=irc_channel, irc_network=irc_network, irc_port=irc_port) self.msg("Connection created. Starting IRC bot.")
def func(self): "Setup the rss-channel mapping" # checking we have all we need if not settings.RSS_ENABLED: string = """RSS is not enabled. You need to activate it in game/settings.py.""" self.msg(string) return try: import feedparser feedparser # to avoid checker error of not being used except ImportError: string = ("RSS requires python-feedparser (https://pypi.python.org/pypi/feedparser). " "Install before continuing.") self.msg(string) return if 'list' in self.switches: # show all connections rssbots = [bot.typeclass for bot in PlayerDB.objects.filter(db_is_bot=True, username__startswith="rssbot-")] if rssbots: from src.utils.evtable import EvTable table = EvTable("{wdbid{n", "{wupdate rate{n", "{wev-channel", "{wRSS feed URL{n", border="cells", maxwidth=78) for rssbot in rssbots: table.add_row(rssbot.id, rssbot.db.rss_rate, rssbot.db.ev_channel, rssbot.db.rss_url) self.caller.msg(table) else: self.msg("No rss bots found.") return if('disconnect' in self.switches or 'remove' in self.switches or 'delete' in self.switches): botname = "rssbot-%s" % self.lhs matches = PlayerDB.objects.filter(db_is_bot=True, db_key=botname) if not matches: # try dbref match matches = PlayerDB.objects.filter(db_is_bot=True, id=self.args.lstrip("#")) if matches: matches[0].delete() self.msg("RSS connection destroyed.") else: self.msg("RSS connection/bot could not be removed, does it exist?") return if not self.args or not self.rhs: string = "Usage: @rss2chan[/switches] <evennia_channel> = <rss url>" self.msg(string) return channel = self.lhs url = self.rhs botname = "rssbot-%s" % url # create a new bot bot = PlayerDB.objects.filter(username__iexact=botname) if bot: # re-use existing bot bot = bot[0].typeclass if not bot.is_bot: self.msg("Player '%s' already exists and is not a bot." % botname) return else: bot = create.create_player(botname, None, None, typeclass=bots.RSSBot) bot.start(ev_channel=channel, rss_url=url, rss_rate=10) self.msg("RSS reporter created. Fetching RSS.")
def func(self): "Do checks and create account" session = self.caller try: playername, email, password = self.playerinfo except ValueError: string = "\n\r Usage (without <>): create \"<playername>\" <email> <password>" session.msg(string) return if not re.findall('^[\w. @+-]+$', playername) or not (0 < len(playername) <= 30): session.msg("\n\r Playername can max be 30 characters or fewer. Letters, spaces, dig\ its and @/./+/-/_ only.") # this echoes the restrictions made by django's auth module. return if not email or not password: session.msg("\n\r You have to supply an e-mail address followed by a password." ) return if not utils.validate_email_address(email): # check so the email at least looks ok. session.msg("'%s' is not a valid e-mail address." % email) return # Run sanity and security checks if PlayerDB.objects.filter(username=playername): # player already exists session.msg("Sorry, there is already a player with the name '%s'." % playername) return if PlayerDB.objects.get_player_from_email(email): # email already set on a player session.msg("Sorry, there is already a player with that email address.") return if len(password) < 3: # too short password string = "Your password must be at least 3 characters or longer." string += "\n\rFor best security, make it at least 8 characters long, " string += "avoid making it a real word and mix numbers into it." session.msg(string) return # everything's ok. Create the new player account. try: default_home = ObjectDB.objects.get_id(settings.CHARACTER_DEFAULT_HOME) typeclass = settings.BASE_CHARACTER_TYPECLASS permissions = settings.PERMISSION_PLAYER_DEFAULT try: new_player = create.create_player(playername, email, password, permissions=permissions) except Exception, e: session.msg("There was an error creating the default Player/Character:\n%s\n If this problem persists, contact an admin." % e) logger.log_trace() return # This needs to be called so the engine knows this player is # logging in for the first time. (so it knows to call the right # hooks during login later) utils.init_new_player(new_player) # join the new player to the public channel pchanneldef = settings.CHANNEL_PUBLIC if pchanneldef: pchannel = ChannelDB.objects.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) if MULTISESSION_MODE < 2: # if we only allow one character, create one with the same name as Player # (in mode 2, the character must be created manually once logging in) new_character = create.create_object(typeclass, key=playername, location=default_home, home=default_home, permissions=permissions) # set playable character list new_player.db._playable_characters.append(new_character) # allow only the character itself and the player to puppet this character (and Immortals). new_character.locks.add("puppet:id(%i) or pid(%i) or perm(Immortals) or pperm(Immortals)" % (new_character.id, new_player.id)) # If no description is set, set a default description if not new_character.db.desc: new_character.db.desc = "This is a Player." # We need to set this to have @ic auto-connect to this character new_player.db._last_puppet = new_character # tell the caller everything went well. string = "A new account '%s' was created. Welcome!" if " " in playername: string += "\n\nYou can now log in with the command 'connect %s <your password>'." else: string += "\n\nYou can now log with the command 'connect %s <your password>'." session.msg(string % (playername, email))