/// <summary> /// Sends a packet with the specified message and identifier /// </summary> /// <param name="packet"></param> public static void Send(string message, int identifier = 1) { if (!IsConnected()) { MessageBox.Show("You aren't connected.", "Sharpcon", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } var packetObj = new Packet(message, identifier); var packetStr = JsonConvert.SerializeObject(packetObj); webSocket.SendAsync(packetStr, null); ServerConsole.AddNewEntry($"> {packetObj.Message}"); }
/// <summary> /// OnMessage event handler /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void WebSocket_OnMessage(object sender, MessageEventArgs e) { var packet = JsonConvert.DeserializeObject <Packet>(e.Data); // If this is a return from something called earlier, process it. if (Listener.Listeners.ContainsKey(packet.Identifier)) { Listener.ProcessMessage(packet); return; } if (packet.Identifier == -1 || string.IsNullOrEmpty(packet.Message)) { return; } ServerConsole.AddNewEntry(packet.Message); }