• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.pack_msg函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中utils.pack_msg函数的典型用法代码示例。如果您正苦于以下问题:Python pack_msg函数的具体用法?Python pack_msg怎么用?Python pack_msg使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了pack_msg函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _get

        def _get():
            got = False
            prob = self.p.prisoners[str_id].prob + treasures_prob
            if prob >= random.randint(1, 100):
                # got it
                save_hero(self.char_id, self.p.prisoners[str_id].oid)
                got = True

                self.p.prisoners.pop(str_id)

                msg = protomsg.RemovePrisonerNotify()
                msg.ids.append(_id)
                publish_to_char(self.char_id, pack_msg(msg))
            else:
                self.p.prisoners[str_id].active = False

                msg = protomsg.UpdatePrisonerNotify()
                p = msg.prisoner.add()
                p_obj = self.p.prisoners[str_id]
                self._fill_up_prisoner_msg(p, _id, p_obj.oid, p_obj.prob, p_obj.active)

                publish_to_char(self.char_id, pack_msg(msg))

            self.p.save()
            return got
开发者ID:hx002,项目名称:sanguo-server,代码行数:25,代码来源:prison.py


示例2: add_soul

    def add_soul(self, souls):
        new_souls = []
        update_souls = []

        for _id, _ in souls:
            if _id not in HEROS:
                raise RuntimeError("soul {0} not exist".format(_id))

        for _id, amount in souls:
            str_id = str(_id)
            if str_id in self.mongo_hs.souls:
                self.mongo_hs.souls[str_id] += amount
                update_souls.append((_id, self.mongo_hs.souls[str_id]))
            else:
                self.mongo_hs.souls[str_id] = amount
                new_souls.append((_id, amount))

        self.mongo_hs.save()
        if new_souls:
            msg = protomsg.AddHeroSoulNotify()
            for _id, amount in new_souls:
                s = msg.herosouls.add()
                s.id = _id
                s.amount = amount

            publish_to_char(self.char_id, pack_msg(msg))

        if update_souls:
            msg = protomsg.UpdateHeroSoulNotify()
            for _id, amount in update_souls:
                s = msg.herosouls.add()
                s.id = _id
                s.amount = amount

            publish_to_char(self.char_id, pack_msg(msg))
开发者ID:yaosj,项目名称:sanguo-server,代码行数:35,代码来源:hero.py


示例3: process_request

    def process_request(self, request):
        super(UnpackAndVerifyData, self).process_request(request)

        if request.path.startswith('/api/'):
            return

        if not server.active:
            return HttpResponse(status=502)

        char_id = getattr(request, '_char_id', None)
        if char_id:
            if request.path != '/resume/':
                p = Player(char_id)
                login_id = p.get_login_id()
                if not login_id:
                    msg = ReLoginResponse()
                    msg.ret = errormsg.SESSION_EXPIRE
                    data = pack_msg(msg)
                    return HttpResponse(data, content_type='text/plain')

                if login_id != request._game_session.login_id:
                    # NEED RE LOGIN
                    msg = ReLoginResponse()
                    msg.ret = errormsg.LOGIN_RE
                    data = pack_msg(msg)
                    return HttpResponse(data, content_type='text/plain')

                p.refresh()

            ap = ActivePlayers()
            ap.set(request._char_id)
开发者ID:hx002,项目名称:sanguo-server,代码行数:31,代码来源:middleware.py


示例4: stuff_add

    def stuff_add(self, add_stuffs, send_notify=True):
        """

        @param add_stuffs: [(id, amount), (id, amount)]
        @type add_stuffs: list | tuple
        """
        for _id, _ in add_stuffs:
            if _id not in STUFFS:
                raise SanguoException(
                    errormsg.STUFF_NOT_EXIST,
                    self.char_id,
                    "Stuff Add",
                    "Stuff Oid {0} not exist".format(_id)
                )

        stuffs = self.item.stuffs
        add_stuffs_dict = {}
        for _id, _amount in add_stuffs:
            add_stuffs_dict[_id] = add_stuffs_dict.get(_id, 0) + _amount

        new_stuffs = []
        update_stuffs = []
        for _id, _amount in add_stuffs_dict.iteritems():
            sid = str(_id)
            if sid in stuffs:
                stuffs[sid] += _amount
                update_stuffs.append((_id, stuffs[sid]))
            else:
                stuffs[sid] = _amount
                new_stuffs.append((_id, _amount))

        self.item.stuffs = stuffs
        self.item.save()

        for _id, _amount in add_stuffs_dict.iteritems():
            stuff_add_signal.send(
                sender=None,
                char_id=self.char_id,
                stuff_id=_id,
                add_amount=_amount,
                new_amount=stuffs[str(_id)]
            )

        if not send_notify:
            return
        if new_stuffs:
            msg = protomsg.AddStuffNotify()
            for k, v in new_stuffs:
                s = msg.stuffs.add()
                s.id, s.amount = k, v

            publish_to_char(self.char_id, pack_msg(msg))

        if update_stuffs:
            msg = protomsg.UpdateStuffNotify()
            for k, v in update_stuffs:
                s = msg.stuffs.add()
                s.id, s.amount = k, v

            publish_to_char(self.char_id, pack_msg(msg))
开发者ID:yueyoum,项目名称:sanguo-server,代码行数:60,代码来源:item.py


示例5: gem_remove

    def gem_remove(self, _id, amount):
        """

        @param _id: gem id
        @type _id: int
        @param amount: this gem amount
        @type amount: int
        """
        try:
            this_gem_amount = self.item.gems[str(_id)]
        except KeyError:
            raise SanguoException(
                errormsg.GEM_NOT_EXIST,
                self.char_id,
                "Gem Remove",
                "Gem {0} not exist".format(_id)
            )

        new_amount = this_gem_amount - amount
        if new_amount <= 0:
            self.item.gems.pop(str(_id))
            self.item.save()

            msg = protomsg.RemoveGemNotify()
            msg.ids.append(_id)
            publish_to_char(self.char_id, pack_msg(msg))
        else:
            self.item.gems[str(_id)] = new_amount
            self.item.save()
            msg = protomsg.UpdateGemNotify()
            g = msg.gems.add()
            g.id, g.amount = _id, new_amount

            publish_to_char(self.char_id, pack_msg(msg))
开发者ID:hx002,项目名称:sanguo-server,代码行数:34,代码来源:item.py


示例6: gem_add

    def gem_add(self, add_gems, send_notify=True):
        """

        @param add_gems: [(id, amount), (id, amount)]
        @type add_gems: list | tuple
        """

        for gid, _ in add_gems:
            if gid not in GEMS:
                raise SanguoException(
                    errormsg.GEM_NOT_EXIST,
                    self.char_id,
                    "Gem Add",
                    "Gem {0} not exist".format(gid)
                )


        gems = self.item.gems
        add_gems_dict = {}
        for gid, amount in add_gems:
            add_gems_dict[gid] = add_gems_dict.get(gid, 0) + amount

        new_gems = []
        update_gems = []
        for gid, amount in add_gems_dict.iteritems():
            gid = str(gid)
            if gid in gems:
                gems[gid] += amount
                update_gems.append((int(gid), gems[gid]))
            else:
                gems[gid] = amount
                new_gems.append((int(gid), amount))

        self.item.gems = gems
        self.item.save()

        if not send_notify:
            return
        if new_gems:
            msg = protomsg.AddGemNotify()
            for k, v in new_gems:
                g = msg.gems.add()
                g.id, g.amount = k, v

            publish_to_char(self.char_id, pack_msg(msg))

        if update_gems:
            msg = protomsg.UpdateGemNotify()
            for k, v in update_gems:
                g = msg.gems.add()
                g.id, g.amount = k, v

            publish_to_char(self.char_id, pack_msg(msg))
开发者ID:hx002,项目名称:sanguo-server,代码行数:53,代码来源:item.py


示例7: stuff_remove

    def stuff_remove(self, _id, amount):
        """
        @param _id: stuff id
        @type _id: int
        @param amount: this stuff amount
        @type amount: int
        """
        try:
            this_stuff_amount = self.item.stuffs[str(_id)]
        except KeyError:
            raise SanguoException(
                errormsg.STUFF_NOT_EXIST,
                self.char_id,
                "Stuff Remove",
                "Stuff {0} not exist".format(_id)
            )

        new_amount = this_stuff_amount - amount

        if new_amount < 0:
            raise SanguoException(
                errormsg.STUFF_NOT_ENOUGH,
                self.char_id,
                "Stuff Remove",
                "Stuff {0} not enough".format(_id)
            )

        if new_amount == 0:
            self.item.stuffs.pop(str(_id))
            self.item.save()

            msg = protomsg.RemoveStuffNotify()
            msg.ids.append(_id)
            publish_to_char(self.char_id, pack_msg(msg))
        else:
            self.item.stuffs[str(_id)] = new_amount
            self.item.save()
            msg = protomsg.UpdateStuffNotify()
            g = msg.stuffs.add()
            g.id, g.amount = _id, new_amount

            publish_to_char(self.char_id, pack_msg(msg))

        stuff_remove_signal.send(
            sender=None,
            char_id=self.char_id,
            stuff_id=_id,
            rm_amount=amount,
            new_amount=self.item.stuffs.get(str(_id), 0)
        )
开发者ID:yueyoum,项目名称:sanguo-server,代码行数:50,代码来源:item.py


示例8: send_socket_notify

    def send_socket_notify(self):
        msg = protomsg.SocketNotify()
        for k, v in self.formation.sockets.iteritems():
            s = msg.sockets.add()
            self._msg_socket(s, int(k), v)

        publish_to_char(self.char_id, pack_msg(msg))
开发者ID:yueyoum,项目名称:sanguo-server,代码行数:7,代码来源:formation.py


示例9: send_gem_notify

    def send_gem_notify(self):
        msg = protomsg.GemNotify()
        for k, v in self.item.gems.iteritems():
            g = msg.gems.add()
            g.id, g.amount = int(k), v

        publish_to_char(self.char_id, pack_msg(msg))
开发者ID:yueyoum,项目名称:sanguo-server,代码行数:7,代码来源:item.py


示例10: equip_add

    def equip_add(self, oid, level=1, notify=True):
        try:
            this_equip = EQUIPMENTS[oid]
        except KeyError:
            raise SanguoException(
                errormsg.EQUIPMENT_NOT_EXIST,
                self.char_id,
                "Equipment Add",
                "Equipment {0} NOT exist".format(oid)
            )

        new_id = id_generator('equipment')[0]
        me = MongoEmbeddedEquipment()
        me.oid = oid
        me.level = level
        me.gems = [0] * this_equip.slots

        self.item.equipments[str(new_id)] = me
        self.item.save()

        if notify:
            msg = protomsg.AddEquipNotify()
            msg_equip = msg.equips.add()
            self._msg_equip(msg_equip, new_id, me, Equipment(self.char_id, new_id, self.item))
            publish_to_char(self.char_id, pack_msg(msg))

        return new_id
开发者ID:yueyoum,项目名称:sanguo-server,代码行数:27,代码来源:item.py


示例11: get_union_boss_log

def get_union_boss_log(request):
    req = request._proto
    char_id = request._char_id

    b = UnionBoss(char_id)
    msg = b.make_log_message(req.boss_id)
    return pack_msg(msg)
开发者ID:yaosj,项目名称:sanguo-server,代码行数:7,代码来源:views.py


示例12: step_up

def step_up(request):
    char_id = request._char_id
    heros_dict = char_heros_dict(char_id)

    req = request._proto
    _id = req.id

    if _id not in heros_dict:
        raise SanguoException(
            errormsg.HERO_NOT_EXSIT,
            char_id,
            "Hero Step Up",
            "hero {0} not belong to char {1}".format(_id, char_id)
        )

    h = Hero(_id)
    h.step_up()

    response = HeroStepUpResponse()
    response.ret = 0
    response.id = _id
    response.step = h.step
    response.max_socket_amount = h.max_socket_amount
    response.current_socket_amount = h.current_socket_amount
    return pack_msg(response)
开发者ID:yaosj,项目名称:sanguo-server,代码行数:25,代码来源:views.py


示例13: send_notify

 def send_notify(self):
     self.load_mongo_record()
     msg = PlunderNotify()
     msg.current_times = self.mongo_plunder.current_times
     msg.max_times = self.max_plunder_times()
     msg.success_times_weekly = PlunderLeaderboardWeekly.get_char_times(self.char_id)
     publish_to_char(self.char_id, pack_msg(msg))
开发者ID:yueyoum,项目名称:sanguo-server,代码行数:7,代码来源:plunder.py


示例14: send_notify

    def send_notify(self):
        msg = CheckInNotify()
        for k in self.checkin_data.keys():
            item = msg.items.add()
            self._fill_up_one_item(item, k)

        publish_to_char(self.char_id, pack_msg(msg))
开发者ID:yueyoum,项目名称:sanguo-server,代码行数:7,代码来源:daily.py


示例15: hero_notify

def hero_notify(char_id, objs, message_name="HeroNotify"):
    data = getattr(protomsg, message_name)()

    for obj in objs:
        g = data.heros.add()
        g.id = obj.id
        g.original_id = obj.oid

        g.attack = int(obj.attack)
        g.defense = int(obj.defense)
        g.hp = int(obj.hp)
        g.cirt = int(obj.crit * 10)

        g.step = obj.step
        g.power = obj.power
        g.max_socket_amount = obj.max_socket_amount
        g.current_socket_amount = obj.current_socket_amount

        for k, v in obj.hero.wuxings.iteritems():
            wuxing = HeroWuXing(int(k), v.level, v.exp)
            msg_wuxing = g.wuxing.add()
            msg_wuxing.MergeFrom(wuxing.to_proto())


    publish_to_char(char_id, pack_msg(data))
开发者ID:yueyoum,项目名称:sanguo-server,代码行数:25,代码来源:notify.py


示例16: send_notify

    def send_notify(self, char=None, opended_funcs=None):
        if not char:
            char = self.mc

        msg = protomsg.CharacterNotify()
        msg.char.id = char.id
        msg.char.name = char.name
        msg.char.gold = char.gold
        msg.char.sycee = char.sycee
        msg.char.level = char.level
        msg.char.current_exp = char.exp
        msg.char.next_level_exp = level_update_exp(char.level)
        msg.char.official = char.official
        msg.char.official_exp = char.official_exp
        msg.char.next_official_exp = official_update_exp(char.level)

        msg.char.power = self.power
        msg.char.vip = char.vip
        msg.char.purchase_got = char.purchase_got

        msg.char.leader = self.leader

        if opended_funcs:
            msg.funcs.extend(opended_funcs)

        publish_to_char(self.id, pack_msg(msg))
开发者ID:hx002,项目名称:sanguo-server,代码行数:26,代码来源:character.py


示例17: send_friends_notify

    def send_friends_notify(self):
        msg = protomsg.FriendsNotify()
        for k, v in self.friends_list():
            f = msg.friends.add()
            self._msg_friend(f, k, v)

        publish_to_char(self.char_id, pack_msg(msg))
开发者ID:yueyoum,项目名称:sanguo-server,代码行数:7,代码来源:friend.py


示例18: enable

    def enable(self, enabled):
        self.stage.activities.extend(enabled)
        self.stage.save()

        msg = protomsg.NewActivityStageNotify()
        msg.ids.extend(enabled)
        publish_to_char(self.char_id, pack_msg(msg))
开发者ID:hx002,项目名称:sanguo-server,代码行数:7,代码来源:stage.py


示例19: someone_refuse_me

    def someone_refuse_me(self, from_id):
        self.mf.friends.pop(str(from_id))
        self.mf.save()

        msg = protomsg.RemoveFriendNotify()
        msg.id = from_id
        publish_to_char(self.char_id, pack_msg(msg))
开发者ID:wyrover,项目名称:sanguo-server,代码行数:7,代码来源:friend.py


示例20: add

    def add(self, oid):
        assert oid in HORSE

        embedded_horse = MongoEmbeddedHorse()
        embedded_horse.oid = oid
        embedded_horse.attack = 0
        embedded_horse.defense = 0
        embedded_horse.hp = 0

        new_id = id_generator('equipment')[0]

        self.mongo_horse.horses[str(new_id)] = embedded_horse
        self.mongo_horse.save()

        hobj = OneHorse(
            new_id,
            embedded_horse.oid,
            embedded_horse.attack,
            embedded_horse.defense,
            embedded_horse.hp
        )

        msg = HorsesAddNotify()
        msg_h = msg.horses.add()
        msg_h.MergeFrom(hobj.make_msg())
        publish_to_char(self.char_id, pack_msg(msg))
开发者ID:yueyoum,项目名称:sanguo-server,代码行数:26,代码来源:horse.py



注:本文中的utils.pack_msg函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.para函数代码示例发布时间:2022-05-26
下一篇:
Python utils.output函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap