Ejemplo n.º 1
0
        /// <summary>
        /// Called when [scheduled task].
        /// </summary>
        /// <param name="packet">The packet.</param>
        private void OnScheduledTask(Packet packet)
        {
            string message = packet.DataAsString();

            if (packet.Opcode == OpcodeEnum.ScheduledTask)
            {
                ConsoleLogUpdated?.Invoke(this, new ConsoleLogEventArgs()
                {
                    Message   = "TASK SERVER RESPONSE: " + message,
                    Timestamp = packet.Timestamp
                });
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Consoles the command.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="nickname">The nickname.</param>
        public void ConsoleCommand(string message, string nickname)
        {
            string formattedMessage = (nickname == null) ? message : "(" + nickname + "): " + message;

            if (!ExecCommand(OpcodeEnum.Generic, message))
            {
                return;
            }

            ConsoleLogUpdated?.Invoke(this, new ConsoleLogEventArgs()
            {
                Message = formattedMessage, Timestamp = DateTime.Now
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Executes the scheduled task.
        /// </summary>
        /// <param name="TaskName">Name of the task.</param>
        /// <param name="TaskCommand">The task command.</param>
        public void ExecuteScheduledTask(string TaskName, string TaskCommand)
        {
            if (!ExecCommand(OpcodeEnum.ScheduledTask, TaskCommand))
            {
                return;
            }

            ConsoleLogUpdated?.Invoke(this, new ConsoleLogEventArgs()
            {
                Message = "EXECUTED SCHEDULED TASK: " + TaskName, Timestamp = DateTime.Now
            });
            ConsoleLogUpdated?.Invoke(this, new ConsoleLogEventArgs()
            {
                Message = "TASK COMMAND: " + TaskCommand, Timestamp = DateTime.Now
            });
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="writeToConsole">if set to <c>true</c> [write to console].</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        public bool ExecCommand(string command, bool writeToConsole = false)
        {
            if (!ExecCommand(OpcodeEnum.Generic, command))
            {
                return(false);
            }

            if (writeToConsole)
            {
                ConsoleLogUpdated?.Invoke(this, new ConsoleLogEventArgs()
                {
                    Message = "> " + command, Timestamp = DateTime.Now
                });
            }

            return(true);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Called when [whitelist player].
        /// </summary>
        /// <param name="packet">The packet.</param>
        private void OnWhitelistPlayer(Packet packet)
        {
            string message = packet.DataAsString();

            if (message.Trim() == "Server received, But no response!!")
            {
                return;
            }

            if (packet.Opcode == OpcodeEnum.Whitelist)
            {
                ConsoleLogUpdated?.Invoke(this, new ConsoleLogEventArgs()
                {
                    Message   = "PLAYER ADDED TO WHITELIST COMMAND EXECUTED: " + message,
                    Timestamp = packet.Timestamp
                });
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Called when [console log updated].
        /// </summary>
        /// <param name="packet">The packet.</param>
        private void OnConsoleLogUpdated(Packet packet)
        {
            string message = packet.DataAsString();

            if (message.Trim() == "Server received, But no response!!")
            {
                message = "Command Executed Successfully!";
            }

            if (packet.Opcode == OpcodeEnum.Generic || packet.Opcode == OpcodeEnum.ServerResponse)
            {
                ConsoleLogUpdated?.Invoke(this, new ConsoleLogEventArgs()
                {
                    Message   = "SERVER CONSOLE: " + message,
                    Timestamp = packet.Timestamp
                });
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Called when [kick player].
        /// </summary>
        /// <param name="packet">The packet.</param>
        private void OnKickPlayer(Packet packet)
        {
            string message = packet.DataAsString();

            if (message.Trim() == "Server received, But no response!!")
            {
                return;
            }

            if (packet.Opcode == OpcodeEnum.KickPlayer)
            {
                ConsoleLogUpdated?.Invoke(this, new ConsoleLogEventArgs()
                {
                    Message   = "KICK PLAYER COMMAND EXECUTED: " + message,
                    Timestamp = packet.Timestamp
                });

                GetPlayers();
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Called when [get players].
        /// </summary>
        /// <param name="packet">The packet.</param>
        private void OnGetPlayers(Packet packet)
        {
            try
            {
                List <Player> players = new List <Player>();
                string        message = packet.DataAsString();
                if (message.Trim() == "No Players Connected")
                {
                    CurrentPlayerCountUpdated?.Invoke(this, new PlayerCountEventArgs()
                    {
                        PlayerCount = players.Count
                    });
                    PlayersUpdated?.Invoke(this, new PlayersEventArgs()
                    {
                        Players = players
                    });
                    ConsoleLogUpdated?.Invoke(this, new ConsoleLogEventArgs()
                    {
                        Message   = "Server Response: No Players Connected",
                        Timestamp = packet.Timestamp
                    });
                    return;
                }
                string   str        = packet.DataAsString();
                string[] lines      = str.Split('\n');
                string[] cleanLines = lines.Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
                foreach (string line in cleanLines)
                {
                    string   lineData     = line.Replace("...", "");
                    string[] split1       = lineData.Split(new char[] { '.' }, 2);
                    string[] split2       = split1[1].Split(new char[] { ',' }, 2);
                    string   playerNumber = split1[0].Trim();
                    string   name         = split2[0].Trim();
                    string   steamId      = split2[1].Trim();

                    players.Add(new Player
                    {
                        PlayerNumber = int.Parse(playerNumber),
                        Name         = name,
                        SteamID      = ulong.Parse(steamId)
                    });
                }

                CurrentPlayerCountUpdated?.Invoke(this, new PlayerCountEventArgs()
                {
                    PlayerCount = players.Count
                });
                PlayersUpdated?.Invoke(this, new PlayersEventArgs()
                {
                    Players = players
                });
                ConsoleLogUpdated?.Invoke(this, new ConsoleLogEventArgs()
                {
                    Message   = "Server Response: Player List Updated",
                    Timestamp = packet.Timestamp
                });
            }
            catch (Exception ex)
            {
                _logger.LogInformation("Exception in OnGetPlayers: {exception}", ex.Message);
            }
        }