コード例 #1
0
        public static bool CreateFromPaths(
            IEnumerable <string> paths,
            string destinationArchiveFileName,
            string relativeTo,
            string compressCommand        = null,
            string compressionProgramPath = null
            )
        {
            _pathToTar ??= GetPathToTar();

            new FileInfo(destinationArchiveFileName).EnsureDirectory();

            using var builder = ValueStringBuilder.Create();
            var i = 0;

            foreach (var path in paths)
            {
                builder.Append($"{(i++ > 0 ? " " : "")}\"{Path.GetRelativePath(relativeTo, path)}\"");
            }
            var pathsToCompress = builder.ToString();

            var tarFlags = compressCommand == null ? "-acf" : "-cf";
            var useExternalCompression = compressCommand != null ? $"--use-compress-program \"{compressCommand}\" " : "";
            var arguments = $"{useExternalCompression}{tarFlags} \"{destinationArchiveFileName}\" -C \"{relativeTo}\" {pathsToCompress}";

            return(RunTar(arguments, compressionProgramPath) == 0);
        }
コード例 #2
0
        private static void EventSink_ClientVersionReceived(NetState state, ClientVersion version)
        {
            using var message = ValueStringBuilder.Create();

            if (!_enable || state.Mobile?.AccessLevel != AccessLevel.Player)
            {
                return;
            }

            var strictRequirement = _invalidClientResponse == InvalidClientResponse.Kick ||
                                    _invalidClientResponse == InvalidClientResponse.LenientKick &&
                                    Core.Now - state.Mobile.Created > _ageLeniency &&
                                    state.Mobile is PlayerMobile mobile &&
                                    mobile.GameTime > _gameTimeLeniency;

            bool shouldKick = false;

            if (MinRequired != null && version < MinRequired)
            {
                message.Append($"This server doesn't support clients older than {MinRequired}.");
                shouldKick = strictRequirement;
            }
            else if (MaxRequired != null && version > MaxRequired)
            {
                message.Append($"This server doesn't support clients newer than {MaxRequired}.");
                shouldKick = strictRequirement;
            }
            else if (!AllowRegular || !AllowUOTD)
            {
                if (!AllowRegular && version.Type == ClientType.Regular)
                {
                    message.Append("This server does not allow regular clients to connect.");
                    shouldKick = true;
                }
                else if (!AllowUOTD && state.IsUOTDClient)
                {
                    message.Append("This server does not allow UO:TD clients to connect.");
                    shouldKick = true;
                }

                if (message.Length > 0)
                {
                    if (AllowRegular && AllowUOTD)
                    {
                        message.Append(" You can use regular or UO:TD clients.");
                    }
                    else if (AllowRegular)
                    {
                        message.Append(" You can use regular clients.");
                    }
                    else if (AllowUOTD)
                    {
                        message.Append(" You can use UO:TD clients.");
                    }
                }
            }

            if (message.Length > 0)
            {
                state.Mobile.SendMessage(0x22, message.ToString());
            }

            if (shouldKick)
            {
                state.Mobile.SendMessage(0x22, "You will be disconnected in {0} seconds.", KickDelay.TotalSeconds);
                Timer.StartTimer(KickDelay, () => OnKick(state));
                return;
            }

            if (message.Length > 0)
            {
                switch (_invalidClientResponse)
                {
                case InvalidClientResponse.Warn:
                {
                    state.Mobile.SendMessage(
                        0x22,
                        $"This server recommends that your client version is {GetVersionExpression()}."
                        );
                    break;
                }

                case InvalidClientResponse.LenientKick:
                case InvalidClientResponse.Annoy:
                {
                    SendAnnoyGump(state.Mobile);
                    break;
                }
                }
            }
        }