public void isLoggedIn()
    {
        checking = true;
        LauncherGUI.CheckForInternetConnection();
        if (!LauncherGUI.internetConnection)
        {
            GameStateManager.loggedIn            = false;
            LauncherGUI.disconnected             = true;
            GameStateManager.RequireDisconnexion = true;
            checking = false;
            return;
        }
        using (WebClient wb = new WebClient())
        {
            NameValueCollection data = new NameValueCollection();

            data["id"]        = GameStateManager.Login;
            data["connectid"] = GameStateManager.connectionID;
            data["mode"]      = "is";

            byte[] response = wb.UploadValues(MainMenu.url, "POST", data);
            using (MD5 md5Hash = MD5.Create())
            {
                if (!Signup.VerifyMd5Hash(md5Hash, "true", System.Text.Encoding.UTF8.GetString(response)))
                {
                    GameStateManager.loggedIn            = false;
                    LauncherGUI.disconnected             = true;
                    GameStateManager.RequireDisconnexion = true;
                }
            }
        }
        checking = false;
    }
Beispiel #2
0
    public void activateKey()
    {
        using (WebClient wb = new WebClient())
        {
            NameValueCollection data = new NameValueCollection();


            data["id"]   = GameStateManager.Login;
            data["psw"]  = GameStateManager.Password;
            data["key"]  = key;
            data["mode"] = "activate";

            byte[] response = wb.UploadValues(MainMenu.url, "POST", data);
            using (MD5 md5Hash = MD5.Create())
            {
                if (GameStateManager.loggedIn && Signup.VerifyMd5Hash(md5Hash, "ok", System.Text.Encoding.UTF8.GetString(response)))
                {
                    GameStateManager.version = GameVersion.VIP;
                    activateMode             = false;
                }
                else if (GameStateManager.loggedIn && Signup.VerifyMd5Hash(md5Hash, "badUser", System.Text.Encoding.UTF8.GetString(response)))
                {
                    keyFailed     = true;
                    keyMessage    = "Account already activated!";
                    lastKeyFailed = Time.time;
                }
                else if (GameStateManager.loggedIn && Signup.VerifyMd5Hash(md5Hash, "badLogin", System.Text.Encoding.UTF8.GetString(response)))
                {
                    keyFailed     = true;
                    keyMessage    = "Invalid user!";
                    lastKeyFailed = Time.time;
                }
                else if (GameStateManager.loggedIn && Signup.VerifyMd5Hash(md5Hash, "badKey", System.Text.Encoding.UTF8.GetString(response)))
                {
                    keyFailed     = true;
                    keyMessage    = "Invalid key!";
                    lastKeyFailed = Time.time;
                }
                else
                {
                    Debug.Log(System.Text.Encoding.UTF8.GetString(response));
                    keyFailed     = true;
                    keyMessage    = "Internal error!";
                    lastKeyFailed = Time.time;
                }
            }
        }
    }
Beispiel #3
0
    public GameVersion checkVersion()
    {
        using (WebClient wb = new WebClient())
        {
            NameValueCollection data = new NameValueCollection();

            data["id"]   = GameStateManager.Login;
            data["psw"]  = GameStateManager.Password;
            data["mode"] = "vip";

            byte[] response = wb.UploadValues(MainMenu.url, "POST", data);
            using (MD5 md5Hash = MD5.Create())
            {
                if (Signup.VerifyMd5Hash(md5Hash, "vip", System.Text.Encoding.UTF8.GetString(response)))
                {
                    return(GameVersion.VIP);
                }
                return(GameVersion.FREE);
            }
        }
    }
Beispiel #4
0
    protected override void OnMenuGUI()
    {
        Screen.lockCursor = false;
        Cursor.visible    = true;

        GUIStyle centeredStyle = new GUIStyle(GUI.skin.label);

        centeredStyle.alignment        = TextAnchor.MiddleCenter;
        centeredStyle.normal.textColor = Color.red;

        if (loginFailed && Time.time - lastLoginFailed < 5f)
        {
            GUILayout.Label(failedMessage, centeredStyle, GUILayout.Width(490));
        }
        else if (Time.time - lastLoginFailed >= 5f)
        {
            loginFailed = false;
        }

        if (!internetConnection)
        {
            failedMessage = "No internet connection";
            loginFailed   = true;

            if (GUILayout.Button("Play offline", GUILayout.Width(490)))
            {
                SwitchTo <MainMenu>();
            }
        }
        else
        {
            if (disconnected)
            {
                disconnected = false;
                OnDisconnected();
            }
            else if (GameStateManager.loggedIn)
            {
                SwitchTo <MainMenu>();
            }

            GUILayout.BeginHorizontal(GUILayout.Width(490));
            GUILayout.Label("Login: "******"Password: "******"Signup", GUILayout.ExpandWidth(true)))
            {
                SwitchTo <Signup>();
            }


            if (GameStateManager.Password != "" && GameStateManager.Login != "")
            {
                if (GUILayout.Button("Login", GUILayout.Width(245)))
                {
                    confirm = true;
                }

                if (confirm)
                {
                    RegexUtilities rg = new RegexUtilities();
                    confirm = false;

                    using (WebClient wb = new WebClient())
                    {
                        string hashString = GameStateManager.Password;
                        if (hashString != startPassword)
                        {
                            isHashNeeded = true;
                        }
                        NameValueCollection data = new NameValueCollection();
                        if (isHashNeeded)
                        {
                            hashString = Signup.HashString(GameStateManager.Password);
                        }

                        data["id"]   = GameStateManager.Login;
                        data["psw"]  = hashString;
                        data["mode"] = "in";

                        byte[] response = wb.UploadValues(MainMenu.url, "POST", data);
                        using (MD5 md5Hash = MD5.Create())
                        {
                            if (!Signup.VerifyMd5Hash(md5Hash, "no", System.Text.Encoding.UTF8.GetString(response)))
                            {
                                GameStateManager.connectionID = System.Text.Encoding.UTF8.GetString(response);
                                GameStateManager.loggedIn     = true;
                                GameStateManager.Password     = hashString;
                                GameStateManager.startProcess = true;
                                GameStateManager.version      = checkVersion();
                                PlayerLogs pl = new PlayerLogs();
                                pl.Login    = GameStateManager.Login;
                                pl.Password = GameStateManager.Password;
                                pl.SerializeLogs();
                                SwitchTo <MainMenu>();
                            }
                            else
                            {
                                loginFailed     = true;
                                failedMessage   = "Login failed";
                                lastLoginFailed = Time.time;
                            }
                        }
                    }
                }
            }
            GUILayout.EndHorizontal();
        }
    }