Ejemplo n.º 1
0
 private void groupChatButton_Click(object sender, EventArgs e)
 {
     {
         GroupChat f = new GroupChat(null);
         f.Show();
     }
 }
Ejemplo n.º 2
0
        public void Actions()
        {
            if (globals.receivedText != null)
            {
                if (globals.receivedText.Contains("$$$$"))
                {
                    globals.receivedText = globals.receivedText.Substring(0, globals.receivedText.IndexOf("$$$$"));
                }

                if (globals.receivedText.Substring(0, 4) == "$cl$")
                {
                    dataGridViewContacts.Rows.Clear();
                    string[] clientsConnected = globals.receivedText.Substring(4).Split(',');

                    foreach (string client in clientsConnected)
                    {
                        if (client != globals.username && client != "")
                        {
                            dataGridViewContacts.Rows.Add(new object[] { "Desconectado", client, "Mensaje" });
                        }
                    }
                    SendString("$cs$" + globals.username + "$cs$" + comboBoxUserStatus.Text + "$$$$");
                }

                else if (globals.receivedText.Substring(0, 4) == "$cs$")
                {
                    string statusMessage = globals.receivedText;


                    if (statusMessage.Length > 4)
                    {
                        string userFrom = statusMessage.Substring(4);
                        userFrom = userFrom.Substring(0, userFrom.IndexOf("$cs$"));
                        string status = statusMessage.Substring(4);
                        status = status.Substring(status.IndexOf("$cs$") + 4);

                        foreach (DataGridViewRow dg in dataGridViewContacts.Rows)
                        {
                            if (dg.Cells[1].Value.ToString().Equals(userFrom))
                            {
                                dg.Cells[0].Value = status;
                                break;
                            }
                        }
                    }
                }

                else if (globals.receivedText.Substring(0, 4) == "$mr$")
                {
                    string userFrom = globals.receivedText.Substring(4);
                    userFrom = userFrom.Substring(0, userFrom.IndexOf("$mr$"));
                    string message = globals.receivedText.Substring(4);
                    message = message.Substring(message.IndexOf("$mr$") + 4);
                    message = message.Substring(0, message.IndexOf("$me$"));

                    if (message.Contains("te ha enviado un zumbido."))
                    {
                        foreach (WindowChat f in Application.OpenForms.OfType <WindowChat>())
                        {
                            if (f.Text.Contains(userFrom))
                            {
                                f.zumbido();
                                f.setMessage("\n" + userFrom + " " + message);
                            }
                        }
                    }
                    else
                    {
                        foreach (DataGridViewRow dg in dataGridViewContacts.Rows)
                        {
                            if (dg.Cells[1].Value.ToString().Contains(userFrom))
                            {
                                dg.Cells[2].Value = message;
                            }
                        }

                        foreach (WindowChat f in Application.OpenForms.OfType <WindowChat>())
                        {
                            if (f.Text.Contains(userFrom))
                            {
                                f.setMessage("\n" + userFrom + ": " + message);
                            }
                        }
                    }
                }

                else if (globals.receivedText.Substring(0, 4) == "$gr$")
                {
                    string usersFrom = globals.receivedText.Substring(4);
                    usersFrom = usersFrom.Substring(0, usersFrom.IndexOf("$gr$"));
                    string[] users   = usersFrom.Split(',');
                    string   message = globals.receivedText.Substring(4);
                    message = message.Substring(message.IndexOf("$gr$") + 4);
                    message = message.Substring(0, message.IndexOf("$me$"));

                    List <string> participants = new List <string>();

                    foreach (string user in users)
                    {
                        participants.Add(user);
                    }

                    usersFrom = participants.Last();
                    participants.Sort();

                    bool isOpen = false;

                    foreach (GroupChat f in Application.OpenForms.OfType <GroupChat>())
                    {
                        if (f.getParticipants().SequenceEqual(participants))
                        {
                            isOpen = true;
                            f.setMessage("\n" + usersFrom + ": " + message);
                        }
                    }

                    GroupChat gc;
                    if (!isOpen)
                    {
                        gc = new GroupChat(participants);
                        gc.Show();
                        gc.setMessage("\n" + usersFrom + ": " + message);
                    }
                }

                else if (globals.receivedText.Substring(0, 4) == "$gm$")
                {
                    string userFrom = globals.receivedText.Substring(4);
                    userFrom = userFrom.Substring(0, userFrom.IndexOf("$gm$"));
                    string message = globals.receivedText.Substring(4);
                    message = message.Substring(message.IndexOf("$gm$") + 4);

                    foreach (WindowChat f in Application.OpenForms.OfType <WindowChat>())
                    {
                        if (f.Text == userFrom)
                        {
                            f.setMessage(message);
                        }
                    }
                }

                else if (globals.receivedText.Substring(0, 4) == "$pg$")
                {
                    string messageReceived = globals.receivedText.Substring(4);
                    messageReceived = messageReceived.Substring(0, messageReceived.IndexOf("$pg$"));
                    string[] users = messageReceived.Split(',');

                    List <string> participants = new List <string>();

                    foreach (string user in users)
                    {
                        participants.Add(user);
                    }

                    bool isOpen = false;

                    foreach (GameBoard f in Application.OpenForms.OfType <GameBoard>())
                    {
                        if (f.getParticipants().SequenceEqual(participants))
                        {
                            isOpen = true;
                        }
                    }

                    GameBoard t;
                    if (!isOpen)
                    {
                        t = new GameBoard(participants, globals.username);
                        t.Show();
                    }
                }

                else if (globals.receivedText.Substring(0, 4) == "$ip$")
                {
                    string userFrom = globals.receivedText.Substring(4);
                    userFrom = userFrom.Substring(0, userFrom.IndexOf("$ip$"));
                    string message = globals.receivedText.Substring(4);
                    message = message.Substring(message.IndexOf("$ip$") + 4);

                    if (!globals.udpClients.ContainsKey(userFrom))
                    {
                        globals.udpClients.Add(userFrom, message);
                    }
                    else
                    {
                        globals.udpClients[userFrom] = message;
                    }
                }

                else
                {
                    return;
                }
            }
            else
            {
                SendString("$cl$");
            }
        }