milimoe d35f9aa81a
服务器结构调整;添加 APIBearer;修复强制下线的目标客户端错误的问题 (#46)
* 服务器结构调整;添加 APIBearer

* Server.exe 需要初始化用户密钥列表,UeerKeys 均需要小写用户名保存和读取

* 修复强制下线的目标客户端错误的问题
2025-03-17 00:49:58 +08:00

118 lines
4.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Milimoe.FunGame.Core.Interface.Base;
using Milimoe.FunGame.Core.Library.Common.Addon;
using Milimoe.FunGame.Server.Others;
using Milimoe.FunGame.Server.Services;
namespace Milimoe.FunGame.Server.Model
{
public class ConsoleModel
{
public static async Task Order<T>(ISocketListener<T>? server, string order) where T : ISocketMessageProcessor
{
try
{
switch (order)
{
case OrderDictionary.Kick:
{
ServerHelper.Write("输入需要踢出的客户端名称:");
string client = Console.ReadLine() ?? "";
if (client != "" && server != null)
{
await Kick((ServerModel<T>)server.ClientList[client]);
}
break;
}
case OrderDictionary.Logout:
{
ServerHelper.Write("输入需要强制下线的玩家ID");
string user = Console.ReadLine() ?? "";
if (user != "" && server != null)
{
await ForceLogOut((ServerModel<T>)server.UserList[user]);
}
break;
}
case OrderDictionary.ShowList:
ShowClients(server);
ShowUsers(server);
break;
case OrderDictionary.ShowClients1:
case OrderDictionary.ShowClients2:
ShowClients(server);
break;
case OrderDictionary.ShowUsers1:
case OrderDictionary.ShowUsers2:
ShowUsers(server);
break;
case OrderDictionary.Help:
ShowHelp();
break;
default:
break;
}
// 广播到插件
if (FunGameSystem.ServerPluginLoader != null)
{
foreach (ServerPlugin plugin in FunGameSystem.ServerPluginLoader.Plugins.Values)
{
plugin.ProcessInput(order);
}
}
if (FunGameSystem.WebAPIPluginLoader != null)
{
foreach (WebAPIPlugin plugin in FunGameSystem.WebAPIPluginLoader.Plugins.Values)
{
plugin.ProcessInput(order);
}
}
}
catch (Exception e)
{
ServerHelper.Error(e);
}
}
public static async Task Kick<T>(ServerModel<T> clientModel) where T : ISocketMessageProcessor
{
await clientModel.Kick("您已被服务器管理员踢出此服务器。");
}
public static async Task ForceLogOut<T>(ServerModel<T> clientModel) where T : ISocketMessageProcessor
{
await clientModel.ForceLogOut("您已被服务器管理员强制下线。");
}
public static void ShowClients<T>(ISocketListener<T>? server) where T : ISocketMessageProcessor
{
if (server != null)
{
ServerHelper.WriteLine("显示在线客户端列表");
int index = 1;
foreach (IServerModel client in server.ClientList)
{
ServerHelper.WriteLine(index++ + ". " + client.ClientName + (client.User.Id != 0 ? " (已登录为:" + client.User.Username + ")" : ""));
}
}
}
public static void ShowUsers<T>(ISocketListener<T>? server) where T : ISocketMessageProcessor
{
if (server != null)
{
ServerHelper.WriteLine("显示在线玩家列表");
int index = 1;
foreach (IServerModel user in server.UserList.Where(u => u.User.Id != 0))
{
ServerHelper.WriteLine(index++ + ". " + (user.User.Username) + " (客户端:" + user.ClientName + ")");
}
}
}
public static void ShowHelp()
{
ServerHelper.WriteLine("Milimoe -> 帮助");
}
}
}