public ConnectionEvent(ACSProtocolReader reader)
 {
     DriverName = reader.ReadStringW();
     DriverGuid = reader.ReadStringW();
     CarId      = reader.ReadByte();
     CarModel   = reader.ReadString();
     CarSkin    = reader.ReadString();
 }
 public CarInfoEvent(ACSProtocolReader reader)
 {
     CarId       = reader.ReadByte();
     IsConnected = reader.ReadByte() != 0;
     Model       = reader.ReadStringW();
     Skin        = reader.ReadStringW();
     DriverName  = reader.ReadStringW();
     DriverTeam  = reader.ReadStringW();
     DriverGuid  = reader.ReadStringW();
 }
        public readonly TimeSpan Elapsed; // Elapsed time from the start(this might be negative for races with WaitTime)

        public SessionInfoEvent(ACSProtocolReader reader)
        {
            Version             = reader.ReadByte();
            SessionIndex        = reader.ReadByte();
            CurrentSessionIndex = reader.ReadByte();
            SessionCount        = reader.ReadByte();

            ServerName      = reader.ReadStringW();
            Track           = reader.ReadString();
            TrackConfig     = reader.ReadString();
            Name            = reader.ReadString();
            Type            = reader.ReadByte();
            Time            = TimeSpan.FromSeconds(reader.ReadUInt16());
            Laps            = reader.ReadUInt16();
            WaitTime        = TimeSpan.FromSeconds(reader.ReadUInt16());
            AmbientTemp     = reader.ReadByte();
            RoadTemp        = reader.ReadByte();
            WeatherGraphics = reader.ReadString();
            Elapsed         = TimeSpan.FromMilliseconds(reader.ReadInt32());
        }
 public ChatEvent(ACSProtocolReader reader)
 {
     CarId   = reader.ReadByte();
     Message = reader.ReadStringW();
 }
示例#5
0
        public async Task DispatchMessagesAsync()
        {
            while (true)
            {
                var receiveResult = await _udpClient.ReceiveAsync();

                var acsReader = new ACSProtocolReader(receiveResult.Buffer);
                var packetId  = acsReader.ReadByte();

                switch (packetId)
                {
                case ACSProtocol.ACSP_ERROR:
                {
                    var message = acsReader.ReadStringW();
                    OnError?.Invoke(packetId, message);
                }
                break;

                case ACSProtocol.ACSP_CHAT:
                {
                    var eventData = new ChatEvent(acsReader);
                    OnChat?.Invoke(packetId, eventData);
                }
                break;

                case ACSProtocol.ACSP_CLIENT_LOADED:
                {
                    var carId = acsReader.ReadByte();
                    OnClientLoaded?.Invoke(packetId, carId);
                }
                break;

                case ACSProtocol.ACSP_VERSION:
                {
                    var protocolVersion = acsReader.ReadByte();
                    OnVersion?.Invoke(packetId, protocolVersion);
                }
                break;

                case ACSProtocol.ACSP_NEW_SESSION:
                {
                    var eventData = new SessionInfoEvent(acsReader);
                    OnNewSession?.Invoke(packetId, eventData);
                }
                break;

                case ACSProtocol.ACSP_SESSION_INFO:
                {
                    var eventData = new SessionInfoEvent(acsReader);
                    OnSessionInfo?.Invoke(packetId, eventData);
                }
                break;

                case ACSProtocol.ACSP_END_SESSION:
                {
                    var reportFile = acsReader.ReadStringW();
                    OnEndSession?.Invoke(packetId, reportFile);
                }
                break;

                case ACSProtocol.ACSP_CLIENT_EVENT:
                {
                    var eventData = new ClientEventEvent(acsReader);
                    OnClientEvent?.Invoke(packetId, eventData);
                }
                break;

                case ACSProtocol.ACSP_CAR_INFO:
                {
                    var eventData = new CarInfoEvent(acsReader);
                    OnCarInfo?.Invoke(packetId, eventData);
                }
                break;

                case ACSProtocol.ACSP_CAR_UPDATE:
                {
                    var eventData = new CarUpdateEvent(acsReader);
                    OnCarUpdate?.Invoke(packetId, eventData);
                }
                break;

                case ACSProtocol.ACSP_NEW_CONNECTION:
                {
                    var eventData = new ConnectionEvent(acsReader);
                    OnNewConnection?.Invoke(packetId, eventData);
                }
                break;

                case ACSProtocol.ACSP_CONNECTION_CLOSED:
                {
                    var eventData = new ConnectionEvent(acsReader);
                    OnConnectionClosed?.Invoke(packetId, eventData);
                }
                break;

                case ACSProtocol.ACSP_LAP_COMPLETED:
                {
                    var eventData = new LapCompletedEvent(acsReader);
                    OnLapCompleted?.Invoke(packetId, eventData);
                }
                break;
                }
            }
        }