public ConsoleWindow(RCONClient rcon) { InitializeComponent(); _vmConsole = ConsoleViewModel.INSTANCE; DataContext = _vmConsole; _rconClient = rcon; _vmConsole.ConsoleMonitor.Add( "[" + DateTime.Now + "] " + "Initialize Complete! Try \"list\" to see who is online."); }
public void SendBTN_Click(object sender, EventArgs e) // Sends doesn't save { string txt = CMDInput.Text; historyStrings.Add(txt); historyPointer = historyStrings.Count; var answer3 = RCONClient.sendMessage(OtherRCON.RCONMessageType.Command, txt); Output.AppendText(AnsiOutput.Reset()); // reset colors Output.AppendText(txt + "\n"); Output.AppendText(answer3); CMDInput.Text = ""; }
public RCONService(Settings settings) { Log.Information("Initializing RCON service..."); this._settings = settings; RCON rconSettings = _settings.RCON; rcon = RCONClient.INSTANCE; rcon.setupStream(rconSettings.RCONHost, rconSettings.RCONPort, rconSettings.RCONPassword); Log.Information("RCON service initialized!"); }
public static bool executePlugin(RCONClient rconClient, IEnumerable <string> players) { Monitor.Enter(threadLock); try { if (!pluginIsActive) { return(false); } // Update the time stamps for the known players: foreach (var playerName in players.Where(player => player != string.Empty)) { var name = playerName.RemoveColorCodes().Trim(); if (!knownPlayers.ContainsKey(name)) { foreach (var command in commands) { rconClient.fireAndForgetMessage(RCONMessageType.Command, command.Replace("$NAME$", name)); } } knownPlayers[name] = DateTime.UtcNow; } // Remove dead entries: var dead = new List <string>(knownPlayers.Keys.Where(n => (DateTime.UtcNow - knownPlayers[n]).TotalSeconds >= 2)); foreach (var d in dead) { knownPlayers.Remove(d); } return(true); } finally { Monitor.Exit(threadLock); } }
private static void DoHandleClient(object objClient) { currentClient = (RCONClient)objClient; if (ValidRCONClients.Count == 0) { currentClient.SetLoginState(RCONClient.ELoginState.LoggedIn); } try { HandleClient(); } catch (Exception e) { LogManager.Error("RCON", "Exception occured in RCON thread for " + currentClient.RemoteEndpoint); LogManager.Error("RCON", e.ToString()); } if (currentClient.tcpClient.Connected) { currentClient.tcpClient.Close(); } }
public static bool executePlugin(RCONClient rconClient, IEnumerable <string> players) { Monitor.Enter(threadLock); try { if (!pluginIsActive) { return(false); } var isRestrictedWorld = rconClient.sendMessage(RCONMessageType.Command, restrictedWorldCommand).RemoveColorCodes().Trim() == string.Empty; if (!isRestrictedWorld) { // Reset the status if a player gets lost: if (players.Count(n => n != string.Empty) != destinationCountPlayers) { allPlayersPresent = false; } // If not all players are present, delete the inventories: if (!allPlayersPresent && players.Count(n => n != string.Empty) != destinationCountPlayers && players.Count(n => n != string.Empty) > 0) { foreach (var player in players.Where(n => n != string.Empty)) { var name = player.RemoveColorCodes().Trim(); rconClient.sendMessage(RCONMessageType.Command, @"clear " + name); } allPlayersPresent = false; return(true); } // Now, all players are in place: if (items.Length > 0 && !allPlayersPresent) { allPlayersPresent = true; // // First: Clear all inventories (important for the last player who was new) // foreach (var player in players.Where(n => n != string.Empty)) { var name = player.RemoveColorCodes().Trim(); rconClient.sendMessage(RCONMessageType.Command, @"clear " + name); } // // Second: Distribute the items // // Get the right list of items which matches the count of players: var rightItemList = items.Skip(items.Length % destinationCountPlayers).ToArray(); // Memorise the already used items: var usedItems = new List <int>(); for (var n = 0; n < rightItemList.Length / destinationCountPlayers; n++) { foreach (var playerName in players.Where(player => player != string.Empty)) { // Find the next matching number i.e. item's position: var nextNumber = 0; while (true) { nextNumber = BetterRND.INSTANCE.nextInt(0, rightItemList.Length); if (!usedItems.Contains(nextNumber)) { usedItems.Add(nextNumber); break; } else { Thread.Sleep(1); continue; } } // Get the item: var item = " " + rightItemList[nextNumber]; // Build the command: var item4Player = "give " + playerName.RemoveColorCodes().Trim() + item; // Send the command: rconClient.fireAndForgetMessage(RCONMessageType.Command, item4Player); } } } } return(true); } finally { Monitor.Exit(threadLock); } }
public void Init() { Client = RCONClient.INSTANCE; Debug = Sys.Ref.Config.Debug; Client.setupStream(Sys.Ref.Config.IP, Sys.Ref.Config.RCONPort, Sys.Ref.Config.RCONPassword); }
private static void DoHandleClient(object objClient) { currentClient = (RCONClient)objClient; if (ValidRCONClients.Count == 0) currentClient.SetLoginState(RCONClient.ELoginState.LoggedIn); try { HandleClient(); } catch (Exception e) { LogManager.Error("RCON", "Exception occured in RCON thread for " + currentClient.RemoteEndpoint); LogManager.Error("RCON", e.ToString()); } if (currentClient.tcpClient.Connected) currentClient.tcpClient.Close(); }