diff orpg/chat/commands.py @ 135:dcf4fbe09b70 beta

Traipse Beta 'OpenRPG' {091010-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Beta) Added Bookmarks Fix to Remote Admin Commands Minor fix to text based Server Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Added 'boot' command to remote admin Added confirmation window for sent nodes Minor changes to allow for portability to an OpenSUSE linux OS Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Zoom Mouse plugin added Images added to Plugin UI Switching to Element Tree Map efficiency, from FlexiRPG Added Status Bar to Update Manager default_manifest.xml renamed to default_upmana.xml Cleaner clode for saved repositories New TrueDebug Class in orpg_log (See documentation for usage) Mercurial's hgweb folder is ported to upmana **Pretty important update that can help remove thousands of dead children from your gametree. **Children, <forms />, <group_atts />, <horizontal />, <cols />, <rows />, <height />, etc... are all tags now. Check your gametree and look for dead children!! **New Gamtree Recusion method, mapping, and context sensitivity. !!Alpha - Watch out for infinite loops!!
author sirebral
date Tue, 10 Nov 2009 14:11:28 -0600
parents 68c7bd272f27
children 3b6888bb53b5
line wrap: on
line diff
--- a/orpg/chat/commands.py	Fri Sep 25 20:47:16 2009 -0500
+++ b/orpg/chat/commands.py	Tue Nov 10 14:11:28 2009 -0600
@@ -8,15 +8,13 @@
 #
 
 
-import string
-import time
+import string, time
 import orpg.orpg_version
 import orpg.orpg_windows
-import traceback
-
-from orpg.orpgCore import component
-from orpg.tools.orpg_log import logger
-from orpg.tools.decorators import debugging
+import traceback
+
+from orpg.orpgCore import component
+from orpg.tools.orpg_log import logger
 
 ##--------------------------------------------------------------
 ## dynamically loading module for extended developer commands
@@ -39,8 +37,8 @@
     # Initialization subroutine.
     #
     # !self : instance of self
-    # !chat : instance of the chat window to write to
-    @debugging
+    # !chat : instance of the chat window to write to
+    
     def __init__(self,chat):
         self.post = chat.Post
         self.colorize = chat.colorize
@@ -60,21 +58,21 @@
         # of implemented emotions.
         #
         # !self : instance of self
-        # !text : string of text matching an implemented emotion
-    @debugging
+        # !text : string of text matching an implemented emotion
+    
     def addcommand(self, cmd, function, helpmsg):
         if not self.cmdlist.has_key(cmd) and not self.shortcmdlist.has_key(cmd):
             self.cmdlist[cmd] = {}
             self.cmdlist[cmd]['function'] = function
             self.cmdlist[cmd]['help'] = helpmsg
             #print 'Command Added: ' + cmd
-
-    @debugging
+
+    
     def addshortcmd(self, shortcmd, longcmd):
         if not self.shortcmdlist.has_key(shortcmd) and not self.cmdlist.has_key(shortcmd):
             self.shortcmdlist[shortcmd] = longcmd
-
-    @debugging
+
+    
     def removecmd(self, cmd):
         if self.cmdlist.has_key(cmd):
             del self.cmdlist[cmd]
@@ -83,8 +81,8 @@
 
         #print 'Command Removed: ' + cmd
 
-
-    @debugging
+
+    
     def defaultcmds(self):
         self.addcommand('/help', self.on_help, '- Displays this help message')
         self.addcommand('/version', self.on_version, ' - Displays current version of OpenRPG.')
@@ -113,8 +111,8 @@
         self.addcommand('/sound', self.on_sound, 'Sound_URL - Plays a sound for all clients in the room.')
         self.addcommand('/purge', self.on_purge, 'This will clear the entire chat window')
         self.addcommand('/advfilter', self.on_filter, 'This will toggle the Advanced Filter')
-
-    @debugging
+
+    
     def defaultcmdalias(self):
         self.addshortcmd('/?', '/help')
         self.addshortcmd('/he', '/me')
@@ -128,8 +126,8 @@
 
         #This is just an example or a differant way the shorcmd can be used
         self.addshortcmd('/sleep', '/me falls asleep')
-
-    @debugging
+
+    
     def docmd(self,text):
         cmdsearch = string.split(text,None,1)
         cmd = string.lower(cmdsearch[0])
@@ -144,8 +142,8 @@
         else:
             msg = "Sorry I don't know what %s is!" % (cmd)
             self.chat.InfoPost(msg)
-
-    @debugging
+
+    
     def on_filter(self, cmdargs):
         #print self.chat.advancedFilter
         test = not self.chat.advancedFilter
@@ -169,13 +167,13 @@
             self.chat.InfoPost("Advanced Filtering has been turned On")
         else:
             self.chat.InfoPost("Advanced Filtering has been turned Off")
-
-    @debugging
+
+    
     def on_purge(self, cmdargs):
         self.chat.PurgeChat()
         self.chat.InfoPost('Chat Buffer has been Purged!')
-
-    @debugging
+
+    
     def on_sound(self, cmdargs):
         if len(cmdargs) < 8:
             self.chat.InfoPost("You must provide a URL for the file name, it does not work for just local sound files")
@@ -208,12 +206,12 @@
             self.chat.InfoPost("You cannot send sound files to the lobby!")
         else:
             self.chat.InfoPost("Something dun fuckered up Frank!")
-
-    @debugging
+
+    
     def on_version(self, cmdargs=""):
         self.chat.InfoPost("Version is OpenRPG " + self.chat.version)
-
-    @debugging
+
+    
     def on_load(self, cmdargs):
         args = string.split(cmdargs,None,-1)
         try:
@@ -223,15 +221,15 @@
         except Exception,e:
             print e
             self.chat.InfoPost("ERROR Loading settings")
-
-    @debugging
+
+    
     def on_font(self, cmdargs):
         try:
             fontsettings = self.chat.set_default_font(fontname=cmdargs, fontsize=None)
         except:
             self.chat.InfoPost("ERROR setting default font")
-
-    @debugging
+
+    
     def on_fontsize(self, cmdargs):
         args = string.split(cmdargs,None,-1)
         try:
@@ -239,8 +237,8 @@
         except Exception, e:
             print e
             self.chat.InfoPost("ERROR setting default font size")
-
-    @debugging
+
+    
     def on_close(self, cmdargs):
         try:
             chatpanel = self.chat
@@ -251,16 +249,16 @@
                 chatpanel.parent.onCloseTab(0)
         except:
             self.chat.InfoPost("Error:  cannot close private chat tab.")
-
-    @debugging
+
+    
     def on_time(self, cmdargs):
         local_time = time.localtime()
         gmt_time = time.gmtime()
         format_string = "%A %b %d, %Y  %I:%M:%S%p"
         self.chat.InfoPost("<br />Local: " + time.strftime(format_string)+\
                            "<br />GMT: "+time.strftime(format_string,gmt_time))
-
-    @debugging
+
+    
     def on_dieroller(self, cmdargs):
         args = string.split(cmdargs,None,-1)
         rm = component.get('DiceManager')
@@ -272,14 +270,14 @@
             print e
             self.chat.InfoPost("Available die rollers: " + str(rm.listRollers()))
             self.chat.InfoPost("You are using the <b>\"" + rm.getRoller() + "\"</b> die roller.")
-
-    @debugging
+
+    
     def on_ping(self, cmdargs):
         ct = time.clock()
         msg = "<ping player='"+self.session.id+"' time='"+str(ct)+"' />"
         self.session.outbox.put(msg)
-
-    @debugging
+
+    
     def on_log(self,cmdargs):
         args = string.split(cmdargs,None,-1)
         logfile = self.settings.get_setting( 'GameLogPrefix' )
@@ -310,25 +308,22 @@
             self.postLoggingState()
         else:
             self.chat.InfoPost("Unknown logging command, use 'on' or 'off'"  )
-
-    @debugging
+
+    
     def postLoggingState( self ):
         logfile = self.settings.get_setting( 'GameLogPrefix' )
         try:
-            if logfile[0] != ANTI_LOG_CHAR:
-                comment = 'is'
-            else:
-                comment = 'is not'
-        except:
-            comment = 'is not'
+            if logfile[0] != ANTI_LOG_CHAR: comment = 'is'
+            else: comment = 'is not'
+        except: comment = 'is not'
         suffix = time.strftime( '-%d-%m-%y.html', time.localtime( time.time() ) )
         self.chat.InfoPost('Log filename is "%s%s", system is %s logging.' % (logfile, suffix, comment) )
 
         # This subroutine will set the players netork status.
         #
         #!self : instance of self
-
-    @debugging
+
+    
     def on_name(self, cmdargs):
         #only 20 chars no more! :)
         if cmdargs == "":
@@ -339,21 +334,20 @@
             self.session.set_name(str(cmdargs))
 
     # def on_status - end
-
         # This subroutine will set the players netork status.
         #
-        # !self : instance of self
-    @debugging
+        # !self : instance of self
+    
     def on_status(self, cmdargs):
         if cmdargs ==  "":
             self.chat.InfoPost("Incorrect synatx for status.")
-        else:
+        else:
         #only 20 chars no more! :)
-            txt = cmdargs[:20]
-            self.session.set_text_status(str(txt))
+            txt = cmdargs[:20]
+            self.session.set_text_status(str(txt))
     # def on_status - end
-
-    @debugging
+
+    
     def on_set(self, cmdargs):
         args = string.split(cmdargs,None,-1)
         keys = self.settings.get_setting_keys()
@@ -387,8 +381,8 @@
         # This subroutine will display the correct usage of the different emotions.
         #
         #!self : instance of self
-
-    @debugging
+
+    
     def on_help(self, cmdargs=""):
         cmds = self.cmdlist.keys()
         cmds.sort()
@@ -404,14 +398,13 @@
                 if self.shortcmdlist[shortcmd] == cmd:
                     msg += ', <b><font color="#0000CC">%s</font></b>' % (shortcmd)
             msg += ' %s' % (self.cmdlist[cmd]['help'])
-
         self.chat.InfoPost(msg)
 
         # This subroutine will either show the list of currently ignored users
         # !self : instance of self
         # !text : string that is comprised of a list of users to toggle the ignore flag
-
-    @debugging
+
+    
     def on_ignore(self, cmdargs):
         args = string.split(cmdargs,None,-1)
         (ignore_list, ignore_name) = self.session.get_ignore_list()
@@ -437,8 +430,8 @@
                 except:
                     self.chat.InfoPost(m + " was ignored because it is an invalid player ID")
                     traceback.print_exc()
-
-    @debugging
+
+    
     def on_role(self, cmdargs):
         if cmdargs == "":
             self.session.display_roles()
@@ -459,8 +452,7 @@
                 if role_pwd != None:
                     for m in player_ids:
                         self.session.set_role(m.strip(),role,role_pwd)
-            except:
-                traceback.print_exc()
+            except:  traceback.print_exc()
 #        return
 
         # This subroutine implements the whisper functionality that enables a user
@@ -469,33 +461,30 @@
         # !self : instance of self
         # !text : string that is comprised of a list of users and the message to
         #whisper.
-
-    @debugging
+
+    
     def on_whisper(self, cmdargs):
         delim = cmdargs.find("=")
 
         if delim < 0:
-            if self.previous_whisper:
-                player_ids = self.previous_whisper
+            if self.previous_whisper: player_ids = self.previous_whisper
             else:
                 self.chat.InfoPost("**Incorrect syntax for whisper." + str(delim))
                 return
-        else:
-            player_ids = string.split(cmdargs[:delim], ",")
+        else: player_ids = string.split(cmdargs[:delim], ",")
         self.previous_whisper = player_ids
         mesg = string.strip(cmdargs[delim+1:])
         self.chat.whisper_to_players(mesg,player_ids)
 
 #---------------------------------------------------------
 # [START] Digitalxero Multi Whisper Group 1/1/05
-#---------------------------------------------------------
-    @debugging
+#---------------------------------------------------------
+    
     def on_groupwhisper(self, cmdargs):
         args = string.split(cmdargs,None,-1)
         delim = cmdargs.find("=")
 
-        if delim > 0:
-            group_ids = string.split(cmdargs[:delim], ",")
+        if delim > 0: group_ids = string.split(cmdargs[:delim], ",")
         elif args[0] == "add":
             if not orpg.player_list.WG_LIST.has_key(args[2]):
                 orpg.player_list.WG_LIST[args[2]] = {}
@@ -540,17 +529,15 @@
         for gid in group_ids:
             idList = ""
             for n in orpg.player_list.WG_LIST[gid]:
-                if idList == "":
-                    idList = str(n)
-                else:
-                    idList = str(n) + ", " + idList
+                if idList == "": idList = str(n)
+                else: idList = str(n) + ", " + idList
             self.on_whisper(idList + "=" + self.settings.get_setting("gwtext") + msg)
 
 #---------------------------------------------------------
 # [END] Digitalxero Multi Whisper Group 1/1/05
 #---------------------------------------------------------
-
-    @debugging
+
+    
     def on_gmwhisper(self, cmdargs):
         if cmdargs == "":
             self.chat.InfoPost("**Incorrect syntax for GM Whisper.")
@@ -559,33 +546,27 @@
             if len(the_gms):
                 gmstring = ""
                 for each_gm in the_gms:
-                    if gmstring != "":
-                        gmstring += ","
+                    if gmstring != "": gmstring += ","
                     gmstring += each_gm
                 self.on_whisper(gmstring + "=" + cmdargs)
-            else:
-                self.chat.InfoPost("**No GMs to Whisper to.")
-
-    @debugging
+            else: self.chat.InfoPost("**No GMs to Whisper to.")
+
+    
     def on_moderate(self, cmdargs):
         if cmdargs != "":
             pos = cmdargs.find("=")
             if (pos < 0):
                 plist = ""
-                if cmdargs.lower() == "on":
-                    action = "enable"
-                elif cmdargs.lower() == "off":
-                    action="disable"
+                if cmdargs.lower() == "on": action = "enable"
+                elif cmdargs.lower() == "off": action="disable"
                 else:
                     self.chat.InfoPost("Wrong syntax for moderate command!")
                     return
             else:
                 plist = string.strip(cmdargs[:pos])
                 tag = string.strip(cmdargs[pos+1:])
-                if tag.lower() == "on":
-                    action = "addvoice"
-                elif tag.lower() == "off":
-                    action = "delvoice"
+                if tag.lower() == "on": action = "addvoice"
+                elif tag.lower() == "off": action = "delvoice"
                 else:
                     self.chat.InfoPost("Wrong syntax for moderate command!")
                     return
@@ -594,8 +575,7 @@
                 msg = "<moderate"
                 msg += " action = '" + action + "'"
                 msg +=" from = '" + self.session.id + "' pwd='" + pwd + "'"
-                if (plist != ""):
-                    msg += " users='"+plist+"'"
+                if (plist != ""): msg += " users='"+plist+"'"
                 msg += " />"
                 self.session.outbox.put(msg)
             pass
@@ -603,12 +583,12 @@
             msg = "<moderate action='list' from='"+self.session.id+"' />"
             self.session.outbox.put(msg)
         self.session.update()
-
-    @debugging
+
+    
     def on_update(self, cmdargs):
         self.chat.InfoPost("This command is no longer valid")
-
-    @debugging
+
+    
     def on_description(self, cmdargs):
         if len(cmdargs) <= 0:
             self.chat.InfoPost("**No description text to display." + str(delim))
@@ -618,8 +598,8 @@
         mesg += "</font></td></tr></table>"
         self.chat.Post(mesg)
         self.chat.send_chat_message(mesg)
-
-    @debugging
+
+    
     def invoke_tab(self, cmdargs):
         ######START mDuo13's Tab Initiator########
         try:
@@ -630,8 +610,7 @@
                 if (panel.sendtarget == playerid):
                     self.chat.Post("Cannot invoke tab: Tab already exists.")
                     return
-            try:
-                displaypanel = self.chat.parent.create_whisper_tab(playerid)
+            try: displaypanel = self.chat.parent.create_whisper_tab(playerid)
             except:
                 self.chat.Post("That ID# is not valid.")
                 return
@@ -644,8 +623,9 @@
             self.chat.parent.newMsg(nidx)
             return
         #######END mDuo13's Tab Initiator#########
-
-    @debugging
+
+
+    
     def on_remote_admin(self, cmdargs):
         args = string.split(cmdargs,None,-1)
         #handles remote administration commands
@@ -660,8 +640,7 @@
                 #raw command return state info
                 msg = "<br /><b>Remote Administrator Config:</b>"
                 if pass_state != 1 : msg += " Password not set. Remote admin functions disabled<br />"
-                else:
-                    msg += " Enabled. Using password \""+pwd+"\"<br />"
+                else: msg += " Enabled. Using password '"+pwd+"'<br />"
                 self.chat.SystemPost(msg)
                 return
 
@@ -669,75 +648,54 @@
                 #no commands under this point will execute unless an admin password has been previously set
                 self.chat.SystemPost("Command ignored. No remote administrator password set!!")
                 return
-            msgbase = "<admin id=\""+self.session.id+"\" group_id=\""+self.session.group_id+"\" pwd=\""+pwd+"\" "
+            msgbase = "<admin id='"+self.session.id+"' group_id='"+self.session.group_id+"' pwd='"+pwd+"'"
             if args[0] == "set":
                 if len( args ) > 1:
                     self.session.orpgFrame_callback.password_manager.server = str( args[1] )
-                    self.chat.SystemPost( "Remote administration commands using password: \""+str(self.session.orpgFrame_callback.password_manager.GetSilentPassword("server"))+"\"" )
+                    self.chat.SystemPost( "Remote administration commands using password: "+str(self.session.orpgFrame_callback.password_manager.GetSilentPassword("server"))+"" )
                 else:
                     pwd = self.session.orpgFrame_callback.password_manager.GetPassword("server")
                     if pwd != None:
-                        self.chat.SystemPost( "Remote administration commands using password: \""+pwd+"\"" )
+                        self.chat.SystemPost( "Remote administration commands using password: "+pwd+"" )
+            elif len(args) == 1:
+                admin_command = {'banlist': ' cmd="banlist" />',
+                                'help': " cmd='help' />",
+                                'roompasswords': " cmd='roompasswords' />",
+                                'uptime': " cmd='uptime' />",
+                                'list': " cmd='list' />",
+                                'killserver': " cmd='killserver' />",
+                                'savemaps': ' cmd="savemaps" />'
+                                }
+                if admin_command.has_key(args[0]):
+                    msg = msgbase + admin_command[args[0]]
+                    self.session.outbox.put(msg)
 
-            elif args[0] == "ban":
-                #Ban a player from the server
-                msg = msgbase + ' cmd="ban" bid="' + str(args[1]) + '" />'
-                self.session.outbox.put(msg)
+            elif len(args) == 2:
+                admin_command = {'ban': ' cmd="ban" bid="' + str(args[1]) + '" />',
+                                'unban': ' cmd="unban" ip="' + str(args[1]) + '" />',
+                                'broadcast': " cmd='broadcast' msg='"+ string.join(args[1:])+"' />",
+                                'killgroup': " cmd='killgroup' gid='"+ str(args[1])+"' />"
+                                }
+                if admin_command.has_key(args[0]):
+                    msg = msgbase + admin_command[args[0]]
+                    self.session.outbox.put(msg)
+
+            elif len(args) == 3:
+                admin_command = {'message':" cmd='message' to_id='"+ str(args[1])+"' msg='"+ string.join(args[2:])+"' />",
+                                'nameroom': " cmd='nameroom' rmid='"+ str(args[1])+"' name='"+ string.join(args[2:])+"' />",
+                                'passwd': " cmd='passwd' gid='"+str(args[1])+"' pass='"+ str(args[2])+"' />"
+                                 }
+                if admin_command.has_key(args[0]):
+                    msg = msgbase + admin_command[args[0]]
+                    self.session.outbox.put(msg)
 
             elif args[0] == "banip":
                 #Ban a player from the server
-                try:
-                    bname = str(args[2])
-                except:
-                    bname = 'Unknown'
+                try: bname = str(args[2])
+                except: bname = 'Unknown'
                 msg = msgbase + ' cmd="banip" bip="' + str(args[1]) + '" bname="' + bname + '"/>'
                 self.session.outbox.put(msg)
 
-            elif args[0] == "unban":
-                #remove a group from the server and drop all players within the group
-                msg = msgbase + ' cmd="unban" ip="' + str(args[1]) + '" />'
-                self.session.outbox.put(msg)
-
-            elif args[0] == "banlist":
-                #remove a group from the server and drop all players within the group
-                msg = msgbase + ' cmd="banlist" />'
-                self.session.outbox.put(msg)
-
-            elif args[0] == "help":
-                #request help from server
-                msg = msgbase + " cmd=\"help\" />"
-                self.session.outbox.put(msg)
-
-            elif args[0] == "nameroom":
-                #reqest room renaming on server
-                msg = msgbase + " cmd=\"nameroom\" rmid=\""+ str(args[1])+"\" name=\""+ string.join(args[2:])+"\" />"
-                self.session.outbox.put(msg)
-
-            elif args[0] == "roompasswords":
-                #reqest room renaming on server
-                msg = msgbase + " cmd=\"roompasswords\"/>"
-                self.session.outbox.put(msg)
-
-            elif args[0] == "message":
-                #send message to a specific player on the server via the system administrator
-                msg = msgbase + " cmd=\"message\" to_id=\""+ str(args[1])+"\" msg=\""+ string.join(args[2:])+"\" />"
-                self.session.outbox.put(msg)
-
-            elif args[0] == "broadcast":
-                #send a message to all players on server from the system administrator
-                msg = msgbase + " cmd=\"broadcast\" msg=\""+ string.join(args[1:])+"\" />"
-                self.session.outbox.put(msg)
-
-            elif args[0] == "killgroup":
-                #remove a group from the server and drop all players within the group
-                msg = msgbase + " cmd=\"killgroup\" gid=\""+ str(args[1])+"\" />"
-                self.session.outbox.put(msg)
-
-            elif args[0] == "uptime":
-                #request uptime report from server
-                msg = msgbase + " cmd=\"uptime\" />"
-                self.session.outbox.put(msg)
-
             elif args[0] == "createroom":
                 #request creation of a (temporary) persistant room
                 if len(args) < 2:
@@ -747,30 +705,11 @@
                     self.chat.SystemPost( "You must supply a boot password also.<br />/admin createroom &lt;name&gt; &lt;boot password&gt; [password]" )
                     return
                 if len(args) < 4: args.append("")
-                msg = msgbase + " cmd=\"createroom\" name=\""+str(args[1])+"\" boot=\""+ str(args[2])+"\" pass=\""+ str(args[3])+"\" />"
-                self.session.outbox.put(msg)
-
-            elif args[0] == "passwd":
-                #request boot password change on a room
-                msg = msgbase + " cmd=\"passwd\" gid=\""+str(args[1])+"\" pass=\""+ str(args[2])+"\" />"
+                msg = msgbase + " cmd='createroom' name='"+str(args[1])+"' boot='"+ str(args[2])+"' pass='"+ str(args[3])+"' />"
                 self.session.outbox.put(msg)
 
-            elif args[0] == "list":
-                #request a list of rooms and players from server
-                msg = msgbase + " cmd=\"list\" />"
-                self.session.outbox.put(msg)
-
-            elif args[0] == "killserver":
-                #remotely kill the server
-                msg = msgbase + " cmd=\"killserver\" />"
-                self.session.outbox.put(msg)
-
-            elif args[0] == "savemaps":
-                msg = msgbase + ' cmd="savemaps" />'
-                self.session.outbox.put(msg)
-
-            else:
-                self.chat.InfoPost("Unknown administrator command"  )
+            else: self.chat.InfoPost("Unknown administrator command"  )
+            #command_function = {'banip': self.admin.r_admin_banip, 'createroom': self.r_admin_createroom,}
         except:
             self.chat.InfoPost("An error has occured while processing a Remote Administrator command!")
             traceback.print_exc()