Пример #1
0
    private void AnalysisMsg()
    {
        while (analysisBufferDataLength > 0)
        {
            int msgLength = BitConverter.ToInt32(analysisBuffer, 0);
            //Debug.Log("msg length " + msgLength);
            if (msgLength <= analysisBufferDataLength - 4)
            {
                readNetBuff.Set(analysisBuffer, 4, msgLength);
                int messageType = BitConverter.ToInt32(analysisBuffer, 4);
                var msg         = NetMessageFactory.GetMessage(messageType);
                if (msg != null)
                {
                    msg.Read(readNetBuff);
                    Messages.Enqueue(msg);
                    //Debug.Log("receve " + msg.MessageType);
                }
                else
                {
                    Debug.LogError("wrong message type " + messageType);
                }

                int remain = analysisBufferDataLength - msgLength - 4;
                Array.Copy(analysisBuffer, 4 + msgLength, analysisTempBuffer, 0, remain);
                Array.Copy(analysisTempBuffer, 0, analysisBuffer, 0, remain);
                analysisBufferDataLength = remain;
                //Debug.Log("remian " + remain);
                //Log();
            }
            else
            {
                break;
            }
        }
    }
Пример #2
0
        private static void AnalysisMsg(PlayerInfo info)
        {
            while (info.AnalysisBufferLength > 0)
            {
                int msgLength = BitConverter.ToInt32(info.AnalysisBuffer, 0);
                //Console.WriteLine("msg length " + msgLength);
                if (msgLength <= info.AnalysisBufferLength - 4)
                {
                    info.NetReadBuff.Set(info.AnalysisBuffer, 4, msgLength);
                    int messageType = BitConverter.ToInt32(info.AnalysisBuffer, 4);

                    if (messageType != (int)EmNetMessageType.CS_SYNCHRONIZATE)
                    {
                        Console.WriteLine("**** 错误,消息不是同步消息 " + messageType);
                    }
                    else
                    {
                        var msg = NetMessageFactory.GetMessage(messageType);
                        if (msg != null)
                        {
                            msg.Read(info.NetReadBuff);
                            NetCSSynchronizateMsg msgg = msg as NetCSSynchronizateMsg;

                            if (info.CurFrame == msgg.CurFrame)
                            {
                                info.OperationData       = msgg.OperationData;
                                info.IsOperationReceived = true;
                                info.CurFrame++;
                            }
                            else
                            {
                                Console.WriteLine("error: player {0} frame should be {1}, receive {2}", info.PlayerId, info.CurFrame, msgg.CurFrame);
                            }

                            //Console.WriteLine("receve " + msg.MessageType);
                        }
                        else
                        {
                            //Console.WriteLine("wrong message type " + messageType);
                        }
                    }

                    int remain = info.AnalysisBufferLength - msgLength - 4;
                    Array.Copy(info.AnalysisBuffer, 4 + msgLength, info.AnalysisTempBuffer, 0, remain);
                    Array.Copy(info.AnalysisTempBuffer, 0, info.AnalysisBuffer, 0, remain);
                    info.AnalysisBufferLength = remain;
                    //Debug.Log("remian " + remain);
                    //Log();
                }
                else
                {
                    break;
                }
            }
        }