comparison orpg/chat/commands.py @ 0:4385a7d0efd1 grumpy-goblin

Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author sirebral
date Tue, 14 Jul 2009 16:41:58 -0500
parents
children 449a8900f9ac
comparison
equal deleted inserted replaced
-1:000000000000 0:4385a7d0efd1
1 # This class implements the basic chat commands available in the chat interface.
2 #
3 # Defines:
4 # __init__(self,chat)
5 # docmd(self,text)
6 # on_help(self)
7 # on_whisper(self,text)
8 #
9
10
11 import string
12 import time
13 import orpg.orpg_version
14 import orpg.orpg_windows
15 import traceback
16
17 ##--------------------------------------------------------------
18 ## dynamically loading module for extended developer commands
19 ## allows developers to work on new chat commands without
20 ## integrating them directly into the ORPG code allowing
21 ## updating of their code without merging changes
22 ## cmd_ext.py should NOT be included in the CVS or Actual Releases
23
24 try:
25 import cmd_ext
26 print "Importing Developer Extended Command Set"
27 except:
28 pass
29 ##----------------------------------------------------------------
30
31 ANTI_LOG_CHAR = '!'
32
33 class chat_commands:
34
35 # Initialization subroutine.
36 #
37 # !self : instance of self
38 # !chat : instance of the chat window to write to
39 def __init__(self,chat):
40 self.post = chat.Post
41 self.colorize = chat.colorize
42 self.session = chat.session
43 #self.send = chat.session.send
44 self.settings = chat.settings
45 self.chat = chat
46 self.cmdlist = {}
47 self.shortcmdlist = {}
48 self.defaultcmds()
49 self.defaultcmdalias()
50 # def __init__ - end
51 self.previous_whisper = []
52
53
54 # This subroutine will take a text string and attempt to match to a series
55 # of implemented emotions.
56 #
57 # !self : instance of self
58 # !text : string of text matching an implemented emotion
59 def addcommand(self, cmd, function, helpmsg):
60 if not self.cmdlist.has_key(cmd) and not self.shortcmdlist.has_key(cmd):
61 self.cmdlist[cmd] = {}
62 self.cmdlist[cmd]['function'] = function
63 self.cmdlist[cmd]['help'] = helpmsg
64 #print 'Command Added: ' + cmd
65
66 def addshortcmd(self, shortcmd, longcmd):
67 if not self.shortcmdlist.has_key(shortcmd) and not self.cmdlist.has_key(shortcmd):
68 self.shortcmdlist[shortcmd] = longcmd
69
70 def removecmd(self, cmd):
71 if self.cmdlist.has_key(cmd):
72 del self.cmdlist[cmd]
73 elif self.shortcmdlist.has_key(cmd):
74 del self.shortcmdlist[cmd]
75
76 #print 'Command Removed: ' + cmd
77
78
79 def defaultcmds(self):
80 self.addcommand('/help', self.on_help, '- Displays this help message')
81 self.addcommand('/version', self.on_version, ' - Displays current version of OpenRPG.')
82 self.addcommand('/me', self.chat.emote_message, ' - Alias for **yourname does something.**')
83 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 only not toggle.')
84 self.addcommand('/load', self.on_load, 'filename - Loads settings from another ini file from the myfiles directory.')
85 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.')
86 self.addcommand('/font', self.on_font, 'fontname - Sets the font.')
87 self.addcommand('/fontsize', self.on_fontsize, 'size - Sets the size of your fonts. Recomended 8 or better for the size.')
88 self.addcommand('/close', self.on_close, 'Close the chat tab')
89 self.addcommand('/set', self.on_set, '[setting[=value]] - Displays one or all settings, self.or sets a setting.')
90 self.addcommand('/whisper', self.on_whisper, 'player_id_number, ... = message - Whisper to player(s). Can contain multiple IDs.')
91 self.addcommand('/gw', self.on_groupwhisper, 'group_name=message - Type /gw help for more information')
92 self.addcommand('/gm', self.on_gmwhisper, 'message - Whispers to all GMs in the room')
93 self.addcommand('/name', self.on_name, 'name - Change your name.')
94 self.addcommand('/time', self.on_time, '- Display the local and GMT time and date.')
95 self.addcommand('/status', self.on_status, 'your_status - Set your online status (afk,away,etc..).')
96 self.addcommand('/dieroller', self.on_dieroller, '- Set your dieroller or list the available rollers.')
97 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.')
98 self.addcommand('/update', self.on_update, '[get] - Get the latest version of OpenRPG.')
99 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.')
100 self.addcommand('/tab', self.invoke_tab, 'player_id - Creates a tab so you can whisper rolls to youror what ever')
101 self.addcommand('/ping', self.on_ping, '- Ask for a response from the server.')
102 self.addcommand('/admin', self.on_remote_admin, '- Remote admin commands')
103 self.addcommand('/description', self.on_description, 'message - Creates a block of text, used for room descriptions and such')
104 self.addcommand('/sound', self.on_sound, 'Sound_URL - Plays a sound for all clients in the room.')
105 self.addcommand('/purge', self.on_purge, 'This will clear the entire chat window')
106 self.addcommand('/advfilter', self.on_filter, 'This will toggle the Advanced Filter')
107
108 def defaultcmdalias(self):
109 self.addshortcmd('/?', '/help')
110 self.addshortcmd('/he', '/me')
111 self.addshortcmd('/she', '/me')
112 self.addshortcmd('/i', '/ignore')
113 self.addshortcmd('/w', '/whisper')
114 self.addshortcmd('/nick', '/name')
115 self.addshortcmd('/date', '/time')
116 self.addshortcmd('/desc', '/description')
117 self.addshortcmd('/d', '/description')
118
119 #This is just an example or a differant way the shorcmd can be used
120 self.addshortcmd('/sleep', '/me falls asleep')
121
122
123 def docmd(self,text):
124 cmdsearch = string.split(text,None,1)
125 cmd = string.lower(cmdsearch[0])
126 start = len(cmd)
127 end = len(text)
128 cmdargs = text[start+1:end]
129
130 if self.cmdlist.has_key(cmd):
131 self.cmdlist[cmd]['function'](cmdargs)
132 elif self.shortcmdlist.has_key(cmd):
133 self.docmd(self.shortcmdlist[cmd] + " " + cmdargs)
134 else:
135 msg = "Sorry I don't know what %s is!" % (cmd)
136 self.chat.InfoPost(msg)
137
138 def on_filter(self, cmdargs):
139 #print self.chat.advancedFilter
140 test = not self.chat.advancedFilter
141 #print test
142
143 for tab in self.chat.parent.whisper_tabs:
144 tab.advancedFilter = not self.chat.advancedFilter
145
146 for tab in self.chat.parent.null_tabs:
147 tab.advancedFilter = not self.chat.advancedFilter
148
149 for tab in self.chat.parent.group_tabs:
150 tab.advancedFilter = not self.chat.advancedFilter
151
152 if self.chat.parent.GMChatPanel != None:
153 self.chat.parent.GMChatPanel.advancedFilter = not self.chat.advancedFilter
154
155 self.chat.advancedFilter = not self.chat.advancedFilter
156
157 if self.chat.advancedFilter:
158 self.chat.InfoPost("Advanced Filtering has been turned On")
159 else:
160 self.chat.InfoPost("Advanced Filtering has been turned Off")
161
162 def on_purge(self, cmdargs):
163 self.chat.PurgeChat()
164 self.chat.InfoPost('Chat Buffer has been Purged!')
165
166 def on_sound(self, cmdargs):
167 if len(cmdargs) < 8:
168 self.chat.InfoPost("You must provide a URL for the file name, it does not work for just local sound files")
169 return
170 args = string.split(cmdargs, None, -1)
171
172 if args[0] == 'loop':
173 snd = args[1].replace('&', '&amp;')
174 loop = '1'
175 else:
176 snd = cmdargs.replace('&', '&amp;')
177 loop = ''
178
179 type = 'remote'
180
181 (name, ip, id, text_status, version, protocol_version, client_string, role) = self.session.get_my_info()
182 group_id = self.session.group_id
183 if (role != 'Lurker' and group_id != '0') or self.session.get_status() != 1:
184 try:
185 self.chat.sound_player.play(snd, type, loop)
186 if type == 'remote':
187 snd_xml = '<sound url="' + snd + '" group_id="' + group_id + '" from="' + id + '" loop="' + str(loop) + '" />'
188 self.session.send_sound(snd_xml)
189 except Exception, e:
190 print e
191 self.chat.InfoPost("Invalid sound file!")
192 elif role == 'Lurker':
193 self.chat.InfoPost("You must be a player or a GM to send a sound file!")
194 elif group_id == '0':
195 self.chat.InfoPost("You cannot send sound files to the lobby!")
196 else:
197 self.chat.InfoPost("Something dun fuckered up Frank!")
198
199 def on_version(self, cmdargs=""):
200 self.chat.InfoPost("Version is OpenRPG " + self.chat.version)
201
202 def on_load(self, cmdargs):
203 args = string.split(cmdargs,None,-1)
204 try:
205 self.settings.setup_ini(args[0])
206 self.settings.reload_settings(self.chat)
207 self.chat.InfoPost("Settings Loaded from file " + args[0] )
208 except Exception,e:
209 print e
210 self.chat.InfoPost("ERROR Loading settings")
211
212 def on_font(self, cmdargs):
213 try:
214 fontsettings = self.chat.set_default_font(fontname=cmdargs, fontsize=None)
215 except:
216 self.chat.InfoPost("ERROR setting default font")
217
218 def on_fontsize(self, cmdargs):
219 args = string.split(cmdargs,None,-1)
220 try:
221 fontsettings = self.chat.set_default_font(fontname=None, fontsize=int(args[0]))
222 except Exception, e:
223 print e
224 self.chat.InfoPost("ERROR setting default font size")
225
226 def on_close(self, cmdargs):
227 try:
228 chatpanel = self.chat
229 if (chatpanel.sendtarget == "all"):
230 chatpanel.InfoPost("Error: cannot close public chat tab.")
231 else:
232 chatpanel.chat_timer.Stop()
233 chatpanel.parent.onCloseTab(0)
234 except:
235 self.chat.InfoPost("Error: cannot close private chat tab.")
236
237 def on_time(self, cmdargs):
238 local_time = time.localtime()
239 gmt_time = time.gmtime()
240 format_string = "%A %b %d, %Y %I:%M:%S%p"
241 self.chat.InfoPost("<br />Local: " + time.strftime(format_string)+\
242 "<br />GMT: "+time.strftime(format_string,gmt_time))
243
244 def on_dieroller(self, cmdargs):
245 args = string.split(cmdargs,None,-1)
246 rm = self.chat.DiceManager
247 try:
248 rm.setRoller(args[0])
249 self.chat.SystemPost("You have changed your die roller to the <b>\"" + args[0] + "\"</b> roller.")
250 self.settings.set_setting('dieroller',args[0])
251 except Exception, e:
252 print e
253 self.chat.InfoPost("Available die rollers: " + str(rm.listRollers()))
254 self.chat.InfoPost("You are using the <b>\"" + rm.getRoller() + "\"</b> die roller.")
255
256 def on_ping(self, cmdargs):
257 ct = time.clock()
258 msg = "<ping player='"+self.session.id+"' time='"+str(ct)+"' />"
259 self.session.outbox.put(msg)
260
261 def on_log(self,cmdargs):
262 args = string.split(cmdargs,None,-1)
263 logfile = self.settings.get_setting( 'GameLogPrefix' )
264
265 if len( args ) == 0:
266 self.postLoggingState()
267 elif args[0] == "on" and logfile != '':
268 try:
269 while logfile[ 0 ] == ANTI_LOG_CHAR:
270 #print logfile
271 logfile = logfile[ 1: ]
272 except IndexError,e:
273 self.chat.SystemPost("log filename is blank, system will *not* be logging until a valid filename is specified" )
274 self.settings.set_setting( 'GameLogPrefix', logfile )
275 return
276 self.settings.set_setting( 'GameLogPrefix', logfile )
277 self.postLoggingState()
278 elif args[0] == "off":
279 logfile = ANTI_LOG_CHAR+logfile
280 self.settings.set_setting( 'GameLogPrefix', logfile )
281 self.postLoggingState()
282 elif args[0] == "to":
283 if len( args ) > 1:
284 logfile = args[1]
285 self.settings.set_setting( 'GameLogPrefix', logfile )
286 else:
287 self.chat.SystemPost('You must also specify a filename with the <em>/log to</em> command.' )
288 self.postLoggingState()
289 else:
290 self.chat.InfoPost("Unknown logging command, use 'on' or 'off'" )
291
292 def postLoggingState( self ):
293 logfile = self.settings.get_setting( 'GameLogPrefix' )
294 try:
295 if logfile[0] != ANTI_LOG_CHAR:
296 comment = 'is'
297 else:
298 comment = 'is not'
299 except:
300 comment = 'is not'
301 suffix = time.strftime( '-%d-%m-%y.html', time.localtime( time.time() ) )
302 self.chat.InfoPost('Log filename is "%s%s", system is %s logging.' % (logfile, suffix, comment) )
303
304 # This subroutine will set the players netork status.
305 #
306 #!self : instance of self
307
308 def on_name(self, cmdargs):
309 #only 20 chars no more! :)
310 if cmdargs == "":
311 self.chat.InfoPost("**Incorrect syntax for name.")
312 else:
313 #txt = txt[:50]
314 self.settings.set_setting('player', cmdargs)
315 self.session.set_name(str(cmdargs))
316
317 # def on_status - end
318
319 # This subroutine will set the players netork status.
320 #
321 # !self : instance of self
322 def on_status(self, cmdargs):
323 if cmdargs == "":
324 self.chat.InfoPost("Incorrect synatx for status.")
325 else:
326 #only 20 chars no more! :)
327 txt = cmdargs[:20]
328 self.session.set_text_status(str(txt))
329 # def on_status - end
330
331 def on_set(self, cmdargs):
332 args = string.split(cmdargs,None,-1)
333 keys = self.settings.get_setting_keys()
334 #print keys
335 if len(args) == 0:
336 line = "<table border='2'>"
337 for m in keys:
338 line += "<tr><td>" + str(m) + "</td><td> " + str(self.settings.get_setting(m)) + "</td></tr>"
339 line += "</table>"
340 self.chat.InfoPost(line)
341 else:
342 split_name_from_data = cmdargs.find("=")
343 if split_name_from_data == -1:
344 for m in keys:
345 if m == args[0]:
346 return_string = "<table border='2'><tr><td>" + args[0] + "</td><td>"\
347 + self.settings.get_setting(args[0]) + "</td></tr></table>"
348 self.chat.InfoPost(return_string)
349 else:
350 name = cmdargs[:split_name_from_data].strip()
351 for m in keys:
352 if m == name:
353 setting = cmdargs[split_name_from_data+1:].strip()
354 self.settings.set_setting(name,setting)
355 return_string = name + " changed to " + setting
356 self.chat.InfoPost(return_string)
357 self.session.set_name(self.settings.get_setting("player"))
358 self.chat.set_colors()
359 self.chat.set_buffersize()
360
361 # This subroutine will display the correct usage of the different emotions.
362 #
363 #!self : instance of self
364
365 def on_help(self, cmdargs=""):
366 cmds = self.cmdlist.keys()
367 cmds.sort()
368 shortcmds = self.shortcmdlist.keys()
369 shortcmds.sort()
370 msg = '<br /><b>Command Alias List:</b>'
371 for shortcmd in shortcmds:
372 msg += '<br /><b><font color="#0000CC">%s</font></b> is short for <font color="#000000">%s</font>' % (shortcmd, self.shortcmdlist[shortcmd])
373 msg += '<br /><br /><b>Command List:</b>'
374 for cmd in cmds:
375 msg += '<br /><b><font color="#000000">%s</font></b>' % (cmd)
376 for shortcmd in shortcmds:
377 if self.shortcmdlist[shortcmd] == cmd:
378 msg += ', <b><font color="#0000CC">%s</font></b>' % (shortcmd)
379 msg += ' %s' % (self.cmdlist[cmd]['help'])
380
381 self.chat.InfoPost(msg)
382
383 # This subroutine will either show the list of currently ignored users
384 # !self : instance of self
385 # !text : string that is comprised of a list of users to toggle the ignore flag
386
387 def on_ignore(self, cmdargs):
388 args = string.split(cmdargs,None,-1)
389 (ignore_list, ignore_name) = self.session.get_ignore_list()
390 ignore_output = self.colorize(self.chat.syscolor,"<br /><u>Player IDs Currently being Ignored:</u><br />")
391 if cmdargs == "":
392 if len(ignore_list) == 0:
393 ignore_output += self.colorize(self.chat.infocolor,"No players are currently being ignored.<br />")
394 else:
395 for m in ignore_list:
396 ignore_txt = m + " " + ignore_name[ignore_list.index(m)] + "<br />"
397 ignore_output += self.colorize(self.chat.infocolor,ignore_txt)
398 self.chat.Post(ignore_output)
399 else:
400 players = cmdargs.split(",")
401 for m in players:
402 try:
403 id = `int(m)`
404 (result, id, name) = self.session.toggle_ignore(id)
405 if result == 0:
406 self.chat.InfoPost("Player " + name + " with ID:" + id + " no longer ignored")
407 if result == 1:
408 self.chat.InfoPost("Player " + name + " with ID:" + id + " now being ignored")
409 except:
410 self.chat.InfoPost(m + " was ignored because it is an invalid player ID")
411 traceback.print_exc()
412
413 def on_role(self, cmdargs):
414 if cmdargs == "":
415 self.session.display_roles()
416 return
417 delim = cmdargs.find("=")
418 if delim < 0:
419 self.chat.InfoPost("**Incorrect synatax for Role." + str(delim))
420 return
421 player_ids = string.split(cmdargs[:delim],",")
422 role = cmdargs[delim+1:].strip()
423 role = role.lower()
424 if (role.lower() == "player") or (role.lower() == "gm") or (role.lower() == "lurker"):
425 if role.lower() == "player": role = "Player"
426 elif role.lower() == "gm": role = "GM"
427 else: role = "Lurker"
428 try:
429 role_pwd = self.session.orpgFrame_callback.password_manager.GetPassword("admin",int(self.session.group_id))
430 if role_pwd != None:
431 for m in player_ids:
432 self.session.set_role(m.strip(),role,role_pwd)
433 except:
434 traceback.print_exc()
435 # return
436
437 # This subroutine implements the whisper functionality that enables a user
438 # to whisper to another user.
439 #
440 # !self : instance of self
441 # !text : string that is comprised of a list of users and the message to
442 #whisper.
443
444 def on_whisper(self, cmdargs):
445 delim = cmdargs.find("=")
446
447 if delim < 0:
448 if self.previous_whisper:
449 player_ids = self.previous_whisper
450 else:
451 self.chat.InfoPost("**Incorrect syntax for whisper." + str(delim))
452 return
453 else:
454 player_ids = string.split(cmdargs[:delim], ",")
455 self.previous_whisper = player_ids
456 mesg = string.strip(cmdargs[delim+1:])
457 self.chat.whisper_to_players(mesg,player_ids)
458
459 #---------------------------------------------------------
460 # [START] Digitalxero Multi Whisper Group 1/1/05
461 #---------------------------------------------------------
462 def on_groupwhisper(self, cmdargs):
463 args = string.split(cmdargs,None,-1)
464 delim = cmdargs.find("=")
465
466 if delim > 0:
467 group_ids = string.split(cmdargs[:delim], ",")
468 elif args[0] == "add":
469 if not orpg.player_list.WG_LIST.has_key(args[2]):
470 orpg.player_list.WG_LIST[args[2]] = {}
471 orpg.player_list.WG_LIST[args[2]][int(args[1])] = int(args[1])
472 return
473 elif args[0] == "remove" or args[0] == "delete":
474 del orpg.player_list.WG_LIST[args[2]][int(args[1])]
475 if len(orpg.player_list.WG_LIST[args[2]]) == 0:
476 del orpg.player_list.WG_LIST[args[2]]
477 return
478 elif args[0] == "create" or args[0] == "new_group":
479 if not orpg.player_list.WG_LIST.has_key(args[1]):
480 orpg.player_list.WG_LIST[args[1]] = {}
481 return
482 elif args[0] == "list":
483 if orpg.player_list.WG_LIST.has_key(args[1]):
484 for n in orpg.player_list.WG_LIST[args[1]]:
485 player = self.session.get_player_info(str(n))
486 self.chat.InfoPost(str(player[0]))
487 else:
488 self.chat.InfoPost("Invalid Whisper Group Name")
489 return
490 elif args[0] == "clear":
491 if orpg.player_list.WG_LIST.has_key(args[1]):
492 orpg.player_list.WG_LIST[args[1]].clear()
493 else:
494 self.chat.InfoPost("Invalid Whisper Group Name")
495 return
496 elif args[0] == "clearall":
497 orpg.player_list.WG_LIST.clear()
498 return
499 else:
500 self.chat.InfoPost("<b>/gw add</b> (player_id) (group_name) - Adds [player_id] to [group_name]")
501 self.chat.InfoPost("<b>/gw remove</b> (player_id) (group_name) - Removes [player_id] from [group_name]")
502 self.chat.InfoPost("<b>/gw</b> (group_name)<b>=</b>(message) - Sends [message] to [group_name]")
503 self.chat.InfoPost("<b>/gw create</b> (group_name) - Creates a whisper group called [group_name]")
504 self.chat.InfoPost("<b>/gw list</b> (group_name) - Lists all players in [group_name]")
505 self.chat.InfoPost("<b>/gw clear</b> (group_name) - Removes all players from [group_name]")
506 self.chat.InfoPost("<b>/gw clearall</b> - Removes all existing whisper groups")
507 return
508 msg = string.strip(cmdargs[delim+1:])
509 for gid in group_ids:
510 idList = ""
511 for n in orpg.player_list.WG_LIST[gid]:
512 if idList == "":
513 idList = str(n)
514 else:
515 idList = str(n) + ", " + idList
516 self.on_whisper(idList + "=" + self.settings.get_setting("gwtext") + msg)
517
518 #---------------------------------------------------------
519 # [END] Digitalxero Multi Whisper Group 1/1/05
520 #---------------------------------------------------------
521
522 def on_gmwhisper(self, cmdargs):
523 if cmdargs == "":
524 self.chat.InfoPost("**Incorrect syntax for GM Whisper.")
525 else:
526 the_gms = self.chat.get_gms()
527 if len(the_gms):
528 gmstring = ""
529 for each_gm in the_gms:
530 if gmstring != "":
531 gmstring += ","
532 gmstring += each_gm
533 self.on_whisper(gmstring + "=" + cmdargs)
534 else:
535 self.chat.InfoPost("**No GMs to Whisper to.")
536
537 def on_moderate(self, cmdargs):
538 if cmdargs != "":
539 pos = cmdargs.find("=")
540 if (pos < 0):
541 plist = ""
542 if cmdargs.lower() == "on":
543 action = "enable"
544 elif cmdargs.lower() == "off":
545 action="disable"
546 else:
547 self.chat.InfoPost("Wrong syntax for moderate command!")
548 return
549 else:
550 plist = string.strip(cmdargs[:pos])
551 tag = string.strip(cmdargs[pos+1:])
552 if tag.lower() == "on":
553 action = "addvoice"
554 elif tag.lower() == "off":
555 action = "delvoice"
556 else:
557 self.chat.InfoPost("Wrong syntax for moderate command!")
558 return
559 pwd = self.session.orpgFrame_callback.password_manager.GetPassword("admin",int(self.session.group_id))
560 if pwd != None:
561 msg = "<moderate"
562 msg += " action = '" + action + "'"
563 msg +=" from = '" + self.session.id + "' pwd='" + pwd + "'"
564 if (plist != ""):
565 msg += " users='"+plist+"'"
566 msg += " />"
567 self.session.outbox.put(msg)
568 pass
569 else:
570 msg = "<moderate action='list' from='"+self.session.id+"' />"
571 self.session.outbox.put(msg)
572 self.session.update()
573
574 def on_update(self, cmdargs):
575 self.chat.InfoPost("This command is no longer valid")
576
577 def on_description(self, cmdargs):
578 if len(cmdargs) <= 0:
579 self.chat.InfoPost("**No description text to display." + str(delim))
580 return
581 mesg = "<table bgcolor='#c0c0c0' border='3' cellpadding='5' cellspacing='0' width='100%'><tr><td><font color='#000000'>"
582 mesg += string.strip(cmdargs)
583 mesg += "</font></td></tr></table>"
584 self.chat.Post(mesg)
585 self.chat.send_chat_message(mesg)
586
587 def invoke_tab(self, cmdargs):
588 ######START mDuo13's Tab Initiator########
589 try:
590 int(cmdargs)
591 playerid = cmdargs.strip()
592 # Check to see if parent notebook already has a private tab for player
593 for panel in self.chat.parent.whisper_tabs:
594 if (panel.sendtarget == playerid):
595 self.chat.Post("Cannot invoke tab: Tab already exists.")
596 return
597 try:
598 displaypanel = self.chat.parent.create_whisper_tab(playerid)
599 except:
600 self.chat.Post("That ID# is not valid.")
601 return
602 nidx = self.chat.parent.get_tab_index(displaypanel)
603 self.chat.parent.newMsg(nidx)
604 return
605 except:
606 displaypanel = self.chat.parent.create_null_tab(cmdargs)
607 nidx = self.chat.parent.get_tab_index(displaypanel)
608 self.chat.parent.newMsg(nidx)
609 return
610 #######END mDuo13's Tab Initiator#########
611
612 def on_remote_admin(self, cmdargs):
613 args = string.split(cmdargs,None,-1)
614 #handles remote administration commands
615 try:
616 pass_state = 0
617 pwd = self.session.orpgFrame_callback.password_manager.GetSilentPassword("server")
618 if pwd != None:
619 pass_state = 1
620 else: pwd = "<i>[NONE]</i>"
621
622 if len( args ) == 0:
623 #raw command return state info
624 msg = "<br /><b>Remote Administrator Config:</b>"
625 if pass_state != 1 : msg += " Password not set. Remote admin functions disabled<br />"
626 else:
627 msg += " Enabled. Using password \""+pwd+"\"<br />"
628 self.chat.SystemPost(msg)
629 return
630
631 if pass_state != 1 and args[0] != "set":
632 #no commands under this point will execute unless an admin password has been previously set
633 self.chat.SystemPost("Command ignored. No remote administrator password set!!")
634 return
635 msgbase = "<admin id=\""+self.session.id+"\" group_id=\""+self.session.group_id+"\" pwd=\""+pwd+"\" "
636 if args[0] == "set":
637 if len( args ) > 1:
638 self.session.orpgFrame_callback.password_manager.server = str( args[1] )
639 self.chat.SystemPost( "Remote administration commands using password: \""+str(self.session.orpgFrame_callback.password_manager.GetSilentPassword("server"))+"\"" )
640 else:
641 pwd = self.session.orpgFrame_callback.password_manager.GetPassword("server")
642 if pwd != None:
643 self.chat.SystemPost( "Remote administration commands using password: \""+pwd+"\"" )
644
645 elif args[0] == "ban":
646 #Ban a player from the server
647 msg = msgbase + ' cmd="ban" bid="' + str(args[1]) + '" />'
648 self.session.outbox.put(msg)
649
650 elif args[0] == "banip":
651 #Ban a player from the server
652 try:
653 bname = str(args[2])
654 except:
655 bname = 'Unknown'
656 msg = msgbase + ' cmd="banip" bip="' + str(args[1]) + '" bname="' + bname + '"/>'
657 self.session.outbox.put(msg)
658
659 elif args[0] == "unban":
660 #remove a group from the server and drop all players within the group
661 msg = msgbase + ' cmd="unban" ip="' + str(args[1]) + '" />'
662 self.session.outbox.put(msg)
663
664 elif args[0] == "banlist":
665 #remove a group from the server and drop all players within the group
666 msg = msgbase + ' cmd="banlist" />'
667 self.session.outbox.put(msg)
668
669 elif args[0] == "help":
670 #request help from server
671 msg = msgbase + " cmd=\"help\" />"
672 self.session.outbox.put(msg)
673
674 elif args[0] == "nameroom":
675 #reqest room renaming on server
676 msg = msgbase + " cmd=\"nameroom\" rmid=\""+ str(args[1])+"\" name=\""+ string.join(args[2:])+"\" />"
677 self.session.outbox.put(msg)
678
679 elif args[0] == "roompasswords":
680 #reqest room renaming on server
681 msg = msgbase + " cmd=\"roompasswords\"/>"
682 self.session.outbox.put(msg)
683
684 elif args[0] == "message":
685 #send message to a specific player on the server via the system administrator
686 msg = msgbase + " cmd=\"message\" to_id=\""+ str(args[1])+"\" msg=\""+ string.join(args[2:])+"\" />"
687 self.session.outbox.put(msg)
688
689 elif args[0] == "broadcast":
690 #send a message to all players on server from the system administrator
691 msg = msgbase + " cmd=\"broadcast\" msg=\""+ string.join(args[1:])+"\" />"
692 self.session.outbox.put(msg)
693
694 elif args[0] == "killgroup":
695 #remove a group from the server and drop all players within the group
696 msg = msgbase + " cmd=\"killgroup\" gid=\""+ str(args[1])+"\" />"
697 self.session.outbox.put(msg)
698
699 elif args[0] == "uptime":
700 #request uptime report from server
701 msg = msgbase + " cmd=\"uptime\" />"
702 self.session.outbox.put(msg)
703
704 elif args[0] == "createroom":
705 #request creation of a (temporary) persistant room
706 if len(args) < 2:
707 self.chat.SystemPost( "You must supply a name and boot password at least. <br />/admin createroom &lt;name&gt; &lt;boot password&gt; [password]" )
708 return
709 if len(args) < 3:
710 self.chat.SystemPost( "You must supply a boot password also.<br />/admin createroom &lt;name&gt; &lt;boot password&gt; [password]" )
711 return
712 if len(args) < 4: args.append("")
713 msg = msgbase + " cmd=\"createroom\" name=\""+str(args[1])+"\" boot=\""+ str(args[2])+"\" pass=\""+ str(args[3])+"\" />"
714 self.session.outbox.put(msg)
715
716 elif args[0] == "passwd":
717 #request boot password change on a room
718 msg = msgbase + " cmd=\"passwd\" gid=\""+str(args[1])+"\" pass=\""+ str(args[2])+"\" />"
719 self.session.outbox.put(msg)
720
721 elif args[0] == "list":
722 #request a list of rooms and players from server
723 msg = msgbase + " cmd=\"list\" />"
724 self.session.outbox.put(msg)
725
726 elif args[0] == "killserver":
727 #remotely kill the server
728 msg = msgbase + " cmd=\"killserver\" />"
729 self.session.outbox.put(msg)
730
731 elif args[0] == "savemaps":
732 msg = msgbase + ' cmd="savemaps" />'
733 self.session.outbox.put(msg)
734
735 else:
736 self.chat.InfoPost("Unknown administrator command" )
737 except:
738 self.chat.InfoPost("An error has occured while processing a Remote Administrator command!")
739 traceback.print_exc()