This is the main class for holding host information for the server browser, master server, and so forth
Ejemplo n.º 1
0
	public void SetupServerListItem(HostInfo host)
	{
		hostInfo = host;
		ServerNameLabel.text = host.name;
		PlayerCountLabel.text = host.connectedPlayers + "/" + host.maxPlayers;
		GameTypeLabel.text = host.gameType;
		PasswordToggle.isOn = !string.IsNullOrEmpty(host.password) && host.password.Length > 0;
	}
	public void JoinServer(HostInfo host)
	{
		if (!string.IsNullOrEmpty(host.password))
		{
			_lastHost = host;
			//Show password prompt
			PasswordPrompt.SetActive(true);
		}
		else
		{
			//Join server
			FinalizeJoin(host);
		}
	}
Ejemplo n.º 3
0
        private void UpdateServerRequest(NetworkingPlayer sender, NetworkingStream stream)
        {
            ushort port = ObjectMapper.Map <ushort>(stream);

            HostInfo host = null;

            try { host = hosts.First(h => h.IpAddress == sender.Ip.Split('+')[0] && h.port == port); }
            catch { }

            if (host == null)
            {
                socket.Disconnect(sender, "Host not found");
                return;
            }

            host.connectedPlayers = ObjectMapper.Map <int>(stream);
            socket.Disconnect(sender, "Update Complete");
            Debug.Log("Updated a server " + host.IpAddress + ":" + host.port);
        }
Ejemplo n.º 4
0
        private void RegisterServerRequest(NetworkingPlayer sender, NetworkingStream stream)
        {
            ushort port       = ObjectMapper.Map <ushort>(stream);
            int    maxPlayers = ObjectMapper.Map <int>(stream);
            string name       = ObjectMapper.Map <string>(stream);
            string gameType   = ObjectMapper.Map <string>(stream);
            string comment    = ObjectMapper.Map <string>(stream);
            string password   = ObjectMapper.Map <string>(stream);
            string sceneName  = ObjectMapper.Map <string>(stream);

            HostInfo host = null;

            try { host = hosts.First(h => h.IpAddress == sender.Ip.Split('+')[0] && h.port == port); }
            catch { }

            if (host == null)
            {
                hosts.Add(new HostInfo()
                {
                    ipAddress = sender.Ip, port = port, maxPlayers = maxPlayers, name = name, gameType = gameType, comment = comment, password = password, sceneName = sceneName, lastPing = DateTime.Now
                });
                Debug.Log("Registered a new server " + sender.Ip.Split('+')[0] + ":" + port);
            }
            else
            {
                host.name       = name;
                host.maxPlayers = maxPlayers;
                host.gameType   = gameType;
                host.comment    = comment;
                host.password   = password;
                host.sceneName  = sceneName;
                host.lastPing   = DateTime.Now;
                Debug.Log("Updated the registration of a server " + host.IpAddress + ":" + host.port);
            }

            socket.Disconnect(sender, "Register Complete");
        }
Ejemplo n.º 5
0
		/// <summary>
		/// Ping a particular host to get its response time in milliseconds
		/// </summary>
		/// <param name="host">The host object to ping</param>
		/// <param name="port">The port number that the server is running on</param>
		public static void Ping(HostInfo host, ushort pingFromPort = 35791)
		{
#if NETFX_CORE

#else
			System.Threading.Thread pingThread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(ThreadPing));
			pingThread.Start(new object[] { host, pingFromPort });
#endif
		}
	private void FinalizeJoin(HostInfo host)
	{
		NetWorker socket = Networking.Connect(host.IpAddress, host.port,
			host.connectionType == "udp" ? Networking.TransportationProtocolType.UDP : Networking.TransportationProtocolType.TCP, isWinRT);

		if (socket.Connected)
		{
			Networking.SetPrimarySocket(socket);
			Application.LoadLevel(host.sceneName);
		}
		else
		{
			socket.connected += delegate()
			{
				Networking.SetPrimarySocket(socket);
				Application.LoadLevel(host.sceneName);
			};
		}
	}