Beispiel #1
0
    public void SndChat(MsgPack pack)
    {
        SndChat    data = pack.msg.sndChat;
        PlayerData pd   = cacheSvc.GetPlayerDataBySession(pack.session);

        // 任务进度数据更新
        PshTaskPrgs pshTaskPrgs = TaskSys.Instance.GetTaskPrgs(pd, 6);

        GameMsg msg = new GameMsg
        {
            cmd     = (int)CMD.PshChat,
            pshChat = new PshChat
            {
                name = pd.name,
                chat = data.chat
            },
            pshTaskPrgs = pshTaskPrgs
        };

        // 广播所有在线客户端
        List <ServerSession> lst = cacheSvc.GetOnlineServerSessions();

        // 重点优化,因为要给很多个客户端发送相同的数据,如果重复地序列化成二进制发送会重复浪费cpu,所以可以先序列化成二进制再重复发送
        byte[] bytes = PENet.PETool.PackNetMsg(msg);

        for (int i = 0; i < lst.Count; i++)
        {
            lst[i].SendMsg(bytes);
        }
    }
    public void SndChat(MsgPack msgPack)
    {
        SndChat    data = msgPack.msg.sndChat;
        PlayerData pd   = cacheSvc.GetPlayerDataBySettion(msgPack.session);
        GameMsg    msg  = new GameMsg
        {
            cmd     = (int)CMD.PshChat,
            pshChat = new PshChat
            {
                name = pd.name,
                chat = data.chat,
            },
        };

        //任务进度更新
        TaskSys.Instance.CalcTaskPrgs(pd, 6);//?需要更新吗
        //广播消息
        var lst = cacheSvc.GetOnlineSvrSessions();

        byte[] msgData = PENet.PETool.PackNetMsg(msg);//广播前提前序列化,减少次数
        foreach (var svrsin in lst)
        {
            svrsin.SendMsg(msgData);
        }
    }
Beispiel #3
0
    public void SndChat(PackMsg pack)
    {
        SndChat      data         = pack.msg.sndChat;
        PlayerData   pd           = cacheSvc.GetPlayerDataCache(pack.session);
        PshTaskProgs pshTaskProgs = null;

        //更新任务进度
        pshTaskProgs = TaskSys.Instance.CalcTaskProgs(pd, 6);

        GameMsg msg = new GameMsg {
            cmd     = (int)CMD.PshChat,
            pshChat = new PshChat
            {
                name = pd.name,
                msg  = data.msg
            }
        };

        if (pshTaskProgs != null)
        {
            msg.pshTaskProgs = pshTaskProgs;
        }

        //广播所有在线客户端
        List <ServerSession> sessionList = cacheSvc.GetOnLineServerSessions();

        foreach (ServerSession session in sessionList)
        {
            session.SendMsg(msg);
        }
    }
Beispiel #4
0
    public void SndChat(MsgPack pack)
    {
        SndChat    data = pack.msg.sndChat;
        PlayerData pd   = CacheSvc.Instance.GetPlayerDataBySession(pack.session);

        GameMsg msg = new GameMsg
        {
            cmd     = (int)CMD.PshChat,
            pshChat = new PshChat
            {
                name = pd.name,
                Chat = data.Chat
            }
        };

        //广播
        List <ServerSession> list = CacheSvc.Instance.GetOnlineServerSession();

        byte[] bytes = PENet.PETool.PackNetMsg(msg);
        for (int i = 0; i < list.Count; i++)
        {
            list[i].SendMsg(bytes);
        }

        TaskSys.Instance.CalcTaskPrgs(pd, 6);//更新任务进度数据
    }
Beispiel #5
0
    public void ClickSendBtn()
    {
        if (!canSend)
        {
            GameEntry.UI.AddTips("聊天消息每5秒钟才能发送一条");
            return;
        }

        if (iptChat.text != null && iptChat.text != "" && iptChat.text != " ")
        {
            if (iptChat.text.Length > 12)
            {
                GameEntry.UI.AddTips("输入信息不能超过12个字");
            }
            else
            {
                //发送网络消息到服务器
                CSPacketBase msg = new SndChat {
                    Chat = iptChat.text
                };
                iptChat.text = "";
                GameEntry.Net.SendMsg(msg);
                canSend = false;

                GameEntry.Timer.AddTimeTask((int tid) => {
                    canSend = true;
                }, 5, PETimeUnit.Second);
            }
        }
        else
        {
            GameEntry.UI.AddTips("尚未输入聊天信息");
        }
    }
Beispiel #6
0
    public void SndChat(MsgPack pack)
    {
        SndChat data = pack.Msg.sndChat;

        PlayerData pd = cacheSvc.GetPlayerDataBySession(pack.Session);

        //任务进度数据更新
        TaskSys.Instance.CalcTaskPrgs(pd, 6);

        GameMsg msg = new GameMsg()
        {
            cmd     = (int)CMD.PshChat,
            pshChat = new PshChat()
            {
                name = pd.name,
                chat = data.chat
            }
        };

        //广播所有在线客户端
        List <ServerSession> list = cacheSvc.GetOnlineServerSessions();

        byte[] bytes = PETool.PackNetMsg(msg);

        for (int i = 0; i < list.Count; i++)
        {
            list[i].SendMsg(bytes);
        }
    }
Beispiel #7
0
    public void SndChat(MsgPack pack)
    {
        SndChat data = pack.msg.sndChat;

        PlayerData playerData = cacheSvc.GetPlayerDataBySession(pack.session);

        // 任务进度更新
        TaskSys.Instance.CalcTaskPrgs(playerData, 6);

        GameMsg msg = new GameMsg {
            cmd     = (int)CMD.PshChat,
            pshChat = new PshChat {
                name = playerData.name,
                chat = data.chat
            }
        };

        // 广播所有在线客户端
        List <ServerSession> lst = cacheSvc.GetAllOnlineServerSessions();

        // 避免重复多次的Cpu自己的序列化二进制 消息(所以这里优先二进制,避免cpu重复多次浪费性能)
        byte[] bytes = PENet.PETool.PackNetMsg(msg);
        for (int i = 0; i < lst.Count; i++)
        {
            lst[i].SendMsg(bytes);
        }
    }
Beispiel #8
0
    public void SndChat(MsgPack pack)
    {
        SndChat    data = pack.gameMsg.val as SndChat;
        PlayerData pd   = cacheSvc.GetPlayerDataBySession(pack.session);

        TaskSys.Instance.CalcTaskPrgs(pd, 6);

        GameMsg msg = new GameMsg
        {
            cmd = (int)CMD.PshChat,
            val = new PshChat()
            {
                name = pd.name,
                chat = data.chat
            }
        };

        List <ServerSession> lst = cacheSvc.GetOnlineServerSession();

        byte[] bytes = PENet.PETool.PackNetMsg(msg);
        for (int i = 0; i < lst.Count; i++)
        {
            lst[i].SendMsg(bytes);
        }
    }
Beispiel #9
0
        public void SndChat(MsgPack pack)
        {
            SndChat    data = pack.msg.sndChat;
            PlayerData pd   = cacheSev.GetPlayerDataBySession(pack.session);
            string     txt  = cfgSev.SerachFilterWordAndReplace(data.txt);

            Console.WriteLine("Recive TXT: " + txt);

            GameMsg msg = new GameMsg
            {
                cmd     = (int)CMD.PshChat,
                pshChat = new PshChat
                {
                    name = pd.name,
                    txt  = txt
                }
            };

            byte[] buffer = PENet.PETool.PackNetMsg(msg);

            // 广播
            List <ServerSession> list = cacheSev.GetOnlineServerSessions();

            Console.WriteLine("List Len: " + list.Count);
            for (int i = 0; i < list.Count; i++)
            {
                list[i].SendMsg(buffer);
            }

            PshTaskPrgs ptp = TaskSystem.Instance.CalcTaskPrg(pd, 6);

            if (ptp != null)
            {
                GameMsg pshTaskMsg = new GameMsg
                {
                    cmd         = (int)CMD.PshTaskPrgs,
                    pshTaskPrgs = ptp
                };
                if (!cacheSev.UpdatePlayerData(pd))
                {
                    msg.err = (int)ErrorCode.UpdateDBError;
                }
                pack.session.SendMsg(pshTaskMsg);
            }
        }
    public void SndChat(MsgPack pack)
    {
        SndChat    data = pack.msg.sndChat;
        PlayerData pd   = cacheSvc.GetPlayerDataBySession(pack.session);

        GameMsg msg = new GameMsg {
            cmd     = (int)CMD.PshChat,
            pshChat = new PshChat {
                name = pd.name,
                chat = data.chat
            },
        };

        //同样的数据包多次分发只序列化一次
        byte[] bytes = PENet.PETool.PackNetMsg(msg);

        //并包处理
        //任务进度数据更新
        msg.pshTaskPrgs = TaskSys.Instance.GetPshTaskPrgs(pd, 6);

        if (!cacheSvc.UpdatePlayerData(pd.id, pd))
        {
            msg.err = (int)ErrorCode.UpdateDBError;
            pack.session.SendMsg(msg);
        }
        else
        {
            //广播所有在线客户端
            List <ServerSession> lst = cacheSvc.GetOnLineServerSessions();
            for (int i = 0; i < lst.Count; i++)
            {
                if (lst[i] != pack.session)
                {
                    lst[i].SendMsg(bytes);
                }
                else
                {
                    //自己发的消息要更新任务进度
                    pack.session.SendMsg(msg);
                }
            }
        }
    }
Beispiel #11
0
    public void SndChat(MsgPack pack)
    {
        SndChat    data = (SndChat)pack.msg;
        PlayerData pd   = cacheSvc.GetPlayerDataBySession(pack.session);

        //任务进度数据更新
        TaskSys.Instance.CalcTaskPrgs(pd, 6);

        SCPacketBase msg = new PshChat {
            Name = pd.Name,
            Chat = data.Chat
        };

        //广播所有在线客户端
        List <ClientSocket> lst = cacheSvc.GetOnlineServerSessions();

        //byte[] bytes = KDNet.KDTool.PackNetMsg(msg);
        for (int i = 0; i < lst.Count; i++)
        {
            lst[i].SendMsg(msg);
        }
    }
Beispiel #12
0
    /// <summary>
    /// 接收客户端的请求
    /// </summary>
    /// <param name="pack"></param>
    public void SndChat(MsgPack pack)
    {
        SndChat    data = pack.msg.sndChat;
        PlayerData pd   = cacheSvc.GetPlayerDataBySession(pack.session);

        TaskSys.Instance.CalcTaskPrgs(pd, 6); // 任务进度数据更新
        GameMsg msg = new GameMsg {
            cmd     = (int)CMD.PshChat,
            pshChat = new PshChat {
                name = pd.name,
                chat = data.chat // 聊天数据
            }
        };

        // 广播给所有在线客户端
        List <ServerSession> lst = cacheSvc.GetOnlineServerSessions();

        byte[] bytes = PENet.PETool.PackNetMsg(msg);
        for (int i = 0; i < lst.Count; i++)
        {
            lst[i].SendMsg(bytes); // 发送二进制数据,而不是直接发送 msg,可以节省 序列化 操作
        }
    }
Beispiel #13
0
    public void SndChat(MsgPack pack)
    {
        PlayerData pd   = cacheSvc.GetPlayeDataBySession(pack.session);
        SndChat    chat = pack.msg.sndChat;

        GameMsg msg = new GameMsg
        {
            cmd     = (int)CMD.PshChat,
            pndChat = new PshChat
            {
                name = pd.name,
                chat = chat.chat
            }
        };

        //广播所有在线客户端
        List <ServerSession> lst = cacheSvc.GetOnlineSeverSession();

        byte[] bytes = PENet.PETool.PackNetMsg(msg);
        for (int i = 0; i < lst.Count; i++)
        {
            lst[i].SendMsg(bytes);
        }
    }