Core/DBLayer: Add nicer api for SQLQueryHolders
Port From (https://github.com/TrinityCore/TrinityCore/commit/d5dcf02196e30c932c7a25c3975a91a0fe1ccd50)
This commit is contained in:
@@ -162,13 +162,13 @@ namespace Framework.Database
|
|||||||
return new QueryCallback(result);
|
return new QueryCallback(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<SQLQueryHolder<R>> DelayQueryHolder<R>(SQLQueryHolder<R> holder)
|
public SQLQueryHolderCallback<R> DelayQueryHolder<R>(SQLQueryHolder<R> holder)
|
||||||
{
|
{
|
||||||
SQLQueryHolderTask<R> task = new(holder);
|
SQLQueryHolderTask<R> task = new(holder);
|
||||||
// Store future result before enqueueing - task might get already processed and deleted before returning from this method
|
// Store future result before enqueueing - task might get already processed and deleted before returning from this method
|
||||||
Task<SQLQueryHolder<R>> result = task.GetFuture();
|
Task<SQLQueryHolder<R>> result = task.GetFuture();
|
||||||
_queue.Push(task);
|
_queue.Push(task);
|
||||||
return result;
|
return new(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadPreparedStatements()
|
public void LoadPreparedStatements()
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@@ -74,4 +75,31 @@ namespace Framework.Database
|
|||||||
|
|
||||||
public Task<SQLQueryHolder<R>> GetFuture() { return m_result.Task; }
|
public Task<SQLQueryHolder<R>> GetFuture() { return m_result.Task; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class SQLQueryHolderCallback<R> : ISqlCallback
|
||||||
|
{
|
||||||
|
Task<SQLQueryHolder<R>> m_future;
|
||||||
|
Action<SQLQueryHolder<R>> m_callback;
|
||||||
|
|
||||||
|
public SQLQueryHolderCallback(Task<SQLQueryHolder<R>> future)
|
||||||
|
{
|
||||||
|
m_future = future;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AfterComplete(Action<SQLQueryHolder<R>> callback)
|
||||||
|
{
|
||||||
|
m_callback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool InvokeIfReady()
|
||||||
|
{
|
||||||
|
if (m_future != null && m_future.Wait(0))
|
||||||
|
{
|
||||||
|
m_callback(m_future.Result);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ namespace Game
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_charEnumCallback = DB.Characters.DelayQueryHolder(holder);
|
AddQueryHolderCallback(DB.Characters.DelayQueryHolder(holder)).AfterComplete(result => HandleCharEnum((EnumCharactersQueryHolder)result));
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleCharEnum(EnumCharactersQueryHolder holder)
|
void HandleCharEnum(EnumCharactersQueryHolder holder)
|
||||||
@@ -148,8 +148,8 @@ namespace Game
|
|||||||
HandleCharEnum(holder);
|
HandleCharEnum(holder);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_charEnumCallback = DB.Characters.DelayQueryHolder(holder);
|
AddQueryHolderCallback(DB.Characters.DelayQueryHolder(holder)).AfterComplete(result => HandleCharEnum((EnumCharactersQueryHolder)result));
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleCharUndeleteEnumCallback(SQLResult result)
|
void HandleCharUndeleteEnumCallback(SQLResult result)
|
||||||
@@ -723,7 +723,7 @@ namespace Game
|
|||||||
|
|
||||||
SendPacket(new ResumeComms(ConnectionType.Instance));
|
SendPacket(new ResumeComms(ConnectionType.Instance));
|
||||||
|
|
||||||
_charLoginCallback = DB.Characters.DelayQueryHolder(holder);
|
AddQueryHolderCallback(DB.Characters.DelayQueryHolder(holder)).AfterComplete(holder => HandlePlayerLogin((LoginQueryHolder)holder));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HandlePlayerLogin(LoginQueryHolder holder)
|
public void HandlePlayerLogin(LoginQueryHolder holder)
|
||||||
|
|||||||
@@ -5371,8 +5371,6 @@ namespace Game.Maps
|
|||||||
if (i_data == null)
|
if (i_data == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
i_data.Initialize();
|
|
||||||
|
|
||||||
if (load)
|
if (load)
|
||||||
{
|
{
|
||||||
// @todo make a global storage for this
|
// @todo make a global storage for this
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ using Framework.Realm;
|
|||||||
using Game.Accounts;
|
using Game.Accounts;
|
||||||
using Game.BattleGrounds;
|
using Game.BattleGrounds;
|
||||||
using Game.BattlePets;
|
using Game.BattlePets;
|
||||||
|
using Game.Chat;
|
||||||
using Game.Entities;
|
using Game.Entities;
|
||||||
using Game.Guilds;
|
using Game.Guilds;
|
||||||
using Game.Maps;
|
using Game.Maps;
|
||||||
@@ -33,8 +34,6 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Game.Chat;
|
|
||||||
|
|
||||||
namespace Game
|
namespace Game
|
||||||
{
|
{
|
||||||
@@ -603,7 +602,7 @@ namespace Game
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool DisallowHyperlinksAndMaybeKick(string str)
|
public bool DisallowHyperlinksAndMaybeKick(string str)
|
||||||
{
|
{
|
||||||
if (!str.Contains('|'))
|
if (!str.Contains('|'))
|
||||||
@@ -616,7 +615,7 @@ namespace Game
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendNotification(CypherStrings str, params object[] args)
|
public void SendNotification(CypherStrings str, params object[] args)
|
||||||
{
|
{
|
||||||
SendNotification(Global.ObjectMgr.GetCypherString(str), args);
|
SendNotification(Global.ObjectMgr.GetCypherString(str), args);
|
||||||
@@ -705,26 +704,7 @@ namespace Game
|
|||||||
{
|
{
|
||||||
_queryProcessor.ProcessReadyCallbacks();
|
_queryProcessor.ProcessReadyCallbacks();
|
||||||
_transactionCallbacks.ProcessReadyCallbacks();
|
_transactionCallbacks.ProcessReadyCallbacks();
|
||||||
|
_queryHolderProcessor.ProcessReadyCallbacks();
|
||||||
if (_realmAccountLoginCallback != null && _realmAccountLoginCallback.IsCompleted && _accountLoginCallback != null && _accountLoginCallback.IsCompleted)
|
|
||||||
{
|
|
||||||
InitializeSessionCallback(_realmAccountLoginCallback.Result, _accountLoginCallback.Result);
|
|
||||||
_realmAccountLoginCallback = null;
|
|
||||||
_accountLoginCallback = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// HandlePlayerLoginOpcode
|
|
||||||
if (_charLoginCallback != null && _charLoginCallback.IsCompleted)
|
|
||||||
{
|
|
||||||
HandlePlayerLogin((LoginQueryHolder)_charLoginCallback.Result);
|
|
||||||
_charLoginCallback = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_charEnumCallback != null && _charEnumCallback.IsCompleted)
|
|
||||||
{
|
|
||||||
HandleCharEnum((EnumCharactersQueryHolder)_charEnumCallback.Result);
|
|
||||||
_charEnumCallback = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TransactionCallback AddTransactionCallback(TransactionCallback callback)
|
TransactionCallback AddTransactionCallback(TransactionCallback callback)
|
||||||
@@ -732,11 +712,16 @@ namespace Game
|
|||||||
return _transactionCallbacks.AddCallback(callback);
|
return _transactionCallbacks.AddCallback(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SQLQueryHolderCallback<R> AddQueryHolderCallback<R>(SQLQueryHolderCallback<R> callback)
|
||||||
|
{
|
||||||
|
return (SQLQueryHolderCallback<R>)_queryHolderProcessor.AddCallback(callback);
|
||||||
|
}
|
||||||
|
|
||||||
public bool CanAccessAlliedRaces()
|
public bool CanAccessAlliedRaces()
|
||||||
{
|
{
|
||||||
return GetAccountExpansion() >= Expansion.BattleForAzeroth;
|
return GetAccountExpansion() >= Expansion.BattleForAzeroth;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitWarden(BigInteger k)
|
void InitWarden(BigInteger k)
|
||||||
{
|
{
|
||||||
if (_os == "Win")
|
if (_os == "Win")
|
||||||
@@ -786,11 +771,25 @@ namespace Game
|
|||||||
AccountInfoQueryHolder holder = new();
|
AccountInfoQueryHolder holder = new();
|
||||||
holder.Initialize(GetAccountId(), GetBattlenetAccountId());
|
holder.Initialize(GetAccountId(), GetBattlenetAccountId());
|
||||||
|
|
||||||
_realmAccountLoginCallback = DB.Characters.DelayQueryHolder(realmHolder);
|
AccountInfoQueryHolderPerRealm characterHolder = null;
|
||||||
_accountLoginCallback = DB.Login.DelayQueryHolder(holder);
|
AccountInfoQueryHolder loginHolder = null;
|
||||||
|
|
||||||
|
AddQueryHolderCallback(DB.Characters.DelayQueryHolder(realmHolder)).AfterComplete(result =>
|
||||||
|
{
|
||||||
|
characterHolder = (AccountInfoQueryHolderPerRealm)result;
|
||||||
|
if (loginHolder != null && characterHolder != null)
|
||||||
|
InitializeSessionCallback(loginHolder, characterHolder);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddQueryHolderCallback(DB.Login.DelayQueryHolder(holder)).AfterComplete(result =>
|
||||||
|
{
|
||||||
|
loginHolder = (AccountInfoQueryHolder)result;
|
||||||
|
if (loginHolder != null && characterHolder != null)
|
||||||
|
InitializeSessionCallback(loginHolder, characterHolder);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitializeSessionCallback(SQLQueryHolder<AccountInfoQueryLoad> realmHolder, SQLQueryHolder<AccountInfoQueryLoad> holder)
|
void InitializeSessionCallback(SQLQueryHolder<AccountInfoQueryLoad> holder, SQLQueryHolder<AccountInfoQueryLoad> realmHolder)
|
||||||
{
|
{
|
||||||
LoadAccountData(realmHolder.GetResult(AccountInfoQueryLoad.GlobalAccountDataIndexPerRealm), AccountDataTypes.GlobalCacheMask);
|
LoadAccountData(realmHolder.GetResult(AccountInfoQueryLoad.GlobalAccountDataIndexPerRealm), AccountDataTypes.GlobalCacheMask);
|
||||||
LoadTutorialsData(realmHolder.GetResult(AccountInfoQueryLoad.TutorialsIndexPerRealm));
|
LoadTutorialsData(realmHolder.GetResult(AccountInfoQueryLoad.TutorialsIndexPerRealm));
|
||||||
@@ -898,7 +897,7 @@ namespace Game
|
|||||||
else
|
else
|
||||||
return (uint)movementTime;
|
return (uint)movementTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Locale GetSessionDbcLocale() { return m_sessionDbcLocale; }
|
public Locale GetSessionDbcLocale() { return m_sessionDbcLocale; }
|
||||||
public Locale GetSessionDbLocaleIndex() { return m_sessionDbLocaleIndex; }
|
public Locale GetSessionDbLocaleIndex() { return m_sessionDbLocaleIndex; }
|
||||||
|
|
||||||
@@ -922,7 +921,7 @@ namespace Game
|
|||||||
// Packets cooldown
|
// Packets cooldown
|
||||||
public long GetCalendarEventCreationCooldown() { return _calendarEventCreationCooldown; }
|
public long GetCalendarEventCreationCooldown() { return _calendarEventCreationCooldown; }
|
||||||
public void SetCalendarEventCreationCooldown(long cooldown) { _calendarEventCreationCooldown = cooldown; }
|
public void SetCalendarEventCreationCooldown(long cooldown) { _calendarEventCreationCooldown = cooldown; }
|
||||||
|
|
||||||
// Battle Pets
|
// Battle Pets
|
||||||
public BattlePetMgr GetBattlePetMgr() { return _battlePetMgr; }
|
public BattlePetMgr GetBattlePetMgr() { return _battlePetMgr; }
|
||||||
public CollectionMgr GetCollectionMgr() { return _collectionMgr; }
|
public CollectionMgr GetCollectionMgr() { return _collectionMgr; }
|
||||||
@@ -1005,13 +1004,9 @@ namespace Game
|
|||||||
|
|
||||||
BattlePetMgr _battlePetMgr;
|
BattlePetMgr _battlePetMgr;
|
||||||
|
|
||||||
Task<SQLQueryHolder<AccountInfoQueryLoad>> _realmAccountLoginCallback;
|
|
||||||
Task<SQLQueryHolder<AccountInfoQueryLoad>> _accountLoginCallback;
|
|
||||||
Task<SQLQueryHolder<PlayerLoginQueryLoad>> _charLoginCallback;
|
|
||||||
Task<SQLQueryHolder<EnumCharacterQueryLoad>> _charEnumCallback;
|
|
||||||
|
|
||||||
AsyncCallbackProcessor<QueryCallback> _queryProcessor = new();
|
AsyncCallbackProcessor<QueryCallback> _queryProcessor = new();
|
||||||
AsyncCallbackProcessor<TransactionCallback> _transactionCallbacks = new();
|
AsyncCallbackProcessor<TransactionCallback> _transactionCallbacks = new();
|
||||||
|
AsyncCallbackProcessor<ISqlCallback> _queryHolderProcessor = new();
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user