Skip to content

Commit bf7a628

Browse files
committed
[增加]1. 增加在线人数达到上限的处理
1 parent 58b8610 commit bf7a628

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

GameFrameX.Hotfix/StartUp/AppStartUpHotfixGameByMain.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using GameFrameX.Apps.Common.Session;
22
using GameFrameX.Config;
33
using GameFrameX.NetWork;
4-
using GameFrameX.NetWork.HTTP;
54
using GameFrameX.NetWork.Message;
65
using GameFrameX.NetWork.Messages;
76
using GameFrameX.SuperSocket.Connection;
@@ -45,14 +44,21 @@ protected override ValueTask OnDisconnected(IAppSession appSession, CloseEventAr
4544
return ValueTask.CompletedTask;
4645
}
4746

48-
protected override ValueTask OnConnected(IAppSession appSession)
47+
protected override async ValueTask OnConnected(IAppSession appSession)
4948
{
5049
LogHelper.Info("有外部客户端网络连接成功!。链接信息:SessionID:" + appSession.SessionID + " RemoteEndPoint:" + appSession.RemoteEndPoint);
5150
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+
5260
var session = new Session(appSession.SessionID, netChannel);
5361
SessionManager.Add(session);
54-
55-
return ValueTask.CompletedTask;
5662
}
5763

5864
/// <summary>

0 commit comments

Comments
 (0)