![]() |
VOOZH | about |
dotnet add package GameFrameX.AppHost.ServiceDefaults --version 1.10.3
NuGet\Install-Package GameFrameX.AppHost.ServiceDefaults -Version 1.10.3
<PackageReference Include="GameFrameX.AppHost.ServiceDefaults" Version="1.10.3" />
<PackageVersion Include="GameFrameX.AppHost.ServiceDefaults" Version="1.10.3" />Directory.Packages.props
<PackageReference Include="GameFrameX.AppHost.ServiceDefaults" />Project file
paket add GameFrameX.AppHost.ServiceDefaults --version 1.10.3
#r "nuget: GameFrameX.AppHost.ServiceDefaults, 1.10.3"
#:package GameFrameX.AppHost.ServiceDefaults@1.10.3
#addin nuget:?package=GameFrameX.AppHost.ServiceDefaults&version=1.10.3Install as a Cake Addin
#tool nuget:?package=GameFrameX.AppHost.ServiceDefaults&version=1.10.3Install as a Cake Tool
<div align="center">
π Version
π .NET
π Documentation
High-Performance, Cross-Platform Game Server Framework
π Documentation β’ π Quick Start β’ π¬ QQ Group: 467608841
π Language: English | | | |
</div>
GameFrameX Server is a high-performance, cross-platform game server framework built with C# .NET 10.0, designed with the Actor model and supporting hot update mechanisms. Designed for multiplayer online game development, it supports integration with various client platforms including Unity3D, Godot, and LayaBox.
Design Philosophy: Simplicity is the ultimate sophistication
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Client Layer β
β Unity3D / Godot / LayaBox / Cocos Creator β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Network Layer β
β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ β
β β TCP β βWebSocket β β HTTP β β KCP β β
β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Message Processing Layer β
β ββββββββββββββββββ ββββββββββββββββββ ββββββββββββββββββ β
β βTCP Msg Handlersβ β HTTP Handlers β βCross-Proc Routerβ β
β ββββββββββββββββββ ββββββββββββββββββ ββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Actor Layer β
β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ β
β β Player β β Server β β Account β β Global β β
β β Actor β β Actor β β Actor β β Actor β β
β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Component-Agent Layer (Hot Update Boundary) β
β βββββββββββββββββββββββ βββββββββββββββββββββββββββββββ β
β β Apps Layer (Static) β β Hotfix Layer (Hot-updatable) β β
β β StateComponent<T> ββββ StateComponentAgent<T,TState>β β
β β CacheState β β ComponentAgent β β
β βββββββββββββββββββββββ βββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Database Layer β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β MongoDB β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Server/
βββ GameFrameX.Launcher/ # Application entry point
βββ GameFrameX.StartUp/ # Startup orchestration and initialization
βββ GameFrameX.Core/ # Core framework (Actor system, components, events, hot update management)
βββ GameFrameX.Apps/ # State data layer (Account, Player, Server modules) β not hot-updatable
βββ GameFrameX.Hotfix/ # Business logic layer (HTTP, Player, Server handlers) β hot-updatable
βββ GameFrameX.Config/ # Game configuration tables (JSON format, generated by LuBan)
βββ GameFrameX.Core.Config/ # Core configuration management
βββ GameFrameX.Proto/ # ProtoBuf protocol definitions
βββ GameFrameX.ProtoBuf.Net/ # ProtoBuf serialization implementation
βββ GameFrameX.NetWork/ # Network core (message objects, sender, WebSocket)
βββ GameFrameX.NetWork.Abstractions/ # Network interfaces (IMessage, IMessageHandler, message mapping)
βββ GameFrameX.NetWork.HTTP/ # HTTP server (Swagger, Kestrel, BaseHttpHandler)
βββ GameFrameX.NetWork.Kcp/ # KCP protocol support (UDP-based reliable transport)
βββ GameFrameX.NetWork.Message/ # Message pipeline and codec
βββ GameFrameX.NetWork.RemoteMessaging/ # Cross-process remote messaging (circuit breaker, retry, consistent hashing)
βββ GameFrameX.DataBase/ # Database abstraction layer
βββ GameFrameX.DataBase.Mongo/ # MongoDB implementation (health monitoring, retry, batch operations)
βββ GameFrameX.Localization/ # Localization system (Keys.*.cs + .resx resource files)
βββ GameFrameX.Monitor/ # OpenTelemetry + Prometheus metrics integration
βββ GameFrameX.Utility/ # Utilities (logging, compression, object pool, Mapster, Harmony)
βββ GameFrameX.Client/ # Test client (TCP connection)
βββ GameFrameX.Architecture.Analyzers/ # Roslyn architecture analyzers
βββ GameFrameX.Hotfix.WrapperGenerator/ # Roslyn source generator (hot update proxy wrapper classes)
βββ GameFrameX.AppHost/ # .NET Aspire application host
βββ GameFrameX.AppHost.ServiceDefaults/ # Aspire shared defaults (OTel, service discovery)
βββ Tests/
βββ GameFrameX.Tests/ # xUnit test suite
Clone the Repository
git clone https://github.com/GameFrameX/GameFrameX.git
cd GameFrameX/Server
Restore Dependencies
dotnet restore
Build the Project
dotnet build
Start MongoDB
# Local installation
mongod --dbpath /path/to/data
# Or use Docker
docker run -d -p 27017:27017 --name mongo mongo:8.2
Run the Server
dotnet run --project GameFrameX.Launcher -- \
--ServerType=Game \
--ServerId=1000 \
--OuterPort=29100 \
--HttpPort=28080 \
--DataBaseUrl=mongodb://127.0.0.1:27017 \
--DataBaseName=gameframex
Verify Startup
http://localhost:28080/game/api/healthGameFrameX uses command-line arguments (--Key=Value) for configuration. All configuration items are defined in the StartupOptions class.
| Option | Description | Default | Example |
|---|---|---|---|
ServerType |
Server type (required) | None | Game, Social |
ServerId |
Unique server ID | None | 1000 |
ServerInstanceId |
Server instance ID (distinguishes different instances of the same type) | 0 |
1001 |
IsSingleMode |
Single process mode | false |
true |
MinModuleId |
Business module start ID (module sharding) | 0 |
100 |
MaxModuleId |
Business module end ID (module sharding) | 0 |
1000 |
TimeZone |
Server timezone | Asia/Shanghai |
UTC |
IsUseTimeZone |
Enable custom timezone | false |
true |
Language |
Language setting | None | zh-CN |
| Option | Description | Default | Example |
|---|---|---|---|
InnerHost |
Internal communication IP (inter-cluster) | 0.0.0.0 |
0.0.0.0 |
InnerPort |
Internal communication port | 8888 |
29100 |
OuterHost |
External communication IP (client-facing) | 0.0.0.0 |
0.0.0.0 |
OuterPort |
External communication port | None | 29100 |
IsEnableTcp |
Enable TCP service | true |
true |
IsEnableUdp |
Enable UDP service | false |
true |
IsEnableWebSocket |
Enable WebSocket | false |
true |
WsPort |
WebSocket port | 8889 |
29300 |
IsEnableHttp |
Enable HTTP service | true |
true |
HttpPort |
HTTP service port | 8080 |
28080 |
HttpsPort |
HTTPS service port | None | 443 |
HttpUrl |
API root path | /game/api/ |
/game/api/ |
HttpIsDevelopment |
HTTP development mode (enables Swagger) | false |
true |
| Option | Description | Default | Example |
|---|---|---|---|
DataBaseUrl |
MongoDB connection string | None | mongodb://localhost:27017 |
DataBaseName |
Database name | None | gameframex |
DataBasePassword |
Database password | None | your_password |
| Option | Description | Default | Example |
|---|---|---|---|
ActorTimeOut |
Actor task execution timeout (ms) | 30000 |
60000 |
ActorQueueTimeOut |
Actor queue timeout (ms) | 30000 |
60000 |
ActorRecycleTime |
Actor idle recycle time (minutes) | 15 |
30 |
SaveDataInterval |
Data save interval (ms) | 30000 |
60000 |
SaveDataBatchCount |
Batch save count | 500 |
1000 |
SaveDataBatchTimeOut |
Batch save timeout (ms) | 30000 |
60000 |
| Option | Description | Default | Example |
|---|---|---|---|
IsDebug |
Debug logging master switch | false |
true |
LogIsConsole |
Output to console | true |
false |
LogIsWriteToFile |
Output to file | true |
false |
LogEventLevel |
Log level | Debug |
Information |
LogRollingInterval |
Log rolling interval | Day |
Hour |
LogIsFileSizeLimit |
Limit single file size | true |
false |
LogFileSizeLimitBytes |
File size limit | 104857600 (100MB) |
52428800 |
LogRetainedFileCountLimit |
Retained file count | 31 |
90 |
LogIsGrafanaLoki |
Output to Grafana Loki | false |
true |
LogGrafanaLokiUrl |
Grafana Loki URL | http://localhost:3100 |
β |
| Option | Description | Default | Example |
|---|---|---|---|
IsOpenTelemetry |
Enable OpenTelemetry | false |
true |
IsOpenTelemetryMetrics |
Enable metrics collection | false |
true |
IsOpenTelemetryTracing |
Enable distributed tracing | false |
true |
MetricsPort |
Prometheus metrics port | 0 (reuses HTTP port) |
9090 |
IsMonitorMessageTimeOut |
Monitor message processing timeout | false |
true |
MonitorMessageTimeOutSeconds |
Timeout threshold (seconds) | 1 |
5 |
| Option | Description | Default | Example |
|---|---|---|---|
WorkerId |
Snowflake ID worker node ID | 1 |
2 |
DataCenterId |
Snowflake ID data center ID | 1 |
2 |
# Minimal startup parameters
dotnet GameFrameX.Launcher.dll \
--ServerType=Game \
--ServerId=1000 \
--DataBaseUrl=mongodb://127.0.0.1:27017 \
--DataBaseName=game_db
# Full startup parameters
dotnet GameFrameX.Launcher.dll \
--ServerType=Game \
--ServerId=1000 \
--ServerInstanceId=1 \
--InnerHost=0.0.0.0 \
--InnerPort=29100 \
--OuterHost=0.0.0.0 \
--OuterPort=29100 \
--HttpPort=28080 \
--IsEnableHttp=true \
--HttpIsDevelopment=true \
--IsEnableWebSocket=false \
--DataBaseUrl=mongodb://127.0.0.1:27017 \
--DataBaseName=gameframex \
--IsDebug=true \
--IsOpenTelemetry=true \
--IsOpenTelemetryMetrics=true \
--LogIsConsole=true \
--LogIsWriteToFile=true
The core design pattern of the framework is state-logic separation, strictly separating persistent state (Apps layer, not hot-updatable) from business logic (Hotfix layer, hot-updatable).
1. Define State (Apps Layer)
// GameFrameX.Apps/Player/BagState.cs
public class BagState : BaseCacheState
{
public List<ItemData> Items { get; set; } = new List<ItemData>();
public int MaxSlots { get; set; } = 50;
}
2. Create Component (Apps Layer)
// GameFrameX.Apps/Player/BagComponent.cs
public class BagComponent : StateComponent<BagState>
{
protected override async Task OnInit()
{
await base.OnInit();
// Initialize component state
}
}
3. Implement Business Logic (Hotfix Layer)
// GameFrameX.Hotfix/Logic/Player/BagComponentAgent.cs
public class BagComponentAgent : StateComponentAgent<BagComponent, BagState>
{
public async Task<bool> AddItem(int itemId, int count)
{
if (State.Items.Count >= State.MaxSlots)
{
return false;
}
var item = new ItemData { Id = itemId, Count = count };
State.Items.Add(item);
await Save();
return true;
}
}
4. Access Component Agent
// Get component agent via ActorManager
var bagAgent = await ActorManager.GetComponentAgent<BagComponentAgent>(playerId);
var result = await bagAgent.AddItem(1001, 10);
HTTP handlers inherit BaseHttpHandler and use the [HttpMessageMapping] attribute to register routes.
[HttpMessageMapping(typeof(GetPlayerInfoHandler))]
[Description("Get player info")]
public sealed class GetPlayerInfoHandler : BaseHttpHandler
{
public override async Task<MessageObject> Action(
string ip, string url,
Dictionary<string, object> parameters,
MessageObject messageObject)
{
var request = (GetPlayerInfoRequest)messageObject;
var response = new GetPlayerInfoResponse();
var agent = await ActorManager.GetComponentAgent<PlayerComponentAgent>(request.PlayerId);
if (agent == null)
{
response.ErrorCode = (int)ResultCode.PlayerNotFound;
return response;
}
response.PlayerInfo = await agent.GetPlayerInfo();
return response;
}
}
TCP message handlers process game messages sent by clients via TCP connections.
One-way Message Handler:
[MessageMapping(typeof(ReqChatMessage))]
internal sealed class ChatMessageHandler : PlayerComponentHandler<ChatComponentAgent, ReqChatMessage>
{
protected override async Task ActionAsync(ReqChatMessage request)
{
await ComponentAgent.ProcessChatMessage(request);
}
}
RPC Handler (Request-Response):
[MessageMapping(typeof(ReqAddItem))]
internal sealed class AddItemHandler : PlayerRpcComponentHandler<BagComponentAgent, ReqAddItem, RespAddItem>
{
protected override async Task ActionAsync(ReqAddItem request, RespAddItem response)
{
try
{
// ComponentAgent is automatically injected by the base class
await ComponentAgent.AddItem(request, response);
}
catch (Exception e)
{
LogHelper.Fatal(e);
response.ErrorCode = (int)OperationStatusCode.InternalServerError;
}
}
}
The event system is used for loosely coupled communication between Actors.
[Event(EventId.PlayerLogin)]
internal sealed class PlayerLoginEventHandler : EventListener<PlayerComponentAgent>
{
protected override Task HandleEvent(PlayerComponentAgent agent, GameEventArgs gameEventArgs)
{
if (agent == null)
{
return Task.CompletedTask;
}
// Handle player login event
return agent.OnLogin();
}
}
The hot update system implements runtime loading and unloading of assemblies through AssemblyLoadContext (collectible):
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Apps Layer (Not hot-updatable) β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β βStateComponentβ βStateComponentβ βStateComponentβ β
β β Persist Stateβ β Persist Stateβ β Persist Stateβ β
β ββββββββ¬βββββββ ββββββββ¬βββββββ ββββββββ¬βββββββ β
β β β β β
βββββββββββΌβββββββββββββββββΌβββββββββββββββββΌββββββββββββ€
β βΌ βΌ βΌ β
β Hotfix Layer (Hot-updatable) β Loaded via β
β AssemblyLoadContext β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β βComponentAgentβ βComponentAgentβ βComponentAgentβ β
β βBusiness Logicβ βBusiness Logicβ βBusiness Logicβ β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β Msg Handler β β EventHandlerβ β HttpHandler β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
GameFrameX.Hotfix.dllHotfixManager loads the new DLL using a collectible AssemblyLoadContextHotfixModule scans the new assembly for agents, handlers, and event listenersActorManager.ClearAgent() clears cached agent instances# Trigger hot update (with specified version)
curl -X POST "http://localhost:28080/game/api/Reload?version=1.7.2"
Use docker-compose.yml to start a complete environment with MongoDB + Game + Social:
# Build and start
docker compose up -d --build
# View running status
docker compose ps
# View logs
docker compose logs -f game social
# Stop
docker compose down
Service port mapping:
| Service | Container Port | Host Port | Description |
|---|---|---|---|
| MongoDB | 27017 | 37017 | Database |
| Game TCP | 29100 | 39100 | Game server |
| Game HTTP | 28080 | 38080 | Game server HTTP API |
| Social TCP | 29400 | 39400 | Social server |
| Social HTTP | 28081 | 38081 | Social server HTTP API |
Use docker-compose.multi.yml to start a cluster with 1 MongoDB + 2 Social + 10 Game instances:
# Build and start
docker compose -f docker-compose.multi.yml up -d --build
# View running status
docker compose -f docker-compose.multi.yml ps
# Stop
docker compose -f docker-compose.multi.yml down
Cluster topology:
| Component | Instances | Description |
|---|---|---|
| MongoDB | 1 | Shared database |
| Social | 2 | Social servers (social-1, social-2) |
| Game | 10 | Game servers (game-1 ~ game-10) |
All instances use Aspire-style environment variables for service discovery:
environment:
services__Social_2001__tcp__0: "tcp://social-1:29400"
services__Social_2002__tcp__0: "tcp://social-2:29401"
services__Game_1001__tcp__0: "tcp://game-1:29100"
# ...
# Build image
docker build -t gameframex/server:custom .
# Run
docker run -d \
--name my-game-server \
-p 29100:29100 \
-p 28080:28080 \
gameframex/server:custom \
--ServerType=Game \
--ServerId=2000 \
--DataBaseUrl=mongodb://mongo-host:27017 \
--DataBaseName=my_game
# Ensure multi-instance environment is running
docker compose -f docker-compose.multi.yml up -d --build
# Execute cross-process smoke test
./scripts/multi/smoke-cross-process.sh
Script verification:
game-1 β social cross-process callgame-2 β social cross-process callcode=0 and FriendCount >= 1Simulate real clients performing repeated "login β online β active disconnect β reconnect":
# Run with default parameters
./scripts/multi/run-bots-rpc.sh
# Custom parameters
BOT_COUNT=200 \
TCP_PORT=49100 \
LOGIN_URL=http://127.0.0.1:48080/game/api/ \
DISCONNECT_AFTER_LOGIN_SECONDS=20 \
RUN_SECONDS=300 \
./scripts/multi/run-bots-rpc.sh
Available environment variables:
| Variable | Description | Default |
|---|---|---|
BOT_COUNT |
Number of bots | β |
TCP_PORT |
TCP connection port | 49100 |
LOGIN_URL |
Login API URL | http://127.0.0.1:48080/game/api/ |
DISCONNECT_AFTER_LOGIN_SECONDS |
Disconnect delay after login (seconds) | 20 |
RUN_SECONDS |
Total run duration (seconds) | 300 |
# View all service logs
docker compose -f docker-compose.multi.yml logs -f
# View specific service logs
docker compose -f docker-compose.multi.yml logs -f game-1 game-2 social-1 social-2
# Rebuild and start (after code changes)
docker compose -f docker-compose.multi.yml up -d --build
| Endpoint | Description |
|---|---|
http://<host>:<HttpPort>/game/api/health |
Health check |
http://<host>:<MetricsPort>/metrics |
Prometheus metrics |
db_operation_latency_ms), retry count (db_open_retry_total), health status (db_health_status)# Run all tests
dotnet test
# Run specific test project
dotnet test Tests/GameFrameX.Tests/GameFrameX.Tests.csproj
# Run with detailed output
dotnet test --logger "console;verbosity=detailed"
The test project is based on xUnit, covering the following modules:
| Test Directory | Description |
|---|---|
Utility/ |
Math/fixed-point tests, compression, random, ID generation, singleton |
NetWork/Kcp/ |
KCP pipeline filter, session management, server integration tests |
DataBase/ |
MongoDB connection and query tests |
ProtoBuff/ |
Protobuf serialization and object pool tests |
Localization/ |
Localization key-value parsing tests |
RemoteMessaging/ |
Cross-process messaging tests |
UnifiedMessaging/ |
Unified cross-process messaging tests |
StartUp/ |
HTTP server route registration tests |
We welcome all forms of contributions! Please follow these steps:
git checkout -b feature/amazing-feature)git commit -m 'feat: add some feature')git push origin feature/amazing-feature)Please follow the Conventional Commits specification for commit messages.
This project is licensed under the Apache License 2.0. See the file for details.
<div align="center">
If this project helps you, please give us a Star
Made by GameFrameX Team
</div>
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.0.2-dev11 | 103 | 2/24/2026 |
| 1.10.3 | 66 | 6/14/2026 |
| 1.10.2 | 70 | 6/11/2026 |
| 1.10.1 | 62 | 6/11/2026 |
| 1.10.0 | 58 | 6/11/2026 |
| 1.9.2 | 60 | 6/10/2026 |
| 1.9.1 | 64 | 6/10/2026 |
| 1.9.0 | 60 | 6/10/2026 |
| 1.8.1 | 67 | 6/5/2026 |
| 1.8.0 | 66 | 6/4/2026 |
| 1.7.5 | 78 | 5/23/2026 |
| 1.7.4 | 69 | 5/23/2026 |
| 1.7.3 | 87 | 5/17/2026 |
| 1.7.2 | 93 | 4/16/2026 |
| 1.7.1 | 71 | 4/16/2026 |
| 1.7.0 | 74 | 4/16/2026 |
| 1.6.1 | 79 | 4/10/2026 |
| 1.6.0 | 69 | 4/9/2026 |
| 1.5.1 | 73 | 3/24/2026 |
| 1.5.0 | 94 | 3/24/2026 |