public void LoadEvents(ConfigReader reader) { StopEvent(); Events.Clear(); foreach (var eventNode in reader["events"]) { var e = new WorldEvent(); e.DropRate = eventNode["DROP_Rate"]?.GetDouble() ?? 1.0; e.ExpRate = eventNode["EXP_Rate"]?.GetDouble() ?? 1.0; e.MesoRate = eventNode["MESO_Rate"]?.GetDouble() ?? 1.0; e.StartTime = DateTime.Parse(eventNode["start"].Value).ToUniversalTime(); e.EndTime = DateTime.Parse(eventNode["end"].Value).ToUniversalTime(); e.Name = eventNode["name"].Value; e.ScrollingHeader = eventNode["header"]?.Value; // Ignore expired events if (e.EndTime < MasterThread.CurrentDate) { continue; } Program.MainForm.LogAppend("Loaded event {0}, running between {1} and {2} (UTC), rates {3}/{4}/{5}", e.Name, e.StartTime, e.EndTime, e.ExpRate, e.MesoRate, e.DropRate); Events.Add(e); } CheckForEvents(); }
void StopEvent() { if (RunningEvent == null) { return; } var eventHadHeader = RunningEvent.ScrollingHeader != ""; Program.MainForm.LogAppend("Stopping event..."); RunningEvent = null; GameServers.ForEach(x => { x.Value.ResetRates(); if (eventHadHeader) { var p = new Packet(ISServerMessages.WSE_ChangeScrollingHeader); p.WriteString(""); x.Value.ActiveServerConnection?.SendPacket(p); } }); }
public void CheckForEvents() { var currentDate = MasterThread.CurrentDate; if (RunningEvent != null) { // Not yet expired if (RunningEvent.EndTime >= currentDate) { return; } StopEvent(); } foreach (var @event in Events) { if (@event.StartTime <= currentDate && @event.EndTime >= currentDate) { Program.MainForm.LogAppend("Starting event '{0}'", @event.Name); GameServers.ForEach(x => { x.Value.SetRates(@event.ExpRate, @event.DropRate, @event.MesoRate, true); if (!string.IsNullOrEmpty(@event.ScrollingHeader)) { var p = new Packet(ISServerMessages.WSE_ChangeScrollingHeader); p.WriteString(@event.ScrollingHeader); x.Value.ActiveServerConnection?.SendPacket(p); } }); RunningEvent = @event; break; } } }