コード例 #1
0
ファイル: PlayerChatCommand.cs プロジェクト: 37Sir/WarChess
    private void Request(int index)
    {
        PlayerChatRequest.Builder request = PlayerChatRequest.CreateBuilder();
        request.SetNumber(index);
        var bytes = request.Build().ToByteArray();

        App.NetworkManager.Request("PlayerChat", bytes, Response);
    }
コード例 #2
0
    /// <summary>
    /// 创建实例
    /// </summary>
    public static PlayerChatRequest create(ChatData data, int channel, long key)
    {
        PlayerChatRequest re = (PlayerChatRequest)BytesControl.createRequest(dataID);

        re.data    = data;
        re.channel = channel;
        re.key     = key;
        return(re);
    }
コード例 #3
0
    //-------------------------------------------------------------------------
    async void c2sPlayerChatRequest(PlayerChatRequest playerchat_request)
    {
        IRpcSession s           = EntityMgr.LastRpcSession;
        ClientInfo  client_info = CoApp.getClientInfo(s);

        if (client_info == null)
        {
            return;
        }

        var task = await Task.Factory.StartNew <Task <MethodData> >(async() =>
        {
            MethodData method_data = new MethodData();
            method_data.method_id  = MethodType.c2sPlayerChatRequest;
            method_data.param1     = EbTool.protobufSerialize <PlayerChatRequest>(playerchat_request);

            MethodData r = null;
            try
            {
                var grain_playerproxy = GrainClient.GrainFactory.GetGrain <ICellPlayer>(new Guid(client_info.et_player_guid));
                r = await grain_playerproxy.c2sRequest(method_data);
            }
            catch (Exception ex)
            {
                EbLog.Error(ex.ToString());
            }

            return(r);
        });

        if (task.Status == TaskStatus.Faulted || task.Result == null)
        {
            if (task.Exception != null)
            {
                EbLog.Error(task.Exception.ToString());
            }

            return;
        }

        MethodData result = task.Result;

        if (result.method_id == MethodType.None)
        {
            return;
        }

        lock (CoApp.RpcLock)
        {
            var playerchat_response = EbTool.protobufDeserialize <PlayerChatResponse>(result.param1);
            CoApp.rpcBySession(s, (ushort)MethodType.s2cPlayerChatResponse, playerchat_response);
        }
    }
コード例 #4
0
    /// <summary>
    /// 发送聊天
    /// </summary>
    public void chat(ChatData data, int channel, long key)
    {
        ChatChannelConfig config = ChatChannelConfig.get(channel);

        //条件不满足
        if (!me.role.checkRoleConditions(config.useConditions, true))
        {
            me.warnLog("聊天条件不满足", channel);
            return;
        }

        ChatChannelData cData = getChatChannelData(channel, key);

        long now = me.getTimeMillis();

        if (config.cd > 0 && (cData.lastChatTime + config.cd > now))
        {
            me.warnLog("聊天cd中", channel);
            return;
        }

        if (config.costID > 0 && !me.bag.hasCost(config.costID))
        {
            me.warnLog("聊天cost不足", channel);
            return;
        }

        //文字
        if (data.type == ChatType.Text && BaseGameUtils.hasSensitiveWord(data.text))
        {
            me.warnLog("聊天有屏蔽字内容", data.text);
            return;
        }

        if (config.cd > 0)
        {
            cData.lastChatTime = now;
        }

        //需要自行添加的
        if (channel == ChatChannelType.Whisper)
        {
            RoleChatData rData = new RoleChatData();
            rData.chatData  = data;
            rData.showData  = me.role.createRoleSimpleShowData();
            rData.time      = me.getTimeMillis();
            rData.sendIndex = _chatReceiveIndex;          //当前序号
            onReceiveChat(rData, channel, key);
        }

        me.send(PlayerChatRequest.create(data, channel, key));
    }