Ejemplo n.º 1
0
        private void PrivProcessData()
        {
            NetIncomingMessage buff;

            while ((_connection.ReadMessage(out buff)) == true)
            {
                NetIncomingMessageType type = buff.MessageType;
                switch (type)
                {
                case NetIncomingMessageType.DebugMessage:
                    string debug1 = buff.ReadString();
                    Debug.WriteLine(debug1);
                    break;

                case NetIncomingMessageType.VerboseDebugMessage:
                    string debug2 = buff.ReadString();
                    Debug.WriteLine(debug2);
                    break;

                case NetIncomingMessageType.WarningMessage:
                    string warning = buff.ReadString();
                    Debug.WriteLine(warning);
                    break;

                case NetIncomingMessageType.ErrorMessage:
                    Debug.WriteLine(buff.ReadString());
                    break;

                case NetIncomingMessageType.StatusChanged:
                    NetConnectionStatus status = (NetConnectionStatus)buff.ReadByte();
                    string reason = buff.ReadString();
                    Debug.WriteLine(status.ToString() + ": " + reason);
                    break;

                case NetIncomingMessageType.Data:

                    int t;

                    if (buff.ReadInt32(out t))
                    {
                        switch ((DataItem.DATA_TYPE)t)
                        {
                        case DataItem.DATA_TYPE.ACK_TYPE:

                            break;

                        case DataItem.DATA_TYPE.EVENT_TYPE:
                            EventData event_d = new EventData();
                            event_d.Deserialize(ref buff);
                            DataManager.PushToIn(new DataItem(DataItem.DATA_TYPE.EVENT_TYPE, event_d));
                            break;

                        case DataItem.DATA_TYPE.INPUT_TYPE:
                            InputData input = new InputData();
                            input.Deserialize(ref buff);
                            DataManager.PushToIn(new DataItem(DataItem.DATA_TYPE.INPUT_TYPE, input));
                            break;

                        case DataItem.DATA_TYPE.SIM_DATA:
                            SimData sim = new SimData();
                            sim.Deserialize(ref buff);
                            DataManager.PushToIn(new DataItem(DataItem.DATA_TYPE.SIM_DATA, sim));
                            break;

                        case DataItem.DATA_TYPE.STATE_TYPE:
                            StateData state = new StateData();
                            state.Deserialize(ref buff);
                            DataManager.PushToIn(new DataItem(DataItem.DATA_TYPE.STATE_TYPE, state));
                            break;
                        }
                    }

                    break;

                case NetIncomingMessageType.UnconnectedData:
                    Debug.WriteLine("Recv(" + buff.SenderEndPoint + "): " + buff.ReadString());
                    break;

                case NetIncomingMessageType.DiscoveryResponse:
                    Debug.WriteLine("Found server at " + buff.SenderEndPoint + " name: " + buff.ReadString());
                    _connection.Connect(buff.SenderEndPoint);
                    break;
                }

                _connection.Recycle(buff);
            }
        }