public override void SendMessageAsync(string text) { Console.WriteLine("(For RCON Connection) " + text); var js = new ConsolePacket(); js.packet = 0; js.text = text; instance.Send(JsonConvert.SerializeObject(js)); // Program.wssv.WebSocketServices.Broadcast(JsonConvert.SerializeObject(js)); }
public virtual void SendMessageAsync(string text) { if (!headless) { channel.SendMessageAsync(text); } else { Console.WriteLine(text); var js = new ConsolePacket(); js.packet = 0; js.text = text; Program.wssv.WebSocketServices.Broadcast(JsonConvert.SerializeObject(js)); } }
public static void ConsoleWriteLine(string text) { Console.WriteLine(text); var js = new ConsolePacket(); js.packet = 0; js.text = text; if (rconSettings.enabled) { //wssv.WebSocketServices.Broadcast(JsonConvert.SerializeObject(js)); foreach (var element in rconConnections) { if (element.Value.logged) { element.Key.Send(JsonConvert.SerializeObject(js)); } } } }
protected override void OnMessage(MessageEventArgs e) { //Console.WriteLine("Packet: "+e.Data); var pack = JsonConvert.DeserializeObject <WebPacket>(e.Data); switch (pack.packet) { case 0: if (!RCONUsersByToken.ContainsKey(pack.token)) { return; } var cs = JsonConvert.DeserializeObject <ConsolePacket>(e.Data); Console.WriteLine("From RCON Connection: " + cs.text); var console = cs.text; var msg = new MessageWrapper(console); var rconuser = RCONUsersByToken[pack.token]; var us = new UserWrapper(rconuser.Username, rconuser.Discriminator, rconuser.Id); msg.Channel = new RCONChannel() { instance = Context.WebSocket }; msg.Author = us; if (console.Length >= Program.botSettings.defaultPrefix.Length) { var args = console.Split(' '); var cmd = args[0]; if (cmd.Substring(0, Program.botSettings.defaultPrefix.Length) == Program.botSettings.defaultPrefix) { cmd = cmd.Substring(Program.botSettings.defaultPrefix.Length); if (Program.commands.ContainsKey(cmd)) { try { Program.commands[cmd].Run(Program.commands[cmd].splitArgs(console), msg); var returnString = ""; var returnInfo = Program.commands[cmd].GetInputField(Program.commands[cmd].splitArgs(console), msg); if (returnInfo.keepCommand) { returnString = args[0]; } if (returnInfo.keepArguments.Length > 0) { returnString += " "; } foreach (var element in returnInfo.keepArguments) { returnString += element + " "; } returnString += returnInfo.suffix; var inputPacket = new ConsolePacket(); inputPacket.packet = 3; inputPacket.text = returnString; Send(JsonConvert.SerializeObject(inputPacket)); } catch (Exception se) { var errorPacket = new ConsolePacket(); errorPacket.packet = 0; errorPacket.text = "Failed to run command. Exception:" + Environment.NewLine + se.ToString(); Send(JsonConvert.SerializeObject(errorPacket)); } } else { Program.onUnknownCommand?.Invoke(msg); } } else { var inputPacket = new ConsolePacket(); inputPacket.packet = 3; inputPacket.text = ""; Send(JsonConvert.SerializeObject(inputPacket)); foreach (var element in Program.rconConnections) { if (element.Key != Context.WebSocket) { var messagePack = new ConsolePacket(); messagePack.packet = 0; messagePack.token = pack.token; messagePack.text = "[RCON] " + rconuser.Username + ": " + console; element.Key.Send(JsonConvert.SerializeObject(messagePack)); } } } } break; case 2: var returnPacket = new TokenReturnPacket(); returnPacket.packet = 1; if (RCONUsersByToken.ContainsKey(pack.token)) { returnPacket.status = true; returnPacket.username = RCONUsersByToken[pack.token].Username; Program.rconConnections[Context.WebSocket].logged = true; Program.rconConnections[Context.WebSocket].token = pack.token; Console.WriteLine("RCON connection from " + Context.UserEndPoint.Address.ToString() + " logged in as " + returnPacket.username); } else { returnPacket.status = false; Program.rconConnections[Context.WebSocket].logged = false; Program.rconConnections[Context.WebSocket].token = ""; Console.WriteLine("RCON connection from " + Context.UserEndPoint.Address.ToString() + " failed to log in, used incorrect token '" + pack.token + "'"); } Send(JsonConvert.SerializeObject(returnPacket)); break; } }