Ejemplo n.º 1
0
    /// <summary>
    /// 发送消息方法
    /// </summary>
    /// <param name="isServer">是否为服务器</param>
    /// <param name="reciverUser">服务器根据用户创建</param>
    /// <returns></returns>
    public MsgsTransport GetSendMsgs(bool isServer = false, string reciverUser = "")
    {
        List <MsgData> sendDatas = null;

        if (isServer)
        {
            List <MsgData> reciverUserData     = new List <MsgData>(MsgList.Values.Where(x => (x.user == reciverUser)));
            Int64          reciveUserTimeStamp = 0;
            if (reciverUserData.Count > 0)
            {
                reciveUserTimeStamp = reciverUserData[0].timestamp;
            }
            sendDatas = new List <MsgData>(MsgList.Values.Where(x => x.timestamp > reciveUserTimeStamp && ((!isServer && x.user == user) || (isServer && x.user != reciverUser))));
        }
        else
        {
            sendDatas = new List <MsgData>(MsgList.Values.Where(x => x.timestamp > sendTimeLine && ((!isServer && x.user == user) || (isServer && x.user != reciverUser))));
        }

        Int64 currentTime = ChatManager.TimeStamp;

        if (sendDatas.Count == 0)
        {
            sendDatas.Add(BaseData.Instance <MsgData>().Set(currentTime, "nan", user));
        }
        string        sendTransportId = (isServer ? "s2c_" : "c2s_") + (isServer ? reciverUser : user) + "_" + ChatManager.TimeStamp.ToString();
        MsgsTransport transport       = BaseData.Instance <MsgsTransport>().Set(sendDatas, currentTime).Called(sendTransportId).As <MsgsTransport>();

        MsgTransportList.Add(transport.id, transport);
        return(transport);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// 接收到消息
    /// </summary>
    /// <param name="msgTrans"></param>
    public void OnReciveMsg(MsgsTransport msgTrans)
    {
        if (msgTrans == null || msgTrans.IsNull)
        {
            return;
        }
        //Console.WriteLine("recive:" + msgTrans.ToString());
        int count = 0;

        foreach (MsgData data in msgTrans.msglist)
        {
            if (MsgList.ContainsKey(data.timestamp))
            {
                //Console.WriteLine("键值重复:"+data.timestamp);
                //  throw new Exception("键值重复:" + data.timestamp);
                continue;
            }
            MsgList.Add(data.timestamp, data);
            count++;
        }
        MsgList.OrderBy(x => x.Key);
        if (count > 0 && showMsg)
        {
            ShowMsg();
        }
    }
Ejemplo n.º 3
0
    public void OnSended(byte[] sended)
    {
        string        json      = Encoding.UTF8.GetString(sended);
        MsgsTransport transport = BaseData.Instance <MsgsTransport>(json);

        serverChatManager.OnSendFinished(transport.id);
    }
Ejemplo n.º 4
0
    public void OnSended(byte[] sended)
    {
        //Console.WriteLine("On sended");
        string        json      = Encoding.UTF8.GetString(sended);
        MsgsTransport transport = BaseData.Instance <MsgsTransport>(json);

        chatManager.OnSendFinished(transport.id);
    }
Ejemplo n.º 5
0
    public byte[] dataTransfer(byte[] reciveData)
    {
        string json = Encoding.UTF8.GetString(reciveData);

        chatManager.OnReciveMsg(BaseData.Instance <MsgsTransport>(json));
        MsgsTransport send = chatManager.GetSendMsgs();

        return(send.ToBytes());
    }
Ejemplo n.º 6
0
    public byte[] dataTransfer(byte[] reciveData)
    {
        if (reciveData == null)
        {
            return(null);
        }
        string        json  = Encoding.UTF8.GetString(reciveData);
        MsgsTransport trans = BaseData.Instance <MsgsTransport>(json);

        serverChatManager.OnReciveMsg(trans);
        return(serverChatManager.GetSendMsgs(true, trans.msglist[0].user).ToBytes());
    }