public WaitForServerList() { conn = DistanceServerMain.Instance.Server.OnMasterServerEvent.Connect(evt => { if (evt == MasterServerEvent.HostListReceived) { conn.Disconnect(); conn = null; done = true; } }); }
public override void Start() { Log.Info("Basic Auto Server started!"); Playlist.AddRange(OfficialPlaylist); Filters = new List <FilterWorkshopSearchDelegate>(); ReadSettings(); Server.MasterServerGameModeOverride = MasterServerGameModeOverride; Server.ServerName = ServerName; Server.MaxPlayers = MaxPlayers; Server.Port = Port; Server.UseNat = UseNat; if (ReportToMasterServerInitialDelay > 0) { Server.ReportToMasterServer = false; DistanceServerMainStarter.Instance.StartCoroutine(SetReportToMasterServerAfterDelay()); } else { Server.ReportToMasterServer = ReportToMasterServer; } lastMasterServerRegistration = DistanceServerMain.UnixTime; if (PrivateServerPassword != null) { UnityEngine.Network.incomingPassword = PrivateServerPassword; } if (IdleTimeout > 0) { Server.OnPlayerConnectedEvent.Connect(player => { player.Countdown = countdownTime; player.OnCarAddedEvent.Connect(car => { car.AddExternalData(new LastMoveTimeData(DistanceServerMain.UnixTime)); }); }); } if (WelcomeMessage != null) { Server.OnPlayerValidatedEvent.Connect(player => { var message = WelcomeMessage; if (message.Contains("$linkcode") && LinkCodeGetter != null) { message = message.Replace("$linkcode", LinkCodeGetter(player)); } message = message.Replace("$player", player.Name); if (!Server.HasModeStarted || player.Car != null) { Server.SayLocalChat(player.UnityPlayer, DistanceChat.Server("AutoServer:Welcome", message)); } else { LocalEvent <DistanceCar> .EventConnection connection = null; connection = player.OnCarAddedEvent.Connect(car => { Server.SayLocalChat(player.UnityPlayer, DistanceChat.Server("AutoServer:Welcome", message)); connection.Disconnect(); }); } }); } Server.OnLevelStartedEvent.Connect(() => { LevelEndTime = -1.0; countdownTime = -1.0; }); Server.OnModeStartedEvent.Connect(() => { Log.DebugLine("BAS OMSE", 1); StartingPlayerGuids.Clear(); Log.DebugLine("BAS OMSE", 2); foreach (var player in Server.ValidPlayers) { Log.DebugLine("BAS OMSE", 3); if (player.Car != null) { Log.DebugLine("BAS OMSE", 4); player.Car.GetExternalData <LastMoveTimeData>().LastMoveTime = DistanceServerMain.UnixTime; Log.DebugLine("BAS OMSE", 5); SetStartingPlayer(player.UnityPlayerGuid, true); Log.DebugLine("BAS OMSE", 6); } Log.DebugLine("BAS OMSE", 7); } Log.DebugLine("BAS OMSE", 8); if (LevelEndTime == -1.0) { Log.DebugLine("BAS OMSE", 9); LevelEndTime = Server.ModeStartTime + LevelTimeout; } Log.DebugLine("BAS OMSE", 10); if (ServerStage == Stage.Starting) { Log.DebugLine("BAS OMSE", 11); ServerStage = Stage.Started; } Log.DebugLine("BAS OMSE", 12); }); OnAdvancingToNextLevel.Connect(() => { if (TipMessages.Count > 0) { var tip = TipMessages[currentTip]; currentTip = (currentTip + 1) % TipMessages.Count; Server.SayChat(DistanceChat.Server("AutoServer:Tip", tip)); } }); DistanceServerMain.GetEvent <Events.Instanced.Finished>().Connect((instance, data) => { Log.WriteLine($"{((DistanceCar)instance).Player.Name} finished"); if (ServerStage != Stage.Starting && ServerStage != Stage.Started && ServerStage != Stage.Timeout) { return; } AttemptToAdvanceLevel(); }); if (LoadWorkshopLevels) { DistanceServerMainStarter.Instance.StartCoroutine(DoLoadWorkshopLevels()); } else { StartAutoServer(); } }