/// <summary> /// Runs the game mode of this runner. /// </summary> /// <returns>true if shut down by the game mode, false otherwise.</returns> /// <exception cref="Exception">Thrown if a game mode is already running.</exception> public bool Run() { InternalStorage.RunningClient = this; // Prepare the syncronization context _messageQueue = new NoWaitMessageQueue(); _synchronizationContext = new SampSharpSynchronizationContext(_messageQueue); SynchronizationContext.SetSynchronizationContext(_synchronizationContext); _mainThread = Thread.CurrentThread.ManagedThreadId; _running = true; CoreLog.Log(CoreLogLevel.Initialisation, "SampSharp GameMode Client"); CoreLog.Log(CoreLogLevel.Initialisation, "-------------------------"); CoreLog.Log(CoreLogLevel.Initialisation, $"v{CoreVersion.Version.ToString(3)}, (C)2014-2020 Tim Potze"); CoreLog.Log(CoreLogLevel.Initialisation, "Hosted run mode is active."); CoreLog.Log(CoreLogLevel.Initialisation, ""); // TODO: Verify plugin version _gameModeProvider.Initialize(this); return(true); }
private async void Initialize() { _mainThread = Thread.CurrentThread.ManagedThreadId; CoreLog.Log(CoreLogLevel.Initialisation, "SampSharp GameMode Client"); CoreLog.Log(CoreLogLevel.Initialisation, "-------------------------"); CoreLog.Log(CoreLogLevel.Initialisation, $"v{CoreVersion.Version.ToString(3)}, (C)2014-2020 Tim Potze"); CoreLog.Log(CoreLogLevel.Initialisation, "Multi-process run mode is active. FOR DEVELOPMENT PURPOSES ONLY!"); CoreLog.Log(CoreLogLevel.Initialisation, "Run your server in hosted run mode for production environments. See https://sampsharp.net/running-in-production for more information."); CoreLog.Log(CoreLogLevel.Initialisation, ""); AppDomain.CurrentDomain.ProcessExit += (sender, args) => { CoreLog.Log(CoreLogLevel.Info, "Shutdown signal received"); ShutDown(); if (_mainRoutine != null && !_mainRoutine.IsCompleted) { _mainRoutine.Wait(); } if (_networkingRoutine != null && !_networkingRoutine.IsCompleted) { _networkingRoutine.Wait(); } }; CoreLog.Log(CoreLogLevel.Info, $"Connecting to the server via {CommunicationClient}..."); await CommunicationClient.Connect(); _running = true; CoreLog.Log(CoreLogLevel.Info, "Set up networking routine..."); StartNetworkingRoutine(); CoreLog.Log(CoreLogLevel.Info, "Connected! Waiting for server announcement..."); ServerCommandData data; do { data = await _commandWaitQueue.WaitAsync(); // Could receive ticks if reconnecting. } while (data.Command == ServerCommand.Tick); if (!VerifyVersionData(data)) { return; } CoreLog.Log(CoreLogLevel.Info, "Initializing game mode provider..."); _gameModeProvider.Initialize(this); CoreLog.Log(CoreLogLevel.Info, "Sending start signal to server..."); Send(ServerCommand.Start, new[] { (byte)_startBehaviour }); CoreLog.Log(CoreLogLevel.Info, "Set up main routine..."); _mainRoutine = MainRoutine(); }
private async void Initialize() { CoreLog.Log(CoreLogLevel.Initialisation, "SampSharp GameMode Client"); CoreLog.Log(CoreLogLevel.Initialisation, "-------------------------"); CoreLog.Log(CoreLogLevel.Initialisation, $"v{CoreVersion.Version.ToString(3)}, (C)2014-2019 Tim Potze"); CoreLog.Log(CoreLogLevel.Initialisation, ""); _mainThread = Thread.CurrentThread.ManagedThreadId; _running = true; CoreLog.Log(CoreLogLevel.Info, $"Connecting to the server via {CommunicationClient}..."); await CommunicationClient.Connect(); CoreLog.Log(CoreLogLevel.Info, "Set up networking routine..."); StartNetworkingRoutine(); CoreLog.Log(CoreLogLevel.Info, "Connected! Waiting for server announcement..."); ServerCommandData data; do { data = await _commandWaitQueue.WaitAsync(); // Could receive ticks if reconnecting. } while (data.Command == ServerCommand.Tick); if (!VerifyVersionData(data)) { return; } CoreLog.Log(CoreLogLevel.Info, "Initializing game mode provider..."); _gameModeProvider.Initialize(this); CoreLog.Log(CoreLogLevel.Info, "Sending start signal to server..."); Send(ServerCommand.Start, new[] { (byte)_startBehaviour }); CoreLog.Log(CoreLogLevel.Info, "Set up main routine..."); MainRoutine(); }