예제 #1
0
        public void GetAdditionalPropertyShouldSucceed()
        {
            var client  = new EFClient();
            int newProp = 5;

            client.SetAdditionalProperty("NewProp", newProp);

            Assert.True(client.GetAdditionalProperty <int>("NewProp") == 5, "added property does not match retrieved property");
        }
예제 #2
0
        private void HandleDisconnectCalculations(EFClient client, HitState state)
        {
            // todo: this not added to states fast connect/disconnect
            var serverStats = state.Hits.FirstOrDefault(stat =>
                                                        stat.ServerId == state.Server.ServerId && stat.WeaponId == null &&
                                                        stat.WeaponAttachmentComboId == null && stat.HitLocationId == null && stat.MeansOfDeathId == null);

            if (serverStats == null)
            {
                _logger.LogWarning("No server hits were found for {serverId} on disconnect for {client}",
                                   state.Server.ServerId, client.ToString());
                return;
            }

            var aggregate = state.Hits.FirstOrDefault(stat => stat.WeaponId == null &&
                                                      stat.WeaponAttachmentComboId == null &&
                                                      stat.HitLocationId == null &&
                                                      stat.MeansOfDeathId == null &&
                                                      stat.ServerId == null);

            if (aggregate == null)
            {
                _logger.LogWarning("No aggregate found for {serverId} on disconnect for {client}",
                                   state.Server.ServerId, client.ToString());
                return;
            }

            var sessionScores = client.GetAdditionalProperty <List <(int, DateTime)> >(SessionScores);

            if (sessionScores == null)
            {
                _logger.LogWarning("No session scores available for {Client}", client.ToString());
                return;
            }

            foreach (var stat in new[] { serverStats, aggregate })
            {
                stat.Score ??= 0;

                if (sessionScores.Count == 0)
                {
                    stat.Score += client.Score > 0 ? client.Score : client.GetAdditionalProperty <int?>(Helpers.StatManager.ESTIMATED_SCORE) ?? 0 * 50;
                }

                else
                {
                    stat.Score += sessionScores.Sum(item => item.Item1) +
                                  (sessionScores.Last().Item1 == client.Score &&
                                   (DateTime.Now - sessionScores.Last().Item2).TotalMinutes < 1
                                      ? 0
                                      : client.Score);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Send a message to a particular players
        /// </summary>
        /// <param name="message">Message to send</param>
        /// <param name="targetClient">EFClient to send message to</param>
        protected async Task Tell(string message, EFClient targetClient)
        {
            var engineMessage = message.FormatMessageForEngine(RconParser.Configuration.ColorCodeMapping);

            if (!Utilities.IsDevelopment)
            {
                var temporalClientId = targetClient.GetAdditionalProperty <string>("ConnectionClientId");
                var parsedClientId   = string.IsNullOrEmpty(temporalClientId) ? (int?)null : int.Parse(temporalClientId);
                var clientNumber     = parsedClientId ?? targetClient.ClientNumber;

                var formattedMessage = string.Format(RconParser.Configuration.CommandPrefixes.Tell,
                                                     clientNumber,
                                                     $"{(CustomSayEnabled && GameName == Game.IW4 ? $"{CustomSayName}: " : "")}{engineMessage}");
                if (targetClient.ClientNumber > -1 && message.Length > 0 && targetClient.Level != EFClient.Permission.Console)
                {
                    await this.ExecuteCommandAsync(formattedMessage);
                }
            }
            else
            {
                ServerLogger.LogDebug("Tell[{ClientNumber}]->{Message}", targetClient.ClientNumber,
                                      message.FormatMessageForEngine(RconParser.Configuration.ColorCodeMapping).StripColors());
            }

            if (targetClient.Level == EFClient.Permission.Console)
            {
                Console.ForegroundColor = ConsoleColor.Green;
                using (LogContext.PushProperty("Server", ToString()))
                {
                    ServerLogger.LogInformation("Command output received: {Message}",
                                                engineMessage.StripColors());
                }
                Console.WriteLine(engineMessage.StripColors());
                Console.ForegroundColor = ConsoleColor.Gray;
            }
        }
예제 #4
0
        private async Task <string> ProcessAnnouncement(string msg, EFClient joining)
        {
            msg = msg.Replace("{{ClientName}}", joining.Name);
            msg = msg.Replace("{{ClientLevel}}",
                              $"{Utilities.ConvertLevelToColor(joining.Level, joining.ClientPermission.Name)}{(string.IsNullOrEmpty(joining.GetAdditionalProperty<string>("ClientTag")) ? "" : $" (Color::White)({joining.GetAdditionalProperty<string>("ClientTag")}(Color::White))")}");
            // this prevents it from trying to evaluate it every message
            if (msg.Contains("{{ClientLocation}}"))
            {
                msg = msg.Replace("{{ClientLocation}}", await GetCountryName(joining.IPAddressString));
            }

            msg = msg.Replace("{{TimesConnected}}", joining.Connections.Ordinalize());

            return(msg);
        }