424 lines
17 KiB
C#
424 lines
17 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Collections.Concurrent;
|
|
using System.Numerics;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
using Nettention.Proud;
|
|
using StackExchange.Redis;
|
|
using Pipelines.Sockets.Unofficial.Buffers;
|
|
|
|
|
|
using ServerCore;
|
|
using ServerBase;
|
|
using ServerCommon;
|
|
using ServerCommon.BusinessLogDomain;
|
|
using MetaAssets;
|
|
|
|
|
|
using SESSION_ID = System.Int32;
|
|
using WORLD_META_ID = System.UInt32;
|
|
using META_ID = System.UInt32;
|
|
using ENTITY_GUID = System.String;
|
|
using ACCOUNT_ID = System.String;
|
|
using OWNER_GUID = System.String;
|
|
using USER_GUID = System.String;
|
|
using CHARACTER_GUID = System.String;
|
|
using ITEM_GUID = System.String;
|
|
|
|
|
|
|
|
|
|
namespace GameServer;
|
|
|
|
public partial class Player : UserBase, IEntityWithSession, IMergeWithInventory, IInitNotifyPacket
|
|
{
|
|
private readonly CancellationTokenSource m_cts = new();
|
|
private readonly List<(ClientToGame packet, bool isNotifyBroadcast)> notifyPackets = new();
|
|
|
|
public Player(NetClientInfo netClient)
|
|
: base(EntityType.Player, netClient)
|
|
{
|
|
|
|
}
|
|
|
|
public override async Task<Result> onInit()
|
|
{
|
|
//=====================================================================================
|
|
// User Domain Attribute
|
|
//=====================================================================================
|
|
addEntityAttribute(new UserAttribute(this));
|
|
addEntityAttribute(new NicknameAttribute(this));
|
|
addEntityAttribute(new LevelAttribute(this));
|
|
addEntityAttribute(new MoneyAttribute(this));
|
|
addEntityAttribute(new LocationAttribute(this));
|
|
|
|
addEntityAttribute(new BuffAttribute(this));
|
|
addEntityAttribute(new GameOptionAttribute(this));
|
|
addEntityAttribute(new CharacterProfileAttribute(this));
|
|
addEntityAttribute(new MailProfileAttribute(this));
|
|
addEntityAttribute(new CraftHelpAttribute(this));
|
|
|
|
addEntityAttribute(new PartyInvitePartyRecvsAttribute(this));
|
|
|
|
addEntityAttribute(new FriendFolderAttribute(this));
|
|
addEntityAttribute(new RepeatQuestAttribute(this));
|
|
|
|
addEntityAttribute(new EscapePositionAttribute(this));
|
|
addEntityAttribute(new SeasonPassAttribute(this));
|
|
|
|
addEntityAttribute(new UserContentsSettingAttribute(this));
|
|
addEntityAttribute(new PackageLastOrderRecodeAttribute(this));
|
|
addEntityAttribute(new AiChatAttribute(this));
|
|
|
|
addEntityAttribute(new UgqDailyRewardCountAttribute(this));
|
|
addEntityAttribute(new RentalInstanceVisitAttribute(this));
|
|
|
|
addEntityAttribute(new DailyQuestCheckAttribute(this));//legacy
|
|
addEntityAttribute(new SwitchingPropAttribute(this));
|
|
addEntityAttribute(new QuestPeriodRepeatCheckAttribute(this));
|
|
|
|
//=====================================================================================
|
|
// Game Domain Attribute
|
|
//=====================================================================================
|
|
addEntityAttribute(new CaliumAttribute(this));
|
|
|
|
//=====================================================================================
|
|
// User Domain Action
|
|
//=====================================================================================
|
|
addEntityAction(new PlayerAction(this));
|
|
addEntityAction(new AbilityAction(this));
|
|
addEntityAction(new NicknameAction(this));
|
|
addEntityAction(new LocationAction(this));
|
|
addEntityAction(new MoneyAction(this));
|
|
addEntityAction(new UserContentsSettingAction(this));
|
|
|
|
//=====================================================================================
|
|
// Inventory 관련 Action
|
|
//=====================================================================================
|
|
addEntityAction(new UserInventoryAction(this));
|
|
|
|
|
|
//=====================================================================================
|
|
// Item 관리적인 Action
|
|
//=====================================================================================
|
|
addEntityAction(new ItemBuyAction(this));
|
|
addEntityAction(new ItemClothAction(this));
|
|
addEntityAction(new ItemToolAction(this));
|
|
addEntityAction(new ItemTattooAction(this));
|
|
|
|
addEntityAction(new RandomBoxItemUseAction(this));
|
|
|
|
|
|
//=====================================================================================
|
|
// GameZone Domain Action
|
|
//=====================================================================================
|
|
addEntityAction(new GameZoneAction(this));
|
|
addEntityAction(new GameZoneMoveAction(this));
|
|
|
|
// room 관련 action
|
|
addEntityAction(new RoomAction(this));
|
|
|
|
|
|
// shop 관련 action
|
|
addEntityAction(new ShopAction(this));
|
|
|
|
// Party 관련 action
|
|
addEntityAction(new PersonalPartyAction(this));
|
|
addEntityAction(new PartyInvitePartyRecvAction(this));
|
|
|
|
addEntityAction(new FriendAgentAction(this));
|
|
addEntityAction(new FriendFolderAction(this));
|
|
addEntityAction(new SendFriendRequestAction(this));
|
|
addEntityAction(new FriendInviteMyhomeAction(this));
|
|
addEntityAction(new FriendReplyInviteMyhomeAction(this));
|
|
addEntityAction(new ReplyReceivedFriendRequestAction(this));
|
|
addEntityAction(new KickFriendsFromMyHomeAction(this));
|
|
addEntityAction(new BlockUserAgentAction(this));
|
|
addEntityAction(new QuestAction(this));
|
|
addEntityAction(new QuestCheatAction(this));
|
|
addEntityAction(new RepeatQuestAction(this));
|
|
addEntityAction(new EndQuestAction(this));
|
|
addEntityAction(new QuestAcceptAction(this));
|
|
addEntityAction(new QuestMailAction(this));
|
|
addEntityAction(new QuestRefuseAction(this));
|
|
addEntityAction(new QuestAbandonAction(this));
|
|
addEntityAction(new QuestTaskUpdateAction(this));
|
|
addEntityAction(new QuestRewardAction(this));
|
|
addEntityAction(new QuestNPCDialogueAction(this));
|
|
addEntityAction(new ClaimAction(this));
|
|
addEntityAction(new ClaimRewardAction(this));
|
|
addEntityAction(new UgqInfoAction(this));
|
|
addEntityAction(new UgqAssignAction(this));
|
|
addEntityAction(new UgqTestAction(this));
|
|
addEntityAction(new UgqAbortAction(this));
|
|
addEntityAction(new UgqRewardAction(this));
|
|
addEntityAction(new SwitchingPropAction(this));
|
|
|
|
addEntityAction(new OwnedBuildingAgentAction(this));
|
|
addEntityAction(new OwnedLandAgentAction(this));
|
|
addEntityAction(new MyhomeAgentAction(this));
|
|
addEntityAction(new RentalAgentAction(this));
|
|
addEntityAction(new UserSocialActionExecutorAction(this));
|
|
addEntityAction(new MinimapMarkerAgentAction(this));
|
|
addEntityAction(new ItemFirstPurchaseHistoryAgentAction(this));
|
|
addEntityAction(new SearchNicknameAction(this));
|
|
|
|
addEntityAction(new ChatAction(this));
|
|
addEntityAction(new CharacterProfileAction(this));
|
|
addEntityAction(new ChannelAction(this));
|
|
addEntityAction(new CartAction(this));
|
|
addEntityAction(new BuffAction(this));
|
|
addEntityAction(new GameOptionAction(this));
|
|
addEntityAction(new LanguageAction(this));
|
|
addEntityAction(new MailAction(this));
|
|
addEntityAction(new StateAction(this));
|
|
addEntityAction(new UserReportAction(this));
|
|
addEntityAction(new EscapeAction(this));
|
|
addEntityAction(new PackageAction(this));
|
|
|
|
addEntityAction(new CraftAction(this));
|
|
addEntityAction(new CraftHelpAction(this));
|
|
addEntityAction(new CraftRecipeAction(this));
|
|
addEntityAction(new SeasonPassAction(this));
|
|
addEntityAction(new RentalVisitAction(this));
|
|
addEntityAction(new P2PDataAction(this));
|
|
addEntityAction(new BeaconShopAction(this));
|
|
|
|
//=====================================================================================
|
|
// AI Chat 관련 Action
|
|
//=====================================================================================
|
|
addEntityAction(new AIChatAction(this));
|
|
|
|
//=====================================================================================
|
|
// Task Reservation 관련 Action
|
|
//=====================================================================================
|
|
addEntityAction(new TaskReservationAction(this));
|
|
|
|
//=====================================================================================
|
|
// Npc 상호작용 Action
|
|
//=====================================================================================
|
|
addEntityAction(new NpcInteractionAction(this));
|
|
|
|
|
|
//=====================================================================================
|
|
// Ugc Npc 관련 Action
|
|
//=====================================================================================
|
|
addEntityAction(new UgcNpcCreationOrLoadAction(this));
|
|
|
|
|
|
//=====================================================================================
|
|
// Farming 관련 Action
|
|
//=====================================================================================
|
|
addEntityAction(new FarmingAction(this));
|
|
|
|
|
|
//=====================================================================================
|
|
// Game LogInOut 관련 Action
|
|
//=====================================================================================
|
|
addEntityAction(new GameLoginAction(this));
|
|
addEntityAction(new GameLogoutAction(this));
|
|
|
|
|
|
//=====================================================================================
|
|
// User Create or Load 관련 Action
|
|
//=====================================================================================
|
|
addEntityAction(new UserCreateOrLoadAction(this));
|
|
|
|
|
|
//=====================================================================================
|
|
// Custom Ui or Data 관련 Action
|
|
//=====================================================================================
|
|
addEntityAction(new CustomDefinedUiAction(this));
|
|
|
|
//=====================================================================================
|
|
// Calium 관련 Action
|
|
//=====================================================================================
|
|
addEntityAction(new CaliumConverterAction(this));
|
|
addEntityAction(new CaliumExchangerAction(this));
|
|
|
|
//=====================================================================================
|
|
// AI Chat 관련 Action
|
|
//=====================================================================================
|
|
|
|
//=====================================================================================
|
|
// 랜드 경매 관련 Action
|
|
//=====================================================================================
|
|
addEntityAction(new UserLandAuctionAction(this));
|
|
|
|
|
|
return await base.onInit();
|
|
}
|
|
|
|
public async Task onResetUser()
|
|
{
|
|
foreach(var each in getEntityAttributes())
|
|
{
|
|
var to_clear_attribute = each.Value;
|
|
|
|
var account_attribute = to_clear_attribute as AccountAttribute;
|
|
if (null != account_attribute) { continue; }
|
|
var user_attribute = to_clear_attribute as UserAttribute;
|
|
if (null != user_attribute) { continue; }
|
|
|
|
to_clear_attribute.onClear();
|
|
}
|
|
|
|
foreach (var each in getEntityActions())
|
|
{
|
|
var to_clear_action = each.Value;
|
|
|
|
to_clear_action.onClear();
|
|
}
|
|
|
|
await Task.CompletedTask;
|
|
}
|
|
|
|
// override IMergeWithInventory
|
|
public async Task<Result> onMerge(List<ReservedSlotOnInven> reservedSlotOnInvens, TransactionRunner transactionRunner)
|
|
{
|
|
ArgumentNullReferenceCheckHelper.throwIfNull(reservedSlotOnInvens, () => $"reservedSlotOnInvens is null !!! - {toBasicString()}");
|
|
ArgumentNullReferenceCheckHelper.throwIfNull(transactionRunner, () => $"transactionRunner is null !!! - {toBasicString()}");
|
|
|
|
var result = new Result();
|
|
|
|
var inventory_action = getEntityAction<InventoryActionBase>();
|
|
NullReferenceCheckHelper.throwIfNull(inventory_action, () => $"inventory_action is null !!! - {toBasicString()}");
|
|
|
|
result = await inventory_action.onMergeInventory(reservedSlotOnInvens, transactionRunner);
|
|
if(result.isFail())
|
|
{
|
|
return result;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public void addNotifyMessage(ClientToGame message, bool isNotifyBroadcast) { notifyPackets.Add((message, isNotifyBroadcast)); }
|
|
public void InitNotifyMessage() { notifyPackets.Clear(); }
|
|
public void sendNotifyMessage()
|
|
{
|
|
foreach ((ClientToGame packet, bool isNotifyBroadcast) notifyInfo in notifyPackets)
|
|
{
|
|
if (notifyInfo.isNotifyBroadcast == true)
|
|
{
|
|
var game_zone_action = this.getEntityAction<GameZoneAction>();
|
|
NullReferenceCheckHelper.throwIfNull(game_zone_action, () => $"game_zone_action is null !!! - {toBasicString()}");
|
|
game_zone_action.broadcast(this, notifyInfo.packet);
|
|
}
|
|
else
|
|
{
|
|
if (false == GameServerApp.getServerLogic().onSendPacket(this, notifyInfo.packet))
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public override TAction getEntityAction<TAction>()
|
|
{
|
|
if (typeof(TAction) == typeof(InventoryActionBase))
|
|
{
|
|
var inventory_action = base.getEntityAction<UserInventoryAction>() as TAction;
|
|
NullReferenceCheckHelper.throwIfNull(inventory_action, () => $"inventory_action is null !!!");
|
|
return inventory_action;
|
|
}
|
|
else if (typeof(TAction) == typeof(SocialActionLoadAction))
|
|
{
|
|
var social_action = base.getEntityAction<UserSocialActionExecutorAction>() as TAction;
|
|
NullReferenceCheckHelper.throwIfNull(social_action, () => $"social_action is null !!!");
|
|
return social_action;
|
|
}
|
|
|
|
var action = base.getEntityAction<TAction>();
|
|
NullReferenceCheckHelper.throwIfNull(action, () => $"action is null !!!");
|
|
return action;
|
|
}
|
|
|
|
public override Type onGetAvailableItemAttributeType()
|
|
{
|
|
return typeof(UserItemAttribute);
|
|
}
|
|
|
|
public override OWNER_GUID onGetGuidOfOwnerEntityType()
|
|
{
|
|
var user_attribute = getEntityAttribute<UserAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(user_attribute, () => $"user_attribute is null !!! - {toBasicString()}");
|
|
|
|
return user_attribute.UserGuid;
|
|
}
|
|
|
|
public bool sendPacket(ClientToGame msg)
|
|
{
|
|
return GameServerApp.getServerLogic().onSendPacket(this, msg);
|
|
}
|
|
|
|
public bool hasOtpForServerConnect()
|
|
{
|
|
var account_attribute = getEntityAttribute<AccountAttribute>();
|
|
if (null == account_attribute)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (0 >= account_attribute.OtpForServerConnect.Length)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public CancellationTokenSource getCancelToken() => m_cts;
|
|
|
|
|
|
public override string onGetDbGuid()
|
|
{
|
|
return getUserGuid();
|
|
}
|
|
|
|
public CommonResult? getCommonResult()
|
|
{
|
|
var err_msg = string.Empty;
|
|
|
|
var found_transaction_runner = findTransactionRunner(TransactionIdType.PrivateContents);
|
|
if (null == found_transaction_runner)
|
|
{
|
|
err_msg = $"Not found TransactionRunner !!! : {toBasicString()}";
|
|
Log.getLogger().error(err_msg);
|
|
|
|
return null;
|
|
}
|
|
|
|
return found_transaction_runner.getCommonResult();
|
|
}
|
|
|
|
public override ILogActor toLogActor()
|
|
{
|
|
var user_actor_log = base.toLogActor() as UserActorLog;
|
|
ArgumentNullReferenceCheckHelper.throwIfNull(user_actor_log, () => $"user_actor_log is null !!!");
|
|
|
|
var nickname_attribute = getEntityAttribute<NicknameAttribute>();
|
|
if(null != nickname_attribute)
|
|
{
|
|
user_actor_log.UserNickname = nickname_attribute.Nickname;
|
|
}
|
|
|
|
return user_actor_log;
|
|
}
|
|
|
|
public override string toSummaryString()
|
|
{
|
|
var server_logic = GameServerApp.getServerLogic();
|
|
var public_ip = server_logic.getProudNetListener().getNetServer().getNetClientPublicIp(this.getHostId());
|
|
|
|
var account_attribute = getOriginEntityAttribute<AccountAttribute>();
|
|
return toBasicString() + $"accountCreationType:{account_attribute?.AccountCreationType}, authAdminLevelType:{account_attribute?.AuthAdminLevelType}, publicIp:{public_ip}, {base.toSummaryString()}";
|
|
}
|
|
}
|