초기커밋
This commit is contained in:
171
GameServer/Ticker/EntityUpdateTicker.cs
Normal file
171
GameServer/Ticker/EntityUpdateTicker.cs
Normal file
@@ -0,0 +1,171 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
using ServerCore; using ServerBase;
|
||||
using ServerCommon;
|
||||
using META_ID = System.UInt32;
|
||||
using GameServer.PacketHandler;
|
||||
using System.Diagnostics;
|
||||
using ServerCommon.BusinessLogDomain;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
|
||||
namespace GameServer
|
||||
{
|
||||
public class EntityUpdateTicker : EntityTicker
|
||||
{
|
||||
public EntityUpdateTicker(double onTickIntervalMilliseconds, CancellationTokenSource? cts)
|
||||
: base(EntityType.EntityUpdateTicker, onTickIntervalMilliseconds, cts)
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task onTaskTick()
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
Stopwatch? stopwatch = null;
|
||||
var event_tid = string.Empty;
|
||||
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
var server_config = server_logic.getServerConfig();
|
||||
var seasonPassManager = server_logic.getSeasonPassManager();
|
||||
|
||||
if (true == server_config.PerformanceCheckEnable)
|
||||
{
|
||||
event_tid = System.Guid.NewGuid().ToString("N");
|
||||
stopwatch = Stopwatch.StartNew();
|
||||
}
|
||||
|
||||
(bool isUpdateNewSeasonPass, META_ID new_season_pass_id) = seasonPassManager.updateNewSeason();
|
||||
|
||||
var ticker_stopwatch = Stopwatch.StartNew();
|
||||
|
||||
foreach (var each in server_logic.getPlayerManager().getUsers())
|
||||
{
|
||||
// TODO : 여기서 유저 주요 테스크를 처리 한다.
|
||||
var user = each.Value;
|
||||
var user_create_or_load_action = user.getEntityAction<UserCreateOrLoadAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(user_create_or_load_action, () => $"user_create_or_load_action is null !!! - {user.toBasicString()}");
|
||||
|
||||
if (false == user_create_or_load_action.isCompletedLoadUser())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ticker_stopwatch.Restart();
|
||||
|
||||
var buff_action = user.getEntityAction<BuffAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(buff_action, () => $"buff_action is null !!! - {user.toBasicString()}");
|
||||
|
||||
await buff_action.onTick();
|
||||
|
||||
stopWatchTickerCheck(ticker_stopwatch, "buff_action");
|
||||
|
||||
if (isUpdateNewSeasonPass == true)
|
||||
{
|
||||
var season_pass_action = user.getEntityAction<SeasonPassAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(season_pass_action, () => $"season_pass_action is null !!! - {user.toBasicString()}");
|
||||
|
||||
if (new_season_pass_id != 0)
|
||||
{
|
||||
await season_pass_action.StartNewSeasonPass(new_season_pass_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
user.send_S2C_NTF_SEASON_PASS_INFOS();
|
||||
}
|
||||
}
|
||||
|
||||
stopWatchTickerCheck(ticker_stopwatch, "season_pass_action");
|
||||
|
||||
var ai_chat_action = user.getEntityAction<AIChatAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(ai_chat_action, () => $"ai_chat_action is null !!! - {user.toBasicString()}");
|
||||
|
||||
if (server_logic.getServerConfig().OfflineMode == false)
|
||||
{
|
||||
await ai_chat_action.updateTickOfIncentivePoint();
|
||||
}
|
||||
|
||||
stopWatchTickerCheck(ticker_stopwatch, "ai_chat_action");
|
||||
|
||||
var task_reservation_action = user.getEntityAction<TaskReservationAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(task_reservation_action, () => $"task_reservation_action is null !!! - {user.toBasicString()}");
|
||||
await task_reservation_action.UpdateTick();
|
||||
|
||||
stopWatchTickerCheck(ticker_stopwatch, "task_reservation_action");
|
||||
|
||||
var package_action = user.getEntityAction<PackageAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(package_action, () => $"package_action is null !!! - {user.toBasicString()}");
|
||||
await package_action.UpdateTick();
|
||||
|
||||
stopWatchTickerCheck(ticker_stopwatch, "package_action");
|
||||
|
||||
var rental_agent_action = user.getEntityAction<RentalAgentAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(rental_agent_action, () => $"rental_agent_action is null !!! - {user.toBasicString()}");
|
||||
await rental_agent_action.onTick();
|
||||
|
||||
stopWatchTickerCheck(ticker_stopwatch, "rental_agent_action");
|
||||
|
||||
var user_inventory_action = user.getEntityAction<UserInventoryAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(user_inventory_action, () => $"user_inventory_action is null !!! - {user.toBasicString()}");
|
||||
await user_inventory_action.onTick();
|
||||
|
||||
stopWatchTickerCheck(ticker_stopwatch, "user_inventory_action");
|
||||
|
||||
/*
|
||||
var fn_entity_update = async delegate ()
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
var result = new Result();
|
||||
|
||||
// TODO HERE : 유저가 처리해야 하는 Update 함수를 추가 한다.
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
result = await user.runTransactionRunnerSafely(TransactionIdType.PrivateContents, "EntityUpdateTicker", fn_entity_update );
|
||||
if(result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to runTransactionRunnerSafely() on EntityUpdateTicker !!!"
|
||||
+ $" : {result.toBasicString()} - {user.toBasicString()}";
|
||||
//Log.getLogger().error(err_msg);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
if (null != stopwatch)
|
||||
{
|
||||
var elapsed_msec = stopwatch.ElapsedMilliseconds;
|
||||
stopwatch.Stop();
|
||||
Log.getLogger().debug($"{GetType()} Ticker Stopwatch Stop : ETID:{event_tid}, ElapsedMSec:{elapsed_msec}, TickIntervalMSec:{getOnTickIntervalMilliseconds()}");
|
||||
}
|
||||
}
|
||||
|
||||
private void stopWatchTickerCheck(Stopwatch ticker_stopwatch, string action)
|
||||
{
|
||||
var elapsed_msec = ticker_stopwatch.ElapsedMilliseconds;
|
||||
if (elapsed_msec > 300)
|
||||
{
|
||||
Log.getLogger().error($"Ticker Stopwatch Stop. Action : {action}, ElapsedMSec:{elapsed_msec}");
|
||||
}
|
||||
ticker_stopwatch.Stop();
|
||||
ticker_stopwatch.Restart();
|
||||
}
|
||||
|
||||
public override string toBasicString()
|
||||
{
|
||||
return $"{this.getTypeName()}";
|
||||
}
|
||||
|
||||
public override string toSummaryString()
|
||||
{
|
||||
return $"{this.getTypeName()}";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user