protected PeerBase CreateGameServerPeer(InitRequest initRequest)
        {
            var peer = this.CreateMasterServerPeer(initRequest);

            if (initRequest.InitObject == null)
            {
                return(peer);
            }

            var request = new RegisterGameServerDataContract(initRequest.Protocol, (Dictionary <byte, object>)initRequest.InitObject);

            if (!request.IsValid)
            {
                log.WarnFormat("Can not register server. Init request from {0}:{1} is invalid:{2}", initRequest.RemoteIP, initRequest.RemotePort, request.GetErrorMessage());
                return(null);
            }

            this.GameServers.RegisterGameServerOnInit(request, peer);

            if (!peer.IsRegistered)
            {
                return(null);
            }

            initRequest.ResponseObject = peer.GetRegisterResponse();
            return(peer);
        }
Exemple #2
0
        private Dictionary <byte, object> GetInitObject()
        {
            var contract = new RegisterGameServerDataContract
            {
                GameServerAddress  = this.Application.PublicIpAddress.ToString(),
                GameServerHostName = GameServerSettings.Default.PublicHostName,

                UdpPort              = GameServerSettings.Default.RelayPortUdp == 0 ? this.Application.GamingUdpPort : GameServerSettings.Default.RelayPortUdp + this.Application.GetCurrentNodeId() - 1,
                TcpPort              = GameServerSettings.Default.RelayPortTcp == 0 ? this.Application.GamingTcpPort : GameServerSettings.Default.RelayPortTcp + this.Application.GetCurrentNodeId() - 1,
                WebSocketPort        = GameServerSettings.Default.RelayPortWebSocket == 0 ? this.Application.GamingWebSocketPort : GameServerSettings.Default.RelayPortWebSocket + this.Application.GetCurrentNodeId() - 1,
                SecureWebSocketPort  = GameServerSettings.Default.RelayPortSecureWebSocket == 0 ? this.Application.GamingSecureWebSocketPort : GameServerSettings.Default.RelayPortSecureWebSocket + this.Application.GetCurrentNodeId() - 1,
                HttpPort             = GameServerSettings.Default.RelayPortHttp == 0 ? this.Application.GamingHttpPort : GameServerSettings.Default.RelayPortHttp + this.Application.GetCurrentNodeId() - 1,
                SecureHttpPort       = this.Application.GamingHttpsPort,
                WebRTCPort           = GameServerSettings.Default.GamingWebRTCPort,
                HttpPath             = this.Application.GamingHttpPath,
                ServerId             = this.Application.ServerId.ToString(),
                ServerState          = (int)this.Application.WorkloadController.ServerState,
                LoadLevelCount       = (byte)FeedbackLevel.LEVELS_COUNT,
                PredictionData       = this.GetPeer().GetPredictionData(),
                LoadBalancerPriority = GameServerSettings.Default.LoadBalancerPriority,
                LoadIndex            = (byte)this.Application.WorkloadController.FeedbackLevel,
                SupportedProtocols   = OutgoingMasterServerPeer.GetSupportedProtocolsFromString(GameServerSettings.Default.SupportedProtocols),
            };

            if (this.Application.PublicIpAddressIPv6 != null)
            {
                contract.GameServerAddressIPv6 = this.Application.PublicIpAddressIPv6.ToString();
            }

            if (log.IsInfoEnabled)
            {
                log.InfoFormat(
                    "Connecting to master server with address {0}, TCP {1}, UDP {2}, WebSocket {3}, " +
                    "Secure WebSocket {4}, HTTP {5}, ServerID {6}, Hostname {7}, IPv6Address {8}, WebRTC {9}",
                    contract.GameServerAddress,
                    contract.TcpPort,
                    contract.UdpPort,
                    contract.WebSocketPort,
                    contract.SecureWebSocketPort,
                    contract.HttpPort,
                    contract.ServerId,
                    contract.GameServerHostName,
                    contract.GameServerAddressIPv6,
                    contract.WebRTCPort);
            }

            return(contract.ToDictionary());
        }