public static void CheckMaxClientCount() { lock (m_syncRoot) { if (m_fulled) { return; } } if (GameGlobal.PlayerMgr.Count >= GameServerConfig.Configuration.MaxClients) { lock (m_syncRoot) { if (m_fulled == false) { ClientMgr.Instance.ForEach(client => { UpdateServerFullPacket pkg = new UpdateServerFullPacket(); client.SendTcp(pkg); }); } m_fulled = true; m_timer.Interval = 300 * 1000; m_timer.Elapsed += new ElapsedEventHandler(m_timer_Elapsed); m_timer.AutoReset = true; m_timer.Start(); } } }
public static void CheckMaxClientCount(GatewayClient client) { lock (m_syncRoot) { if (Fulled) { //TODO: 服务器已满 请求中心服务器更换网关 ChangeGatewayPacket pkg = new ChangeGatewayPacket(); pkg.ClientID = client.ClientID; GatewayGlobal.Send2Center(pkg, client); return; } } if (ClientMgr.Instance.ClientCount >= GatewayServerConfig.Configuration.MaxClients) { lock (m_syncRoot) { Fulled = true; //TODO: 通知中心服务器此网关已满 并N分钟后重置为未满 UpdateServerFullPacket pkg = new UpdateServerFullPacket(); pkg.ClientID = client.ClientID; GatewayGlobal.Send2Center(pkg, client); m_timer.Interval = 300 * 1000; m_timer.Elapsed += new ElapsedEventHandler(m_timer_Elapsed); m_timer.AutoReset = true; m_timer.Start(); } } else { //TODO: 通知客户端登陆 NoticeLoginPacket pkg = new NoticeLoginPacket(); client.SendTcp(pkg); } }
protected override void SaveClient(ClientBase client) { base.SaveClient(client); GatewayClient c = (GatewayClient)client; GatewayGlobal.PlayerClientMgr.Add(c.ClientID, c); if (Fulled) { ConnectOtherGatewayPacket pkg = new ConnectOtherGatewayPacket(); pkg.GatewayID = GatewayGlobal.GatewayID; pkg.ClientID = ((GatewayClient)client).ClientID; GatewayGlobal.CenterServer.SendTCP(pkg); return; } else if (GatewayGlobal.PlayerClientMgr.Count > GatewayServerConfig.Configuration.MaxClients) { UpdateServerFullPacket pkg = new UpdateServerFullPacket(); pkg.GatewayID = GatewayGlobal.GatewayID; pkg.ClientID = ((GatewayClient)client).ClientID; GatewayGlobal.CenterServer.SendTCP(pkg); Fulled = true; m_timer = new System.Timers.Timer(GatewayServerConfig.Configuration.FullInterval * 1000); m_timer.Elapsed += new System.Timers.ElapsedEventHandler(m_timer_Elapsed); m_timer.Start(); } else { NoticeLoginPacket pkg = new NoticeLoginPacket(); client.SendTcp(pkg); } }