Exemple #1
0
        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);
        }