yuanshen/Yuanshen.Gameserver/Program.cs
wisedev 49450270db World drops, group based spawning and a pile of fixes
Drops now land on the ground as gadgets and are picked up with F instead of
appearing in the bag out of nowhere. Chests, ore, crystals and plants all spawn
and can be interacted with.

Monsters load by scene group rather than by a radius around each one, so a camp
shows up as a camp and nothing pops into existence mid fight. The group anchors
come out of the scene Lua, which also killed four invented tuning constants.

The gateway was creating a whole new session for every handshake datagram, and
the client retransmits those until it gets an answer. That is where the piles of
duplicated monsters and the chests coming back from the dead were coming from.

Also: monster level scales to the party now, path queries return an actual two
point path instead of an empty one, NpcTalk closes properly, and the ability and
combat invocations are no longer echoed back to the client that sent them.
2026-09-04 17:44:02 +03:00

77 lines
2.9 KiB
C#

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Yuanshen.Gameserver;
using Yuanshen.Gameserver.Controllers.Dispatching;
using Yuanshen.Gameserver.Game;
using Yuanshen.Gameserver.Network;
using Yuanshen.Gameserver.Network.Kcp;
using Yuanshen.Gameserver.Network.Session;
using Yuanshen.Gameserver.Options;
using Yuanshen.Common.Console;
using Yuanshen.Common.Data.Provider;
Console.Title = "Yuanshen | Game Server";
Directory.SetCurrentDirectory(AppContext.BaseDirectory);
ConsoleBanner.Print("GAME SERVER", new[]
{
("listen", "0.0.0.0:22102"),
("protocol", "kcp / 0.9.10"),
("console", "type a GM command, ? for help")
});
HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
builder.Logging.ClearProviders();
builder.Logging.AddProvider(new ThemedLoggerProvider());
builder.Services.Configure<GatewayOptions>(builder.Configuration.GetSection(GatewayOptions.Section));
builder.Services.Configure<DatabaseOptions>(builder.Configuration.GetSection(DatabaseOptions.Section));
builder.Services.UseLocalAssets();
builder.Services.AddScoped<NetCommandDispatcher>();
builder.Services.AddScoped<NetSession, KcpSession>();
builder.Services.AddScoped<GameState>();
builder.Services.AddScoped<Player>();
builder.Services.AddScoped<SceneManager>();
builder.Services.AddScoped<CombatManager>();
builder.Services.AddScoped<GmCommandService>();
builder.Services.AddSingleton<MonsterSpawnTable>();
builder.Services.AddSingleton<DropTable>();
builder.Services.AddSingleton<GadgetSpawnTable>();
builder.Services.AddSingleton<SpawnGroupTable>();
builder.Services.AddScoped<WorldSpawner>();
builder.Services.AddScoped<Yuanshen.Gameserver.Database.PlayerPersistence>();
builder.Services.AddSingleton<Yuanshen.Gameserver.Database.PlayerSessionRegistry>();
builder.Services.AddSingleton<Yuanshen.Gameserver.Database.IPlayerRepository, Yuanshen.Gameserver.Database.PostgresPlayerRepository>();
builder.Services.AddSingleton<Yuanshen.Gameserver.Database.IAccountRepository, Yuanshen.Gameserver.Database.PostgresAccountRepository>();
builder.Services.AddSingleton<IGateway, KcpGateway>();
builder.Services.AddSingleton<ScenePointTable>();
builder.Services.AddSingleton<OpenStateTable>();
builder.Services.AddSingleton<GachaBannerTable>();
builder.Services.AddSingleton<ConsoleBridge>();
builder.Services.AddSingleton<NetSessionManager>();
builder.Services.AddHostedService<GameServer>();
IHost host = builder.Build();
ConsoleBridge bridge = host.Services.GetRequiredService<ConsoleBridge>();
ConsolePrompt.Start("yuanshen >", async command =>
{
IServiceProvider? session = bridge.Session;
if (session is null)
{
ConsolePrompt.Warn("no player is connected");
return;
}
GmCommandService gm = session.GetRequiredService<GmCommandService>();
foreach (string line in await gm.ExecuteAsync(command))
ConsolePrompt.Reply(line);
});
await host.RunAsync();