/// <summary> /// Handles the Coding Text /// </summary> /// <param name="msg">Code text</param> /// <param name="server">Server</param> public static void HandleCodeMsg(string msg, Server server) { MethodInvoker invoker = new MethodInvoker(delegate() { MainForm.mainForm.richTextBoxCode.AppendText(msg); }); MainForm.mainForm.Invoke(invoker); }
public static void HandleChatMsg(string msg, Server server) { MethodInvoker invoker = new MethodInvoker(delegate() { MainForm.mainForm.richTextBoxChat.AppendText(msg); MainForm.mainForm.richTextBoxChat.AppendText(Environment.NewLine); }); MainForm.mainForm.Invoke(invoker); }
/// <summary> /// Starts the server /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonServer_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxHost.Text) || string.IsNullOrEmpty(textBoxPort.Text)) return; if (Start(textBoxHost.Text, Convert.ToInt32(textBoxPort.Text))) { server = new Server(); isServer = true; buttonClient.Enabled = false; } }
/// <summary> /// Handles Client > Server and Server > Client deletion of code /// </summary> /// <param name="length">Length of the text deleted</param> /// <param name="server">Server</param> public static void HandleCodeDel(int length, Server server) { if (length < 0) return; MethodInvoker invoker = new MethodInvoker(delegate() { MainForm.mainForm.richTextBoxCode.Select(length, 1); MainForm.mainForm.richTextBoxCode.SelectedText = ""; MainForm.mainForm.richTextBoxCode.SelectionStart = length; }); MainForm.mainForm.Invoke(invoker); }
/// <summary> /// Handles incoming data /// </summary> /// <param name="data"></param> /// <param name="server"></param> public static void HandleData(string data, Server server) { if (data.Contains(Packet.GetPacket(Packets.ACCOUNT_LOGIN))) { data.Remove(data.Length - Packets.ACCOUNT_LOGIN.ToPacket().Length); string username = Packet.HandleSplitData(data)[0]; if (!string.IsNullOrEmpty(username)) LoginHandler.HandleLogin(username, server); } else if (data.Contains(Packet.GetPacket(Packets.CODE_MSG))) { data.Remove(data.Length - Packets.CODE_MSG.ToPacket().Length); string msg = Packet.HandleSplitData(data)[0]; if (!string.IsNullOrEmpty(msg)) MessageHandler.HandleCodeMsg(msg, server); } else if (data.Contains(Packet.GetPacket(Packets.CODE_DEL))) { data.Remove(data.Length - Packets.CODE_DEL.ToPacket().Length); int length = Convert.ToInt32(Packet.HandleSplitData(data)[0]); if (length >= 0) MessageHandler.HandleCodeDel(length, server); } else if (data.Contains(Packet.GetPacket(Packets.CHAT_MSG))) { data.Remove(data.Length - Packets.CHAT_MSG.ToPacket().Length); string chatMessage = Packet.HandleSplitData(data)[0]; if (!string.IsNullOrEmpty(chatMessage)) MessageHandler.HandleChatMsg(chatMessage, server); } }