コード例 #1
0
        public async Task LogFeedback(GenericCommand genericCommand)
        {
            string message =
                $"{DateTime.Now} - {genericCommand.Player.Name} ({genericCommand.Player.Team}): {genericCommand.Message}";

            for (int i = 0; i < 4; i++)
            {
                try
                {
                    if (!File.Exists(FileName))
                    {
                        // Create a file to write to.
                        using (var sw = File.CreateText(FileName))
                        {
                            sw.WriteLine(message);
                        }
                    }
                    else
                    {
                        // This text is always added, making the file longer over time
                        // if it is not deleted.
                        using (var sw = File.AppendText(FileName))
                        {
                            sw.WriteLine(message);
                        }
                    }

                    break;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    await Task.Delay(5000);
                }
            }

            await _rconService.RconCommand(Server.ServerId, $"say Feedback from {genericCommand.Player.Name} captured!",
                                           false);
        }
コード例 #2
0
        /// <summary>
        ///     Handles ingame commands mapping to discord commands. Not all commands will work.
        ///     Since some commands require a context, we have some manual leg work to "build" the context when needed.
        /// </summary>
        /// <param name="server">Game server we are using</param>
        /// <param name="genericCommand">Generic command containing what command to fire, with what options.</param>
        private async void HandleIngameCommand(IPEndPoint ipServer, GenericCommand genericCommand)
        {
            Server server = null;

            if (_serverIdDictionary.ContainsKey(ipServer))
            {
                server = _serverIdDictionary[ipServer];
            }

            //Handle commands that don't need a steam user mapping.
            switch (genericCommand.Command.Trim().ToLower())
            {
            case "fb":
            case "feedback":
                HandleInGameFeedback(server, genericCommand);
                return;
            }

            genericCommand.Player.SteamId = GeneralUtil.TranslateSteamId3ToSteamId(genericCommand.Player.SteamId);
            var user = _dataService.GetSocketGuildUserFromSteamId(genericCommand.Player.SteamId);

            if (user == null)
            {
                await _rconService.RconCommand(server.Address,
                                               $"say No Discord user link found for {genericCommand.Player.Name}. See >help link in Discord");

                return;
            }

            switch (genericCommand.Command.Trim().ToLower())
            {
            case "fb":
            case "feedback":
                HandleInGameFeedback(server, genericCommand);
                break;

            case "p":
            case "playtest":
                HandlePlaytestCommand(server, genericCommand, user);
                break;

            case "r":
            case "rcon":
                HandleInGameRcon(server, genericCommand, user);
                break;

            case "done":
                HandleInGameDone(server, genericCommand, user);
                break;

            case "q":
                HandleInGameQueue(server, genericCommand, user);
                break;

            case "pc":
                HandleInGamePublicCommand(server, genericCommand, user);
                break;

            default:
                await _rconService.RconCommand(server.Address,
                                               $"say Unknown Command from {genericCommand.Player.Name}");

                break;
            }
        }