void Update() { if (m_SQPServer == null) { if (ServerPort == 0) { return; } m_SQPServer = new SQP.SQPServer(m_SQPPort); m_SQPData = m_SQPServer.ServerInfoData; Debug.Log($"SQPDriver initialized. Responding to SQP queries on port {m_SQPPort}..."); } else { // Set server data m_SQPData.Map = ServerMapName; m_SQPData.Port = ServerPort; m_SQPData.BuildId = Application.unityVersion; m_SQPData.MaxPlayers = MaxPlayersCount; m_SQPData.CurrentPlayers = CurrentPlayersCount; m_SQPData.GameType = GameType; m_SQPData.ServerName = ServerName; // Tick SQP 'server' m_SQPServer.Update(); } }
public bool Init(string[] args) { // Set up statemachine for ServerGame m_StateMachine = new StateMachine <ServerState>(); m_StateMachine.Add(ServerState.Idle, null, UpdateIdleState, null); m_StateMachine.Add(ServerState.Loading, null, UpdateLoadingState, null); m_StateMachine.Add(ServerState.Active, EnterActiveState, UpdateActiveState, LeaveActiveState); m_StateMachine.SwitchTo(ServerState.Idle); m_NetworkTransport = new SocketTransport(NetworkConfig.serverPort.IntValue, serverMaxClients.IntValue); var listenAddresses = NetworkUtils.GetLocalInterfaceAddresses(); if (listenAddresses.Count > 0) { Console.SetPrompt(listenAddresses[0] + ":" + NetworkConfig.serverPort.Value + "> "); } GameDebug.Log("Listening on " + string.Join(", ", NetworkUtils.GetLocalInterfaceAddresses()) + " on port " + NetworkConfig.serverPort.IntValue); m_NetworkServer = new NetworkServer(m_NetworkTransport); if (Game.game.clientFrontend != null) { var serverPanel = Game.game.clientFrontend.serverPanel; serverPanel.SetPanelActive(true); serverPanel.serverInfo.text += "Listening on:\n"; foreach (var a in NetworkUtils.GetLocalInterfaceAddresses()) { serverPanel.serverInfo.text += a + ":" + NetworkConfig.serverPort.IntValue + "\n"; } } m_NetworkServer.UpdateClientInfo(); m_NetworkServer.serverInfo.compressionModel = m_Model; if (serverServerName.Value == "") { serverServerName.Value = MakeServername(); } m_ServerQueryProtocolServer = new SQP.SQPServer(NetworkConfig.serverSQPPort.IntValue > 0? NetworkConfig.serverSQPPort.IntValue : NetworkConfig.serverPort.IntValue + NetworkConfig.sqpPortOffset); #if UNITY_EDITOR Game.game.levelManager.UnloadLevel(); World.DisposeAllWorlds(); #endif m_GameWorld = new GameWorld("ServerWorld"); m_NetworkStatistics = new NetworkStatisticsServer(m_NetworkServer); m_ChatSystem = new ChatSystemServer(m_Clients, m_NetworkServer); GameDebug.Log("Network server initialized"); Console.AddCommand("load", CmdLoad, "Load a named scene", this.GetHashCode()); Console.AddCommand("unload", CmdUnload, "Unload current scene", this.GetHashCode()); Console.AddCommand("respawn", CmdRespawn, "Respawn character (usage : respawn playername|playerId)", this.GetHashCode()); Console.AddCommand("servername", CmdSetServerName, "Set name of the server", this.GetHashCode()); Console.AddCommand("beginnetworkprofile", CmdBeginNetworkProfile, "begins a network profile", this.GetHashCode()); Console.AddCommand("endnetworkprofile", CmdEndNetworkProfile, "Ends a network profile and analyzes. [optional] filepath for model data", this.GetHashCode()); Console.AddCommand("loadcompressionmodel", CmdLoadNetworkCompressionModel, "Loads a network compression model from a filepath", this.GetHashCode()); Console.AddCommand("list", CmdList, "List clients", this.GetHashCode()); CmdLoad(args); Game.SetMousePointerLock(false); m_ServerStartTime = Time.time; GameDebug.Log("Server initialized"); Console.SetOpen(false); return(true); }
public bool Init(string[] args) { // Set up statemachine for ServerGame m_StateMachine = new StateMachine <ServerState>(); m_StateMachine.Add(ServerState.Idle, null, UpdateIdleState, null); m_StateMachine.Add(ServerState.Loading, null, UpdateLoadingState, null); m_StateMachine.Add(ServerState.Active, EnterActiveState, UpdateActiveState, LeaveActiveState); m_StateMachine.SwitchTo(ServerState.Idle); #if USE_UNET m_NetworkTransport = new UNETTransport(); if (!m_NetworkTransport.Init(serverPort.IntValue, 32)) { return(false); } m_NetworkServer = new NetworkServer(m_NetworkTransport); m_ServerBroadcast = new UNETServerBroadcast(m_NetworkTransport.hostId, new UNETBroadcastConfig(), 7913); // TODO (petera) what if these (max clients and name) changes during play m_ServerBroadcast.gameInfo.maxPlayers = serverMaxClients.IntValue; if (serverServerName.Value.Length == 0) { serverServerName.Value = MakeServername(); } m_ServerBroadcast.gameInfo.servername = serverServerName.Value; GameDebug.Log("Server name: '" + m_ServerBroadcast.gameInfo.servername + "'"); m_ServerBroadcast.gameInfo.levelname = "-"; m_ServerBroadcast.gameInfo.gamemode = "-"; m_ServerBroadcast.Start(); #else m_NetworkTransport = new SocketTransport(serverPort.IntValue); GameDebug.Log("Listening on " + string.Join(", ", NetworkUtils.GetLocalInterfaceAddresses()) + " on port " + serverPort.IntValue); m_NetworkServer = new NetworkServer(m_NetworkTransport); if (Game.game.clientFrontend != null) { var serverPanel = Game.game.clientFrontend.serverPanel; serverPanel.SetPanelActive(true); serverPanel.serverInfo.text += "Listening on:\n"; foreach (var a in NetworkUtils.GetLocalInterfaceAddresses()) { serverPanel.serverInfo.text += a + ":" + serverPort.IntValue + "\n"; } } #endif m_NetworkServer.UpdateClientInfo(); m_NetworkServer.clientInfo.compressionModel = m_Model; m_ServerQueryProtocolServer = new SQP.SQPServer(serverSQPPort.IntValue); var info = m_ServerQueryProtocolServer.ServerInfoData; info.BuildId = Game.game.buildId; info.Port = (ushort)serverPort.IntValue; info.CurrentPlayers = 0; info.GameType = "Deathmatch"; info.Map = ""; info.MaxPlayers = 32; info.ServerName = MakeServername(); #if UNITY_EDITOR Game.game.levelManager.UnloadLevel(); World.DisposeAllWorlds(); #endif m_GameWorld = new GameWorld("ServerWorld"); m_NetworkStatistics = new NetworkStatisticsServer(m_NetworkServer); m_ChatSystem = new ChatSystemServer(m_Clients, m_NetworkServer); GameDebug.Log("Network server initialized"); Console.AddCommand("load", CmdLoad, "Load a named scene", this.GetHashCode()); Console.AddCommand("unload", CmdUnload, "Unload current scene", this.GetHashCode()); Console.AddCommand("respawn", CmdRespawn, "Respawn character (usage : respawn playername|playerId)", this.GetHashCode()); Console.AddCommand("servername", CmdSetServerName, "Set name of the server", this.GetHashCode()); Console.AddCommand("beginnetworkprofile", CmdBeginNetworkProfile, "begins a network profile", this.GetHashCode()); Console.AddCommand("endnetworkprofile", CmdEndNetworkProfile, "Ends a network profile and analyzes. [optional] filepath for model data", this.GetHashCode()); Console.AddCommand("loadcompressionmodel", CmdLoadNetworkCompressionModel, "Loads a network compression model from a filepath", this.GetHashCode()); Console.AddCommand("list", CmdList, "List clients", this.GetHashCode()); CmdLoad(args); Game.SetMousePointerLock(false); m_ServerStartTime = Time.time; GameDebug.Log("Server initialized"); Console.SetOpen(false); return(true); }