public static void CheckForUpdates(object state, ElapsedEventArgs elapsedEventArgs) { var mods = Mongo.Mods.FindAllAs <Mod>(); var updatedMods = new HashSet <Mod>(); log.Info("Checking for updates to mods..."); var logic = new CompareLogic() { Config = new ComparisonConfig() { Caching = false, MaxDifferences = 100 } }; var modIds = new HashSet <string>(); bool cosmeticsChanged = false; foreach (var mod in mods) { modIds.Add(mod.Id); if (!ModCache.ContainsKey(mod.Id)) { ModCache.Add(mod.Id, mod); updatedMods.Add(mod); log.InfoFormat("Mod [{0}] added to database.", mod.fullname); cosmeticsChanged = true; continue; } var omod = ModCache[mod.Id]; var diff = logic.Compare(omod, mod); if (diff.AreEqual) { continue; } log.InfoFormat("Mod [{0}] updated!", mod.fullname); foreach (var difference in diff.Differences) { log.Info(difference.PropertyName + ": " + difference.Object1Value + " => " + difference.Object2Value); } if (mod.version != omod.version || mod.isPublic != omod.isPublic || mod.playable != omod.playable) { updatedMods.Add(mod); } ModCache[mod.Id] = mod; cosmeticsChanged = true; } foreach (var mod in ModCache.Where(mod => !modIds.Contains(mod.Key)).ToArray()) { updatedMods.Add(mod.Value); ModCache.Remove(mod.Value.Id); cosmeticsChanged = true; log.InfoFormat("Mod [{0}] deleted!", mod.Value.fullname); } if (cosmeticsChanged) { Browser.AsyncSendToAll(BrowserController.UpdateMods(), res => {}); log.Info("Telling browsers to download new mod list!"); } if (updatedMods.Count == 0) { return; } log.InfoFormat("[{0}] mods updated, re-initing all clients and servers.", updatedMods.Count); ServerAddons.Init(ModCache.Values); foreach (var mod in updatedMods) { LobbyManager.CloseAll(mod); } Clients.SendToAll(ClientController.UpdateMods()); foreach (var server in Servers.Find(m => m.Inited)) { server.Inited = false; server.Send("updateMods|" + string.Join(",", updatedMods.Select(m => m.name))); } }
public static void Main(string[] args) { XmlConfigurator.Configure(); System.Net.ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; Console.Title = string.Format("[{0}] D2MP Master", version); log.Info("Master server starting v." + version + "."); log.Info("Initializing database..."); log.Debug(Settings.Default.MongoURL); Mongo.Setup(); Task.Factory.StartNew(Mongo.UpdateOldMatchResults); log.Info("Caching mods..."); Mods.Mods.InitCache(); log.Info(Mods.Mods.ModCache.Count + " mods cached."); log.Info("Generating server addon list..."); ServerAddons.Init(Mods.Mods.ModCache.Values); log.Info("Initializing Amazon S3..."); S3 = new S3Manager(); log.Info("Initializing match result server..."); Uri[] urilist = null; { IList <Uri> uris = new List <Uri>(); #if DEBUG || DEV uris.Add(new Uri("http://127.0.0.1:" + Settings.Default.WebserverBind)); //uris.Add(new Uri("http://10.0.1.3:" + Settings.Default.WebserverBind)); #else //uris.Add(new Uri("http://net1.d2modd.in:" + Settings.Default.WebserverBind)); uris.Add(new Uri("http://" + Settings.Default.WebAddress + ":" + Settings.Default.WebserverBind)); #endif urilist = uris.ToArray(); } foreach (var uri in urilist) { log.Debug(uri); } var config = new HostConfiguration(); using (var nancyServer = new NancyHost(config, urilist)) { nancyServer.Start(); log.Info("Initializing xsockets..."); Console.CancelKeyPress += delegate { shutdown = true; }; using (var server = Composable.GetExport <IXSocketServerContainer>()) { server.StartServers(); Mods.Mods.StartUpdateTimer(); Lobbies.LobbyManager.Start(); log.Info("Server running!"); while (!shutdown) { Thread.Sleep(100); } BrowserController.cts.Cancel(); ClientController.cts.Cancel(); ServerController.cts.Cancel(); Lobbies.LobbyManager.Stop(); Mods.Mods.StopUpdateTimer(); server.StopServers(); } nancyServer.Stop(); } log.Info("Done, shutting down..."); //wserver.Stop(); }