コード例 #1
0
ファイル: AccountManager.cs プロジェクト: wovencode/OldMMO
        // -------------------------------------------------------------------------------
        // ReqAccountDelete
        // -------------------------------------------------------------------------------
        public MsgAckAccountDelete ReqAccountDelete(MsgReqAccountDelete message, NetworkConnection connection = null)
        {
            int      _nResult = confirmAccountDelete ? Constants.INT_CONFIRM : Constants.INT_FAILURE;
            CAccount cAccount = null;

            if (dictLobby.TryGetValue(connection, out cAccount))
            {
                if (passwordManager.VerifyPassword(message.sPassword, cAccount.sPassword))
                {
                    if (confirmAccountDelete && !cAccount.IsDone)
                    {
                        RequestSecurityCode(cAccount, Constants.AccountActionType.DeleteAccount);
                    }

                    _nResult = AccountDelete(cAccount, connection, false) ? Constants.INT_SUCCESS : _nResult;

                    if (dictLobby.ContainsKey(connection))
                    {
                        dictLobby.Remove(connection);
                    }
                }
                else
                {
                    _nResult = Constants.INT_FAILURE;
                }
            }

            return(new MsgAckAccountDelete {
                nResult = _nResult
            });
        }
コード例 #2
0
ファイル: AccountManager.cs プロジェクト: wovencode/OldMMO
        // -------------------------------------------------------------------------------
        // ReqAccountChangeMail
        // -------------------------------------------------------------------------------
        public MsgAckAccountChangeMail ReqAccountChangeMail(MsgReqAccountChangeMail message, NetworkConnection connection = null)
        {
            int      _nResult = confirmAccountChangeMail ? Constants.INT_CONFIRM : Constants.INT_FAILURE;
            CAccount cAccount = null;

            if (dictLobby.TryGetValue(connection, out cAccount))
            {
                if (
                    !databaseManager.RowExists(DatabaseManager.tableAccounts, DatabaseManager.fieldEmail, message.sMail) &&
                    passwordManager.VerifyPassword(message.sPassword, cAccount.sPassword))
                {
                    if (confirmAccountChangeMail && !cAccount.IsDone)
                    {
                        RequestSecurityCode(cAccount, Constants.AccountActionType.ChangeMail);
                    }
                    else
                    {
                        cAccount.sMail = message.sMail;
                        _nResult       = AccountUpdate(cAccount, connection) ? Constants.INT_SUCCESS : _nResult;
                    }
                }
                else
                {
                    _nResult = Constants.INT_FAILURE;
                }
            }

            return(new MsgAckAccountChangeMail {
                nResult = _nResult
            });
        }
コード例 #3
0
ファイル: AccountManager.cs プロジェクト: wovencode/OldMMO
        // -------------------------------------------------------------------------------
        // ReqCodeConfirm
        // -------------------------------------------------------------------------------
        public MsgAckCodeConfirm ReqCodeConfirm(MsgReqCodeConfirm message, NetworkConnection connection = null)
        {
            bool     _bSuccess = false;
            CAccount cAccount  = AccountLoad(message.sName);

            if (cAccount != null &&
                !cAccount.IsEmpty &&
                cAccount.Action != Constants.AccountActionType.None)
            {
                if (cAccount.ValidateAll((Constants.AccountActionType)message.nAction, message.nCode))
                {
                    cAccount.ConfirmCode();

                    if (dictLobby.ContainsKey(connection))
                    {
                        dictLobby[connection] = cAccount;
                    }

                    _bSuccess = databaseManager.AccountSave(cAccount);
                }
            }

            return(new MsgAckCodeConfirm {
                bSuccess = _bSuccess
            });
        }
コード例 #4
0
ファイル: AccountManager.cs プロジェクト: wovencode/OldMMO
        // -------------------------------------------------------------------------------
        // ReqAccountChangePassword
        // -------------------------------------------------------------------------------
        public MsgAckAccountChangePassword ReqAccountChangePassword(MsgReqAccountChangePassword message, NetworkConnection connection = null)
        {
            int      _nResult = confirmAccountChangePassword ? Constants.INT_CONFIRM : Constants.INT_FAILURE;
            CAccount cAccount = null;

            if (dictLobby.TryGetValue(connection, out cAccount))
            {
                if (passwordManager.VerifyPassword(message.sOldPassword, cAccount.sPassword))
                {
                    if (confirmAccountChangePassword && !cAccount.IsDone)
                    {
                        RequestSecurityCode(cAccount, Constants.AccountActionType.ChangePassword);
                    }
                    else
                    {
                        cAccount.sPassword = passwordManager.CreateHash(message.sNewPassword);
                        _nResult           = AccountUpdate(cAccount, connection) ? Constants.INT_SUCCESS : _nResult;
                    }
                }
                else
                {
                    _nResult = Constants.INT_FAILURE;
                }
            }

            return(new MsgAckAccountChangePassword {
                nResult = _nResult
            });
        }
コード例 #5
0
ファイル: AccountManager.cs プロジェクト: wovencode/OldMMO
        // -------------------------------------------------------------------------------
        // AccountUpdate
        // -------------------------------------------------------------------------------
        public bool AccountUpdate(CAccount cAccount, NetworkConnection connection)
        {
            cAccount.ResetCode(false);

            if (dictLobby.ContainsKey(connection))
            {
                dictLobby[connection] = cAccount;
            }

            return(databaseManager.AccountSave(cAccount));
        }
コード例 #6
0
ファイル: ClientManager.cs プロジェクト: wovencode/OldMMO
        // -------------------------------------------------------------------------------
        // AckAccountLogout
        // -------------------------------------------------------------------------------
        public void AckAccountLogout(MsgAckAccountLogout message, NetworkConnection connection = null)
        {
            string sResult = (message.bSuccess) ? Constants.INT_SUCCESS.ToString() : Constants.INT_FAILURE.ToString();

            if (message.bSuccess)
            {
                clientAccount           = null;
                networkManager.netState = BaseNetworkManager.NetStateType.Handshake;
            }

            DictionaryDoAction("CallbackAccountLogout", new string[] { sResult });
        }
コード例 #7
0
ファイル: AccountManager.cs プロジェクト: wovencode/OldMMO
        // -------------------------------------------------------------------------------
        // ReqAccountLogin
        // -------------------------------------------------------------------------------
        public MsgAckAccountLogin ReqAccountLogin(MsgReqAccountLogin message, NetworkConnection connection = null)
        {
            int      _nResult          = confirmAccountCreate || confirmAccountLogin ? Constants.INT_CONFIRM : Constants.INT_FAILURE;
            int      _nActorsRemaining = actorsPerAccounts;
            CAccount cAccount          = null;

            if (!AccountOnline(connection))
            {
                cAccount = databaseManager.AccountLoad(message.sName);

                if (cAccount != null &&
                    cAccount.IsValid &&
                    passwordManager.VerifyPassword(message.sPassword, cAccount.sPassword))
                {
                    if (cAccount.bConfirmed || !confirmAccountCreate)
                    {
                        if (confirmAccountLogin &&
                            !cAccount.IsDone &&
                            !String.IsNullOrWhiteSpace(cAccount.sMail) &&
                            message.sDeviceId != cAccount.sDeviceId)
                        {
                            RequestSecurityCode(cAccount, Constants.AccountActionType.LoginAccount);
                            _nResult = Constants.INT_RECONFIRM;
                        }
                        else
                        {
                            dictLobby.Add(connection, cAccount);
                            _nActorsRemaining = AccountActorsRemaining(message.sName);
                            _nResult          = Constants.INT_SUCCESS;
                        }
                    }

                    return(new MsgAckAccountLogin {
                        nResult = _nResult,
                        nActorsRemaining = _nActorsRemaining,
                        sName = cAccount.sName,
                        sMail = cAccount.sMail,
                        bBanned = cAccount.bBanned,
                        bDeleted = cAccount.bDeleted,
                        bConfirmed = cAccount.bConfirmed
                    });
                }
                else
                {
                    _nResult = Constants.INT_FAILURE;
                }
            }

            return(new MsgAckAccountLogin {
                nResult = _nResult
            });
        }
コード例 #8
0
ファイル: AccountManager.cs プロジェクト: wovencode/OldMMO
        // ===============================================================================
        // ACCOUNT RELATED
        // ===============================================================================

        // -------------------------------------------------------------------------------
        // RequestSecurityCode
        // -------------------------------------------------------------------------------
        public bool RequestSecurityCode(CAccount cAccount, Constants.AccountActionType accountActionType)
        {
            if (cAccount.IsEmpty || accountActionType == Constants.AccountActionType.None)
            {
                return(false);
            }

            int tmpCode = cAccount.GenerateCode(accountActionType);

            mailManager.SendMailSecurityCode(cAccount.sMail, tmpCode);

            return(databaseManager.AccountSave(cAccount));
        }
コード例 #9
0
ファイル: ClientManager.cs プロジェクト: wovencode/OldMMO
        // -------------------------------------------------------------------------------
        // ReqAccountForgotPassword
        // -------------------------------------------------------------------------------
        public void ReqAccountForgotPassword(string[] fields, Action <string[]> callbackFunction)
        {
            DictionaryAddAction(callbackFunction);

            clientAccount = new CAccount();

            clientAccount.sName = fields[0];

            MsgReqAccountForgotPassword message = new MsgReqAccountForgotPassword {
                sName = fields[0]
            };

            networkManager.client.Send(MsgReqAccountForgotPassword.nId, message);
        }
コード例 #10
0
ファイル: AccountManager.cs プロジェクト: wovencode/OldMMO
        // -------------------------------------------------------------------------------
        // ReqActorPlayerDelete
        // -------------------------------------------------------------------------------
        public MsgAckActorPlayerDelete ReqActorPlayerDelete(MsgReqActorPlayerDelete message, NetworkConnection connection = null)
        {
            bool     _bSuccess = false;
            CAccount cAccount  = null;

            if (dictLobby.TryGetValue(connection, out cAccount))
            {
                _bSuccess = ActorPlayerDelete(message.sName, connection);
            }

            return(new MsgAckActorPlayerDelete {
                bSuccess = _bSuccess
            });
        }
コード例 #11
0
ファイル: AccountManager.cs プロジェクト: wovencode/OldMMO
        // -------------------------------------------------------------------------------
        // ReqAccountRegister
        // -------------------------------------------------------------------------------
        public MsgAckAccountRegister ReqAccountRegister(MsgReqAccountRegister message, NetworkConnection connection = null)
        {
            int _nResult = confirmAccountCreate ? Constants.INT_CONFIRM : Constants.INT_SUCCESS;

            CAccount cAccount = null;

            cAccount = TryAccountCreate(message.sName, message.sPassword, message.sMail, message.sDeviceId);

            _nResult = (cAccount != null) ? _nResult : Constants.INT_FAILURE;

            return(new MsgAckAccountRegister {
                nResult = _nResult
            });
        }
コード例 #12
0
ファイル: AccountManager.cs プロジェクト: wovencode/OldMMO
        // -------------------------------------------------------------------------------
        // ReqAccountResendConfirmation
        // -------------------------------------------------------------------------------
        public MsgAckAccountResendConfirmation ReqAccountResendConfirmation(MsgReqAccountResendConfirmation message, NetworkConnection connection = null)
        {
            bool _bSuccess = false;

            CAccount cAccount = AccountLoad(message.sName);

            if (cAccount != null && !cAccount.bConfirmed)
            {
                _bSuccess = RequestSecurityCode(cAccount, Constants.AccountActionType.ConfirmAccount);
            }

            return(new MsgAckAccountResendConfirmation {
                bSuccess = _bSuccess
            });
        }
コード例 #13
0
ファイル: ClientManager.cs プロジェクト: wovencode/OldMMO
        // -------------------------------------------------------------------------------
        // ReqAccountLogin
        // -------------------------------------------------------------------------------
        public void ReqAccountLogin(string[] fields, Action <string[]> callbackFunction)
        {
            DictionaryAddAction(callbackFunction);

            clientAccount = new CAccount();

            clientAccount.sName = fields[0];

            MsgReqAccountLogin message = new MsgReqAccountLogin {
                sName     = fields[0],
                sPassword = Tools.HashPassword(fields[1]),
                sDeviceId = fields[2]
            };

            networkManager.client.Send(MsgReqAccountLogin.nId, message);
        }
コード例 #14
0
ファイル: AccountManager.cs プロジェクト: wovencode/OldMMO
        // ===============================================================================
        // ACTOR RELATED
        // ===============================================================================

        // -------------------------------------------------------------------------------
        // TryActorPlayerCreate
        // -------------------------------------------------------------------------------
        public bool TryActorPlayerCreate(CAccount cAccount, string _sName, string[] fields)
        {
            // Validate Actor Name
            // Check Actors remaining on this account
            if (_sName.validateName() &&
                AccountActorsRemaining(cAccount.sName) > 0)
            {
                // Actor Name does not exist already
                if (!databaseManager.RowExists(DatabaseManager.tableActorPlayers, DatabaseManager.fieldName, _sName))
                {
                    return(ActorPlayerCreate(cAccount, _sName, fields));
                }
            }

            return(false);
        }
コード例 #15
0
ファイル: AccountManager.cs プロジェクト: wovencode/OldMMO
        // -------------------------------------------------------------------------------
        // ActorPlayerCreate
        // -------------------------------------------------------------------------------
        public bool ActorPlayerCreate(CAccount cAccount, string _sName, string[] fields)
        {
            bool bSuccess = false;
            List <TemplateAspect> actorAspects = new List <TemplateAspect>();
            GameObject            actorObject  = null;

            // -- determine the required prefab via the actors aspects
            for (int i = 0; i < fields.Length; ++i)
            {
                TemplateAspect tmpl;

                if (DataManager.dictAspect.TryGetValue(Int32.Parse(fields[i]), out tmpl))
                {
                    actorAspects.Add(tmpl);
                }
                else
                {
                    Debug.LogWarning("Skipped template '" + fields[i] + "' as it was not found in Library.");
                }
            }

            foreach (TemplateAspect aspect in actorAspects)
            {
                if (aspect.actorPrefab)
                {
                    actorObject = Instantiate(aspect.actorPrefab);
                    actorObject.GetComponent <MetaSubsystem>().Init(actorObject, _sName, cAccount.sName);
                    actorObject.GetComponent <AspectSubsystem>().Init(actorObject, actorAspects.ToList());

                    if (String.IsNullOrWhiteSpace(_sName))
                    {
                        actorObject.name = aspect.actorPrefab.name;
                    }
                    else
                    {
                        actorObject.name = _sName;
                    }

                    break;
                }
            }

            bSuccess = databaseManager.ActorPlayerSave(actorObject);
            GameObject.Destroy(actorObject);

            return(bSuccess);
        }
コード例 #16
0
ファイル: AccountManager.cs プロジェクト: wovencode/OldMMO
        // -------------------------------------------------------------------------------
        // ReqActorPlayerList
        // -------------------------------------------------------------------------------
        public MsgAckActorPlayerList ReqActorPlayerList(MsgReqActorPlayerList message, NetworkConnection connection = null)
        {
            bool _bSuccess = false;

            SActorPlayerPreview[] _previews = null;
            CAccount cAccount = null;

            if (dictLobby.TryGetValue(connection, out cAccount))
            {
                _previews = databaseManager.GetActorPlayerPreviews(cAccount.sName);
                _bSuccess = (_previews.Length > 0) ? true : false;
            }

            return(new MsgAckActorPlayerList {
                bSuccess = _bSuccess, sActorPlayerPreviews = _previews
            });
        }
コード例 #17
0
ファイル: DatabaseManager.cs プロジェクト: wovencode/OldMMO
        // -------------------------------------------------------------------------------
        // AccountDelete
        // -------------------------------------------------------------------------------
        public bool AccountDelete(CAccount cAccount, bool hardDelete = false)
        {
            if (cAccount == null)
            {
                return(false);
            }

            if (hardDelete)
            {
                // Delete the account immediately
                return(databaseProvider.DeleteRows(DatabaseManager.tableAccounts, cAccount.sName).Result);
            }
            else
            {
                // Update the account and set 'deleted' to true
                return(databaseProvider.SaveAccount(cAccount.Save()).Result);
            }
        }
コード例 #18
0
ファイル: AccountManager.cs プロジェクト: wovencode/OldMMO
        // -------------------------------------------------------------------------------
        // AccountDelete
        // Soft or hard deletion of the stated account
        // -------------------------------------------------------------------------------
        public bool AccountDelete(CAccount cAccount, NetworkConnection connection, bool hardDelete = false)
        {
            if (cAccount == null)
            {
                return(false);
            }

            if (hardDelete)
            {
                // Delete the account immediately
                return(databaseManager.DeleteRows(DatabaseManager.tableAccounts, cAccount.sName));
            }
            else
            {
                // Update the account and set 'deleted' to true
                cAccount.bDeleted = true;
                return(databaseManager.AccountSave(cAccount));
            }
        }
コード例 #19
0
ファイル: AccountManager.cs プロジェクト: wovencode/OldMMO
        // -------------------------------------------------------------------------------
        // ReqAccountForgotPassword
        // -------------------------------------------------------------------------------
        public MsgAckAccountForgotPassword ReqAccountForgotPassword(MsgReqAccountForgotPassword message, NetworkConnection connection = null)
        {
            int      _nResult = confirmAccountForgotPassword ? Constants.INT_CONFIRM : Constants.INT_FAILURE;
            CAccount cAccount = null;

            if (!dictLobby.TryGetValue(connection, out cAccount))
            {
                cAccount = databaseManager.AccountLoad(message.sName);

                if (cAccount != null && !cAccount.IsEmpty)
                {
                    if (confirmAccountForgotPassword && !cAccount.IsDone)
                    {
                        RequestSecurityCode(cAccount, Constants.AccountActionType.ForgotPassword);
                    }
                    else
                    {
                        int tmpPassword = UnityEngine.Random.Range(1000, 9999);
                        cAccount.sPassword = passwordManager.CreateHash(Tools.HashPassword(tmpPassword.ToString()));
                        mailManager.SendMailForgotPassword(cAccount.sMail, tmpPassword);
                        _nResult = AccountUpdate(cAccount, connection) ? Constants.INT_SUCCESS : _nResult;
                    }
                }
                else
                {
                    _nResult = Constants.INT_FAILURE;
                }
            }
            else
            {
                _nResult = Constants.INT_FAILURE;
            }


            return(new MsgAckAccountForgotPassword {
                nResult = _nResult
            });
        }
コード例 #20
0
ファイル: AccountManager.cs プロジェクト: wovencode/OldMMO
        // -------------------------------------------------------------------------------
        // AccountCreate
        // Creates a new account with the given information
        // -------------------------------------------------------------------------------
        public CAccount AccountCreate(string _sName, string _sPassword, string _sMail, string _sDeviceId)
        {
            CAccount cAccount = new CAccount();

            cAccount.sName     = _sName;
            cAccount.sPassword = passwordManager.CreateHash(_sPassword);
            cAccount.sMail     = _sMail;
            cAccount.sDeviceId = _sDeviceId;

            // Now we:
            // a. Save Account + generate a security code and send via email (if required)
            // b. Or simply save the account
            if (confirmAccountCreate)
            {
                RequestSecurityCode(cAccount, Constants.AccountActionType.ConfirmAccount);
            }
            else
            {
                databaseManager.AccountSave(cAccount);
            }

            return(cAccount);
        }
コード例 #21
0
ファイル: ClientManager.cs プロジェクト: wovencode/OldMMO
        // -------------------------------------------------------------------------------
        // AckAccountLogin
        // -------------------------------------------------------------------------------
        public void AckAccountLogin(MsgAckAccountLogin message, NetworkConnection connection = null)
        {
            string sResult = message.nResult.ToString();

            if (message.nResult == Constants.INT_SUCCESS)
            {
                sResult = Constants.INT_SUCCESS.ToString();

                clientAccount = new CAccount();

                clientAccount.sName      = message.sName;
                clientAccount.sMail      = message.sMail;
                clientAccount.bBanned    = message.bBanned;
                clientAccount.bDeleted   = message.bDeleted;
                clientAccount.bConfirmed = message.bConfirmed;

                actorsRemaining = message.nActorsRemaining;

                networkManager.netState = BaseNetworkManager.NetStateType.InLobby;
            }

            DictionaryDoAction("CallbackLogin", new string[] { sResult });
        }
コード例 #22
0
ファイル: DatabaseManager.cs プロジェクト: wovencode/OldMMO
        // ===============================================================================
        // ACCOUNT RELATED
        // ===============================================================================

        // -------------------------------------------------------------------------------
        // AccountLoad
        // -------------------------------------------------------------------------------
        public CAccount AccountLoad(string sName)
        {
            CAccount cAccount = null;

            if (String.IsNullOrWhiteSpace(sName))
            {
                return(cAccount);
            }

            if (!String.IsNullOrWhiteSpace(sName) &&
                databaseProvider.RowExists(tableAccounts, fieldName, sName).Result)
            {
                BaseDataTable data = databaseProvider.LoadAccount(sName).Result;

                if (data != null)
                {
                    cAccount = new CAccount();
                    cAccount.Load(data);
                }
            }

            return(cAccount);
        }
コード例 #23
0
ファイル: AccountManager.cs プロジェクト: wovencode/OldMMO
        // -------------------------------------------------------------------------------
        // TryAccountCreate
        // Tries to create a new account (validating all required data etc.)
        // -------------------------------------------------------------------------------
        public CAccount TryAccountCreate(string _sName, string _sPassword, string _sMail, string _sDeviceId)
        {
            CAccount cAccount = null;

            // Validate Name and Password server side again
            // We only validate the eMail if its required to confirm the account, otherwise
            // the eMail is optional.
            if (_sName.validateName() &&
                !String.IsNullOrWhiteSpace(_sPassword) &&
                (!confirmAccountCreate || _sMail.validateEmail()))
            {
                // Check if:
                // a. Account Name does not exist already
                // b. eMail is not in use by another account already
                if (!databaseManager.RowExists(DatabaseManager.tableAccounts, DatabaseManager.fieldName, _sName) &&
                    !databaseManager.RowExists(DatabaseManager.tableAccounts, DatabaseManager.fieldEmail, _sMail))
                {
                    return(AccountCreate(_sName, _sPassword, _sMail, _sDeviceId));
                }
            }

            return(cAccount);
        }
コード例 #24
0
ファイル: DatabaseManager.cs プロジェクト: wovencode/OldMMO
 // -------------------------------------------------------------------------------
 // AccountSave
 // -------------------------------------------------------------------------------
 public bool AccountSave(CAccount cAccount)
 {
     return(databaseProvider.SaveAccount(cAccount.Save()).Result);
 }