public void OnAreaInitialize(IAreaDefiniton area, IPlayer p) { try { logger.Info("AreaInitialize {0} {1}", area.Identifier, p.SteamID); AreaEventDelegate handler = AreaInitialize; if (handler != null) { handler(area, new AreaEventArgs(p, AreaEventType.Init)); } } catch (Exception ex) { logger.Error("OnAreaInitialize: {0}", ex.ToString()); } }
private void CleanupProtections(IServerConnection server) { foreach (var checkPlayer in server.AllPlayers.Players) { IAreaDefiniton[] oldList = checkPlayer.LandProtections.Items.ToArray(); foreach (var item in oldList) { IAreaDefiniton protection = (from p in found where p.Center == item.Center select p).FirstOrDefault(); if (protection == null) { logger.Info("KeyStone {0} ({1}) destroyed ({2})", item.Identifier, item.Center.ToString(), checkPlayer.Name); item.OnDestroy(); checkPlayer.LandProtections.Remove(item); //TODO: Does not remove item? } } } }
public override bool ProcessLine(IServerConnection serverConnection, string currentLine) { if (rgLLPStart.IsMatch(currentLine)) // Start of ListLandProtections deteced { PriorityProcess = true; if (IsFirst) { countStones = 0; found = new List <IAreaDefiniton>(); } Match match = rgLLPStart.Match(currentLine); GroupCollection groups = match.Groups; IPlayer p = serverConnection.AllPlayers.FindPlayerBySteamID(groups["steamid"].Value); currentPlayer = p; if (p != null) { logger.Debug("Parsing LandProtections of {0}", p.Name); } else { logger.Debug("Player {0} unknown! {1}", groups["name"].Value, currentLine); } IsFirst = false; return(true); } if (rgLLPLine.IsMatch(currentLine)) { Match match = rgLLPLine.Match(currentLine); GroupCollection groups = match.Groups; IPosition newLP = serverConnection.CreatePosition(groups["pos"].Value); if ((newLP != null) && (currentPlayer != null)) { IAreaDefiniton protection = (from p in currentPlayer.LandProtections.Items where p.Center.Equals(newLP) select p).FirstOrDefault(); if (protection == null) { protection = serverConnection.CreateArea(currentPlayer, newLP, 10.0); currentPlayer.LandProtections.Add(protection); } found.Add(protection); countStones++; } return(true); } if (rgLLPEnd.IsMatch(currentLine)) { Match match = rgLLPEnd.Match(currentLine); GroupCollection groups = match.Groups; PriorityProcess = false; IsFirst = true; int targetNum = Int32.Parse(groups["numstones"].Value); if (countStones != targetNum) { logger.Warn("Number mismatch in ListLandProtection! {0} != {1}", targetNum, countStones); } logger.Info("LandProtection Parsing done."); CleanupProtections(serverConnection); serverConnection.AllPlayers.Save(true); return(true); } return(false); }