protected override void OnDisconnected() { base.OnDisconnected(); GatewayGlobal.Clients.Remove(ClientID); if (PlayerID != 0) { ClientDisconnectPacket pkg = new ClientDisconnectPacket(PlayerID); pkg.ClientID = ClientID; LogicServer.SendTCP(pkg); pkg = new ClientDisconnectPacket(PlayerID); pkg.ClientID = ClientID; GatewayGlobal.Send2Center(pkg, this); } if (Player != null) { Player.OnDisconnect(); } }
static void m_timer_Elapsed(object sender, ElapsedEventArgs e) { lock (m_syncRoot) { Fulled = false; UpdateServerNormalPacket pkg = new UpdateServerNormalPacket(); GatewayGlobal.Send2Center(pkg, null); m_timer.Elapsed -= m_timer_Elapsed; m_timer.Stop(); } }
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); } }