protected override void Bootstrap() { var shards = Kernel.Get <IShardsDomain>(); var shard = shards.GetById(Config.ID); if (shard == null) { throw new Exception("Unable to find a shard with id " + Config.ID + ", check it exists in the database"); } LOG.Info("City identified as " + shard.Name); var context = new CityServerContext(); context.ShardId = shard.Id; context.Config = Config; Kernel.Bind <EventSystem>().ToSelf().InSingletonScope(); Kernel.Bind <CityLivenessEngine>().ToSelf().InSingletonScope(); Kernel.Bind <CityServerContext>().ToConstant(context); Kernel.Bind <int>().ToConstant(shard.Id).Named("ShardId"); Kernel.Bind <CityServerConfiguration>().ToConstant(Config); Kernel.Bind <JobMatchmaker>().ToSelf().InSingletonScope(); Kernel.Bind <LotServerPicker>().To <LotServerPicker>().InSingletonScope(); Kernel.Bind <LotAllocations>().To <LotAllocations>().InSingletonScope(); Kernel.Bind <Neighborhoods>().ToSelf().InSingletonScope(); Kernel.Bind <Tuning>().ToSelf().InSingletonScope(); Liveness = Kernel.Get <CityLivenessEngine>(); IDAFactory da = Kernel.Get <IDAFactory>(); using (var db = da.Get()){ var version = ServerVersion.Get(); db.Shards.UpdateVersion(shard.Id, version.Name, version.Number, version.UpdateID); ((Shards)shards).Update(); var oldClaims = db.LotClaims.GetAllByOwner(context.Config.Call_Sign).ToList(); if (oldClaims.Count > 0) { LOG.Warn("Detected " + oldClaims.Count + " previously allocated lot claims, perhaps the server did not shut down cleanly. Lot consistency may be affected."); db.LotClaims.RemoveAllByOwner(context.Config.Call_Sign); } var oldAvatarClaims = db.AvatarClaims.GetAllByOwner(context.Config.Call_Sign).ToList(); if (oldAvatarClaims.Count > 0) { LOG.Warn("Detected " + oldAvatarClaims.Count + " avatar claims, perhaps the server did not shut down cleanly. Avatar consistency may be affected."); db.AvatarClaims.DeleteAll(context.Config.Call_Sign); } } base.Bootstrap(); Kernel.Get <EventSystem>().Init(); }
public static bool QueueUpdateIfRequired(IKernel kernel, string branch) { var version = ServerVersion.Get(); var factory = kernel.Get <IDAFactory>(); using (var da = factory.Get()) { //first - did we install an update last time? if (File.Exists("scheduledUpdate/complete.txt")) { try { var completeInfo = File.ReadAllText("scheduledUpdate/complete.txt"); //var branchItem = da.Updates.GetBranch(branch); //da.Updates.UpdateBranchLatestDeployed(branchItem.branch_id, int.Parse(completeInfo)); try { Directory.Delete("scheduledUpdate/", true); } catch (Exception) { } } catch { //invalid complete.txt? } } var updates = da.Updates.GetPublishableByBranchName(branch).ToList(); if (updates.Count != 0) { //prepare update for watchdog to apply var ordered = updates.OrderBy(x => x.publish_date); //already ordered by add date, so same publish date will publish in order added to db. foreach (var update in ordered) { da.Updates.MarkUpdatePublished(update.update_id); } var last = ordered.Last(); da.Updates.UpdateBranchLatestDeployed(last.branch_id, last.update_id); } //does the latest update for our branch match our current update id? var latest = da.Updates.GetBranch(branch)?.current_dist_id; if (latest != version.UpdateID) { var published = da.Updates.GetRecentUpdatesForBranchByName(branch, 100); var path = FindPath(published.ToList(), version.UpdateID, latest); if (path == null) { //oops return(false); } string updateFile = "UPDATE\n"; foreach (var update in path) { updateFile += update.server_zip + "\n"; } updateFile += latest; Directory.CreateDirectory("scheduledUpdate/"); File.WriteAllText("scheduledUpdate/update.txt", updateFile); return(true); } } return(false); }