Пример #1
0
        public SetupAppObj SetupApplication(string prevToolVersion, string newToolVersion, bool throwException)
        {
            SetupAppObj returnObj = new SetupAppObj();
            Service     myService = null;

            try
            {
                myService = new Service();
                GetValidWebServiceUrl(true);
                myService.Url             = _currentWebServiceUrl.Url;
                myService.AuthHeaderValue = _soapHeader;
                string retValue = myService.SetupApplication((Guid)_soapHeader.ToolId, (Guid)_soapHeader.ApplicationKey, prevToolVersion, newToolVersion);
                returnObj = SerializeDeserializeObject.DeserializeObject <SetupAppObj>(retValue);
            }
            catch (Exception ex)
            {
                if (throwException)
                {
                    throw ex;
                }
            }
            finally
            {
                if (myService != null)
                {
                    myService.Dispose();
                }
                myService = null;
            }
            return(returnObj);
        }
Пример #2
0
        void bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            bool knownException = false;

            _celestosUserName = CelestosLogintextBox.Text.Trim();
            _celestosPassword = CelestosPasswordtextBox.Text;
            OgameServiceV1Call webServiceCall = new OgameServiceV1Call(_toolId, "", _applicationId, _celestosUserName, _celestosPassword, null);

            try
            {
                SetupAppObj returnObj = webServiceCall.SetupApplication(_prevToolVersion, _newToolVersion, true);

                if (!returnObj.Error)
                {
                    // _celestosUserId = returnObj.UserId;

                    if (returnObj.IsToolValid && returnObj.IsUserAllowedToUseThisTool)
                    {
                        if (!string.IsNullOrEmpty(returnObj.CommunityData))
                        {
                            try
                            {
                                _userCommunityList = SerializeDeserializeObject.DeserializeObject <List <GF.BrowserGame.Schema.Serializable.Community> >(returnObj.CommunityData);
                            }
                            catch { }

                            if (_userCommunityList != null && _userCommunityList.Count > 0)
                            {
                                e.Result = "Valid credentials";
                                return;
                            }
                        }
                        knownException = true;
                        throw new Exception("Your credentials are valid but unfortunately you have not been allocated to any universes!\r\n\r\nContact your game administrator for more information.");
                    }
                    else if (!returnObj.IsToolValid)
                    {
                        knownException = true;
                        throw new Exception("Your credentials are valid but unfortunately this tool is not currently active or your version is expired!\r\n\r\nDownload a new version or contact an administrator for more information.");
                    }
                    else if (!returnObj.IsUserAllowedToUseThisTool)
                    {
                        knownException = true;
                        throw new Exception("Your credentials are valid but unfortunately you are not allowed to use this tool!\r\n\r\nContact an administrator for more information.");
                    }
                }
                else
                {
                    knownException = true;
                    throw new Exception("Your credentials are valid but unfortunately something went wrong while downloading your account details!\r\n\r\nContact an administrator for more information.");
                }
            }
            catch (SoapException soapEx)
            {
                if (soapEx.Message.Contains("account is not approved"))
                {
                    e.Result = "Authentication has failed because your account is not approved.\r\n\r\nContact an administrator for more information";
                }
                else if (soapEx.Message.Contains("account is locked"))
                {
                    e.Result = "Authentication has failed because your account is locked.\r\n\r\nContact an administrator for more information";
                }
                else if (soapEx.Message.Contains("database problem"))
                {
                    throw new Exception("Network");
                }
                else
                {
                    e.Result = "Wrong credentials";
                }
            }
            catch (Exception ex)
            {
                if (!knownException || ex.Message.Equals("all webservices are down"))
                {
                    throw new Exception("Network");
                }
                else
                {
                    throw ex;
                }
            }
        }
Пример #3
0
        public string SetupApplication(Guid toolId, Guid applicationKey, string prevToolVersion, string newToolVersion)
        {
            Guid userId = AuthenticateClient("SetupApplication");

            SetupAppObj returnObj = new SetupAppObj();

            try
            {
                // Link user to the application
                WebServiceDAL.LinkUserToApplication(applicationKey, userId);
                WebServiceDAL.UpgradeApplicationVersion(toolId, applicationKey, userId, prevToolVersion, newToolVersion);

                returnObj.IsApplicationUserValid = WebServiceDAL.IsApplicationUserValid(applicationKey, userId);
                returnObj.ToolLatestVersion      = WebServiceDAL.GetLatestToolVersion(toolId);
                returnObj.IsToolValid            = WebServiceDAL.IsToolValid(toolId, newToolVersion);

                if (returnObj.IsApplicationUserValid && returnObj.IsToolValid)
                {
                    returnObj.IsUserAllowedToUseThisTool = WebServiceDAL.IsUserAllowedToUseThisTool(toolId, userId);
                }

                if (returnObj.IsApplicationUserValid && returnObj.IsToolValid && returnObj.IsUserAllowedToUseThisTool)
                {
                    returnObj.CommunityData = WebServiceDAL.GetUserCommunityData(toolId, userId);

                    Int64 encryptionKeyId = WebServiceDAL.GetUserEncryptionKeyId(userId);

                    if (encryptionKeyId == 0)
                    {
                        returnObj.EncryptionKeysExists = WebServiceDAL.CreateUserEncryptionKey(userId, Credentials.Password);
                        encryptionKeyId = WebServiceDAL.GetUserEncryptionKeyId(userId);
                    }
                    else
                    {
                        returnObj.EncryptionKeysExists = true;
                    }

                    if (encryptionKeyId != 0)
                    {
                        DataTable encryptionKeys = WebServiceDAL.GetUserEncryptionKeys(encryptionKeyId);
                        string    serverKey      = "";
                        string    clientKey      = "";
                        try
                        {
                            serverKey = Encryption.DecryptString(UtilitiesBLL.DecryptEncryptionKeyHash(encryptionKeys.Rows[0]["ServerKey"].ToString()), Credentials.Password);
                            clientKey = Encryption.DecryptString(UtilitiesBLL.DecryptEncryptionKeyHash(encryptionKeys.Rows[0]["ClientKey"].ToString()), Credentials.Password);
                        }
                        catch (Exception ex)
                        {
                            WebServiceDAL.StoreException("Webservice", "SetupApplication - Keys encryption", ex);
                            // ServerKey or ClientKey is null/empty or something else went wrong when decrypting
                            // Therefore, create new keys
                            serverKey = UtilitiesBLL.CreateEncryptionKeyHash(Encryption.EncryptString(RandomPassword.Generate(15, 20), Credentials.Password));
                            clientKey = RandomPassword.Generate(15, 20);
                            returnObj.EncryptionKeysExists = WebServiceDAL.UpdateEncryptionKey(encryptionKeyId, serverKey, UtilitiesBLL.CreateEncryptionKeyHash(Encryption.EncryptString(clientKey, Credentials.Password)));
                            // Delete all saved passwords
                            WebServiceDAL.DeleteUserUniverseCredentialsPassword(userId);
                            serverKey = null;
                        }
                        if (!string.IsNullOrEmpty(clientKey))
                        {
                            returnObj.ClientEncryptionKey = clientKey;
                        }
                        else
                        {
                            throw new Exception("ClientKey cannot be empty or null");
                        }

                        if (!string.IsNullOrEmpty(serverKey))
                        {
                            returnObj.CredentialsList = WebServiceDAL.GetUserUniversesAccounts(userId, serverKey, clientKey);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                WebServiceDAL.StoreException("Webservice", "SetupApplication", ex);
                returnObj.Error        = true;
                returnObj.ErrorMessage = ex.Message;
            }

            return(SerializeDeserializeObject.SerializeObject <SetupAppObj>(returnObj));;
        }