Repository navigation
fix(admin-api): 管理面启动输出无鉴权全网卡监听告警 #973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| { | ||
| "$schema": "http://json.schemastore.org/template", | ||
| "author": "GameFrameX", | ||
| "classifications": [ | ||
| "GameFrameX", | ||
| "Game", | ||
| "Starter" | ||
| ], | ||
| "identity": "GameFrameX.GameStarter", | ||
| "name": "GameFrameX 游戏起点工程", | ||
| "shortName": "gfx-game", | ||
| "tags": { | ||
| "language": "C#", | ||
| "type": "project" | ||
| }, | ||
| "description": "生成「用 GameFrameX 做一个游戏」的独立起点工程:以 2.0 NuGet 包消费框架 Online 能力(缺省黄金路径最小集 Foundation+Match+Assets+Leaderboard+Competition,零配置开箱即通)。注意:2.0 包当前仅内部 feed 分发,nuget.config 缺省指向生成目录旁的 ../LocalPackages(需与 GameFrameX 源码仓同级摆放方可还原;公开发布后改指 nuget.org)。完整官方示例见 Server 游戏仓(四子棋接 Online 桥)。", | ||
| "symbols": { | ||
| "Name": { | ||
| "type": "parameter", | ||
| "datatype": "string", | ||
| "description": "游戏工程名(PascalCase,如 MyGame);参与工程名/目录与 Program 装配代码替换", | ||
| "isRequired": true, | ||
| "replaces": "{{Name}}", | ||
| "fileRename": "{{Name}}" | ||
| } | ||
| }, | ||
| "primaryOutputs": [ | ||
| { | ||
| "path": "{{Name}}\\{{Name}}.csproj" | ||
| } | ||
| ], | ||
| "postActions": [ | ||
| { | ||
| "id": "restore", | ||
| "condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\") || (HostIdentifier == \"dotnetcli\" && SkipRestore != true)", | ||
| "description": "还原工程引用的 NuGet 包", | ||
| "manualInstructions": [ | ||
| { | ||
| "text": "dotnet restore" | ||
| } | ||
| ], | ||
| "actionId": "210D431B-A78B-4D2F-B762-DFEA895BB429" | ||
| } | ||
| ] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| // ========================================================================================== | ||
| // GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 | ||
| // GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights | ||
| // 均受中华人民共和国及相关国际法律法规保护。 | ||
| // are protected by the laws and regulations of the People's Republic of China and relevant international regulations. | ||
| // | ||
| // 使用本项目须严格遵守相应法律法规与开源许可证之规定。 | ||
| // Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. | ||
| // | ||
| // 本项目采用 MIT 许可证与 Apache License 2.0 双许可证分发, | ||
| // This project is dual-licensed under the MIT License and Apache License 2.0, | ||
| // 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 | ||
| // please refer to the LICENSE file at the root of the source code for the full license text. | ||
| // | ||
| // 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 | ||
| // It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, | ||
| // 侵犯其他合法权益等法律法规所禁止的行为! | ||
| // or infringe upon the legitimate rights and interests of others as prohibited by laws and regulations. | ||
| // | ||
| // 因基于本项目二次开发所产生的一切法律纠纷与责任, | ||
| // Any legal disputes or liabilities arising from secondary development of this project | ||
| // 本项目组织与贡献者概不承担。 | ||
| // shall be borne solely by the developer; the project organization and contributors assume no responsibility. | ||
| // | ||
| // GitHub 仓库:https://github.com/GameFrameX | ||
| // GitHub Repository: https://github.com/GameFrameX | ||
| // Gitee 仓库:https://gitee.com/GameFrameX | ||
| // Gitee Repository: https://gitee.com/GameFrameX | ||
| // 官方文档:https://gameframex.doc.alianblank.com/ | ||
| // Official Documentation: https://gameframex.doc.alianblank.com/ | ||
| // ========================================================================================== | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using GameFrameX.Capability.Online.Abstractions.Contracts; | ||
|
|
||
| namespace {{Name}}; | ||
|
Check warning on line 38 in GameFrameX.Templates/templates/gfx-game/{{Name}}/EmptyPlayerDirectory.cs
|
||
|
|
||
| /// <summary> | ||
| /// 最小宿主的玩家目录(满足 online-social 以 RequireHostService 声明的宿主扩展点)。 | ||
| /// <para> | ||
| /// 维护约束:本宿主不接玩家库,搜索与查找恒返回空集合——好友搜索无结果、好友展示名为空, | ||
| /// 其余社交功能不受影响。接入真实玩家数据时替换为读取玩家库的实现,并在 Program.cs 的 Override 处更换实例。 | ||
| /// </para> | ||
| /// </summary> | ||
| public sealed class EmptyPlayerDirectory : IOnlinePlayerDirectory | ||
|
Check warning on line 47 in GameFrameX.Templates/templates/gfx-game/{{Name}}/EmptyPlayerDirectory.cs
|
||
| { | ||
| /// <summary> | ||
| /// 模板缺省实现:最小 Online 宿主没有玩家存储,任何关键字搜索都返回空列表;接入真实玩家数据时须替换本类。 | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Template default: the minimal Online host has no player store, so every name search returns an empty list. | ||
| /// Replace this class when wiring real player data. | ||
| /// </remarks> | ||
| /// <param name="keyword">名称关键字(未使用) / Name keyword (unused)</param> | ||
| /// <param name="limit">最大返回条数(未使用) / Maximum number of entries (unused)</param> | ||
| /// <param name="cancellationToken">取消令牌(未使用) / Cancellation token (unused)</param> | ||
| /// <returns>已完成的空列表任务 / Completed task with an empty list</returns> | ||
| public Task<IReadOnlyList<OnlinePlayerDirectoryEntry>> SearchByNameAsync(string keyword, int limit, CancellationToken cancellationToken = default) | ||
|
Check warning on line 60 in GameFrameX.Templates/templates/gfx-game/{{Name}}/EmptyPlayerDirectory.cs
|
||
| { | ||
| return Task.FromResult<IReadOnlyList<OnlinePlayerDirectoryEntry>>(new List<OnlinePlayerDirectoryEntry>()); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// 模板缺省实现:最小 Online 宿主没有玩家存储,任何 ID 查询都返回空列表;接入真实玩家数据时须替换本类。 | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Template default: the minimal Online host has no player store, so every ID lookup returns an empty list. | ||
| /// Replace this class when wiring real player data. | ||
| /// </remarks> | ||
| /// <param name="playerIds">玩家 ID 列表(未使用) / Player IDs (unused)</param> | ||
| /// <param name="cancellationToken">取消令牌(未使用) / Cancellation token (unused)</param> | ||
| /// <returns>已完成的空列表任务 / Completed task with an empty list</returns> | ||
| public Task<IReadOnlyList<OnlinePlayerDirectoryEntry>> FindAsync(IReadOnlyList<long> playerIds, CancellationToken cancellationToken = default) | ||
|
Check warning on line 75 in GameFrameX.Templates/templates/gfx-game/{{Name}}/EmptyPlayerDirectory.cs
|
||
| { | ||
| return Task.FromResult<IReadOnlyList<OnlinePlayerDirectoryEntry>>(new List<OnlinePlayerDirectoryEntry>()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| // ========================================================================================== | ||
| // GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 | ||
| // GameFrameX organization and its derivative projects' copyrights, trademarks, patents and related rights | ||
| // 均受中华人民共和国及相关国际法律法规保护。 | ||
| // are protected by the laws of the People's Republic of China and international regulations. | ||
| // 使用本项目须严格遵守相应法律法规与开源许可证之规定。 | ||
| // Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. | ||
| // 本项目采用 Apache License 2.0 单协议分发, | ||
| // This project is licensed solely under the Apache License 2.0, | ||
| // 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 | ||
| // please see the LICENSE file in the root directory of the source code for the full license text. | ||
| // ========================================================================================== | ||
|
|
||
| using System; | ||
| using System.Text.Json; | ||
| using System.Threading; | ||
| using GameFrameX.Capability.Hosting.AdminApi; | ||
| using GameFrameX.Capability.Hosting.Core; | ||
| using GameFrameX.Capability.Online.Abstractions; | ||
| using GameFrameX.Capability.Online.Abstractions.Contracts; | ||
|
|
||
| using {{Name}}; | ||
|
Check warning on line 22 in GameFrameX.Templates/templates/gfx-game/{{Name}}/Program.cs
|
||
|
|
||
| // {{Name}} —— 用 GameFrameX 做一个游戏的起点(gfx-game 模板生成)。 | ||
| // 独立工程:以 GameFrameX 2.0 NuGet 包消费框架能力,引啥装配啥—— | ||
| // CapabilityComposition.Compose 按 Online 族部署前缀扫描本进程加载的能力包, | ||
| // csproj 引用了哪些能力包就装配哪些能力(编译期保证)。缺省勾选黄金路径最小集: | ||
| // 开局 → 对局裁决 → 结算 → 发奖(统一资产入口)→ 默认榜上榜,零 JSON 配置开箱即通。 | ||
| // 参考:官方游戏仓 https://github.com/GameFrameX/GameFrameX.Server (四子棋完整活演示)。 | ||
|
|
||
| // 授权作用域区服键(单键化:作用域只剩 ServerId;接入配置管道时改走嵌套强类型段 "Online": { ... })。 | ||
| const long serverId = 1; | ||
|
|
||
| // 族配置段(零 Settings = 全部走包内默认参数)。 | ||
| var familyConfigurationSection = JsonSerializer.SerializeToElement(new | ||
| { | ||
| ServerId = serverId, | ||
| Settings = new { }, | ||
| }); | ||
|
|
||
| var options = new CapabilityCompositionOptions(familyConfigurationSection, new ConsoleCapabilityAssemblyLog()); | ||
| options.HostOptions.ServerId = serverId; | ||
|
|
||
| // 管理面:admin action 注册 + 元端点(list_capability_services / list_capability_settings / query_leaderboard 等)。 | ||
| options.UseAdminApi(adminOptions => | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 不要默认开放无鉴权管理面。 新工程会在所有网卡开放管理端口。任何能访问该端口的人都可以使用默认的
|
||
| { | ||
| adminOptions.AdminPort = 28092; | ||
| adminOptions.AdminApiPrefix = "online/admin"; | ||
| }); | ||
|
|
||
| // 宿主扩展点:能力以 RequireHostService 声明、包内无默认实现,宿主必须 Override 提供(缺失 = 装配期 fail-fast)。 | ||
| // 玩家目录供 online-social 好友搜索使用;本起点工程不接玩家库,提供空目录。 | ||
| options.Override<IOnlinePlayerDirectory>(new EmptyPlayerDirectory()); | ||
| // 唯一组合入口:族骨架 + 机制装配(依赖检查、拓扑定序、Options 绑定、装配日志一次报全)。 | ||
| var runtime = CapabilityComposition.Compose(new OnlineCapabilityFamily(), options); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| await runtime.StartAsync(); | ||
|
|
||
| Console.WriteLine("[{{Name}}] 游戏宿主已启动。已装配能力(拓扑序): {0}", string.Join(", ", runtime.Report.EnabledIdsInOrder)); | ||
| Console.WriteLine("[{{Name}}] 管理面: POST http://<主机>:28092/online/admin/{{action}}(监听本机所有网卡,无鉴权,仅限内网/可信环境使用)"); | ||
| Console.WriteLine("[{{Name}}] 按 Ctrl+C 退出。"); | ||
|
|
||
| var shutdown = new ManualResetEventSlim(false); | ||
| Console.CancelKeyPress += (_, eventArgs) => | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 让 SIGTERM 触发宿主停止。 Linux 容器停止时通常发送 SIGTERM,但这里仅监听
|
||
| { | ||
| eventArgs.Cancel = true; | ||
| shutdown.Set(); | ||
| }; | ||
| shutdown.Wait(); | ||
|
|
||
| await runtime.StopAsync(); | ||
| Console.WriteLine("[{{Name}}] 已停止。"); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <configuration> | ||
| <packageSources> | ||
| <clear /> | ||
| <!-- GameFrameX 2.0 包还原源(内部验证期): | ||
| 相对路径按「生成工程所在目录」解析,即 LocalPackages 必须位于生成工程目录的父目录下 | ||
| (GameFrameX 源码仓 `dotnet pack` 产物投放目录,与生成工程同级摆放);缺失或摆放不符将还原失败 NU1301。 | ||
| GameFrameX 2.0 公开发布至 nuget.org 后:删除下面的 GameFrameX-Internal 源即可(2.0.0 当前不在 nuget.org)。 --> | ||
| <add key="GameFrameX-Internal" value="../LocalPackages" /> | ||
| <add key="nuget.org" value="https://api.nuget.org/v3/index.json" /> | ||
| </packageSources> | ||
| </configuration> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <!-- 独立用户游戏工程(gfx-game 模板生成):以 GameFrameX 2.0 NuGet 包消费框架能力,可在任意目录构建运行。 --> | ||
| <IsPackable>false</IsPackable> | ||
| <LangVersion>latest</LangVersion> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <!-- 引啥装配啥(编译期保证):Compose 按部署前缀扫描能力包,本工程只引用所选能力包,引用集即装配集。 | ||
| 本模板缺省勾选黄金路径最小集(Foundation + Social + Match + Assets + Leaderboard + Competition): | ||
| 开局 → 对局裁决 → 结算 → 发奖 → 默认榜上榜开箱即通;增减能力 = 只增删 PackageReference。 --> | ||
| <PackageReference Include="GameFrameX.Capability.Hosting.AdminApi" Version="2.0.0" /> | ||
| <PackageReference Include="GameFrameX.Capability.Online.Foundation" Version="2.0.0" /> | ||
| <PackageReference Include="GameFrameX.Capability.Online.Social" Version="2.0.0" /> | ||
| <PackageReference Include="GameFrameX.Capability.Online.Assets" Version="2.0.0" /> | ||
| <PackageReference Include="GameFrameX.Capability.Online.Match" Version="2.0.0" /> | ||
| <PackageReference Include="GameFrameX.Capability.Online.Leaderboard" Version="2.0.0" /> | ||
| <PackageReference Include="GameFrameX.Capability.Online.Competition" Version="2.0.0" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改用已注册的 NuGet 还原操作 ID。
当前
actionId不是 .NET SDK 的还原操作 ID。执行dotnet new gfx-game时,模板无法通过该后置操作自动还原项目。请将其改为210D431B-A78B-4D2F-B762-4ED3E3EA9025。用户仍可手动运行dotnet restore。(github.com)建议修改
Committable suggestion