public GameServerContext(GameServerContextManager gameServerContextManager, MasterApplication application, IRegisterGameServer request) { this.contextManager = gameServerContextManager; this.application = application; this.AddressInfo = GameServerAddressInfo.CreateAddressInfo(request, log); this.Key = GetKey(request); this.ServerId = request.ServerId; this.LoadBalancerPriority = request.LoadBalancerPriority; this.State = ServerState.Offline; if (request.SupportedProtocols != null && request.SupportedProtocols.Length != 0) { this.SupportedProtocols = new List <byte>(request.SupportedProtocols); } }
public static GameServerAddressInfo CreateAddressInfo(IRegisterGameServer registerRequest, ILogger log) { var result = new GameServerAddressInfo { Address = registerRequest.GameServerAddress }; if (registerRequest.GameServerAddressIPv6 != null && IPAddress.Parse(registerRequest.GameServerAddressIPv6).AddressFamily == AddressFamily.InterNetworkV6) { result.AddressIPv6 = string.Format("[{0}]", IPAddress.Parse(registerRequest.GameServerAddressIPv6)); } result.Hostname = registerRequest.GameServerHostName; if (registerRequest.UdpPort.HasValue) { result.UdpAddress = string.IsNullOrEmpty(result.Address) ? null : string.Format("{0}:{1}", result.Address, registerRequest.UdpPort); result.UdpAddressIPv6 = string.IsNullOrEmpty(result.AddressIPv6) ? null : string.Format("{0}:{1}", result.AddressIPv6, registerRequest.UdpPort); result.UdpHostname = string.IsNullOrEmpty(result.Hostname) ? null : string.Format("{0}:{1}", result.Hostname, registerRequest.UdpPort); } if (registerRequest.TcpPort.HasValue) { result.TcpAddress = string.IsNullOrEmpty(result.Address) ? null : string.Format("{0}:{1}", result.Address, registerRequest.TcpPort); result.TcpAddressIPv6 = string.IsNullOrEmpty(result.AddressIPv6) ? null : string.Format("{0}:{1}", result.AddressIPv6, registerRequest.TcpPort); result.TcpHostname = string.IsNullOrEmpty(result.Hostname) ? null : string.Format("{0}:{1}", result.Hostname, registerRequest.TcpPort); } if (registerRequest.WebSocketPort.HasValue && registerRequest.WebSocketPort != 0) { result.WebSocketAddress = string.IsNullOrEmpty(result.Address) ? null : string.Format("ws://{0}:{1}", result.Address, registerRequest.WebSocketPort); result.WebSocketAddressIPv6 = string.IsNullOrEmpty(result.AddressIPv6) ? null : string.Format("ws://{0}:{1}", result.AddressIPv6, registerRequest.WebSocketPort); result.WebSocketHostname = string.IsNullOrEmpty(result.Hostname) ? null : string.Format("ws://{0}:{1}", result.Hostname, registerRequest.WebSocketPort); } if (registerRequest.HttpPort.HasValue && registerRequest.HttpPort != 0) { result.HttpAddress = string.IsNullOrEmpty(result.Address) ? null : string.Format("http://{0}:{1}{2}", result.Address, registerRequest.HttpPort, registerRequest.HttpPath); result.HttpAddressIPv6 = string.IsNullOrEmpty(result.AddressIPv6) ? null : string.Format("http://{0}:{1}{2}", result.AddressIPv6, registerRequest.HttpPort, registerRequest.HttpPath); result.HttpHostname = string.IsNullOrEmpty(result.Hostname) ? null : string.Format("http://{0}:{1}{2}", result.Hostname, registerRequest.HttpPort, registerRequest.HttpPath); } if (registerRequest.WebRTCPort.HasValue && registerRequest.WebRTCPort != 0) { result.WebRTCAddress = string.IsNullOrEmpty(result.Address) ? null : string.Format("{0}:{1}", result.Address, registerRequest.WebRTCPort); } // HTTP & WebSockets require a proper domain name (especially for certificate validation on secure Websocket & HTTPS connections): if (string.IsNullOrEmpty(result.Hostname)) { log.WarnFormat("HTTPs & Secure WebSockets not supported. GameServer {0} does not have a public hostname.", result.Address); } else { if (registerRequest.SecureWebSocketPort.HasValue && registerRequest.SecureWebSocketPort != 0) { result.SecureWebSocketHostname = string.Format("wss://{0}:{1}", result.Hostname, registerRequest.SecureWebSocketPort); } if (registerRequest.SecureHttpPort.HasValue && registerRequest.SecureHttpPort != 0) { result.SecureHttpHostname = string.Format("https://{0}:{1}{2}", result.Hostname, registerRequest.SecureHttpPort, registerRequest.HttpPath); } } return(result); }