Ejemplo n.º 1
0
        private async Task <string> OnHandleServerAccountQuery(JObject obj)
        {
            try
            {
                var account_id = obj["account_id"].ToString();
                if (!string.IsNullOrEmpty(account_id))
                {
                    //角色列表//
                    List <RoleIDSnap> roleList = new List <RoleIDSnap>();
                    using (var accountRoleSnapSave = new MappingReference <AccountRoleSnap>(RPGServerPersistenceManager.TYPE_ACCOUNT_ROLE_SNAP_DATA, account_id, this))
                    {
                        var accountRoleSnap = await accountRoleSnapSave.LoadOrCreateDataAsync(() => new AccountRoleSnap());

                        foreach (var item in accountRoleSnap.roleIDMap)
                        {
                            roleList.Add(item.Value);
                        }
                    }

                    return(CustomResult(true, JsonConvert.SerializeObject(roleList)));
                }
                else
                {
                    return(CustomResult(false, null, "role_name_not_exist"));
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return(CustomResult(false, null, "page_gmt_command_unknown_error"));
            }
        }
Ejemplo n.º 2
0
        public virtual async Task <AccountData> GetOrCreateAccountDataAsync(MappingReference <AccountData> saveAcc, string accountName, string accountToken)
        {
            if (await saveAcc.EnterLockAsync(out var token))
            {
                try
                {
                    var accountData = await saveAcc.LoadOrCreateDataAsync(() =>
                    {
                        var ret   = new AccountData();
                        ret.uuid  = accountName;
                        ret.token = accountToken;
                        return(ret);
                    });

                    return(accountData);
                }
                finally
                {
                    await saveAcc.ExitLockAsync(token);
                }
            }

            return(null);
        }