Exemplo n.º 1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="timeoutMilliSeconds">Timeout milli seconds for send and receive. Timeout of connect is not effected.</param>
        /// <param name="keepAliveNoticeIntervalSeconds"></param>
        /// <param name="logger"></param>
        public MatchMakerClient(int timeoutMilliSeconds = 10000, int keepAliveNoticeIntervalSeconds = 30,
                                ILogger logger          = null)
        {
            if (logger == null)
            {
                logger = StreamLogger.CreateStandardOutputLogger();
            }

            TimeoutMilliSeconds = timeoutMilliSeconds;
            Logger                     = logger;
            PortMappingCreator         = new NatPortMappingCreator(logger);
            keepAliveSenderNotificator = new KeepAliveSenderNotificator(this, keepAliveNoticeIntervalSeconds);
        }
Exemplo n.º 2
0
        private static void Main(string[] args)
        {
            var versionInfo =
                FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);

            Console.WriteLine($"{versionInfo.ProductName} v{versionInfo.ProductVersion}");

            var parsedResult = CommandLine.Parser.Default.ParseArguments <Options>(args);

            if (parsedResult.Tag != CommandLine.ParserResultType.Parsed)
            {
                var helpText = HelpText.AutoBuild(parsedResult);
                Console.WriteLine("Failed to parse options.");
                Console.WriteLine(helpText);
                return;
            }

            var options          = ((CommandLine.Parsed <Options>)parsedResult).Value;
            var commandProcessor = CommandProcessorFactory.Create();

            try
            {
                var logger = StreamLogger.CreateStandardOutputLogger(LogLevel.Debug);
                using var client        = new MatchMakerClient(logger: logger);
                Console.CancelKeyPress += OnKeyBoardInterrupted;

                if (!string.IsNullOrEmpty(options.CommandAndOptions))
                {
                    var items = options.CommandAndOptions.Split(' ');
                    if (!CommandProcessor.TryParseCommand(items[0], out var command))
                    {
                        Console.WriteLine("Command is invalid.");
                    }
                    else
                    {
                        var commandOptions = items.Skip(1);
                        ExecuteCommand(commandProcessor, command, client, commandOptions);
                    }
                }
                else
                {
                    while (!isFinishProgram)
                    {
                        Console.WriteLine("Input command.");
                        commandProcessor.DisplayCommandList();
                        var input = Console.ReadLine();
                        if (input == null)
                        {
                            Console.WriteLine("Command is invalid.");
                            continue;
                        }

                        var items = input.Split(' ');
                        if (!CommandProcessor.TryParseCommand(items[0], out var command))
                        {
                            Console.WriteLine("Command is invalid.");
                            continue;
                        }

                        var commandOptions = items.Skip(1);
                        ExecuteCommand(commandProcessor, command, client, commandOptions);
                    }
                }
            }
            finally
            {
                NatPortMappingCreator.ReleaseCreatedPortMappings();
            }
        }