Ejemplo n.º 1
0
 public void CallEventMsg(MessageReceiveData _data)
 {
     if (msgCallBack != null)
     {
         msgCallBack(_data);
     }
 }
Ejemplo n.º 2
0
        public void DealMsg(MessageReceiveData _data)
        {
            if (_data == null)
            {
                return;
            }
            byte[]     _dataBytes   = _data.receiveBytes;
            IPEndPoint receivePoint = _data.receivePoint;
            ByteBuffer _buff        = new ByteBuffer(_dataBytes);
            int        length       = _buff.ReadInt32();

            byte[] _bytes = _buff.ReadBytes(length);
            MessageData <BaseMessageData> data = ProtoBufTools.DeSerialize <MessageData <BaseMessageData> > (_bytes);

            if (data.body.dealFlg == 0)
            {
                if (Main.Self.clientType == ClientType.server)
                {
                    if (data.head.cmd == 1 && data.head.scmd == 1)
                    {
                        Main.Self.server.AddPlayer(receivePoint);
                    }
                    else if (data.head.cmd == 1 && data.head.scmd == 2)
                    {
                        Main.Self.server.RemovePlayer(receivePoint);
                    }
                    byte[]     _serverDealBytes = ServerDealMsg(data, receivePoint);
                    ByteBuffer _serverDealBuff  = new ByteBuffer();
                    _serverDealBuff.WriteInt32(_serverDealBytes.Length);
                    _serverDealBuff.WriteBytes(_serverDealBytes);
                    Main.Self.server.AddSendQueue(_serverDealBuff.ToBytes());
                }
            }
            else
            {
                if (Main.Self.clientType == ClientType.server)
                {
                }
                else
                {
                }
                SwitchMsg(data);
            }
        }
Ejemplo n.º 3
0
        //服务器接收
        public void SocketReceive()
        {
            //定义服务端
            IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);

            serverEnd = (EndPoint)sender;
            //进入接收循环
            while (true)
            {
                //对data清零
                byte[] recvData = new byte[1024];
                //获取客户端,获取服务端端数据,用引用给服务端赋值,实际上服务端已经定义好并不需要赋值
                recvLen = socket.ReceiveFrom(recvData, ref serverEnd);
                if (recvLen > 0)
                {
                    MessageReceiveData data = new MessageReceiveData();
                    data.receivePoint = serverEnd;
                    data.receiveBytes = recvData;
                    Main.Self.messageQueue.Enqueue(data);
                }
            }
        }
Ejemplo n.º 4
0
        //服务器接收
        public void SocketReceive()
        {
            //定义客户端
            IPEndPoint sender   = new IPEndPoint(IPAddress.Any, 0);
            EndPoint   endPoint = (EndPoint)sender;

            //进入接收循环
            while (true)
            {
                //对data清零
                byte[] recvData = new byte[1024];
                //获取客户端,获取客户端数据,用引用给客户端赋值
                recvLen = socket.ReceiveFrom(recvData, ref endPoint);
                if (recvLen > 0)
                {
                    MessageReceiveData data = new MessageReceiveData();
                    data.receivePoint = endPoint;
                    data.receiveBytes = recvData;
                    Main.Self.messageQueue.Enqueue(data);
                }
            }
        }