초기커밋

This commit is contained in:
2025-05-01 07:20:41 +09:00
commit 98bb2e3c5c
2747 changed files with 646947 additions and 0 deletions

View File

@@ -0,0 +1,153 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StackExchange.Redis;
using ServerCore;
using SERVER_METRICS_TRIGGER_TYPE = System.UInt32;
namespace ServerBase;
public class ServerInfo : IComparable<ServerInfo>
{
public ServerInfo()
{
}
public ServerInfo(ServerInfo serverInfo)
{
this.Name = serverInfo.Name;
this.Address = serverInfo.Address;
this.Port = serverInfo.Port;
this.Sessions = serverInfo.Sessions;
this.RoomCapacity = serverInfo.RoomCapacity;
this.Capacity = serverInfo.Capacity;
this.Reservation = serverInfo.Reservation;
this.ReturnCount = serverInfo.ReturnCount;
this.UgcNpcCount = serverInfo.UgcNpcCount;
this.Inspection = serverInfo.Inspection;
this.ReadyForDistroy = serverInfo.ReadyForDistroy;
this.LastUpdateTime = serverInfo.LastUpdateTime;
this.AwsInstanceID = serverInfo.AwsInstanceID;
this.Channel = serverInfo.Channel;
this.WorldId = serverInfo.WorldId;
}
public string Name = string.Empty;
public string Address = string.Empty;
public string AwsInstanceID = string.Empty;
public int Port = 0;
public int Sessions = 0;
public int RoomCapacity = 0;
public int Capacity = 0;
public int Reservation = 0;
public int ReturnCount = 0;
public int UgcNpcCount = 0;
public bool Inspection = false;
public bool ReadyForDistroy = false;
public DateTime LastUpdateTime;
public int Channel = 0;
public int WorldId = 0;
public int CompareTo(ServerInfo? other)
{
if (other == null)
return 1;
return Sessions.CompareTo(other.Sessions);
}
}
public class ServerMetricsCacheRequest : RedisRequestWithLambdaBase<ServerMetricsCacheRequest.FnConditionCheck>
{
public class CacheServerKey
{
public string key = string.Empty;
public long tick = 0;
public List<RedisValue> redisValue = new();
}
public delegate Task<Result> FnConditionCheck();
public delegate Task<IWithResult> FnTriggerHandler( params object[] handlerParams );
// for Metrics
public enum TriggerType
{
ServerMetrics_Init, //Return : ResultOnly, Params : { SERVER_NAME, ServerType, WORLD_META_ID }
ServerMetrics_AllGetAndFill, //Return : ResultValue<List<ServerInfo>>, Params : { WORLD_META_ID List } with ServerType{ Login, Channel, Indun }
ServerMetrics_ServerTypeGetAndFill, //Return : ResultValue<List<ServerInfo>>, Params : { ServerType, WORLD_META_ID }
ServerMetrics_ChannelTargetGetAndFill, //Return : ResultValue<ServerInfo>, Params : { WORLD_META_ID, ChannelNo } with ServerType{ Channel }
ServerMetrics_GetByServerName, //Return : ResultValue<ServerInfo>, Params : { SERVER_NAME }
ServerMetrics_ExpiredAllRemove, //Return : ResultOnly, Params : { WORLD_META_ID List } with ServerType{ Login, Channel, Indun }
ServerMetrics_RemoveByServerName, //Return : ResultOnly, Params : { SERVER_NAME }
ServerMetrics_UpdateToCache, //Return : ResultOnly, Params : { SERVER_NAME, ServerInfo }
}
private ConcurrentDictionary<SERVER_METRICS_TRIGGER_TYPE, FnTriggerHandler> m_trigger_handlers = new();
private ServerMetricsManager m_manager;
public ServerMetricsCacheRequest(ServerMetricsManager manager, RedisConnector redisConnector)
: base(redisConnector)
{
m_manager = manager;
}
public bool registerTriggerHandler(SERVER_METRICS_TRIGGER_TYPE triggerType, FnTriggerHandler handler)
{
return m_trigger_handlers.TryAdd(triggerType, handler);
}
public async Task<IWithResult> tryRunTriggerHandler(SERVER_METRICS_TRIGGER_TYPE triggerType, params object[] handlerParams)
{
var result = new Result();
var err_msg = string.Empty;
if (false == m_trigger_handlers.TryGetValue(triggerType, out var found_handler))
{
err_msg = $"Failed to TryGetValue() !!!, in tryRunTriggerHandler(), Not found FnTriggerHandler : triggerType:{triggerType}";
result.setFail(ServerErrorCode.ServerMetricsTriggerHandlerNotFound, err_msg);
return new ResultOnly(result);
}
return await found_handler.Invoke(handlerParams);
}
public ServerInfo makeServerInfo( string serverName
, string address, int port
, int sessions, int capacity, int reservation
, int returnCount, int ugcNpcCount
, int worldId = 0, int channel = 0, int roomCapacity = 0
, string awsInstanceId = "" )
{
var server_info = new ServerInfo();
server_info.Name = serverName;
server_info.Address = address;
server_info.Port = port;
server_info.Sessions = sessions;
server_info.Capacity = capacity;
server_info.Reservation = reservation;
server_info.ReturnCount = returnCount;
server_info.UgcNpcCount = ugcNpcCount;
server_info.RoomCapacity = roomCapacity;
//server_info.Inspection = AccountAuthorityManager.Instance.isInspection;
//server_info.ReadyForDistroy = AccountAuthorityManager.Instance.isReadyForDistroy;
server_info.LastUpdateTime = DateTime.Now;
server_info.AwsInstanceID = awsInstanceId;
server_info.Channel = channel;
server_info.WorldId = worldId;
return server_info;
}
public ServerMetricsManager getServerMetricsManager() => m_manager;
}