void PregameTimerThread() { MRKToSLogger.LogInfo("Pregame timer thread started"); while (true) { if (PregameTimer.Enabled) { MatchListener.OnPregameTimerStateChanged(new MRKToSTimerEvent(PregameTimer, MRKTosTimerEventState.Updated)); if (PregameTimer.RelativeCurrent <= 0) { MRKToSLogger.LogInfo("Pregame timer ended"); Players = new List <MRKToSPlayer>(); foreach (MRKToSUser user in m_QueuedUsers) { Players.Add(new MRKToSPlayer(user, this, Players.Count + 1)); } SwitchToState(State.Names); break; } } Thread.Sleep(200); // i like to sleep for 200 mils } }
/// <summary> /// Add a user to the queue /// </summary> /// <param name="user"></param> public bool QueueUser(MRKToSUser user) { if (MatchState != State.Waiting) { MRKToSLogger.LogError($"Can not queue {user.Username} to the match, match has already started or is still idle"); return(false); } if (FindQueuedUser(user.Username) != null) { MRKToSLogger.LogWarning($"User {user.Username} is already queued"); return(false); } if (m_QueuedUsers.Count >= Settings.MaximumPlayerCount) { MRKToSLogger.LogWarning($"Can not que {user.Username} to the match, match has maximum player count"); return(false); } m_QueuedUsers.Add(user); MRKToSLogger.LogInfo($"User {user.Username} has been added to the queue"); LogQueueCount(); MatchListener.OnQueueUserAdded(user); UpdatePregame(); return(true); }
/// <summary> /// Updates the pregame counter /// </summary> void UpdatePregame() { if (Settings.MinimumPlayerCount > m_QueuedUsers.Count) { if (PregameTimer.Enabled) { //disable timer PregameTimer.Stop(); MatchListener.OnPregameTimerStateChanged(new MRKToSTimerEvent(PregameTimer, MRKTosTimerEventState.Stopped)); MRKToSLogger.LogInfo("Pregame timer state: start -> stop due to 0"); } } else if (m_QueuedUsers.Count >= Settings.MinimumPlayerCount) { if (!PregameTimer.Enabled) { //start timer PregameTimer.Max = Settings.MinimumStartTime * 1000; PregameTimer.Start(); MatchListener.OnPregameTimerStateChanged(new MRKToSTimerEvent(PregameTimer, MRKTosTimerEventState.Started)); MRKToSLogger.LogInfo("Pregame timer state: stop -> start due to 1"); } if (m_QueuedUsers.Count == Settings.MaximumPlayerCount) { if (PregameTimer.Max == Settings.MinimumStartTime * 1000) { PregameTimer.Max = Settings.MaximumStartTime * 1000; PregameTimer.Reset(); MatchListener.OnPregameTimerStateChanged(new MRKToSTimerEvent(PregameTimer, MRKTosTimerEventState.Changed)); MRKToSLogger.LogInfo("Pregame timer state: reset due to 2"); } } else { if (PregameTimer.Max == Settings.MaximumStartTime * 1000) { PregameTimer.Max = Settings.MinimumStartTime * 1000; PregameTimer.Reset(); MatchListener.OnPregameTimerStateChanged(new MRKToSTimerEvent(PregameTimer, MRKTosTimerEventState.Changed)); MRKToSLogger.LogInfo("Pregame timer state: reset due to 3"); } } } if (m_PregameTimerThread == null) { (m_PregameTimerThread = new Thread(PregameTimerThread)).Start(); } }
/// <summary> /// Remove a user from the queue /// </summary> /// <param name="user"></param> public bool DequeueUser(MRKToSUser user) { if (MatchState != State.Waiting) { MRKToSLogger.LogError($"Can not dequeue {user.Username} to the match, match has already started or is still idle"); return(false); } if (FindQueuedUser(user.Username) == null) { MRKToSLogger.LogWarning($"User {user.Username} is not queued"); return(false); } m_QueuedUsers.Remove(user); MRKToSLogger.LogInfo($"User {user.Username} has been removed from the queue"); LogQueueCount(); MatchListener.OnQueueUserRemoved(user); UpdatePregame(); return(true); }
/// <summary> /// Logs the queue count /// </summary> void LogQueueCount() { MRKToSLogger.LogInfo($"Queue[{m_QueuedUsers.Count}/{Settings.MaximumPlayerCount}]"); }
public void Start() { MatchState = State.Waiting; MRKToSLogger.LogInfo("MRKTownOfSalem started... v1\nBy MRKDaGods\n\n"); }