Files
caliverse_server/GameServer/z.Backup/ChatCommand.cs
2025-05-01 07:20:41 +09:00

703 lines
26 KiB
C#

using GameServer;
using GameServer.PacketHandler;
using ServerCommon;
using ServerCore; using ServerBase;
using static ClientToGameReq.Types;
namespace GameServer
{
// 임시로 GameServer 내부로 이동 했다. - kangms
/*
public class ChatCommand : Attribute
{
Dictionary<string, ChatCommandBase> command_base_map = new Dictionary<string, ChatCommandBase>();
public ChatCommand()
{
loadChatCommand();
}
private void loadChatCommand()
{
// ChatCommand 클래스의 모든 메서드를 가져옵니다.
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (var assembly in assemblies)
{
foreach (Type type in assembly.GetTypes())
{
ChatCommandAttribute[] attributes = (ChatCommandAttribute[])type.GetCustomAttributes(typeof(ChatCommandAttribute), false);
foreach (var attrib in attributes)
{
string command_key = attrib.getCommand();
if (command_key == null)
{
Log.getLogger().error($"chatCommand Key is null attrib : {attrib.getHandlerClass().FullName} ");
continue;
}
var handler_class = Activator.CreateInstance(attrib.getHandlerClass()) as ChatCommandBase;
if (handler_class == null)
{
Log.getLogger().error($"Failed to create chatCommand : commandKey:{command_key}");
continue;
}
handler_class.setAuthAdminLevelType(attrib.getAdminLevel());
handler_class.setClassName(attrib.getHandlerClass().Name);
if (command_base_map.TryAdd(command_key, handler_class) == false)
{
Log.getLogger().error($"command_base_map add Error : commandKey:{command_key}");
continue;
}
}
}
}
}
public bool isCheatCommand(string input)
{
return input.StartsWith("//");
}
public async Task<bool> HandleCommand(Player player, string input)
{
var tokenArr = input.Split(" ", 2);
try
{
var command = tokenArr[0].Remove(0, 2);
if(command_base_map.TryGetValue(command.ToLower(), out var handler_class) == false )
{
Log.getLogger().error($"Command Not Exist Command : {command.ToLower()}");
return false;
}
if (await hasAuthority(handler_class, player) == false)
{
return false;
}
if (tokenArr.Length > 1)
{
var args = tokenArr[1].Split(" ", StringSplitOptions.RemoveEmptyEntries);
await handler_class.invoke(player, tokenArr[1], args);
}
else
{
await handler_class.invoke(player, String.Empty, new string[] { });
}
}
catch (TaskCanceledException)
{
}
catch (Exception ex)
{
Log.getLogger().error($"{ex}");
return false;
}
return true;
}
private async Task<bool> hasAuthority(ChatCommandBase handlerClass, Player player)
{
//서버 타입이 Dev면 무조건 true처리
if (ServerConfigHelper.getServerConfig().ServiceType.Equals(ServiceType.Dev.ToString()))
{
return true;
}
var account_attribute = player.getEntityAttribute<AccountAttribute>();
var adim_level_type = account_attribute.AuthAdminLevelType;
//여기에 유저 레벨이랑, 클래스에 할당된 레벨이랑 비교 필요
var class_admin_level_type = handlerClass.getAuthAddminLevelType();
if (class_admin_level_type.Contains(adim_level_type) == false)
{
Log.getLogger().info($"Not Match Admin LevelType : {account_attribute.AccountId}, className = {handlerClass.getAuthAddminLevelType().ToString()}, className : {handlerClass.getClassName()}");
return false;
}
return true;
}
}
[AttributeUsage(AttributeTargets.Class)]
internal class ChatCommandAttribute : Attribute
{
readonly string m_cheat_comment;
private readonly Type m_handler_class;
private readonly HashSet<AuthAdminLevelType> m_auth_admin_level_type;
public ChatCommandAttribute(string cheatCommend, Type handlerClass, params AuthAdminLevelType[] authAdminLevelType)
{
m_cheat_comment = cheatCommend;
m_handler_class = handlerClass;
m_auth_admin_level_type = new HashSet<AuthAdminLevelType>(authAdminLevelType);
}
public string getCommand()
{
return m_cheat_comment;
}
public HashSet<AuthAdminLevelType> getAdminLevel()
{
return m_auth_admin_level_type;
}
public Type getHandlerClass()
{
return m_handler_class;
}
}
public abstract class ChatCommandBase
{
private HashSet<AuthAdminLevelType> m_auth_admin_level_type = new();
private string m_class_name = string.Empty;
public void setAuthAdminLevelType(HashSet<AuthAdminLevelType> typeSet)
{
m_auth_admin_level_type = typeSet;
}
public HashSet<AuthAdminLevelType> getAuthAddminLevelType()
{
return m_auth_admin_level_type;
}
public void setClassName(string className)
{
m_class_name = className;
}
public string getClassName()
{
return m_class_name;
}
public virtual async Task invoke(Player player, string token, string[] args) { }
}
[ChatCommandAttribute("dummyClazz", typeof(ChatCommandDummy), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
internal class ChatCommandDummy : ChatCommandBase
{
public override async Task invoke(Player player, string token, string[] args)
{
}
}
[ChatCommandAttribute("teleport", typeof(ChatCommandTeleport), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
internal class ChatCommandTeleport : ChatCommandBase
{
public override async Task invoke(Player player, string token, string[] args)
{
Log.getLogger().info($"HandleTeleport");
if (args.Length < 2)
return;
if (float.TryParse(args[0], out float x) == false || float.TryParse(args[1], out float y) == false)
return;
Pos pos = new Pos();
pos.X = x;
pos.Y = y;
pos.Z = 0.0f;
pos.Angle = 0;
//player.Teleport(pos);
}
}
[ChatCommandAttribute("additem", typeof(ChatCommandAddItem), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
internal class ChatCommandAddItem : ChatCommandBase
{
public override async Task invoke(Player player, string token, string[] args)
{
Log.getLogger().info($"HandleAddItem");
if (args.Length < 2)
return;
if (int.TryParse(args[0], out int itemId) == false || int.TryParse(args[1], out int count) == false)
return;
//await player.CheatAddItem(itemId, count);
}
}
[ChatCommandAttribute("delitem", typeof(ChatCommandDelItem), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
internal class ChatCommandDelItem : ChatCommandBase
{
public override async Task invoke(Player player, string token, string[] args)
{
Log.getLogger().info($"HandleDelItem");
if (args.Length < 2)
return;
if (int.TryParse(args[0], out int itemId) == false || int.TryParse(args[1], out int count) == false)
return;
//await player.CheatDelItem(itemId, count);
}
}
[ChatCommandAttribute("init", typeof(ChatCommandInit), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
internal class ChatCommandInit : ChatCommandBase
{
public override async Task invoke(Player player, string token, string[] args)
{
Log.getLogger().info($"HandleInit");
// player._charEntity.AvatarInfo.Init = 1;
// await GameServerApp.Instance.MainDB.SaveChar(player._charEntity);
}
}
[ChatCommandAttribute("mailsetremainedtime", typeof(ChatCommandMailSetRemainedTime), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
internal class ChatCommandMailSetRemainedTime : ChatCommandBase
{
public override async Task invoke(Player player, string token, string[] args)
{
Log.getLogger().info($"HandleMailDecreaseTime");
if (args.Length < 2)
{
Log.getLogger().error($"Invalid Argument");
return;
}
// var session = ClientSessionManager.Instance.GetSession(player.HostId);
//
// if (session is null)
// {
// Log.getLogger().error($"session is null.");
// return;
// }
// try
// {
// ServerErrorCode errorCode = await session.ownedMail.SetRemainedTime(int.Parse(args[0]) == 0 ? false : true, int.Parse(args[1]));
// if (errorCode != ServerErrorCode.Success)
// {
// Log.getLogger().error($"HandleMailDecreaseTime Cheat Failed.");
// return;
// }
// }
// catch (Exception ex)
// {
// Log.getLogger().error($"{ex}");
// }
}
}
[ChatCommandAttribute("mailsendtome", typeof(ChatCommandMailSendToMe), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
internal class ChatCommandMailSendToMe : ChatCommandBase
{
public override async Task invoke(Player player, string token, string[] args)
{
Log.getLogger().info($"HandleMailSendToMe");
if (args.Length < 1)
{
Log.getLogger().error($"Invalid Argument");
return;
}
// var session = ClientSessionManager.Instance.GetSession(player.HostId);
// if (session is null)
// {
// Log.getLogger().error($"session is null.");
// return;
// }
//
// DateTime now = DateTime.UtcNow;
// string nickName = player._charEntity.CharInfo.DisplayName;
// try
// {
// int mailCount = int.Parse(args[0]);
//
// CharMetaDataEntity MetaDataEntity = new CharMetaDataEntity(session.ownedCharMetaDataEntity.DocumentForUpdate());
// NickNameEntity? nicknameEntity = await GameServerApp.Instance.MainDB.GetEntityFromNickName(nickName);
// if (nicknameEntity is null)
// {
// Log.getLogger().debug($"InvalidTarget. Target : {nickName}");
// return;
// }
//
// for (int i = 0; i < mailCount; ++i)
// {
// var (errorCode, mailInfo) = await session.SendMailProcess(nickName, nicknameEntity.Attr.AccountId, nicknameEntity.Attr.AccountGuid, "testTitle", "testBody", MetaDataEntity);
// if (errorCode != ServerErrorCode.Success)
// {
// Log.getLogger().error($"HandleMailDecreaseTime Cheat Failed.");
// return;
// }
// }
// }
// catch (Exception ex)
// {
// Log.getLogger().error($"{ex}");
// }
}
}
[ChatCommandAttribute("mailsendcountinit", typeof(ChatCommandMailSendCountInit), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
internal class ChatCommandMailSendCountInit : ChatCommandBase
{
public override async Task invoke(Player player, string token, string[] args)
{
Log.getLogger().info($"HandleMailSendCountInit");
// var session = ClientSessionManager.Instance.GetSession(player.HostId);
// if (session is null)
// {
// Log.getLogger().error($"session is null.");
// return;
// }
//
// if (await session.CheatMailSendUpdateDay() == false)
// {
// Log.getLogger().error($"HandleMailSendCountInit Cheat Failed.");
// return;
// }
}
}
[ChatCommandAttribute("currencymodify", typeof(ChatCommandModifyCurrency), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
internal class ChatCommandModifyCurrency : ChatCommandBase
{
public override async Task invoke(Player player, string token, string[] args)
{
var money_action = player.getEntityAction<MoneyAction>();
money_action.modifyMoney();
}
}
[ChatCommandAttribute("questreset", typeof(ChatCommandQuestReset), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
internal class ChatCommandQuestReset : ChatCommandBase
{
public override async Task invoke(Player player, string token, string[] args)
{
var quest_action = player.getEntityAction<QuestAction>();
quest_action.resetQuest();
}
}
[ChatCommandAttribute("questcomplete", typeof(ChatCommandQuestComplete), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
internal class ChatCommandQuestComplete : ChatCommandBase
{
public override async Task invoke(Player player, string token, string[] args)
{
if (args.Length < 1)
{
Log.getLogger().error($"Invalid Argument");
return;
}
if (!int.TryParse(args[0], out var questId))
{
Log.getLogger().error($"questcomplete param parsing Error args : {args[0]}");
}
var quest_action = player.getEntityAction<QuestAction>();
quest_action.questComplete(questId);
}
}
[ChatCommandAttribute("startbuff", typeof(ChatCommandStartBuff), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
internal class ChatCommandStartBuff : ChatCommandBase
{
public override async Task invoke(Player player, string token, string[] args)
{
Log.getLogger().info($"HandleStartBuff");
// var session = ClientSessionManager.Instance.GetSession(player.HostId);
// if (session is null)
// {
// Log.getLogger().error($"session is null.");
// return;
// }
//
// if (args.Length < 1)
// {
// Log.getLogger().error($"Invalid Argument");
// return;
// }
//
// try
// {
// int buffId = int.Parse(args[0]);
// var errorCode = session.StartBuff(buffId);
// if (errorCode != ServerErrorCode.Success)
// {
// Log.getLogger().error($"StartBuff Cheat Failed.");
// return;
// }
// }
// catch (Exception ex)
// {
// Log.getLogger().error($"StartBuff Cheat Failed. {ex}");
// return;
// }
}
}
[ChatCommandAttribute("addsystemmail", typeof(ChatCommandAddSystemMail), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
internal class ChatCommandAddSystemMail : ChatCommandBase
{
public override async Task invoke(Player player, string token, string[] args)
{
// Log.getLogger().info($"HandleAddSystemMail");
// await SystemMailManager.Instance.CheatFuncSaveSystemMail();
// ClientSessionManager.Instance.AllPlayerSystemMailNoti();
}
}
[ChatCommandAttribute("addnoticechat", typeof(ChatCommandAddNoticeChat), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
internal class ChatCommandAddNoticeChat : ChatCommandBase
{
public override async Task invoke(Player player, string token, string[] args)
{
// Log.getLogger().info($"HandleAddNoticeChat");
//
// if (args.Length < 3)
// {
// Log.getLogger().error($"Invalid Argument");
// return;
// }
//
// try
// {
// int messageType = int.Parse(args[0]);
// string KoMessage = args[1];
// string EnMessage = args[2];
// await NoticeChatManager.Instance.TempFuncAddData(messageType, KoMessage, EnMessage);
// }
// catch (Exception ex)
// {
// Log.getLogger().error($"AddNoticeChat cheat Failed. {ex}");
// return;
// }
}
}
[ChatCommandAttribute("userreport", typeof(ChatCommandUserReport), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
internal class ChatCommandUserReport : ChatCommandBase
{
public override async Task invoke(Player player, string token, string[] args)
{
Log.getLogger().info($"HandleUserReport");
//await player.UserReport("그리노스", "이유", "신고", "신고합니다.");
}
}
[ChatCommandAttribute("changenickname", typeof(ChatCommandChangeNickName), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
internal class ChatCommandChangeNickName : ChatCommandBase
{
public override async Task invoke(Player player, string token, string[] args)
{
Log.getLogger().info($"HandleChangeNickName");
if (args.Length < 1)
{
Log.getLogger().error($"Invalid Argument");
return;
}
try
{
//await player.changeNickName(args[0]);
}
catch (Exception ex)
{
Log.getLogger().error($"ChangeNickName cheat Failed. {ex}");
return;
}
}
}
[ChatCommandAttribute("megaphone", typeof(ChatCommandMegaPhone), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
internal class ChatCommandMegaPhone : ChatCommandBase
{
public override async Task invoke(Player player, string token, string[] args)
{
Log.getLogger().info($"HandleMegaPhone");
if (args.Length < 1)
{
Log.getLogger().error($"Invalid Argument");
return;
}
// try
// {
// ClientToGame clientMsg = new();
// clientMsg.Message = new ClientToGameMessage();
// clientMsg.Message.Chat = new();
// clientMsg.Message.Chat.Message = args[0];
// clientMsg.Message.Chat.Sender = player._charEntity.CharInfo.DisplayName;
// clientMsg.Message.Chat.Type = (int)ChatType.Channel;
// ClientSessionManager.Instance.Broadcast(player, clientMsg);
// }
// catch (Exception ex)
// {
// Log.getLogger().error($"MegaPhone Cheat Failed. {ex}");
// return;
// }
}
}
[ChatCommandAttribute("userandomboxitem", typeof(ChatCommandRandomBoxItemReward), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
internal class ChatCommandRandomBoxItemReward : ChatCommandBase
{
public override async Task invoke(Player player, string token, string[] args)
{
var randombox_item_action = player.getEntityAction<RandomBoxItemUseAction>();
randombox_item_action.useRandomBoxItem();
}
}
[ChatCommandAttribute("socialactionall", typeof(ChatCommandSocialActionAll), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
internal class ChatCommandSocialActionAll : ChatCommandBase
{
public override async Task invoke(Player player, string token, string[] args)
{
// Log.getLogger().info($"HandleSocialActionAll");
// var session = ClientSessionManager.Instance.GetSession(player.HostId);
// if (session is null)
// {
// Log.getLogger().error($"session is null.");
// return;
// }
//
// await session.ownedSocialAction.AllSocialActionCollectionsSetting();
// session.ownedSocialAction.SendInfo(session.HostId);
}
}
[ChatCommandAttribute("storereset", typeof(ChatCommandStoreReset), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
internal class ChatCommandStoreReset : ChatCommandBase
{
public override async Task invoke(Player player, string token, string[] args)
{
// Log.getLogger().info($"HandleStoreReset");
// var session = ClientSessionManager.Instance.GetSession(player.HostId);
// if (session is null)
// {
// Log.getLogger().error($"session is null.");
// return;
// }
//
// ClientToGame clientMsg = new();
// clientMsg.Message = new ClientToGameMessage();
// clientMsg.Message.Chat = new();
// clientMsg.Message.Chat.Sender = "Cheat";
// clientMsg.Message.Chat.Type = ChatType.System;
//
// ServerErrorCode errorCode = await session.ownedShop.CheatInitResetTime();
// if (errorCode.isFail())
// {
// Log.getLogger().error($"Cheat Store Reset Failed. error : {errorCode}.");
// clientMsg.Message.Chat.Message = "Cheat Failed.";
// player.Send(clientMsg);
// return;
// }
// clientMsg.Message.Chat.Message = "StoreReset Complete.";
// player.Send(clientMsg);
}
}
[ChatCommandAttribute("methodtest", typeof(ChatCommandMethodTest), AuthAdminLevelType.Developer)]
internal class ChatCommandMethodTest : ChatCommandBase
{
public override async Task invoke(Player player, string token, string[] args)
{
}
}
[ChatCommandAttribute("sessionkeepalivetime", typeof(ChatCommandSessionKeepAliveTime), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
internal class ChatCommandSessionKeepAliveTime : ChatCommandBase
{
public override async Task invoke(Player player, string token, string[] args)
{
// Log.getLogger().info($"handleSessionKeepAliveTime");
// var session = ClientSessionManager.Instance.GetSession(player.HostId);
// if (session is null)
// {
// Log.getLogger().error($"session is null.");
// return;
// }
//
// var keep_alive_minutes = int.Parse(args[0]);
//
// GameServer.Instance._srv.SetTimeoutTimeMs(player.HostId, keep_alive_minutes * 60 * 1000);
}
}
[ChatCommandAttribute("leveluptattoo", typeof(ChatCommandLevelUpTattoo), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
internal class ChatCommandLevelUpTattoo : ChatCommandBase
{
public override async Task invoke(Player player, string token, string[] args)
{
// Log.getLogger().info($"HandleLevelUpTattoo");
// var session = ClientSessionManager.Instance.GetSession(player.HostId);
// if (session is null || session._selectedChar is null)
// {
// Log.getLogger().error($"session is null.");
// return;
// }
//
// var slot = int.Parse(args[0]);
// var ItemGuid = session._selectedChar.GetTattooGuidFromSlot(slot);
// if (ItemGuid == string.Empty)
// {
// return;
// }
//
// List<ILogInvoker> invokers = new List<ILogInvoker>();
// var log_action = new LogActionEx(LogActionType.CheatCommandItemLevelUp);
//
// var itemlogDatas = await session.LevelUpTattoo(ItemGuid);
// if (itemlogDatas == null)
// {
// return;
// }
//
// foreach (var itemInfoLog in itemlogDatas)
// {
// //invokers.Add(new ItemLog(itemInfoLog));
// }
// BusinessLogger.collectLogs(log_action, session._selectedChar, invokers);
}
}
*/
}