Ejemplo n.º 1
0
    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))
Ejemplo n.º 2
0
    def add_soul(self, souls):
        new_souls = []
        update_souls = []
        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))
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
        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
Ejemplo n.º 5
0
    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))
Ejemplo n.º 6
0
    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))
Ejemplo n.º 7
0
    def remove_soul(self, souls):
        remove_souls = []
        update_souls = []
        for _id, amount in souls:
            if not self.has_soul(_id, amount):
                raise SanguoException(
                    errormsg.SOUL_NOT_ENOUGH, self.char_id, "HeroSoul Remove",
                    "HeroSoul {0} not enough/exist, expected amount {1}".
                    format(_id, amount))

        for _id, amount in souls:
            str_id = str(_id)
            self.mongo_hs.souls[str_id] -= amount
            if self.mongo_hs.souls[str_id] <= 0:
                remove_souls.append(_id)
                self.mongo_hs.souls.pop(str_id)
            else:
                update_souls.append((_id, self.mongo_hs.souls[str_id]))

        self.mongo_hs.save()
        if remove_souls:
            msg = protomsg.RemoveHeroSoulNotify()
            msg.ids.extend(remove_souls)

            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))
Ejemplo n.º 8
0
    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()

        for gid, amount in add_gems_dict.iteritems():
            gem_add_signal.send(sender=None,
                                char_id=self.char_id,
                                gem_id=gid,
                                add_amount=amount,
                                new_amount=gems[str(gid)])

        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))
Ejemplo n.º 9
0
    def prisoner_get(self, _id, treasures):
        str_id = str(_id)
        if str_id not in self.p.prisoners:
            raise SanguoException(errormsg.PRISONER_NOT_EXIST, self.char_id,
                                  "Prisoner Get", "{0} not exist".format(_id))

        if not self.p.prisoners[str_id].active:
            raise SanguoException(errormsg.PRISONER_NOT_ACTIVE, self.char_id,
                                  "Prisoner Get", "{0} not active".format(_id))

        treasures_prob = 0
        for tid in treasures:
            try:
                treasures_prob += TREASURES[tid].value
            except KeyError:
                raise SanguoException(errormsg.STUFF_NOT_EXIST, self.char_id,
                                      "Prisoner Get",
                                      "treasure {0} not exist".format(tid))

        using_stuffs = [(tid, 1) for tid in treasures]

        resource = Resource(self.char_id, "Prisoner Get")
        with resource.check(stuffs=using_stuffs):
            got = False
            prob = self.p.prisoners[str_id].prob + treasures_prob
            char = Char(self.char_id).mc
            vip_plus = VIP_FUNCTION[char.vip].prisoner_get
            prob += vip_plus
            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()

        t = Task(self.char_id)
        t.trig(5)

        return got
Ejemplo n.º 10
0
    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))
Ejemplo n.º 11
0
    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))
Ejemplo n.º 12
0
    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)
        )
Ejemplo n.º 13
0
    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))
Ejemplo n.º 14
0
    def send_stuff_notify(self):
        msg = protomsg.StuffNotify()
        for k, v in self.item.stuffs.iteritems():
            s = msg.stuffs.add()
            s.id, s.amount = int(k), v

        publish_to_char(self.char_id, pack_msg(msg))
Ejemplo n.º 15
0
    def remove(self, _id):
        self.mongo_horse.horses.pop(str(_id))
        self.mongo_horse.save()

        msg = HorsesRemoveNotify()
        msg.ids.extend([_id])
        publish_to_char(self.char_id, pack_msg(msg))
Ejemplo n.º 16
0
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)
Ejemplo n.º 17
0
    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))
Ejemplo n.º 18
0
    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))
Ejemplo n.º 19
0
    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))
Ejemplo n.º 20
0
    def send_notify(self):
        msg = CheckInNotify()
        for k in CHECKIN_DATA.keys():
            item = msg.items.add()
            self._fill_up_one_item(item, k)

        publish_to_char(self.char_id, pack_msg(msg))
Ejemplo n.º 21
0
    def send_prisoners_notify(self):
        msg = protomsg.PrisonerListNotify()
        for k, v in self.p.prisoners.iteritems():
            p = msg.prisoner.add()
            self._fill_up_prisoner_msg(p, int(k), v.oid, v.prob, v.active)

        publish_to_char(self.char_id, pack_msg(msg))
Ejemplo n.º 22
0
    def send_stuff_notify(self):
        msg = protomsg.StuffNotify()
        for k, v in self.item.stuffs.iteritems():
            s = msg.stuffs.add()
            s.id, s.amount = int(k), v

        publish_to_char(self.char_id, pack_msg(msg))
Ejemplo n.º 23
0
    def send_prisoners_notify(self):
        msg = protomsg.PrisonerListNotify()
        for k, v in self.p.prisoners.iteritems():
            p = msg.prisoner.add()
            self._fill_up_prisoner_msg(p, int(k), v.oid, v.prob, v.active)

        publish_to_char(self.char_id, pack_msg(msg))
Ejemplo n.º 24
0
    def remove(self, _id):
        self.mongo_horse.horses.pop(str(_id))
        self.mongo_horse.save()

        msg = HorsesRemoveNotify()
        msg.ids.extend([_id])
        publish_to_char(self.char_id, pack_msg(msg))
Ejemplo n.º 25
0
    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))
Ejemplo n.º 26
0
    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))
Ejemplo n.º 27
0
    def send_equip_notify(self):
        msg = protomsg.EquipNotify()
        for _id, data in self.item.equipments.iteritems():
            equip = msg.equips.add()
            self._msg_equip(equip, int(_id), data, Equipment(self.char_id, int(_id), self.item))

        publish_to_char(self.char_id, pack_msg(msg))
Ejemplo n.º 28
0
    def send_notify(self):
        msg = protomsg.EliteStageNotify()
        for _id in self.stage.elites.keys():
            s = msg.stages.add()
            self._msg_one_stage(s, int(_id))

        publish_to_char(self.char_id, pack_msg(msg))
Ejemplo n.º 29
0
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))
Ejemplo n.º 30
0
    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))
Ejemplo n.º 31
0
    def send_equip_notify(self):
        msg = protomsg.EquipNotify()
        for _id, data in self.item.equipments.iteritems():
            equip = msg.equips.add()
            self._msg_equip(equip, int(_id), data, Equipment(self.char_id, int(_id), self.item))

        publish_to_char(self.char_id, pack_msg(msg))
Ejemplo n.º 32
0
    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
Ejemplo n.º 33
0
    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))
Ejemplo n.º 34
0
    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))
Ejemplo n.º 35
0
 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))
Ejemplo n.º 36
0
    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))
Ejemplo n.º 37
0
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)
Ejemplo n.º 38
0
    def send_notify(self):
        msg = protomsg.HangNotify()
        msg.remained_time = self.get_hang_remained()

        if self.hang_doing:
            msg.hang.stage_id = self.hang_doing.stage_id
            msg.hang.start_time = self.hang_doing.start
            if self.hang_doing.finished:
                msg.hang.used_time = self.hang_doing.actual_seconds
            else:
                msg.hang.used_time = arrow.utcnow(
                ).timestamp - self.hang_doing.start

            msg.hang.finished = self.hang_doing.finished

            times = msg.hang.used_time / 15
            stage = STAGES[self.hang_doing.stage_id]
            msg.hang.rewared_gold = self._actual_gold(stage.normal_gold *
                                                      times)
            msg.hang.rewared_exp = stage.normal_exp * times

            for l in self.hang_doing.logs:
                msg_log = msg.logs.add()
                msg_log.attacker = l.name
                msg_log.win = l.gold > 0
                msg_log.gold = abs(l.gold)

        publish_to_char(self.char_id, pack_msg(msg))
Ejemplo n.º 39
0
    def send_notify(self):
        msg = TaskNotify()
        for t in self.task.doing:
            this_task = TASKS[t]
            if this_task.func and not func_opened(self.char_id,
                                                  this_task.func):
                # 对于没有开放功能的任务不显示
                continue

            msg_t = msg.tasks.add()
            msg_t.id = t

            current_times = self.task.tasks[str(this_task.tp)]
            if current_times > this_task.times:
                current_times = this_task.times

            msg_t.current_times = current_times

            if t in self.task.complete:
                status = MsgTask.COMPLETE
            elif t in self.task.finished:
                status = MsgTask.REWARD
            else:
                status = MsgTask.DOING

            msg_t.status = status

        publish_to_char(self.char_id, pack_msg(msg))
Ejemplo n.º 40
0
    def send_notify(self):
        msg = TaskNotify()
        for t in self.task.doing:
            this_task = TASKS[t]
            if this_task.func and not func_opened(self.char_id, this_task.func):
                # 对于没有开放功能的任务不显示
                continue

            msg_t = msg.tasks.add()
            msg_t.id = t

            current_times = self.task.tasks[str(this_task.tp)]
            if current_times > this_task.times:
                current_times = this_task.times

            msg_t.current_times = current_times

            if t in self.task.complete:
                status = MsgTask.COMPLETE
            elif t in self.task.finished:
                status = MsgTask.REWARD
            else:
                status = MsgTask.DOING

            msg_t.status = status

        publish_to_char(self.char_id, pack_msg(msg))
Ejemplo n.º 41
0
    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))
Ejemplo n.º 42
0
    def purge_soul(self, _id):
        self.mongo_hs.souls.pop(str(_id))
        self.mongo_hs.save()

        msg = protomsg.RemoveHeroSoulNotify()
        msg.ids.append(_id)
        publish_to_char(self.char_id, pack_msg(msg))
Ejemplo n.º 43
0
    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
Ejemplo n.º 44
0
def connect_to_server(ip, port_num):
    s = socket(AF_INET, SOCK_STREAM)  # создали сокет TCP
    print('Подключение...\n Создан сокет TCP')
    try:
        s.connect((ip, port_num))  # соединиться с сервером по адресу и порту
        print('Соединяемся с сервером по адресу: {} и порту: {}'.format(
            ip, port_num))
        # отправляем на сервер presence сообщение в формате json
        pr_msg = utils.pack_msg(utils.make_pr_msg())
        print('Посылаем на сервер presence сообщение...\n')
        print(pr_msg)
        s.send(pr_msg)
        # принимаем ответ от сервера
        recieved_data = s.recv(1024)  # принимаем не более 1024 байт данных
        parsed_json_recieved_data = utils.load_msg(recieved_data)
        if parsed_json_recieved_data['response'] == 200:
            print('Получен status 200. Соединение установлено!')

        return 1
        # s.close()     # адо закрывать или нет?
        pass
    except ConnectionRefusedError:
        print(
            'Подключение не установлено, т.к конечный компьютер отверг запрос на подключение'
        )
Ejemplo n.º 45
0
    def send_already_stage_notify(self):
        msg = protomsg.AlreadyStageNotify()
        for _id, star in self.stage.stages.iteritems():
            s = msg.stages.add()
            self._msg_stage(s, int(_id), star)

        publish_to_char(self.char_id, pack_msg(msg))
Ejemplo n.º 46
0
    def send_notify(self):
        msg = AchievementNotify()
        for v in ACHIEVEMENTS.values():
            a = msg.achievements.add()
            self._fill_up_achievement_msg(a, v)

        publish_to_char(self.char_id, pack_msg(msg))
Ejemplo n.º 47
0
    def send_notify(self):
        msg = protomsg.HangNotify()
        msg.remained_time = self.get_hang_remained()

        if self.hang_doing:
            msg.hang.stage_id = self.hang_doing.stage_id
            msg.hang.start_time = self.hang_doing.start
            if self.hang_doing.finished:
                msg.hang.used_time = self.hang_doing.actual_seconds
            else:
                msg.hang.used_time = arrow.utcnow().timestamp - self.hang_doing.start

            msg.hang.finished = self.hang_doing.finished

            times = msg.hang.used_time / 15
            stage = STAGES[self.hang_doing.stage_id]
            msg.hang.rewared_gold = self._actual_gold(stage.normal_gold * times)
            msg.hang.rewared_exp = stage.normal_exp * times

            for l in self.hang_doing.logs:
                msg_log = msg.logs.add()
                msg_log.attacker = l.name
                msg_log.win = l.gold > 0
                msg_log.gold = abs(l.gold)


        publish_to_char(self.char_id, pack_msg(msg))
Ejemplo n.º 48
0
    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))
Ejemplo n.º 49
0
    def send_notify(self):
        msg = AchievementNotify()
        for v in ACHIEVEMENTS.values():
            a = msg.achievements.add()
            self._fill_up_achievement_msg(a, v)

        publish_to_char(self.char_id, pack_msg(msg))
Ejemplo n.º 50
0
    def send_socket_changed_notify(self, socket_id, socket):
        msg = protomsg.UpdateSocketNotify()
        s = msg.sockets.add()
        self._msg_socket(s, socket_id, socket)
        publish_to_char(self.char_id, pack_msg(msg))

        socket_changed_signal.send(sender=None, socket_obj=socket)
Ejemplo n.º 51
0
    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))
Ejemplo n.º 52
0
    def purge_soul(self, _id):
        self.mongo_hs.souls.pop(str(_id))
        self.mongo_hs.save()

        msg = protomsg.RemoveHeroSoulNotify()
        msg.ids.append(_id)
        publish_to_char(self.char_id, pack_msg(msg))
Ejemplo n.º 53
0
    def send_notify(self):
        msg = protomsg.HeroSoulNotify()
        for _id, amount in self.mongo_hs.souls.iteritems():
            s = msg.herosouls.add()
            s.id = int(_id)
            s.amount = amount

        publish_to_char(self.char_id, pack_msg(msg))
Ejemplo n.º 54
0
 def wrap(request, *args, **kwargs):
     m = getattr(protomsg, message_name)()
     m.ret = 0
     try:
         res = func(request, *args, **kwargs)
         if res is None:
             return HttpResponse(pack_msg(m), content_type='text/plain')
         if isinstance(res, (list, tuple)):
             msg_amount = len(res)
             res = ''.join(res)
             response = HttpResponse(res, content_type='text/plain')
             response._msg_amount = msg_amount
             return response
         return HttpResponse(res, content_type='text/plain')
     except SanguoException as e:
         m.ret = e.error_id
         return HttpResponse(pack_msg(m), content_type='text/plain')