示例#1
0
        private void try_login()
        {
            try
            {
                if (username_input.Text == "")
                {
                    throw new Exception("Sisesta kasutajanimi");
                }

                if (password_input.Text == "")
                {
                    throw new Exception("Sisesta parool");
                }

                network udpcon = new network();

                if (udpcon.connect_to_server())
                {
                    // Get sha512 password
                    string sha512_password = "";

                    if (Properties.Settings.Default.remember_me)
                    {
                        sha512_password = Properties.Settings.Default.sha512_pw;
                    }
                    else
                    {
                        UnicodeEncoding UE         = new UnicodeEncoding();
                        byte[]          message    = UE.GetBytes(password_input.Text);
                        SHA512Managed   hashString = new SHA512Managed();

                        byte[] hashValue = hashString.ComputeHash(message);
                        foreach (byte x in hashValue)
                        {
                            sha512_password += String.Format("{0:x2}", x);
                        }
                    }


                    // Let's start building the packet
                    List <string> login_packet = new List <string>();
                    string        version      = Properties.Settings.Default.version.ToString();
                    //Clipboard.SetText(sha512_password);
                    if (version.Contains(","))
                    {
                        version = version.Replace(',', '.');
                    }

                    login_packet.Add(username_input.Text.ToLower());
                    login_packet.Add(sha512_password);

                    login_packet.Add(version);
                    login_packet.Add(get_hw_id());

                    // Send login packet and recieve response
                    byte[] login_response = udpcon.send_and_recieve(0x02, login_packet);

                    if (login_response[0] == 0xFA)
                    {
                        // we have failed login attempt
                        switch (login_response[1])
                        {
                        case 0x01:
                            throw new Exception("Tundmatu veateade!");

                        case 0x02:
                            throw new Exception("Sinu kliendi versioon on liiga vana!");

                        case 0x03:
                            throw new Exception("Vale kasutajanimi või parool!");

                        case 0x04:
                            throw new Exception("Kasutaja on juba sisse loginud. Juhul kui Sinu ühendus aegus, oota 2min!");

                        case 0x05:
                            List <string> ban_info = udpcon.extract_data(login_response);
                            throw new Exception("Sa oled banned.\nPõhjus: " + ban_info[0] + "\nKestab kuni: " + ban_info[1]);

                        case 0x06:
                            throw new Exception("Serveriga ühenduse loomine ebaõnnestus!");
                        }
                    }

                    if (login_response[0] == 0xFF)
                    {
                        // Login was successful
                        List <string> recieved_data = udpcon.extract_data(login_response);
                        steamid = recieved_data[0];
                        string password = recieved_data[1];
                        s_hash = long.Parse(recieved_data[2]);

                        if (password != sha512_password)
                        {
                            List <string> abuse_data = new List <string>();
                            abuse_data.Add("Passwords do not match at user-side after getting 'ok'");
                            //main_client.send_data(0x16, abuseData);
                        }
                        else
                        {
                            if (remember_me.Checked)
                            {
                                string keyName = @"HKEY_CURRENT_USER\SOFTWARE\everest\Gather";
                                Registry.SetValue(keyName, "username", username_input.Text);
                                Registry.SetValue(keyName, "password", sha512_password);
                                Registry.SetValue(keyName, "remember_me", true);
                            }
                            else
                            {
                                string keyName = @"HKEY_CURRENT_USER\SOFTWARE\everest\Gather";
                                Registry.SetValue(keyName, "username", "");
                                Registry.SetValue(keyName, "password", "");
                                Registry.SetValue(keyName, "remember_me", false);
                            }

                            // initialize new window and give refrence to connection and this form
                            main_hub_scr main_window = new main_hub_scr(this, udpcon);
                            main_window.Show();
                            this.Hide();
                            //throw new Exception("LOGIN OK");
                        }
                    }

                    //c_msgbox.show_msg(false, "See funktsioon ei ole valmis veel!\nSinu hw_id: " + get_hw_id());
                }
                else
                {
                    c_msgbox.show_msg(true, "Serveriga ühenduse loomine ebaõnnestus!");
                }
            }
            catch (Exception ex)
            {
                c_msgbox.show_msg(true, ex.Message);
            }
        }
示例#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);
            }
        }