예제 #1
0
        /// <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);
        }
예제 #2
0
        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);
        }
예제 #3
0
파일: Main.cs 프로젝트: Hamarz/CodeWithMe
        /// <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;
            }
        }
예제 #4
0
        /// <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);
        }
예제 #5
0
        /// <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);
            }
        }