Inheritance: MonoBehaviour
Exemplo n.º 1
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        /// <param name="args">Command line arguments.</param>
        public static void Main(string[] args)
        {
            AppDomain.CurrentDomain.ProcessExit += OnProcessExit;
            AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
            MasterServer = new MasterServer();
            MasterServer.Start();
            PrintStatus();
            PrintCommands();

            while (true)
            {
                Thread.Sleep(100);
                switch (Console.ReadLine())
                {
                    case "?":
                        PrintCommands();
                        break;
                    case "status":
                        PrintStatus();
                        break;
                    case "reboot":
                        MasterServer.Start();
                        break;
                    case "quit":
                        Environment.Exit(0);
                        return;
                }
            }
        }
Exemplo n.º 2
0
 public void Setup()
 {
     var client = new MasterServer();
     var t = client.GetServers(MasterServerRegion.All, MasterServerFilter.Gamedir("arma2arrowpc"));
     t.Wait(TimeSpan.FromSeconds(10));
     _servers = t.Result.ToList();
 }
        public void BasicQuery()
        {
            var client = new MasterServer();
            var t = client.GetServers(MasterServerRegion.All, MasterServerFilter.Gamedir("arma2arrowpc"));
            t.Wait(TimeSpan.FromSeconds(10));

            Assert.IsTrue(t.Result.Any(), "No servers were returned");
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            //System.Console.Write("Insert the server port: ");
            //int port = Convert.ToInt32(System.Console.ReadLine());

            //Master server fixo
            int port = 8086;
            MasterServer server = new MasterServer(port);

            System.Console.WriteLine("server running on the port: " + port);
            System.Console.WriteLine("<enter> para sair...");
            System.Console.ReadLine();
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            TcpChannel channelServ = new TcpChannel(Constants.MASTER_SERV_PORT);
            ChannelServices.RegisterChannel(channelServ, true);
            MarshalByRefObject master = new MasterServer();
            RemotingServices.Marshal(
                master,
                Constants.REMOTE_MASTER_OBJ_NAME,
                typeof(IMaster)
            );

            Console.WriteLine("Press <enter> to exit");
            Console.ReadLine();
        }
Exemplo n.º 6
0
	void MakeServerWindow(int id)
	{
		
		if (Network.peerType == NetworkPeerType.Disconnected)
		{

			GUILayout.BeginHorizontal();
			GUILayout.Space(10);

			GUILayout.Label("Server name:");
			Server_Name = GUILayout.TextField(Server_Name, 20, GUILayout.Width(130));

			GUILayout.Space(10);
			GUILayout.EndHorizontal();

			GUILayout.BeginHorizontal();
			GUILayout.Space(10);

			GUILayout.Label("Player name:");
			Player_Name = GUILayout.TextField(Player_Name, 20, GUILayout.Width(130));

			GUILayout.Space(10);
			GUILayout.EndHorizontal();

			GUILayout.Space(10);
			GUILayout.BeginHorizontal();
			GUILayout.Space(10);

			// Start a new server
			if (GUILayout.Button("Start Server") && Check_Player_Name())
			{
				if (Server_Name == "")
				{
					Popup_Script.Popup_Box("Please enter the server's name", "Problem starting server...", 5.0f);
				}
				else
				{
					GetComponent<AudioSource>().PlayOneShot(GetComponent<Audio>().JoinGame);
					Network.InitializeServer(5, Connection_Port, Use_Nat);
					MasterServer.RegisterHost(Game_Name, Server_Name, "Host: " + Player_Name);
				}
			}

			// Refresh hosts
			if (GUILayout.Button("Refresh available Servers") || Time.realtimeSinceStartup > Last_Host_List_Request + Host_List_Refresh_Timeout)
			{
				MasterServer.ClearHostList();
				MasterServer.RequestHostList(Game_Name);
				Last_Host_List_Request = Time.realtimeSinceStartup;
			}

			GUILayout.FlexibleSpace();
			GUILayout.Space(10);
			GUILayout.EndHorizontal();
		}
		else
		{
			if (!Is_Ingame && Network.peerType == NetworkPeerType.Server)
			{
				if (GUILayout.Button("Start Game"))
				{
					Is_Ingame = true;
					// register as an in progress game
					MasterServer.RegisterHost(Game_Name, Server_Name, "In Progress");
					//MasterServer.UnregisterHost();

					//LOAD LEVEL 1!
					// Make sure no old RPC calls are buffered and then send load level command
					Network.RemoveRPCsInGroup(0);
					Network.RemoveRPCsInGroup(1);
					// Load level with incremented level prefix (for view IDs)
					networkView.RPC("Load_Level", RPCMode.AllBuffered, Supported_Levels[0], Last_Level_Prefix + 1);
				}
			}
			if (GUILayout.Button("Disconnect"))
			{
				GetComponent<AudioSource>().PlayOneShot(GetComponent<Audio>().LeaveGame);
				Network.Disconnect();
				MasterServer.UnregisterHost();
			}
			GUILayout.FlexibleSpace();

		}
		GUI.DragWindow(new Rect(0, 0, 1000, 1000));
	}
Exemplo n.º 7
0
 public void RpcFinishGame()
 {
     Network.Disconnect();
     MasterServer.UnregisterHost();
 }
 private void StartServer()
 {
     Network.InitializeServer(16, 25002, false);
     MasterServer.RegisterHost(registerGameName, "Divided Islands Game", "Test Server");
 }
Exemplo n.º 9
0
    public void OnGUI()
    {
        if (Network.peerType == NetworkPeerType.Disconnected)
        {
            if (!Network.isClient || !Network.isServer)
            {
                if (GUI.Button(new Rect(25f, 25f, 150f, 30f), "Start New Server"))
                {
                    startServer();
                }

                if (GUI.Button(new Rect(25f, 65f, 150f, 30f), "Connect"))
                {
                    StartCoroutine("RefreshHostList");
                }

                if (hostData != null)
                {
                    for (int i = 0; i < hostData.Length; i++)
                    {
                        if (GUI.Button(new Rect(Screen.width / 2, 65f + (30f * i), 300f, 30f), "Connect to " + hostData[i].gameName))
                        {
                            Network.Connect(hostData[i]);
                        }
                    }
                }
            }
        }
        else
        {
            if (Network.isServer)
            {
                GUILayout.Label("Server");
            }
            else if (Network.isClient)
            {
                GUILayout.Label("Client");

                if (GUI.Button(new Rect(Screen.width / 2 - 75f, 25f, 150f, 30f), "Spawn"))
                {
                    SpawnClientPlayer();
                }
            }
            //string ipAddress = Network.player.ipAddress.ToString();
            //string port = Network.player.port.ToString();

            //GUI.Label(new Rect(140, 20, 250, 40), "IP Address: " + ipAddress + ":" + port);

            if (GUI.Button(new Rect(10, 10, 100, 50), "Disconnect"))
            {
                if (Network.isServer)
                {
                    Network.Disconnect(200);
                    MasterServer.UnregisterHost();
                }

                if (Network.isClient)
                {
                    Network.Disconnect(200);
                }
            }
        }
    }
Exemplo n.º 10
0
 void RequestHosts()
 {
     MasterServer.RequestHostList(gameTypeName);
 }
    void OnGUI()
    {
        //GUILayout.BeginHorizontal();

        GUILayout.BeginHorizontal();


        GUILayout.Label("MasterServer ip = " + MasterServer.ipAddress);
        GUILayout.Label("Player external ip = " + Network.player.externalIP);
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("connect to 213.30.176.244"))
        {
            Network.Connect("213.30.176.244", 7890);
        }

        if (GUILayout.Button("connect to 192.168.0.242"))
        {
            Network.Connect("192.168.0.242", 7890);
        }
        //GUILayout.Label ("" + Network.player.ipAddress);
        if (Network.isServer)
        {
            GUILayout.Label("Running as a server");
        }
        else
        if (Network.isClient)
        {
            GUILayout.Label("Running as a client");
        }
        GUILayout.EndHorizontal();
        //GUILayout.BeginHorizontal();
        if (GUILayout.Button("Refresh"))
        {
            refreshHostList();
        }

        if (loading)
        {
            GUILayout.Label("Loading...");
        }
        else
        {
            scrollPos = GUILayout.BeginScrollView(scrollPos,
                                                  GUILayout.Width(Screen.width), GUILayout.Height(500f));

            HostData[] hosts = MasterServer.PollHostList();
            for (int i = 0; i < hosts.Length; i++)
            {
                HostData d  = hosts[i];
                string   ip = "";
                foreach (string s in d.ip)
                {
                    ip += s + ".";
                }

                string caption = d.gameName + "[" + d.connectedPlayers + "/" + d.playerLimit + "]";
                if (GUILayout.Button(caption,
                                     GUILayout.ExpandWidth(true)))
                {
                    Network.Connect(hosts[i]);
                }
            }
            if (hosts.Length == 0)
            {
                GUILayout.Label("No servers running");
            }

            GUILayout.EndScrollView();
        }
    }
    /// <summary>
    /// The Launcher is a temporary solution to test the server/client implementation.
    /// </summary>
    /// <param name="args"></param>
    static void Main(string[] args)
    {
        ClientProgram myFirstClient = new ClientProgram();

        // Thread serverThread = new Thread(new ThreadStart(() => MasterServer.StartServer()));
        // serverThread.Start();

        MasterServer.StartServer();

        System.Threading.Thread.Sleep(500);

        myFirstClient.ConnectToServer();
        myFirstClient.CreateNewGame("level1");
        myFirstClient.CreateNewPlayerForSession("Snoop Dog", MDC.CharacterClass.Knight);

        // myFirstClient.DisconnectFromServer();

        System.Threading.Thread.Sleep(500);

        ClientProgram mySecondClient = new ClientProgram();

        mySecondClient.ConnectToServer();
        mySecondClient.ConnectToGame(myFirstClient.GameSession_ID);
        mySecondClient.CreateNewPlayerForSession("Tux", MDC.CharacterClass.Archer);

        while (true)
        {
            if (mySecondClient.Update != null)
            {
                Console.WriteLine(mySecondClient.Update.PlayerList[0].PlayerName);
            }
            else
            {
                System.Threading.Thread.Sleep(1500);
            }
        }


        // try
        // {
        //     mySecondClient.ConnectToGame("4711");
        // }
        // catch (System.Exception)
        // {

        //     throw;
        // }

        // //############################################
        // ClientProgram elChappo01 = new ClientProgram();
        // elChappo01.ConnectToServer();
        // elChappo01.CreateNewGame();
        // System.Threading.Thread.Sleep(500);
        // ClientProgram elChappo02 = new ClientProgram();
        // elChappo02.ConnectToServer();
        // //############################################

        ClientProgram myThirdClient = new ClientProgram();

        myThirdClient.ConnectToServer();

        // elChappo02.ConnectToGame(elChappo01.GameSession_ID);
        myThirdClient.ConnectToGame(myFirstClient.GameSession_ID);

        ClientProgram myFourthClient = new ClientProgram();

        myFourthClient.ConnectToServer();
        myFourthClient.ConnectToGame(myFirstClient.GameSession_ID);


        // ClientProgram myFifthClient = new ClientProgram();
        // myFifthClient.ConnectToServer();
        // myFifthClient.ConnectToGame(myFirstClient.GameSession_ID);

        /*
         *
         * myFirstClient.CreateNewPlayerForSession("Snoop Dog", MDC.CharacterClass.MeleeFighter);
         * mySecondClient.CreateNewPlayerForSession("Tux", MDC.CharacterClass.RangeFighter);
         * myThirdClient.CreateNewPlayerForSession("Franz", MDC.CharacterClass.MeleeFighter);
         * myFourthClient.CreateNewPlayerForSession("Pepe", MDC.CharacterClass.MeleeFighter);
         *
         * myFirstClient.StartCreatedGame();
         *
         * myFirstClient.MovePlayer(1, 0);
         * myFirstClient.MovePlayer(2, 0);
         * myFirstClient.MovePlayer(2, 1);
         * // myFirstClient.EndTurn();
         * myFirstClient.MovePlayer(2, 2);
         * myFirstClient.MovePlayer(3, 2);
         *
         * System.Threading.Thread.Sleep(2000);
         * mySecondClient.MovePlayer(18, 2);
         *
         */
        // System.Threading.Thread.Sleep(5000);
        // myFirstClient.DisconnectFromServer();
        while (true)
        {
        }
        // ClientProgram myFifthClient = new ClientProgram();
        // myFifthClient.ConnectToServer();
        // myFifthClient.ConnectToGame(myFirstClient.GameSession_ID);
    }
Exemplo n.º 13
0
 /* ------------------------------ Server ------------------------------ */
 /// <summary>
 /// Server Side: Inititalize server and register a host to connect.
 /// </summary>
 public void OpenHost()
 {
     Network.InitializeServer(totalUser, port, !Network.HavePublicAddress());
     MasterServer.RegisterHost(connectName, appName, comment);
 }
Exemplo n.º 14
0
 /// <summary>
 /// Server Side: Close and clear Host.
 /// </summary>
 public void CloseHost()
 {
     Network.Disconnect();
     MasterServer.UnregisterHost();
     Disconnect();
 }
Exemplo n.º 15
0
 private void PrintHostData()
 {
     HostData[] hostData = MasterServer.PollHostList();
     log.Debug("HostData length " + hostData.Length);
 }
Exemplo n.º 16
0
 private void refreshHostList()
 {
     MasterServer.RequestHostList(gameTypeName);
     refreshing = true;
 }
Exemplo n.º 17
0
 public void HostGame()
 {
     Network.InitializeServer(4, int.Parse(gamePort), !Network.HavePublicAddress());
     MasterServer.RegisterHost(typeName, gameRoomName);
 }
Exemplo n.º 18
0
        private static void Main(string[] args)
        {
            string host     = "127.0.0.1";
            ushort port     = 15940;
            string read     = string.Empty;
            int    eloRange = 0;

            Dictionary <string, string> arguments = ArgumentParser.Parse(args);

            if (args.Length > 0)
            {
                if (arguments.ContainsKey("host"))
                {
                    host = arguments["host"];
                }

                if (arguments.ContainsKey("port"))
                {
                    ushort.TryParse(arguments["port"], out port);
                }

                if (arguments.ContainsKey("elorange"))
                {
                    int.TryParse(arguments["elorange"], out eloRange);
                }
            }
            //else
            //{
            //    Console.WriteLine("Entering nothing will choose defaults.");
            //    Console.WriteLine("Enter Host IP (Default: 0.0.0.0):");
            //    read = Console.ReadLine();
            //    if (string.IsNullOrEmpty(read))
            //        host = "0.0.0.0";
            //    else
            //        host = read;

            //    Console.WriteLine("Enter Port (Default: 15940):");
            //    read = Console.ReadLine();
            //    if (string.IsNullOrEmpty(read))
            //        port = 15940;
            //    else
            //    {
            //        ushort.TryParse(read, out port);
            //    }
            //}

            Console.WriteLine(string.Format("Hosting ip [{0}] on port [{1}]", host, port));
            PrintHelp();
            MasterServer server = new MasterServer(host, port);

            server.EloRange = eloRange;
            server.ToggleLogging();

            while (true)
            {
                Thread.Sleep(500);
                //read = Console.ReadLine().ToLower();
                //if (read == "s" || read == "stop")
                //{
                //    lock (server)
                //    {
                //        Console.WriteLine("Server stopped.");
                //        server.Dispose();
                //    }
                //}
                //else if (read == "l" || read == "log")
                //{
                //    if (server.ToggleLogging())
                //        Console.WriteLine("Logging has been enabled");
                //    else
                //        Console.WriteLine("Logging has been disabled");
                //}
                //else if (read == "r" || read == "restart")
                //{
                //    lock (server)
                //    {
                //        if (server.IsRunning)
                //        {
                //            Console.WriteLine("Server stopped.");
                //            server.Dispose();
                //        }
                //    }

                //    Console.WriteLine("Restarting...");
                //    Console.WriteLine(string.Format("Hosting ip [{0}] on port [{1}]", host, port));
                //    server = new MasterServer(host, port);
                //}
                //else if (read == "q" || read == "quit")
                //{
                //    lock (server)
                //    {
                //        Console.WriteLine("Quitting...");
                //        server.Dispose();
                //    }
                //    break;
                //}
                //else if (read == "h" || read == "help")
                //    PrintHelp();
                //else if (read.StartsWith("elo"))
                //{
                //    int index = read.IndexOf("=");
                //    string val = read.Substring(index + 1, read.Length - (index + 1));
                //    if (int.TryParse(val.Replace(" ", string.Empty), out index))
                //    {
                //        Console.WriteLine(string.Format("Elo range set to {0}", index));
                //        if (index == 0)
                //            Console.WriteLine("Elo turned off");
                //        server.EloRange = index;
                //    }
                //    else
                //        Console.WriteLine("Invalid elo range provided (Must be an integer)\n");
                //}
                //else
                //    Console.WriteLine("Command not recognized, please try again");
            }
        }
Exemplo n.º 19
0
 void Awake()
 {
     MasterServer.RequestHostList(gameName);
 }
 void OnApplicationExit()
 {
     MasterServer.UnregisterHost();
 }
Exemplo n.º 21
0
 public void refreshHostList()
 {
     MasterServer.RequestHostList(gameName);
     refreshingHostList = true;
     Debug.Log("Getting Host List");
 }
Exemplo n.º 22
0
 private void startServer()
 {
     Network.InitializeServer(4, 25002, false);
     MasterServer.RegisterHost(gameName, "Game Name", "Server");
     SpawnServerPlayer();
 }
 public void StartServer()
 {
     DontDestroyOnLoad(this);
     Network.InitializeServer(3, 27015, !Network.HavePublicAddress());
     MasterServer.RegisterHost(gameName, "LOBBY", "lobby test");
 }
        void DoMasterServerRequestHost()
        {
            MasterServer.ClearHostList();

            MasterServer.RequestHostList(gameTypeName.Value);
        }
 public void RefreshHosts()
 {
     MasterServer.RequestHostList(gameName);
     refreshHosts = true;
     timeOut      = Time.time + 10f;
 }
Exemplo n.º 26
0
 static void StartServer(string lobbyName)
 {
     Network.InitializeServer(4, 12, !Network.HavePublicAddress());
     MasterServer.RegisterHost(gameTypeName, lobbyName);
 }
Exemplo n.º 27
0
    // Use this for initialization
    void Start()
    {
        // setup reference to networkVariables
        nvs = gameObject.GetComponent("networkVariables") as networkVariables;

        // get server version
        serverVersion = nvs.serverVersion;

        // Use NAT punchthrough if no public IP present
        Network.InitializeServer(32, 11177, !Network.HavePublicAddress());
        MasterServer.RegisterHost(serverVersion, SystemInfo.deviceName, "Test server");

        // create server owners buggy
        GameObject cartGameObject      = Instantiate(Resources.Load("buggy1"), new Vector3(0, 5, 0), Quaternion.identity) as GameObject;
        GameObject ballGameObject      = Instantiate(Resources.Load("ball"), new Vector3(3, 5, 0), Quaternion.identity) as GameObject;
        GameObject characterGameObject = Instantiate(Resources.Load("lil_patrick"), new Vector3(0, 5, 0), Quaternion.identity) as GameObject;

        // set buggy as characters parent
        characterGameObject.transform.parent = cartGameObject.transform;

        // networkview that shit
        NetworkViewID cartViewIDTransform = Network.AllocateViewID();
        NetworkView   cgt = cartGameObject.AddComponent("NetworkView") as NetworkView;

        cgt.observed             = cartGameObject.transform;
        cgt.viewID               = cartViewIDTransform;
        cgt.stateSynchronization = NetworkStateSynchronization.Unreliable;
        NetworkViewID cartViewIDRigidbody = Network.AllocateViewID();
        NetworkView   cgr = cartGameObject.AddComponent("NetworkView") as NetworkView;

        cgr.observed             = cartGameObject.rigidbody;
        cgr.viewID               = cartViewIDRigidbody;
        cgr.stateSynchronization = NetworkStateSynchronization.Unreliable;
        NetworkViewID ballViewID = Network.AllocateViewID();

        ballGameObject.networkView.viewID = ballViewID;
        NetworkViewID characterViewID = Network.AllocateViewID();

        characterGameObject.networkView.viewID = characterViewID;

        // turn it into a PlayerInfo
        nvs.myInfo.cartGameObject      = cartGameObject;
        nvs.myInfo.cartModel           = "buggy1";
        nvs.myInfo.cartViewIDTransform = cartViewIDTransform;
        nvs.myInfo.cartViewIDRigidbody = cartViewIDRigidbody;
        nvs.myInfo.ballGameObject      = ballGameObject;
        nvs.myInfo.ballModel           = "ball";
        nvs.myInfo.ballViewID          = ballViewID;
        nvs.myInfo.characterGameObject = characterGameObject;
        nvs.myInfo.characterModel      = "lil_patrick";
        nvs.myInfo.characterViewID     = characterViewID;
        nvs.myInfo.currentMode         = 0;     // set in buggy

        // get self
        nvs.myInfo.player = Network.player;

        // keep a copy
        myInfo = nvs.myInfo;

        // add myInfo to the player list
        nvs.players = new ArrayList();
        nvs.players.Add(myInfo);

        // ANY SERVER SIDE SCRIPTS GO HERE
        //********************************************
        // receives all players inputs and handles fiziks
        gameObject.AddComponent("controlServer");
        // chat
        gameObject.AddComponent("netChat");
        //pause
        gameObject.AddComponent("netPause");
        //********************************************
    }
Exemplo n.º 28
0
        public override void OnEnter()
        {
            MasterServer.ClearHostList();

            Finish();
        }
Exemplo n.º 29
0
 private void StartServer()
 {
     Network.InitializeServer(4, 7777, !Network.HavePublicAddress());
     MasterServer.RegisterHost(typeName, "Room1");
     MasterServer.ipAddress = "127.0.0.1";
 }
Exemplo n.º 30
0
    //----------------------------------------------------------------window Multiplayer Main
    void DoMyWindow3(int windowID)
    {
        GUILayout.BeginVertical();
        GUILayout.Label("Multiplayer Setup");
        GUILayout.Label("                  ", "Divider");
        GUILayout.Label("Username");
        username = GUILayout.TextField(username, 32);
        GUILayout.Label("                  ", "Divider");

        if (GUILayout.Button("start a server"))
        {
            options        = false;
            main           = false;
            multiplayer    = false;
            startServerWin = true;
        }

        if (GUILayout.Button("Refresh Server list"))
        {
            Debug.Log("Refresh Hosts");
            refreshHostList();
        }
        Debug.Log("Refresh");
        refreshHostList();

        if (GUILayout.Button("Back To Main"))
        {
            options        = false;
            main           = true;
            multiplayer    = false;
            startServerWin = false;
        }

        GUILayout.Label("password (defult is nimda)");
        password = GUILayout.PasswordField(password, "*"[0], 32);

        GUILayout.Label("Multiplayer Servers (may need refresh)");
        GUILayout.Label("                  ", "Divider");
        int i = 0;

        if (MasterServer.PollHostList().Length > i)
        {
            foreach (HostData element in hostData)
            {
                if (GUILayout.Button(element.connectedPlayers + " of " + element.playerLimit + " on level " + element.comment + "[" + element.ip[0] + "]"))
                {
                    string tmpIp = "";
                    tmpIp = element.ip[i] + "";

                    options          = false;
                    main             = false;
                    multiplayer      = false;
                    startServerWin   = false;
                    loadinglevelMenu = true;

                    Connect(tmpIp, element.port);
                }
                i++;
            }
        }
        GUILayout.Label("                  ", "Divider");
        GUILayout.EndVertical();
    }
Exemplo n.º 31
0
 private void RefreshHostList()
 {
     MasterServer.RequestHostList(typeName);
 }
Exemplo n.º 32
0
	void MakeExistingGamesWindow(int id)
	{


		HostData[] data = MasterServer.PollHostList();
		string connections;
		bool inprogress;
		
		GUILayout.Space(5);

		GUILayout.BeginHorizontal();
		
		GUILayout.EndHorizontal();
		
		foreach (HostData element in data)
		{
			GUILayout.BeginHorizontal();

			// Do not display NAT enabled games if we cannot do NAT punchthrough
			if (!(Filter_NAT_Hosts && element.useNat))
			{
				connections = element.connectedPlayers + "/" + element.playerLimit;
				if (element.comment == "In Progress")
				{
					inprogress = true;
				}
				else
				{
					inprogress = false;
				}
				GUILayout.Label(element.gameName);
				GUILayout.Space(5);
				GUILayout.Label(connections);
				GUILayout.Space(5);

				// Indicate if NAT punchthrough will be performed, omit showing GUID
				if (element.useNat)
				{
					GUILayout.Label("NAT");
					GUILayout.Space(5);
				}
				/*string hostInfo = "";
				// Here we display all IP addresses, there can be multiple in cases where
				// internal LAN connections are being attempted. In the GUI we could just display
				// the first one in order not confuse the end user, but internally Unity will
				// do a connection check on all IP addresses in the element.ip list, and connect to the
				// first valid one.
				foreach (string hostIP in element.ip)
				{
					hostInfo = hostInfo + hostIP + ":" + element.port + " ";
					break;
				}

				//GUILayout.Label("[" + element.ip + ":" + element.port + "]");	
				GUILayout.Label(hostInfo);
				GUILayout.Space(5);*/
				GUILayout.Label(element.comment);
				GUILayout.Space(5);
				GUILayout.FlexibleSpace();
				if (!inprogress) 
				{
					if (GUILayout.Button("Connect") && Check_Player_Name())
					{
						Network.Connect(element);
					}
				}
			}
			GUILayout.EndHorizontal();
		}
		GUI.DragWindow(new Rect(0, 0, 1000, 1000));
	}
Exemplo n.º 33
0
 private void StartServer()
 {
     Network.InitializeServer(4, 25000, !Network.HavePublicAddress());
     MasterServer.RegisterHost(typeName, gameName);
 }
Exemplo n.º 34
0
    // Here we paint the menu screen so the player can choose to join a game or start a new game
    void ShowGUI()
    {
        // in the AWAKE method we used: DontDestroyOnLoad(this);
        // so when we load our game level this ShowGUI is still running
        // so here we can see what menu we should be showing and display the appropriate menu

        // When we're ingame we want to show a Disconnect button to quit the game and return to the lobby
        if (gamemenustate == menustate.ingame)
        {
            /*if (GUI.Button (new Rect(10,10,90,30),"Disconnect"))
             * {
             *      Network.Disconnect(); // Tell all the other clients you're disconnecting
             *      MasterServer.UnregisterHost();
             *      gamemenustate = menustate.networklobby;
             *      // Return to the Master Game Server Lobby because we pressed disconnect
             *      Application.LoadLevel("MasterGameServerLobby");
             * }*/
        }
        else if (gamemenustate == menustate.networklobby)           // ensure we're in the lobby, and not off somewhere unexpected
        {
            if (Network.peerType == NetworkPeerType.Disconnected)
            {
                format.fontSize         = 40;
                format.normal.textColor = Color.white;
                GUI.Label(new Rect(((Screen.width / 2) - 80) * 0.2f, (Screen.height / 2) - 200, 400, 50), "Lite: Special Forces", format);
                //GUI.Label(new Rect(((Screen.width / 2) - 80) * 0.2f, (Screen.height / 2) - 200, 400, 50), "Lite: Special Forces", format);

                gameName = GUI.TextField(new Rect((((Screen.width / 2)) * 0.2f) + 200,
                                                  (Screen.height / 2) - 100,
                                                  200,
                                                  20),
                                         gameName);

                gamePort = GUI.TextField(new Rect((((Screen.width / 2)) * 0.2f) + 400,
                                                  (Screen.height / 2) - 100,
                                                  50,
                                                  20),
                                         gamePort);

                /*
                 * joinip = GUI.TextField(new Rect((((Screen.width / 2)) * 0.2f) + 200,
                 *                       (Screen.height / 2) - 75,
                 *                      200,
                 *                      20),
                 *                      joinip);
                 *
                 * joinport = GUI.TextField(new Rect((((Screen.width / 2)) * 0.2f) + 400,
                 *                       (Screen.height / 2) - 75,
                 *                      50,
                 *                      20),
                 *                      joinport);
                 */
                if (GUI.Button(new Rect(0, 0, 150, 20),
                               "Quit"))
                {
                    Application.Quit();
                }
                // Start a new server
                if (GUI.Button(new Rect(((Screen.width / 2) - 100) * 0.2f,
                                        (Screen.height / 2) - 100,
                                        150,
                                        20),
                               "Start Server"))
                {
                    // If start server is chosen then we want to initialize ourselves as a server
                    // and then register with the master server so other players will see us
                    // as a choice in the list of game servers

                    // We'll use Network.InitializeServer to enable our Game Server (GS) functionality
                    // but first we need to determine if we'll require clients to connect to us directly
                    // or by using NPT.

                    // The first two parameters to InitializeServer are how many clients can connect and the port to use
                    // The port needs to be unique, but on desktop/laptop pc's it's not usually an issue as there aren't a
                    // lot of network listeners running to contend
                    // Once the game starts you can consider using Network.maxConnections to stop any new players
                    // from connecting

                    if (doneTesting)
                    { // If done testing use the more thourough results of the testing to setup the server
                        serverPort = int.Parse(gamePort);
                        Network.InitializeServer(15, serverPort, useNat);
                    }
                    else // otherwise setup the server and specific NPT based on public/private IP
                         // this is not as accurate as the full test, but is sufficient for most needs
                    {
                        Network.InitializeServer(15, serverPort, !Network.HavePublicAddress());
                    }
                    MasterServer.updateRate = 3;
                    MasterServer.RegisterHost(gameType, gameName, "lsf_desert");
                }

                /*
                 * if (GUI.Button(new Rect(((Screen.width / 2) - 100) * 0.2f,
                 *                       (Screen.height / 2) - 75,
                 *                      150,
                 *                      20),
                 *                      "Direct Connect"))
                 * {
                 *  HostData[] data1 = MasterServer.PollHostList();	// Extract the list of available GS's into a local variable array for processing
                 *  int _cnt1 = 0;
                 *
                 *  // Loop through all the available GS's provided by the MGS and display each one so we can choose one to joing
                 *  foreach (HostData gs in data1)
                 *  {
                 *      // Do not display NAT enabled games if we cannot do NAT punchthrough
                 *      if (!(filterNATHosts && gs.useNat))
                 *      {
                 *          // Build a name string to use for displaying the GS in the list
                 *
                 *          if (gs.ip[_cnt1] == joinip)
                 *          {
                 *              // Enable NAT functionality based on GS host we're connecting to
                 *              useNat = gs.useNat;
                 *              if (useNat)
                 *              {
                 *                  print("Using Nat punchthrough to connect");
                 *                  Network.Connect(gs.guid);
                 *              }
                 *              else
                 *              {
                 *                  print("Connecting directly to host");
                 *                  Network.Connect(gs.ip, gs.port);
                 *              }
                 *          }
                 *      }
                 *      _cnt1++;
                 *  }
                 *  Network.Connect(joinip, joinport);
                 * }
                 */
                HostData[] data = MasterServer.PollHostList();                  // Extract the list of available GS's into a local variable array for processing
                int        _cnt = 0;

                // Loop through all the available GS's provided by the MGS and display each one so we can choose one to joing
                foreach (HostData gs in data)
                {
                    // Do not display NAT enabled games if we cannot do NAT punchthrough
                    if (!(filterNATHosts && gs.useNat))
                    {
                        // Build a name string to use for displaying the GS in the list
                        string name = gs.gameName + " (" + gs.ip[_cnt] + ") " + gs.comment + " (" + gs.connectedPlayers + " / " + gs.playerLimit + ")";

                        if (GUI.Button(new Rect(((Screen.width / 2) - 100) * 0.2f,
                                                (Screen.height / 2) + (40 * _cnt),
                                                550,
                                                30),
                                       name))
                        {
                            // Enable NAT functionality based on GS host we're connecting to
                            useNat = gs.useNat;
                            if (useNat)
                            {
                                print("Using Nat punchthrough to connect");
                                Network.Connect(gs.guid);
                            }
                            else
                            {
                                print("Connecting directly to host");
                                Network.Connect(gs.ip, gs.port);
                            }
                        }
                    }
                    _cnt++;
                }
            }
        }
    }
Exemplo n.º 35
0
 void OnDestroy()
 {
     Network.Disconnect();
     MasterServer.UnregisterHost();
 }