Files
hjha-server/GameNetModule/Manager/UserNet/UserNetSession.cs
xiaoou e9616125ce feat: initial commit - HJHA game server full source
6 major server modules (PdkFriendServer/GlobalSever/ServerCore/GameModule/GameNetModule) +
game logic (GameFix/GameDAL/ServerData) +
network layer (NetWorkMessage) +
data layer (ObjectModel) +
utilities (MrWu/Core/Config/CloudAPI/dll) +
adapters (zyxAdapter/base)

.NET 8.0 C# solution, 16 projects, 958 source files
2026-07-07 12:02:15 +08:00

82 lines
2.1 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 System;
using System.Threading;
using Server.Net;
namespace Server
{
/// <summary>
/// UserNet 是 UserNetActor 管理, 与 主线程的 UserSession 对应, id 和 instanceId 用来查找对应的 Session
/// </summary>
public class UserNetSession : BaseSession
{
/// <summary>
/// 实例ID 如果Id 改变就不能用了,不再是之前的用户
/// </summary>
public long InstanceId { get; set; }
public byte Ver;
public bool IsDisConnected { get; set; }
/// <summary>
/// Fin 就是链接断了 Idle 就是还没绑定用户 从收到链接请求到发送中断确认之间都是Using
/// </summary>
public UserSessionState State = UserSessionState.Idle;
private static long IdGenerate;
public int ForceDisConnectCode { get; set; }
private long GetInstanceId()
{
if (InstanceId >= long.MaxValue)
{
IdGenerate = 0;
}
IdGenerate++;
return IdGenerate;
}
public UserNetSession(long id, TService service, Action<long> disposeAction) : base(id, service,disposeAction)
{
}
/// <summary>
/// 链接确认 建立链接就生成新的
/// </summary>
public void ConnectAck()
{
InstanceId = GetInstanceId();
}
}
/**
* 收到链接包 - 回链接成功,表示建立连接成功 标志为使用中
* 如果收到断开连接包,则触发用户断线的事件 标志为空闲
* 如果是真断开,判断状态如果是使用中,也要出发用户断线事件, 标志为断开
*
*
*
*
*/
public enum UserSessionState
{
/// <summary>
/// 空闲
/// </summary>
Idle,
/// <summary>
/// 使用中
/// </summary>
Using,
/// <summary>
/// 断开中
/// </summary>
Fin,
}
}