Example #1
0
        void update_lobby_labels(lobby c_lobby)
        {
            lobby_name.Text    = c_lobby.name;
            lobby_map.Text     = c_lobby.map;
            lobby_players.Text = c_lobby.players;
            lobby_score.Text   = c_lobby.score;
            lobby_status.Text  = c_lobby.status;

            if (c_lobby.status == "Live" || c_lobby.status == "Ready-up" || c_lobby.status == "Veto")
            {
                List <string> get_players = new List <string>();
                get_players.Add(current_active_lobby_id.ToString());
                main_hub.shared_udpclient.send_data(0x09, get_players);
            }
            else
            {
                team_a_label.Visible   = false;
                team_b_label.Visible   = false;
                team_a_players.Visible = false;
                team_b_players.Visible = false;
            }
        }
Example #2
0
        private void manage_packets()
        {
            while (true)
            {
                byte[] packet = udpclient.listen();

                byte cmd = packet[0];

                if (cmd != 0x17)
                {
                    switch (cmd)
                    {
                    case 0x01:
                        if (packet[1] == 0xFA)
                        {
                            stop_timers();     // Stops timers and threads
                            c_msgbox.show_msg(false, "Server on sinu ühenduse katkestanud!");
                            logout();
                        }
                        else
                        {
                            List <string> me_live_info = udpclient.extract_data(packet);
                            // me_live_info[0] - stored client hash
                            // me_live_info[1] - is_client_in_lobby
                            // me_live_info[2] - lobby id
                            // me_live_info[3] - lobby status
                            // me_live_info[4] - am i ready
                            if (my_info.s_hash == long.Parse(me_live_info[0]))
                            {
                                if (me_live_info[1] == "in_lobby")
                                {
                                    my_info.am_i_in_lobby = true;
                                    //MessageBox.Show("IN LOBBY");
                                    play_screen.allow_leave_button();

                                    if (me_live_info[3] == "Live" || me_live_info[3] == "Veto")
                                    {
                                        play_screen.disable_both_buttons();
                                        if (!my_info.lobby_window_open)
                                        {
                                            //change to active lobby screen
                                            change_screen(4);
                                        }
                                    }

                                    if (me_live_info[4] == "not_ready")
                                    {
                                        my_info.am_i_ready = false;
                                    }
                                    else
                                    {
                                        my_info.am_i_ready = true;
                                    }

                                    if (me_live_info[3] == "Ready-up")
                                    {
                                        if (!my_info.ready_window_open)
                                        {
                                            //open ready screenr
                                            my_info.ready_window_open = true;
                                            open_ready_screen();
                                            if (my_info.am_i_ready)
                                            {
                                                ready_screen.im_ready();
                                            }
                                        }
                                    }

                                    my_info.lobby_id     = int.Parse(me_live_info[2]);
                                    my_info.lobby_status = me_live_info[3];
                                }
                                else
                                {
                                    my_info.am_i_in_lobby = false;
                                    play_screen.allow_join_button();

                                    if (my_info.ready_window_open)
                                    {
                                        //close ready window
                                    }

                                    if (my_info.lobby_window_open)
                                    {
                                        //close lobby window
                                        if (active_screen == 4)
                                        {
                                            change_screen(1);
                                        }
                                    }
                                }
                            }
                            update_server_alive(true);
                        }
                        break;

                    case 0x03:
                        List <lobby>  lobbies = new List <lobby>();
                        List <string> data    = udpclient.extract_data(packet);

                        /*
                         * 0 - lobbies count
                         * 1 - [i]lobby name
                         * 2 - [i]lobby status
                         * 3 - [i]lobby map
                         * 4 - [i]lobby players
                         * 5 - [i]lobby score
                         * 6 - [i]lobby avg_elo
                         * 7 - [i]lobby id
                         */
                        int offset = 1;
                        for (int i = 0; i <= int.Parse(data[0]) - 1; i++)
                        {
                            lobby temp_lobby = new lobby();
                            temp_lobby.name    = data[offset];
                            temp_lobby.status  = data[offset + 1];
                            temp_lobby.map     = data[offset + 2];
                            temp_lobby.players = data[offset + 3];
                            temp_lobby.score   = data[offset + 4];
                            if (data[offset + 5] == "-nan")
                            {
                                temp_lobby.avg_elo = "-";
                            }
                            else
                            {
                                temp_lobby.avg_elo = Math.Round(float.Parse(data[offset + 5], CultureInfo.InvariantCulture.NumberFormat), 3).ToString();
                            }

                            temp_lobby.id = int.Parse(data[offset + 6]);
                            lobbies.Add(temp_lobby);
                            offset += 7;
                        }

                        play_screen.update_lobby_list(lobbies);
                        break;

                    case 0x05:
                        if (packet[1] == 0x01)
                        {
                            // you're already in lobby
                            c_msgbox.show_msg(false, "Sa oled juba kuskil lobbis!");
                        }

                        if (packet[1] == 0x02)
                        {
                            //lobby is full
                            c_msgbox.show_msg(false, "See lobby on täis!");
                        }

                        if (packet[1] == 0x03)
                        {
                            // lobby does not accept players
                            c_msgbox.show_msg(false, "See lobby ei võta enam uusi mängijaid vastu!");
                        }

                        if (packet[1] == 0xFF)
                        {
                            // success
                            play_screen.allow_leave_button();
                            //c_msgbox.show_msg(false, "Sa liitusid lobbiga!");
                        }
                        break;

                    case 0x06:
                        //ready
                        if (packet[1] == 0xFF)
                        {
                            ready_screen.im_ready();
                        }
                        break;

                    case 0x08:
                        home_screen.update_clients_online_numer(udpclient.extract_data(packet)[0]);
                        break;

                    case 0x09:
                        List <string> players_data = udpclient.extract_data(packet);
                        play_screen.show_players(players_data[0], players_data[1]);
                        break;

                    case 0x10:
                        // leave lobby
                        if (packet[1] == 0x01)
                        {
                            // Player is actually not in lobby
                        }

                        if (packet[1] == 0x02)
                        {
                            // You cannot leave lobby anymore
                        }

                        if (packet[1] == 0x03)
                        {
                            // You are not in THIS lobby
                        }

                        if (packet[1] == 0xFF)
                        {
                            my_info.am_i_in_lobby = false;
                            my_info.am_i_ready    = false;
                            play_screen.allow_join_button();
                            c_msgbox.show_msg(false, "Sa lahkusid lobbist!");
                        }
                        break;

                    case 0x11:
                        // update ready time
                        //MessageBox.Show("timeleft: " + udpclient.extract_data(packet)[0]);
                        ready_screen.update_ready_time(udpclient.extract_data(packet)[0]);
                        break;

                    case 0x12:
                        // notice 0x01 - open ready screen
                        // 0x02 - You failed to ready up
                        if (packet[1] == 0x01)
                        {
                            my_info.ready_window_open = true;
                            open_ready_screen();
                        }

                        if (packet[1] == 0x02)
                        {
                            if (my_info.ready_window_open)
                            {
                                close_ready_screen();
                                c_msgbox.show_msg(false, "Sa ei jõudnud valmis vajutada!");
                            }
                        }
                        break;

                    case 0x25:
                        home_screen.update_clients_list(udpclient.extract_data(packet));
                        break;

                    case 0x27:
                        paint_my_profile_picture(udpclient.extract_data(packet)[0]);
                        break;
                    }
                }
                Thread.Sleep(1);
            }
        }