Esempio n. 1
0
 public static void    SendChatMessageToAllPlayersAsServer(string msg)
 {
     if (NetworkStatus.IsServerStarted())
     {
         SendChatMessageToAllPlayers(msg, singleton.serverChatNick);
     }
 }
Esempio n. 2
0
        // Update is called once per frame
        void Update()
        {
            if (!NetworkServer.active)
            {
                return;
            }

            if (0 == this.mapCycleList.Count)
            {
                return;
            }

            if (NetworkStatus.IsServerStarted() && !SceneChanger.isLoadingScene)
            {
                m_timePassedSinceStartedMap += Time.deltaTime;

                // automatic map changing
                if (this.AutomaticMapChanging)
                {
                    if (m_timePassedSinceStartedMap > this.mapChangeInterval)
                    {
                        this.ChangeMapToNextMap();

                        //	m_timePassedSinceStartedMap = 0 ;
                    }
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Throws exception if server is not started, with explanation that command can only be used on server.
 /// </summary>
 public static void    EnsureServerIsStarted()
 {
     if (!NetworkStatus.IsServerStarted())
     {
         throw new System.Exception("Only server can use this command");
     }
 }
Esempio n. 4
0
        /// <summary> Use only on server. </summary>
        public static void    SendChatMessageToPlayer(Player player, string msg)
        {
            if (!NetworkStatus.IsServerStarted())
            {
                return;
            }

            SendChatMessageToPlayer(player, msg, singleton.serverChatNick);
        }
Esempio n. 5
0
        // Update is called once per frame
        void Update()
        {
            if (!NetworkStatus.IsServerStarted())
            {
                return;
            }


            if (!SceneChanger.isLoadingScene)
            {
                m_timePassedSinceStartedMap   += Time.deltaTime;
                m_timeSinceCheckedForRoundEnd += Time.deltaTime;

                if (m_enableRoundSystem)
                {
                    // check if round should be started
                    if (!m_isRoundStartedSinceMapChange)
                    {
                        // round is not started since the map was changed
                        if (m_timePassedSinceStartedMap > 2)
                        {
                            this.StartRound();
                            return;
                        }
                    }
                    else
                    {
                        if (m_isRoundFinished && Time.time - m_timeWhenRoundFinished > 3.5f)
                        {
                            // start new round
                            this.StartRound();
                            return;
                        }
                    }

                    // check if round should be ended
                    if (m_isRoundStartedSinceMapChange && !m_isRoundFinished && m_timeSinceCheckedForRoundEnd > 1 &&
                        Time.time - m_timeWhenRoundStarted > 3)
                    {
                        try {
                            CheckForRoundEnd();
                        } finally {
                            m_timeSinceCheckedForRoundEnd = 0;
                        }
                    }
                }
            }


            this.RespawnPlayers();
        }
Esempio n. 6
0
        private static void    SendChatMessageToPlayer(Player player, string msg, string sender)
        {
            if (!NetworkStatus.IsServerStarted())
            {
                return;
            }

            var chatSync = player.GetComponent <ChatSync> ();

            if (chatSync != null)
            {
                chatSync.TargetChatMsg(player.connectionToClient, msg, sender);
            }
        }
Esempio n. 7
0
        /// <summary> Use only on server. </summary>
        public static void    SendChatMessageToAllPlayers(string msg, string sender)
        {
            if (!NetworkStatus.IsServerStarted())
            {
                return;
            }

            foreach (var player in PlayerManager.GetLoggedInNonBotPlayers())
            {
                SendChatMessageToPlayer(player, msg, sender);
            }

            if (!NetworkStatus.IsHost())
            {
                // running as dedicated server
                // we should invoke the event here, because there is no local player to receive the chat message
                onChatMessage(new ChatMessage(msg, sender));
            }
        }
Esempio n. 8
0
        void Update()
        {
            // open/close score view
            if (Input.GetKeyDown(singleton.toggleKey))
            {
                if (GameManager.CanGameObjectsReadUserInput() && (NetworkStatus.IsClientConnected() ||
                                                                  NetworkStatus.IsServerStarted()))
                {
                    // toggle score view
                    m_isScoreDrawingToggled = !m_isScoreDrawingToggled;
                }
            }

            this.scoreCanvas.enabled = m_isScoreDrawingToggled;

            if (this.scoreCanvas.enabled)
            {
                UpdateUI();
            }
        }
Esempio n. 9
0
        string ProcessCommand(string command)
        {
            //	string invalidSyntaxString = "Invalid syntax.";

            string[] words    = command.Split(" ".ToCharArray());
            int      numWords = words.Length;
            //	string restOfTheCommand = command.Substring (command.IndexOf (' ') + 1);

            string response = "";

            //	var networkManager = UnityEngine.Networking.NetworkManager.singleton;

            if (words [0] == "endround")
            {
                if (NetworkStatus.IsServerStarted())
                {
                    RoundSystem.singleton.EndRound("");
                }
            }

            return(response);
        }
Esempio n. 10
0
 void EnableDisable()
 {
     this.gameObject.SetActive(NetworkStatus.IsServerStarted());
 }
Esempio n. 11
0
        string ProcessCommand(string command)
        {
            //	string invalidSyntaxString = "Invalid syntax.";

            string[] words    = command.Split(" ".ToCharArray());
            int      numWords = words.Length;
            //	string restOfTheCommand = command.Substring (command.IndexOf (' ') + 1);

            string response = "";

            //	var networkManager = UnityEngine.Networking.NetworkManager.singleton;


            if (2 == numWords && words [0] == "change_scene")
            {
                string newSceneName = words [1];
                if (NetworkStatus.IsServerStarted())
                {
                    if (newSceneName.Length < 1)
                    {
                        response += "Invalid scene name.";
                    }
                    else
                    {
                        bool mapExists = MapCycle.singleton.mapCycleList.Contains(newSceneName);

                        if (mapExists)
                        {
                            response += "Changing scene to " + newSceneName + ".";
                            SceneChanger.ChangeScene(newSceneName);
                        }
                        else
                        {
                            response += "This scene does not exist.";
                        }
                    }
                }
            }
            else if (words [0] == "list_maps")
            {
                if (NetworkStatus.IsServerStarted())
                {
                    var maps = MapCycle.singleton.mapCycleList;
                    foreach (string mapName in maps)
                    {
                        response += mapName + "\n";
                    }
                }
                else
                {
                    if (NetworkStatus.IsClientConnected())
                    {
                        // Ask server to display all available maps.
                        Player.local.CmdListMaps();
                    }
                }
            }
            else if (words [0] == "timeleft")
            {
                if (NetworkStatus.IsServerStarted())
                {
                    response += MapCycle.singleton.GetTimeLeftAsString();
                }
            }
            else if (words [0] == "nextmap")
            {
                if (NetworkStatus.IsServerStarted())
                {
                    response += MapCycle.singleton.GetNextMap();
                }
            }

            return(response);
        }
Esempio n. 12
0
        static void    DrawConsole()
        {
            int consoleWidth  = Screen.width;
            int consoleHeight = Screen.height / 2;

            // Draw rectangle in background.
            GUI.Box(new Rect(0, 0, consoleWidth, consoleHeight), "");


            // Draw some statistics above console

            GUILayout.BeginArea(new Rect(0, 0, Screen.width, 30));
            GUILayout.BeginHorizontal();

            // display fps
            GUILayout.Label("FPS: " + GameManager.GetAverageFps());

            // display uptime
            if (NetworkStatus.IsServerStarted())
            {
                GUILayout.Label(" uptime: " + Utilities.Utilities.FormatElapsedTime(Time.realtimeSinceStartup));
            }

            // let anybody else display their own stats
            try {
                onDrawStats();
            } catch (System.Exception ex) {
                Debug.LogException(ex);
            }

            // Display network statistics for client
            if (NetworkStatus.IsClientConnected() && !NetworkStatus.IsHost())
            {
                NetworkConnection conn = NetManager.GetClient().connection;
                byte error             = 0;
                GUILayout.Label(" ping: " + NetworkTransport.GetCurrentRtt(conn.hostId, conn.connectionId, out error) + " ms");
                GUILayout.Label(" lost_packets: " + NetworkTransport.GetNetworkLostPacketNum(conn.hostId, conn.connectionId, out error));
                GUILayout.Label(" received_rate: " + NetworkTransport.GetPacketReceivedRate(conn.hostId, conn.connectionId, out error));
                GUILayout.Label(" sent_rate: " + NetworkTransport.GetPacketSentRate(conn.hostId, conn.connectionId, out error));
            }

            GUILayout.EndHorizontal();
            GUILayout.EndArea();


            m_consoleScrollPosition = GUILayout.BeginScrollView(
                m_consoleScrollPosition, GUILayout.Width(consoleWidth), GUILayout.Height(consoleHeight));


            /*
             * // Display player information
             * if( networkManager.IsServer() ) {
             *
             *      GUILayout.Label("Players");
             *      GUILayout.Label("name\t\t | health\t | kills\t | deaths\t | ping");
             *      foreach ( Player player in networkManager.players ) {
             *
             *              string s = "";
             *              s += player.playerName + "\t ";
             *              if (player.mainNetworkScript != null) {
             *                      s += player.mainNetworkScript.health + "\t " + player.mainNetworkScript.numKills + "\t " + player.mainNetworkScript.numDeaths ;
             *              }
             *              s += "\t 0 ms";
             *
             *              GUILayout.Label( s );
             *      }
             * }
             */

            // Draw log string
            //	if( logString != "" ) {
            {
                /*
                 * GUIStyle style = new GUIStyle( GUI.skin.textArea );
                 * //	style.wordWrap = true;
                 * style.richText = true ;
                 * GUILayout.Space(25);
                 * GUILayout.TextArea( logString, style, GUILayout.MinHeight (consoleHeight - 30) );
                 */

                GUILayout.Space(30);
                GUILayout.Label(m_logString);
            }

            GUILayout.EndScrollView();


            GUILayout.BeginHorizontal();

            string textToProcess = "";

            // Edit box for commands input.
            GUI.SetNextControlName("commands_input");
            m_consoleCommandText = GUILayout.TextField(m_consoleCommandText, 1000, GUILayout.Width(Screen.width / 4), GUILayout.Height(40));
            if (Event.current.isKey && GUI.GetNameOfFocusedControl() == "commands_input")
            {
                if (Event.current.keyCode == KeyCode.UpArrow)
                {
                    // up arrow pressed and edit box is in focus
                    BrowseHistoryBackwards();
                }
                else if (Event.current.keyCode == KeyCode.DownArrow)
                {
                    // down arrow pressed and edit box is in focus
                    BrowseHistoryForwards();
                }
                else if (Event.current.keyCode == KeyCode.Return)
                {
                    // enter pressed
                    textToProcess = m_consoleCommandText;
                }
            }

            // submit button
            //	bool submited = GUILayout.Button( "Submit", GUILayout.Width(60), GUILayout.Height(40) );
            bool submited = GameManager.DrawButtonWithCalculatedSize("Submit");

            if (submited)
            {
                textToProcess = m_consoleCommandText;
            }

            GUILayout.EndHorizontal();


            if (textToProcess != "")
            {
                SubmittedText(textToProcess);

                // clear input text box
                SetInputBoxText("");
            }
        }
Esempio n. 13
0
        string ProcessCommand(string command)
        {
            string[] words            = CommandManager.SplitCommandIntoArguments(command);
            int      numWords         = words.Length;
            string   restOfTheCommand = CommandManager.GetRestOfTheCommand(command, 0);

            string response = "";


            if (2 == numWords && words [0] == "camera_disable")
            {
                int cameraDisable = int.Parse(words [1]);

                if (Camera.main != null)
                {
                    if (0 == cameraDisable)
                    {
                        Camera.main.enabled = true;
                    }
                    else if (1 == cameraDisable)
                    {
                        Camera.main.enabled = false;
                    }
                    else
                    {
                        response += "Invalid value.";
                    }
                }
            }
            else if (words [0] == "uptime")
            {
                response += Utilities.Utilities.FormatElapsedTime(Time.realtimeSinceStartup);
            }
//			else if (words [0] == "server_cmd") {
//
//				if (NetworkStatus.IsClientConnected ()) {
//					if (numWords < 2)
//						response += invalidSyntaxString;
//					else
//						Player.local.ExecuteCommandOnServer (restOfTheCommand);
//				}
//
//			}
            else if (words [0] == "client_cmd")
            {
                if (NetworkStatus.IsServerStarted())
                {
                    if (numWords < 2)
                    {
                        response += CommandManager.invalidSyntaxText;
                    }
                    else
                    {
                        CommandManager.SendCommandToAllPlayers(restOfTheCommand, true);
                    }
                }
            }
            else if (words [0] == "players")
            {
                // list all players

                response += "name | net id";
                if (NetworkStatus.IsServerStarted())
                {
                    response += " | ip";
                }
                response += "\n";

                foreach (var player in PlayerManager.players)
                {
                    response += player.playerName + " | " + player.netId.Value;
                    if (NetworkStatus.IsServerStarted())
                    {
                        response += " | " + player.connectionToClient.address;
                    }
                    response += "\n";
                }
            }
            else if (words [0] == "kick")
            {
                if (NetworkStatus.IsServerStarted())
                {
                    var p = PlayerManager.GetPlayerByName(restOfTheCommand);
                    if (null == p)
                    {
                        response += "There is no such player connected.";
                    }
                    else
                    {
                        p.DisconnectPlayer(3, "You are kicked from server.");
                    }
                }
                else
                {
                    response += "Only server can use this command.";
                }
            }
            else if (words [0] == "kick_instantly")
            {
                if (NetworkStatus.IsServerStarted())
                {
                    var p = PlayerManager.GetPlayerByName(restOfTheCommand);
                    if (null == p)
                    {
                        response += "There is no such player connected.";
                    }
                    else
                    {
                        p.DisconnectPlayer(0, "");
                    }
                }
                else
                {
                    response += "Only server can use this command.";
                }
            }
            else if (words [0] == "bot_add")
            {
                if (NetworkStatus.IsServerStarted())
                {
                    //					Player player = this.networkManager.AddBot ();
                    //					if (player != null)
                    //						response += "Added bot: " + player.playerName;
                    //					else
                    //						response += "Failed to add bot.";
                    //

                    /*	GameObject go = GameObject.Instantiate( this.playerObjectPrefab );
                     * if( go != null ) {
                     *      go.GetComponent<NavMeshAgent>().enabled = true ;
                     *
                     *      FPS_Character script = go.GetComponent<FPS_Character>();
                     *      script.isBot = true ;
                     *              //	script.playerName = this.networkManager.CheckPlayerNameAndChangeItIfItExists( "bot" );
                     *      // find random waypoints
                     *      GameObject[] waypoints = GameObject.FindGameObjectsWithTag( "Waypoint" );
                     *      if( waypoints.Length > 0 ) {
                     *              int index1 = Random.Range( 0, waypoints.Length );
                     *              int index2 = Random.Range( 0, waypoints.Length );
                     *              if( index1 == index2 ) {
                     *                      index2 ++ ;
                     *                      if( index2 >= waypoints.Length )
                     *                              index2 = 0 ;
                     *              }
                     *
                     *              script.botWaypoints.Add( waypoints[index1].transform );
                     *              script.botWaypoints.Add( waypoints[index2].transform );
                     *
                     *              script.botCurrentWaypointIndex = 0;
                     *      }
                     *
                     * //	Player player = this.networkManager.AddLocalPlayer( go );
                     *
                     *      // the above function assigns name
                     * //	script.playerName = player.playerName ;
                     *
                     *      NetworkServer.Spawn( go );
                     *
                     *      script.respawnOnStart = true;
                     * //	script.Respawn();
                     *
                     *      response += "Added bot." ;
                     *
                     * } else {
                     *      response += "Can't create object for bot." ;
                     * }
                     */
                }
                else
                {
                    response += "Only server can use this command.";
                }
            }
            else if (words [0] == "bot_add_multiple")
            {
                //				if (this.networkManager.IsServer () && NetworkStatus.IsServerStarted ()) {
                //
                //					int numBotsToAdd = 0;
                //					if (2 == numWords && int.TryParse (words [1], out numBotsToAdd)) {
                //
                //						int numBotsAdded = 0;
                //						for (int i = 0; i < numBotsToAdd; i++) {
                //							Player player = this.networkManager.AddBot ();
                //							if (player != null)
                //								numBotsAdded++;
                //						}
                //
                //						response += "Added " + numBotsAdded + " bots.";
                //
                //					} else {
                //						response += invalidSyntaxString;
                //					}
                //				}
            }
            else if (words [0] == "remove_all_bots")
            {
                if (NetworkStatus.IsServerStarted())
                {
                    int count = 0;
                    foreach (var p in PlayerManager.players)
                    {
                        if (p.IsBot())
                        {
                            p.DisconnectPlayer(0, "");
                            count++;
                        }
                    }
                    response += "Removed " + count + " bots.";
                }
            }
            else if (words [0] == "startserver" || words[0] == "starthost")
            {
                int portNumber = NetManager.defaultListenPortNumber;

                if (numWords > 1)
                {
                    portNumber = int.Parse(words [1]);
                }

                if (words [0] == "startserver")
                {
                    NetManager.StartServer(portNumber);
                }
                else
                {
                    NetManager.StartHost(portNumber);
                }
            }
            else if (words [0] == "connect")
            {
                if (numWords != 3)
                {
                    response += CommandManager.invalidSyntaxText;
                }
                else
                {
                    string ip   = words [1];
                    int    port = int.Parse(words [2]);

                    NetManager.StartClient(ip, port);
                }
            }
            else if (words [0] == "stopnet")
            {
                NetManager.StopNetwork();
            }
            else if (words [0] == "exit")
            {
                GameManager.singleton.ExitApplication();
            }

            return(response);
        }