Exemplo n.º 1
0
        private void CaseEnter(string cmd, string dat, string tm)
        {
            rd = new RoomDialog(client, form1.request);

            rd.room.name = cmd;
            if (rd.room.name.Contains("+"))
            {
                rd.btn_exit.Enabled = false;
            }
            else
            {
                rd.btn_exit.Enabled = true;
            }
            rd.Text = cmd;
            string[] str = dat.Split(',');
            if (str[0] == "missed")
            {
                string[] tmp = str[1].Split('.');
                for (int i = 0; i < tmp.Length; i++)
                {
                    rd.rtb_message.Text += tmp[i] + "\n";
                }
            }
            Thread tr = new Thread(new ThreadStart(OpenForm));

            tr.Start();
            Thread.Sleep(100);
            if (str.Length > 1)
            {
                string[] tmp = rd.rtb_message.Text.Split('\n');
                for (int i = Convert.ToInt32(tm); i < tmp.Length; i++)
                {
                    string str11 = tmp[i];
                    int    j     = 0;
                    while (j < rd.rtb_message.Text.Length - str11.Length)
                    {
                        j = rd.rtb_message.Text.IndexOf(str11, j);
                        if (j <= 0)
                        {
                            break;
                        }
                        rd.rtb_message.SelectionStart  = j;
                        rd.rtb_message.SelectionLength = str11.Length;
                        rd.rtb_message.SelectionColor  = Color.Red;
                        j += str11.Length;
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void Listen()
        {
            try
            {
                while (true)
                {
                    StreamReader reader  = new StreamReader(client.GetStream());
                    string       message = reader.ReadLine();
                    Request      req     = JsonConvert.DeserializeObject <Request>(message);
                    switch (req.modul)
                    {
                    case "ok":
                        VisibleComponents(req.data);
                        if (req.data == "admin")
                        {
                            form1.btn_ban.BeginInvoke(new InvokeDelegate(form1.VisibleBan));
                            form1.btn_unban.BeginInvoke(new InvokeDelegate(form1.VisibeUnban));
                        }
                        break;

                    case "enter":
                        rd           = new RoomDialog(client, form1.request);
                        rd.room.name = req.command;
                        rd.Text      = req.command;
                        if (req.data == "missed")
                        {
                            string[] tmp1 = req.time.Split('.');
                            for (int i = 0; i < tmp1.Length; i++)
                            {
                                rd.rtb_message.Text += tmp1[i] + "\n";
                            }
                        }
                        tr = new Thread(new ThreadStart(OpenForm));
                        tr.Start();
                        break;

                    case "leave":
                        rd.Close();
                        break;

                    case "bancreate":
                        MessageBox.Show(req.data);
                        break;

                    case "wrongroom":
                        MessageBox.Show("Ошибка, комната " + req.data + " уже создана");
                        break;

                    case "refresh":
                        string[] splitrooms = req.data.Split('.');
                        if (splitrooms[0] == "")
                        {
                            break;
                        }
                        form1.lst_rooms.Items.Clear();
                        form1.lst_rooms.Items.AddRange(splitrooms);
                        break;

                    case "refreshclients":
                        string[] splitclients = req.data.Split('.');
                        form1.lst_clients.Items.Clear();
                        if (splitclients[0] == "")
                        {
                            break;
                        }
                        form1.lst_clients.Items.AddRange(splitclients);
                        break;

                    case "message":
                        rd.rtb_message.Text += req.data + "\n";
                        break;

                    case "youbanned":
                        rd.rtb_message.Text += req.data + "\n";
                        break;

                    case "pofig":
                        int a = -1;
                        for (int i = 0; i < form1.lst_rooms.Items.Count; i++)
                        {
                            string[] str1 = form1.lst_rooms.Items[i].ToString().Split(' ');
                            if (str1[0] == req.command)
                            {
                                a = i;
                            }
                        }
                        if (a != -1)
                        {
                            form1.lst_rooms.Items.RemoveAt(a);
                            form1.lst_rooms.Items.Insert(a, req.command + "   +" + req.data);
                        }
                        else
                        {
                            form1.lst_rooms.Items.Insert(form1.lst_rooms.Items.Count, req.command + "   +" + req.data);
                        }
                        break;

                    case "wrongprivate":
                        MessageBox.Show("Уже есть приватная комната с этим клиентом");
                        break;

                    case "badlogin":
                        MessageBox.Show("Плохой Log/pass или юзер online");
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Сервер упал");
                form1.client = null;
                try
                {
                    rd.Close();
                }
                catch (Exception e) { }

                foreach (Control item in form1.Controls)
                {
                    item.Enabled = false;
                    client       = null;
                }
            }
        }