Matchmaking feature removed because Unity pretty much abandoned it and plans to replace it with a solution on Google Cloud. People that need it might as well use the 'fixes-only' version.

This commit is contained in:
vis2k 2018-07-19 17:43:37 +02:00
parent 0425e896aa
commit 27f5717b70
5 changed files with 16 additions and 412 deletions

View File

@ -21,7 +21,6 @@ public class NetworkManagerHUDEditor : Editor
protected GUIContent m_ShowServerObjectsLabel;
protected GUIContent m_ShowClientLabel;
protected GUIContent m_ShowClientObjectsLabel;
protected GUIContent m_ShowMatchMakerLabel;
protected GUIContent m_ShowControlsLabel;
protected GUIContent m_ShowRuntimeGuiLabel;
protected GUIContent m_OffsetXLabel;
@ -32,7 +31,6 @@ public class NetworkManagerHUDEditor : Editor
bool m_ShowServerObjects;
bool m_ShowClient;
bool m_ShowClientObjects;
bool m_ShowMatchMaker;
bool m_ShowControls;
@ -71,7 +69,6 @@ void Init()
m_ShowServerObjectsLabel = new GUIContent("Server Objects", "Networked objects spawned by the server");
m_ShowClientLabel = new GUIContent("Client Info", "Details of internal client state");
m_ShowClientObjectsLabel = new GUIContent("Client Objects", "Networked objects created on the client");
m_ShowMatchMakerLabel = new GUIContent("MatchMaker Info", "Details about the matchmaker state");
m_ShowControlsLabel = new GUIContent("Runtime Controls", "Buttons for controlling network state at runtime");
m_ShowRuntimeGuiLabel = new GUIContent("Show Runtime GUI", "Show the default network control GUI when the game is running");
m_OffsetXLabel = new GUIContent("GUI Horizontal Offset", "Horizontal offset of runtime GUI");
@ -272,28 +269,6 @@ void ShowClientInfo()
EditorGUI.indentLevel -= 1;
}
void ShowMatchMakerInfo()
{
if (m_Manager == null || m_Manager.matchMaker == null)
{
return;
}
m_ShowMatchMaker = EditorGUILayout.Foldout(m_ShowMatchMaker, m_ShowMatchMakerLabel);
if (!m_ShowMatchMaker)
{
return;
}
EditorGUI.indentLevel += 1;
EditorGUILayout.BeginVertical();
EditorGUILayout.LabelField("Match Information", m_Manager.matchInfo == null ? "None" : m_Manager.matchInfo.ToString());
EditorGUILayout.EndVertical();
EditorGUI.indentLevel -= 1;
}
static UnityObject GetSceneObject(string sceneObjectName)
{
if (string.IsNullOrEmpty(sceneObjectName))
@ -333,7 +308,7 @@ void ShowControls()
}
EditorGUILayout.Separator();
if (!NetworkClient.active && !NetworkServer.active && m_Manager.matchMaker == null)
if (!NetworkClient.active && !NetworkServer.active)
{
EditorGUILayout.BeginHorizontal();
if (GUILayout.Toggle(false, "LAN Host", EditorStyles.miniButton))
@ -348,11 +323,6 @@ void ShowControls()
{
m_Manager.StartClient();
}
if (GUILayout.Toggle(false, "Start Matchmaker", EditorStyles.miniButton))
{
m_Manager.StartMatchMaker();
m_ShowMatchMaker = true;
}
EditorGUILayout.EndHorizontal();
}
@ -377,64 +347,6 @@ void ShowControls()
m_Manager.StopClient();
}
}
if (!NetworkServer.active && !NetworkClient.active)
{
EditorGUILayout.Separator();
if (m_Manager.matchMaker != null)
{
if (m_Manager.matchInfo == null)
{
if (m_Manager.matches == null)
{
EditorGUILayout.BeginHorizontal();
if (GUILayout.Toggle(false, "Create Internet Match", EditorStyles.miniButton))
{
m_Manager.matchMaker.CreateMatch(m_Manager.matchName, m_Manager.matchSize, true, "", "", "", 0, 0, m_Manager.OnMatchCreate);
}
if (GUILayout.Toggle(false, "Find Internet Match", EditorStyles.miniButton))
{
m_Manager.matchMaker.ListMatches(0, 20, "", false, 0, 0, m_Manager.OnMatchList);
}
if (GUILayout.Toggle(false, "Stop MatchMaker", EditorStyles.miniButton))
{
m_Manager.StopMatchMaker();
}
EditorGUILayout.EndHorizontal();
m_Manager.matchName = EditorGUILayout.TextField("Room Name:", m_Manager.matchName);
m_Manager.matchSize = (uint)EditorGUILayout.IntField("Room Size:", (int)m_Manager.matchSize);
EditorGUILayout.BeginHorizontal();
if (GUILayout.Toggle(false, "Use Local Relay", EditorStyles.miniButton))
{
m_Manager.SetMatchHost("localhost", 1337, false);
}
if (GUILayout.Toggle(false, "Use Internet Relay", EditorStyles.miniButton))
{
m_Manager.SetMatchHost("mm.unet.unity3d.com", 443, true);
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.Separator();
}
else
{
foreach (var match in m_Manager.matches)
{
if (GUI.Button(GetButtonRect(), "Join Match:" + match.name))
{
m_Manager.matchName = match.name;
m_Manager.matchSize = (uint)match.currentSize;
m_Manager.matchMaker.JoinMatch(match.networkId, "", "", "", 0, 0, m_Manager.OnMatchJoined);
}
}
if (GUI.Button(GetButtonRect(), "Stop MatchMaker"))
{
m_Manager.StopMatchMaker();
}
}
}
}
}
EditorGUILayout.Separator();
}
@ -463,7 +375,6 @@ public override void OnInspectorGUI()
ShowControls();
ShowServerInfo();
ShowClientInfo();
ShowMatchMakerInfo();
}
}
}

View File

@ -3,7 +3,6 @@
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using UnityEngine.Networking.Match;
using UnityEngine.Networking.NetworkSystem;
namespace UnityEngine.Networking
@ -123,12 +122,6 @@ public bool Configure(HostTopology topology)
return true;
}
public void Connect(MatchInfo matchInfo)
{
PrepareForConnect();
ConnectWithRelay(matchInfo);
}
static bool IsValidIpV6(string address)
{
// use C# built-in method
@ -293,31 +286,6 @@ internal void ContinueConnect()
m_Connection.Initialize(m_ServerIp, m_ClientId, m_ClientConnectionId, m_HostTopology);
}
void ConnectWithRelay(MatchInfo info)
{
m_AsyncConnect = ConnectState.Connecting;
Update();
byte error;
m_ClientConnectionId = NetworkTransport.ConnectToNetworkPeer(
m_ClientId,
info.address,
info.port,
0,
0,
info.networkId,
Utility.GetSourceID(),
info.nodeId,
out error);
m_Connection = (NetworkConnection)Activator.CreateInstance(m_NetworkConnectionClass);
m_Connection.SetHandlers(m_MessageHandlers);
m_Connection.Initialize(info.address, m_ClientId, m_ClientConnectionId, m_HostTopology);
if (error != 0) { Debug.LogError("ConnectToNetworkPeer Error: " + error); }
}
public virtual void Disconnect()
{
m_AsyncConnect = ConnectState.Disconnected;

View File

@ -3,7 +3,6 @@
using System.Collections.Generic;
using System.Net;
using System.Linq;
using UnityEngine.Networking.Match;
using UnityEngine.Networking.NetworkSystem;
using UnityEngine.Networking.Types;
using UnityEngine.SceneManagement;
@ -53,12 +52,6 @@ public class NetworkManager : MonoBehaviour
[SerializeField] bool m_AllowFragmentation;
#pragma warning restore 0169
// matchmaking configuration
[SerializeField] string m_MatchHost = "mm.unet.unity3d.com";
[SerializeField] int m_MatchPort = 443;
[SerializeField] public string matchName = "default";
[SerializeField] public uint matchSize = 4;
private EndPoint m_EndPoint;
bool m_ClientLoadedScene;
@ -94,8 +87,6 @@ public class NetworkManager : MonoBehaviour
public bool useWebSockets { get { return m_UseWebSockets; } set { m_UseWebSockets = value; } }
public string matchHost { get { return m_MatchHost; } set { m_MatchHost = value; } }
public int matchPort { get { return m_MatchPort; } set { m_MatchPort = value; } }
public bool clientLoadedScene { get { return m_ClientLoadedScene; } set { m_ClientLoadedScene = value; } }
// only really valid on the server
@ -122,10 +113,6 @@ public int numPlayers
static List<Transform> s_StartPositions = new List<Transform>();
static int s_StartPositionIndex;
// matchmaking runtime data
public MatchInfo matchInfo;
public NetworkMatch matchMaker;
public List<MatchInfoSnapshot> matches;
public static NetworkManager singleton;
static AsyncOperation s_LoadingSceneAsync;
@ -247,22 +234,12 @@ internal void RegisterServerMessages()
NetworkServer.RegisterHandler(MsgType.Error, OnServerErrorInternal);
}
public bool StartServer(ConnectionConfig config, int maxConnections)
{
return StartServer(null, config, maxConnections);
}
public bool StartServer()
{
return StartServer(null);
return StartServer(null, -1);
}
public bool StartServer(MatchInfo info)
{
return StartServer(info, null, -1);
}
bool StartServer(MatchInfo info, ConnectionConfig config, int maxConnections)
bool StartServer(ConnectionConfig config, int maxConnections)
{
InitializeSingleton();
@ -294,16 +271,6 @@ bool StartServer(MatchInfo info, ConnectionConfig config, int maxConnections)
NetworkServer.Configure(config, maxConnections);
}
if (info != null)
{
if (!NetworkServer.Listen(info, m_NetworkPort))
{
if (LogFilter.logError) { Debug.LogError("StartServer listen failed."); }
return false;
}
}
else
{
if (m_ServerBindToIP && !string.IsNullOrEmpty(m_ServerBindAddress))
{
if (!NetworkServer.Listen(m_ServerBindAddress, m_NetworkPort))
@ -320,7 +287,6 @@ bool StartServer(MatchInfo info, ConnectionConfig config, int maxConnections)
return false;
}
}
}
// this must be after Listen(), since that registers the default message handlers
RegisterServerMessages();
@ -391,11 +357,10 @@ public void UseExternalClient(NetworkClient externalClient)
s_Address = m_NetworkAddress;
}
public NetworkClient StartClient(MatchInfo info, ConnectionConfig config, int hostPort)
public NetworkClient StartClient(ConnectionConfig config, int hostPort)
{
InitializeSingleton();
matchInfo = info;
if (m_RunInBackground)
Application.runInBackground = true;
@ -432,12 +397,7 @@ public NetworkClient StartClient(MatchInfo info, ConnectionConfig config, int ho
}
RegisterClientMessages(client);
if (matchInfo != null)
{
if (LogFilter.logDebug) { Debug.Log("NetworkManager StartClient match: " + matchInfo); }
client.Connect(matchInfo);
}
else if (m_EndPoint != null)
if (m_EndPoint != null)
{
if (LogFilter.logDebug) { Debug.Log("NetworkManager StartClient using provided SecureTunnel"); }
client.Connect(m_EndPoint);
@ -459,19 +419,14 @@ public NetworkClient StartClient(MatchInfo info, ConnectionConfig config, int ho
return client;
}
public NetworkClient StartClient(MatchInfo matchInfo)
{
return StartClient(matchInfo, null);
}
public NetworkClient StartClient()
{
return StartClient(null, null);
return StartClient(null);
}
public NetworkClient StartClient(MatchInfo info, ConnectionConfig config)
public NetworkClient StartClient(ConnectionConfig config)
{
return StartClient(info, config, 0);
return StartClient(config, 0);
}
public virtual NetworkClient StartHost(ConnectionConfig config, int maxConnections)
@ -487,19 +442,6 @@ public virtual NetworkClient StartHost(ConnectionConfig config, int maxConnectio
return null;
}
public virtual NetworkClient StartHost(MatchInfo info)
{
OnStartHost();
matchInfo = info;
if (StartServer(info))
{
var client = ConnectLocalClient();
OnStartClient(client);
return client;
}
return null;
}
public virtual NetworkClient StartHost()
{
OnStartHost();
@ -539,7 +481,6 @@ public void StopServer()
if (LogFilter.logDebug) { Debug.Log("NetworkManager StopServer"); }
isNetworkActive = false;
NetworkServer.Shutdown();
StopMatchMaker();
if (!string.IsNullOrEmpty(m_OfflineScene))
{
ServerChangeScene(m_OfflineScene);
@ -560,7 +501,6 @@ public void StopClient()
client.Shutdown();
client = null;
}
StopMatchMaker();
ClientScene.DestroyAllClientObjects();
if (!string.IsNullOrEmpty(m_OfflineScene))
@ -839,12 +779,6 @@ internal void OnClientDisconnectInternal(NetworkMessage netMsg)
ClientChangeScene(m_OfflineScene, false);
}
// If we have a valid connection here drop the client in the matchmaker before shutting down below
if (matchMaker != null && matchInfo != null && matchInfo.networkId != NetworkID.Invalid && matchInfo.nodeId != NodeID.Invalid)
{
matchMaker.DropConnection(matchInfo.networkId, matchInfo.nodeId, matchInfo.domain, OnDropConnection);
}
OnClientDisconnect(netMsg.conn);
}
@ -1044,60 +978,6 @@ public virtual void OnClientSceneChanged(NetworkConnection conn)
}
}
// ----------------------------- Matchmaker --------------------------------
public void StartMatchMaker()
{
if (LogFilter.logDebug) { Debug.Log("NetworkManager StartMatchMaker"); }
SetMatchHost(m_MatchHost, m_MatchPort, m_MatchPort == 443);
}
public void StopMatchMaker()
{
// If we have a valid connection here drop the client in the matchmaker before shutting down below
if (matchMaker != null && matchInfo != null && matchInfo.networkId != NetworkID.Invalid && matchInfo.nodeId != NodeID.Invalid)
{
matchMaker.DropConnection(matchInfo.networkId, matchInfo.nodeId, matchInfo.domain, OnDropConnection);
}
if (matchMaker != null)
{
Destroy(matchMaker);
matchMaker = null;
}
matchInfo = null;
matches = null;
}
public void SetMatchHost(string newHost, int port, bool https)
{
if (matchMaker == null)
{
matchMaker = gameObject.AddComponent<NetworkMatch>();
}
if (newHost == "127.0.0.1")
{
newHost = "localhost";
}
string prefix = https ? "https://" : "http://";
if (newHost.StartsWith("http://"))
{
newHost = newHost.Replace("http://", "");
}
if (newHost.StartsWith("https://"))
{
newHost = newHost.Replace("https://", "");
}
m_MatchHost = newHost;
m_MatchPort = port;
string fullURI = prefix + m_MatchHost + ":" + m_MatchPort;
if (LogFilter.logDebug) { Debug.Log("SetMatchHost:" + fullURI); }
matchMaker.baseUri = new Uri(fullURI);
}
//------------------------------ Start & Stop callbacks -----------------------------------
// Since there are multiple versions of StartServer, StartClient and StartHost, to reliably customize
@ -1127,46 +1007,6 @@ public virtual void OnStopClient()
public virtual void OnStopHost()
{
}
//------------------------------ Matchmaker callbacks -----------------------------------
public virtual void OnMatchCreate(bool success, string extendedInfo, MatchInfo matchInfo)
{
if (LogFilter.logDebug) { Debug.LogFormat("NetworkManager OnMatchCreate Success:{0}, ExtendedInfo:{1}, matchInfo:{2}", success, extendedInfo, matchInfo); }
if (success)
StartHost(matchInfo);
}
public virtual void OnMatchList(bool success, string extendedInfo, List<MatchInfoSnapshot> matchList)
{
if (LogFilter.logDebug) { Debug.LogFormat("NetworkManager OnMatchList Success:{0}, ExtendedInfo:{1}, matchList.Count:{2}", success, extendedInfo, matchList.Count); }
matches = matchList;
}
public virtual void OnMatchJoined(bool success, string extendedInfo, MatchInfo matchInfo)
{
if (LogFilter.logDebug) { Debug.LogFormat("NetworkManager OnMatchJoined Success:{0}, ExtendedInfo:{1}, matchInfo:{2}", success, extendedInfo, matchInfo); }
if (success)
StartClient(matchInfo);
}
public virtual void OnDestroyMatch(bool success, string extendedInfo)
{
if (LogFilter.logDebug) { Debug.LogFormat("NetworkManager OnDestroyMatch Success:{0}, ExtendedInfo:{1}", success, extendedInfo); }
}
public virtual void OnDropConnection(bool success, string extendedInfo)
{
if (LogFilter.logDebug) { Debug.LogFormat("NetworkManager OnDropConnection Success:{0}, ExtendedInfo:{1}", success, extendedInfo); }
}
public virtual void OnSetMatchAttributes(bool success, string extendedInfo)
{
if (LogFilter.logDebug) { Debug.LogFormat("NetworkManager OnSetMatchAttributes Success:{0}, ExtendedInfo:{1}", success, extendedInfo); }
}
}
}
#endif //ENABLE_UNET

View File

@ -15,9 +15,6 @@ public class NetworkManagerHUD : MonoBehaviour
[SerializeField] public int offsetX;
[SerializeField] public int offsetY;
// Runtime variable
bool m_ShowServer;
void Awake()
{
manager = GetComponent<NetworkManager>();
@ -28,7 +25,7 @@ void Update()
if (!showGUI)
return;
if (!manager.IsClientConnected() && !NetworkServer.active && manager.matchMaker == null)
if (!manager.IsClientConnected() && !NetworkServer.active)
{
if (Application.platform != RuntimePlatform.WebGLPlayer)
{
@ -77,7 +74,7 @@ void OnGUI()
bool noConnection = (manager.client == null || manager.client.connection == null ||
manager.client.connection.connectionId == -1);
if (!manager.IsClientConnected() && !NetworkServer.active && manager.matchMaker == null)
if (!manager.IsClientConnected() && !NetworkServer.active)
{
if (noConnection)
{
@ -166,108 +163,6 @@ void OnGUI()
}
ypos += spacing;
}
if (!NetworkServer.active && !manager.IsClientConnected() && noConnection)
{
ypos += 10;
if (Application.platform == RuntimePlatform.WebGLPlayer)
{
GUI.Box(new Rect(xpos - 5, ypos, 220, 25), "(WebGL cannot use Match Maker)");
return;
}
if (manager.matchMaker == null)
{
if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Enable Match Maker (M)"))
{
manager.StartMatchMaker();
}
ypos += spacing;
}
else
{
if (manager.matchInfo == null)
{
if (manager.matches == null)
{
if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Create Internet Match"))
{
manager.matchMaker.CreateMatch(manager.matchName, manager.matchSize, true, "", "", "", 0, 0, manager.OnMatchCreate);
}
ypos += spacing;
GUI.Label(new Rect(xpos, ypos, 100, 20), "Room Name:");
manager.matchName = GUI.TextField(new Rect(xpos + 100, ypos, 100, 20), manager.matchName);
ypos += spacing;
ypos += 10;
if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Find Internet Match"))
{
manager.matchMaker.ListMatches(0, 20, "", false, 0, 0, manager.OnMatchList);
}
ypos += spacing;
}
else
{
for (int i = 0; i < manager.matches.Count; i++)
{
var match = manager.matches[i];
if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Join Match:" + match.name))
{
manager.matchName = match.name;
manager.matchMaker.JoinMatch(match.networkId, "", "", "", 0, 0, manager.OnMatchJoined);
}
ypos += spacing;
}
if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Back to Match Menu"))
{
manager.matches = null;
}
ypos += spacing;
}
}
if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Change MM server"))
{
m_ShowServer = !m_ShowServer;
}
if (m_ShowServer)
{
ypos += spacing;
if (GUI.Button(new Rect(xpos, ypos, 100, 20), "Local"))
{
manager.SetMatchHost("localhost", 1337, false);
m_ShowServer = false;
}
ypos += spacing;
if (GUI.Button(new Rect(xpos, ypos, 100, 20), "Internet"))
{
manager.SetMatchHost("mm.unet.unity3d.com", 443, true);
m_ShowServer = false;
}
ypos += spacing;
if (GUI.Button(new Rect(xpos, ypos, 100, 20), "Staging"))
{
manager.SetMatchHost("staging-mm.unet.unity3d.com", 443, true);
m_ShowServer = false;
}
}
ypos += spacing;
GUI.Label(new Rect(xpos, ypos, 300, 20), "MM Uri: " + manager.matchMaker.baseUri);
ypos += spacing;
if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Disable Match Maker"))
{
manager.StopMatchMaker();
}
ypos += spacing;
}
}
}
}
}

View File

@ -2,7 +2,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.Networking.Match;
using UnityEngine.Networking.NetworkSystem;
using UnityEngine.Networking.Types;
@ -125,15 +124,6 @@ public static void Initialize()
if (LogFilter.logDebug) { Debug.Log("NetworkServer initialize."); }
}
static public bool Listen(MatchInfo matchInfo, int listenPort)
{
if (!matchInfo.usingRelay)
return InternalListen(null, listenPort);
InternalListenRelay(matchInfo.address, matchInfo.port, matchInfo.networkId, Utility.GetSourceID(), matchInfo.nodeId);
return true;
}
static internal void RegisterMessageHandlers()
{
s_MessageHandlers.RegisterHandlerSafe(MsgType.Ready, OnClientReadyMessage);