Ejemplo n.º 1
0
 def create_friend(self, user_id, target_user_id):
     debug("create_friend: ", user_id, target_user_id)
     now = fttime.getCurrentTimestamp()
     info = {"time": now, "last_msg": "hi", "remark": ""}
     self.friend_dao.create_friend(user_id, target_user_id,
                                   ftstr.dumps(info))
     system_chat(user_id, target_user_id, 2)
Ejemplo n.º 2
0
    def doReportGameResult(self, userId, mini_game_id, msg):
        """
        小游戏比赛服上报游戏结果.
        mo.setResult('winnerId', self.winnerId)
        mo.setResult('userId_a', self.userId_a)
        mo.setResult('userId_b', self.userId_b)
        mo.setResult('table_msgId', self.table_msgId)
        """
        debug("ChatGameSrv : report_game_result : msg = ",userId,mini_game_id, msg, type(msg))
        msg = ftstr.loads(msg)
        user_id = msg.get('userId_a')
        target_user_id = msg.get('userId_b')
        win_user_id = msg.get('winnerId')
        if isinstance(user_id, int) and user_id > 0 and isinstance(target_user_id, int) and target_user_id > 0 and \
                isinstance(win_user_id, int):
            msg_id = msg.get('table_msgId')
            if not msg_id or msg_id == -1:
                now = current_milli_time()
                msg_id = get_msg_id(user_id, target_user_id, now)
                content = ftstr.dumps({'miniGameId': mini_game_id, 'code': 'result'})
                game_message = GameChatMessage(user_id, target_user_id, 2, now, content)
                self.service.save_record(user_id, target_user_id, msg_id, game_message)

            debug("ChatGameSrv report_game_result", user_id, target_user_id, msg_id, win_user_id)
            self.service.save_record_result(user_id, target_user_id, msg_id, win_user_id)
            record = self.service.get_record(msg_id)
            if record:
                # 结果推送给双方
                game_message = GameChatMessage.load_info(record)
                push_game_message(user_id, target_user_id, msg_id, game_message)
                # 所有的对战消息都在sns中存储为对战记录
                _upload_vs_record(user_id, target_user_id, mini_game_id, win_user_id)
                return 1
        return 0
Ejemplo n.º 3
0
 def leave_channel(self, msg):
     """
     离开临时会话.(一方退出即终结临时会话)
     :param msg:
     :return:
     """
     debug("ChatSrv leave_channel", msg)
     user_id = msg.getParamInt('userId')
     target_user_id = msg.getParamInt('targetUserId')
     channel_key = _get_channel_key(user_id, target_user_id)
     if channel_key in self.channels:
         del self.channels[channel_key]
         debug("ChatSrv clean channel", channel_key)
         is_friend = _check_friend(user_id, target_user_id)
         if not is_friend:
             now = current_milli_time()
             msg_id = get_msg_id(user_id, target_user_id, now)
             content = ftstr.dumps({"code": "chat", "status": "leave_channel"})
             system_message = ChatMessage(user_id, target_user_id, 7, now, content)
             self.service.save_record(user_id, target_user_id, msg_id, system_message)
             # 回应对方离线
             self.write(target_user_id, user_id, msg_id, system_message)
             # TODO 清理临时聊天消息
         ftcore.runOnceDelay(0.1, self.__do_leave_game_message,user_id, target_user_id)
     if channel_key in self.tmp_channels:
         del self.tmp_channels[channel_key]
         debug("ChatSrv clean temp channel", channel_key)
Ejemplo n.º 4
0
 def sns_system_message(self, user_id, target_user_id, code):
     """
     收到添加好友邀请/添加好友邀请被通过.
     :param user_id:
     :param target_user_id:
     :param code:
     :return:
     """
     debug("ChatSrv sns_system_message", user_id, target_user_id, code)
     # resp = MsgPack()
     # resp.setCmd('chat')
     #1 xxx,请求添加你为好友(不存储/打招呼的语言-以上是打招呼的内容)
     #2 你的添加好友请求已被xxx通过(生成一条你们刚刚成为好友/你已经添加xxx,现在可以开始聊天了。)
     #3 对方已离开聊天,添加好友继续聊天
     #4 xxx(你),撤回了一条消息
     #5 你的消息不能够送达(被删除、屏蔽)
     #6 游戏结果
     now = current_milli_time()
     code_status = ["invite", "accept"][code-1]
     content = ftstr.dumps({"code": "sns", "status": code_status})
     system_message = ChatMessage(user_id, target_user_id, 7, now, content)
     msg_id = get_msg_id(user_id,target_user_id,now)
     # 申请不计入聊天消息
     if code == 1:
         self.service.save_record(user_id, target_user_id, msg_id, system_message)
     # 各回应一条
     self.write(user_id, target_user_id, msg_id, system_message)
     self.write(target_user_id, user_id, msg_id, system_message)
     return 1
Ejemplo n.º 5
0
 def do_leave_chat_record(self, user_id, target_user_id, score):
     msg_list = self.record_dao.get_next_record_list(
         user_id, target_user_id, score)
     debug("do_leave_chat_record", msg_list)
     datas = len(msg_list) - 1
     i = 0
     msg_ids = []
     while i < datas:
         msg_id = msg_list[i]
         info = self.get_record(msg_list[i])
         time = info.get("time")
         msg_type = info.get("msgType")
         content = info.get("content")
         uid = info.get("userId")
         tid = info.get("targetUserId")
         content_obj = ftstr.loads(content)
         mini_game_id = content_obj.get("miniGameId")
         ex_code = content_obj.get("code")
         if ex_code == "invite":
             info = {"miniGameId": mini_game_id, "code": "leave"}
             content = ftstr.dumps(info)
             info = {
                 "time": time,
                 "userId": uid,
                 "targetUserId": tid,
                 "msgType": msg_type,
                 "content": content
             }
             self.save_record(user_id, target_user_id, msg_id, info)
         msg_ids.append(msg_id)
         i += 2
     return msg_ids
Ejemplo n.º 6
0
    def checkUserOrderListLimit(self, userId):
        dataLen = DaoUserOrderList.HLEN(userId)
        if dataLen <= DaoUserOrderList.MAX_DATA_LENGTH:
            return

        # 超过最大数量限制时,删除历史数据
        orderIds = DaoUserOrderList.HKEYS(userId)
        historys = []
        for orderId in orderIds:
            datas = DaoUserOrderList.HGET(userId, orderId)
            datas.append(orderId)
            historys.append(datas)

        # 按时间排序, 7天以上的或已完结的记录优先删除
        historys.sort(key=lambda x: x[0], reverse=True)
        ct = fttime.getCurrentTimestamp() - 7 * 24 * 60 * 60  # 7 天前的时间点
        for x in xrange(DaoUserOrderList.MAX_DATA_LENGTH, len(historys)):
            isTimeOut = historys[x][0] <= ct
            isFinished = historys[x][5] not in (TYOrder.STATE_CREATE,
                                                TYOrder.STATE_DELIVERYING)
            if isTimeOut or isFinished:
                orderId = historys[x][-1]
                order = DaoGameOrder.HGETALL(0, orderId)
                ftlog.info('AUTO CLEANUP STORE ORDER->', userId, orderId,
                           ftstr.dumps(order))
                DaoUserOrderList.HDEL(userId, orderId)
                DaoGameOrder.DEL(0, orderId)
Ejemplo n.º 7
0
def _doExchangeRequestGdss(userId, exchangeId, mi):
    if _DEBUG:
        debug('_doExchangeRequestGdss IN', userId, mi)

    parasDict = {}
    parasDict['callbackAudit'] = tyglobal.httpGame(
    ) + '/api/hall5/exchange/auditCallback'
    parasDict['callbackShipping'] = tyglobal.httpGame(
    ) + '/api/hall5/exchange/shippingCallback'
    parasDict['user_id'] = userId
    parasDict['exchange_id'] = exchangeId
    parasDict['prod_id'] = mi.itemId
    parasDict['prod_num'] = 1
    parasDict['prod_kind_name'] = mi.displayName
    parasDict['exchange_type'] = mi.type
    parasDict['exchange_amount'] = mi.count
    parasDict['exchange_desc'] = ''
    parasDict['user_phone'] = mi.phone
    parasDict['user_name'] = mi.uName
    parasDict['user_addres'] = mi.uAddres
    # 微信红包需要
    parasDict['wxappid'] = mi.wxappid
    # 京东实物兑换需要
    parasDict['jd_product_id'] = mi.jd_product_id
    parasDict['user_province'] = mi.proviceId
    parasDict['user_city'] = mi.cityId
    parasDict['user_district'] = mi.countyId
    parasDict['user_town'] = mi.townId

    res = tyrpcgdss.itemExchange(parasDict)
    retcode = res.get('retcode', -1)

    if retcode != 1:
        state = _dao.TYExchangeRecord.STATE_GDSS_AUDIT_ERROR_FAIL
        errMsg = '兑换请求出错(' + res.get('retmsg', '') + ')'
    else:
        state = _dao.TYExchangeRecord.STATE_GDSS_AUDIT
        errMsg = None

    if _DEBUG:
        debug('_doExchangeRequestGdss userId=', userId, 'exchangeId=',
              exchangeId, 'parasDict=', ftstr.dumps(parasDict), 'response=',
              ftstr.dumps(res), 'state=', state, 'errMsg=', errMsg)
    return errMsg, state
Ejemplo n.º 8
0
    def addCreateTableNo(cls, tableId, roomId, serverId, tableNoKey,
                         initParams):
        """添加自建桌验证码数据 只在GT服调用
        """
        tableNoMapValue = ftstr.dumps([tableId, roomId])
        initString = ftstr.dumps(initParams)
        if _DEBUG:
            debug('CreateTableData.addCreateTableNo tableId:', tableId,
                  ' roomId:', roomId, ' serverId:', serverId, ' tableNoKey:',
                  tableNoMapValue, ' initParams:', initString)
        keyList = [
            cls._getCreateTableNoKey(), tableNoKey, serverId,
            cls._getTableNoMapTableIdKey(), tableId, tableNoMapValue,
            cls._getTableNoParamsKey(), initString
        ]
        result = cls.EVALSHA(0, cls._LUA_ADD_CREATE_TABLE_NO_SCRIPT_NAME,
                             keyList)

        ftlog.info("CreateTableData.addCreateTableNo serverId:", serverId,
                   " tableNoKey:", tableNoKey, " result:", result)
        return result
Ejemplo n.º 9
0
 def save_record_result(self, user_id, target_user_id, message_id,win_user_id):
     debug("save record:  ", user_id, target_user_id,message_id, win_user_id)
     info = DaoChatRecordHash.HGET(0, message_id)
     if info:
         debug("save record: ", user_id, target_user_id, info, type(info))
         content = info.get("content")
         # TODO 应该都是字符串吧
         content_obj = ftstr.loads(content)
         content_obj["code"] = "result"
         content_obj["winUserId"] = win_user_id
         info["content"]=ftstr.dumps(content_obj)
         DaoChatRecordHash.HSET(0, message_id, info)
Ejemplo n.º 10
0
 def again_game(self, msg):
     """
     再来一局.
     TODO 并发
     :param msg: userId,targetUserId,miniGameId
     :return: msgId,ok
     """
     debug("ChatGameSrv again_game", msg)
     user_id = msg.getParamInt('userId')
     target_user_id = msg.getParamInt('targetUserId')
     mini_game_id = msg.getParamInt('miniGameId')
     resp = MsgPack()
     resp.setCmd('chat')
     resp.setResult('action', 'again_game')
     try:
         double_again,now,msg_id = self.check_channel(user_id,target_user_id)
         if double_again:
             info = self.service.get_record(msg_id)
             if info:
                 game_message = GameChatMessage.load_info(info)
                 game_message.code = "accept"
                 self.service.save_record(user_id, target_user_id, msg_id, game_message)
                 ftcore.runOnceDelay(0.1, self.__do_answer_again_game_message, user_id, target_user_id, "accept",
                                     msg_id)
                 push_game_message(user_id, target_user_id, msg_id, game_message)
                 resp.setResult('status', 'error')
             else:
                 raise StrangerException()
         else:
             content = ftstr.dumps({'miniGameId': mini_game_id, 'code': 'invite'})
             game_message = GameChatMessage(user_id, target_user_id, 2, now, content)
             self.service.save_record(user_id, target_user_id, msg_id, game_message)
             ftcore.runOnceDelay(0.1, self.__do_again_game_message,user_id,target_user_id,msg_id)
             push_game_message(user_id, target_user_id, msg_id, game_message)
             debug("ChatGameSrv again_game", msg_id)
             resp.setResult('msgId', msg_id)
             resp.setResult('userId', user_id)
             resp.setResult('targetUserId', target_user_id)
             resp.setResult('status', 'ok')
     except TYBizException, e:
         resp.setResult('status', 'error')
         resp.setError(e.errorCode, e.message)
Ejemplo n.º 11
0
 def verify_2(self, msg):
     content = msg.getParamStr("content")
     obj = ftstr.loads(content)
     message_id = obj.get("msgId","")
     if message_id:
         code = obj.get("code", "refuse")
         info = self.service.get_record(message_id)
         if info:
             time = info.get("time")
             content = info.get("content")
             mini_game_id = ftstr.loads(content).get("miniGameId")
             info = {"miniGameId": mini_game_id, "code": code}
             content = ftstr.dumps(info)
         else:
             raise StrangerException()
     else:
         # TODO 校验minigameID及code
         time = current_milli_time()
         message_id = self.get_message_id(msg,time)
     return message_id, content, time
Ejemplo n.º 12
0
 def save(cls, info):
     jstr = ftstr.dumps(info.toDict())
     # daobase.executeUserCmd(info.userId, 'hset', cls.buildKey(info.userId), info.matchId, jstr)
     daobase.saveMatchPlayerInfo(info.userId, info.matchId, jstr)
Ejemplo n.º 13
0
 def code(self, code):
     self._code_ = code
     self._content = ftstr.dumps({
         "miniGameId": self._miniGameId_,
         "code": self._code_
     })
Ejemplo n.º 14
0
def saveRoomInfo(gameId, roomInfo):
    d = roomInfo.toDict()
    jstr = ftstr.dumps(d)
    DaoRoomInfo.HSET(gameId, roomInfo.roomId, jstr)