def handle_admin_cmd(self, user, cmd): args = map(unicode, shlex.split(cmd.encode('utf-8'))) cmd = args[0] args = args[1:] if cmd == 'stacktrace': manager = GameManager.get_by_user(user) manager.record_stacktrace() elif cmd == 'clearzombies': self.clearzombies() elif cmd == 'ping': self.ping(user) elif cmd == 'start_migration': self.start_migration() elif cmd == 'kick': uid, = args self.force_disconnect(int(uid)) elif cmd == 'match': self.setup_match(user, *args) elif cmd == 'kill_game': gid, = args manager = self.games.get(int(gid)) manager and self.force_end_game(manager) elif cmd == 'add_admin': uid, = args self.admins.append(int(uid)) elif cmd == 'remove_admin': uid, = args self.admins.remove(int(uid)) elif cmd == 'bigbrother': self.bigbrothers.append(user.account.userid) elif cmd == 'nobigbrother': try: self.bigbrothers.remove(user.account.userid) except Exception: pass elif cmd == 'give_item': from server.item import backpack uid, sku = args backpack.add(int(uid), sku) elif cmd == 'mute': manager = GameManager.get_by_user(user) if manager: manager.muted = not manager.muted else: return user.write(['system_msg', [None, u'成功的执行了管理命令']])
def testBackpack(self): from db.models import User, Item, DiscuzMember from server.item import backpack, constants s = current_session() backpack.use(1, 'foo') with assert_raises(exceptions.ItemNotFound): backpack.use(1, 'foo') with assert_raises(exceptions.ItemNotFound): backpack.use(1, 'bar') backpack.add(1, 'foo') backpack.use(1, 'foo') backpack.add(1, 'bar') with assert_raises(exceptions.ItemNotUsable): backpack.use(1, 'bar') s.rollback() id = s.query(Item).filter(Item.owner_id == 1, Item.sku == 'bar').first().id backpack.drop(1, id) for i in xrange(constants.BACKPACK_SIZE): backpack.add(1, 'foo') with assert_raises(exceptions.BackpackFull): backpack.add(1, 'foo') eq_(len(backpack.list(1)), constants.BACKPACK_SIZE) s.rollback() id = s.query(Item).filter(Item.owner_id == 1).first().id backpack.drop(1, id) eq_(len(backpack.list(1)), constants.BACKPACK_SIZE - 1) with assert_raises(exceptions.ItemNotFound): backpack.drop(1, id) s.rollback() u = s.query(User).filter(User.id == 1).first() u.ppoint = 0 if not options.freeplay: dz_member = s.query(DiscuzMember).filter(DiscuzMember.uid == 1).first() dz_member.member_count.jiecao = 0 else: u.jiecao = 0 s.commit() backpack.add(1, 'jiecao:1234') backpack.use(1, 'jiecao:1234') backpack.add(1, 'ppoint:1234') backpack.use(1, 'ppoint:1234') u = s.query(User).filter(User.id == 1).first() eq_(u.ppoint, 1234) if not options.freeplay: dz_member = s.query(DiscuzMember).filter(DiscuzMember.uid == 1).first() eq_(dz_member.member_count.jiecao, 1234)
def testBackpack(self): from db.models import User, Item, DiscuzMember from server.item import backpack, constants s = current_session() backpack.use(1, 'foo') with assert_raises(exceptions.ItemNotFound): backpack.use(1, 'foo') with assert_raises(exceptions.ItemNotFound): backpack.use(1, 'bar') backpack.add(1, 'foo') backpack.use(1, 'foo') backpack.add(1, 'bar') with assert_raises(exceptions.ItemNotUsable): backpack.use(1, 'bar') s.rollback() id = s.query(Item).filter(Item.owner_id == 1, Item.sku == 'bar').first().id backpack.drop(1, id) for i in xrange(constants.BACKPACK_SIZE): backpack.add(1, 'foo') with assert_raises(exceptions.BackpackFull): backpack.add(1, 'foo') eq_(len(backpack.list(1)), constants.BACKPACK_SIZE) s.rollback() id = s.query(Item).filter(Item.owner_id == 1).first().id backpack.drop(1, id) eq_(len(backpack.list(1)), constants.BACKPACK_SIZE - 1) with assert_raises(exceptions.ItemNotFound): backpack.drop(1, id) s.rollback() u = s.query(User).filter(User.id == 1).first() u.ppoint = 0 if not options.freeplay: dz_member = s.query(DiscuzMember).filter( DiscuzMember.uid == 1).first() dz_member.member_count.jiecao = 0 else: u.jiecao = 0 s.commit() backpack.add(1, 'jiecao:1234') backpack.use(1, 'jiecao:1234') backpack.add(1, 'ppoint:1234') backpack.use(1, 'ppoint:1234') u = s.query(User).filter(User.id == 1).first() eq_(u.ppoint, 1234) if not options.freeplay: dz_member = s.query(DiscuzMember).filter( DiscuzMember.uid == 1).first() eq_(dz_member.member_count.jiecao, 1234)