Ejemplo n.º 1
0
        public override void Process()
        {
            //Visits a region of the map and runs the specified sub command if any.
            //default (no extra params) mode - takes vector2i of region co-ords. Runs a map visitor on that region to expose map and generate chunks

            if (Options.ContainsKey("stop"))
            {
                if (_mapVisitor == null)
                {
                    SendOutput("VisitRegion not running.");

                    return;
                }

                _mapVisitor.Stop();
                _mapVisitor = null;
                SendOutput("VisitRegion stopped.");

                return;
            }

            if (_mapVisitor != null && _mapVisitor.IsRunning())
            {
                SendOutput("VisitRegion already running. You can stop it with \"bc-visitregion /stop\".");
            }
            else if (!int.TryParse(Params[0], out var x))
            {
                SendOutput("The given x1 coordinate is not a valid integer");
            }
            else if (!int.TryParse(Params[1], out var z))
            {
                SendOutput("The given z1 coordinate is not a valid integer");
            }
            else
            {
                if (x > 19 || x < -20)
                {
                    SendOutput("Note: The given x1 coordinate is beyond the recommended range (-20 to 19)");
                }
                if (z > 19 || z < -20)
                {
                    SendOutput("Note: The given z1 coordinate is beyond the recommended range (-20 to 19)");
                }

                SendOutput("Sending a visitor to region " + x + " " + z);

                _lastSender = SenderInfo.RemoteClientInfo;

                _mapVisitor = new MapVisitor(new Vector3i(x * 512, 0, z * 512), new Vector3i(x * 512 + 511, 0, z * 512 + 511));
                _mapVisitor.OnVisitChunk   += ReportStatus;
                _mapVisitor.OnVisitChunk   += GetMapColors;
                _mapVisitor.OnVisitMapDone += ReportCompletion;
                _mapVisitor.Start();

                _hash = _mapVisitor.GetHashCode();
                BCTask.AddTask("MapVisitor", _mapVisitor.GetHashCode(), null);
            }
        }
        public long Property <TProperty>(Expression <Func <TEntity, TProperty> > predicate, string columnName)
        {
            var visitor = new MapVisitor(_map);

            visitor.Visit(predicate);
            var key = visitor.ExposeMap().FullColumnKey;

            return(GetTs($"{key}{columnName}"));
        }
Ejemplo n.º 3
0
        public IDeleteCommand <TEntity> ExplicitColumn(Expression <Func <TEntity, object> > predicate)
        {
            var visitor = new MapVisitor(_map);

            visitor.Visit(predicate);
            //var maps = visitor.ExposeMap().Select(x => x.FullColumnKey);
            _descriptors.Add(visitor.ExposeMap().FullColumnKey);
            return(this);
        }
Ejemplo n.º 4
0
        private void ReportCompletion(int total, float elapsedTime)
        {
            Log.Out($"VisitRegion done, visited {total} chunks in {elapsedTime:0.00} seconds (average {total / elapsedTime:0.00} chunks/sec).");

            if (_lastSender != null)
            {
                _lastSender.SendPackage(new NetPackageGameMessage(EnumGameMessages.Chat, "(PM) Visit Region Completed", "Server", false, "", false));
                _lastSender = null;
            }
            _mapVisitor = null;
        }
Ejemplo n.º 5
0
        public IScanCommand <TEntity> FetchColumns <T>(params Expression <Func <TEntity, T> >[] predicates)
        {
            foreach (var predicate in predicates)
            {
                var visitor = new MapVisitor(_map);
                visitor.Visit(predicate);

                _columns.Add(visitor.ExposeMap().FullColumnKey);
            }

            return(this);
        }
Ejemplo n.º 6
0
        public IGetCommand <TEntity> Column(Expression <Func <TEntity, object> > predicate)
        {
            var visitor = new MapVisitor(_map);

            visitor.Visit(predicate);

            //var maps = visitor.ExposeMap();
            //foreach (var map in maps) _columns.Add(map.FullColumnKey);
            _columns.Add(visitor.ExposeMap().FullColumnKey);

            return(this);
        }
Ejemplo n.º 7
0
        public IScanCommand <TEntity> FetchColumns <T>(Expression <Func <TEntity, IEnumerable <T> > > predicate,
                                                       params string[] columns)
        {
            var visitor = new MapVisitor(_map);

            visitor.Visit(predicate);

            var map = visitor.ExposeMap();

            _columns.AddRange(columns.Select(x => $"{map.ColumnFamily}:{x}"));

            return(this);
        }
        public QualifierFilter <TEntity> Column(Expression <Func <TEntity, object> > predicate)
        {
            var visitor = new MapVisitor(_map);

            visitor.Visit(predicate);

            var map = visitor.ExposeMap();

            //if (maps.Count > 1)
            //    throw new FilterException($"[ColumnPrefixFilter] Expected 1 column from predicate, got {maps.Count}");

            //var map = maps.FirstOrDefault();

            _columnName = map?.ColumnName;
            return(this);
        }
Ejemplo n.º 9
0
        public void ColumnName(Expression <Func <TEntity, object> > predicate)
        {
            //todo: rework this as the visitor will always expose 1 map associated to the property
            var visitor = new MapVisitor(_map);

            visitor.Visit(predicate);

            var map = visitor.ExposeMap();

            //if (maps.Count > 1)
            //    throw new FilterException($"[ColumnPrefixFilter] Expected 1 column from predicate, got {maps.Count}");

            //var map = maps.FirstOrDefault();

            _columnName = map?.ColumnName;
        }
Ejemplo n.º 10
0
        private void ReportCompletion(int total, float elapsedTime)
        {
            if (bcmTask != null)
            {
                bcmTask.Status = BCMTaskStatus.Complete;
                bcmTask.Output = $"VisitRegion done, visited {total} chunks in {elapsedTime:0.00} seconds (average {total / elapsedTime:0.00} chunks/sec).";
                BCTask.DelTask("MapVisitor", _hash);
            }

            Log.Out($"VisitRegion done, visited {total} chunks in {elapsedTime:0.00} seconds (average {total / elapsedTime:0.00} chunks/sec).");

            if (_lastSender != null)
            {
                _lastSender.SendPackage(new NetPackageGameMessage(EnumGameMessages.Chat, "(PM) Visit Region Completed", "Server", false, "", false));
                _lastSender = null;
            }
            _mapVisitor = null;
        }
        public SingleColumnValueFilter <TEntity> Column <TSub>(Expression <Func <TEntity, TSub> > predicate)
        {
            var visitor = new MapVisitor(_map);

            visitor.Visit(predicate);

            var map = visitor.ExposeMap();

            //if (maps.Count > 1)
            //    throw new FilterException($"[ColumnPrefixFilter] Expected 1 column from predicate, got {maps.Count}");

            //var map = maps.FirstOrDefault();

            _columnName   = map?.ColumnName;
            _columnFamily = map?.ColumnFamily;

            return(this);
        }
Ejemplo n.º 12
0
        protected override void Process()
        {
            if (!BCUtils.CheckWorld())
            {
                return;
            }

            if (Options.ContainsKey("stop"))
            {
                if (_mapVisitor == null)
                {
                    SendOutput("VisitRegion not running.");

                    return;
                }

                if (bcmTask != null)
                {
                    bcmTask.Output  = new { Message = "Visitor was stopped before it completed" };
                    bcmTask.Command = new BCCmd {
                        Command = commandStr
                    };
                    bcmTask.Status     = BCMTaskStatus.Aborted;
                    bcmTask.Completion = DateTime.UtcNow;
                    bcmTask.Duration   = bcmTask.Completion - bcmTask.Timestamp;
                }

                _mapVisitor.Stop();
                _mapVisitor = null;
                SendOutput("VisitRegion stopped.");

                return;
            }

            if (_mapVisitor != null && _mapVisitor.IsRunning())
            {
                SendOutput($"VisitRegion already running ({completePercent}%). You can stop it with \"bc-visitregion /stop\".");

                return;
            }

            if (Params.Count < 2)
            {
                SendOutput("VisitRegion isn't running. Provide some co-ords to explore some regions");

                return;
            }

            if (!int.TryParse(Params[0], out var x))
            {
                SendOutput("The given x1 coordinate is not a valid integer");

                return;
            }
            if (!int.TryParse(Params[1], out var z))
            {
                SendOutput("The given z1 coordinate is not a valid integer");

                return;
            }

            if (x > 19 || x < -20)
            {
                SendOutput("Note: The given x1 coordinate is beyond the recommended range (-20 to 19)");
            }

            if (z > 19 || z < -20)
            {
                SendOutput("Note: The given z1 coordinate is beyond the recommended range (-20 to 19)");
            }

            completePercent = 0;
            var x2 = x;
            var z2 = z;

            switch (Params.Count)
            {
            case 2:
                SendOutput($"Sending a visitor to region {x},{z}");
                break;

            case 3:
                if (!int.TryParse(Params[2], out var r))
                {
                    SendOutput("The given radius is not a valid integer");
                }

                if (r < 0)
                {
                    SendOutput("The given radius can't be less than 0, the recommended range is 0 to 20");

                    return;
                }

                if (r > 20)
                {
                    SendOutput("Note: The given radius is beyond the recommended range (0 to 20)");
                }

                x  -= r;
                z  -= r;
                x2 += r;
                z2 += r;
                SendOutput($"Sending a visitor to regions between {x},{z} and {x2},{z2}");
                break;

            case 4:
                if (!int.TryParse(Params[2], out x2))
                {
                    SendOutput("The given x2 coordinate is not a valid integer");
                }
                else if (!int.TryParse(Params[3], out z2))
                {
                    SendOutput("The given z2 coordinate is not a valid integer");
                }

                if (x2 > 19 || x2 < -20)
                {
                    SendOutput("Note: The given x2 coordinate is beyond the recommended range (-20 to 19)");
                }

                if (z2 > 19 || z2 < -20)
                {
                    SendOutput("Note: The given z2 coordinate is beyond the recommended range (-20 to 19)");
                }

                SendOutput($"Sending a visitor to regions between {x},{z} and {x2},{z2}");
                break;

            default:
                SendOutput("Invalid param count");
                SendOutput(GetHelp());
                break;
            }

            _lastSender = SenderInfo.RemoteClientInfo;

            commandStr = "";
            if (Params.Count > 0 || Options.Count > 0)
            {
                commandStr += string.Join(" ", new[] { GetCommands()[0] }.Concat(
                                              Options.Count > 0
            ? Params.Concat(Options.Select(o => "/" + o.Key + (o.Value != null ? "=" + o.Value : "")))
            : Params
                                              ).ToArray());
            }

            _mapVisitor = new MapVisitor(new Vector3i(x * 512, 0, z * 512), new Vector3i(x2 * 512 + 511, 0, z2 * 512 + 511));

            _hash = _mapVisitor.GetHashCode();
            BCTask.AddTask("MapVisitor", _mapVisitor.GetHashCode(), null);
            bcmTask = BCTask.GetTask("MapVisitor", _hash);
            if (bcmTask != null)
            {
                bcmTask.Command = new BCCmd {
                    Command = commandStr
                };
                bcmTask.Output = new { Count = 0, Total = 0, Perc = 0.00, Time = 0.00 };
            }

            _mapVisitor.OnVisitChunk   += ReportStatus;
            _mapVisitor.OnVisitChunk   += GetMapColors;
            _mapVisitor.OnVisitMapDone += ReportCompletion;
            _mapVisitor.Start();
        }
Ejemplo n.º 13
0
        public override void Process()
        {
            if (Options.ContainsKey("stop"))
            {
                if (_mapVisitor == null)
                {
                    SendOutput("VisitRegion not running.");

                    return;
                }

                _mapVisitor.Stop();
                _mapVisitor = null;
                SendOutput("VisitRegion stopped.");

                return;
            }

            if (_mapVisitor != null && _mapVisitor.IsRunning())
            {
                SendOutput($"VisitRegion already running ({completePercent}%). You can stop it with \"bc-visitregion /stop\".");

                return;
            }

            if (!int.TryParse(Params[0], out var x))
            {
                SendOutput("The given x1 coordinate is not a valid integer");

                return;
            }
            if (!int.TryParse(Params[1], out var z))
            {
                SendOutput("The given z1 coordinate is not a valid integer");

                return;
            }

            if (x > 19 || x < -20)
            {
                SendOutput("Note: The given x1 coordinate is beyond the recommended range (-20 to 19)");
            }

            if (z > 19 || z < -20)
            {
                SendOutput("Note: The given z1 coordinate is beyond the recommended range (-20 to 19)");
            }

            completePercent = 0;
            var x2 = x;
            var z2 = z;

            switch (Params.Count)
            {
            case 2:
                SendOutput($"Sending a visitor to region {x},{z}");
                break;

            case 3:
                if (!int.TryParse(Params[2], out var r))
                {
                    SendOutput("The given radius is not a valid integer");
                }

                if (r < 0)
                {
                    SendOutput("The given radius can't be less than 0, the recommended range is 0 to 20");

                    return;
                }

                if (r > 20)
                {
                    SendOutput("Note: The given radius is beyond the recommended range (0 to 20)");
                }

                x  -= r;
                z  -= r;
                x2 += r;
                z2 += r;
                SendOutput($"Sending a visitor to regions between {x},{z} and {x2},{z2}");
                break;

            case 4:
                if (!int.TryParse(Params[2], out x2))
                {
                    SendOutput("The given x2 coordinate is not a valid integer");
                }
                else if (!int.TryParse(Params[3], out z2))
                {
                    SendOutput("The given z2 coordinate is not a valid integer");
                }

                if (x2 > 19 || x2 < -20)
                {
                    SendOutput("Note: The given x2 coordinate is beyond the recommended range (-20 to 19)");
                }

                if (z2 > 19 || z2 < -20)
                {
                    SendOutput("Note: The given z2 coordinate is beyond the recommended range (-20 to 19)");
                }

                SendOutput($"Sending a visitor to regions between {x},{z} and {x2},{z2}");
                break;

            default:
                SendOutput("Invalid param count");
                SendOutput(GetHelp());
                break;
            }

            _lastSender = SenderInfo.RemoteClientInfo;

            _mapVisitor = new MapVisitor(new Vector3i(x * 512, 0, z * 512), new Vector3i(x2 * 512 + 511, 0, z2 * 512 + 511));
            _mapVisitor.OnVisitChunk   += ReportStatus;
            _mapVisitor.OnVisitChunk   += GetMapColors;
            _mapVisitor.OnVisitMapDone += ReportCompletion;
            _mapVisitor.Start();

            _hash = _mapVisitor.GetHashCode();
            BCTask.AddTask("MapVisitor", _mapVisitor.GetHashCode(), null);
        }