Пример #1
0
 /// <summary>
 /// Broadcast broadcasts to a specific RCON session
 /// </summary>
 /// <param name="behavior"></param>
 /// <param name="message"></param>
 /// <param name="identifier"></param>
 public static void Broadcast(JuicedWebSocketBehavior behavior, string message, int identifier)
 {
     Broadcast(behavior, RemoteMessage.CreateMessage(message, identifier));
 }
Пример #2
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);
            }