public IDisposable EnterPlanetExclusive(IPlanetExclusiveOperation operation) { Monitor.Enter(_lockPlanetExclusive); // if the same thread entered here, but invoked an exlusive planet operation for a different planet, it's an error! if (CurrentPlanetExclusiveOperation != null) { // the same planet id, it's all fine, we don't need a new lock because the existing one is still there if (CurrentPlanetExclusiveOperation.Operation.PlanetId == operation.PlanetId) { Monitor.Exit(_lockPlanetExclusive); return(null); } else { Logger.Instance.Log(LogLevel.Error, $"Current planet exclusive is not released!!! Current: {CurrentPlanetExclusiveOperation.Operation.Name}, new: {operation.Name}."); } } CurrentPlanetExclusiveOperation = new PlanetExclusiveOperation(this, operation); return(CurrentPlanetExclusiveOperation); }
public string Inject(OgamePageInfo info, string body, ResponseContainer response, string host, int port) { if (!response.RequestMessage.RequestUri.PathAndQuery.Contains("ogpe=1")) { return(body); } using (BotDb db = new BotDb()) { IPlanetExclusiveOperation op = _client.CurrentPlanetExclusiveOperation?.Operation; // Disposed since check was made if (op == null) { return(body); } Planet planet = db.Planets.Where(p => p.PlanetId == op.PlanetId).First(); // body += $"<script type='text/javascript'>errorBoxNotify('Ongoing activity','There is an ongoing bot activity on planet {planet.Name} {planet.Coords} - {op.Name}: {op.Progress}! Cannot change planets right now.','OK');</script>"; return(body); } }
public PlanetExclusiveOperation(OGameClient client, IPlanetExclusiveOperation operation) { _client = client; Operation = operation; Logger.Instance.Log(LogLevel.Debug, $"Creating PEO {Operation.Name} on planet {Operation.PlanetId}"); }