Skip to content

Commit 0c64db7

Browse files
committed
[增加]1. 增加在线人数达到上限的处理
# Conflicts: # GameFrameX.Hotfix/StartUp/AppStartUpHotfixGameByMain.cs
1 parent d29df01 commit 0c64db7

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

GameFrameX.Hotfix/StartUp/AppStartUpHotfixGameByMain.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
using GameFrameX.Apps.Common.Session;
2+
using GameFrameX.Config;
3+
using GameFrameX.NetWork;
4+
using GameFrameX.NetWork.Message;
5+
using GameFrameX.NetWork.Messages;
26
using GameFrameX.SuperSocket.Connection;
37
using GameFrameX.SuperSocket.Server.Abstractions.Session;
48
using GameFrameX.SuperSocket.WebSocket.Server;
@@ -40,14 +44,21 @@ protected override ValueTask OnDisconnected(IAppSession appSession, CloseEventAr
4044
return ValueTask.CompletedTask;
4145
}
4246

43-
protected override ValueTask OnConnected(IAppSession appSession)
47+
protected override async ValueTask OnConnected(IAppSession appSession)
4448
{
4549
LogHelper.Info("有外部客户端网络连接成功!。链接信息:SessionID:" + appSession.SessionID + " RemoteEndPoint:" + appSession.RemoteEndPoint);
4650
var netChannel = new DefaultNetWorkChannel(appSession, Setting, MessageEncoderHandler, null, appSession is WebSocketSession);
51+
var count = SessionManager.Count();
52+
if (count > Setting.MaxClientCount)
53+
{
54+
// 达到最大在线人数限制
55+
await netChannel.WriteAsync(new NotifyServerFullyLoaded(), (int)OperationStatusCode.ServerFullyLoaded);
56+
netChannel.Close();
57+
return;
58+
}
59+
4760
var session = new Session(appSession.SessionID, netChannel);
4861
SessionManager.Add(session);
49-
50-
return ValueTask.CompletedTask;
5162
}
5263

5364
/// <summary>

0 commit comments

Comments
 (0)