ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/Qzhteln/trunk/TELTest/MatchmakingStuff.cs
Revision: 2
Committed: Wed Feb 11 13:07:01 2026 UTC (8 weeks, 4 days ago) by figdor32
File size: 1955 byte(s)
Log Message:
Initial check-in

File Contents

# User Rev Content
1 figdor32 2 using System;
2     using System.Collections.Generic;
3     using System.Linq;
4     using System.Text;
5     using System.Threading.Tasks;
6     using TELTest.Matchmaking;
7    
8     namespace TELTest {
9     public static class MatchmakingStuff {
10     static MatchmakingStuff() {
11     tmr.Interval = 60 * 60_000; // Every hour
12     tmr.Elapsed += Tmr_Elapsed;
13     tmr.AutoReset = true;
14     Retime();
15    
16     }
17     static System.Timers.Timer tmr = new System.Timers.Timer();
18     private static void Tmr_Elapsed(Object sender, System.Timers.ElapsedEventArgs e) {
19     Program.WriteWithTime("Begin lobby cleanup...");
20     RunCleanup();
21     }
22     private static void Retime() {
23     tmr.Stop();
24     tmr.Start();
25     }
26     public static Lobby RequestNew(QuizContainer subject, QuizGamemode gamemode) {
27     Lobby m = new Lobby();
28     m.Subject = subject;
29     m.Gamemode = gamemode;
30     m.Identifier = Utilities.RandomString(5);
31     m.LastAccessed = DateTime.Now;
32     lock (AllLobbies)
33     AllLobbies.Add(m);
34     return m;
35     }
36     public static List<Lobby> GetPublic() {
37     lock(AllLobbies)
38     return AllLobbies.Where(x => x.AnnouncePublic).ToList();
39     }
40     public static void RunCleanup() {
41     List<Lobby> remove = new List<Lobby>();
42     lock (AllLobbies)
43     for (Int32 i = 0; i < AllLobbies.Count; i++) {
44     Lobby item = AllLobbies[i];
45     if (item.Players.Count == 0 || DateTime.Now - item.LastAccessed > new TimeSpan(2, 0, 0) && !item.AnnouncePublic) remove.Add(item);
46     }
47     lock(AllLobbies)
48     foreach (var item in remove) AllLobbies.Remove(item);
49     }
50    
51     public static List<Lobby> AllLobbies { get; } = new List<Lobby>();
52     }
53     }