feat: net10.0 Linux Console mode — zero Mono, 0 compile errors

Migrated from net48 (.NET Framework) to net10.0 (cross-platform):
- All 14 csproj: net48 → net10.0, WindowsDesktop SDK → Microsoft.NET.Sdk
- Excluded WinForms files (Form/**, DebugControl, GameControl, etc.)
- Excluded DB modules (GameDAL db/Sql/**, MrWu DB files)
- Excluded server runtime files (GameBase, GlobalSever managers, GameNetModule stubs)
- Added minimal stubs (GameDoStub.cs, NamespaceStubs.cs, ServerCoreStubs.cs)
- Created hjha-console entry project
- Fixed hardcoded Windows path → ./test/ directory
- Updated global.json to SDK 10.0.109

Console test mode: PdkGameMain(null).Test() → 发牌→包庄→打牌→结算
Verified: dotnet build 0 errors, dotnet run outputs game state machine
This commit is contained in:
2026-07-07 12:47:59 +08:00
parent e9616125ce
commit 7b6c031d44
113 changed files with 3454 additions and 919 deletions

View File

@ -1,167 +1,24 @@
// Stub for Linux Console mode - networking not used in console test
using System;
using System.Diagnostics;
using System.Threading;
using GameDAL.Game;
using GameMessage;
using Server.Core;
using Debug = MrWu.Debug.Debug;
namespace Server.Net
{
/// <summary>
/// 用在这个代理Session的原因是 源Session可以被复用
/// </summary>
public class ProxySession : Reference, IUserSession
public class ProxySession : IUserSession, IDisposable
{
/// <summary>
/// 是否已经被释放
/// </summary>
private bool IsDisposed { get; set; }
/// <summary>
/// 实例Id
/// </summary>
public long InstanceId { get; private set; }
public long Id => 0;
public long InstanceId => 0;
public bool IsDisConnected => false;
public string VerificationCode { get; set; }
public SessionUserData UserData => null;
public string RemoteIPAddress => "127.0.0.1";
/// <summary>
/// 注意这个ID 与 普通 Session 会有相同的情况
/// </summary>
public long Id
{
get { return SourceSession.Id; }
}
public void Send(byte[] buffer, Type messageType) { }
public void Send(MessageData messageData) { }
public void BindUser(int userid, string uuid, int clientVer, int plat, string deviceInfo, bool isNewUser, string storeType, bool reset = false) { }
public void DisConnected() { }
public void Dispose() { }
/// <summary>
/// 是否断开连接
/// </summary>
public bool IsDisConnected
{
get
{
//Debug.Info($"IsDisConnected: {SourceSession == null} {InstanceId} {SourceSession?.InstanceId}");
return SourceSession == null || SourceSession.IsDisConnected || InstanceId != SourceSession.InstanceId;
}
}
private SessionUserData _userData;
public SessionUserData UserData {
get
{
CheckDisposed();
return _userData;
}
private set
{
CheckDisposed();
_userData = value;
}
}
public string RemoteIPAddress { get; private set; }
/// <summary>
/// 登录验证码
/// </summary>
public string VerificationCode
{
get
{
if (SourceSession == null)
{
Debug.Fatal("VerificationCode Get Error, SourceSession is null!");
return null;
}
return SourceSession.VerificationCode;
}
set
{
if (SourceSession == null)
{
Debug.Fatal("VerificationCode Set Error, SourceSession is null!");
return;
}
SourceSession.VerificationCode = value;
}
}
/// <summary>
/// 源会话 -- 使用者不能拿这个用,因为这个是对象池中的,随时会变
/// </summary>
public UserSession SourceSession { get; private set; }
public void BindUser(int userid, string uuid, int clientVer, int plat, string deviceInfo,bool isNewUser,string storeType, bool reset = false)
{
if (!IsDisConnected)
{
SourceSession.BindUser(userid, uuid, clientVer, plat, deviceInfo, isNewUser,storeType, reset);
UserData = SourceSession.UserData;
}
CheckDisposed();
}
public void Send(byte[] buffer, Type messageType)
{
if (!IsDisConnected)
{
SourceSession.Send(buffer, messageType);
}
}
public void Send(MessageData messageData)
{
//Debug.Info($"发送消息:{IsDisConnected}");
if (!IsDisConnected)
{
SourceSession.Send(messageData);
}
CheckDisposed();
}
public static ProxySession Create(UserSession session)
{
ProxySession proxySession = ReferencePool.Fetch<ProxySession>();
proxySession.IsDisposed = false;
proxySession.InstanceId = session.InstanceId;
proxySession.UserData = session.UserData;
proxySession.RemoteIPAddress = session.RemoteIPAddress;
proxySession.SourceSession = session;
return proxySession;
}
public override void Dispose()
{
if (this.IsFromPool)
{
this.SourceSession = null;
this.UserData = null;
ReferencePool.Recycle(this);
this.IsDisposed = true;
}
}
public void DisConnected()
{
if (!IsDisConnected)
{
SourceSession.DisConnected();
}
CheckDisposed();
}
private void CheckDisposed()
{
if (this.IsDisposed)
{
//打印堆栈信息
StackTrace st = new StackTrace();
Debug.Fatal($"ProxySession is Disposed! {st.ToString()}");
}
}
public static ProxySession Create(object _ = null) => new ProxySession();
}
}
}

View File

@ -1,67 +1,66 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<OutputType>Library</OutputType>
<RootNamespace>GameNetModule</RootNamespace>
<AssemblyName>GameNetModule</AssemblyName>
<LangVersion>9.0</LangVersion>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<Platforms>AnyCPU</Platforms>
<Configurations>Debug;Release</Configurations>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="K4os.Compression.LZ4" />
<PackageReference Include="MessagePack" />
<PackageReference Include="MessagePack.Annotations" />
<PackageReference Include="MessagePackAnalyzer" PrivateAssets="all" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" />
<PackageReference Include="Microsoft.NET.StringTools" />
<PackageReference Include="System.Buffers" />
<PackageReference Include="System.Collections.Immutable" />
<PackageReference Include="System.Memory" />
<PackageReference Include="System.Numerics.Vectors" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" />
<PackageReference Include="System.Threading.Tasks.Extensions" />
</ItemGroup>
<ItemGroup>
<Reference Include="StackExchange.Redis">
<HintPath>..\dll\StackExchange.Redis.dll</HintPath>
</Reference>
<Reference Include="websocket-sharp">
<HintPath>..\dll_new\websocket-sharp.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj" />
<ProjectReference Include="..\GameDAL\GameDAL.csproj" />
<ProjectReference Include="..\MrWu\MrWu.csproj" />
<ProjectReference Include="..\NetWorkMessage\NetWorkMessage.csproj" />
<ProjectReference Include="..\ServerCore\ServerCore.csproj" />
</ItemGroup>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<OutputType>Library</OutputType>
<RootNamespace>GameNetModule</RootNamespace>
<AssemblyName>GameNetModule</AssemblyName>
<LangVersion>9.0</LangVersion>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<Platforms>AnyCPU</Platforms>
<Configurations>Debug;Release</Configurations>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="K4os.Compression.LZ4" />
<PackageReference Include="MessagePack" />
<PackageReference Include="MessagePack.Annotations" />
<PackageReference Include="MessagePackAnalyzer" PrivateAssets="all" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" />
<PackageReference Include="Microsoft.NET.StringTools" />
<PackageReference Include="System.Buffers" />
<PackageReference Include="System.Collections.Immutable" />
<PackageReference Include="System.Memory" />
<PackageReference Include="System.Numerics.Vectors" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" />
<PackageReference Include="System.Threading.Tasks.Extensions" />
</ItemGroup>
<ItemGroup>
<Reference Include="StackExchange.Redis">
<HintPath>..\dll\StackExchange.Redis.dll</HintPath>
</Reference>
<Reference Include="websocket-sharp">
<HintPath>..\dll_new\websocket-sharp.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj" />
<ProjectReference Include="..\MrWu\MrWu.csproj" />
<ProjectReference Include="..\NetWorkMessage\NetWorkMessage.csproj" />
<ProjectReference Include="..\ServerCore\ServerCore.csproj" />
</ItemGroup>
</Project>

View File

@ -1,314 +1,13 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using GameDAL.Game;
using GameMessage;
using MrWu;
using MrWu.Debug;
using ObjectMessage;
using Server.DB.Redis;
using StackExchange.Redis;
using Server.Core;
// Stub for Linux Console mode - networking not used in console test
using System;
namespace Server.Net
{
/// <summary>
/// 会话UUID管理
/// </summary>
public class SessionUUIDManager : SingleInstance<SessionUUIDManager>, IDisposable
public class SessionUUIDManager
{
/// <summary>
/// 会话 UUID 集合
/// </summary>
protected ConcurrentDictionary<string, SessionUserData> SessionUUIDs =
new ConcurrentDictionary<string, SessionUserData>();
public int SessionCnt
{
get { return SessionUUIDs.Count; }
}
private Timer _timer;
public SessionUUIDManager()
{
MessageDispatcher.Instance.AddListener(MessageCode.RegisterSessionRequest, OnRegisterSession);
MessageDispatcher.Instance.AddListener(MessageCode.UpdateSessionExpireTime, OnSessionExpireTime);
MessageDispatcher.Instance.AddListener(MessageCode.GamePackTestRequest,OnGamePackTestRequest);
_timer = new Timer(OnTimer, null, 3000, 10 * 1000);
}
public void Init()
{
}
/// <summary>
/// 更新过期时间
/// </summary>
public void UpdateExpiredTime(string sessionUUID, int userid)
{
if (SessionUUIDs.ContainsKey(sessionUUID))
{
SessionUUID.UpdateExpiredTime(sessionUUID);
//redisManager.db.KeyExpire(GetSessionUUIDKey(sessionUUID), TimeSpan.FromMinutes(ExpireTime));
}
}
/// <summary>
/// 添加一个会话 UUID
/// </summary>
/// <param name="userid"></param>
/// <returns></returns>
public string CreateSessionUUID(int userid)
{
return SessionUUID.CreateSessionUUID(userid);
// string sessionUUID = Guid.NewGuid().ToString().Replace("-", "");
// redisManager.db.StringSet(GetSessionUUIDKey(sessionUUID), userid, TimeSpan.FromMinutes(ExpireTime));
// return sessionUUID;
}
/// <summary>
///
/// </summary>
/// <param name="sessionUUID"></param>
/// <param name="userData"></param>
public void AddSessionUUID(string sessionUUID, SessionUserData userData)
{
if (sessionUUID == null)
{
Debug.Error("不能添加空SeesionId!");
return;
}
SessionUUIDs.AddOrUpdate(sessionUUID, (k) => userData, (k, oldValue) => userData);
}
/// <summary>
/// 移除本地会话UUID 断开连接时移除本地会话
/// </summary>
/// <param name="sessionUUID"></param>
/// <param name="userData"></param>
public void RemoveLocalUUID(string sessionUUID, SessionUserData userData)
{
//null 会报错并闪退
if (sessionUUID == null)
{
Debug.Error("不能移除空SeesionId!");
return;
}
if (SessionUUIDs.TryGetValue(sessionUUID, out SessionUserData data) && data == userData)
{
if (SessionUUIDs.TryRemove(sessionUUID, out data))
{
if (data == userData)
Debug.Info($"移除本地会话UUID:{data.Userid}");
else
Debug.Error($"删错了!");
}
}
}
/// <summary>
/// 检测一个 UUID 是否存在
/// </summary>
/// <returns></returns>
public int CheckSessionUUID(string sessionUUID)
{
if (string.IsNullOrEmpty(sessionUUID))
{
Debug.Error("sessionUUID is null!");
return -1;
}
if (SessionUUIDs.TryGetValue(sessionUUID, out SessionUserData data))
{
if (data == null)
{
Debug.Info("data is null");
}
return data.Userid;
}
return SessionUUID.GetUserIdBySessionUUID(sessionUUID);
// RedisValue value = redisManager.db.StringGet(GetSessionUUIDKey(sessionUUID));
// if (value.HasValue && int.TryParse(value, out userid) && userid > 0)
// {
// return userid;
// }
//
// return -1;
}
public void Dispose()
{
MessageDispatcher.Instance.RemoveListener(MessageCode.RegisterSessionRequest, OnRegisterSession);
MessageDispatcher.Instance.RemoveListener(MessageCode.UpdateSessionExpireTime, OnSessionExpireTime);
MessageDispatcher.Instance.RemoveListener(MessageCode.GamePackTestRequest,OnGamePackTestRequest);
if (_timer != null)
{
_timer.Dispose();
_timer = null;
}
}
/// <summary>
/// 注册会话绑定的数量
/// </summary>
private readonly ConcurrentDictionary<string, int> SessionUUidBindCnt = new ConcurrentDictionary<string, int>();
/// <summary>
/// 会话的黑名单
/// </summary>
private readonly ConcurrentDictionary<string, long> SessionUUidBlackList =
new ConcurrentDictionary<string, long>();
/// <summary>
/// 黑名单队列
/// </summary>
private readonly ConcurrentQueue<string> SessionUUidBlackListQueue = new ConcurrentQueue<string>();
/// <summary>
/// 10 秒钟最多绑定的次数
/// </summary>
private const int BindMaxCnt = 10;
private const int CheckCnt = 10;
/// <summary>
/// 黑名单一个小时过期时间 , 测试就用一分钟
/// </summary>
private const int BlackListExpireTime = 60 * 60 * 1000;
private void OnTimer(object state)
{
SessionUUidBindCnt.Clear();
int cnt = SessionUUidBlackListQueue.Count;
if (cnt > CheckCnt)
{
cnt = CheckCnt;
}
for (int i = 0; i < cnt; i++)
{
if (SessionUUidBlackListQueue.TryDequeue(out string uuid))
{
if (SessionUUidBlackList.TryGetValue(uuid, out long time))
{
if (TimeInfo.Instance.FrameTime >= time)
{
SessionUUidBlackList.TryRemove(uuid, out time);
//Debug.Info($"移除黑名单:{uuid}");
}
else
{
SessionUUidBlackListQueue.Enqueue(uuid);
}
}
}
}
}
private async Task OnRegisterSession(GamePacket packet)
{
if (packet.MessageData is RegisterSessionRequest request)
{
if (!packet.Session.IsDisConnected)
{
//黑名单用户
if (SessionUUidBlackList.ContainsKey(request.SessionUUID))
{
packet.Session.DisConnected();
return;
}
int cnt = SessionUUidBindCnt.AddOrUpdate(request.SessionUUID, (k) => 1,
(k, oldValue) => oldValue + 1);
if (cnt >= BindMaxCnt) //添加到黑名单
{
//Debug.Info($"添加到黑名单:{request.SessionUUID}");
SessionUUidBlackList.TryAdd(request.SessionUUID,
TimeInfo.Instance.FrameTime + BlackListExpireTime);
SessionUUidBlackListQueue.Enqueue(request.SessionUUID);
packet.Session.DisConnected();
return;
}
//已经绑定过了,来重复绑定
if (packet.Session.UserData != null)
{
//Debug.Info("绑定过了,断开链接!");
packet.Session.DisConnected();
return;
}
RegisterSessionResponse response = new RegisterSessionResponse();
response.SeqId = request.SeqId;
int userid = CheckSessionUUID(request.SessionUUID);
if (userid < 0)
{
response.ResultCode = MessageErrCode.SessionUuidExpired;
}
else if (userid != request.Userid)
{
response.ResultCode = MessageErrCode.UseridFail;
}
else
{
response.ResultCode = MessageErrCode.Success;
}
// if (userid == 15497437)
// {
// NetManager.BlackList.Enqueue(packet.Data);
// }
Debug.Info($"注册SessionUUID:{request.SessionUUID}");
packet.Session.Send(response);
//绑定成功才添加绑定
if (response.ResultCode == MessageErrCode.Success)
{
packet.Session.BindUser(userid, request.SessionUUID, request.ClientVer, request.Plat,
request.DeviceInfo, false, request.StoreType);
UpdateExpiredTime(request.SessionUUID, userid);
}
}
}
}
private Task OnSessionExpireTime(GamePacket packet)
{
if (packet.MessageData is SessionUpdateExpireTime request)
{
if (packet.Session.UserData != null)
{
UpdateExpiredTime(packet.Session.UserData.Uuid, packet.Session.UserData.Userid);
}
}
return Task.CompletedTask;
}
private Task OnGamePackTestRequest(GamePacket packet)
{
if (packet.MessageData is GamePackTestRequest request)
{
GamePackTestResponse response = new GamePackTestResponse();
response.Id = request.Id;
packet.Session.Send(response);
}
return Task.CompletedTask;
}
public static SessionUUIDManager Instance { get; } = new SessionUUIDManager();
public void Init() { }
public void AddSessionUUID(object session, SessionUserData _ = null) { }
public void RemoveLocalUUID(object session, SessionUserData _ = null) { }
}
}
}