Merge pull request #223 from misternebula/quantum-unet-refactor

Quantumunet refactor
This commit is contained in:
Mister_Nebula 2020-12-07 21:21:39 +00:00 committed by GitHub
commit 6cd94c66fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
60 changed files with 1344 additions and 3487 deletions

View File

@ -3,7 +3,7 @@ using OWML.ModHelper.Events;
using QSB.EventsCore;
using QSB.Player;
using QSB.Utility;
using QuantumUNET;
using QuantumUNET.Components;
using System.Linq;
using UnityEngine;

View File

@ -2,6 +2,7 @@
using QSB.EventsCore;
using QSB.Utility;
using QuantumUNET;
using QuantumUNET.Messages;
using System;
using System.Linq;
using UnityEngine.Networking;

View File

@ -1,4 +1,5 @@
using QuantumUNET;
using QuantumUNET.Messages;
namespace QSB.Messaging
{

View File

@ -1,7 +1,5 @@
using QSB.EventsCore;
using QSB.Utility;
using QSB.WorldSync;
using QSB.WorldSync.Events;
namespace QSB.OrbSync.Events
{

View File

@ -1,9 +1,5 @@
using QSB.Messaging;
using QuantumUNET;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace QSB.OrbSync.Events
{

View File

@ -4,6 +4,7 @@ using QSB.Utility;
using QSB.WorldSync;
using QSB.WorldSync.Events;
using QuantumUNET;
using QuantumUNET.Components;
using System.Linq;
namespace QSB.OrbSync.Events

View File

@ -1,4 +1,5 @@
using QuantumUNET;
using QuantumUNET.Components;
namespace QSB.Player
{

View File

@ -2,7 +2,7 @@
using QSB.Player.Events;
using QSB.TransformSync;
using QSB.Utility;
using QuantumUNET;
using QuantumUNET.Components;
using System.Collections.Generic;
using System.Linq;

View File

@ -9,7 +9,7 @@ using QSB.Patches;
using QSB.SectorSync;
using QSB.TimeSync;
using QSB.Utility;
using QuantumUNET;
using QuantumUNET.Components;
using UnityEngine;
using UnityEngine.Networking;

View File

@ -15,6 +15,7 @@ using QSB.TransformSync;
using QSB.Utility;
using QSB.WorldSync;
using QuantumUNET;
using QuantumUNET.Components;
using System;
using System.Linq;
using UnityEngine;

View File

@ -1,6 +1,7 @@
using UnityEngine;
using QuantumUNET.Messages;
using UnityEngine;
namespace QuantumUNET
namespace QuantumUNET.Components
{
public class QSBNetworkAnimator : QSBNetworkBehaviour
{

View File

@ -1,11 +1,12 @@
using OWML.Logging;
using QuantumUNET.Messages;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using UnityEngine;
using UnityEngine.Networking;
namespace QuantumUNET
namespace QuantumUNET.Components
{
public sealed class QSBNetworkIdentity : MonoBehaviour
{

View File

@ -0,0 +1,109 @@
using UnityEngine;
namespace QuantumUNET.Components
{
public class QSBNetworkManagerHUD : MonoBehaviour
{
private void Awake()
{
manager = GetComponent<QSBNetworkManagerUNET>();
}
private void OnGUI()
{
if (showGUI)
{
var num = 10 + offsetX;
var num2 = 40 + offsetY;
var flag = manager.client == null || manager.client.connection == null || manager.client.connection.connectionId == -1;
if (!manager.IsClientConnected() && !QSBNetworkServer.active)
{
if (flag)
{
if (Application.platform != RuntimePlatform.WebGLPlayer)
{
if (GUI.Button(new Rect(num, num2, 200f, 20f), "Host"))
{
manager.StartHost();
}
num2 += 24;
}
if (GUI.Button(new Rect(num, num2, 105f, 20f), "Connect"))
{
manager.StartClient();
}
manager.networkAddress = GUI.TextField(new Rect(num + 100, num2, 95f, 20f), manager.networkAddress);
num2 += 24;
}
else
{
GUI.Label(new Rect(num, num2, 200f, 20f), string.Concat(new object[]
{
"Connecting to ",
manager.networkAddress,
":",
manager.networkPort,
".."
}));
num2 += 24;
if (GUI.Button(new Rect(num, num2, 200f, 20f), "Cancel Connection Attempt"))
{
manager.StopClient();
}
}
}
else
{
if (QSBNetworkServer.active)
{
var text = $"Hosting on port {manager.networkPort}";
if (manager.useWebSockets)
{
text += " (using WebSockets)";
}
GUI.Label(new Rect(num, num2, 300f, 20f), text);
num2 += 24;
}
if (manager.IsClientConnected())
{
GUI.Label(new Rect(num, num2, 300f, 20f), $"Connected to {manager.networkAddress}, port {manager.networkPort}");
num2 += 24;
}
}
if (manager.IsClientConnected() && !QSBClientScene.ready)
{
if (GUI.Button(new Rect(num, num2, 200f, 20f), "Client Ready"))
{
QSBClientScene.Ready(manager.client.connection);
if (QSBClientScene.localPlayers.Count == 0)
{
QSBClientScene.AddPlayer(0);
}
}
num2 += 24;
}
if (QSBNetworkServer.active || manager.IsClientConnected())
{
if (GUI.Button(new Rect(num, num2, 200f, 20f), "Stop"))
{
manager.StopHost();
}
num2 += 24;
}
}
}
public QSBNetworkManagerUNET manager;
[SerializeField]
public bool showGUI = true;
[SerializeField]
public int offsetX;
[SerializeField]
public int offsetY;
private bool m_ShowServer;
}
}

View File

@ -0,0 +1,961 @@
using OWML.Logging;
using QuantumUNET.Messages;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
namespace QuantumUNET.Components
{
public class QSBNetworkManagerUNET : MonoBehaviour
{
public static QSBNetworkManagerUNET singleton;
public static string networkSceneName = "";
public int networkPort { get; set; } = 7777;
public int simulatedLatency { get; set; } = 1;
public bool serverBindToIP { get; set; }
public bool dontDestroyOnLoad { get; set; } = true;
public bool runInBackground { get; set; } = true;
public bool scriptCRCCheck { get; set; } = true;
public bool autoCreatePlayer { get; set; } = true;
public bool isNetworkActive;
public bool useWebSockets { get; set; }
public bool useSimulator { get; set; }
public bool clientLoadedScene { get; set; }
public string serverBindAddress { get; set; } = "";
public string networkAddress { get; set; } = "localhost";
public string offlineScene { get; set; } = "";
public string onlineScene { get; set; } = "";
public float packetLossPercentage { get; set; }
public float maxDelay { get; set; } = 0.01f;
public GameObject playerPrefab { get; set; }
public PlayerSpawnMethod playerSpawnMethod { get; set; }
public List<GameObject> spawnPrefabs { get; } = new List<GameObject>();
public QSBNetworkClient client;
public int maxConnections { get; set; } = 4;
public List<QosType> channels { get; } = new List<QosType>();
private ConnectionConfig m_ConnectionConfig;
private GlobalConfig m_GlobalConfig;
private int m_MaxBufferedPackets = 16;
private bool m_AllowFragmentation = true;
private static List<Transform> s_StartPositions = new List<Transform>();
private static int s_StartPositionIndex;
private static QSBAddPlayerMessage s_AddPlayerMessage = new QSBAddPlayerMessage();
private static QSBRemovePlayerMessage s_RemovePlayerMessage = new QSBRemovePlayerMessage();
private static QSBErrorMessage s_ErrorMessage = new QSBErrorMessage();
private static AsyncOperation s_LoadingSceneAsync;
private static QSBNetworkConnection s_ClientReadyConnection;
private static string s_Address;
public List<Transform> startPositions
{
get
{
return s_StartPositions;
}
}
public bool customConfig { get; set; }
public ConnectionConfig connectionConfig
{
get
{
if (m_ConnectionConfig == null)
{
m_ConnectionConfig = new ConnectionConfig();
}
return m_ConnectionConfig;
}
}
public GlobalConfig globalConfig
{
get
{
if (m_GlobalConfig == null)
{
m_GlobalConfig = new GlobalConfig();
}
return m_GlobalConfig;
}
}
public int numPlayers
{
get
{
var num = 0;
for (var i = 0; i < QSBNetworkServer.connections.Count; i++)
{
var networkConnection = QSBNetworkServer.connections[i];
if (networkConnection != null)
{
for (var j = 0; j < networkConnection.PlayerControllers.Count; j++)
{
if (networkConnection.PlayerControllers[j].IsValid)
{
num++;
}
}
}
}
return num;
}
}
private void Awake()
{
InitializeSingleton();
}
private void InitializeSingleton()
{
if (!(singleton != null) || !(singleton == this))
{
if (dontDestroyOnLoad)
{
if (singleton != null)
{
Debug.Log("Multiple NetworkManagers detected in the scene. Only one NetworkManager can exist at a time. The duplicate NetworkManager will not be used.");
Destroy(base.gameObject);
return;
}
Debug.Log("NetworkManager created singleton (DontDestroyOnLoad)");
singleton = this;
if (Application.isPlaying)
{
DontDestroyOnLoad(base.gameObject);
}
}
else
{
Debug.Log("NetworkManager created singleton (ForScene)");
singleton = this;
}
if (networkAddress != "")
{
s_Address = networkAddress;
}
else if (s_Address != "")
{
networkAddress = s_Address;
}
}
}
internal void RegisterServerMessages()
{
QSBNetworkServer.RegisterHandler(32, new QSBNetworkMessageDelegate(OnServerConnectInternal));
QSBNetworkServer.RegisterHandler(33, new QSBNetworkMessageDelegate(OnServerDisconnectInternal));
QSBNetworkServer.RegisterHandler(35, new QSBNetworkMessageDelegate(OnServerReadyMessageInternal));
QSBNetworkServer.RegisterHandler(37, new QSBNetworkMessageDelegate(OnServerAddPlayerMessageInternal));
QSBNetworkServer.RegisterHandler(38, new QSBNetworkMessageDelegate(OnServerRemovePlayerMessageInternal));
QSBNetworkServer.RegisterHandler(34, new QSBNetworkMessageDelegate(OnServerErrorInternal));
}
public bool StartServer()
{
return StartServer(null, -1);
}
private bool StartServer(ConnectionConfig config, int maxConnections)
{
InitializeSingleton();
OnStartServer();
if (runInBackground)
{
Application.runInBackground = true;
}
QSBNetworkCRC.scriptCRCCheck = scriptCRCCheck;
QSBNetworkServer.useWebSockets = useWebSockets;
if (m_GlobalConfig != null)
{
NetworkTransport.Init(m_GlobalConfig);
}
if (customConfig && m_ConnectionConfig != null && config == null)
{
m_ConnectionConfig.Channels.Clear();
for (var i = 0; i < channels.Count; i++)
{
m_ConnectionConfig.AddChannel(channels[i]);
}
QSBNetworkServer.Configure(m_ConnectionConfig, this.maxConnections);
}
if (config != null)
{
QSBNetworkServer.Configure(config, maxConnections);
}
if (serverBindToIP && !string.IsNullOrEmpty(serverBindAddress))
{
if (!QSBNetworkServer.Listen(serverBindAddress, networkPort))
{
if (LogFilter.logError)
{
Debug.LogError("StartServer listen on " + serverBindAddress + " failed.");
}
return false;
}
}
else if (!QSBNetworkServer.Listen(networkPort))
{
if (LogFilter.logError)
{
Debug.LogError("StartServer listen failed.");
}
return false;
}
RegisterServerMessages();
if (LogFilter.logDebug)
{
Debug.Log("NetworkManager StartServer port:" + networkPort);
}
isNetworkActive = true;
var name = SceneManager.GetSceneAt(0).name;
if (!string.IsNullOrEmpty(onlineScene) && onlineScene != name && onlineScene != offlineScene)
{
ServerChangeScene(onlineScene);
}
else
{
QSBNetworkServer.SpawnObjects();
}
return true;
}
internal void RegisterClientMessages(QSBNetworkClient client)
{
client.RegisterHandler(32, new QSBNetworkMessageDelegate(OnClientConnectInternal));
client.RegisterHandler(33, new QSBNetworkMessageDelegate(OnClientDisconnectInternal));
client.RegisterHandler(36, new QSBNetworkMessageDelegate(OnClientNotReadyMessageInternal));
client.RegisterHandler(34, new QSBNetworkMessageDelegate(OnClientErrorInternal));
client.RegisterHandler(39, new QSBNetworkMessageDelegate(OnClientSceneInternal));
if (playerPrefab != null)
{
QSBClientScene.RegisterPrefab(playerPrefab);
}
for (var i = 0; i < spawnPrefabs.Count; i++)
{
var gameObject = spawnPrefabs[i];
if (gameObject != null)
{
QSBClientScene.RegisterPrefab(gameObject);
}
}
}
public void UseExternalClient(QSBNetworkClient externalClient)
{
if (runInBackground)
{
Application.runInBackground = true;
}
if (externalClient != null)
{
client = externalClient;
isNetworkActive = true;
RegisterClientMessages(client);
OnStartClient(client);
}
else
{
OnStopClient();
QSBClientScene.DestroyAllClientObjects();
QSBClientScene.HandleClientDisconnect(client.connection);
client = null;
if (!string.IsNullOrEmpty(offlineScene))
{
ClientChangeScene(offlineScene, false);
}
}
s_Address = networkAddress;
}
public QSBNetworkClient StartClient(ConnectionConfig config, int hostPort)
{
InitializeSingleton();
if (runInBackground)
{
Application.runInBackground = true;
}
isNetworkActive = true;
if (m_GlobalConfig != null)
{
NetworkTransport.Init(m_GlobalConfig);
}
client = new QSBNetworkClient
{
hostPort = hostPort
};
if (config != null)
{
if (config.UsePlatformSpecificProtocols && Application.platform != RuntimePlatform.PS4 && Application.platform != RuntimePlatform.PSP2)
{
throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
}
client.Configure(config, 1);
}
else if (customConfig && m_ConnectionConfig != null)
{
m_ConnectionConfig.Channels.Clear();
for (var i = 0; i < channels.Count; i++)
{
m_ConnectionConfig.AddChannel(channels[i]);
}
if (m_ConnectionConfig.UsePlatformSpecificProtocols && Application.platform != RuntimePlatform.PS4 && Application.platform != RuntimePlatform.PSP2)
{
throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
}
client.Configure(m_ConnectionConfig, maxConnections);
}
RegisterClientMessages(client);
if (string.IsNullOrEmpty(networkAddress))
{
ModConsole.OwmlConsole.WriteLine("Must set the Network Address field in the manager");
return null;
}
ModConsole.OwmlConsole.WriteLine(string.Concat(new object[]
{
"NetworkManager StartClient address:",
networkAddress,
" port:",
networkPort
}));
if (useSimulator)
{
ModConsole.OwmlConsole.WriteLine("connecting with simulator");
client.ConnectWithSimulator(networkAddress, networkPort, simulatedLatency, packetLossPercentage);
}
else
{
ModConsole.OwmlConsole.WriteLine("connecting");
client.Connect(networkAddress, networkPort);
}
OnStartClient(client);
s_Address = networkAddress;
return client;
}
public QSBNetworkClient StartClient()
{
return StartClient(null);
}
public QSBNetworkClient StartClient(ConnectionConfig config)
{
return StartClient(config, 0);
}
public virtual QSBNetworkClient StartHost(ConnectionConfig config, int maxConnections)
{
OnStartHost();
QSBNetworkClient result;
if (StartServer(config, maxConnections))
{
var networkClient = ConnectLocalClient();
OnServerConnect(networkClient.connection);
OnStartClient(networkClient);
result = networkClient;
}
else
{
result = null;
}
return result;
}
public virtual QSBNetworkClient StartHost()
{
OnStartHost();
QSBNetworkClient result;
if (StartServer())
{
var networkClient = ConnectLocalClient();
OnStartClient(networkClient);
result = networkClient;
}
else
{
result = null;
}
return result;
}
private QSBNetworkClient ConnectLocalClient()
{
if (LogFilter.logDebug)
{
Debug.Log("NetworkManager StartHost port:" + networkPort);
}
networkAddress = "localhost";
client = QSBClientScene.ConnectLocalServer();
RegisterClientMessages(client);
return client;
}
public void StopHost()
{
OnStopHost();
StopServer();
StopClient();
}
public void StopServer()
{
if (QSBNetworkServer.active)
{
OnStopServer();
if (LogFilter.logDebug)
{
Debug.Log("NetworkManager StopServer");
}
isNetworkActive = false;
QSBNetworkServer.Shutdown();
if (!string.IsNullOrEmpty(offlineScene))
{
ServerChangeScene(offlineScene);
}
CleanupNetworkIdentities();
}
}
public void StopClient()
{
OnStopClient();
if (LogFilter.logDebug)
{
Debug.Log("NetworkManager StopClient");
}
isNetworkActive = false;
if (client != null)
{
client.Disconnect();
client.Shutdown();
client = null;
}
QSBClientScene.DestroyAllClientObjects();
if (!string.IsNullOrEmpty(offlineScene))
{
ClientChangeScene(offlineScene, false);
}
CleanupNetworkIdentities();
}
public virtual void ServerChangeScene(string newSceneName)
{
if (string.IsNullOrEmpty(newSceneName))
{
if (LogFilter.logError)
{
Debug.LogError("ServerChangeScene empty scene name");
}
}
else
{
if (LogFilter.logDebug)
{
Debug.Log("ServerChangeScene " + newSceneName);
}
QSBNetworkServer.SetAllClientsNotReady();
networkSceneName = newSceneName;
s_LoadingSceneAsync = SceneManager.LoadSceneAsync(newSceneName);
var msg = new QSBStringMessage(networkSceneName);
QSBNetworkServer.SendToAll(39, msg);
s_StartPositionIndex = 0;
s_StartPositions.Clear();
}
}
private void CleanupNetworkIdentities()
{
foreach (var networkIdentity in Resources.FindObjectsOfTypeAll<QSBNetworkIdentity>())
{
networkIdentity.MarkForReset();
}
}
internal void ClientChangeScene(string newSceneName, bool forceReload)
{
if (string.IsNullOrEmpty(newSceneName))
{
if (LogFilter.logError)
{
Debug.LogError("ClientChangeScene empty scene name");
}
}
else
{
if (LogFilter.logDebug)
{
Debug.Log("ClientChangeScene newSceneName:" + newSceneName + " networkSceneName:" + networkSceneName);
}
if (newSceneName == networkSceneName)
{
if (!forceReload)
{
FinishLoadScene();
return;
}
}
s_LoadingSceneAsync = SceneManager.LoadSceneAsync(newSceneName);
networkSceneName = newSceneName;
}
}
private void FinishLoadScene()
{
if (client != null)
{
if (s_ClientReadyConnection != null)
{
clientLoadedScene = true;
OnClientConnect(s_ClientReadyConnection);
s_ClientReadyConnection = null;
}
}
else
{
Debug.Log("FinishLoadScene client is null");
}
if (QSBNetworkServer.active)
{
QSBNetworkServer.SpawnObjects();
OnServerSceneChanged(networkSceneName);
}
if (IsClientConnected() && client != null)
{
RegisterClientMessages(client);
OnClientSceneChanged(client.connection);
}
}
internal static void UpdateScene()
{
if (!(singleton == null))
{
if (s_LoadingSceneAsync != null)
{
if (s_LoadingSceneAsync.isDone)
{
ModConsole.OwmlConsole.WriteLine("ClientChangeScene done readyCon:" + s_ClientReadyConnection);
singleton.FinishLoadScene();
s_LoadingSceneAsync.allowSceneActivation = true;
s_LoadingSceneAsync = null;
}
}
}
}
public static void RegisterStartPosition(Transform start)
{
if (LogFilter.logDebug)
{
Debug.Log(string.Concat(new object[]
{
"RegisterStartPosition: (",
start.gameObject.name,
") ",
start.position
}));
}
s_StartPositions.Add(start);
}
public static void UnRegisterStartPosition(Transform start)
{
if (LogFilter.logDebug)
{
Debug.Log(string.Concat(new object[]
{
"UnRegisterStartPosition: (",
start.gameObject.name,
") ",
start.position
}));
}
s_StartPositions.Remove(start);
}
public bool IsClientConnected()
{
return client != null && client.isConnected;
}
public static void Shutdown()
{
if (!(singleton == null))
{
s_StartPositions.Clear();
s_StartPositionIndex = 0;
s_ClientReadyConnection = null;
singleton.StopHost();
singleton = null;
}
}
internal void OnServerConnectInternal(QSBNetworkMessage netMsg)
{
if (LogFilter.logDebug)
{
Debug.Log("NetworkManager:OnServerConnectInternal");
}
netMsg.Connection.SetMaxDelay(maxDelay);
if (m_MaxBufferedPackets != 512)
{
for (var i = 0; i < QSBNetworkServer.numChannels; i++)
{
netMsg.Connection.SetChannelOption(i, ChannelOption.MaxPendingBuffers, m_MaxBufferedPackets);
}
}
if (!m_AllowFragmentation)
{
for (var j = 0; j < QSBNetworkServer.numChannels; j++)
{
netMsg.Connection.SetChannelOption(j, ChannelOption.AllowFragmentation, 0);
}
}
if (networkSceneName != "" && networkSceneName != offlineScene)
{
var msg = new QSBStringMessage(networkSceneName);
netMsg.Connection.Send(39, msg);
}
OnServerConnect(netMsg.Connection);
}
internal void OnServerDisconnectInternal(QSBNetworkMessage netMsg)
{
if (LogFilter.logDebug)
{
Debug.Log("NetworkManager:OnServerDisconnectInternal");
}
OnServerDisconnect(netMsg.Connection);
}
internal void OnServerReadyMessageInternal(QSBNetworkMessage netMsg)
{
if (LogFilter.logDebug)
{
Debug.Log("NetworkManager:OnServerReadyMessageInternal");
}
OnServerReady(netMsg.Connection);
}
internal void OnServerAddPlayerMessageInternal(QSBNetworkMessage netMsg)
{
if (LogFilter.logDebug)
{
Debug.Log("NetworkManager:OnServerAddPlayerMessageInternal");
}
netMsg.ReadMessage<QSBAddPlayerMessage>(s_AddPlayerMessage);
if (s_AddPlayerMessage.msgSize != 0)
{
var extraMessageReader = new NetworkReader(s_AddPlayerMessage.msgData);
OnServerAddPlayer(netMsg.Connection, s_AddPlayerMessage.playerControllerId, extraMessageReader);
}
else
{
OnServerAddPlayer(netMsg.Connection, s_AddPlayerMessage.playerControllerId);
}
}
internal void OnServerRemovePlayerMessageInternal(QSBNetworkMessage netMsg)
{
if (LogFilter.logDebug)
{
Debug.Log("NetworkManager:OnServerRemovePlayerMessageInternal");
}
netMsg.ReadMessage<QSBRemovePlayerMessage>(s_RemovePlayerMessage);
netMsg.Connection.GetPlayerController(s_RemovePlayerMessage.PlayerControllerId, out var player);
OnServerRemovePlayer(netMsg.Connection, player);
netMsg.Connection.RemovePlayerController(s_RemovePlayerMessage.PlayerControllerId);
}
internal void OnServerErrorInternal(QSBNetworkMessage netMsg)
{
if (LogFilter.logDebug)
{
Debug.Log("NetworkManager:OnServerErrorInternal");
}
netMsg.ReadMessage<QSBErrorMessage>(s_ErrorMessage);
OnServerError(netMsg.Connection, s_ErrorMessage.errorCode);
}
internal void OnClientConnectInternal(QSBNetworkMessage netMsg)
{
if (LogFilter.logDebug)
{
Debug.Log("NetworkManager:OnClientConnectInternal");
}
netMsg.Connection.SetMaxDelay(maxDelay);
var name = SceneManager.GetSceneAt(0).name;
if (string.IsNullOrEmpty(onlineScene) || onlineScene == offlineScene || name == onlineScene)
{
clientLoadedScene = false;
OnClientConnect(netMsg.Connection);
}
else
{
s_ClientReadyConnection = netMsg.Connection;
}
}
internal void OnClientDisconnectInternal(QSBNetworkMessage netMsg)
{
if (LogFilter.logDebug)
{
Debug.Log("NetworkManager:OnClientDisconnectInternal");
}
if (!string.IsNullOrEmpty(offlineScene))
{
ClientChangeScene(offlineScene, false);
}
OnClientDisconnect(netMsg.Connection);
}
internal void OnClientNotReadyMessageInternal(QSBNetworkMessage netMsg)
{
if (LogFilter.logDebug)
{
Debug.Log("NetworkManager:OnClientNotReadyMessageInternal");
}
QSBClientScene.SetNotReady();
OnClientNotReady(netMsg.Connection);
}
internal void OnClientErrorInternal(QSBNetworkMessage netMsg)
{
if (LogFilter.logDebug)
{
Debug.Log("NetworkManager:OnClientErrorInternal");
}
netMsg.ReadMessage<QSBErrorMessage>(s_ErrorMessage);
OnClientError(netMsg.Connection, s_ErrorMessage.errorCode);
}
internal void OnClientSceneInternal(QSBNetworkMessage netMsg)
{
if (LogFilter.logDebug)
{
Debug.Log("NetworkManager:OnClientSceneInternal");
}
var newSceneName = netMsg.Reader.ReadString();
if (IsClientConnected() && !QSBNetworkServer.active)
{
ClientChangeScene(newSceneName, true);
}
}
public virtual void OnServerConnect(QSBNetworkConnection conn)
{
}
public virtual void OnServerDisconnect(QSBNetworkConnection conn)
{
QSBNetworkServer.DestroyPlayersForConnection(conn);
if (conn.LastError != NetworkError.Ok)
{
if (LogFilter.logError)
{
Debug.LogError("ServerDisconnected due to error: " + conn.LastError);
}
}
}
public virtual void OnServerReady(QSBNetworkConnection conn)
{
if (conn.PlayerControllers.Count == 0)
{
if (LogFilter.logDebug)
{
Debug.Log("Ready with no player object");
}
}
QSBNetworkServer.SetClientReady(conn);
}
public virtual void OnServerAddPlayer(QSBNetworkConnection conn, short playerControllerId, NetworkReader extraMessageReader)
{
OnServerAddPlayerInternal(conn, playerControllerId);
}
public virtual void OnServerAddPlayer(QSBNetworkConnection conn, short playerControllerId)
{
OnServerAddPlayerInternal(conn, playerControllerId);
}
private void OnServerAddPlayerInternal(QSBNetworkConnection conn, short playerControllerId)
{
if (playerPrefab == null)
{
if (LogFilter.logError)
{
ModConsole.OwmlConsole.WriteLine("Error - The PlayerPrefab is empty on the QSBNetworkManager. Please setup a PlayerPrefab object.");
}
}
else if (playerPrefab.GetComponent<QSBNetworkIdentity>() == null)
{
if (LogFilter.logError)
{
ModConsole.OwmlConsole.WriteLine("Error - The PlayerPrefab does not have a QSBNetworkIdentity. Please add a QSBNetworkIdentity to the player prefab.");
}
}
else if (playerControllerId < conn.PlayerControllers.Count && conn.PlayerControllers[playerControllerId].IsValid && conn.PlayerControllers[playerControllerId].Gameobject != null)
{
if (LogFilter.logError)
{
ModConsole.OwmlConsole.WriteLine("Warning - There is already a player at that playerControllerId for this connections.");
}
}
else
{
var startPosition = GetStartPosition();
GameObject player;
if (startPosition != null)
{
player = Instantiate<GameObject>(playerPrefab, startPosition.position, startPosition.rotation);
}
else
{
player = Instantiate<GameObject>(playerPrefab, Vector3.zero, Quaternion.identity);
}
QSBNetworkServer.AddPlayerForConnection(conn, player, playerControllerId);
}
}
public Transform GetStartPosition()
{
if (s_StartPositions.Count > 0)
{
for (var i = s_StartPositions.Count - 1; i >= 0; i--)
{
if (s_StartPositions[i] == null)
{
s_StartPositions.RemoveAt(i);
}
}
}
Transform result;
if (playerSpawnMethod == PlayerSpawnMethod.Random && s_StartPositions.Count > 0)
{
var index = UnityEngine.Random.Range(0, s_StartPositions.Count);
result = s_StartPositions[index];
}
else if (playerSpawnMethod == PlayerSpawnMethod.RoundRobin && s_StartPositions.Count > 0)
{
if (s_StartPositionIndex >= s_StartPositions.Count)
{
s_StartPositionIndex = 0;
}
var transform = s_StartPositions[s_StartPositionIndex];
s_StartPositionIndex++;
result = transform;
}
else
{
result = null;
}
return result;
}
public virtual void OnServerRemovePlayer(QSBNetworkConnection conn, QSBPlayerController player)
{
if (player.Gameobject != null)
{
QSBNetworkServer.Destroy(player.Gameobject);
}
}
public virtual void OnServerError(QSBNetworkConnection conn, int errorCode)
{
}
public virtual void OnServerSceneChanged(string sceneName)
{
}
public virtual void OnClientConnect(QSBNetworkConnection conn)
{
if (!clientLoadedScene)
{
QSBClientScene.Ready(conn);
if (autoCreatePlayer)
{
QSBClientScene.AddPlayer(0);
}
}
}
public virtual void OnClientDisconnect(QSBNetworkConnection conn)
{
StopClient();
if (conn.LastError != NetworkError.Ok)
{
if (LogFilter.logError)
{
Debug.LogError("ClientDisconnected due to error: " + conn.LastError);
}
}
}
public virtual void OnClientError(QSBNetworkConnection conn, int errorCode)
{
}
public virtual void OnClientNotReady(QSBNetworkConnection conn)
{
}
public virtual void OnClientSceneChanged(QSBNetworkConnection conn)
{
QSBClientScene.Ready(conn);
if (autoCreatePlayer)
{
var flag = QSBClientScene.localPlayers.Count == 0;
var flag2 = false;
for (var i = 0; i < QSBClientScene.localPlayers.Count; i++)
{
if (QSBClientScene.localPlayers[i].Gameobject != null)
{
flag2 = true;
break;
}
}
if (!flag2)
{
flag = true;
}
if (flag)
{
QSBClientScene.AddPlayer(0);
}
}
}
public virtual void OnStartHost()
{
}
public virtual void OnStartServer()
{
}
public virtual void OnStartClient(QSBNetworkClient client)
{
}
public virtual void OnStopServer()
{
}
public virtual void OnStopClient()
{
}
public virtual void OnStopHost()
{
}
}
}

View File

@ -1,8 +1,9 @@
using OWML.Logging;
using QuantumUNET.Messages;
using UnityEngine;
using UnityEngine.Networking;
namespace QuantumUNET
namespace QuantumUNET.Components
{
public class QSBNetworkTransform : QSBNetworkBehaviour
{

View File

@ -0,0 +1,29 @@
namespace QuantumUNET.Messages
{
internal class QSBAddPlayerMessage : QSBMessageBase
{
public short playerControllerId;
public int msgSize;
public byte[] msgData;
public override void Deserialize(QSBNetworkReader reader)
{
playerControllerId = reader.ReadInt16();
msgData = reader.ReadBytesAndSize();
if (msgData == null)
{
msgSize = 0;
}
else
{
msgSize = msgData.Length;
}
}
public override void Serialize(QSBNetworkWriter writer)
{
writer.Write(playerControllerId);
writer.WriteBytesAndSize(msgData, msgSize);
}
}
}

View File

@ -1,6 +1,6 @@
using UnityEngine.Networking;
namespace QuantumUNET
namespace QuantumUNET.Messages
{
internal class QSBAnimationMessage : QSBMessageBase
{

View File

@ -1,6 +1,6 @@
using UnityEngine.Networking;
namespace QuantumUNET
namespace QuantumUNET.Messages
{
internal class QSBAnimationParametersMessage : QSBMessageBase
{

View File

@ -1,6 +1,6 @@
using UnityEngine.Networking;
namespace QuantumUNET
namespace QuantumUNET.Messages
{
internal class QSBAnimationTriggerMessage : QSBMessageBase
{

View File

@ -1,4 +1,4 @@
namespace QuantumUNET
namespace QuantumUNET.Messages
{
internal class QSBCRCMessage : QSBMessageBase
{

View File

@ -1,6 +1,6 @@
using UnityEngine.Networking;
namespace QuantumUNET
namespace QuantumUNET.Messages
{
internal class QSBClientAuthorityMessage : QSBMessageBase
{

View File

@ -1,4 +1,4 @@
namespace QuantumUNET
namespace QuantumUNET.Messages
{
public class QSBEmptyMessage : QSBMessageBase
{

View File

@ -1,4 +1,4 @@
namespace QuantumUNET
namespace QuantumUNET.Messages
{
public class QSBErrorMessage : QSBMessageBase
{

View File

@ -1,4 +1,4 @@
namespace QuantumUNET
namespace QuantumUNET.Messages
{
public abstract class QSBMessageBase
{

View File

@ -1,6 +1,6 @@
using System;
namespace QuantumUNET
namespace QuantumUNET.Messages
{
public class QSBNetworkMessage
{

View File

@ -1,4 +1,4 @@
namespace QuantumUNET
namespace QuantumUNET.Messages
{
public delegate void QSBNetworkMessageDelegate(QSBNetworkMessage netMsg);
}

View File

@ -1,4 +1,4 @@
namespace QuantumUNET
namespace QuantumUNET.Messages
{
public class QSBNotReadyMessage : QSBEmptyMessage
{

View File

@ -1,6 +1,6 @@
using UnityEngine.Networking;
namespace QuantumUNET
namespace QuantumUNET.Messages
{
internal class QSBObjectDestroyMessage : QSBMessageBase
{

View File

@ -1,4 +1,4 @@
namespace QuantumUNET
namespace QuantumUNET.Messages
{
internal class QSBObjectSpawnFinishedMessage : QSBMessageBase
{

View File

@ -1,7 +1,7 @@
using UnityEngine;
using UnityEngine.Networking;
namespace QuantumUNET
namespace QuantumUNET.Messages
{
internal class QSBObjectSpawnMessage : QSBMessageBase
{

View File

@ -1,7 +1,7 @@
using UnityEngine;
using UnityEngine.Networking;
namespace QuantumUNET
namespace QuantumUNET.Messages
{
internal class QSBObjectSpawnSceneMessage : QSBMessageBase
{

View File

@ -1,6 +1,6 @@
using UnityEngine.Networking;
namespace QuantumUNET
namespace QuantumUNET.Messages
{
internal class QSBOwnerMessage : QSBMessageBase
{

View File

@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace QuantumUNET
namespace QuantumUNET.Messages
{
public class QSBPeerInfoMessage : QSBMessageBase
{

View File

@ -1,4 +1,4 @@
namespace QuantumUNET
namespace QuantumUNET.Messages
{
public class QSBReadyMessage : QSBEmptyMessage
{

View File

@ -0,0 +1,30 @@
using UnityEngine.Networking;
namespace QuantumUNET.Messages
{
public class QSBReconnectMessage : QSBMessageBase
{
public int oldConnectionId;
public short playerControllerId;
public NetworkInstanceId netId;
public int msgSize;
public byte[] msgData;
public override void Deserialize(QSBNetworkReader reader)
{
oldConnectionId = (int)reader.ReadPackedUInt32();
playerControllerId = (short)reader.ReadPackedUInt32();
netId = reader.ReadNetworkId();
msgData = reader.ReadBytesAndSize();
msgSize = msgData.Length;
}
public override void Serialize(QSBNetworkWriter writer)
{
writer.WritePackedUInt32((uint)oldConnectionId);
writer.WritePackedUInt32((uint)playerControllerId);
writer.Write(netId);
writer.WriteBytesAndSize(msgData, msgSize);
}
}
}

View File

@ -1,4 +1,4 @@
namespace QuantumUNET
namespace QuantumUNET.Messages
{
public class QSBRemovePlayerMessage : QSBMessageBase
{

View File

@ -1,4 +1,4 @@
namespace QuantumUNET
namespace QuantumUNET.Messages
{
public class QSBStringMessage : QSBMessageBase
{

View File

@ -1,31 +0,0 @@
namespace QuantumUNET
{
internal class QSBAddPlayerMessage : QSBMessageBase
{
public override void Deserialize(QSBNetworkReader reader)
{
this.playerControllerId = (short)reader.ReadUInt16();
this.msgData = reader.ReadBytesAndSize();
if (this.msgData == null)
{
this.msgSize = 0;
}
else
{
this.msgSize = this.msgData.Length;
}
}
public override void Serialize(QSBNetworkWriter writer)
{
writer.Write((ushort)this.playerControllerId);
writer.WriteBytesAndSize(this.msgData, this.msgSize);
}
public short playerControllerId;
public int msgSize;
public byte[] msgData;
}
}

View File

@ -1,4 +1,5 @@
using System;
using QuantumUNET.Messages;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

View File

@ -1,4 +1,6 @@
using System.Collections.Generic;
using QuantumUNET.Components;
using QuantumUNET.Messages;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using QuantumUNET.Messages;
using System.Collections.Generic;
using UnityEngine;
namespace QuantumUNET

View File

@ -1,4 +1,5 @@
using OWML.Logging;
using QuantumUNET.Components;
using System;
using System.Collections.Generic;
using System.Net.Sockets;

View File

@ -1,12 +1,11 @@
using OWML.Logging;
using QuantumUNET.Messages;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Networking.Match;
using UnityEngine.Networking.NetworkSystem;
namespace QuantumUNET
{
@ -76,15 +75,6 @@ namespace QuantumUNET
}
}
[Obsolete("Moved to NetworkMigrationManager.")]
public PeerInfoMessage[] peers
{
get
{
return null;
}
}
internal int hostId
{
get
@ -170,12 +160,6 @@ namespace QuantumUNET
return true;
}
public void Connect(MatchInfo matchInfo)
{
PrepareForConnect();
ConnectWithRelay(matchInfo);
}
public bool ReconnectToNewHost(string serverIp, int serverPort)
{
bool result;
@ -580,21 +564,6 @@ namespace QuantumUNET
m_Connection.Initialize(m_ServerIp, m_ClientId, m_ClientConnectionId, m_HostTopology);
}
private void ConnectWithRelay(MatchInfo info)
{
m_AsyncConnect = ConnectState.Connecting;
Update();
byte b;
m_ClientConnectionId = NetworkTransport.ConnectToNetworkPeer(m_ClientId, info.address, info.port, 0, 0, info.networkId, QSBUtility.GetSourceID(), info.nodeId, out b);
m_Connection = (QSBNetworkConnection)Activator.CreateInstance(m_NetworkConnectionClass);
m_Connection.SetHandlers(m_MessageHandlers);
m_Connection.Initialize(info.address, m_ClientId, m_ClientConnectionId, m_HostTopology);
if (b != 0)
{
Debug.LogError("ConnectToNetworkPeer Error: " + b);
}
}
public virtual void Disconnect()
{
m_AsyncConnect = ConnectState.Disconnected;

View File

@ -1,4 +1,6 @@
using OWML.Logging;
using QuantumUNET.Components;
using QuantumUNET.Messages;
using System;
using System.Collections.Generic;
using System.Text;
@ -450,9 +452,6 @@ namespace QuantumUNET
public virtual void TransportReceive(byte[] bytes, int numBytes, int channelId) => HandleBytes(bytes, numBytes, channelId);
[Obsolete("TransportRecieve has been deprecated. Use TransportReceive instead (UnityUpgradable) -> TransportReceive(*)", false)]
public virtual void TransportRecieve(byte[] bytes, int numBytes, int channelId) => TransportReceive(bytes, numBytes, channelId);
public virtual bool TransportSend(byte[] bytes, int numBytes, int channelId, out byte error) => NetworkTransport.Send(hostId, connectionId, channelId, bytes, numBytes, out error);
internal void AddOwnedObject(QSBNetworkIdentity obj)

View File

@ -1,220 +0,0 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking.Match;
namespace QuantumUNET
{
public class QSBNetworkManagerHUD : MonoBehaviour
{
private void Awake()
{
this.manager = base.GetComponent<QSBNetworkManagerUNET>();
}
private void OnGUI()
{
if (this.showGUI)
{
int num = 10 + this.offsetX;
int num2 = 40 + this.offsetY;
bool flag = this.manager.client == null || this.manager.client.connection == null || this.manager.client.connection.connectionId == -1;
if (!this.manager.IsClientConnected() && !QSBNetworkServer.active && this.manager.matchMaker == null)
{
if (flag)
{
if (Application.platform != RuntimePlatform.WebGLPlayer)
{
if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "LAN Host(H)"))
{
this.manager.StartHost();
}
num2 += 24;
}
if (GUI.Button(new Rect((float)num, (float)num2, 105f, 20f), "LAN Client(C)"))
{
this.manager.StartClient();
}
this.manager.networkAddress = GUI.TextField(new Rect((float)(num + 100), (float)num2, 95f, 20f), this.manager.networkAddress);
num2 += 24;
if (Application.platform == RuntimePlatform.WebGLPlayer)
{
GUI.Box(new Rect((float)num, (float)num2, 200f, 25f), "( WebGL cannot be server )");
num2 += 24;
}
else
{
if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "LAN Server Only(S)"))
{
this.manager.StartServer();
}
num2 += 24;
}
}
else
{
GUI.Label(new Rect((float)num, (float)num2, 200f, 20f), string.Concat(new object[]
{
"Connecting to ",
this.manager.networkAddress,
":",
this.manager.networkPort,
".."
}));
num2 += 24;
if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Cancel Connection Attempt"))
{
this.manager.StopClient();
}
}
}
else
{
if (QSBNetworkServer.active)
{
string text = "Server: port=" + this.manager.networkPort;
if (this.manager.useWebSockets)
{
text += " (Using WebSockets)";
}
GUI.Label(new Rect((float)num, (float)num2, 300f, 20f), text);
num2 += 24;
}
if (this.manager.IsClientConnected())
{
GUI.Label(new Rect((float)num, (float)num2, 300f, 20f), string.Concat(new object[]
{
"Client: address=",
this.manager.networkAddress,
" port=",
this.manager.networkPort
}));
num2 += 24;
}
}
if (this.manager.IsClientConnected() && !QSBClientScene.ready)
{
if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Client Ready"))
{
QSBClientScene.Ready(this.manager.client.connection);
if (QSBClientScene.localPlayers.Count == 0)
{
QSBClientScene.AddPlayer(0);
}
}
num2 += 24;
}
if (QSBNetworkServer.active || this.manager.IsClientConnected())
{
if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Stop (X)"))
{
this.manager.StopHost();
}
num2 += 24;
}
if (!QSBNetworkServer.active && !this.manager.IsClientConnected() && flag)
{
num2 += 10;
if (Application.platform == RuntimePlatform.WebGLPlayer)
{
GUI.Box(new Rect((float)(num - 5), (float)num2, 220f, 25f), "(WebGL cannot use Match Maker)");
}
else if (this.manager.matchMaker == null)
{
if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Enable Match Maker (M)"))
{
this.manager.StartMatchMaker();
}
num2 += 24;
}
else
{
if (this.manager.matchInfo == null)
{
if (this.manager.matches == null)
{
if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Create Internet Match"))
{
this.manager.matchMaker.CreateMatch(this.manager.matchName, this.manager.matchSize, true, "", "", "", 0, 0, new NetworkMatch.DataResponseDelegate<MatchInfo>(this.manager.OnMatchCreate));
}
num2 += 24;
GUI.Label(new Rect((float)num, (float)num2, 100f, 20f), "Room Name:");
this.manager.matchName = GUI.TextField(new Rect((float)(num + 100), (float)num2, 100f, 20f), this.manager.matchName);
num2 += 24;
num2 += 10;
if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Find Internet Match"))
{
this.manager.matchMaker.ListMatches(0, 20, "", false, 0, 0, new NetworkMatch.DataResponseDelegate<List<MatchInfoSnapshot>>(this.manager.OnMatchList));
}
num2 += 24;
}
else
{
for (int i = 0; i < this.manager.matches.Count; i++)
{
MatchInfoSnapshot matchInfoSnapshot = this.manager.matches[i];
if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Join Match:" + matchInfoSnapshot.name))
{
this.manager.matchName = matchInfoSnapshot.name;
this.manager.matchMaker.JoinMatch(matchInfoSnapshot.networkId, "", "", "", 0, 0, new NetworkMatch.DataResponseDelegate<MatchInfo>(this.manager.OnMatchJoined));
}
num2 += 24;
}
if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Back to Match Menu"))
{
this.manager.matches = null;
}
num2 += 24;
}
}
if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Change MM server"))
{
this.m_ShowServer = !this.m_ShowServer;
}
if (this.m_ShowServer)
{
num2 += 24;
if (GUI.Button(new Rect((float)num, (float)num2, 100f, 20f), "Local"))
{
this.manager.SetMatchHost("localhost", 1337, false);
this.m_ShowServer = false;
}
num2 += 24;
if (GUI.Button(new Rect((float)num, (float)num2, 100f, 20f), "Internet"))
{
this.manager.SetMatchHost("mm.unet.unity3d.com", 443, true);
this.m_ShowServer = false;
}
num2 += 24;
if (GUI.Button(new Rect((float)num, (float)num2, 100f, 20f), "Staging"))
{
this.manager.SetMatchHost("staging-mm.unet.unity3d.com", 443, true);
this.m_ShowServer = false;
}
}
num2 += 24;
GUI.Label(new Rect((float)num, (float)num2, 300f, 20f), "MM Uri: " + this.manager.matchMaker.baseUri);
num2 += 24;
if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Disable Match Maker"))
{
this.manager.StopMatchMaker();
}
num2 += 24;
}
}
}
}
public QSBNetworkManagerUNET manager;
[SerializeField]
public bool showGUI = true;
[SerializeField]
public int offsetX;
[SerializeField]
public int offsetY;
private bool m_ShowServer;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using QuantumUNET.Messages;
using System.Collections.Generic;
using UnityEngine;
namespace QuantumUNET

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,6 @@
using System;
using QuantumUNET.Components;
using QuantumUNET.Messages;
using System;
using System.Text;
using UnityEngine;
using UnityEngine.Networking;
@ -7,11 +9,9 @@ namespace QuantumUNET
{
public class QSBNetworkReader
{
public QSBNetworkReader()
{
m_buf = new QSBNetBuffer();
Initialize();
}
private QSBNetBuffer m_buf;
private static byte[] s_StringReaderBuffer;
private static Encoding s_Encoding;
public QSBNetworkReader(QSBNetworkWriter writer)
{
@ -34,69 +34,51 @@ namespace QuantumUNET
}
}
public uint Position
{
get
{
return m_buf.Position;
}
}
public uint Position => m_buf.Position;
public int Length
{
get
{
return m_buf.Length;
}
}
public int Length => m_buf.Length;
public void SeekZero()
{
m_buf.SeekZero();
}
public void SeekZero() => m_buf.SeekZero();
internal void Replace(byte[] buffer)
{
m_buf.Replace(buffer);
}
internal void Replace(byte[] buffer) => m_buf.Replace(buffer);
public uint ReadPackedUInt32()
{
byte b = ReadByte();
var b = ReadByte();
uint result;
if (b < 241)
{
result = (uint)b;
result = b;
}
else
{
byte b2 = ReadByte();
var b2 = ReadByte();
if (b >= 241 && b <= 248)
{
result = 240U + 256U * (uint)(b - 241) + (uint)b2;
result = 240U + (256U * (uint)(b - 241)) + b2;
}
else
{
byte b3 = ReadByte();
var b3 = ReadByte();
if (b == 249)
{
result = 2288U + 256U * (uint)b2 + (uint)b3;
result = 2288U + (256U * b2) + b3;
}
else
{
byte b4 = ReadByte();
var b4 = ReadByte();
if (b == 250)
{
result = (uint)((int)b2 + ((int)b3 << 8) + ((int)b4 << 16));
result = (uint)(b2 + (b3 << 8) + (b4 << 16));
}
else
{
byte b5 = ReadByte();
var b5 = ReadByte();
if (b < 251)
{
throw new IndexOutOfRangeException("ReadPackedUInt32() failure: " + b);
}
result = (uint)((int)b2 + ((int)b3 << 8) + ((int)b4 << 16) + ((int)b5 << 24));
result = (uint)(b2 + (b3 << 8) + (b4 << 16) + (b5 << 24));
}
}
}
@ -106,69 +88,69 @@ namespace QuantumUNET
public ulong ReadPackedUInt64()
{
byte b = ReadByte();
var b = ReadByte();
ulong result;
if (b < 241)
{
result = (ulong)b;
result = b;
}
else
{
byte b2 = ReadByte();
var b2 = ReadByte();
if (b >= 241 && b <= 248)
{
result = 240UL + 256UL * ((ulong)b - 241UL) + (ulong)b2;
result = 240UL + (256UL * (b - 241UL)) + b2;
}
else
{
byte b3 = ReadByte();
var b3 = ReadByte();
if (b == 249)
{
result = 2288UL + 256UL * (ulong)b2 + (ulong)b3;
result = 2288UL + (256UL * b2) + b3;
}
else
{
byte b4 = ReadByte();
var b4 = ReadByte();
if (b == 250)
{
result = (ulong)b2 + ((ulong)b3 << 8) + ((ulong)b4 << 16);
result = b2 + ((ulong)b3 << 8) + ((ulong)b4 << 16);
}
else
{
byte b5 = ReadByte();
var b5 = ReadByte();
if (b == 251)
{
result = (ulong)b2 + ((ulong)b3 << 8) + ((ulong)b4 << 16) + ((ulong)b5 << 24);
result = b2 + ((ulong)b3 << 8) + ((ulong)b4 << 16) + ((ulong)b5 << 24);
}
else
{
byte b6 = ReadByte();
var b6 = ReadByte();
if (b == 252)
{
result = (ulong)b2 + ((ulong)b3 << 8) + ((ulong)b4 << 16) + ((ulong)b5 << 24) + ((ulong)b6 << 32);
result = b2 + ((ulong)b3 << 8) + ((ulong)b4 << 16) + ((ulong)b5 << 24) + ((ulong)b6 << 32);
}
else
{
byte b7 = ReadByte();
var b7 = ReadByte();
if (b == 253)
{
result = (ulong)b2 + ((ulong)b3 << 8) + ((ulong)b4 << 16) + ((ulong)b5 << 24) + ((ulong)b6 << 32) + ((ulong)b7 << 40);
result = b2 + ((ulong)b3 << 8) + ((ulong)b4 << 16) + ((ulong)b5 << 24) + ((ulong)b6 << 32) + ((ulong)b7 << 40);
}
else
{
byte b8 = ReadByte();
var b8 = ReadByte();
if (b == 254)
{
result = (ulong)b2 + ((ulong)b3 << 8) + ((ulong)b4 << 16) + ((ulong)b5 << 24) + ((ulong)b6 << 32) + ((ulong)b7 << 40) + ((ulong)b8 << 48);
result = b2 + ((ulong)b3 << 8) + ((ulong)b4 << 16) + ((ulong)b5 << 24) + ((ulong)b6 << 32) + ((ulong)b7 << 40) + ((ulong)b8 << 48);
}
else
{
byte b9 = ReadByte();
var b9 = ReadByte();
if (b != 255)
{
throw new IndexOutOfRangeException("ReadPackedUInt64() failure: " + b);
}
result = (ulong)b2 + ((ulong)b3 << 8) + ((ulong)b4 << 16) + ((ulong)b5 << 24) + ((ulong)b6 << 32) + ((ulong)b7 << 40) + ((ulong)b8 << 48) + ((ulong)b9 << 56);
result = b2 + ((ulong)b3 << 8) + ((ulong)b4 << 16) + ((ulong)b5 << 24) + ((ulong)b6 << 32) + ((ulong)b7 << 40) + ((ulong)b8 << 48) + ((ulong)b9 << 56);
}
}
}
@ -180,61 +162,46 @@ namespace QuantumUNET
return result;
}
public NetworkInstanceId ReadNetworkId()
{
return new NetworkInstanceId(ReadPackedUInt32());
}
public NetworkInstanceId ReadNetworkId() => new NetworkInstanceId(ReadPackedUInt32());
public NetworkSceneId ReadSceneId()
{
return new NetworkSceneId(ReadPackedUInt32());
}
public NetworkSceneId ReadSceneId() => new NetworkSceneId(ReadPackedUInt32());
public byte ReadByte()
{
return m_buf.ReadByte();
}
public byte ReadByte() => m_buf.ReadByte();
public sbyte ReadSByte()
{
return (sbyte)m_buf.ReadByte();
}
public sbyte ReadSByte() => (sbyte)m_buf.ReadByte();
public short ReadInt16()
{
ushort num = 0;
num |= (ushort)m_buf.ReadByte();
num |= m_buf.ReadByte();
num |= (ushort)(m_buf.ReadByte() << 8);
return (short)num;
}
public ushort ReadUInt16()
{
return (ushort)((uint)(ushort)(0U | (uint)m_buf.ReadByte()) | (uint)(ushort)((uint)m_buf.ReadByte() << 8));
}
public ushort ReadUInt16() => (ushort)((ushort)(0U | m_buf.ReadByte()) | (uint)(ushort)((uint)m_buf.ReadByte() << 8));
public int ReadInt32()
{
uint num = 0U;
num |= (uint)m_buf.ReadByte();
num |= (uint)((uint)m_buf.ReadByte() << 8);
num |= (uint)((uint)m_buf.ReadByte() << 16);
return (int)(num | (uint)((uint)m_buf.ReadByte() << 24));
var num = 0U;
num |= m_buf.ReadByte();
num |= (uint)m_buf.ReadByte() << 8;
num |= (uint)m_buf.ReadByte() << 16;
return (int)(num | ((uint)m_buf.ReadByte() << 24));
}
public uint ReadUInt32()
{
uint num = 0U;
num |= (uint)m_buf.ReadByte();
num |= (uint)((uint)m_buf.ReadByte() << 8);
num |= (uint)((uint)m_buf.ReadByte() << 16);
return num | (uint)((uint)m_buf.ReadByte() << 24);
var num = 0U;
num |= m_buf.ReadByte();
num |= (uint)m_buf.ReadByte() << 8;
num |= (uint)m_buf.ReadByte() << 16;
return num | ((uint)m_buf.ReadByte() << 24);
}
public long ReadInt64()
{
ulong num = 0UL;
ulong num2 = (ulong)m_buf.ReadByte();
var num = 0UL;
var num2 = (ulong)m_buf.ReadByte();
num |= num2;
num2 = (ulong)m_buf.ReadByte() << 8;
num |= num2;
@ -254,8 +221,8 @@ namespace QuantumUNET
public ulong ReadUInt64()
{
ulong num = 0UL;
ulong num2 = (ulong)m_buf.ReadByte();
var num = 0UL;
var num2 = (ulong)m_buf.ReadByte();
num |= num2;
num2 = (ulong)m_buf.ReadByte() << 8;
num |= num2;
@ -298,7 +265,7 @@ namespace QuantumUNET
public string ReadString()
{
ushort num = ReadUInt16();
var num = ReadUInt16();
string result;
if (num == 0)
{
@ -310,25 +277,22 @@ namespace QuantumUNET
{
throw new IndexOutOfRangeException("ReadString() too long: " + num);
}
while ((int)num > s_StringReaderBuffer.Length)
while (num > s_StringReaderBuffer.Length)
{
s_StringReaderBuffer = new byte[s_StringReaderBuffer.Length * 2];
}
m_buf.ReadBytes(s_StringReaderBuffer, (uint)num);
char[] chars = s_Encoding.GetChars(s_StringReaderBuffer, 0, (int)num);
m_buf.ReadBytes(s_StringReaderBuffer, num);
var chars = s_Encoding.GetChars(s_StringReaderBuffer, 0, num);
result = new string(chars);
}
return result;
}
public char ReadChar()
{
return (char)m_buf.ReadByte();
}
public char ReadChar() => (char)m_buf.ReadByte();
public bool ReadBoolean()
{
int num = (int)m_buf.ReadByte();
var num = (int)m_buf.ReadByte();
return num == 1;
}
@ -338,14 +302,14 @@ namespace QuantumUNET
{
throw new IndexOutOfRangeException("NetworkReader ReadBytes " + count);
}
byte[] array = new byte[count];
var array = new byte[count];
m_buf.ReadBytes(array, (uint)count);
return array;
}
public byte[] ReadBytesAndSize()
{
ushort num = ReadUInt16();
var num = ReadUInt16();
byte[] result;
if (num == 0)
{
@ -353,55 +317,28 @@ namespace QuantumUNET
}
else
{
result = ReadBytes((int)num);
result = ReadBytes(num);
}
return result;
}
public Vector2 ReadVector2()
{
return new Vector2(ReadSingle(), ReadSingle());
}
public Vector2 ReadVector2() => new Vector2(ReadSingle(), ReadSingle());
public Vector3 ReadVector3()
{
return new Vector3(ReadSingle(), ReadSingle(), ReadSingle());
}
public Vector3 ReadVector3() => new Vector3(ReadSingle(), ReadSingle(), ReadSingle());
public Vector4 ReadVector4()
{
return new Vector4(ReadSingle(), ReadSingle(), ReadSingle(), ReadSingle());
}
public Vector4 ReadVector4() => new Vector4(ReadSingle(), ReadSingle(), ReadSingle(), ReadSingle());
public Color ReadColor()
{
return new Color(ReadSingle(), ReadSingle(), ReadSingle(), ReadSingle());
}
public Color ReadColor() => new Color(ReadSingle(), ReadSingle(), ReadSingle(), ReadSingle());
public Color32 ReadColor32()
{
return new Color32(ReadByte(), ReadByte(), ReadByte(), ReadByte());
}
public Color32 ReadColor32() => new Color32(ReadByte(), ReadByte(), ReadByte(), ReadByte());
public Quaternion ReadQuaternion()
{
return new Quaternion(ReadSingle(), ReadSingle(), ReadSingle(), ReadSingle());
}
public Quaternion ReadQuaternion() => new Quaternion(ReadSingle(), ReadSingle(), ReadSingle(), ReadSingle());
public Rect ReadRect()
{
return new Rect(ReadSingle(), ReadSingle(), ReadSingle(), ReadSingle());
}
public Rect ReadRect() => new Rect(ReadSingle(), ReadSingle(), ReadSingle(), ReadSingle());
public Plane ReadPlane()
{
return new Plane(ReadVector3(), ReadSingle());
}
public Plane ReadPlane() => new Plane(ReadVector3(), ReadSingle());
public Ray ReadRay()
{
return new Ray(ReadVector3(), ReadVector3());
}
public Ray ReadRay() => new Ray(ReadVector3(), ReadVector3());
public Matrix4x4 ReadMatrix4x4()
{
@ -450,7 +387,7 @@ namespace QuantumUNET
public Transform ReadTransform()
{
NetworkInstanceId networkInstanceId = ReadNetworkId();
var networkInstanceId = ReadNetworkId();
Transform result;
if (networkInstanceId.IsEmpty())
{
@ -458,7 +395,7 @@ namespace QuantumUNET
}
else
{
GameObject gameObject = QSBClientScene.FindLocalObject(networkInstanceId);
var gameObject = QSBClientScene.FindLocalObject(networkInstanceId);
if (gameObject == null)
{
if (LogFilter.logDebug)
@ -477,7 +414,7 @@ namespace QuantumUNET
public GameObject ReadGameObject()
{
NetworkInstanceId networkInstanceId = ReadNetworkId();
var networkInstanceId = ReadNetworkId();
GameObject result;
if (networkInstanceId.IsEmpty())
{
@ -508,7 +445,7 @@ namespace QuantumUNET
public QSBNetworkIdentity ReadNetworkIdentity()
{
NetworkInstanceId networkInstanceId = ReadNetworkId();
var networkInstanceId = ReadNetworkId();
QSBNetworkIdentity result;
if (networkInstanceId.IsEmpty())
{
@ -541,26 +478,13 @@ namespace QuantumUNET
return result;
}
public override string ToString()
{
return m_buf.ToString();
}
public override string ToString() => m_buf.ToString();
public TMsg ReadMessage<TMsg>() where TMsg : QSBMessageBase, new()
{
TMsg result = Activator.CreateInstance<TMsg>();
var result = Activator.CreateInstance<TMsg>();
result.Deserialize(this);
return result;
}
private QSBNetBuffer m_buf;
private const int k_MaxStringLength = 32768;
private const int k_InitialStringBufferSize = 1024;
private static byte[] s_StringReaderBuffer;
private static Encoding s_Encoding;
}
}

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using QuantumUNET.Components;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
@ -18,13 +19,13 @@ namespace QuantumUNET
{
get
{
return this.m_LocalObjects;
return m_LocalObjects;
}
}
internal void Shutdown()
{
this.ClearLocalObjects();
ClearLocalObjects();
ClearSpawners();
}
@ -32,19 +33,19 @@ namespace QuantumUNET
{
if (obj == null)
{
this.localObjects[netId] = null;
localObjects[netId] = null;
}
else
{
QSBNetworkIdentity networkIdentity = null;
if (this.localObjects.ContainsKey(netId))
if (localObjects.ContainsKey(netId))
{
networkIdentity = this.localObjects[netId];
networkIdentity = localObjects[netId];
}
if (networkIdentity == null)
{
networkIdentity = obj.GetComponent<QSBNetworkIdentity>();
this.localObjects[netId] = networkIdentity;
localObjects[netId] = networkIdentity;
}
networkIdentity.UpdateClientServer(isClient, isServer);
}
@ -52,9 +53,9 @@ namespace QuantumUNET
internal GameObject FindLocalObject(NetworkInstanceId netId)
{
if (this.localObjects.ContainsKey(netId))
if (localObjects.ContainsKey(netId))
{
QSBNetworkIdentity networkIdentity = this.localObjects[netId];
var networkIdentity = localObjects[netId];
if (networkIdentity != null)
{
return networkIdentity.gameObject;
@ -87,11 +88,11 @@ namespace QuantumUNET
internal bool RemoveLocalObjectAndDestroy(NetworkInstanceId netId)
{
bool result;
if (this.localObjects.ContainsKey(netId))
if (localObjects.ContainsKey(netId))
{
QSBNetworkIdentity networkIdentity = this.localObjects[netId];
var networkIdentity = localObjects[netId];
UnityEngine.Object.Destroy(networkIdentity.gameObject);
result = this.localObjects.Remove(netId);
result = localObjects.Remove(netId);
}
else
{
@ -102,12 +103,12 @@ namespace QuantumUNET
internal void ClearLocalObjects()
{
this.localObjects.Clear();
localObjects.Clear();
}
internal static void RegisterPrefab(GameObject prefab, NetworkHash128 newAssetId)
{
QSBNetworkIdentity component = prefab.GetComponent<QSBNetworkIdentity>();
var component = prefab.GetComponent<QSBNetworkIdentity>();
if (component)
{
component.SetDynamicAssetId(newAssetId);
@ -121,11 +122,11 @@ namespace QuantumUNET
internal static void RegisterPrefab(GameObject prefab)
{
QSBNetworkIdentity component = prefab.GetComponent<QSBNetworkIdentity>();
var component = prefab.GetComponent<QSBNetworkIdentity>();
if (component)
{
guidToPrefab[component.AssetId] = prefab;
NetworkIdentity[] componentsInChildren = prefab.GetComponentsInChildren<NetworkIdentity>();
var componentsInChildren = prefab.GetComponentsInChildren<NetworkIdentity>();
if (componentsInChildren.Length > 1)
{
if (LogFilter.logWarn)
@ -192,7 +193,7 @@ namespace QuantumUNET
internal static void UnregisterPrefab(GameObject prefab)
{
QSBNetworkIdentity component = prefab.GetComponent<QSBNetworkIdentity>();
var component = prefab.GetComponent<QSBNetworkIdentity>();
if (component == null)
{
if (LogFilter.logError)
@ -209,7 +210,7 @@ namespace QuantumUNET
internal static void RegisterPrefab(GameObject prefab, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
{
QSBNetworkIdentity component = prefab.GetComponent<QSBNetworkIdentity>();
var component = prefab.GetComponent<QSBNetworkIdentity>();
if (component == null)
{
Debug.LogError("Could not register '" + prefab.name + "' since it contains no NetworkIdentity component");
@ -250,7 +251,7 @@ namespace QuantumUNET
bool result;
if (unspawnHandlers.ContainsKey(assetId) && unspawnHandlers[assetId] != null)
{
UnSpawnDelegate unSpawnDelegate = unspawnHandlers[assetId];
var unSpawnDelegate = unspawnHandlers[assetId];
unSpawnDelegate(obj);
result = true;
}
@ -263,9 +264,9 @@ namespace QuantumUNET
internal void DestroyAllClientObjects()
{
foreach (NetworkInstanceId key in this.localObjects.Keys)
foreach (var key in localObjects.Keys)
{
QSBNetworkIdentity networkIdentity = this.localObjects[key];
var networkIdentity = localObjects[key];
if (networkIdentity != null && networkIdentity.gameObject != null)
{
if (!InvokeUnSpawnHandler(networkIdentity.AssetId, networkIdentity.gameObject))
@ -282,14 +283,14 @@ namespace QuantumUNET
}
}
}
this.ClearLocalObjects();
ClearLocalObjects();
}
internal void DumpAllClientObjects()
{
foreach (NetworkInstanceId networkInstanceId in this.localObjects.Keys)
foreach (var networkInstanceId in localObjects.Keys)
{
QSBNetworkIdentity networkIdentity = this.localObjects[networkInstanceId];
var networkIdentity = localObjects[networkInstanceId];
if (networkIdentity != null)
{
Debug.Log(string.Concat(new object[]

View File

@ -1,10 +1,11 @@
using OWML.Logging;
using QuantumUNET.Components;
using QuantumUNET.Messages;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Networking.Match;
using UnityEngine.Networking.Types;
namespace QuantumUNET
@ -76,29 +77,7 @@ namespace QuantumUNET
}
}
[Obsolete("Moved to NetworkMigrationManager")]
public static bool sendPeerInfo
{
get
{
return false;
}
set
{
}
}
public static bool dontListen
{
get
{
return m_DontListen;
}
set
{
m_DontListen = value;
}
}
public static bool dontListen { get; set; }
public static bool useWebSockets
{
@ -131,13 +110,7 @@ namespace QuantumUNET
}
}
public static bool active
{
get
{
return s_Active;
}
}
public static bool active { get; private set; }
public static bool localClientActive
{
@ -195,7 +168,7 @@ namespace QuantumUNET
NetworkTransport.Shutdown();
NetworkTransport.Init();
s_Instance = null;
s_Active = false;
active = false;
}
public static void Shutdown()
@ -203,29 +176,14 @@ namespace QuantumUNET
if (s_Instance != null)
{
s_Instance.InternalDisconnectAll();
if (!m_DontListen)
if (!dontListen)
{
s_Instance.m_SimpleServerSimple.Stop();
}
s_Instance = null;
}
m_DontListen = false;
s_Active = false;
}
public static bool Listen(MatchInfo matchInfo, int listenPort)
{
bool result;
if (!matchInfo.usingRelay)
{
result = instance.InternalListen(null, listenPort);
}
else
{
instance.InternalListenRelay(matchInfo.address, matchInfo.port, matchInfo.networkId, QSBUtility.GetSourceID(), matchInfo.nodeId);
result = true;
}
return result;
dontListen = false;
active = false;
}
internal void RegisterMessageHandlers()
@ -249,7 +207,7 @@ namespace QuantumUNET
private void InternalListenRelay(string relayIp, int relayPort, NetworkID netGuid, SourceID sourceId, NodeID nodeId)
{
m_SimpleServerSimple.ListenRelay(relayIp, relayPort, netGuid, sourceId, nodeId);
s_Active = true;
active = true;
RegisterMessageHandlers();
}
@ -265,7 +223,7 @@ namespace QuantumUNET
internal bool InternalListen(string ipAddress, int serverPort)
{
if (m_DontListen)
if (dontListen)
{
m_SimpleServerSimple.Initialize();
}
@ -274,20 +232,20 @@ namespace QuantumUNET
return false;
}
maxPacketSize = hostTopology.DefaultConfig.PacketSize;
s_Active = true;
active = true;
RegisterMessageHandlers();
return true;
}
public static QSBNetworkClient BecomeHost(QSBNetworkClient oldClient, int port, MatchInfo matchInfo, int oldConnectionId, QSBPeerInfoMessage[] peers)
public static QSBNetworkClient BecomeHost(QSBNetworkClient oldClient, int port, int oldConnectionId, QSBPeerInfoMessage[] peers)
{
return instance.BecomeHostInternal(oldClient, port, matchInfo, oldConnectionId, peers);
return instance.BecomeHostInternal(oldClient, port, oldConnectionId, peers);
}
internal QSBNetworkClient BecomeHostInternal(QSBNetworkClient oldClient, int port, MatchInfo matchInfo, int oldConnectionId, QSBPeerInfoMessage[] peers)
internal QSBNetworkClient BecomeHostInternal(QSBNetworkClient oldClient, int port, int oldConnectionId, QSBPeerInfoMessage[] peers)
{
QSBNetworkClient result;
if (s_Active)
if (active)
{
if (LogFilter.logError)
{
@ -306,22 +264,14 @@ namespace QuantumUNET
else
{
Configure(hostTopology);
if (matchInfo == null)
Debug.Log("BecomeHost Listen on " + port);
if (!Listen(port))
{
Debug.Log("BecomeHost Listen on " + port);
if (!Listen(port))
if (LogFilter.logError)
{
if (LogFilter.logError)
{
Debug.LogError("BecomeHost bind failed.");
}
return null;
Debug.LogError("BecomeHost bind failed.");
}
}
else
{
Debug.Log("BecomeHost match:" + matchInfo.networkId);
ListenRelay(matchInfo.address, matchInfo.port, matchInfo.networkId, QSBUtility.GetSourceID(), matchInfo.nodeId);
return null;
}
foreach (var networkIdentity in QSBClientScene.Objects.Values)
{
@ -765,7 +715,7 @@ namespace QuantumUNET
internal void InternalUpdate()
{
m_SimpleServerSimple.Update();
if (m_DontListen)
if (dontListen)
{
m_SimpleServerSimple.UpdateConnections();
}
@ -1940,19 +1890,10 @@ namespace QuantumUNET
}
}
[Obsolete("moved to NetworkMigrationManager")]
public void SendNetworkInfo(NetworkConnection targetConnection)
{
}
private static bool s_Active;
private static volatile QSBNetworkServer s_Instance;
private static object s_Sync = new UnityEngine.Object();
private static bool m_DontListen;
private bool m_LocalClientActive;
private List<QSBNetworkConnection> m_LocalConnectionsFakeList = new List<QSBNetworkConnection>();

View File

@ -1,4 +1,5 @@
using System;
using QuantumUNET.Messages;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using UnityEngine;

View File

@ -1,4 +1,6 @@
using System;
using QuantumUNET.Components;
using QuantumUNET.Messages;
using System;
using System.Text;
using UnityEngine;
using UnityEngine.Networking;

View File

@ -1,27 +0,0 @@
using UnityEngine.Networking;
namespace QuantumUNET
{
public class QSBPeerAuthorityMessage : QSBMessageBase
{
public override void Deserialize(QSBNetworkReader reader)
{
this.connectionId = (int)reader.ReadPackedUInt32();
this.netId = reader.ReadNetworkId();
this.authorityState = reader.ReadBoolean();
}
public override void Serialize(QSBNetworkWriter writer)
{
writer.WritePackedUInt32((uint)this.connectionId);
writer.Write(this.netId);
writer.Write(this.authorityState);
}
public int connectionId;
public NetworkInstanceId netId;
public bool authorityState;
}
}

View File

@ -1,32 +0,0 @@
namespace QuantumUNET
{
public class QSBPeerListMessage : QSBMessageBase
{
public override void Deserialize(QSBNetworkReader reader)
{
this.oldServerConnectionId = (int)reader.ReadPackedUInt32();
int num = (int)reader.ReadUInt16();
this.peers = new QSBPeerInfoMessage[num];
for (int i = 0; i < this.peers.Length; i++)
{
QSBPeerInfoMessage peerInfoMessage = new QSBPeerInfoMessage();
peerInfoMessage.Deserialize(reader);
this.peers[i] = peerInfoMessage;
}
}
public override void Serialize(QSBNetworkWriter writer)
{
writer.WritePackedUInt32((uint)this.oldServerConnectionId);
writer.Write((ushort)this.peers.Length);
for (int i = 0; i < this.peers.Length; i++)
{
this.peers[i].Serialize(writer);
}
}
public QSBPeerInfoMessage[] peers;
public int oldServerConnectionId;
}
}

View File

@ -1,4 +1,5 @@
using UnityEngine;
using QuantumUNET.Components;
using UnityEngine;
namespace QuantumUNET
{

View File

@ -1,34 +0,0 @@
using UnityEngine.Networking;
namespace QuantumUNET
{
public class QSBReconnectMessage : QSBMessageBase
{
public override void Deserialize(QSBNetworkReader reader)
{
this.oldConnectionId = (int)reader.ReadPackedUInt32();
this.playerControllerId = (short)reader.ReadPackedUInt32();
this.netId = reader.ReadNetworkId();
this.msgData = reader.ReadBytesAndSize();
this.msgSize = this.msgData.Length;
}
public override void Serialize(QSBNetworkWriter writer)
{
writer.WritePackedUInt32((uint)this.oldConnectionId);
writer.WritePackedUInt32((uint)this.playerControllerId);
writer.Write(this.netId);
writer.WriteBytesAndSize(this.msgData, this.msgSize);
}
public int oldConnectionId;
public short playerControllerId;
public NetworkInstanceId netId;
public int msgSize;
public byte[] msgData;
}
}

View File

@ -1,4 +1,6 @@
namespace QuantumUNET
using QuantumUNET.Messages;
namespace QuantumUNET
{
internal class QSBULocalConnectionToClient : QSBNetworkConnection
{

View File

@ -1,4 +1,5 @@
using UnityEngine;
using QuantumUNET.Messages;
using UnityEngine;
using UnityEngine.Networking;
namespace QuantumUNET

View File

@ -94,54 +94,51 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="QSBAddPlayerMessage.cs" />
<Compile Include="QSBAnimationMessage.cs" />
<Compile Include="QSBAnimationParametersMessage.cs" />
<Compile Include="QSBAnimationTriggerMessage.cs" />
<Compile Include="Messages\QSBAddPlayerMessage.cs" />
<Compile Include="Messages\QSBAnimationMessage.cs" />
<Compile Include="Messages\QSBAnimationParametersMessage.cs" />
<Compile Include="Messages\QSBAnimationTriggerMessage.cs" />
<Compile Include="QSBChannelBuffer.cs" />
<Compile Include="QSBChannelPacket.cs" />
<Compile Include="QSBClientAuthorityMessage.cs" />
<Compile Include="Messages\QSBClientAuthorityMessage.cs" />
<Compile Include="QSBClientScene.cs" />
<Compile Include="QSBCRCMessage.cs" />
<Compile Include="Messages\QSBCRCMessage.cs" />
<Compile Include="QSBCRCMessageEntry.cs" />
<Compile Include="QSBEmptyMessage.cs" />
<Compile Include="QSBErrorMessage.cs" />
<Compile Include="Messages\QSBEmptyMessage.cs" />
<Compile Include="Messages\QSBErrorMessage.cs" />
<Compile Include="QSBLocalClient.cs" />
<Compile Include="QSBMessageBase.cs" />
<Compile Include="Messages\QSBMessageBase.cs" />
<Compile Include="QSBNetBuffer.cs" />
<Compile Include="QSBNetworkAnimator.cs" />
<Compile Include="Components\QSBNetworkAnimator.cs" />
<Compile Include="QSBNetworkBehaviour.cs" />
<Compile Include="QSBNetworkClient.cs" />
<Compile Include="QSBNetworkConnection.cs" />
<Compile Include="QSBNetworkCRC.cs" />
<Compile Include="QSBNetworkIdentity.cs" />
<Compile Include="QSBNetworkManagerHUD.cs" />
<Compile Include="QSBNetworkManagerUNET.cs" />
<Compile Include="QSBNetworkMessage.cs" />
<Compile Include="QSBNetworkMessageDelegate.cs" />
<Compile Include="Components\QSBNetworkIdentity.cs" />
<Compile Include="Components\QSBNetworkManagerHUD.cs" />
<Compile Include="Components\QSBNetworkManagerUNET.cs" />
<Compile Include="Messages\QSBNetworkMessage.cs" />
<Compile Include="Messages\QSBNetworkMessageDelegate.cs" />
<Compile Include="QSBNetworkMessageHandlers.cs" />
<Compile Include="QSBNetworkMigrationManager.cs" />
<Compile Include="QSBNetworkReader.cs" />
<Compile Include="QSBNetworkScene.cs" />
<Compile Include="QSBNetworkServer.cs" />
<Compile Include="QSBNetworkServerSimple.cs" />
<Compile Include="QSBNetworkTransform.cs" />
<Compile Include="Components\QSBNetworkTransform.cs" />
<Compile Include="QSBNetworkWriter.cs" />
<Compile Include="QSBNotReadyMessage.cs" />
<Compile Include="QSBObjectDestroyMessage.cs" />
<Compile Include="QSBObjectSpawnFinishedMessage.cs" />
<Compile Include="QSBObjectSpawnMessage.cs" />
<Compile Include="QSBObjectSpawnSceneMessage.cs" />
<Compile Include="QSBOwnerMessage.cs" />
<Compile Include="QSBPeerAuthorityMessage.cs" />
<Compile Include="QSBPeerInfoMessage.cs" />
<Compile Include="Messages\QSBNotReadyMessage.cs" />
<Compile Include="Messages\QSBObjectDestroyMessage.cs" />
<Compile Include="Messages\QSBObjectSpawnFinishedMessage.cs" />
<Compile Include="Messages\QSBObjectSpawnMessage.cs" />
<Compile Include="Messages\QSBObjectSpawnSceneMessage.cs" />
<Compile Include="Messages\QSBOwnerMessage.cs" />
<Compile Include="Messages\QSBPeerInfoMessage.cs" />
<Compile Include="QSBPeerInfoPlayer.cs" />
<Compile Include="QSBPeerListMessage.cs" />
<Compile Include="QSBPlayerController.cs" />
<Compile Include="QSBReadyMessage.cs" />
<Compile Include="QSBReconnectMessage.cs" />
<Compile Include="QSBRemovePlayerMessage.cs" />
<Compile Include="QSBStringMessage.cs" />
<Compile Include="Messages\QSBReadyMessage.cs" />
<Compile Include="Messages\QSBReconnectMessage.cs" />
<Compile Include="Messages\QSBRemovePlayerMessage.cs" />
<Compile Include="Messages\QSBStringMessage.cs" />
<Compile Include="QSBULocalConnectionToClient.cs" />
<Compile Include="QSBULocalConnectionToServer.cs" />
<Compile Include="QSBUtility.cs" />