private void Form1_FormClosed(object sender, FormClosedEventArgs e) { if (WebSocketsWrapper.IsConnected()) { WebSocketsWrapper.Disconnect(); } }
/// <summary> /// Called when a key is pressed in the broadcast box /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void textBoxBroadcast_KeyPress(object sender, KeyPressEventArgs e) { if ((ConsoleKey)e.KeyChar == ConsoleKey.Enter) { WebSocketsWrapper.Send($"say {textBoxBroadcast.Text}"); } }
/// <summary> /// Called when a key is pressed in the command box /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void textBoxCommand_KeyPress(object sender, KeyPressEventArgs e) { if ((ConsoleKey)e.KeyChar == ConsoleKey.Enter) { WebSocketsWrapper.SendCommand(textBoxCommand.Text); } }
public static void UpdatePlayers() { while (WebSocketsWrapper.IsConnected()) { WebSocketsWrapper.SendCommand("playerlist"); Thread.Sleep(TimeSpan.FromSeconds(10)); } }
/// <summary> /// Called when "Send" (command) button is clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonCommand_Click(object sender, EventArgs e) { WebSocketsWrapper.SendCommand(textBoxCommand.Text); }
/// <summary> /// Called when "Disconnect" button is clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonDisconnect_Click(object sender, EventArgs e) { WebSocketsWrapper.Disconnect(); }
/// <summary> /// Called when "Send" (broadcast) button is clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonBroadcast_Click(object sender, EventArgs e) { WebSocketsWrapper.Send($"say {textBoxBroadcast.Text}"); }
/// <summary> /// Formats the string for the status text /// </summary> /// <param name="text"></param> /// <returns></returns> private static string FormatStatus(string text) { var connected = WebSocketsWrapper.IsConnected() ? "Connected" : "Disconnected"; return($"{text} ({connected})"); }