/// <inheritdoc/> public void RegisterGameServer(IGameServerInfo gameServer, IPEndPoint publicEndPoint) { Logger.InfoFormat("GameServer {0} is registering with endpoint {1}", gameServer, publicEndPoint); try { var serverListItem = new ServerListItem(this.ServerList) { ServerId = gameServer.Id, EndPoint = publicEndPoint, ServerLoad = (byte)(gameServer.OnlinePlayerCount * 100f / gameServer.MaximumPlayers) }; if (gameServer is INotifyPropertyChanged notifier) { notifier.PropertyChanged += this.HandleServerPropertyChanged; } this.ServerList.Servers.Add(serverListItem); this.ConnectInfos.Add(serverListItem.ServerId, serverListItem.ConnectInfo); } catch (Exception ex) { Logger.Error("Error during registration process", ex); throw; } Logger.InfoFormat("GameServer {0} has registered with endpoint {1}", gameServer, publicEndPoint); }
/// <inheritdoc /> public void UnregisterGameServer(IGameServerInfo gameServer) { for (int i = 0; i < this.observers.Count; i++) { this.observers[i].UnregisterGameServer(gameServer); } }
/// <inheritdoc /> public void RegisterGameServer(IGameServerInfo gameServer, IPEndPoint publicEndPoint) { for (int i = 0; i < this.observers.Count; i++) { this.observers[i].RegisterGameServer(gameServer, publicEndPoint); } }
/// <summary> /// Initializes a new instance of the <see cref="DefaultTcpGameServerListener" /> class. /// </summary> /// <param name="port">The tcp port.</param> /// <param name="gameServerInfo">The game server information.</param> /// <param name="gameContext">The game context.</param> /// <param name="connectServer">The connect server.</param> /// <param name="mainPacketHandler">The main packet handler which should be used by clients which connected through this listener.</param> public DefaultTcpGameServerListener(int port, IGameServerInfo gameServerInfo, GameServerContext gameContext, IConnectServer connectServer, IMainPacketHandler mainPacketHandler) { this.port = port; this.gameServerInfo = gameServerInfo; this.gameContext = gameContext; this.connectServer = connectServer; this.mainPacketHandler = mainPacketHandler; }
/// <summary> /// Initializes a new instance of the <see cref="DefaultTcpGameServerListener" /> class. /// </summary> /// <param name="endPoint">The endpoint to which this listener is listening.</param> /// <param name="gameServerInfo">The game server information.</param> /// <param name="gameContext">The game context.</param> /// <param name="stateObserver">The connect server.</param> /// <param name="addressResolver">The address resolver which returns the address on which the listener will be bound to.</param> public DefaultTcpGameServerListener(GameServerEndpoint endPoint, IGameServerInfo gameServerInfo, GameServerContext gameContext, IGameServerStateObserver stateObserver, IIpAddressResolver addressResolver) { this.endPoint = endPoint; this.gameServerInfo = gameServerInfo; this.gameContext = gameContext; this.stateObserver = stateObserver; this.addressResolver = addressResolver; }
/// <summary> /// Initializes a new instance of the <see cref="DefaultTcpGameServerListener" /> class. /// </summary> /// <param name="endPoint">The endpoint to which this listener is listening.</param> /// <param name="gameServerInfo">The game server information.</param> /// <param name="gameContext">The game context.</param> /// <param name="connectServer">The connect server.</param> /// <param name="addressResolver">The address resolver which returns the address on which the listener will be bound to.</param> public DefaultTcpGameServerListener(GameServerEndpoint endPoint, IGameServerInfo gameServerInfo, GameServerContext gameContext, IConnectServer connectServer, IIpAddressResolver addressResolver) { this.endPoint = endPoint; this.gameServerInfo = gameServerInfo; this.gameContext = gameContext; this.connectServer = connectServer; this.addressResolver = addressResolver; }
/// <summary> /// Initializes a new instance of the <see cref="DefaultTcpGameServerListener" /> class. /// </summary> /// <param name="endPoint">The endpoint to which this listener is listening.</param> /// <param name="gameServerInfo">The game server information.</param> /// <param name="gameContext">The game context.</param> /// <param name="stateObserver">The connect server.</param> /// <param name="addressResolver">The address resolver which returns the address on which the listener will be bound to.</param> /// <param name="loggerFactory">The logger factory.</param> public DefaultTcpGameServerListener(GameServerEndpoint endPoint, IGameServerInfo gameServerInfo, GameServerContext gameContext, IGameServerStateObserver stateObserver, IIpAddressResolver addressResolver, ILoggerFactory loggerFactory) { this.endPoint = endPoint; this.gameServerInfo = gameServerInfo; this.gameContext = gameContext; this.stateObserver = stateObserver; this.addressResolver = addressResolver; this.loggerFactory = loggerFactory; this.logger = this.loggerFactory.CreateLogger <DefaultTcpGameServerListener>(); }
/// <inheritdoc/> public void UnregisterGameServer(IGameServerInfo gameServer) { Logger.WarnFormat("GameServer {0} is unregistering", gameServer); var serverListItem = this.ServerList.Servers.FirstOrDefault(s => s.ServerId == gameServer.Id); if (serverListItem != null) { this.ConnectInfos.Remove(serverListItem.ServerId); this.ServerList.Servers.Remove(serverListItem); this.ServerList.InvalidateCache(); } if (gameServer is INotifyPropertyChanged notifier) { notifier.PropertyChanged -= this.HandleServerPropertyChanged; } Logger.WarnFormat("GameServer {0} has unregistered", gameServer); }