Example #1
0
 def cmd_rank(self, client, username=None, rank=None):
     """
     /rank [username] [newrank]
     Displays the rank of the user with the given username. If no username is given, displays your rank. If a new rank is given, assigns the new rank.
     """
     if username == None:
         username = self.chat.identify(client)
     if not rank:
         caller = self.chat.identify(client)
         acct_rank = Account.get_rank(username)
         return StatusMessage("%s has rank %s." % (username, acct_rank))
     new_rank = int(rank)
     acct = Account.find_user(username)
     client_rank = Account.get_rank(self.chat.identify(client))
     if not acct:
         return ErrorMessage(
             "No such account was found. As a security" +
             " precaution, rank cannot be assigned to accounts that have" +
             " not been created and given password")
     if acct.rank >= client_rank:
         return ErrorMessage(
             "That user's rank is currently greater than or" +
             " equal to yours. Ask somebody of greater rank to make the" +
             " change instead.")
     if new_rank >= client_rank:
         return ErrorMessage(
             "The rank you are attempting to give that user" +
             " is greater than your current rank. Ask somebody of greater" +
             " rank to make the change instead.")
     acct.rank = int(new_rank)
     return StatusMessage("Rank of user %s is now %s." %
                          (username, acct.rank))
Example #2
0
 def cmd_arbiter(self, client):
     """
     /arbiter
     Displays the current arbiter.
     """
     owner = self.chat.find_owner()
     if not owner:
         return StatusMessage("Nobody is currently arbiter.")
     return StatusMessage("The arbiter is %s." % self.chat.identify(owner))
Example #3
0
 def approve_auth(self, client, name):
     self.socket_manager.multicast(
         StatusMessage("%s has authed as %s" %
                       (self.identify(client), name)))
     client.data["name"] = name
     if self.find_owner() == client:
         client.status("(They are still arbiter.)")
Example #4
0
 def cmd_list(self, client):
     """
     /list
     Lists available commands.
     """
     prefix = "cmd_"
     cmds = [i[len(prefix):] for i in dir(self) if i.startswith(prefix)]
     return StatusMessage("Currently availiable commands are %s" %
                          ", ".join(cmds))
Example #5
0
 def cmd_register(self, client, username, password):
     """
     /register username password
     Registers the given username with the given password. While passwords are case-sensitive, usernames are not. After registration you should log in with /auth.
     """
     try:
         Account.create(username, password)
         return StatusMessage("Registration complete: you may now /auth.")
     except AccountError, e:
         return ErrorMessage("Registration failed: %s" % e.message)
Example #6
0
 def cmd_drop(self, client):
     """
     /drop
     Releases control of the console if you have it.
     """
     if self.chat.find_owner() != client:
         return ErrorMessage("You do not control the console.")
     self.chat.socket_manager.multicast(
         StatusMessage("%s has dropped control." %
                       (self.chat.identify(client))))
     self.chat.change_owner(None)
Example #7
0
 def cmd_ask(self, client):
     """
     /ask
     The gentle alternative to /grab: for women and hippies.
     Takes control of the console only if nobody else has it. 
     You can use /take if you want webterm to automatically decide between /grabbing and /asking.
     """
     if self.chat.find_owner():
         return ErrorMessage("Someone is already the arbiter.")
     self.chat.socket_manager.multicast(
         StatusMessage("%s has requested control." %
                       (self.chat.identify(client))))
     self.chat.change_owner(client)
Example #8
0
 def cmd_grab(self, client):
     """
     /grab
     The forceful alternative to /take: for real men only.
     Attempts to forcefully grab control of the console from whoever currently has it. That person immediately loses control. Can only be used on others who are lower-ranking.
     You can use /take if you want webterm to automatically decide between /grabbing and /asking.
     """
     rank = Account.get_rank(self.chat.identify(client))
     rank_other = (Account.get_rank(
         self.chat.identify(self.chat.find_owner()))
                   if self.chat.find_owner() else 0)
     if rank < rank_other:
         return ErrorMessage("The current arbiter outranks you.")
     self.chat.socket_manager.multicast(
         StatusMessage("%s has grabbed control." %
                       (self.chat.identify(client))))
     self.chat.change_owner(client)
Example #9
0
    def change_owner(self, new):
        old = self.find_owner()
        if old == new:
            return

        if old and new:
            msg = "Arbiter changed from %s to %s." % (
                self.identify(old),
                self.identify(new),
            )
        elif new:
            msg = "%s is now arbiter." % (self.identify(new), )
        elif old:
            msg = "%s is no longer arbiter." % (self.identify(old))

        self.socket_manager.multicast(StatusMessage(msg))
        self.app_state.change_owner(new)
Example #10
0
    def cmd_free(self, client):
        """
        /free
        Releases control of the console from whoever has it. This is similar to
        a /grab followed by a /drop.
        """
        owner = self.chat.find_owner()
        if not owner:
            return ErrorMessage("The console is already free.")

        rank = Account.get_rank(self.chat.identify(client))
        rank_other = (Account.get_rank(self.chat.identify(owner))
                      if owner else 0)

        if rank < rank_other:
            return ErrorMessage("The current arbiter outranks you.")

        self.chat.socket_manager.multicast(
            StatusMessage("%s has freed the console." %
                          (self.chat.identify(client))))
        self.chat.change_owner(None)
Example #11
0
 def handle_leave(self, client):
     self.socket_manager.multicast(
         StatusMessage("%s has left." % self.identify(client)))
     if client == self.find_owner():
         self.change_owner(None)
Example #12
0
 def handle_join(self, client):
     self.greet(client)
     self.socket_manager.multicast(
         StatusMessage("%s has joined." % self.identify(client)))
Example #13
0
File: app.py Project: Zekka/webterm
 def status(self, statusmessage):
     self.msg(StatusMessage(statusmessage))