示例#1
0
        private object IOnRconCommand(IPAddress ipAddress, string command)
        {
            if (ipAddress != null && !string.IsNullOrEmpty(command))
            {
                RemoteMessage message = RemoteMessage.GetMessage(command);

                if (string.IsNullOrEmpty(message?.Message))
                {
                    return(null);
                }

                string[] fullCommand = CommandLine.Split(message.Message);

                if (fullCommand.Length >= 1)
                {
                    string   cmd  = fullCommand[0].ToLower();
                    string[] args = fullCommand.Skip(1).ToArray();

                    if (Interface.CallHook("OnRconCommand", ipAddress, cmd, args) != null)
                    {
                        return(true);
                    }
                }
            }

            return(null);
        }
示例#2
0
        private object IOnRconCommand(IPAddress sender, string message)
        {
            if (string.IsNullOrEmpty(message))
            {
                return(null);
            }

            var msg = RemoteMessage.GetMessage(message);

            if (msg == null)
            {
                return(null);
            }

            var args = msg.Message.Split(' ');
            var cmd  = args[0];
            var call = Interface.Call("OnRconCommand", sender, cmd, (args.Length > 1) ? args.Skip(1).ToArray() : null);

            if (call != null)
            {
                return(true);
            }

            return(null);
        }
示例#3
0
        private object IOnRconCommand(IPEndPoint sender, string command)
        {
            if (sender != null && !string.IsNullOrEmpty(command))
            {
                RemoteMessage message = RemoteMessage.GetMessage(command);
                if (message != null)
                {
                    string[] fullCommand = CommandLine.Split(message.Message);
                    string   cmd         = fullCommand[0].ToLower();
                    string[] args        = fullCommand.Skip(1).ToArray();

                    object callHook = Interface.CallHook("OnRconCommand", sender, cmd, args);
                    if (callHook != null)
                    {
                        return(true);
                    }
                }
            }

            return(null);
        }
示例#4
0
            /// <summary>
            /// OnMessage handles all executed RCON requests from connected sessions
            /// </summary>
            /// <param name="e"></param>
            /// <param name="behavior"></param>
            private void OnMessage(MessageEventArgs e, JuicedWebSocketBehavior behavior)
            {
                RemoteMessage request = RemoteMessage.GetMessage(e.Data);

                // ignore empty requests
                if (request == null || string.IsNullOrEmpty(request.Message))
                {
                    return;
                }

                var data    = new List <string>(request.Message.Split(' '));
                var command = data[0];

                data.RemoveAt(0);
                var args = data.ToArray();

                if (!behavior.Profile.HasAccess(command))
                {
                    Broadcast(behavior, "Permission denied", -1);
                    return;
                }

                if (Interface.CallHook("OnRconCommand", behavior?.Context?.UserEndPoint.Address, command, args) != null)
                {
                    return;
                }

                // handle rcon say
                if (command == CommandType.CommandJuicedRconSay)
                {
                    // broadcast to all sessions
                    Interface.Oxide.LogInfo(string.Format($"{behavior.Profile.DisplayName}: {string.Join(" ", args)}"));
                    return;
                }

                string output;
                // run command and capture output
                Func <string[], string> cmd;

                if (commands.TryGetValue(command, out cmd))
                {
                    output = cmd.Invoke(args);
                }
                else
                {
                    output = ConsoleSystem.Run(ConsoleSystem.Option.Server, command, args);
                }

                // do not broadcast if nothing to broadcast
                if (output == null)
                {
                    return;
                }

                // handle "say"
                if (command == CommandType.CommandSay)
                {
                    // broadcast to all sessions
                    Interface.Oxide.LogInfo(string.Format($"SERVER {string.Join(" ", args)}"));
                    return;
                }

                RemoteMessage response = RemoteMessage.CreateMessage(output, -1, RemoteMessageType.Generic);

                // handle "echo"
                if (command == CommandType.CommandEcho)
                {
                    response.Message = string.Join(" ", args);
                }

                // broadcast to session
                Broadcast(behavior, response);
            }