NetworkCRC removed because all it did was compare each script's channelIds by sending all the script names over the network. This uses unnecessary bandwidth, causes unnecessary code complexity and makes no real sense because there's virtually no reason why anyone would modify a script's channel after building the server/client.

This commit is contained in:
vis2k 2018-07-17 22:06:26 +02:00
parent 869896495a
commit ffa6e4e2ea
9 changed files with 3 additions and 203 deletions

View File

@ -50,7 +50,6 @@
<Compile Include="..\Runtime\LogFilter.cs" />
<Compile Include="..\Runtime\Messages.cs" />
<Compile Include="..\Runtime\NetworkAnimator.cs" />
<Compile Include="..\Runtime\NetworkCRC.cs" />
<Compile Include="..\Runtime\NetworkDiscovery.cs" />
<Compile Include="..\Runtime\NetworkHash128.cs" />
<Compile Include="..\Runtime\NetworkInstanceId.cs" />
@ -91,4 +90,4 @@
<!--<Copy SourceFiles="$(TargetDir)$(TargetName).dll" DestinationFiles="/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/Networking/$(TargetName).dll"/>
<Copy Condition="'$(Configuration)' == 'Debug'" SourceFiles="$(TargetDir)$(TargetName).dll.mdb" DestinationFiles="/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/Networking/$(TargetName).dll.mdb"/>-->
</Target>
</Project>
</Project>

View File

@ -391,37 +391,5 @@ public override void Serialize(NetworkWriter writer)
writer.Write(readyState);
}
}
struct CRCMessageEntry
{
public string name;
public byte channel;
}
class CRCMessage : MessageBase
{
public CRCMessageEntry[] scripts;
public override void Deserialize(NetworkReader reader)
{
int numScripts = reader.ReadUInt16();
scripts = new CRCMessageEntry[numScripts];
for (int i = 0; i < scripts.Length; ++i)
{
scripts[i].name = reader.ReadString();
scripts[i].channel = reader.ReadByte();
}
}
public override void Serialize(NetworkWriter writer)
{
writer.Write((ushort)scripts.Length);
for (int i = 0; i < scripts.Length; i++)
{
writer.Write(scripts[i].name);
writer.Write(scripts[i].channel);
}
}
}
}
#endif //ENABLE_UNET

View File

@ -1,121 +0,0 @@
#if ENABLE_UNET
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine.Networking.NetworkSystem;
namespace UnityEngine.Networking
{
public class NetworkCRC
{
internal static NetworkCRC s_Singleton;
Dictionary<string, int> m_Scripts = new Dictionary<string, int>();
bool m_ScriptCRCCheck;
static internal NetworkCRC singleton
{
get
{
if (s_Singleton == null)
{
s_Singleton = new NetworkCRC();
}
return s_Singleton;
}
}
public Dictionary<string, int> scripts { get { return m_Scripts; } }
static public bool scriptCRCCheck
{
get
{
return singleton.m_ScriptCRCCheck;
}
set
{
singleton.m_ScriptCRCCheck = value;
}
}
// The NetworkCRC cache contain entries from
static public void ReinitializeScriptCRCs(Assembly callingAssembly)
{
singleton.m_Scripts.Clear();
var types = callingAssembly.GetTypes();
for (int i = 0; i < types.Length; i++)
{
var t = types[i];
if (t.GetBaseType() == typeof(NetworkBehaviour))
{
var cctor = t.GetMethod(".cctor", BindingFlags.Static);
if (cctor != null)
{
cctor.Invoke(null, new object[] {});
}
}
}
}
static public void RegisterBehaviour(string name, int channel)
{
singleton.m_Scripts[name] = channel;
}
internal static bool Validate(CRCMessageEntry[] scripts, int numChannels)
{
return singleton.ValidateInternal(scripts, numChannels);
}
bool ValidateInternal(CRCMessageEntry[] remoteScripts, int numChannels)
{
// check count against my channels
if (m_Scripts.Count != remoteScripts.Length)
{
if (LogFilter.logWarn) { Debug.LogWarning("Network configuration mismatch detected. The number of networked scripts on the client does not match the number of networked scripts on the server. This could be caused by lazy loading of scripts on the client. This warning can be disabled by the checkbox in NetworkManager Script CRC Check."); }
Dump(remoteScripts);
return false;
}
// check each script
for (int i = 0; i < remoteScripts.Length; i++)
{
var script = remoteScripts[i];
if (LogFilter.logDebug) { Debug.Log("Script: " + script.name + " Channel: " + script.channel); }
if (m_Scripts.ContainsKey(script.name))
{
int localChannel = m_Scripts[script.name];
if (localChannel != script.channel)
{
if (LogFilter.logError) { Debug.LogError("HLAPI CRC Channel Mismatch. Script: " + script.name + " LocalChannel: " + localChannel + " RemoteChannel: " + script.channel); }
Dump(remoteScripts);
return false;
}
}
if (script.channel >= numChannels)
{
if (LogFilter.logError) { Debug.LogError("HLAPI CRC channel out of range! Script: " + script.name + " Channel: " + script.channel); }
Dump(remoteScripts);
return false;
}
}
return true;
}
void Dump(CRCMessageEntry[] remoteScripts)
{
foreach (var script in m_Scripts.Keys)
{
Debug.Log("CRC Local Dump " + script + " : " + m_Scripts[script]);
}
foreach (var remote in remoteScripts)
{
Debug.Log("CRC Remote Dump " + remote.name + " : " + remote.channel);
}
}
}
}
#endif //ENABLE_UNET

View File

@ -685,17 +685,9 @@ public int GetRTT()
internal void RegisterSystemHandlers(bool localClient)
{
ClientScene.RegisterSystemHandlers(this, localClient);
RegisterHandlerSafe(MsgType.CRC, OnCRC);
RegisterHandlerSafe(MsgType.Fragment, NetworkConnection.OnFragment);
}
void OnCRC(NetworkMessage netMsg)
{
CRCMessage msg = new CRCMessage();
netMsg.ReadMessage(msg);
NetworkCRC.Validate(msg.scripts, numChannels);
}
public void RegisterHandler(short msgType, NetworkMessageDelegate handler)
{
m_MessageHandlers.RegisterHandler(msgType, handler);

View File

@ -26,7 +26,7 @@ public class NetworkManager : MonoBehaviour
[SerializeField] string m_NetworkAddress = "localhost";
[SerializeField] bool m_DontDestroyOnLoad = true;
[SerializeField] bool m_RunInBackground = true;
[SerializeField] bool m_ScriptCRCCheck = true;
[SerializeField] bool m_ScriptCRCCheck = true; // not used anymore, but keep for compatibility
[SerializeField] float m_MaxDelay = 0.01f;
[SerializeField] LogFilter.FilterLevel m_LogLevel = LogFilter.FilterLevel.Info;
[SerializeField] GameObject m_PlayerPrefab;
@ -278,7 +278,6 @@ bool StartServer(MatchInfo info, ConnectionConfig config, int maxConnections)
if (m_RunInBackground)
Application.runInBackground = true;
NetworkCRC.scriptCRCCheck = scriptCRCCheck;
NetworkServer.useWebSockets = m_UseWebSockets;
if (m_GlobalConfig != null)

View File

@ -668,8 +668,6 @@ static void OnConnected(NetworkConnection conn)
conn.SetMaxDelay(s_MaxDelay);
conn.InvokeHandlerNoData(MsgType.Connect);
SendCrc(conn);
}
static void HandleDisconnect(int connectionId, byte error)
@ -1776,30 +1774,6 @@ static public bool SpawnObjects()
}
return true;
}
static void SendCrc(NetworkConnection targetConnection)
{
if (NetworkCRC.singleton == null)
return;
if (NetworkCRC.scriptCRCCheck == false)
return;
CRCMessage crcMsg = new CRCMessage();
// build entries
List<CRCMessageEntry> entries = new List<CRCMessageEntry>();
foreach (var name in NetworkCRC.singleton.scripts.Keys)
{
CRCMessageEntry entry = new CRCMessageEntry();
entry.name = name;
entry.channel = (byte)NetworkCRC.singleton.scripts[name];
entries.Add(entry);
}
crcMsg.scripts = entries.ToArray();
targetConnection.Send(MsgType.CRC, crcMsg);
}
};
}
#endif //ENABLE_UNET

View File

@ -49,7 +49,6 @@
<Compile Include="LogFilter.cs" />
<Compile Include="Messages.cs" />
<Compile Include="NetworkAnimator.cs" />
<Compile Include="NetworkCRC.cs" />
<Compile Include="NetworkDiscovery.cs" />
<Compile Include="NetworkHash128.cs" />
<Compile Include="NetworkInstanceId.cs" />
@ -90,4 +89,4 @@
<!--<Copy SourceFiles="$(TargetDir)$(TargetName).dll" DestinationFiles="/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/Networking/Standalone/$(TargetName).dll"/>
<Copy Condition="'$(Configuration)' == 'Debug'" SourceFiles="$(TargetDir)$(TargetName).dll.mdb" DestinationFiles="/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/Networking/Standalone/$(TargetName).dll.mdb"/>-->
</Target>
</Project>
</Project>

View File

@ -330,12 +330,6 @@ void GenerateConstants()
syncListIndex += 1;
}
// register CRC entry
// "NetworkCRC.RegisterBehaviour('MyScript', 2);"
cctorWorker.Append(cctorWorker.Create(OpCodes.Ldstr, m_td.Name));
cctorWorker.Append(cctorWorker.Create(OpCodes.Ldc_I4, m_QosChannel));
cctorWorker.Append(cctorWorker.Create(OpCodes.Call, Weaver.RegisterBehaviourReference));
cctorWorker.Append(cctorWorker.Create(OpCodes.Ret));
if (!cctorFound)
{

View File

@ -67,7 +67,6 @@ class Weaver
public static MethodReference NetworkBehaviourDirtyBitsReference;
public static TypeReference NetworkClientType;
public static TypeReference NetworkServerType;
public static TypeReference NetworkCRCType;
public static TypeReference NetworkReaderType;
public static TypeDefinition NetworkReaderDef;
@ -89,7 +88,6 @@ class Weaver
public static TypeReference ClientSceneType;
public static MethodReference FindLocalObjectReference;
public static MethodReference RegisterBehaviourReference;
public static MethodReference ReadyConnectionReference;
public static TypeReference ComponentType;
@ -1296,7 +1294,6 @@ static void SetupUnityTypes()
hashType = m_UNetAssemblyDefinition.MainModule.GetType("UnityEngine.Networking.NetworkHash128");
NetworkClientType = m_UNetAssemblyDefinition.MainModule.GetType("UnityEngine.Networking.NetworkClient");
NetworkServerType = m_UNetAssemblyDefinition.MainModule.GetType("UnityEngine.Networking.NetworkServer");
NetworkCRCType = m_UNetAssemblyDefinition.MainModule.GetType("UnityEngine.Networking.NetworkCRC");
SyncVarType = m_UNetAssemblyDefinition.MainModule.GetType("UnityEngine.Networking.SyncVarAttribute");
CommandType = m_UNetAssemblyDefinition.MainModule.GetType("UnityEngine.Networking.CommandAttribute");
@ -1445,7 +1442,6 @@ static void SetupTargetTypes()
ComponentType = m_UnityAssemblyDefinition.MainModule.GetType("UnityEngine.Component");
ClientSceneType = m_UNetAssemblyDefinition.MainModule.GetType("UnityEngine.Networking.ClientScene");
FindLocalObjectReference = ResolveMethod(ClientSceneType, "FindLocalObject");
RegisterBehaviourReference = ResolveMethod(NetworkCRCType, "RegisterBehaviour");
ReadyConnectionReference = ResolveMethod(ClientSceneType, "get_readyConnection");
// get specialized GetComponent<NetworkIdentity>()