Exemplo n.º 1
0
        private async Task ConnectToSlack()
        {
            await Client.ConnectAsync();

            _logger.Verbose($"Team Name: {Client.MyTeam.name}");
            _logger.Verbose($"Bots Name: {Client.MySelf.name}");

            await ConnectSocket();
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        public void Trace <T1>(string template, T1 parameter1)
        {
            if (!IsEnabled(LogLevel.Trace))
            {
                return;
            }

            _target.Verbose(template, parameter1);
        }
Exemplo n.º 3
0
        //
        // HELPERS

        private void LogClaims(ClaimsPrincipal user)
        {
            _logger.Verbose("***************************");
            _logger.Verbose(string.Format("{0} claims recieved for user {1}", User.Claims.Count <Claim>().ToString(), User.Identity.Name));

            foreach (Claim claim in User.Claims)
            {
                _logger.Verbose(string.Format("    - {0}: {1}", claim.Type, claim.Value));
            }

            _logger.Verbose("***************************");
        }
Exemplo n.º 4
0
 public void Trace(string template, params object[] values)
 {
     if (_inner.IsEnabled(LogEventLevel.Verbose))
     {
         _inner.Verbose(template, values);
     }
 }
Exemplo n.º 5
0
        /// <inheritdoc />
        public Task LogMessage(LogMessage message)
        {
            switch (message.Severity)
            {
            case LogSeverity.Error:
            case LogSeverity.Critical:
                _logger.Fatal($"{message.Source}: {message.Message} {message.Exception}");
                break;

            case LogSeverity.Warning:
                _logger.Warning($"{message.Source}: {message.Message} {message.Exception}");
                break;

            case LogSeverity.Info:
                _logger.Information($"{message.Source}: {message.Message} {message.Exception}");
                break;

            case LogSeverity.Verbose:
                _logger.Verbose($"{message.Source}: {message.Message} {message.Exception}");
                break;

            case LogSeverity.Debug:
                _logger.Debug($"{message.Source}: {message.Message} {message.Exception}");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(Task.CompletedTask);
        }
        private void OnMessageReceived(MessageReader message)
        {
            var flag = message.Tag;

            Logger.Verbose("Server got {0}.", flag);

            switch (flag)
            {
            case MessageFlags.HostGame:
            {
                using (var packet = MessageWriter.Get(SendOption.Reliable))
                {
                    Message13Redirect.Serialize(packet, false, _nodeProvider.Get());
                    _connection.Send(packet);
                }
                break;
            }

            case MessageFlags.JoinGame:
            {
                Message01JoinGame.Deserialize(message,
                                              out var gameCode,
                                              out var unknown);

                using (var packet = MessageWriter.Get(SendOption.Reliable))
                {
                    var endpoint = _nodeLocator.Find(GameCode.IntToGameName(gameCode));
                    if (endpoint == null)
                    {
                        Message01JoinGame.SerializeError(packet, false, DisconnectReason.GameMissing);
                    }
                    else
                    {
                        Message13Redirect.Serialize(packet, false, endpoint);
                    }

                    _connection.Send(packet);
                }
                break;
            }

            case MessageFlags.GetGameListV2:
            {
                // TODO: Implement.
                using (var packet = MessageWriter.Get(SendOption.Reliable))
                {
                    Message01JoinGame.SerializeError(packet, false, DisconnectReason.Custom, DisconnectMessages.NotImplemented);
                    _connection.Send(packet);
                }
                break;
            }

            default:
            {
                Logger.Warning("Received unsupported message flag on the redirector ({0}).", flag);
                break;
            }
            }
        }
Exemplo n.º 7
0
        public override async ValueTask HandleMessageAsync(IMessageReader reader, MessageType messageType)
        {
            var flag = reader.Tag;

            Logger.Verbose("Server got {0}.", flag);

            switch (flag)
            {
            case MessageFlags.HostGame:
            {
                using var packet = MessageWriter.Get(MessageType.Reliable);
                Message13RedirectS2C.Serialize(packet, false, _nodeProvider.Get());
                await Connection.SendAsync(packet);

                break;
            }

            case MessageFlags.JoinGame:
            {
                Message01JoinGameC2S.Deserialize(
                    reader,
                    out var gameCode,
                    out _);

                using var packet = MessageWriter.Get(MessageType.Reliable);
                var endpoint = await _nodeLocator.FindAsync(GameCodeParser.IntToGameName(gameCode));

                if (endpoint == null)
                {
                    Message01JoinGameS2C.SerializeError(packet, false, DisconnectReason.GameMissing);
                }
                else
                {
                    Message13RedirectS2C.Serialize(packet, false, endpoint);
                }

                await Connection.SendAsync(packet);

                break;
            }

            case MessageFlags.GetGameListV2:
            {
                // TODO: Implement.
                using var packet = MessageWriter.Get(MessageType.Reliable);
                Message01JoinGameS2C.SerializeError(packet, false, DisconnectReason.Custom, DisconnectMessages.NotImplemented);
                await Connection.SendAsync(packet);

                break;
            }

            default:
            {
                Logger.Warning("Received unsupported message flag on the redirector ({0}).", flag);
                break;
            }
            }
        }
Exemplo n.º 8
0
        public void Log(string category,
                        LogLevel level,
                        string msg,
                        params object[] parameters)
        {
            var template = msg;

            if (!string.IsNullOrEmpty(category))
            {
                template = string.Format("[{0}]: {1}", category, msg);
            }

            msg = string.Format(template, parameters);

            switch (level)
            {
            case LogLevel.Trace:
                _logger.Verbose(msg);
                break;

            case LogLevel.Debug:
                _logger.Debug(msg);
                break;

            case LogLevel.Info:
                _logger.Information(msg);
                break;

            case LogLevel.Warning:
                _logger.Warning(msg);
                break;

            case LogLevel.Error:
                _logger.Error(msg);
                break;

            case LogLevel.Critical:
                _logger.Fatal(msg);
                break;
            }
        }
Exemplo n.º 9
0
 internal virtual void WakeReminderService(object state)
 {
     ReminderServiceLog.Verbose($"{DateTime.Now.ToString(LogDateFormat)} : Waking Reminder Service");
     FireRemindersByAssignmentType();
     ReminderServiceLog.Verbose($"{DateTime.Now.ToString(LogDateFormat)} : Reminder Service Sleeping");
 }
Exemplo n.º 10
0
 public void Trace(string message) => _logger.Verbose($"[{_loggerName}] {message}");
Exemplo n.º 11
0
 /// <summary>
 /// Log a verbose message, by default these aren't output.
 /// </summary>
 public void LogVerbose(string message, params object[] args)
 {
     serilog.Verbose(message, args);
 }
Exemplo n.º 12
0
 public void Verbose <T>(string stringTemplate, T payload = default)
 {
     _logger.Verbose <T>(stringTemplate, payload);
 }
Exemplo n.º 13
0
        private void OnMessageReceived(MessageReader message, SendOption sendOption)
        {
            var flag = (RequestFlag)message.Tag;

            Logger.Verbose("[{0}] Server got {1}.", Id, flag);

            switch (flag)
            {
            case RequestFlag.HostGame:
            {
                // Read game settings.
                var gameInfoBytes = message.ReadBytesAndSize();
                var gameInfo      = GameOptionsData.Deserialize(gameInfoBytes);

                // Create game.
                var game = _gameManager.Create(this, gameInfo);
                if (game == null)
                {
                    Connection.Send(new Message1DisconnectReason(DisconnectReason.ServerFull));
                    return;
                }

                // Code in the packet below will be used in JoinGame.
                using (var writer = MessageWriter.Get(SendOption.Reliable))
                {
                    writer.StartMessage(0);
                    writer.Write(game.Code);
                    writer.EndMessage();

                    Connection.Send(writer);
                }
                break;
            }

            case RequestFlag.JoinGame:
            {
                var gameCode = message.ReadInt32();
                var unknown  = message.ReadByte();
                var game     = _gameManager.Find(gameCode);
                if (game == null)
                {
                    Connection.Send(new Message1DisconnectReason(DisconnectReason.GameMissing));
                    return;
                }

                game.HandleJoinGame(Player);
                break;
            }

            case RequestFlag.StartGame:
            {
                if (!IsPacketAllowed(message, true))
                {
                    return;
                }

                Player.Game.HandleStartGame(message);
                break;
            }

            // No idea how this flag is triggered.
            case RequestFlag.RemoveGame:
                break;

            case RequestFlag.RemovePlayer:
            {
                if (!IsPacketAllowed(message, true))
                {
                    return;
                }

                var playerId = message.ReadPackedInt32();
                var reason   = message.ReadByte();

                Player.Game.HandleRemovePlayer(playerId, (DisconnectReason)reason);
                break;
            }

            case RequestFlag.GameData:
            case RequestFlag.GameDataTo:
            {
                if (!IsPacketAllowed(message, false))
                {
                    return;
                }

                // Broadcast packet to all other players.
                using (var writer = MessageWriter.Get(sendOption))
                {
                    if (flag == RequestFlag.GameDataTo)
                    {
                        var target = message.ReadPackedInt32();
                        writer.CopyFrom(message);
                        Player.Game.SendTo(writer, target);
                    }
                    else
                    {
                        writer.CopyFrom(message);
                        Player.Game.SendToAllExcept(writer, Player);
                    }
                }
                break;
            }

            case RequestFlag.EndGame:
            {
                if (!IsPacketAllowed(message, true))
                {
                    return;
                }

                Player.Game.HandleEndGame(message);
                break;
            }

            case RequestFlag.AlterGame:
            {
                if (!IsPacketAllowed(message, true))
                {
                    return;
                }

                if (message.ReadByte() != (byte)AlterGameTags.ChangePrivacy)
                {
                    return;
                }

                var isPublic = message.ReadByte() == 1;

                Player.Game.HandleAlterGame(message, Player, isPublic);
                break;
            }

            case RequestFlag.KickPlayer:
            {
                if (!IsPacketAllowed(message, true))
                {
                    return;
                }

                var playerId = message.ReadPackedInt32();
                var isBan    = message.ReadBoolean();

                Player.Game.HandleKickPlayer(playerId, isBan);
                break;
            }

            default:
                Logger.Warning("Server received unknown flag {0}.", flag);
                break;
            }

            if (flag != RequestFlag.GameData &&
                flag != RequestFlag.GameDataTo &&
                flag != RequestFlag.EndGame &&
                message.Position < message.Length)
            {
                Logger.Warning("Server did not consume all bytes from {0} ({1} < {2}).",
                               flag,
                               message.Position,
                               message.Length);
            }
        }
Exemplo n.º 14
0
        private void OnMessageReceived(MessageReader message, SendOption sendOption)
        {
            var flag = message.Tag;

            Logger.Verbose("[{0}] Server got {1}.", Id, flag);

            switch (flag)
            {
            case MessageFlags.HostGame:
            {
                // Read game settings.
                var gameInfo = Message00HostGame.Deserialize(message);

                // Create game.
                var game = _gameManager.Create(gameInfo);
                if (game == null)
                {
                    Player.SendDisconnectReason(DisconnectReason.ServerFull);
                    return;
                }

                // Code in the packet below will be used in JoinGame.
                using (var writer = MessageWriter.Get(SendOption.Reliable))
                {
                    Message00HostGame.Serialize(writer, game.Code);

                    Connection.Send(writer);
                }
                break;
            }

            case MessageFlags.JoinGame:
            {
                Message01JoinGame.Deserialize(message,
                                              out var gameCode,
                                              out var unknown);

                var game = _gameManager.Find(gameCode);
                if (game == null)
                {
                    Player.SendDisconnectReason(DisconnectReason.GameMissing);
                    return;
                }

                game.HandleJoinGame(Player);
                break;
            }

            case MessageFlags.StartGame:
            {
                if (!IsPacketAllowed(message, true))
                {
                    return;
                }

                Player.Game.HandleStartGame(message);
                break;
            }

            // No idea how this flag is triggered.
            case MessageFlags.RemoveGame:
                break;

            case MessageFlags.RemovePlayer:
            {
                if (!IsPacketAllowed(message, true))
                {
                    return;
                }

                Message04RemovePlayer.Deserialize(message,
                                                  out var playerId,
                                                  out var reason);

                Player.Game.HandleRemovePlayer(playerId, (DisconnectReason)reason);
                break;
            }

            case MessageFlags.GameData:
            case MessageFlags.GameDataTo:
            {
                if (!IsPacketAllowed(message, false))
                {
                    return;
                }

                // Broadcast packet to all other players.
                using (var writer = MessageWriter.Get(sendOption))
                {
                    if (flag == MessageFlags.GameDataTo)
                    {
                        var target = message.ReadPackedInt32();
                        writer.CopyFrom(message);
                        Player.Game.SendTo(writer, target);
                    }
                    else
                    {
                        writer.CopyFrom(message);
                        Player.Game.SendToAllExcept(writer, Player.Client.Id);
                    }
                }
                break;
            }

            case MessageFlags.EndGame:
            {
                if (!IsPacketAllowed(message, true))
                {
                    return;
                }

                Player.Game.HandleEndGame(message);
                break;
            }

            case MessageFlags.AlterGame:
            {
                if (!IsPacketAllowed(message, true))
                {
                    return;
                }

                Message10AlterGame.Deserialize(message,
                                               out var gameTag,
                                               out var value);

                if (gameTag != AlterGameTags.ChangePrivacy)
                {
                    return;
                }

                Player.Game.HandleAlterGame(message, Player, value);
                break;
            }

            case MessageFlags.KickPlayer:
            {
                if (!IsPacketAllowed(message, true))
                {
                    return;
                }

                Message11KickPlayer.Deserialize(message,
                                                out var playerId,
                                                out var isBan);

                Player.Game.HandleKickPlayer(playerId, isBan);
                break;
            }

            case MessageFlags.GetGameListV2:
            {
                Message16GetGameListV2.Deserialize(message, out var options);
                Player.OnRequestGameList(options);
                break;
            }

            default:
                Logger.Warning("Server received unknown flag {0}.", flag);
                break;
            }

#if DEBUG
            if (flag != MessageFlags.GameData &&
                flag != MessageFlags.GameDataTo &&
                flag != MessageFlags.EndGame &&
                message.Position < message.Length)
            {
                Logger.Warning("Server did not consume all bytes from {0} ({1} < {2}).",
                               flag,
                               message.Position,
                               message.Length);
            }
#endif
        }
Exemplo n.º 15
0
 public void Trace(string message)
 {
     _logger.Verbose(message);
 }
Exemplo n.º 16
0
        public void Verbose(string message, params object[] propertyValues)
        {
            _serilog.Verbose(message, propertyValues);

            LogMessage(LogType.Verbose, message, propertyValues);
        }
        public static IHostBuilder GetHostBuilder(EnvironmentConfiguration environmentConfiguration,
                                                  IKeyValueConfiguration configuration,
                                                  ServiceProviderHolder serviceProviderHolder,
                                                  ILogger logger,
                                                  string[] commandLineArgs,
                                                  Action <IServiceCollection>?onRegistration = null)
        {
            if (environmentConfiguration == null)
            {
                throw new ArgumentNullException(nameof(environmentConfiguration));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            if (serviceProviderHolder == null)
            {
                throw new ArgumentNullException(nameof(serviceProviderHolder));
            }

            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            if (commandLineArgs == null)
            {
                throw new ArgumentNullException(nameof(commandLineArgs));
            }

            string contentRoot = environmentConfiguration.ContentBasePath ?? Directory.GetCurrentDirectory();

            logger.Debug("Using content root {ContentRoot}", contentRoot);

            var kestrelServerOptions = new List <KestrelServerOptions>();

            IHostBuilder hostBuilder = Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(commandLineArgs);

            hostBuilder.ConfigureLogging((_, builder) => builder.AddProvider(new SerilogLoggerProvider(logger)))
            .ConfigureServices(services =>
            {
                foreach (var serviceDescriptor in serviceProviderHolder.ServiceCollection)
                {
                    logger.Verbose("Adding service descriptor {Descriptor}",
                                   serviceDescriptor.GetDescription());

                    services.Add(serviceDescriptor);
                }

                services.AddSingleton(environmentConfiguration);
                services.AddHttpClient();

                onRegistration?.Invoke(services);
            }).ConfigureAppConfiguration((hostingContext, config) =>
            {
                config.AddKeyValueConfigurationSource(configuration);

                hostingContext.Configuration =
                    new ConfigurationWrapper((IConfigurationRoot)hostingContext.Configuration,
                                             serviceProviderHolder);

                if (!string.IsNullOrWhiteSpace(environmentConfiguration.ApplicationName))
                {
                    hostingContext.HostingEnvironment.ApplicationName =
                        environmentConfiguration.ApplicationName;
                }
            });

            if (environmentConfiguration.HttpEnabled)
            {
                hostBuilder.ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseKestrel(options =>
                    {
                        if (kestrelServerOptions.Contains(options))
                        {
                            logger.Debug("Kestrel options has already been configured");
                            return;
                        }

                        if (environmentConfiguration.UseExplicitPorts)
                        {
                            logger.Debug("Environment configuration is set to use explicit ports");

                            if (environmentConfiguration.HttpPort.HasValue)
                            {
                                logger.Information("Listening on http port {Port}",
                                                   environmentConfiguration.HttpPort.Value);

                                options.Listen(IPAddress.Any, environmentConfiguration.HttpPort.Value);
                            }

                            if (environmentConfiguration.HttpsPort.HasValue &&
                                environmentConfiguration.PfxFile.HasValue() &&
                                environmentConfiguration.PfxPassword.HasValue())
                            {
                                logger.Information("Listening on https port {Port}",
                                                   environmentConfiguration.HttpsPort.Value);

                                options.Listen(IPAddress.Any,
                                               environmentConfiguration.HttpsPort.Value,
                                               listenOptions =>
                                {
                                    listenOptions.UseHttps(environmentConfiguration.PfxFile,
                                                           environmentConfiguration.PfxPassword);
                                });
                            }
                        }

                        kestrelServerOptions.Add(options);
                    }).UseContentRoot(contentRoot)
                    .ConfigureAppConfiguration((_, config) => config.AddEnvironmentVariables())
                    .UseIISIntegration()
                    .UseDefaultServiceProvider((context, options) =>
                                               options.ValidateScopes = context.HostingEnvironment.IsDevelopment()).UseStartup <T>();

                    if (environmentConfiguration.EnvironmentName is { })
                    {
                        webBuilder.UseEnvironment(environmentConfiguration.EnvironmentName);
                    }
                }).UseSerilog(logger);
Exemplo n.º 18
0
 public void LogSystemActivity(string activityType, object data)
 {
     serilogLogger.Information(activityType + " - {@data}", data);
     serilogLogger.Verbose(activityType + " - {@data} - {@StackTrace}", data, Environment.StackTrace);
 }
Exemplo n.º 19
0
 /// <summary>
 /// Log a verbose message.
 /// </summary>
 public void LogVerbose(string message, params object[] args)
 {
     factoryLogger.Verbose(message, args);
     mainLogger.LogVerbose(message, args);
 }