[Winopenrpg-developer] openrpg1/orpg/chat __init__.py,NONE,1.1 chat_msg.py,NONE,1.1 chat_util.py,NON
Status: Inactive
Brought to you by:
digitalxero
|
From: Digital X. <dig...@us...> - 2006-01-26 17:33:25
|
Update of /cvsroot/winopenrpg/openrpg1/orpg/chat In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30930/orpg/chat Added Files: __init__.py chat_msg.py chat_util.py chat_version.py chatwnd.py commands.py Log Message: Initial commit of OpenRPG++ python --- NEW FILE: chat_msg.py --- # Copyright (C) 2000-2001 The OpenRPG Project # # ope...@li... # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # -- # # File: chat_msg.py # Author: Ted Berg # Maintainer: # Version: # $Id: chat_msg.py,v 1.1 2006/01/26 17:33:15 digitalxero Exp $ # # Description: Contains class definitions for manipulating <chat/> messages # # __version__ = "$Id: chat_msg.py,v 1.1 2006/01/26 17:33:15 digitalxero Exp $" import orpg.orpg_xml from chat_version import CHAT_VERSION CHAT_MESSAGE = 1 WHISPER_MESSAGE = 2 EMOTE_MESSAGE = 3 INFO_MESSAGE = 4 SYSTEM_MESSAGE = 5 class chat_msg: def __init__(self,xml_text="<chat type=\"1\" version=\""+CHAT_VERSION+"\" alias=\"\" ></chat>"): self.chat_dom = None self.takexml(xml_text) def __del__(self): if self.chat_dom: self.chat_dom.unlink() def toxml(self): return orpg.orpg_xml.toxml(self.chat_dom) def takexml(self,xml_text): xml_dom = orpg.orpg_xml.parseXml(xml_text) node_list = xml_dom.getElementsByTagName("chat") if len(node_list) < 1: print "Warning: no <chat/> elements found in DOM." else: if len(node_list) > 1: print "Found more than one instance of <" + self.tagname + "/>. Taking first one" self.takedom(node_list[0]) def takedom(self,xml_dom): if self.chat_dom: self.text_node = None self.chat_dom.unlink() self.chat_dom = xml_dom self.text_node = orpg.orpg_xml.safe_get_text_node(self.chat_dom) def set_text(self,text): text = orpg.orpg_xml.strip_text(text) self.text_node._set_nodeValue(text) def set_type(self,type): self.chat_dom.setAttribute("type",str(type)) def get_type(self): return int(self.chat_dom.getAttribute("type")) def set_alias(self,alias): self.chat_dom.setAttribute("alias",alias) def get_alias(self): return self.chat_dom.getAttribute("alias") def get_text(self): return self.text_node._get_nodeValue() def get_version(self): return self.chat_dom.getAttribute("version") --- NEW FILE: chatwnd.py --- # Copyright (C) 2000-2001 The OpenRPG Project # # ope...@li... # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # -- # [...1968 lines suppressed...] def getAttentionBitmap(): return wxBitmapFromImage(getAttentionImage()) def getAttentionImage(): stream = cStringIO.StringIO(getAttentionData()) return wxImageFromStream(stream) def getNormalData(): return \ '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x02\x00\x00\x00\x90\x91h6\x00\x00\x00\tpHYs\x00\x00\x0b\x12\x00\x00\x0b\x12\x01\xd2\xdd~\xfc\x00\x00\x01\x9eIDATx\x9c\x8d\xcb\xcfK\xd3q\x1c\xc7\xf1\xd7\xeb\xfd\xf9\xda\x886\x1c$\xb9\x8c\x99V\xb3\x15\x16\xe8\x8eI\x87\x0e\xb1\xf5\x0fx\xebo\x88N\xfd\x03\xd1\xbf\xe1\xcds\x04\x99\x04\x15\x11A\x87\x141b?\x88pPN\x17\xe5\\\x10\xad\xef\xe7\xfd\xea\xd0\xa5\xc3\x98>\xcf\x8f\'%\x17$\r\xa8CaO\xda\x97w\x1c}@B& o,\x90S\xb2<\x99#,\x01"\x90B\xfb\xee\x9f\xdc?\xc8w\x1cm\xe9\x07%\xd9I`"r\xca\xec\nq\xd5\xec\x02\x99M$I]\xf7\xed\x187\\\xef\xdc[\xd5\xb9\x06\xfe\xebYk!\xc1.\xd1#\x06\xb29F\xef*n\xa7\xfe&\x8d\xcf\xab\xa5\xd7\x18Vmy\xf5\xfe\xc3\'I\xb8i\xb6\xc44\xfd\x18\xfde\x8c\xeb\xb7/=\x1e\xaa\xff\xb5\xd6(\'\xc9\xad\xc4\xaa&\xecI\x9f\xa3\xea#4\x80\xda\xe5\xba{\xdd\xd16\xa9\x0buj\xa5\xc6\xe8\x01\x80\xb4\xeb\xfab\xe0o\xe9\xe7\x91\x1a@\xbfw\n\x18\x18\x00\x80\xc7\x19\x00\x900*G\xe4\x8f\xa3s\xe3N\x8c\x1bY0\xce\xae7\x17\x8e\x1c\x8c\xd3\xc6i3L\xd2.Z\xb8v\xb6\xd8\x1e\xa1\x9f\xb6\x16ieb\xd6`\xf9\xc0r\xb0\xca\xca\xab{\xb5\xe5\xd5\xa1z\xadY\x19\x0b7\x12[4;O\xd7\x1fx\xcfU\x8fq+\xea\xbd\xd4|p\xf7\xd1\xe6\xdb%\x00\x85b{\xe5\xc5\x1d\x0bE\xf2z@%\xd8<m\x86\x92\x0b\x11\xfe\xcd\xbd\x13\xd5\x14v\xa0\xaf\xf2CA\xb41\xd3\x19\x84s\xc6\x92q\x86\x9c$3\x94\x04@J\xa1_\xc0\x81\xf4]:\x10\xfa\x92\x1b3D\x16v\x1a\x9c0f\x85\x13\x04\xff\x02\xf1\xb8\xd1\xec\x08\xfa\x9c\x89\x00\x00\x00\x00IEND\xaeB`\x82' def getNormalBitmap(): return wxBitmapFromImage(getNormalImage()) def getNormalImage(): stream = cStringIO.StringIO(getNormalData()) return wxImageFromStream(stream) --- NEW FILE: __init__.py --- --- NEW FILE: commands.py --- # This class implements the basic chat commands available in the chat interface. # # Defines: # __init__(self,chat) # docmd(self,text) # on_help(self) # on_whisper(self,text) # import string import time import orpg.tools.orpg_update import orpg.orpg_version import orpg.orpg_windows import orpg.plugins#mDuo13 added import traceback ##-------------------------------------------------------------- ## dynamically loading module for extended developer commands ## allows developers to work on new chat commands without ## integrating them directly into the ORPG code allowing ## updating of their code without merging changes ## cmd_ext.py should NOT be included in the CVS or Actual Releases try: import cmd_ext print "Importing Developer Extended Command Set" except: pass ##---------------------------------------------------------------- ANTI_LOG_CHAR = '!' class chat_commands: # Initialization subroutine. # # !self : instance of self # !chat : instance of the chat window to write to def __init__(self,chat): self.post = chat.Post self.colorize = chat.colorize self.session = chat.session #self.send = chat.session.send self.settings = chat.settings self.chat = chat self.cmdlist = {} self.shortcmdlist = {} self.defaultcmds() self.defaultcmdalias() # def __init__ - end self.previous_whisper = [] # This subroutine will take a text string and attempt to match to a series # of implemented emotions. # # !self : instance of self # !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 def addshortcmd(self, shortcmd, longcmd): if not self.shortcmdlist.has_key(shortcmd) and not self.cmdlist.has_key(shortcmd): self.shortcmdlist[shortcmd] = longcmd def removecmd(self, cmd): if self.cmdlist.has_key(cmd): del self.cmdlist[cmd] elif self.shortcmdlist.has_key(cmd): del self.shortcmdlist[cmd] #print 'Command Removed: ' + cmd def defaultcmds(self): self.addcommand('/help', self.on_help, '- Displays this help message') self.addcommand('/version', self.on_version, ' - Displays current version of OpenRPG.') self.addcommand('/me', self.chat.emote_message, ' - Alias for **yourname does something.**') self.addcommand('/ignore', self.on_ignore, '[player_id,player_id,... | ignored_ip,ignored_ip,... | list] - Toggle ignore for user associated with that player ID. Using the IP will remove the only not toggle.') self.addcommand('/lines', self.on_lines, 'number - View or set the maximum number of lines shown in chat.') self.addcommand('/load', self.on_load, 'filename - Loads settings from another ini file from the myfiles directory.') self.addcommand('/purge', self.chat.Purge_buffer, '- Purge history older than your buffersize.') self.addcommand('/role', self.on_role, '[player_id = GM | Player | Lurker] - Get player roles from ther server, self.or change the role of a player.') self.addcommand('/font', self.on_font, 'fontname - Sets the font.') self.addcommand('/fontsize', self.on_fontsize, 'size - Sets the size of your fonts. Recomended 8 or better for the size.') self.addcommand('/close', self.on_close, 'Close the chat tab') self.addcommand('/set', self.on_set, '[setting[=value]] - Displays one or all settings, self.or sets a setting.') self.addcommand('/whisper', self.on_whisper, 'player_id_number, ... = message - Whisper to player(s). Can contain multiple IDs.') self.addcommand('/gw', self.on_groupwhisper, 'group_name=message - Type /gw help for more information') self.addcommand('/gm', self.on_gmwhisper, 'message - Whispers to all GMs in the room') self.addcommand('/name', self.on_name, 'name - Change your name.') self.addcommand('/time', self.on_time, '- Display the local and GMT time and date.') self.addcommand('/status', self.on_status, 'your_status - Set your online status (afk,away,etc..).') self.addcommand('/dieroller', self.on_dieroller, '- Set your dieroller or list the available rollers.') self.addcommand('/log', self.on_log, '[ on | off | to <em>filename</em> ] - Check log state, additionally turn logging on, self.off, self.or set the log filename prefix.') self.addcommand('/update', self.on_update, '[get] - Get the latest version of OpenRPG.') self.addcommand('/moderate', self.on_moderate, '[ on | off ][player_id=on|off] - Show who can speak in a moderated room, self.or turn room moderation on or off.') self.addcommand('/tab', self.invoke_tab, 'player_id - Creates a tab so you can whisper rolls to youror what ever') self.addcommand('/ping', self.on_ping, '- Ask for a response from the server.') self.addcommand('/admin', self.on_remote_admin, '- Remote admin commands') self.addcommand('/description', self.on_description, 'message - Creates a block of text, used for room descriptions and such') def defaultcmdalias(self): self.addshortcmd('/?', '/help') self.addshortcmd('/he', '/me') self.addshortcmd('/she', '/me') self.addshortcmd('/i', '/ignore') self.addshortcmd('/w', '/whisper') self.addshortcmd('/nick', '/name') self.addshortcmd('/date', '/time') self.addshortcmd('/desc', '/description') self.addshortcmd('/d', '/description') #This is just an example or a differant way the shorcmd can be used self.addshortcmd('/sleep', '/me falls asleep') def docmd(self,text): cmdsearch = string.split(text,None,1) cmd = string.lower(cmdsearch[0]) start = len(cmd) end = len(text) cmdargs = text[start+1:end] if self.cmdlist.has_key(cmd): self.cmdlist[cmd]['function'](cmdargs) elif self.shortcmdlist.has_key(cmd): self.docmd(self.shortcmdlist[cmd] + " " + cmdargs) else: msg = "Sorry I don't know what %s is!" % (cmd) self.chat.InfoPost(msg) def on_version(self, cmdargs=""): self.chat.InfoPost("Version is OpenRPG " + self.chat.version) def on_load(self, cmdargs): args = string.split(cmdargs,None,-1) try: self.settings.setup_ini(args[0]) self.settings.reload_settings(self.chat) self.chat.InfoPost("Settings Loaded from file " + args[0] ) except Exception,e: print e self.chat.InfoPost("ERROR Loading settings") def on_font(self, cmdargs): try: fontsettings = self.chat.set_default_font(fontname=cmdargs, fontsize=None) except: self.chat.InfoPost("ERROR setting default font") def on_fontsize(self, cmdargs): args = string.split(cmdargs,None,-1) try: fontsettings = self.chat.set_default_font(fontname=None, fontsize=int(args[0])) except Exception, e: print e self.chat.InfoPost("ERROR setting default font size") def on_close(self, cmdargs): try: chatpanel = self.chat if (chatpanel.sendtarget == "all"): chatpanel.InfoPost("Error: cannot close public chat tab.") else: chatpanel.chat_timer.Stop() chatpanel.parent.destroy_private_tab(chatpanel) except: self.chat.InfoPost("Error: cannot close private chat tab.") 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)) def on_dieroller(self, cmdargs): args = string.split(cmdargs,None,-1) rm = self.chat.roller_manager try: rm.set_roller(args[0]) self.chat.SystemPost("You have changed your die roller to the <b>\"" + args[0] + "\"</b> roller.") self.settings.set_setting('dieroller',args[0]) except Exception, e: print e self.chat.InfoPost("Available die rollers: " + str(rm.get_rollers())) self.chat.InfoPost("You are using the <b>\"" + rm.get_roller() + "\"</b> die roller.") def on_ping(self, cmdargs): ct = time.clock() msg = "<ping player='"+self.session.id+"' time='"+str(ct)+"' />" self.session.outbox.put(msg) def on_log(self,cmdargs): args = string.split(cmdargs,None,-1) logfile = self.settings.get_setting( 'GameLogPrefix' ) if len( args ) == 0: self.postLoggingState() elif args[0] == "on" and logfile != '': try: while logfile[ 0 ] == ANTI_LOG_CHAR: print logfile logfile = logfile[ 1: ] except IndexError,e: self.chat.SystemPost("log filename is blank, system will *not* be logging until a valid filename is specified" ) self.settings.set_setting( 'GameLogPrefix', logfile ) return self.settings.set_setting( 'GameLogPrefix', logfile ) self.postLoggingState() elif args[0] == "off": logfile = ANTI_LOG_CHAR+logfile self.settings.set_setting( 'GameLogPrefix', logfile ) self.postLoggingState() elif args[0] == "to": if len( args ) > 1: logfile = args[1] self.settings.set_setting( 'GameLogPrefix', logfile ) else: self.chat.SystemPost('You must also specify a filename with the <em>/log to</em> command.' ) self.postLoggingState() else: self.chat.InfoPost("Unknown logging command, use 'on' or 'off'" ) def on_lines(self, cmdargs): if int(cmdargs) > 0: self.settings.set_setting('buffersize',cmdargs) self.chat.SystemPost("Maximum number of lines in chat now set to " + cmdargs) # self.chat.buftxt = cmdargs self.chat.on_buffer_size(cmdargs) else: self.chat.SystemPost("Maximum lines in chat: " + self.settings.get_setting("buffersize")) self.chat.Post() 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' 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 def on_name(self, cmdargs): #only 20 chars no more! :) if cmdargs == "": self.chat.InfoPost("**Incorrect syntax for name.") else: #txt = txt[:50] self.settings.set_setting('player', cmdargs) self.session.set_name(cmdargs) # def on_status - end # This subroutine will set the players netork status. # # !self : instance of self def on_status(self, cmdargs): if cmdargs == "": self.chat.InfoPost("Incorrect synatx for status.") else: #only 20 chars no more! :) txt = cmdargs[:20] self.session.set_text_status(txt) # def on_status - end def on_set(self, cmdargs): args = string.split(cmdargs,None,-1) keys = self.settings.get_setting_keys() if len(args) == 0: line = "<table border='2'>" for m in range(len(keys)): line += "<tr><td>" + keys[m] + "</td><td> " + self.settings.get_setting(keys[m]) + "</td></tr>" line += "</table>" self.chat.InfoPost(line) else: split_name_from_data = cmdargs.find("=") if split_name_from_data == -1: for m in keys: if m == args[0]: return_string = "<table border='2'><tr><td>" + args[0] + "</td><td>"\ + self.settings.get_setting(args[0]) + "</td></tr></table>" self.chat.InfoPost(return_string) else: name = cmdargs[:split_name_from_data].strip() for m in keys: if m == name: setting = cmdargs[split_name_from_data+1:].strip() self.settings.set_setting(name,setting) return_string = name + " changed to " + setting self.chat.InfoPost(return_string) self.session.set_name(self.settings.get_setting("player")) self.chat.set_colors() self.chat.set_buffersize() # This subroutine will display the correct usage of the different emotions. # #!self : instance of self def on_help(self, cmdargs=""): cmds = self.cmdlist.keys() cmds.sort() shortcmds = self.shortcmdlist.keys() shortcmds.sort() msg = '<br><b>Command Alias List:</b>' for shortcmd in shortcmds: msg += '<br><b><font color="#0000CC">%s</font></b> is short for <font color="#000000">%s</font>' % (shortcmd, self.shortcmdlist[shortcmd]) msg += '<br><br><b>Command List:</b>' for cmd in cmds: msg += '<br><b><font color="#000000">%s</font></b>' % (cmd) for shortcmd in shortcmds: 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 def on_ignore(self, cmdargs): args = string.split(cmdargs,None,-1) (ignore_list, ignore_name) = self.session.get_ignore_list() ignore_output = self.colorize(self.chat.syscolor,"<br><u>Player IDs Currently being Ignored:</u><br>") if cmdargs == "": if len(ignore_list) == 0: ignore_output += self.colorize(self.chat.infocolor,"No players are currently being ignored.<br>") else: for m in ignore_list: ignore_txt = m + " " + ignore_name[ignore_list.index(m)] + "<br>" ignore_output += self.colorize(self.chat.infocolor,ignore_txt) self.chat.Post(ignore_output) else: players = cmdargs.split(",") for m in players: try: id = `int(m)` (result, id, name) = self.session.toggle_ignore(id) if result == 0: self.chat.InfoPost("Player " + name + " with ID:" + id + " no longer ignored") if result == 1: self.chat.InfoPost("Player " + name + " with ID:" + id + " now being ignored") except: self.chat.InfoPost(m + " was ignored because it is an invalid player ID") traceback.print_exc() def on_role(self, cmdargs): if cmdargs == "": self.session.display_roles() return delim = cmdargs.find("=") if delim < 0: self.chat.InfoPost("**Incorrect synatax for Role." + str(delim)) return player_ids = string.split(cmdargs[:delim],",") role = cmdargs[delim+1:].strip() role = role.lower() if (role.lower() == "player") or (role.lower() == "gm") or (role.lower() == "lurker"): if role.lower() == "player": role = "Player" elif role.lower() == "gm": role = "GM" else: role = "Lurker" try: role_pwd = self.session.orpgFrame_callback.password_manager.GetPassword("admin",int(self.session.group_id)) if role_pwd != None: for m in player_ids: self.session.set_role(m.strip(),role,role_pwd) except: traceback.print_exc() # return # This subroutine implements the whisper functionality that enables a user # to whisper to another user. # # !self : instance of self # !text : string that is comprised of a list of users and the message to #whisper. def on_whisper(self, cmdargs): delim = cmdargs.find("=") if delim < 0: 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], ",") 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 #--------------------------------------------------------- def on_groupwhisper(self, cmdargs): args = string.split(cmdargs,None,-1) delim = cmdargs.find("=") 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]] = {} orpg.player_list.WG_LIST[args[2]][int(args[1])] = int(args[1]) return elif args[0] == "remove" or args[0] == "delete": del orpg.player_list.WG_LIST[args[2]][int(args[1])] if len(orpg.player_list.WG_LIST[args[2]]) == 0: del orpg.player_list.WG_LIST[args[2]] return elif args[0] == "create" or args[0] == "new_group": if not orpg.player_list.WG_LIST.has_key(args[1]): orpg.player_list.WG_LIST[args[1]] = {} return elif args[0] == "list": if orpg.player_list.WG_LIST.has_key(args[1]): for n in orpg.player_list.WG_LIST[args[1]]: player = self.session.get_player_info(str(n)) self.chat.InfoPost(str(player[0])) else: self.chat.InfoPost("Invalid Whisper Group Name") return elif args[0] == "clear": if orpg.player_list.WG_LIST.has_key(args[1]): orpg.player_list.WG_LIST[args[1]].clear() else: self.chat.InfoPost("Invalid Whisper Group Name") return elif args[0] == "clearall": orpg.player_list.WG_LIST.clear() return else: self.chat.InfoPost("<b>/gw add</b> (player_id) (group_name) - Adds [player_id] to [group_name]") self.chat.InfoPost("<b>/gw remove</b> (player_id) (group_name) - Removes [player_id] from [group_name]") self.chat.InfoPost("<b>/gw</b> (group_name)<b>=</b>(message) - Sends [message] to [group_name]") self.chat.InfoPost("<b>/gw create</b> (group_name) - Creates a whisper group called [group_name]") self.chat.InfoPost("<b>/gw list</b> (group_name) - Lists all players in [group_name]") self.chat.InfoPost("<b>/gw clear</b> (group_name) - Removes all players from [group_name]") self.chat.InfoPost("<b>/gw clearall</b> - Removes all existing whisper groups") return msg = string.strip(cmdargs[delim+1:]) 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 self.on_whisper(idList + "=" + self.settings.get_setting("gwtext") + msg) #--------------------------------------------------------- # [END] Digitalxero Multi Whisper Group 1/1/05 #--------------------------------------------------------- def on_gmwhisper(self, cmdargs): if cmdargs == "": self.chat.InfoPost("**Incorrect syntax for GM Whisper.") else: the_gms = self.chat.get_gms() if len(the_gms): gmstring = "" for each_gm in the_gms: if gmstring != "": gmstring += "," gmstring += each_gm self.on_whisper(gmstring + "=" + cmdargs) 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" 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" else: self.chat.InfoPost("Wrong syntax for moderate command!") return pwd = self.session.orpgFrame_callback.password_manager.GetPassword("admin",int(self.session.group_id)) if pwd != None: msg = "<moderate" msg += " action = '" + action + "'" msg +=" from = '" + self.session.id + "' pwd='" + pwd + "'" if (plist <> ""): msg += " users='"+plist+"'" msg += " />" self.session.outbox.put(msg) pass else: msg = "<moderate action='list' from='"+self.session.id+"' />" self.session.outbox.put(msg) self.session.update() def on_update(self, cmdargs): url = self.settings.get_setting( "PackagesBaseURL" ) Disableupdate = int(self.settings.get_setting("Disableupdate" )) updater = orpg.tools.orpg_update.orpg_update(url,self.chat.InfoPost) self.chat.InfoPost("You are running " + orpg.orpg_version.VERSION + " (build "+orpg.orpg_version.BUILD+")") p = updater.get_package() self.chat.InfoPost("The latest version is " + p.getAttribute("version") + " (build "+p.getAttribute("build")+")") is_up2date = updater.is_up2date(orpg.orpg_version.VERSION, orpg.orpg_version.BUILD) if is_up2date: self.chat.InfoPost("OpenRPG does not require updating.") else: self.chat.SystemPost("Your code is out of date!") self.chat.SystemPost("Type \"/update get\" to update to the latest version.") if cmdargs == "get" and is_up2date: self.chat.InfoPost("OpenRPG does not require updating.") elif cmdargs == "get" and not is_up2date: if not Disableupdate: dlg = orpg.orpg_windows.do_progress_dlg(self.chat,"OpenRPG Updater","Please wait while OpenRPG upates...",3) dlg.Update(1,"Please wait while OpenRPG upates...") updater.update() # set the setting back so we get new gametree features self.settings.set_setting("LoadGameTreeFeatures","1") self.chat.SystemPost("Please restart OpenRPG!") dlg.Update(2,"Done.") dlg.Destroy() def on_description(self, cmdargs): if len(cmdargs) <= 0: self.chat.InfoPost("**No description text to display." + str(delim)) return mesg = "<table bgcolor='#c0c0c0' border='3' cellpadding='5' cellspacing='0' width='100%'><tr><td><font color='#000000'>" mesg += string.strip(cmdargs) mesg += "</font></td></tr></table>" self.chat.Post(mesg) self.chat.send_chat_message(mesg) def invoke_tab(self, cmdargs): ######START mDuo13's Tab Initiator######## playerid = cmdargs.strip() tabbed_whispers_p = self.settings.get_setting("tabbedwhispers") panelexists = 0 if (tabbed_whispers_p == "1"): # Check to see if parent notebook already has a private tab for player for panel in self.chat.parent.panel_list: if (panel.sendtarget == playerid): self.chat.Post("Cannot invoke tab: Tab already exists.") return try: displaypanel = self.chat.parent.create_private_tab(playerid) except: self.chat.Post("That ID# is not valid.") return cidx = self.chat.parent.GetSelection() nidx = self.chat.parent.get_tab_index(displaypanel) self.chat.parent.SetSelection(nidx) self.chat.parent.SetSelection(cidx) self.chat.parent.SetPageImage(nidx, self.chat.parent.chatAttentionIdx) return else: self.chat.Post("Cannot invoke tab: Tabbed whispering is disabled.") return #######END mDuo13's Tab Initiator######### def on_remote_admin(self, cmdargs): args = string.split(cmdargs,None,-1) #handles remote administration commands try: pass_state = 0 pwd = self.session.orpgFrame_callback.password_manager.GetSilentPassword("server") if pwd != None: pass_state = 1 else: pwd = "<i>[NONE]</i>" if len( args ) == 0: #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>" self.chat.SystemPost(msg) return if pass_state != 1 and args[0] != "set": #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+"\" " 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"))+"\"" ) else: pwd = self.session.orpgFrame_callback.password_manager.GetPassword("server") if pwd != None: self.chat.SystemPost( "Remote administration commands using password: \""+pwd+"\"" ) 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: self.chat.SystemPost( "You must supply a name and boot password at least. <br>/admin createroom <name> <boot password> [password]" ) return if len( args ) < 3: self.chat.SystemPost( "You must supply a boot password also.<br>/admin createroom <name> <boot password> [password]" ) return if len( args ) < 4: cmdlist.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])+"\" />" 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) else: self.chat.InfoPost("Unknown administrator command" ) except: self.chat.InfoPost("An error has occured while processing a Remote Administrator command!") traceback.print_exc() --- NEW FILE: chat_version.py --- ## this file hold the chat version ## CHAT_VERSION = "1.0" --- NEW FILE: chat_util.py --- # utility function; see Post() in chatwnd.py import re #============================================ # simple_html_repair(string) # # Crude html/xml parser/verifier. # Catches many mistyped and/or malformed # html tags and prevents them from causing # issues with the chat display (see chatwnd.py) # DOES NOT catch misused but properly formated # html like <script> or <li> which are known # to cause issues with the chat display # # Created 04-25-2005 by Snowdog #============================================= def simple_html_repair(string): "Returns string with extra > symbols to isolate badly formated HTML" #walk though string checking positions of < and > tags. first_instance = string.find('<') if first_instance == -1: return string #no html, bail out. #strip string of an instances of ">>" and "<<" recursively #while (string.find(">>") != -1):string = string.replace(">>",">") while (string.find("<<") != -1):string = string.replace("<<","<") last_start = first_instance in_tag_flag = 1 a = first_instance + 1 while a < len(string): if string[a] == '<': if in_tag_flag == 1: #attempt to figure out best place to put missing > #search from last_start to current position at_front = 1 for best_pos in range(last_start,a): if (str(string[best_pos]).isspace())and (at_front == 0): break else: at_front = 0 best_pos = best_pos + 1 a = best_pos string = string[:a]+">"+string[a:] in_tag_flag = 0 #jump back up one character to catch the last > and reset the in_tag_flag a = a - 1 else: in_tag_flag = 1 last_start = a if string[a] == '>': last_start = a #found a closing tag, move start of scan block up. in_tag_flag = 0 if (a >= (len(string)-1))and(in_tag_flag == 1): #at end of string and need a closing tag marker string = string +">" a = a+1 #strip string of an instances of "<>" string = string.replace("<>","") #sanity check. Count the < and > characters, if there arn't enough > chars #tack them on the end to avoid open-tag conditions diff = string.count('<') - string.count('>') if diff > 0: for d in range(1,diff): string = string+">" return string #================================================ # strip_script_tags(string) # # removes all script tags (start and end) # 04-26-2005 Snowdog #================================================ def strip_script_tags(string): #kill the <script> issue p = re.compile( '<(\s*)(/*)[Ss][Cc][Rr][Ii][Pp][Tt](.*?)>') string = p.sub( "<!-- script tag removed //-->", string) return string #================================================ # strip_li_tags(string) # # removes all li tags (start and end) # 05-13-2005 #================================================ def strip_li_tags(string): #kill the <li> issue string = re.sub( r'<(\s*)[Ll][Ii](.*?)>', r'<b><font color="#000000" size=+1>*</font></b> ', string) string = re.sub( r'<(/*)[Ll][Ii](.*?)>', r'<br>', string) return string #================================================ # strip_body_tags(string) # # removes all body tags (start and end) from messages # should not break the setting of custom background colors # through legitimate means such as the OpenRPG settings. # 07-27-2005 by mDuo13 #================================================ def strip_body_tags(string): bodytag_regex = re.compile(r"""<\/?body.*?>""", re.I) string = re.sub(bodytag_regex, "", string) return string #================================================ # strip_misalignment_tags(string) # # removes the alignment aspect of <p> tags, since # simply closing one doesn't actually fix the text # alignment. (I'm assuming this is a bug in wxWindows' # html parser.) # However, closing <center> tags does # return the text to its normal alignment, so this # algorithm simply closes them, allowing them to be # used legitimately without causing much annoyance. # 07-27-2005 mDuo13 #================================================ def strip_misalignment_tags(string): alignment_regex = re.compile(r"""<p([^>]*?)align\s*=\s*('.*?'|".*?"|[^\s>]*)(.*?)>""", re.I) string = re.sub(alignment_regex, "<p\\1\\3>", string) center_regex = re.compile(r"""<center.*?>""", re.I) endcenter_regex = re.compile(r"""</center.*?>""", re.I) num_centertags = center_regex.findall(string) num_endcentertags = endcenter_regex.findall(string) if num_centertags > num_endcentertags: missing_tags = len(num_centertags) - len(num_endcentertags) string = string + missing_tags*"</center>"#yes, you can do this. return string #================================================ # strip_img_tags(string) # # removes all img tags (start and end) # 05-13-2005 # redone 07-11-2005 by mDuo13 #================================================ def strip_img_tags(string): #This is a Settings definable feature, Allowing users to enable or disable image display to fix the client crash due to large img posted to chat. #p = re.sub( r'<(\s*)(/*)[Ii][Mm][Gg][ ][Ss][Rr][Cc][=](.*?)>', r'<!-- img tag removed //--> <a href=\3>\3</a>', string) #this regex is substantially more powerful than the one above img_tag_regex = re.compile(r"""<img.*?src\s*?=\s*('.*?'|".*?"|[^\s>]*).*?>""", re.I) #this is what replaces the regex match. the \\1 refers to the URL from the previous string img_repl_str = "<a href=\\1>[img]</a>" #replaces all instances of images in the string with links p = re.sub(img_tag_regex, img_repl_str, string) return p |