Пример #1
0
        private static void HandleConnectionChange(BinaryReader reader, ACSProtocol packetID)
        {
            string driverName = ReadUnicodeString(reader);   // Driver name.
            string driverGUID = ReadUnicodeString(reader);   // Driver GUID.
            var    carID      = reader.ReadByte();

            if (packetID == ACSProtocol.NewConnection)
            {
                Console.WriteLine($"Driver joined: {driverName}");
                Driver curDriver;
                if (m_driversFromGUID.ContainsKey(driverGUID))
                {
                    curDriver = m_driversFromGUID[driverGUID];
                }
                else
                {
                    curDriver = new Driver(driverGUID);
                    m_driversFromGUID[driverGUID] = curDriver;
                }

                curDriver.Name  = driverName;
                curDriver.CarID = carID;
                curDriver.ResetPosition();
                m_driversFromCarID[carID] = curDriver;
            }
            else
            {
                Console.WriteLine($"Driver left: {driverName}");
                m_driversFromCarID.Remove(carID);
            }
        }
Пример #2
0
        private static void HandleNewSessionInfo(BinaryReader reader, ACSProtocol packetID)
        {
            reader.ReadByte();         // Version.
            reader.ReadByte();         // Session index.
            reader.ReadByte();         // Current session index.
            reader.ReadByte();         // Session count.
            ReadUnicodeString(reader); // Server name.

            string track       = ReadAsciiString(reader);
            string trackLayout = ReadAsciiString(reader);

            ReadAsciiString(reader);   // Session name.

            var prevSessionType = m_sessionType;

            m_sessionType = (SessionType)reader.ReadByte();

            if (packetID == ACSProtocol.NewSession)
            {
                if (!m_forwardingEnabled || m_overrideUpdateRate)
                {
                    ActivateRealTimeReporting();
                }

                string currentLayout = $"{track}-{trackLayout}";

                if (m_lastTrackLayout != currentLayout)
                {
                    Console.WriteLine($"Loading cut file for {track}-{trackLayout}");
                    CutTester.LoadTrack(track, trackLayout);
                    m_lastTrackLayout = $"{track}-{trackLayout}";
                }

                Console.WriteLine($"New session started: {m_sessionType}");

                if (prevSessionType == SessionType.Qualifying)
                {
                    OutputCutBestLaps();
                }

                WriteLog($"[Session] : Session ended {prevSessionType}");

                foreach (var driver in m_driversFromGUID)
                {
                    driver.Value.ResetLapCount();
                    driver.Value.ResetCutCount();
                }
            }
        }
Пример #3
0
 private static PluginMessage CreateInstance(ACSProtocol.MessageType msgType)
 {
     switch (msgType)
     {
         case ACSProtocol.MessageType.ACSP_VERSION: return new MsgVersionInfo();
         case ACSProtocol.MessageType.ACSP_SESSION_INFO: return new MsgSessionInfo();
         case ACSProtocol.MessageType.ACSP_NEW_SESSION: return new MsgSessionInfo(ACSProtocol.MessageType.ACSP_NEW_SESSION);
         case ACSProtocol.MessageType.ACSP_NEW_CONNECTION: return new MsgNewConnection();
         case ACSProtocol.MessageType.ACSP_CONNECTION_CLOSED: return new MsgConnectionClosed();
         case ACSProtocol.MessageType.ACSP_CAR_UPDATE: return new MsgCarUpdate();
         case ACSProtocol.MessageType.ACSP_CAR_INFO: return new MsgCarInfo();
         case ACSProtocol.MessageType.ACSP_LAP_COMPLETED: return new MsgLapCompleted();
         case ACSProtocol.MessageType.ACSP_END_SESSION: return new MsgSessionEnded();
         case ACSProtocol.MessageType.ACSP_CLIENT_EVENT: return new MsgClientEvent();
         case ACSProtocol.MessageType.ACSP_REALTIMEPOS_INTERVAL: return new RequestRealtimeInfo();
         case ACSProtocol.MessageType.ACSP_GET_CAR_INFO: return new RequestCarInfo();
         case ACSProtocol.MessageType.ACSP_SEND_CHAT: return new RequestSendChat();
         case ACSProtocol.MessageType.ACSP_BROADCAST_CHAT: return new RequestBroadcastChat();
         case ACSProtocol.MessageType.ACSP_ADMIN_COMMAND: return new RequestAdminCommand();
         case ACSProtocol.MessageType.ACSP_NEXT_SESSION: return new RequestNextSession();
         case ACSProtocol.MessageType.ACSP_RESTART_SESSION: return new RequestRestartSession();
         case ACSProtocol.MessageType.ACSP_CHAT: return new MsgChat();
         case ACSProtocol.MessageType.ACSP_GET_SESSION_INFO: return new RequestSessionInfo();
         case ACSProtocol.MessageType.ACSP_CLIENT_LOADED: return new MsgClientLoaded();
         case ACSProtocol.MessageType.ACSP_SET_SESSION_INFO: return new RequestSetSession();
         case ACSProtocol.MessageType.ACSP_ERROR: return new MsgError();
         case ACSProtocol.MessageType.ACSP_KICK_USER: return new RequestKickUser();
         case ACSProtocol.MessageType.ERROR_BYTE:
             throw new Exception("CreateInstance: MessageType is not set or wrong (ERROR_BYTE=0)");
         case ACSProtocol.MessageType.ACSP_CE_COLLISION_WITH_CAR:
         case ACSProtocol.MessageType.ACSP_CE_COLLISION_WITH_ENV:
             throw new Exception("CreateInstance: MessageType " + msgType + " is not meant to be used as MessageType, but as Subtype to ACSP_CLIENT_EVENT");
         default:
             throw new Exception("MessageType " + msgType + " is not known or implemented");
     }
 }
Пример #4
0
 public MsgSessionInfo(ACSProtocol.MessageType overridingNewSessionFlag)
     : base(ACSProtocol.MessageType.ACSP_NEW_SESSION)
 {
     if (overridingNewSessionFlag != ACSProtocol.MessageType.ACSP_NEW_SESSION)
         throw new Exception("MsgSessionInfo's type may only be overriden by ACSP_NEW_SESSION");
 }
Пример #5
0
        static void Main(string[] args)
        {
            Console.WriteLine($"Assetto Corsa Cut Detection Plugin - Version {m_version}");

            if (!ReadConfig())
            {
                Console.WriteLine("Config error, Exiting.");
                return;
            }

            if (m_loggingEnabled)
            {
                string filename = $"cutlog-{DateTime.UtcNow:yyyy-MM-dd-HH-mm-ss}.log";
                Console.WriteLine($"Opening log file {filename}");
                m_logFile = new StreamWriter(filename, false, Encoding.UTF8);
            }

            if (m_forwardingEnabled)
            {
                Console.WriteLine($"Opening Forwarding UDP Client at {m_clientDataPoint.Address}:{m_clientDataPoint.Port}");
                m_forwardClient = new UdpClient(m_clientCommandPoint);

                if (m_suppressSocketError)
                {
                    SuppressSocketError(m_forwardClient);
                }

                Console.WriteLine("Client Opened.");
                Thread commandThread = new Thread(CommandForwardTask);
                commandThread.Start();
            }

            Console.WriteLine($"Opening UDP Client at {m_serverDataPoint.Address}:{m_serverDataPoint.Port}");
            m_serverClient = new UdpClient(m_serverDataPoint);

            if (m_suppressSocketError)
            {
                SuppressSocketError(m_serverClient);
            }

            Console.WriteLine("Client Opened. Waiting for server.");

            while (true)
            {
                byte[] bytes = m_serverClient.Receive(ref m_serverCommandPoint);

                if (m_forwardingEnabled)
                {
                    m_forwardClient.Send(bytes, bytes.Length, m_clientDataPoint);
                }

                BinaryReader reader = new BinaryReader(new MemoryStream(bytes));

                ACSProtocol packetID = (ACSProtocol)reader.ReadByte();

                switch (packetID)
                {
                case ACSProtocol.CarInfo:
                case ACSProtocol.ClientEvent:
                case ACSProtocol.Version:
                case ACSProtocol.Chat:
                case ACSProtocol.ClientLoaded:
                case ACSProtocol.EndSession:
                    break;

                case ACSProtocol.LapCompleted:
                    HandleLapCompleted(reader);
                    break;

                case ACSProtocol.NewSession:     // Is immediately followed by session info.
                case ACSProtocol.SessionInfo:
                    HandleNewSessionInfo(reader, packetID);
                    break;

                case ACSProtocol.NewConnection:
                case ACSProtocol.ConnectionClosed:
                    HandleConnectionChange(reader, packetID);
                    break;

                case ACSProtocol.CarUpdate:
                    HandleCarUpdate(reader);
                    break;

                case ACSProtocol.Error:
                    Console.WriteLine("Error from server:");
                    Console.WriteLine($" - {ReadUnicodeString( reader )}");
                    break;

                default:
                    Console.WriteLine($"Invalid packet ID: {(byte)packetID}:H");
                    break;
                }
            }
        }
Пример #6
0
 public PluginMessage(ACSProtocol.MessageType type)
 {
     Type = type;
 }