コード例 #1
0
ファイル: user_manager.py プロジェクト: TTXDM/firstGame
def game_hu_pai(ro, data):
    """
    胡牌
    :param ro:
    :param data:
    胡牌的type,  1表示德国, 2表示正常胡牌, 3表示七对,  4表示十三烂,5表示七星十三烂
    德国就是没用精牌就胡了;德中德就是胡牌的时候,四个人手里都没有精牌;
    13烂就是没对子,没顺子,没刻子
    13烂,如果有东南西北中发白七张,就是七星十三烂
    :return:
    """
    obj = Parser(data)
    type = obj.read_ubyte()
    str1 = obj.read_string()
    tt = str1.split(",")
    print u"game_hu_pai:", ro.user.id, type, str1
    print u"game_hu_pai:", tt
    print u"game_hu_pai:", "\t".join(["".join(map(PAI_NAME, m)) for m in tt])
    if not check_room_state(ro):
        return
    d = defer.maybeDeferred(partial(ro.user.room.maj.hu_pai), ro, ro.user.tableid, type, str1)
    if d:
        d.addCallback(hupai_ok)
        d.addErrback(hupai_err)
    yield
コード例 #2
0
ファイル: user_manager.py プロジェクト: TTXDM/firstGame
def account_create(ro, data):
    """
    创建用户账号;
    """
    obj = Parser(data)
    u = obj.read_string()
    p = obj.read_string()
    nick = obj.read_string()
    mail = obj.read_string()
    sex = obj.read_ushort()
    avata = obj.read_ushort()
    print u"account_create:", u, p, mail, sex, avata
    rc = yield redis.Connection()
    print u"redis connected!"
    yield rc.select("0")
    usr = yield rc.get("usr_" + u)
    if usr:
        print u"用户已存在"
        yield rc.disconnect()
        res = Buffer()
        res.write_ushort(1024)
        res.write_short(-100)
        res.write_string(u"用户已存在")
        ro.sendData(res.getValue())
    else:
        m = User()
        m.id, m.pwd, m.nick, m.mail, m.sex, m.avata = u, p, nick, mail, sex, avata
        yield rc.set("usr_" + u, repr(m))
        yield rc.disconnect()
        res = Buffer()
        res.write_ushort(1024)
        res.write_short(1)
        res.write_string(u"ok")
        # dat=res.getValue()
        # for i in range(len(dat)):
        #     print dat[i]
        ro.sendData(res.getValue())
        logging.getLogger("user").info(u"用户账号注册成功:%s<%s>" % (nick, u))
コード例 #3
0
ファイル: user_manager.py プロジェクト: TTXDM/firstGame
def game_ting(ro, data):
    """
    听牌
    :param ro:
    :param data:
    :return:
    """
    obj = Parser(data)
    ss = obj.read_string()
    print u"game_ting.", ro.user.id, ss
    if not check_room_state(ro):
        return
    ro.user.room.maj.ting_pai(ro.user.tableid, ss)
    yield
コード例 #4
0
ファイル: user_manager.py プロジェクト: TTXDM/firstGame
def auth_login(ro, data):
    """
    用户登录
    :param ro:连接
    :param data:客户端数据包
    :return:
    """
    obj = Parser(data)
    u = obj.read_string()
    p = obj.read_string()
    print u"auth_login:"******"0")
    usr = yield getUser(u)
    if not usr or usr.pwd != p:
        print u"登录失败", usr, usr or u"无次用户"
        yield rc.disconnect()
        res = Buffer()
        res.write_ushort(1025)
        res.write_short(-100)
        res.write_string(u"登录失败")
        ro.sendData(res.getValue())
    else:
        ro2 = getSockByUsrId(u)
        if ro2:
            res = Buffer()
            res.write_ushort(1025)
            res.write_short(-102)
            res.write_string(u"账号被重新登录")
            ro2.sendData(res.getValue())
            ro2.transport.loseConnection()
        yield rc.sadd("lobby_usr", u)
        yield rc.disconnect()
        res = Buffer()
        res.write_ushort(1025)
        res.write_short(1)
        res.write_ushort(int(usr.avata))
        ro.sendData(res.getValue())
        User_connected(usr, ro)
        logging.getLogger("user").info(u"登录成功:" + u)
コード例 #5
0
ファイル: user_manager.py プロジェクト: TTXDM/firstGame
def enter_room(ro, data):
    """
    加入游戏房间;
    :param ro:
    :param data:
    :return:
    """
    obj = Parser(data)
    roomid = str(obj.read_short())
    tableid = obj.read_ubyte()
    pwd = obj.read_string()
    print u"enter_room:", roomid, tableid, pwd
    if roomid == "-1":
        roomid, tableid, msg = room_find_waiting()
        print u"room_find_waiting>>", roomid, tableid, msg
        if msg:
            res = Buffer()
            res.write_ushort(1032)
            res.write_short(-100)
            res.write_string(msg)
            ro.sendData(res.getValue())
            print u"自动匹配失败"
            return
    room, pos, msg, num = room_join_usr(ro.user, roomid, tableid)
    if not room:
        res = Buffer()
        res.write_ushort(1032)
        res.write_short(-100)
        res.write_string(msg)
        ro.sendData(res.getValue())
        return
    res = Buffer()
    res.write_ushort(1032)
    res.write_short(1)
    res.write_ushort(int(roomid))
    res.write_byte(tableid)
    ro.sendData(res.getValue())
    logging.getLogger("user").info(u"房间[%s]座位[%d]玩家<%s>加入ok" % (roomid, tableid, ro.user.id))

    res = Buffer()
    res.write_ushort(1052)
    res.write_string(ro.user.id)
    res.write_string(ro.user.nick)
    res.write_ushort(ro.user.sex)
    res.write_ushort(int(ro.user.avata))
    res.write_byte(tableid)
    res.write_short(int(roomid))
    res.write_byte(num)
    ddat = res.getValue()
    # 广播新玩家加入房间的消息;
    yield room_cast_msg(room, ddat)
    pageId = getattr(ro.user, "pageId", None)
    ss = page_get_users(pageId)
    for kk in ss:
        print "\t->", kk
        yield ss[kk].sendData(ddat)
    page_remove_user(ro, pageId)
    for i in range(4):
        if i == tableid:
            continue
        user = room_get_user(room, i)
        if not user:
            continue
        res = Buffer()
        res.write_ushort(1052)
        res.write_string(user.id)
        res.write_string(user.nick)
        res.write_ushort(user.sex)
        res.write_ushort(int(user.avata))
        res.write_byte(i)
        ro.sendData(res.getValue())

    @registe_msg_handler(ro, "connectionLost")
    @defer.inlineCallbacks
    def User_disconnected(*args, **kwargs):
        if hasattr(ro.user, "room"):
            room = ro.user.room
            logging.getLogger("room").info("room_disconnected: <%s>room[%s]table[%s]" % (ro.user.id, roomid, tableid))
            if hasattr(ro.user.room, "maj"):
                ro.user.room.maj.game_exit(ro, ro.user.tableid)
                res = Buffer()
                res.write_ushort(1099)
                res.write_string("exit")
                yield room_cast_msg(room, res.getValue())
                for i in range(4):
                    user = room_get_user(room, i)
                    if not user:
                        continue
                    if hasattr(user.room, "maj"):
                        del user.room.maj
                room_exit_usr(ro.user, ro.user.room.id, ro.user.tableid)

            res = Buffer()
            res.write_ushort(1053)
            res.write_string(ro.user.id)
            res.write_string(ro.user.nick)
            res.write_byte(tableid)
            res.write_short(int(roomid))
            ddat = res.getValue()
            # yield room_cast_msg(room,res.getValue())
            pageId = getattr(ro.user, "pageId", None)
            ss = page_get_users(pageId)
            for kk in ss:
                print "\t->", ss[kk].user.id
                yield ss[kk].sendData(ddat)
            page_remove_user(ro, pageId)
コード例 #6
0
ファイル: user_manager.py プロジェクト: TTXDM/firstGame
def lobby_user_chat(ro, data):
    """
    大厅用户聊天
    :param ro:
    :param data:
    :return:
    """
    obj = Parser(data)
    peer = obj.read_string()
    msg = obj.read_string()
    print u"user_chat:", peer, msg
    rc = yield redis.Connection()
    yield rc.select("0")
    me = ro.user
    if not me:
        print u"msg发送失败", u"登录过期"
        yield rc.disconnect()
        res = Buffer()
        res.write_ushort(1040)
        res.write_short(-101)
        res.write_string(u"登录过期")
        ro.sendData(res.getValue())
        return
    if peer == "All":
        res = Buffer()
        res.write_ushort(1040)
        res.write_short(1)
        res.write_string(u"ok")
        ro.sendData(res.getValue())
        mems = yield rc.smembers("lobby_usr")
        for mm in mems:
            ro2 = getSockByUsrId(mm)
            if not ro2:
                continue
            res = Buffer()
            res.write_ushort(1042)
            res.write_string(me.id)
            res.write_string(me.nick)
            res.write_string(msg)
            ro2.sendData(res.getValue())
        yield rc.disconnect()
        print u"发送成功!"
    else:
        usr = yield getUser(peer)
        if not usr:
            print u"msg发送失败", usr, usr or u"无次用户"
            yield rc.disconnect()
            res = Buffer()
            res.write_ushort(1040)
            res.write_short(-100)
            res.write_string(u"无此用户")
            ro.sendData(res.getValue())
            return
        ro2 = getSockByUsrId(peer)
        if not ro2:
            print u"msg发送失败", u"用户不在线"
            yield rc.disconnect()
            res = Buffer()
            res.write_ushort(1040)
            res.write_short(-101)
            res.write_string(u"用户不在线")
            ro.sendData(res.getValue())
            return
        yield rc.disconnect()
        print u"发送成功!"
        res = Buffer()
        res.write_ushort(1040)
        res.write_short(1)
        res.write_string(u"ok")
        ro.sendData(res.getValue())
        res = Buffer()
        res.write_ushort(1042)
        res.write_string(me.id)
        res.write_string(me.nick)
        res.write_string(msg)
        ro2.sendData(res.getValue())