초기커밋
This commit is contained in:
79
GameServer/Contents/Friend/LockAction/FriendInterlockBase.cs
Normal file
79
GameServer/Contents/Friend/LockAction/FriendInterlockBase.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
using ServerCommon.BusinessLogDomain;
|
||||
using MetaAssets;
|
||||
|
||||
|
||||
|
||||
namespace GameServer;
|
||||
|
||||
public interface IFriendInterlockAction
|
||||
{
|
||||
public Task<Result> doInterlockAction();
|
||||
public Task<(Result, FriendInterlockCacheRequest?)> doInterLockAndGetCache();
|
||||
}
|
||||
|
||||
public abstract class FriendInterlockBase : IFriendInterlockAction
|
||||
{
|
||||
private UserBase m_owner;
|
||||
private string m_my_guid;
|
||||
private string m_friend_guid;
|
||||
|
||||
public FriendInterlockBase(UserBase owner, string myGuid, string friendGuid)
|
||||
{
|
||||
m_owner = owner;
|
||||
m_my_guid = myGuid;
|
||||
m_friend_guid = friendGuid;
|
||||
}
|
||||
|
||||
public abstract Task<Result> doAction();
|
||||
|
||||
public async Task<(Result, FriendInterlockCacheRequest?)> doInterLockAndGetCache()
|
||||
{
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
|
||||
var friend_cache_request = new FriendInterlockCacheRequest(m_owner, server_logic.getRedisConnector(), m_my_guid, m_friend_guid);
|
||||
var result = await friend_cache_request.getLock();
|
||||
if (result.isFail()) return (result, null);
|
||||
|
||||
result = await doAction();
|
||||
if (result.isFail()) return (result, null);
|
||||
|
||||
return (result, friend_cache_request);
|
||||
}
|
||||
|
||||
public async Task<Result> doInterlockAction()
|
||||
{
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
|
||||
var player = m_owner as Player;
|
||||
var friend_cache_request = new FriendInterlockCacheRequest(m_owner, server_logic.getRedisConnector(), m_my_guid, m_friend_guid);
|
||||
var result = await friend_cache_request.getLock();
|
||||
if (result.isFail()) return result;
|
||||
|
||||
result = await doAction();
|
||||
if (result.isFail()) return result;
|
||||
|
||||
await friend_cache_request.removeFirstCache();
|
||||
return result;
|
||||
}
|
||||
|
||||
protected Player getOwner()
|
||||
{
|
||||
var owner = m_owner as Player;
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
||||
|
||||
return owner;
|
||||
}
|
||||
|
||||
protected string getMyGuid() => m_my_guid;
|
||||
protected string getFriendGuid() => m_friend_guid;
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user