public static LogicServerConnector GetFreeLogicServer(GatewayClient client) { LogicServerConnector connector = LogicServerMgr[m_freeID]; if (connector != null && connector.Fulled == false) { return(connector); } LogicServerConnector connect = LogicServerMgr.SelectSingle(conn => conn.Fulled == false); if (connect != null) { m_freeID = connect.ID; connector = connect; return(connect); } else if (connector == null) { //TODO: 通知客户端逻辑服务器已满 稍候登陆 ClientMsgPacket pkg = new ClientMsgPacket(); pkg.MsgFlag = MsgFlag.NoneLogic; client.SendTcp(pkg); log.Warn("所有逻辑服务器满载 请增开新的逻辑服务器"); } return(connector); }
public GatewayPlayer(LoginInfo info, GatewayClient client) : base(info, client) { Client = client; Client.PlayerID = PlayerID; Client.Player = this; }
protected override ClientBase CreateClient(Socket socket) { GatewayClient client = new GatewayClient(); client.Accept(socket); lock (m_locker) { GatewayGlobal.ClientCount++; client.SetClientID(GatewayGlobal.ClientCount); } return(client); }
protected override ClientBase CreateClient(Socket socket) { GatewayClient client = new GatewayClient(); client.Accept(socket); lock (m_locker) { GatewayGlobal.ClientCount++; client.ClientID = GatewayGlobal.ClientCount; } return client; }
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); } }
public GatewayPlayer(PlayerInfo info, GatewayClient client) : base(info, client) { //GClient = client; }
public static LogicServerConnector GetFreeLogicServer(GatewayClient client) { LogicServerConnector connector = LogicServerMgr[m_freeID]; if (connector != null && connector.Fulled == false) { return connector; } LogicServerConnector connect = LogicServerMgr.SelectSingle(conn => conn.Fulled == false); if (connect != null) { m_freeID = connect.ID; connector = connect; return connect; } else if(connector == null) { //TODO: 通知客户端逻辑服务器已满 稍候登陆 ClientMsgPacket pkg = new ClientMsgPacket(); pkg.MsgFlag = MsgFlag.NoneLogic; client.SendTcp(pkg); log.Warn("所有逻辑服务器满载 请增开新的逻辑服务器"); } return connector; }