Пример #1
0
    def add(self, target_id=None, target_name=None):
        # 发出好友申请
        if not target_id and not target_name:
            raise SanguoException(
                errormsg.BAD_MESSAGE,
                self.char_id,
                "Friend Add",
                "no target_id and no target_name"
            )

        if target_id:
            doc = MongoCharacter._get_collection().find_one({'_id': target_id}, {'_id': 1})
            if not doc:
                raise SanguoException(
                    errormsg.CHARACTER_NOT_FOUND,
                    self.char_id,
                    "Friend Add",
                    "character id {0} not found".format(target_id)
                )
        else:
            doc = MongoCharacter._get_collection().find_one({'name': target_name}, {'_id': 1})
            if not doc:
                raise SanguoException(
                    errormsg.CHARACTER_NOT_FOUND,
                    self.char_id,
                    "Friend Add",
                    u"can not found character {0} in server {1}".format(target_name, self.char.mc.server_id)
                )

        cid = doc['_id']

        if cid in self.mf.friends:
            raise SanguoException(
                errormsg.FRIEND_ALREADY_ADD,
                self.char_id,
                "Friend Add",
                "character {0} already has beed added".format(cid)
            )

        self.check_max_amount("Friend Add")

        if cid in self.mf.accepting:
            # 如果要加的好友以前已经给我发过好友申请,那么就是直接接受
            self.accept(cid)
            return

        if cid not in self.mf.pending:
            self.mf.pending.append(cid)
            self.send_new_friend_notify(cid, status=FRIEND_ACK)

        self.mf.save()

        target_char_friend = Friend(cid)
        target_char_friend.someone_add_me(self.char_id)
Пример #2
0
def login(char_id, **kwargs):
    if char_id:
        # od = OfficialDailyReward(char_id)
        # od.check()

        now = datetime.datetime.utcnow()
        MongoCharacter._get_collection().update(
            {'_id': char_id},
            {'$set': {'last_login': now}}
        )

        login_notify(char_id)
Пример #3
0
def login(char_id, real_login, **kwargs):
    if char_id:
        # od = OfficialDailyReward(char_id)
        # od.check()

        now = datetime.datetime.utcnow()
        MongoCharacter._get_collection().update({'_id': char_id},
                                                {'$set': {
                                                    'last_login': now
                                                }})

        if real_login:
            TimesLogLogin(char_id).inc()

        login_notify(char_id)
Пример #4
0
def get_char_property(char_id, key):
    doc = MongoCharacter._get_collection().find_one(
            {'_id': char_id},
            {key: 1}
    )

    return doc[key]
Пример #5
0
    def add(self, target_id=None, target_name=None):
        # 发出好友申请
        if not target_id and not target_name:
            raise SanguoException(errormsg.BAD_MESSAGE, self.char_id,
                                  "Friend Add",
                                  "no target_id and no target_name")

        if target_id:
            doc = MongoCharacter._get_collection().find_one({'_id': target_id},
                                                            {'_id': 1})
            if not doc:
                raise SanguoException(
                    errormsg.CHARACTER_NOT_FOUND, self.char_id, "Friend Add",
                    "character id {0} not found".format(target_id))
        else:
            doc = MongoCharacter._get_collection().find_one(
                {'name': target_name}, {'_id': 1})
            if not doc:
                raise SanguoException(
                    errormsg.CHARACTER_NOT_FOUND, self.char_id, "Friend Add",
                    u"can not found character {0} in server {1}".format(
                        target_name, self.char.mc.server_id))

        cid = doc['_id']

        if cid in self.mf.friends:
            raise SanguoException(
                errormsg.FRIEND_ALREADY_ADD, self.char_id, "Friend Add",
                "character {0} already has beed added".format(cid))

        self.check_max_amount("Friend Add")

        if cid in self.mf.accepting:
            # 如果要加的好友以前已经给我发过好友申请,那么就是直接接受
            self.accept(cid)
            return

        if cid not in self.mf.pending:
            self.mf.pending.append(cid)
            self.send_new_friend_notify(cid, status=FRIEND_ACK)

        self.mf.save()

        target_char_friend = Friend(cid)
        target_char_friend.someone_add_me(self.char_id)
Пример #6
0
def get_char_ids_by_last_login(limit=7):
    date = arrow.utcnow().replace(days=-limit)

    dt = datetime.datetime(date.year, date.month, date.day, date.hour,
                           date.minute, date.second)

    chars = MongoCharacter._get_collection().find({'last_login': {
        '$gte': dt
    }}, {'_id': 1})
    return [c['_id'] for c in chars]
Пример #7
0
def get_char_ids_by_last_login(limit=7):
    date = arrow.utcnow().replace(days=-limit)

    dt = datetime.datetime(
        date.year,
        date.month,
        date.day,
        date.hour,
        date.minute,
        date.second
    )

    chars = MongoCharacter._get_collection().find({'last_login': {'$gte': dt}}, {'_id': 1})
    return [c['_id'] for c in chars]
Пример #8
0
def send_vip_reward(signum):
    logger = Logger("send_vip_reward.log")
    logger.write("Start")

    try:
        docs = MongoCharacter._get_collection().find({'vip': {
            '$gte': 6
        }}, {'_id': 1})

        for doc in docs:
            char_id = doc['_id']

            ac = ActivityEntry(char_id, 22001)
            if ac and ac.is_valid():
                ac.send_mail()
    except:
        logger.error(traceback.format_exc())
    else:
        logger.write("Done")
    finally:
        logger.close()
Пример #9
0
def send_vip_reward(signum):
    logger = Logger("send_vip_reward.log")
    logger.write("Start")

    try:
        docs = MongoCharacter._get_collection().find(
            {'vip': {'$gte': 6}},
            {'_id': 1}
        )

        for doc in docs:
            char_id = doc['_id']

            ac = ActivityEntry(char_id, 22001)
            if ac and ac.is_valid():
                ac.send_mail()
    except:
        logger.error(traceback.format_exc())
    else:
        logger.write("Done")
    finally:
        logger.close()
Пример #10
0
def char_initialize(account_id, server_id, char_id, name):
    mc = MongoCharacter(id=char_id)
    mc.account_id = account_id
    mc.server_id = server_id
    mc.name = name
    mc.gold = CHARACTER_INIT['gold']
    mc.sycee = CHARACTER_INIT['sycee']
    mc.save()

    from core.item import Item
    item = Item(char_id)
    # save equipment
    for _id, _amount in CHARACTER_INIT['equipment']:
        for _x in range(_amount):
            item.equip_add(_id, notify=False)
    # save gem
    if CHARACTER_INIT['gem']:
        item.gem_add(CHARACTER_INIT['gem'], send_notify=False)
    # save stuff
    if CHARACTER_INIT['stuff']:
        item.stuff_add(CHARACTER_INIT['stuff'], send_notify=False)
    # save hero
    if CHARACTER_INIT['hero']:
        save_hero(char_id, CHARACTER_INIT['hero'], add_notify=False)
    # save souls:
    if CHARACTER_INIT['souls']:
        s = HeroSoul(char_id)
        s.add_soul(CHARACTER_INIT['souls'])

    # hero in formation!
    in_formaiton_heros = CHARACTER_INIT['hero_in_formation']

    final_in_formation_heros = {}
    for k, v in in_formaiton_heros.iteritems():
        new_ids = []
        for _equip_id in v:
            if not _equip_id:
                new_ids.append(0)
            else:
                new_ids.append(item.equip_add(_equip_id, notify=False))

        final_in_formation_heros[k] = new_ids

    hero_ids = save_hero(char_id, final_in_formation_heros.keys(), add_notify=False).id_range
    hero_new_id_to_oid_table = dict(zip(hero_ids, final_in_formation_heros.keys()))

    hero_oid_socket_id_table = {}
    f = Formation(char_id)

    for hid in hero_ids:
        this_oid = hero_new_id_to_oid_table[hid]
        weapon, armor, jewelry = final_in_formation_heros[this_oid]

        _sid = f.initialize_socket(hero=hid, weapon=weapon, armor=armor, jewelry=jewelry)
        hero_oid_socket_id_table[this_oid] = _sid

    socket_ids = FORMATION_INIT_TABLE[:]
    for index, oid in enumerate(socket_ids):
        if oid:
            socket_ids[index] = hero_oid_socket_id_table[oid]

    if FORMATION_INIT_OPENED_SOCKETS > len(hero_ids):
        for i in range(FORMATION_INIT_OPENED_SOCKETS - len(hero_ids)):
            _sid = f.initialize_socket()
            for index, sid in enumerate(socket_ids):
                if sid == 0:
                    socket_ids[index] = _sid
                    break

    f.save_formation(socket_ids, send_notify=False)
Пример #11
0
def char_initialize(account_id, server_id, char_id, name):
    mc = MongoCharacter(id=char_id)
    mc.account_id = account_id
    mc.server_id = server_id
    mc.name = name
    mc.gold = CHARINIT.gold
    mc.sycee = CHARINIT.sycee
    mc.save()

    from core.item import Item

    init_heros = CHARINIT.decoded_heros

    init_heros_ids = init_heros.keys()

    transformed_init_heros = {}

    item = Item(char_id)
    for k, v in init_heros.iteritems():
        weapon, armor, jewelry = v
        new_ids = []
        if not weapon:
            new_ids.append(0)
        else:
            new_ids.append(item.equip_add(weapon, notify=False))
        if not armor:
            new_ids.append(0)
        else:
            new_ids.append(item.equip_add(armor, notify=False))
        if not jewelry:
            new_ids.append(0)
        else:
            new_ids.append(item.equip_add(jewelry, notify=False))

        transformed_init_heros[k] = new_ids

    init_heros_equips = transformed_init_heros.values()

    hero_ids = save_hero(char_id, init_heros_ids, add_notify=False).id_range

    f = Formation(char_id)

    hero_ids = hero_ids + (4 - len(hero_ids)) * [0]

    socket_ids = []
    for index, _id in enumerate(hero_ids):
        try:
            weapon, armor, jewelry = init_heros_equips[index]
        except IndexError:
            weapon, armor, jewelry = 0, 0, 0
        _sid = f.initialize_socket(hero=_id,
                                   weapon=weapon,
                                   armor=armor,
                                   jewelry=jewelry)
        socket_ids.append(_sid)

    socket_ids = [
        socket_ids[0],
        socket_ids[3],
        0,
        socket_ids[1],
        0,
        0,
        socket_ids[2],
        0,
        0,
    ]

    f.save_formation(socket_ids, send_notify=False)

    if CHARINIT.decoded_gems:
        item.gem_add(CHARINIT.decoded_gems, send_notify=False)
    if CHARINIT.decoded_stuffs:
        item.stuff_add(CHARINIT.decoded_stuffs, send_notify=False)
Пример #12
0
def char_initialize(account_id, server_id, char_id, name):
    mc = MongoCharacter(id=char_id)
    mc.account_id = account_id
    mc.server_id = server_id
    mc.name = name
    mc.gold = CHARACTER_INIT['gold']
    mc.sycee = CHARACTER_INIT['sycee']
    mc.save()

    from core.item import Item
    item = Item(char_id)
    # save equipment
    for _id, _amount in CHARACTER_INIT['equipment']:
        for _x in range(_amount):
            item.equip_add(_id, notify=False)
    # save gem
    if CHARACTER_INIT['gem']:
        item.gem_add(CHARACTER_INIT['gem'], send_notify=False)
    # save stuff
    if CHARACTER_INIT['stuff']:
        item.stuff_add(CHARACTER_INIT['stuff'], send_notify=False)
    # save hero
    if CHARACTER_INIT['hero']:
        save_hero(char_id, CHARACTER_INIT['hero'], add_notify=False)
    # save souls:
    if CHARACTER_INIT['souls']:
        s = HeroSoul(char_id)
        s.add_soul(CHARACTER_INIT['souls'])

    # hero in formation!
    in_formaiton_heros = CHARACTER_INIT['hero_in_formation']

    final_in_formation_heros = {}
    for k, v in in_formaiton_heros.iteritems():
        new_ids = []
        for _equip_id in v:
            if not _equip_id:
                new_ids.append(0)
            else:
                new_ids.append(item.equip_add(_equip_id, notify=False))

        final_in_formation_heros[k] = new_ids

    hero_ids = save_hero(char_id,
                         final_in_formation_heros.keys(),
                         add_notify=False).id_range
    hero_new_id_to_oid_table = dict(
        zip(hero_ids, final_in_formation_heros.keys()))

    hero_oid_socket_id_table = {}
    f = Formation(char_id)

    for hid in hero_ids:
        this_oid = hero_new_id_to_oid_table[hid]
        weapon, armor, jewelry = final_in_formation_heros[this_oid]

        _sid = f.initialize_socket(hero=hid,
                                   weapon=weapon,
                                   armor=armor,
                                   jewelry=jewelry)
        hero_oid_socket_id_table[this_oid] = _sid

    socket_ids = FORMATION_INIT_TABLE[:]
    for index, oid in enumerate(socket_ids):
        if oid:
            socket_ids[index] = hero_oid_socket_id_table[oid]

    if FORMATION_INIT_OPENED_SOCKETS > len(hero_ids):
        for i in range(FORMATION_INIT_OPENED_SOCKETS - len(hero_ids)):
            _sid = f.initialize_socket()
            for index, sid in enumerate(socket_ids):
                if sid == 0:
                    socket_ids[index] = _sid
                    break

    f.save_formation(socket_ids, send_notify=False)
Пример #13
0
def get_char_property(char_id, key):
    doc = MongoCharacter._get_collection().find_one({'_id': char_id}, {key: 1})

    return doc[key]