def show_settings(self): m = Message(to_jid=self.room_state.room_jid.bare(), stanza_type='groupchat') command_node = m.add_new_content(None, 'command') command_node.newChild(None, 'command', 'settings') command_node.newChild(None, 'level', str(self.level_id)) # Custom type if Flash isn't going to know about it if self.mode.lower() in LEGIONS_GAMETYPES_DICT: command_node.newChild(None, 'mode', LEGIONS_GAMETYPES_DICT[self.mode.lower()]) else: command_node.newChild(None, 'mode', 'deathmatch') # Show a specific limit if score can't be displayed show_scorelimit = self.scorelimit if self.mode == 'CTF': if self.scorelimit not in [1, 2, 5, 10, 15, 25]: show_scorelimit = 1 else: if self.scorelimit not in [10, 20, 50, 100]: show_scorelimit = 100 scorelimit_node = command_node.newChild(None, 'scorelimit', str(show_scorelimit)) scorelimit_node.setProp('type', 'number') teams_node = command_node.newChild(None, 'teams', str(self.teams)) teams_node.setProp('type', 'number') # Show custom time limits as "unlimited" if self.timelimit in [-1, 5, 10, 15, 20, 25, 30, 45, 60]: timelimit_node = command_node.newChild(None, 'timelimit', str(self.timelimit)) else: timelimit_node = command_node.newChild(None, 'timelimit', '-1') timelimit_node.setProp('type', 'number') stream = self.room_state.manager.stream stream.send(m)
def party_refresh(self): m = Message(to_jid=self.room_state.room_jid.bare(), stanza_type='groupchat') command_node = m.add_new_content(None, 'command') command_node.newChild(None, 'command', 'refresh') stream = self.room_state.manager.stream stream.send(m)
def show_state(self): m = Message(to_jid=self.room_state.room_jid.bare(), stanza_type='groupchat') query_node = m.add_new_content(None, 'query') args_node = query_node.newChild(None, 'args', None) args_node.newChild(None, 'state', self.state) canhost_node = args_node.newChild(None, 'canHost', 'true') canhost_node.setProp('type', 'boolean') args_node.newChild(None, 'matchID', '%s19884641' % self.bot_nick) if self.state in ['ready', 'playing']: args_node.newChild(None, 'game', 'Legions') args_node.newChild(None, 'gameLevelId', str(self.level_id)) args_node.newChild(None, 'gameLevel', self.level) args_node.newChild(None, 'gameMode', self.mode) args_node.newChild(None, 'jid', unicode(self.gamelist_jid)) # args_node.newChild(None, 'anonymous', '0') maxplayers_node = args_node.newChild(None, 'maxplayers', str(self.size_limit)) maxplayers_node.setProp('type', 'number') args_node.newChild(None, 'partyJID', unicode(self.room_state.room_jid.bare())) args_node.newChild(None, 'private', yes_or_no(self.private)) args_node.newChild(None, 'allowAnon', 'no') args_node.newChild(None, 'createdAt', self.lobby_started) stream = self.room_state.manager.stream stream.send(m)
def vipadia_command(self, iq): dbg("vipadia_command:\n%s" % (fmt_evt(iq),)) StLock.acquire() try: items = iq.xpath_eval("v:command/v:item", { "v": "http://vipadia.com/skype", }) for item in items: command = item.prop("command") if command == "create-muc": chatid = item.prop("chatid") # skype chat name jid = JID(item.prop("jid")) member = item.prop("member") gid = groupchatid(chatid) # populate St['conferences'] St['conferences'][gid] = (iq.get_from(),jid) invite = Message(from_jid="%s@%s" % (gid, self.config.muc), to_jid=jid, ) x = invite.add_new_content("http://jabber.org/protocol/muc#user", "x") add_child(add_child(x, "invite", attrs={"from": "%s@%s" % (member, self.config.component)} ), "reason", value=Msgs.join_chat) add_child(x, "password") self.safe_send(invite) result = iq.make_result_response() q = result.new_query("http://vipadia.com/skype", "command") add_child(q, "item", attrs={"command": "create-muc", "gid": gid, "chatid": chatid}) self.safe_send(result) elif command == "destroy-muc": gid = item.prop("gid") # skype chat name if gid in St['conferences']: # Tidy up del St['conferences'][gid] result = iq.make_result_response() q = result.new_query("http://vipadia.com/skype", "command") add_child(q, "item", attrs={"command": "destroy-muc", "gid": gid}) self.safe_send(result) else: err("unknown command! command:%s\n%s" % (command, fmt_evt(iq),)) return True finally: StLock.release()
def message(self, stanza): subject = stanza.get_subject() body = stanza.get_body() t = stanza.get_type() print u'Message from %s received.' % (unicode(stanza.get_from(),)), if t: if t == 'chat': if not body: command_message = stanza.xpath_eval("ns:command") if command_message: command = stanza.xpath_eval("ns:command/ns:command") if command: command_text = command[0].getContent() if command_text == 'requestLobby': self.client.ia_party.show_state() return True elif command_text == 'requestSettings': self.client.ia_party.show_settings() return True else: print "no command" else: msg_from = stanza.get_from() if not self.client.ia_party.commands.is_admin(msg_from.node): return msg = stanza.get_body() bang_re = re.compile('^!(\w+)( .*)?$') bang_cmd = bang_re.match(msg) if not bang_cmd: return (command, args) = bang_cmd.groups() command = command.lower() if args: args = args.strip().rstrip() bang_command = self.client.ia_party.commands.get_command(command) if bang_command: result = bang_command(stanza.get_from(), args) if result: # Have to insert a bit of XML into the body, grrr m = Message(to_jid=stanza.get_from(), stanza_type='headline') body_node = m.add_new_content(None, 'body') body_node.setContent(result) party_node = body_node.newChild( None, 'party', self.client.ia_partyresource) stream = self.client.stream stream.send(m) return True