mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
Removed channels and configs everywhere
This commit is contained in:
parent
89964d32a2
commit
baad970706
@ -19,7 +19,6 @@ public class NetworkBehaviourInspector : Editor
|
|||||||
bool[] m_ShowSyncLists;
|
bool[] m_ShowSyncLists;
|
||||||
|
|
||||||
GUIContent m_SyncVarIndicatorContent;
|
GUIContent m_SyncVarIndicatorContent;
|
||||||
protected GUIContent m_NetworkChannelLabel;
|
|
||||||
protected GUIContent m_NetworkSendIntervalLabel;
|
protected GUIContent m_NetworkSendIntervalLabel;
|
||||||
|
|
||||||
internal virtual bool hideScriptField
|
internal virtual bool hideScriptField
|
||||||
@ -33,7 +32,6 @@ void Init(MonoScript script)
|
|||||||
m_ScriptClass = script.GetClass();
|
m_ScriptClass = script.GetClass();
|
||||||
|
|
||||||
m_SyncVarIndicatorContent = new GUIContent("SyncVar", "This variable has been marked with the [SyncVar] attribute.");
|
m_SyncVarIndicatorContent = new GUIContent("SyncVar", "This variable has been marked with the [SyncVar] attribute.");
|
||||||
m_NetworkChannelLabel = new GUIContent("Network Channel", "QoS channel used for updates. Use the [NetworkSettings] class attribute to change this.");
|
|
||||||
m_NetworkSendIntervalLabel = new GUIContent("Network Send Interval", "Maximum update rate in seconds. Use the [NetworkSettings] class attribute to change this, or implement GetNetworkSendInterval");
|
m_NetworkSendIntervalLabel = new GUIContent("Network Send Interval", "Maximum update rate in seconds. Use the [NetworkSettings] class attribute to change this, or implement GetNetworkSendInterval");
|
||||||
|
|
||||||
foreach (var field in m_ScriptClass.GetFields(BindingFlags.Public | BindingFlags.Instance))
|
foreach (var field in m_ScriptClass.GetFields(BindingFlags.Public | BindingFlags.Instance))
|
||||||
@ -166,7 +164,6 @@ public override void OnInspectorGUI()
|
|||||||
var beh = target as NetworkBehaviour;
|
var beh = target as NetworkBehaviour;
|
||||||
if (beh != null)
|
if (beh != null)
|
||||||
{
|
{
|
||||||
EditorGUILayout.LabelField(m_NetworkChannelLabel, new GUIContent(beh.GetNetworkChannel().ToString()));
|
|
||||||
EditorGUILayout.LabelField(m_NetworkSendIntervalLabel, new GUIContent(beh.GetNetworkSendInterval().ToString()));
|
EditorGUILayout.LabelField(m_NetworkSendIntervalLabel, new GUIContent(beh.GetNetworkSendInterval().ToString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,13 +28,8 @@ public class NetworkManagerEditor : Editor
|
|||||||
SerializedProperty m_PlayerSpawnMethodProperty;
|
SerializedProperty m_PlayerSpawnMethodProperty;
|
||||||
SerializedProperty m_SpawnListProperty;
|
SerializedProperty m_SpawnListProperty;
|
||||||
|
|
||||||
SerializedProperty m_CustomConfigProperty;
|
|
||||||
|
|
||||||
SerializedProperty m_UseWebSocketsProperty;
|
SerializedProperty m_UseWebSocketsProperty;
|
||||||
|
|
||||||
SerializedProperty m_ChannelListProperty;
|
|
||||||
ReorderableList m_ChannelList;
|
|
||||||
|
|
||||||
GUIContent m_ShowNetworkLabel;
|
GUIContent m_ShowNetworkLabel;
|
||||||
GUIContent m_ShowSpawnLabel;
|
GUIContent m_ShowSpawnLabel;
|
||||||
|
|
||||||
@ -43,17 +38,6 @@ public class NetworkManagerEditor : Editor
|
|||||||
protected GUIContent m_DontDestroyOnLoadLabel;
|
protected GUIContent m_DontDestroyOnLoadLabel;
|
||||||
protected GUIContent m_RunInBackgroundLabel;
|
protected GUIContent m_RunInBackgroundLabel;
|
||||||
|
|
||||||
GUIContent m_MaxConnectionsLabel;
|
|
||||||
GUIContent m_MinUpdateTimeoutLabel;
|
|
||||||
GUIContent m_ConnectTimeoutLabel;
|
|
||||||
GUIContent m_DisconnectTimeoutLabel;
|
|
||||||
GUIContent m_PingTimeoutLabel;
|
|
||||||
|
|
||||||
GUIContent m_ThreadAwakeTimeoutLabel;
|
|
||||||
GUIContent m_ReactorModelLabel;
|
|
||||||
GUIContent m_ReactorMaximumReceivedMessagesLabel;
|
|
||||||
GUIContent m_ReactorMaximumSentMessagesLabel;
|
|
||||||
|
|
||||||
GUIContent m_UseWebSocketsLabel;
|
GUIContent m_UseWebSocketsLabel;
|
||||||
|
|
||||||
GUIContent m_NetworkAddressLabel;
|
GUIContent m_NetworkAddressLabel;
|
||||||
@ -88,17 +72,6 @@ protected void Init()
|
|||||||
m_OnlineSceneLabel = new GUIContent("Online Scene", "The scene loaded when the network comes online (connected to server)");
|
m_OnlineSceneLabel = new GUIContent("Online Scene", "The scene loaded when the network comes online (connected to server)");
|
||||||
m_DontDestroyOnLoadLabel = new GUIContent("Don't Destroy on Load", "Enable to persist the NetworkManager across scene changes.");
|
m_DontDestroyOnLoadLabel = new GUIContent("Don't Destroy on Load", "Enable to persist the NetworkManager across scene changes.");
|
||||||
m_RunInBackgroundLabel = new GUIContent("Run in Background", "Enable to ensure that the application runs when it does not have focus.\n\nThis is required when testing multiple instances on a single machine, but not recommended for shipping on mobile platforms.");
|
m_RunInBackgroundLabel = new GUIContent("Run in Background", "Enable to ensure that the application runs when it does not have focus.\n\nThis is required when testing multiple instances on a single machine, but not recommended for shipping on mobile platforms.");
|
||||||
|
|
||||||
m_MaxConnectionsLabel = new GUIContent("Max Connections", "Maximum number of network connections");
|
|
||||||
m_MinUpdateTimeoutLabel = new GUIContent("Min Update Timeout", "Minimum time network thread waits for events");
|
|
||||||
m_ConnectTimeoutLabel = new GUIContent("Connect Timeout", "Time to wait for timeout on connecting");
|
|
||||||
m_DisconnectTimeoutLabel = new GUIContent("Disconnect Timeout", "Time to wait for detecting disconnect");
|
|
||||||
m_PingTimeoutLabel = new GUIContent("Ping Timeout", "Time to wait for ping messages");
|
|
||||||
|
|
||||||
m_ThreadAwakeTimeoutLabel = new GUIContent("Thread Awake Timeout", "The minimum time period when system will check if there are any messages for send (or receive).");
|
|
||||||
m_ReactorModelLabel = new GUIContent("Reactor Model", "Defines reactor model for the network library");
|
|
||||||
m_ReactorMaximumReceivedMessagesLabel = new GUIContent("Reactor Max Recv Messages", "Defines maximum amount of messages in the receive queue");
|
|
||||||
m_ReactorMaximumSentMessagesLabel = new GUIContent("Reactor Max Sent Messages", "Defines maximum message count in sent queue");
|
|
||||||
|
|
||||||
m_UseWebSocketsLabel = new GUIContent("Use WebSockets", "This makes the server listen for connections using WebSockets. This allows WebGL clients to connect to the server.");
|
m_UseWebSocketsLabel = new GUIContent("Use WebSockets", "This makes the server listen for connections using WebSockets. This allows WebGL clients to connect to the server.");
|
||||||
m_NetworkAddressLabel = new GUIContent("Network Address", "The network address currently in use.");
|
m_NetworkAddressLabel = new GUIContent("Network Address", "The network address currently in use.");
|
||||||
@ -137,19 +110,6 @@ protected void Init()
|
|||||||
m_SpawnList.onAddCallback = AddButton;
|
m_SpawnList.onAddCallback = AddButton;
|
||||||
m_SpawnList.elementHeight = 16; // this uses a 16x16 icon. other sizes make it stretch.
|
m_SpawnList.elementHeight = 16; // this uses a 16x16 icon. other sizes make it stretch.
|
||||||
|
|
||||||
// network configuration
|
|
||||||
m_CustomConfigProperty = serializedObject.FindProperty("m_CustomConfig");
|
|
||||||
m_ChannelListProperty = serializedObject.FindProperty("m_Channels");
|
|
||||||
m_ChannelList = new ReorderableList(serializedObject, m_ChannelListProperty);
|
|
||||||
m_ChannelList.drawHeaderCallback = ChannelDrawHeader;
|
|
||||||
m_ChannelList.drawElementCallback = ChannelDrawChild;
|
|
||||||
m_ChannelList.onReorderCallback = ChannelChanged;
|
|
||||||
m_ChannelList.onAddDropdownCallback = ChannelAddButton;
|
|
||||||
m_ChannelList.onRemoveCallback = ChannelRemoveButton;
|
|
||||||
m_ChannelList.onChangedCallback = ChannelChanged;
|
|
||||||
m_ChannelList.onReorderCallback = ChannelChanged;
|
|
||||||
m_ChannelList.onAddCallback = ChannelChanged;
|
|
||||||
|
|
||||||
// web sockets
|
// web sockets
|
||||||
m_UseWebSocketsProperty = serializedObject.FindProperty("m_UseWebSockets");
|
m_UseWebSocketsProperty = serializedObject.FindProperty("m_UseWebSockets");
|
||||||
}
|
}
|
||||||
@ -162,71 +122,6 @@ static void ShowPropertySuffix(GUIContent content, SerializedProperty prop, stri
|
|||||||
EditorGUILayout.EndHorizontal();
|
EditorGUILayout.EndHorizontal();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void ShowConfigInfo()
|
|
||||||
{
|
|
||||||
bool oldCustomConfig = m_NetworkManager.customConfig;
|
|
||||||
EditorGUILayout.PropertyField(m_CustomConfigProperty, m_AdvancedConfigurationLabel);
|
|
||||||
|
|
||||||
// Populate default channels first time a custom config is created.
|
|
||||||
if (m_CustomConfigProperty.boolValue)
|
|
||||||
{
|
|
||||||
if (!oldCustomConfig)
|
|
||||||
{
|
|
||||||
if (m_NetworkManager.channels.Count == 0)
|
|
||||||
{
|
|
||||||
m_NetworkManager.channels.Add(QosType.ReliableSequenced);
|
|
||||||
m_NetworkManager.channels.Add(QosType.Unreliable);
|
|
||||||
m_NetworkManager.customConfig = true;
|
|
||||||
m_CustomConfigProperty.serializedObject.Update();
|
|
||||||
m_ChannelList.serializedProperty.serializedObject.Update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_NetworkManager.customConfig)
|
|
||||||
{
|
|
||||||
EditorGUI.indentLevel += 1;
|
|
||||||
var maxConn = serializedObject.FindProperty("m_MaxConnections");
|
|
||||||
ShowPropertySuffix(m_MaxConnectionsLabel, maxConn, "connections");
|
|
||||||
|
|
||||||
m_ChannelList.DoLayoutList();
|
|
||||||
|
|
||||||
maxConn.isExpanded = EditorGUILayout.Foldout(maxConn.isExpanded, "Timeouts");
|
|
||||||
if (maxConn.isExpanded)
|
|
||||||
{
|
|
||||||
EditorGUI.indentLevel += 1;
|
|
||||||
var minUpdateTimeout = serializedObject.FindProperty("m_ConnectionConfig.m_MinUpdateTimeout");
|
|
||||||
var connectTimeout = serializedObject.FindProperty("m_ConnectionConfig.m_ConnectTimeout");
|
|
||||||
var disconnectTimeout = serializedObject.FindProperty("m_ConnectionConfig.m_DisconnectTimeout");
|
|
||||||
var pingTimeout = serializedObject.FindProperty("m_ConnectionConfig.m_PingTimeout");
|
|
||||||
|
|
||||||
ShowPropertySuffix(m_MinUpdateTimeoutLabel, minUpdateTimeout, "millisec");
|
|
||||||
ShowPropertySuffix(m_ConnectTimeoutLabel, connectTimeout, "millisec");
|
|
||||||
ShowPropertySuffix(m_DisconnectTimeoutLabel, disconnectTimeout, "millisec");
|
|
||||||
ShowPropertySuffix(m_PingTimeoutLabel, pingTimeout, "millisec");
|
|
||||||
EditorGUI.indentLevel -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
var threadAwakeTimeout = serializedObject.FindProperty("m_GlobalConfig.m_ThreadAwakeTimeout");
|
|
||||||
threadAwakeTimeout.isExpanded = EditorGUILayout.Foldout(threadAwakeTimeout.isExpanded, "Global Config");
|
|
||||||
if (threadAwakeTimeout.isExpanded)
|
|
||||||
{
|
|
||||||
EditorGUI.indentLevel += 1;
|
|
||||||
var reactorModel = serializedObject.FindProperty("m_GlobalConfig.m_ReactorModel");
|
|
||||||
var reactorMaximumReceivedMessages = serializedObject.FindProperty("m_GlobalConfig.m_ReactorMaximumReceivedMessages");
|
|
||||||
var reactorMaximumSentMessages = serializedObject.FindProperty("m_GlobalConfig.m_ReactorMaximumSentMessages");
|
|
||||||
|
|
||||||
ShowPropertySuffix(m_ThreadAwakeTimeoutLabel, threadAwakeTimeout, "millisec");
|
|
||||||
EditorGUILayout.PropertyField(reactorModel, m_ReactorModelLabel);
|
|
||||||
ShowPropertySuffix(m_ReactorMaximumReceivedMessagesLabel, reactorMaximumReceivedMessages, "messages");
|
|
||||||
ShowPropertySuffix(m_ReactorMaximumSentMessagesLabel, reactorMaximumSentMessages, "messages");
|
|
||||||
EditorGUI.indentLevel -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
EditorGUI.indentLevel -= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void ShowSpawnInfo()
|
protected void ShowSpawnInfo()
|
||||||
{
|
{
|
||||||
m_PlayerPrefabProperty.isExpanded = EditorGUILayout.Foldout(m_PlayerPrefabProperty.isExpanded, m_ShowSpawnLabel);
|
m_PlayerPrefabProperty.isExpanded = EditorGUILayout.Foldout(m_PlayerPrefabProperty.isExpanded, m_ShowSpawnLabel);
|
||||||
@ -415,7 +310,6 @@ public override void OnInspectorGUI()
|
|||||||
ShowScenes();
|
ShowScenes();
|
||||||
ShowNetworkInfo();
|
ShowNetworkInfo();
|
||||||
ShowSpawnInfo();
|
ShowSpawnInfo();
|
||||||
ShowConfigInfo();
|
|
||||||
serializedObject.ApplyModifiedProperties();
|
serializedObject.ApplyModifiedProperties();
|
||||||
|
|
||||||
ShowDerivedProperties(typeof(NetworkManager), null);
|
ShowDerivedProperties(typeof(NetworkManager), null);
|
||||||
@ -489,51 +383,6 @@ internal void RemoveButton(ReorderableList list)
|
|||||||
list.index = m_SpawnListProperty.arraySize - 1;
|
list.index = m_SpawnListProperty.arraySize - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// List widget functions
|
|
||||||
|
|
||||||
static void ChannelDrawHeader(Rect headerRect)
|
|
||||||
{
|
|
||||||
GUI.Label(headerRect, "Qos Channels:");
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void ChannelDrawChild(Rect r, int index, bool isActive, bool isFocused)
|
|
||||||
{
|
|
||||||
QosType qos = (QosType)m_ChannelListProperty.GetArrayElementAtIndex(index).enumValueIndex;
|
|
||||||
QosType newValue = (QosType)EditorGUI.EnumPopup(r, "Channel #" + index, qos);
|
|
||||||
if (newValue != qos)
|
|
||||||
{
|
|
||||||
var obj = m_ChannelListProperty.GetArrayElementAtIndex(index);
|
|
||||||
obj.enumValueIndex = (int)newValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void ChannelChanged(ReorderableList list)
|
|
||||||
{
|
|
||||||
EditorUtility.SetDirty(target);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void ChannelAddButton(Rect rect, ReorderableList list)
|
|
||||||
{
|
|
||||||
m_ChannelListProperty.arraySize += 1;
|
|
||||||
var obj = m_ChannelListProperty.GetArrayElementAtIndex(m_ChannelListProperty.arraySize - 1);
|
|
||||||
obj.enumValueIndex = (int)QosType.ReliableSequenced;
|
|
||||||
list.index = m_ChannelListProperty.arraySize - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void ChannelRemoveButton(ReorderableList list)
|
|
||||||
{
|
|
||||||
if (m_NetworkManager.channels.Count == 1)
|
|
||||||
{
|
|
||||||
if (LogFilter.logError) { Debug.LogError("Cannot remove channel. There must be at least one QoS channel."); }
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_ChannelListProperty.DeleteArrayElementAtIndex(m_ChannelList.index);
|
|
||||||
if (list.index >= m_ChannelListProperty.arraySize - 1)
|
|
||||||
{
|
|
||||||
list.index = m_ChannelListProperty.arraySize - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif //ENABLE_UNET
|
#endif //ENABLE_UNET
|
||||||
|
@ -580,7 +580,7 @@ static void OnUpdateVarsMessage(NetworkMessage netMsg)
|
|||||||
{
|
{
|
||||||
UpdateVarsMessage message = netMsg.ReadMessage<UpdateVarsMessage>();
|
UpdateVarsMessage message = netMsg.ReadMessage<UpdateVarsMessage>();
|
||||||
|
|
||||||
if (LogFilter.logDev) { Debug.Log("ClientScene::OnUpdateVarsMessage " + message.netId + " channel:" + netMsg.channelId); }
|
if (LogFilter.logDev) { Debug.Log("ClientScene::OnUpdateVarsMessage " + message.netId); }
|
||||||
|
|
||||||
NetworkIdentity localObject;
|
NetworkIdentity localObject;
|
||||||
if (s_NetworkScene.GetNetworkIdentity(message.netId, out localObject))
|
if (s_NetworkScene.GetNetworkIdentity(message.netId, out localObject))
|
||||||
|
@ -7,7 +7,6 @@ namespace UnityEngine.Networking
|
|||||||
[AttributeUsage(AttributeTargets.Class)]
|
[AttributeUsage(AttributeTargets.Class)]
|
||||||
public class NetworkSettingsAttribute : Attribute
|
public class NetworkSettingsAttribute : Attribute
|
||||||
{
|
{
|
||||||
public int channel = Channels.DefaultReliable;
|
|
||||||
public float sendInterval = 0.1f;
|
public float sendInterval = 0.1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,26 +19,22 @@ public class SyncVarAttribute : Attribute
|
|||||||
[AttributeUsage(AttributeTargets.Method)]
|
[AttributeUsage(AttributeTargets.Method)]
|
||||||
public class CommandAttribute : Attribute
|
public class CommandAttribute : Attribute
|
||||||
{
|
{
|
||||||
public int channel = Channels.DefaultReliable; // this is zero
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Method)]
|
[AttributeUsage(AttributeTargets.Method)]
|
||||||
public class ClientRpcAttribute : Attribute
|
public class ClientRpcAttribute : Attribute
|
||||||
{
|
{
|
||||||
public int channel = Channels.DefaultReliable; // this is zero
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Method)]
|
[AttributeUsage(AttributeTargets.Method)]
|
||||||
public class TargetRpcAttribute : Attribute
|
public class TargetRpcAttribute : Attribute
|
||||||
{
|
{
|
||||||
public int channel = Channels.DefaultReliable; // this is zero
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Event)]
|
[AttributeUsage(AttributeTargets.Event)]
|
||||||
public class SyncEventAttribute : Attribute
|
public class SyncEventAttribute : Attribute
|
||||||
{
|
{
|
||||||
public int channel = Channels.DefaultReliable; // this is zero
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Method)]
|
[AttributeUsage(AttributeTargets.Method)]
|
||||||
|
@ -10,7 +10,6 @@ struct InternalMsg
|
|||||||
{
|
{
|
||||||
internal ushort msgType;
|
internal ushort msgType;
|
||||||
internal byte[] content;
|
internal byte[] content;
|
||||||
internal int channelId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<InternalMsg> m_InternalMsgs = new List<InternalMsg>();
|
List<InternalMsg> m_InternalMsgs = new List<InternalMsg>();
|
||||||
@ -68,12 +67,11 @@ internal void AddLocalPlayer(PlayerController localPlayer)
|
|||||||
ClientScene.InternalAddPlayer(uv, localPlayer.playerControllerId);
|
ClientScene.InternalAddPlayer(uv, localPlayer.playerControllerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PostInternalMessage(short msgType, byte[] content, int channelId)
|
private void PostInternalMessage(short msgType, byte[] content)
|
||||||
{
|
{
|
||||||
InternalMsg msg = new InternalMsg();
|
InternalMsg msg = new InternalMsg();
|
||||||
msg.msgType = (ushort)msgType;
|
msg.msgType = (ushort)msgType;
|
||||||
msg.content = content;
|
msg.content = content;
|
||||||
msg.channelId = channelId;
|
|
||||||
m_InternalMsgs.Add(msg);
|
m_InternalMsgs.Add(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +79,7 @@ private void PostInternalMessage(short msgType)
|
|||||||
{
|
{
|
||||||
// call PostInternalMessage with empty content array if we just want to call a message like Connect
|
// call PostInternalMessage with empty content array if we just want to call a message like Connect
|
||||||
// -> NetworkTransport has empty [] and not null array for those messages too
|
// -> NetworkTransport has empty [] and not null array for those messages too
|
||||||
PostInternalMessage(msgType, new byte[0], 0);
|
PostInternalMessage(msgType, new byte[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessInternalMessages()
|
private void ProcessInternalMessages()
|
||||||
@ -103,7 +101,6 @@ private void ProcessInternalMessages()
|
|||||||
NetworkMessage internalMessage = new NetworkMessage();
|
NetworkMessage internalMessage = new NetworkMessage();
|
||||||
internalMessage.msgType = (short)msg.msgType;
|
internalMessage.msgType = (short)msg.msgType;
|
||||||
internalMessage.reader = new NetworkReader(msg.content);
|
internalMessage.reader = new NetworkReader(msg.content);
|
||||||
internalMessage.channelId = msg.channelId;
|
|
||||||
internalMessage.conn = connection;
|
internalMessage.conn = connection;
|
||||||
|
|
||||||
m_Connection.InvokeHandler(internalMessage);
|
m_Connection.InvokeHandler(internalMessage);
|
||||||
@ -120,14 +117,14 @@ private void ProcessInternalMessages()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// called by the server, to bypass network
|
// called by the server, to bypass network
|
||||||
internal void InvokeBytesOnClient(byte[] buffer, int channelId)
|
internal void InvokeBytesOnClient(byte[] buffer)
|
||||||
{
|
{
|
||||||
// unpack message and post to internal list for processing
|
// unpack message and post to internal list for processing
|
||||||
ushort msgType;
|
ushort msgType;
|
||||||
byte[] content;
|
byte[] content;
|
||||||
if (Protocol.UnpackMessage(buffer, out msgType, out content))
|
if (Protocol.UnpackMessage(buffer, out msgType, out content))
|
||||||
{
|
{
|
||||||
PostInternalMessage((short)msgType, content, channelId);
|
PostInternalMessage((short)msgType, content);
|
||||||
}
|
}
|
||||||
else if (LogFilter.logError) Debug.LogError("InvokeBytesOnClient failed to unpack message: " + BitConverter.ToString(buffer));
|
else if (LogFilter.logError) Debug.LogError("InvokeBytesOnClient failed to unpack message: " + BitConverter.ToString(buffer));
|
||||||
}
|
}
|
||||||
|
@ -18,9 +18,9 @@ public ULocalConnectionToClient(LocalClient localClient)
|
|||||||
m_LocalClient = localClient;
|
m_LocalClient = localClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool SendBytes(byte[] bytes, int channelId)
|
protected override bool SendBytes(byte[] bytes)
|
||||||
{
|
{
|
||||||
m_LocalClient.InvokeBytesOnClient(bytes, channelId);
|
m_LocalClient.InvokeBytesOnClient(bytes);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -34,14 +34,14 @@ public ULocalConnectionToServer()
|
|||||||
address = "localServer";
|
address = "localServer";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool SendBytes(byte[] bytes, int channelId)
|
protected override bool SendBytes(byte[] bytes)
|
||||||
{
|
{
|
||||||
if (bytes.Length == 0)
|
if (bytes.Length == 0)
|
||||||
{
|
{
|
||||||
if (LogFilter.logError) { Debug.LogError("LocalConnection:SendBytes cannot send zero bytes"); }
|
if (LogFilter.logError) { Debug.LogError("LocalConnection:SendBytes cannot send zero bytes"); }
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return NetworkServer.InvokeBytes(this, bytes, channelId);
|
return NetworkServer.InvokeBytes(this, bytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ NetworkIdentity myView
|
|||||||
// ----------------------------- Commands --------------------------------
|
// ----------------------------- Commands --------------------------------
|
||||||
|
|
||||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
protected void SendCommandInternal(int cmdHash, NetworkWriter writer, int channelId, string cmdName)
|
protected void SendCommandInternal(int cmdHash, NetworkWriter writer, string cmdName)
|
||||||
{
|
{
|
||||||
// local players can always send commands, regardless of authority, other objects must have authority.
|
// local players can always send commands, regardless of authority, other objects must have authority.
|
||||||
if (!(isLocalPlayer || hasAuthority))
|
if (!(isLocalPlayer || hasAuthority))
|
||||||
@ -74,7 +74,7 @@ protected void SendCommandInternal(int cmdHash, NetworkWriter writer, int channe
|
|||||||
message.cmdHash = cmdHash;
|
message.cmdHash = cmdHash;
|
||||||
message.payload = writer.ToArray();
|
message.payload = writer.ToArray();
|
||||||
|
|
||||||
ClientScene.readyConnection.SendByChannel((short)MsgType.Command, message, channelId);
|
ClientScene.readyConnection.Send((short)MsgType.Command, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
@ -86,7 +86,7 @@ public virtual bool InvokeCommand(int cmdHash, NetworkReader reader)
|
|||||||
// ----------------------------- Client RPCs --------------------------------
|
// ----------------------------- Client RPCs --------------------------------
|
||||||
|
|
||||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
protected void SendRPCInternal(int rpcHash, NetworkWriter writer, int channelId, string rpcName)
|
protected void SendRPCInternal(int rpcHash, NetworkWriter writer, string rpcName)
|
||||||
{
|
{
|
||||||
// This cannot use NetworkServer.active, as that is not specific to this object.
|
// This cannot use NetworkServer.active, as that is not specific to this object.
|
||||||
if (!isServer)
|
if (!isServer)
|
||||||
@ -101,11 +101,11 @@ protected void SendRPCInternal(int rpcHash, NetworkWriter writer, int channelId,
|
|||||||
message.rpcHash = rpcHash;
|
message.rpcHash = rpcHash;
|
||||||
message.payload = writer.ToArray();
|
message.payload = writer.ToArray();
|
||||||
|
|
||||||
NetworkServer.SendByChannelToReady(gameObject, (short)MsgType.Rpc, message, channelId);
|
NetworkServer.SendToReady(gameObject, (short)MsgType.Rpc, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
protected void SendTargetRPCInternal(NetworkConnection conn, int rpcHash, NetworkWriter writer, int channelId, string rpcName)
|
protected void SendTargetRPCInternal(NetworkConnection conn, int rpcHash, NetworkWriter writer, string rpcName)
|
||||||
{
|
{
|
||||||
// This cannot use NetworkServer.active, as that is not specific to this object.
|
// This cannot use NetworkServer.active, as that is not specific to this object.
|
||||||
if (!isServer)
|
if (!isServer)
|
||||||
@ -120,7 +120,7 @@ protected void SendTargetRPCInternal(NetworkConnection conn, int rpcHash, Networ
|
|||||||
message.rpcHash = rpcHash;
|
message.rpcHash = rpcHash;
|
||||||
message.payload = writer.ToArray();
|
message.payload = writer.ToArray();
|
||||||
|
|
||||||
conn.SendByChannel((short)MsgType.Rpc, message, channelId);
|
conn.Send((short)MsgType.Rpc, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
@ -132,7 +132,7 @@ public virtual bool InvokeRPC(int cmdHash, NetworkReader reader)
|
|||||||
// ----------------------------- Sync Events --------------------------------
|
// ----------------------------- Sync Events --------------------------------
|
||||||
|
|
||||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
protected void SendEventInternal(int eventHash, NetworkWriter writer, int channelId, string eventName)
|
protected void SendEventInternal(int eventHash, NetworkWriter writer, string eventName)
|
||||||
{
|
{
|
||||||
if (!NetworkServer.active)
|
if (!NetworkServer.active)
|
||||||
{
|
{
|
||||||
@ -146,7 +146,7 @@ protected void SendEventInternal(int eventHash, NetworkWriter writer, int channe
|
|||||||
message.eventHash = eventHash;
|
message.eventHash = eventHash;
|
||||||
message.payload = writer.ToArray();
|
message.payload = writer.ToArray();
|
||||||
|
|
||||||
NetworkServer.SendByChannelToReady(gameObject, (short)MsgType.SyncEvent, message, channelId);
|
NetworkServer.SendToReady(gameObject, (short)MsgType.SyncEvent, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
@ -587,11 +587,6 @@ public virtual bool OnCheckObserver(NetworkConnection conn)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual int GetNetworkChannel()
|
|
||||||
{
|
|
||||||
return Channels.DefaultReliable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual float GetNetworkSendInterval()
|
public virtual float GetNetworkSendInterval()
|
||||||
{
|
{
|
||||||
return k_DefaultSendInterval;
|
return k_DefaultSendInterval;
|
||||||
|
@ -17,7 +17,6 @@ public class NetworkClient
|
|||||||
public static List<NetworkClient> allClients { get { return s_Clients; } }
|
public static List<NetworkClient> allClients { get { return s_Clients; } }
|
||||||
public static bool active { get { return s_IsActive; } }
|
public static bool active { get { return s_IsActive; } }
|
||||||
|
|
||||||
HostTopology m_HostTopology;
|
|
||||||
int m_HostPort;
|
int m_HostPort;
|
||||||
|
|
||||||
string m_ServerIp = "";
|
string m_ServerIp = "";
|
||||||
@ -47,8 +46,6 @@ internal void SetHandlers(NetworkConnection conn)
|
|||||||
public NetworkConnection connection { get { return m_Connection; } }
|
public NetworkConnection connection { get { return m_Connection; } }
|
||||||
|
|
||||||
public Dictionary<short, NetworkMessageDelegate> handlers { get { return m_MessageHandlers; } }
|
public Dictionary<short, NetworkMessageDelegate> handlers { get { return m_MessageHandlers; } }
|
||||||
public int numChannels { get { return m_HostTopology.DefaultConfig.ChannelCount; } }
|
|
||||||
public HostTopology hostTopology { get { return m_HostTopology; }}
|
|
||||||
public int hostPort
|
public int hostPort
|
||||||
{
|
{
|
||||||
get { return m_HostPort; }
|
get { return m_HostPort; }
|
||||||
@ -91,20 +88,6 @@ public NetworkClient(NetworkConnection conn)
|
|||||||
RegisterSystemHandlers(false);
|
RegisterSystemHandlers(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Configure(ConnectionConfig config, int maxConnections)
|
|
||||||
{
|
|
||||||
HostTopology top = new HostTopology(config, maxConnections);
|
|
||||||
return Configure(top);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Configure(HostTopology topology)
|
|
||||||
{
|
|
||||||
//NOTE: this maxConnections is across all clients that use this tuner, so it is
|
|
||||||
// effectively the number of _clients_.
|
|
||||||
m_HostTopology = topology;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool IsValidIpV6(string address)
|
static bool IsValidIpV6(string address)
|
||||||
{
|
{
|
||||||
// use C# built-in method
|
// use C# built-in method
|
||||||
@ -129,23 +112,13 @@ public void Connect(string serverIp, int serverPort)
|
|||||||
m_ClientConnectionId = 0;
|
m_ClientConnectionId = 0;
|
||||||
m_Connection = (NetworkConnection)Activator.CreateInstance(m_NetworkConnectionClass);
|
m_Connection = (NetworkConnection)Activator.CreateInstance(m_NetworkConnectionClass);
|
||||||
m_Connection.SetHandlers(m_MessageHandlers);
|
m_Connection.SetHandlers(m_MessageHandlers);
|
||||||
m_Connection.Initialize(m_ServerIp, m_ClientId, m_ClientConnectionId, m_HostTopology);
|
m_Connection.Initialize(m_ServerIp, m_ClientId, m_ClientConnectionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrepareForConnect(bool usePlatformSpecificProtocols)
|
void PrepareForConnect(bool usePlatformSpecificProtocols)
|
||||||
{
|
{
|
||||||
SetActive(true);
|
SetActive(true);
|
||||||
RegisterSystemHandlers(false);
|
RegisterSystemHandlers(false);
|
||||||
|
|
||||||
if (m_HostTopology == null)
|
|
||||||
{
|
|
||||||
var config = new ConnectionConfig();
|
|
||||||
config.AddChannel(QosType.ReliableSequenced);
|
|
||||||
config.AddChannel(QosType.Unreliable);
|
|
||||||
config.UsePlatformSpecificProtocols = usePlatformSpecificProtocols;
|
|
||||||
m_HostTopology = new HostTopology(config, 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_ClientId = 0; // NetworkTransport.AddHost 'Returns the ID of the host that was created.'
|
m_ClientId = 0; // NetworkTransport.AddHost 'Returns the ID of the host that was created.'
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,22 +135,20 @@ public virtual void Disconnect()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool SendByChannel(short msgType, MessageBase msg, int channelId)
|
public bool Send(short msgType, MessageBase msg)
|
||||||
{
|
{
|
||||||
if (m_Connection != null)
|
if (m_Connection != null)
|
||||||
{
|
{
|
||||||
if (connectState != ConnectState.Connected)
|
if (connectState != ConnectState.Connected)
|
||||||
{
|
{
|
||||||
if (LogFilter.logError) { Debug.LogError("NetworkClient SendByChannel when not connected to a server"); }
|
if (LogFilter.logError) { Debug.LogError("NetworkClient Send when not connected to a server"); }
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return m_Connection.SendByChannel(msgType, msg, channelId);
|
return m_Connection.Send(msgType, msg);
|
||||||
}
|
}
|
||||||
if (LogFilter.logError) { Debug.LogError("NetworkClient SendByChannel with no connection"); }
|
if (LogFilter.logError) { Debug.LogError("NetworkClient Send with no connection"); }
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
public bool Send(short msgType, MessageBase msg) { return SendByChannel(msgType, msg, Channels.DefaultReliable); }
|
|
||||||
public bool SendUnreliable(short msgType, MessageBase msg) { return SendByChannel(msgType, msg, Channels.DefaultUnreliable); }
|
|
||||||
|
|
||||||
public void Shutdown()
|
public void Shutdown()
|
||||||
{
|
{
|
||||||
@ -224,7 +195,7 @@ internal virtual void Update()
|
|||||||
break;
|
break;
|
||||||
case Telepathy.EventType.Data:
|
case Telepathy.EventType.Data:
|
||||||
Debug.Log("NetworkClient loop: Data: " + BitConverter.ToString(msg.data));
|
Debug.Log("NetworkClient loop: Data: " + BitConverter.ToString(msg.data));
|
||||||
m_Connection.TransportReceive(msg.data, 0);
|
m_Connection.TransportReceive(msg.data);
|
||||||
break;
|
break;
|
||||||
case Telepathy.EventType.Disconnected:
|
case Telepathy.EventType.Disconnected:
|
||||||
Debug.Log("NetworkClient loop: Disconnected");
|
Debug.Log("NetworkClient loop: Disconnected");
|
||||||
@ -277,7 +248,6 @@ void GenerateError(byte error)
|
|||||||
netMsg.msgType = (short)MsgType.Error;
|
netMsg.msgType = (short)MsgType.Error;
|
||||||
netMsg.reader = new NetworkReader(writer.ToArray());
|
netMsg.reader = new NetworkReader(writer.ToArray());
|
||||||
netMsg.conn = m_Connection;
|
netMsg.conn = m_Connection;
|
||||||
netMsg.channelId = 0;
|
|
||||||
msgDelegate(netMsg);
|
msgDelegate(netMsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,14 +34,11 @@ public class NetworkConnection : IDisposable
|
|||||||
|
|
||||||
public NetworkError lastError { get { return error; } internal set { error = value; } }
|
public NetworkError lastError { get { return error; } internal set { error = value; } }
|
||||||
|
|
||||||
public virtual void Initialize(string networkAddress, int networkHostId, int networkConnectionId, HostTopology hostTopology)
|
public virtual void Initialize(string networkAddress, int networkHostId, int networkConnectionId)
|
||||||
{
|
{
|
||||||
address = networkAddress;
|
address = networkAddress;
|
||||||
hostId = networkHostId;
|
hostId = networkHostId;
|
||||||
connectionId = networkConnectionId;
|
connectionId = networkConnectionId;
|
||||||
|
|
||||||
if ((hostTopology.DefaultConfig.UsePlatformSpecificProtocols) && (Application.platform != RuntimePlatform.PS4) && (Application.platform != RuntimePlatform.PSP2))
|
|
||||||
throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~NetworkConnection()
|
~NetworkConnection()
|
||||||
@ -99,10 +96,10 @@ internal void SetHandlers(Dictionary<short, NetworkMessageDelegate> handlers)
|
|||||||
|
|
||||||
public bool InvokeHandlerNoData(short msgType)
|
public bool InvokeHandlerNoData(short msgType)
|
||||||
{
|
{
|
||||||
return InvokeHandler(msgType, null, 0);
|
return InvokeHandler(msgType, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool InvokeHandler(short msgType, NetworkReader reader, int channelId)
|
public bool InvokeHandler(short msgType, NetworkReader reader)
|
||||||
{
|
{
|
||||||
NetworkMessageDelegate msgDelegate;
|
NetworkMessageDelegate msgDelegate;
|
||||||
if (m_MessageHandlers.TryGetValue(msgType, out msgDelegate))
|
if (m_MessageHandlers.TryGetValue(msgType, out msgDelegate))
|
||||||
@ -111,7 +108,6 @@ public bool InvokeHandler(short msgType, NetworkReader reader, int channelId)
|
|||||||
message.msgType = msgType;
|
message.msgType = msgType;
|
||||||
message.conn = this;
|
message.conn = this;
|
||||||
message.reader = reader;
|
message.reader = reader;
|
||||||
message.channelId = channelId;
|
|
||||||
|
|
||||||
msgDelegate(message);
|
msgDelegate(message);
|
||||||
return true;
|
return true;
|
||||||
@ -177,39 +173,37 @@ internal bool GetPlayerController(short playerControllerId, out PlayerController
|
|||||||
return playerController != null;
|
return playerController != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual bool SendByChannel(short msgType, MessageBase msg, int channelId)
|
public virtual bool Send(short msgType, MessageBase msg)
|
||||||
{
|
{
|
||||||
NetworkWriter writer = new NetworkWriter();
|
NetworkWriter writer = new NetworkWriter();
|
||||||
msg.Serialize(writer);
|
msg.Serialize(writer);
|
||||||
|
|
||||||
// pack message and send
|
// pack message and send
|
||||||
byte[] message = Protocol.PackMessage((ushort)msgType, writer.ToArray());
|
byte[] message = Protocol.PackMessage((ushort)msgType, writer.ToArray());
|
||||||
return SendBytes(message, channelId);
|
return SendBytes(message);
|
||||||
}
|
}
|
||||||
public virtual bool Send(short msgType, MessageBase msg) { return SendByChannel(msgType, msg, Channels.DefaultReliable); }
|
|
||||||
public virtual bool SendUnreliable(short msgType, MessageBase msg) { return SendByChannel(msgType, msg, Channels.DefaultUnreliable); }
|
|
||||||
|
|
||||||
// protected because no one except NetworkConnection should ever send bytes directly to the client, as they
|
// protected because no one except NetworkConnection should ever send bytes directly to the client, as they
|
||||||
// would be detected as some kind of message. send messages instead.
|
// would be detected as some kind of message. send messages instead.
|
||||||
protected virtual bool SendBytes(byte[] bytes, int channelId)
|
protected virtual bool SendBytes(byte[] bytes)
|
||||||
{
|
{
|
||||||
if (logNetworkMessages) { Debug.Log("ConnectionSend con:" + connectionId + " bytes:" + BitConverter.ToString(bytes)); }
|
if (logNetworkMessages) { Debug.Log("ConnectionSend con:" + connectionId + " bytes:" + BitConverter.ToString(bytes)); }
|
||||||
|
|
||||||
if (bytes.Length > UInt16.MaxValue)
|
if (bytes.Length > UInt16.MaxValue)
|
||||||
{
|
{
|
||||||
if (LogFilter.logError) { Debug.LogError("ChannelBuffer:SendBytes cannot send packet larger than " + UInt16.MaxValue + " bytes"); }
|
if (LogFilter.logError) { Debug.LogError("NetworkConnection:SendBytes cannot send packet larger than " + UInt16.MaxValue + " bytes"); }
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytes.Length == 0)
|
if (bytes.Length == 0)
|
||||||
{
|
{
|
||||||
// zero length packets getting into the packet queues are bad.
|
// zero length packets getting into the packet queues are bad.
|
||||||
if (LogFilter.logError) { Debug.LogError("ChannelBuffer:SendBytes cannot send zero bytes"); }
|
if (LogFilter.logError) { Debug.LogError("NetworkConnection:SendBytes cannot send zero bytes"); }
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte error;
|
byte error;
|
||||||
return TransportSend(bytes, channelId, out error);
|
return TransportSend(bytes, out error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle this message
|
// handle this message
|
||||||
@ -219,7 +213,7 @@ protected virtual bool SendBytes(byte[] bytes, int channelId)
|
|||||||
// -> in other words, we always receive 1 message per NetworkTransport.Receive call, never two.
|
// -> in other words, we always receive 1 message per NetworkTransport.Receive call, never two.
|
||||||
// -> can be tested easily with a 1000ms send delay and then logging amount received in while loops here
|
// -> can be tested easily with a 1000ms send delay and then logging amount received in while loops here
|
||||||
// and in NetworkServer/Client Update. HandleBytes already takes exactly one.
|
// and in NetworkServer/Client Update. HandleBytes already takes exactly one.
|
||||||
protected void HandleBytes(byte[] buffer, int channelId)
|
protected void HandleBytes(byte[] buffer)
|
||||||
{
|
{
|
||||||
// unpack message
|
// unpack message
|
||||||
ushort msgType;
|
ushort msgType;
|
||||||
@ -236,7 +230,6 @@ protected void HandleBytes(byte[] buffer, int channelId)
|
|||||||
msg.msgType = (short)msgType;
|
msg.msgType = (short)msgType;
|
||||||
msg.reader = new NetworkReader(content);
|
msg.reader = new NetworkReader(content);
|
||||||
msg.conn = this;
|
msg.conn = this;
|
||||||
msg.channelId = channelId;
|
|
||||||
|
|
||||||
// add to queue while paused, otherwise process directly
|
// add to queue while paused, otherwise process directly
|
||||||
if (pauseQueue != null)
|
if (pauseQueue != null)
|
||||||
@ -308,12 +301,12 @@ internal void RemoveObservers()
|
|||||||
m_VisList.Clear();
|
m_VisList.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void TransportReceive(byte[] bytes, int channelId)
|
public virtual void TransportReceive(byte[] bytes)
|
||||||
{
|
{
|
||||||
HandleBytes(bytes, channelId);
|
HandleBytes(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual bool TransportSend(byte[] bytes, int channelId, out byte error)
|
public virtual bool TransportSend(byte[] bytes, out byte error)
|
||||||
{
|
{
|
||||||
error = 0;
|
error = 0;
|
||||||
if (Transport.client.Connected)
|
if (Transport.client.Connected)
|
||||||
|
@ -433,7 +433,7 @@ internal bool OnSerializeSafely(NetworkBehaviour comp, NetworkWriter writer, boo
|
|||||||
|
|
||||||
// original HLAPI had a warning in UNetUpdate() in case of large state updates. let's move it here, might
|
// original HLAPI had a warning in UNetUpdate() in case of large state updates. let's move it here, might
|
||||||
// be useful for debugging.
|
// be useful for debugging.
|
||||||
if (bytes.Length > NetworkServer.maxPacketSize)
|
if (bytes.Length > Transport.MaxPacketSize)
|
||||||
{
|
{
|
||||||
if (LogFilter.logWarn) { Debug.LogWarning("Large state update of " + bytes.Length + " bytes for netId:" + netId + " from script:" + comp); }
|
if (LogFilter.logWarn) { Debug.LogWarning("Large state update of " + bytes.Length + " bytes for netId:" + netId + " from script:" + comp); }
|
||||||
}
|
}
|
||||||
@ -443,9 +443,9 @@ internal bool OnSerializeSafely(NetworkBehaviour comp, NetworkWriter writer, boo
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// serialize all components (or only dirty ones for channelId if not initial state)
|
// serialize all components (or only dirty ones if not initial state)
|
||||||
// -> returns TRUE if any date other than dirtyMask was written!
|
// -> returns TRUE if any date other than dirtyMask was written!
|
||||||
internal bool OnSerializeAllSafely(NetworkBehaviour[] components, NetworkWriter writer, bool initialState, int channelId)
|
internal bool OnSerializeAllSafely(NetworkBehaviour[] components, NetworkWriter writer, bool initialState)
|
||||||
{
|
{
|
||||||
if (components.Length > 64)
|
if (components.Length > 64)
|
||||||
{
|
{
|
||||||
@ -458,17 +458,17 @@ internal bool OnSerializeAllSafely(NetworkBehaviour[] components, NetworkWriter
|
|||||||
NetworkWriter payload = new NetworkWriter();
|
NetworkWriter payload = new NetworkWriter();
|
||||||
for (int i = 0; i < components.Length; ++i)
|
for (int i = 0; i < components.Length; ++i)
|
||||||
{
|
{
|
||||||
// is this component dirty on this channel?
|
// is this component dirty?
|
||||||
// -> always serialize if initialState so all components with all channels are included in spawn packet
|
// -> always serialize if initialState so all components are included in spawn packet
|
||||||
// -> note: IsDirty() is false if the component isn't dirty or sendInterval isn't elapsed yet
|
// -> note: IsDirty() is false if the component isn't dirty or sendInterval isn't elapsed yet
|
||||||
NetworkBehaviour comp = m_NetworkBehaviours[i];
|
NetworkBehaviour comp = m_NetworkBehaviours[i];
|
||||||
if (initialState || (comp.IsDirty() && comp.GetNetworkChannel() == channelId))
|
if (initialState || comp.IsDirty())
|
||||||
{
|
{
|
||||||
// set bit #i to 1 in dirty mask
|
// set bit #i to 1 in dirty mask
|
||||||
dirtyComponentsMask |= (ulong)(1L << i);
|
dirtyComponentsMask |= (ulong)(1L << i);
|
||||||
|
|
||||||
// serialize the data
|
// serialize the data
|
||||||
if (LogFilter.logDebug) { Debug.Log("OnSerializeAllSafely: " + name + " -> " + comp.GetType() + " initial=" + initialState + " channelId=" + channelId); }
|
if (LogFilter.logDebug) { Debug.Log("OnSerializeAllSafely: " + name + " -> " + comp.GetType() + " initial=" + initialState); }
|
||||||
OnSerializeSafely(comp, payload, initialState);
|
OnSerializeSafely(comp, payload, initialState);
|
||||||
|
|
||||||
// Clear dirty bits only if we are synchronizing data and not sending a spawn message.
|
// Clear dirty bits only if we are synchronizing data and not sending a spawn message.
|
||||||
@ -494,7 +494,7 @@ internal bool OnSerializeAllSafely(NetworkBehaviour[] components, NetworkWriter
|
|||||||
}
|
}
|
||||||
|
|
||||||
// extra version that uses m_NetworkBehaviours so we can call it from the outside
|
// extra version that uses m_NetworkBehaviours so we can call it from the outside
|
||||||
internal void OnSerializeAllSafely(NetworkWriter writer, bool initialState, int channelId) { OnSerializeAllSafely(m_NetworkBehaviours, writer, initialState, channelId); }
|
internal void OnSerializeAllSafely(NetworkWriter writer, bool initialState) { OnSerializeAllSafely(m_NetworkBehaviours, writer, initialState); }
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@ -721,20 +721,16 @@ internal void HandleRPC(int cmdHash, NetworkReader reader)
|
|||||||
// invoked by unity runtime immediately after the regular "Update()" function.
|
// invoked by unity runtime immediately after the regular "Update()" function.
|
||||||
internal void UNetUpdate()
|
internal void UNetUpdate()
|
||||||
{
|
{
|
||||||
// go through each channel
|
// serialize all the dirty components and send (if any were dirty)
|
||||||
for (int channelId = 0; channelId < NetworkServer.numChannels; channelId++)
|
NetworkWriter writer = new NetworkWriter();
|
||||||
|
if (OnSerializeAllSafely(m_NetworkBehaviours, writer, false))
|
||||||
{
|
{
|
||||||
// serialize all the dirty components and send (if any were dirty)
|
// construct message and send
|
||||||
NetworkWriter writer = new NetworkWriter();
|
UpdateVarsMessage message = new UpdateVarsMessage();
|
||||||
if (OnSerializeAllSafely(m_NetworkBehaviours, writer, false, channelId))
|
message.netId = netId;
|
||||||
{
|
message.payload = writer.ToArray();
|
||||||
// construct message and send
|
|
||||||
UpdateVarsMessage message = new UpdateVarsMessage();
|
|
||||||
message.netId = netId;
|
|
||||||
message.payload = writer.ToArray();
|
|
||||||
|
|
||||||
NetworkServer.SendByChannelToReady(gameObject, (short)MsgType.UpdateVars, message, channelId);
|
NetworkServer.SendToReady(gameObject, (short)MsgType.UpdateVars, message);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,11 +37,7 @@ public class NetworkManager : MonoBehaviour
|
|||||||
[SerializeField] string m_OnlineScene = "";
|
[SerializeField] string m_OnlineScene = "";
|
||||||
[SerializeField] List<GameObject> m_SpawnPrefabs = new List<GameObject>();
|
[SerializeField] List<GameObject> m_SpawnPrefabs = new List<GameObject>();
|
||||||
|
|
||||||
[SerializeField] bool m_CustomConfig;
|
|
||||||
[SerializeField] int m_MaxConnections = 4;
|
[SerializeField] int m_MaxConnections = 4;
|
||||||
[SerializeField] ConnectionConfig m_ConnectionConfig;
|
|
||||||
[SerializeField] GlobalConfig m_GlobalConfig;
|
|
||||||
[SerializeField] List<QosType> m_Channels = new List<QosType>();
|
|
||||||
|
|
||||||
[SerializeField] bool m_UseWebSockets;
|
[SerializeField] bool m_UseWebSockets;
|
||||||
|
|
||||||
@ -76,11 +72,7 @@ public class NetworkManager : MonoBehaviour
|
|||||||
|
|
||||||
public List<Transform> startPositions { get { return s_StartPositions; }}
|
public List<Transform> startPositions { get { return s_StartPositions; }}
|
||||||
|
|
||||||
public bool customConfig { get { return m_CustomConfig; } set { m_CustomConfig = value; } }
|
|
||||||
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 maxConnections { get { return m_MaxConnections; } set { m_MaxConnections = value; } }
|
public int maxConnections { get { return m_MaxConnections; } set { m_MaxConnections = value; } }
|
||||||
public List<QosType> channels { get { return m_Channels; } }
|
|
||||||
|
|
||||||
public bool useWebSockets { get { return m_UseWebSockets; } set { m_UseWebSockets = value; } }
|
public bool useWebSockets { get { return m_UseWebSockets; } set { m_UseWebSockets = value; } }
|
||||||
|
|
||||||
@ -201,35 +193,6 @@ void OnValidate()
|
|||||||
if (LogFilter.logError) { Debug.LogError("NetworkManager - playerPrefab must have a NetworkIdentity."); }
|
if (LogFilter.logError) { Debug.LogError("NetworkManager - playerPrefab must have a NetworkIdentity."); }
|
||||||
m_PlayerPrefab = null;
|
m_PlayerPrefab = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_ConnectionConfig != null && m_ConnectionConfig.MinUpdateTimeout <= 0)
|
|
||||||
{
|
|
||||||
if (LogFilter.logError) { Debug.LogError("NetworkManager MinUpdateTimeout cannot be zero or less. The value will be reset to 1 millisecond"); }
|
|
||||||
m_ConnectionConfig.MinUpdateTimeout = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_GlobalConfig != null)
|
|
||||||
{
|
|
||||||
if (m_GlobalConfig.ThreadAwakeTimeout <= 0)
|
|
||||||
{
|
|
||||||
if (LogFilter.logError) { Debug.LogError("NetworkManager ThreadAwakeTimeout cannot be zero or less. The value will be reset to 1 millisecond"); }
|
|
||||||
m_GlobalConfig.ThreadAwakeTimeout = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// vis2k
|
|
||||||
// Channels.DefaultReliable = 0 and Unreliable = 1, so we have to
|
|
||||||
// force some kind of reliable to channel 0 and unreliable to 1.
|
|
||||||
// Otherwise the HLAPI code will assume a wrong channel for a lot of
|
|
||||||
// built-in functions.
|
|
||||||
//
|
|
||||||
// Changing them would result in chaos. Using anything != Fragmented
|
|
||||||
// would fail to send bigger messages too.
|
|
||||||
if (channels.Count < 1 || !Channels.IsReliableQoS(channels[0]))
|
|
||||||
Debug.LogWarning("NetworkManager: First channel needs to be Reliable because in the code Channels.DefaultReliable is 0.");
|
|
||||||
|
|
||||||
if (channels.Count < 2 || !Channels.IsUnreliableQoS(channels[1]))
|
|
||||||
Debug.LogWarning("NetworkManager: Second channel needs to be Unreliable because in the code Channels.DefaultReliable is 1.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void RegisterServerMessages()
|
internal void RegisterServerMessages()
|
||||||
@ -244,10 +207,10 @@ internal void RegisterServerMessages()
|
|||||||
|
|
||||||
public bool StartServer()
|
public bool StartServer()
|
||||||
{
|
{
|
||||||
return StartServer(null, -1);
|
return StartServer(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StartServer(ConnectionConfig config, int maxConnections)
|
bool StartServer(int maxConnections)
|
||||||
{
|
{
|
||||||
InitializeSingleton();
|
InitializeSingleton();
|
||||||
|
|
||||||
@ -258,27 +221,6 @@ bool StartServer(ConnectionConfig config, int maxConnections)
|
|||||||
|
|
||||||
NetworkServer.useWebSockets = m_UseWebSockets;
|
NetworkServer.useWebSockets = m_UseWebSockets;
|
||||||
|
|
||||||
if (m_GlobalConfig != null)
|
|
||||||
{
|
|
||||||
//NetworkTransport.Init(m_GlobalConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
// passing a config overrides setting the connectionConfig property
|
|
||||||
if (m_CustomConfig && m_ConnectionConfig != null && config == null)
|
|
||||||
{
|
|
||||||
m_ConnectionConfig.Channels.Clear();
|
|
||||||
for (int channelId = 0; channelId < m_Channels.Count; channelId++)
|
|
||||||
{
|
|
||||||
m_ConnectionConfig.AddChannel(m_Channels[channelId]);
|
|
||||||
}
|
|
||||||
NetworkServer.Configure(m_ConnectionConfig, m_MaxConnections);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config != null)
|
|
||||||
{
|
|
||||||
NetworkServer.Configure(config, maxConnections);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_ServerBindToIP && !string.IsNullOrEmpty(m_ServerBindAddress))
|
if (m_ServerBindToIP && !string.IsNullOrEmpty(m_ServerBindAddress))
|
||||||
{
|
{
|
||||||
if (!NetworkServer.Listen(m_ServerBindAddress, m_NetworkPort))
|
if (!NetworkServer.Listen(m_ServerBindAddress, m_NetworkPort))
|
||||||
@ -365,7 +307,7 @@ public void UseExternalClient(NetworkClient externalClient)
|
|||||||
s_Address = m_NetworkAddress;
|
s_Address = m_NetworkAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetworkClient StartClient(ConnectionConfig config, int hostPort)
|
public NetworkClient StartClient(int hostPort)
|
||||||
{
|
{
|
||||||
InitializeSingleton();
|
InitializeSingleton();
|
||||||
|
|
||||||
@ -374,36 +316,9 @@ public NetworkClient StartClient(ConnectionConfig config, int hostPort)
|
|||||||
|
|
||||||
isNetworkActive = true;
|
isNetworkActive = true;
|
||||||
|
|
||||||
if (m_GlobalConfig != null)
|
|
||||||
{
|
|
||||||
//NetworkTransport.Init(m_GlobalConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
client = new NetworkClient();
|
client = new NetworkClient();
|
||||||
client.hostPort = hostPort;
|
client.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 (m_CustomConfig && m_ConnectionConfig != null)
|
|
||||||
{
|
|
||||||
m_ConnectionConfig.Channels.Clear();
|
|
||||||
for (int i = 0; i < m_Channels.Count; i++)
|
|
||||||
{
|
|
||||||
m_ConnectionConfig.AddChannel(m_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, m_MaxConnections);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RegisterClientMessages(client);
|
RegisterClientMessages(client);
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(m_NetworkAddress))
|
if (string.IsNullOrEmpty(m_NetworkAddress))
|
||||||
@ -422,18 +337,13 @@ public NetworkClient StartClient(ConnectionConfig config, int hostPort)
|
|||||||
|
|
||||||
public NetworkClient StartClient()
|
public NetworkClient StartClient()
|
||||||
{
|
{
|
||||||
return StartClient(null);
|
return StartClient(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetworkClient StartClient(ConnectionConfig config)
|
public virtual NetworkClient StartHost(int maxConnections)
|
||||||
{
|
|
||||||
return StartClient(config, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual NetworkClient StartHost(ConnectionConfig config, int maxConnections)
|
|
||||||
{
|
{
|
||||||
OnStartHost();
|
OnStartHost();
|
||||||
if (StartServer(config, maxConnections))
|
if (StartServer(maxConnections))
|
||||||
{
|
{
|
||||||
var client = ConnectLocalClient();
|
var client = ConnectLocalClient();
|
||||||
OnServerConnect(client.connection);
|
OnServerConnect(client.connection);
|
||||||
|
@ -22,13 +22,9 @@ public sealed class NetworkServer
|
|||||||
|
|
||||||
static int s_ServerHostId = -1;
|
static int s_ServerHostId = -1;
|
||||||
static int s_ServerPort = -1;
|
static int s_ServerPort = -1;
|
||||||
static HostTopology s_HostTopology;
|
|
||||||
static bool s_UseWebSockets;
|
static bool s_UseWebSockets;
|
||||||
static bool s_Initialized = false;
|
static bool s_Initialized = false;
|
||||||
|
|
||||||
// this is cached here for easy access when checking the size of state update packets in NetworkIdentity
|
|
||||||
static internal ushort maxPacketSize;
|
|
||||||
|
|
||||||
// original HLAPI has .localConnections list with only m_LocalConnection in it
|
// original HLAPI has .localConnections list with only m_LocalConnection in it
|
||||||
// (for downwards compatibility because they removed the real localConnections list a while ago)
|
// (for downwards compatibility because they removed the real localConnections list a while ago)
|
||||||
// => removed it for easier code. use .localConection now!
|
// => removed it for easier code. use .localConection now!
|
||||||
@ -39,7 +35,6 @@ public sealed class NetworkServer
|
|||||||
|
|
||||||
public static List<NetworkConnection> connections { get { return s_Connections; } }
|
public static List<NetworkConnection> connections { get { return s_Connections; } }
|
||||||
public static Dictionary<short, NetworkMessageDelegate> handlers { get { return s_MessageHandlers; } }
|
public static Dictionary<short, NetworkMessageDelegate> handlers { get { return s_MessageHandlers; } }
|
||||||
public static HostTopology hostTopology { get { return s_HostTopology; }}
|
|
||||||
|
|
||||||
public static Dictionary<NetworkInstanceId, NetworkIdentity> objects { get { return s_NetworkScene.localObjects; } }
|
public static Dictionary<NetworkInstanceId, NetworkIdentity> objects { get { return s_NetworkScene.localObjects; } }
|
||||||
public static bool dontListen { get { return s_DontListen; } set { s_DontListen = value; } }
|
public static bool dontListen { get { return s_DontListen; } set { s_DontListen = value; } }
|
||||||
@ -47,7 +42,6 @@ public sealed class NetworkServer
|
|||||||
|
|
||||||
public static bool active { get { return s_Active; } }
|
public static bool active { get { return s_Active; } }
|
||||||
public static bool localClientActive { get { return s_LocalClientActive; } }
|
public static bool localClientActive { get { return s_LocalClientActive; } }
|
||||||
public static int numChannels { get { return s_HostTopology.DefaultConfig.ChannelCount; } }
|
|
||||||
|
|
||||||
static Type s_NetworkConnectionClass = typeof(NetworkConnection);
|
static Type s_NetworkConnectionClass = typeof(NetworkConnection);
|
||||||
public static Type networkConnectionClass { get { return s_NetworkConnectionClass; } }
|
public static Type networkConnectionClass { get { return s_NetworkConnectionClass; } }
|
||||||
@ -56,18 +50,6 @@ static public void SetNetworkConnectionClass<T>() where T : NetworkConnection
|
|||||||
s_NetworkConnectionClass = typeof(T);
|
s_NetworkConnectionClass = typeof(T);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public bool Configure(ConnectionConfig config, int maxConnections)
|
|
||||||
{
|
|
||||||
HostTopology top = new HostTopology(config, maxConnections);
|
|
||||||
return Configure(top);
|
|
||||||
}
|
|
||||||
|
|
||||||
static public bool Configure(HostTopology topology)
|
|
||||||
{
|
|
||||||
s_HostTopology = topology;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Reset()
|
public static void Reset()
|
||||||
{
|
{
|
||||||
Debug.Log("NetworkServer.Reset calls NetworkTransport.Shutdown and Init");
|
Debug.Log("NetworkServer.Reset calls NetworkTransport.Shutdown and Init");
|
||||||
@ -104,14 +86,6 @@ public static void Initialize()
|
|||||||
s_Initialized = true;
|
s_Initialized = true;
|
||||||
if (LogFilter.logDev) { Debug.Log("NetworkServer Created version " + Version.Current); }
|
if (LogFilter.logDev) { Debug.Log("NetworkServer Created version " + Version.Current); }
|
||||||
|
|
||||||
if (s_HostTopology == null)
|
|
||||||
{
|
|
||||||
var config = new ConnectionConfig();
|
|
||||||
config.AddChannel(QosType.ReliableSequenced);
|
|
||||||
config.AddChannel(QosType.Unreliable);
|
|
||||||
s_HostTopology = new HostTopology(config, 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (LogFilter.logDebug) { Debug.Log("NetworkServer initialize."); }
|
if (LogFilter.logDebug) { Debug.Log("NetworkServer initialize."); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,9 +99,6 @@ static internal void RegisterMessageHandlers()
|
|||||||
RegisterHandler((short)MsgType.Animation, NetworkAnimator.OnAnimationServerMessage);
|
RegisterHandler((short)MsgType.Animation, NetworkAnimator.OnAnimationServerMessage);
|
||||||
RegisterHandler((short)MsgType.AnimationParameters, NetworkAnimator.OnAnimationParametersServerMessage);
|
RegisterHandler((short)MsgType.AnimationParameters, NetworkAnimator.OnAnimationParametersServerMessage);
|
||||||
RegisterHandler((short)MsgType.AnimationTrigger, NetworkAnimator.OnAnimationTriggerServerMessage);
|
RegisterHandler((short)MsgType.AnimationTrigger, NetworkAnimator.OnAnimationTriggerServerMessage);
|
||||||
|
|
||||||
// also setup max packet size.
|
|
||||||
maxPacketSize = hostTopology.DefaultConfig.PacketSize;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static public bool Listen(int serverPort)
|
static public bool Listen(int serverPort)
|
||||||
@ -171,7 +142,6 @@ static internal bool InternalListen(string ipAddress, int serverPort)
|
|||||||
if (LogFilter.logDebug) { Debug.Log("Server listen: " + ipAddress + ":" + s_ServerPort); }
|
if (LogFilter.logDebug) { Debug.Log("Server listen: " + ipAddress + ":" + s_ServerPort); }
|
||||||
}
|
}
|
||||||
|
|
||||||
maxPacketSize = hostTopology.DefaultConfig.PacketSize;
|
|
||||||
s_Active = true;
|
s_Active = true;
|
||||||
RegisterMessageHandlers();
|
RegisterMessageHandlers();
|
||||||
return true;
|
return true;
|
||||||
@ -279,25 +249,23 @@ static bool SendToObservers(GameObject contextObj, short msgType, MessageBase ms
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public bool SendByChannelToAll(short msgType, MessageBase msg, int channelId)
|
static public bool SendToAll(short msgType, MessageBase msg)
|
||||||
{
|
{
|
||||||
if (LogFilter.logDev) { Debug.Log("Server.SendByChannelToAll id:" + msgType); }
|
if (LogFilter.logDev) { Debug.Log("Server.SendToAll id:" + msgType); }
|
||||||
|
|
||||||
bool result = true;
|
bool result = true;
|
||||||
for (int i = 0; i < connections.Count; i++)
|
for (int i = 0; i < connections.Count; i++)
|
||||||
{
|
{
|
||||||
NetworkConnection conn = connections[i];
|
NetworkConnection conn = connections[i];
|
||||||
if (conn != null)
|
if (conn != null)
|
||||||
result &= conn.SendByChannel(msgType, msg, channelId);
|
result &= conn.Send(msgType, msg);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
static public bool SendToAll(short msgType, MessageBase msg) { return SendByChannelToAll(msgType, msg, Channels.DefaultReliable); }
|
|
||||||
static public bool SendUnreliableToAll(short msgType, MessageBase msg) { return SendByChannelToAll(msgType, msg, Channels.DefaultUnreliable); }
|
|
||||||
|
|
||||||
static public bool SendByChannelToReady(GameObject contextObj, short msgType, MessageBase msg, int channelId)
|
static public bool SendToReady(GameObject contextObj, short msgType, MessageBase msg)
|
||||||
{
|
{
|
||||||
if (LogFilter.logDev) { Debug.Log("Server.SendByChannelToReady msgType:" + msgType); }
|
if (LogFilter.logDev) { Debug.Log("Server.SendToReady msgType:" + msgType); }
|
||||||
|
|
||||||
if (contextObj == null)
|
if (contextObj == null)
|
||||||
{
|
{
|
||||||
@ -307,7 +275,7 @@ static public bool SendByChannelToReady(GameObject contextObj, short msgType, Me
|
|||||||
NetworkConnection conn = connections[i];
|
NetworkConnection conn = connections[i];
|
||||||
if (conn != null && conn.isReady)
|
if (conn != null && conn.isReady)
|
||||||
{
|
{
|
||||||
conn.SendByChannel(msgType, msg, channelId);
|
conn.Send(msgType, msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -322,15 +290,13 @@ static public bool SendByChannelToReady(GameObject contextObj, short msgType, Me
|
|||||||
NetworkConnection conn = uv.observers[i];
|
NetworkConnection conn = uv.observers[i];
|
||||||
if (conn.isReady)
|
if (conn.isReady)
|
||||||
{
|
{
|
||||||
result &= conn.SendByChannel(msgType, msg, channelId);
|
result &= conn.Send(msgType, msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
static public bool SendToReady(GameObject contextObj, short msgType, MessageBase msg) { return SendByChannelToReady(contextObj, msgType, msg, Channels.DefaultReliable); }
|
|
||||||
static public bool SendUnreliableToReady(GameObject contextObj, short msgType, MessageBase msg) { return SendByChannelToReady(contextObj, msgType, msg, Channels.DefaultUnreliable); }
|
|
||||||
|
|
||||||
static public void DisconnectAll()
|
static public void DisconnectAll()
|
||||||
{
|
{
|
||||||
@ -414,7 +380,7 @@ static internal void InternalUpdate()
|
|||||||
break;
|
break;
|
||||||
case Telepathy.EventType.Data:
|
case Telepathy.EventType.Data:
|
||||||
//Debug.Log(message.connectionId + " Data: " + BitConverter.ToString(message.data));
|
//Debug.Log(message.connectionId + " Data: " + BitConverter.ToString(message.data));
|
||||||
HandleData((int)message.connectionId, message.data, 0, 0);
|
HandleData((int)message.connectionId, message.data, 0);
|
||||||
break;
|
break;
|
||||||
case Telepathy.EventType.Disconnected:
|
case Telepathy.EventType.Disconnected:
|
||||||
Console.WriteLine(message.connectionId + " Disconnected");
|
Console.WriteLine(message.connectionId + " Disconnected");
|
||||||
@ -439,7 +405,7 @@ static void HandleConnect(int connectionId, byte error)
|
|||||||
// add player info
|
// add player info
|
||||||
NetworkConnection conn = (NetworkConnection)Activator.CreateInstance(s_NetworkConnectionClass);
|
NetworkConnection conn = (NetworkConnection)Activator.CreateInstance(s_NetworkConnectionClass);
|
||||||
conn.SetHandlers(s_MessageHandlers);
|
conn.SetHandlers(s_MessageHandlers);
|
||||||
conn.Initialize("TODO_ADDRESS_FROM_TCP", s_ServerHostId, connectionId, s_HostTopology);
|
conn.Initialize("TODO_ADDRESS_FROM_TCP", s_ServerHostId, connectionId);
|
||||||
conn.lastError = (NetworkError)0;
|
conn.lastError = (NetworkError)0;
|
||||||
|
|
||||||
// add connection at correct index
|
// add connection at correct index
|
||||||
@ -509,7 +475,7 @@ public static NetworkConnection FindConnection(int connectionId)
|
|||||||
return s_Connections[connectionId];
|
return s_Connections[connectionId];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void HandleData(int connectionId, byte[] data, int channelId, byte error)
|
static void HandleData(int connectionId, byte[] data, byte error)
|
||||||
{
|
{
|
||||||
var conn = FindConnection(connectionId);
|
var conn = FindConnection(connectionId);
|
||||||
if (conn == null)
|
if (conn == null)
|
||||||
@ -525,12 +491,12 @@ static void HandleData(int connectionId, byte[] data, int channelId, byte error)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
OnData(conn, data, channelId);
|
OnData(conn, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OnData(NetworkConnection conn, byte[] data, int channelId)
|
static void OnData(NetworkConnection conn, byte[] data)
|
||||||
{
|
{
|
||||||
conn.TransportReceive(data, channelId);
|
conn.TransportReceive(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GenerateConnectError(byte error)
|
static void GenerateConnectError(byte error)
|
||||||
@ -566,7 +532,7 @@ static void GenerateError(NetworkConnection conn, byte error)
|
|||||||
|
|
||||||
// pass a reader (attached to local buffer) to handler
|
// pass a reader (attached to local buffer) to handler
|
||||||
NetworkReader reader = new NetworkReader(writer.ToArray());
|
NetworkReader reader = new NetworkReader(writer.ToArray());
|
||||||
conn.InvokeHandler((short)MsgType.Error, reader, 0);
|
conn.InvokeHandler((short)MsgType.Error, reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1067,7 +1033,7 @@ static internal void SendSpawnMessage(NetworkIdentity uv, NetworkConnection conn
|
|||||||
|
|
||||||
// serialize all components with initialState = true
|
// serialize all components with initialState = true
|
||||||
NetworkWriter writer = new NetworkWriter();
|
NetworkWriter writer = new NetworkWriter();
|
||||||
uv.OnSerializeAllSafely(writer, true, -1); // channelId doesn't matter if initialState
|
uv.OnSerializeAllSafely(writer, true);
|
||||||
msg.payload = writer.ToArray();
|
msg.payload = writer.ToArray();
|
||||||
|
|
||||||
// conn is != null when spawning it for a client
|
// conn is != null when spawning it for a client
|
||||||
@ -1091,7 +1057,7 @@ static internal void SendSpawnMessage(NetworkIdentity uv, NetworkConnection conn
|
|||||||
|
|
||||||
// include synch data
|
// include synch data
|
||||||
NetworkWriter writer = new NetworkWriter();
|
NetworkWriter writer = new NetworkWriter();
|
||||||
uv.OnSerializeAllSafely(writer, true, -1); // channelId doesn't matter if initialState
|
uv.OnSerializeAllSafely(writer, true);
|
||||||
msg.payload = writer.ToArray();
|
msg.payload = writer.ToArray();
|
||||||
|
|
||||||
// conn is != null when spawning it for a client
|
// conn is != null when spawning it for a client
|
||||||
@ -1321,7 +1287,7 @@ static public void UnSpawn(GameObject obj)
|
|||||||
UnSpawnObject(obj);
|
UnSpawnObject(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
static internal bool InvokeBytes(ULocalConnectionToServer conn, byte[] buffer, int channelId)
|
static internal bool InvokeBytes(ULocalConnectionToServer conn, byte[] buffer)
|
||||||
{
|
{
|
||||||
ushort msgType;
|
ushort msgType;
|
||||||
byte[] content;
|
byte[] content;
|
||||||
@ -1330,7 +1296,7 @@ static internal bool InvokeBytes(ULocalConnectionToServer conn, byte[] buffer, i
|
|||||||
if (handlers.ContainsKey((short)msgType) && s_LocalConnection != null)
|
if (handlers.ContainsKey((short)msgType) && s_LocalConnection != null)
|
||||||
{
|
{
|
||||||
// this must be invoked with the connection to the client, not the client's connection to the server
|
// this must be invoked with the connection to the client, not the client's connection to the server
|
||||||
s_LocalConnection.InvokeHandler((short)msgType, new NetworkReader(content), channelId);
|
s_LocalConnection.InvokeHandler((short)msgType, new NetworkReader(content));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -395,7 +395,7 @@ void SendTransform()
|
|||||||
m_PrevPosition = m_Target.localPosition;
|
m_PrevPosition = m_Target.localPosition;
|
||||||
m_PrevRotation = m_Target.localRotation;
|
m_PrevRotation = m_Target.localRotation;
|
||||||
|
|
||||||
ClientScene.readyConnection.SendByChannel((short)MsgType.LocalChildTransform, message, GetNetworkChannel());
|
ClientScene.readyConnection.Send((short)MsgType.LocalChildTransform, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
static internal void HandleChildTransform(NetworkMessage netMsg)
|
static internal void HandleChildTransform(NetworkMessage netMsg)
|
||||||
@ -449,11 +449,6 @@ static internal void HandleChildTransform(NetworkMessage netMsg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int GetNetworkChannel()
|
|
||||||
{
|
|
||||||
return Channels.DefaultUnreliable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override float GetNetworkSendInterval()
|
public override float GetNetworkSendInterval()
|
||||||
{
|
{
|
||||||
return m_SendInterval;
|
return m_SendInterval;
|
||||||
|
@ -1233,7 +1233,7 @@ void SendTransform()
|
|||||||
message.netId = netId;
|
message.netId = netId;
|
||||||
message.payload = writer.ToArray();
|
message.payload = writer.ToArray();
|
||||||
|
|
||||||
ClientScene.readyConnection.SendByChannel((short)MsgType.LocalPlayerTransform, message, GetNetworkChannel());
|
ClientScene.readyConnection.Send((short)MsgType.LocalPlayerTransform, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public void HandleTransform(NetworkMessage netMsg)
|
static public void HandleTransform(NetworkMessage netMsg)
|
||||||
@ -1557,11 +1557,6 @@ static public float UnserializeSpin2D(NetworkReader reader, CompressionSyncMode
|
|||||||
return ReadAngle(reader, compression);
|
return ReadAngle(reader, compression);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int GetNetworkChannel()
|
|
||||||
{
|
|
||||||
return Channels.DefaultUnreliable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override float GetNetworkSendInterval()
|
public override float GetNetworkSendInterval()
|
||||||
{
|
{
|
||||||
return m_SendInterval;
|
return m_SendInterval;
|
||||||
|
@ -263,7 +263,7 @@ void SendMsg(Operation op, int itemIndex, T item)
|
|||||||
|
|
||||||
message.payload = writer.ToArray();
|
message.payload = writer.ToArray();
|
||||||
|
|
||||||
NetworkServer.SendByChannelToReady(uv.gameObject, (short)MsgType.SyncList, message, m_Behaviour.GetNetworkChannel());
|
NetworkServer.SendToReady(uv.gameObject, (short)MsgType.SyncList, message);
|
||||||
|
|
||||||
// ensure it is invoked on host
|
// ensure it is invoked on host
|
||||||
if (m_Behaviour.isServer && m_Behaviour.isClient && m_Callback != null)
|
if (m_Behaviour.isServer && m_Behaviour.isClient && m_Callback != null)
|
||||||
|
@ -7,6 +7,9 @@ public static class Transport
|
|||||||
public static Telepathy.Client client = new Telepathy.Client();
|
public static Telepathy.Client client = new Telepathy.Client();
|
||||||
public static Telepathy.Server server = new Telepathy.Server();
|
public static Telepathy.Server server = new Telepathy.Server();
|
||||||
|
|
||||||
|
// hlapi needs to know max packet size to show warnings
|
||||||
|
public static int MaxPacketSize = ushort.MaxValue;
|
||||||
|
|
||||||
static Transport()
|
static Transport()
|
||||||
{
|
{
|
||||||
// tell Telepathy to use Unity's Debug.Log
|
// tell Telepathy to use Unity's Debug.Log
|
||||||
|
@ -63,7 +63,6 @@ public class NetworkMessage
|
|||||||
public short msgType;
|
public short msgType;
|
||||||
public NetworkConnection conn;
|
public NetworkConnection conn;
|
||||||
public NetworkReader reader;
|
public NetworkReader reader;
|
||||||
public int channelId;
|
|
||||||
|
|
||||||
public static string Dump(byte[] payload, int sz)
|
public static string Dump(byte[] payload, int sz)
|
||||||
{
|
{
|
||||||
@ -94,28 +93,6 @@ public enum Version
|
|||||||
Current = 1
|
Current = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Channels
|
|
||||||
{
|
|
||||||
public const int DefaultReliable = 0;
|
|
||||||
public const int DefaultUnreliable = 1;
|
|
||||||
|
|
||||||
// moved IsSequenced etc. functions here because it's better than in NetworkConnection
|
|
||||||
public static bool IsSequencedQoS(QosType qos)
|
|
||||||
{
|
|
||||||
return (qos == QosType.ReliableSequenced || qos == QosType.UnreliableSequenced);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool IsReliableQoS(QosType qos)
|
|
||||||
{
|
|
||||||
return (qos == QosType.Reliable || qos == QosType.ReliableFragmented || qos == QosType.ReliableSequenced || qos == QosType.ReliableStateUpdate);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool IsUnreliableQoS(QosType qos)
|
|
||||||
{
|
|
||||||
return (qos == QosType.Unreliable || qos == QosType.UnreliableFragmented || qos == QosType.UnreliableSequenced || qos == QosType.StateUpdate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// network protocol all in one place, instead of constructing headers in all kinds of different places
|
// network protocol all in one place, instead of constructing headers in all kinds of different places
|
||||||
//
|
//
|
||||||
// MsgType (1-n bytes)
|
// MsgType (1-n bytes)
|
||||||
|
@ -27,7 +27,6 @@ class NetworkBehaviourProcessor
|
|||||||
List<MethodDefinition> m_TargetRpcCallFuncs = new List<MethodDefinition>();
|
List<MethodDefinition> m_TargetRpcCallFuncs = new List<MethodDefinition>();
|
||||||
|
|
||||||
const int k_SyncVarLimit = 64; // ulong = 64 bytes
|
const int k_SyncVarLimit = 64; // ulong = 64 bytes
|
||||||
int m_QosChannel;
|
|
||||||
|
|
||||||
TypeDefinition m_td;
|
TypeDefinition m_td;
|
||||||
int m_NetIdFieldCounter;
|
int m_NetIdFieldCounter;
|
||||||
@ -527,7 +526,7 @@ void GenerateSerialization()
|
|||||||
|
|
||||||
if (m_SyncVars.Count == 0)
|
if (m_SyncVars.Count == 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
// generate: return dirtyLocal
|
// generate: return dirtyLocal
|
||||||
serWorker.Append(serWorker.Create(OpCodes.Ldloc_0));
|
serWorker.Append(serWorker.Create(OpCodes.Ldloc_0));
|
||||||
serWorker.Append(serWorker.Create(OpCodes.Ret));
|
serWorker.Append(serWorker.Create(OpCodes.Ret));
|
||||||
@ -578,7 +577,7 @@ void GenerateSerialization()
|
|||||||
// generate a writer call for any dirty variable in this class
|
// generate a writer call for any dirty variable in this class
|
||||||
|
|
||||||
// start at number of syncvars in parent
|
// start at number of syncvars in parent
|
||||||
int dirtyBit = Weaver.GetSyncVarStart(m_td.BaseType.FullName);
|
int dirtyBit = Weaver.GetSyncVarStart(m_td.BaseType.FullName);
|
||||||
foreach (FieldDefinition syncVar in m_SyncVars)
|
foreach (FieldDefinition syncVar in m_SyncVars)
|
||||||
{
|
{
|
||||||
Instruction varLabel = serWorker.Create(OpCodes.Nop);
|
Instruction varLabel = serWorker.Create(OpCodes.Nop);
|
||||||
@ -594,7 +593,7 @@ void GenerateSerialization()
|
|||||||
serWorker.Append(serWorker.Create(OpCodes.Ldarg_1)); // writer
|
serWorker.Append(serWorker.Create(OpCodes.Ldarg_1)); // writer
|
||||||
serWorker.Append(serWorker.Create(OpCodes.Ldarg_0)); // base
|
serWorker.Append(serWorker.Create(OpCodes.Ldarg_0)); // base
|
||||||
serWorker.Append(serWorker.Create(OpCodes.Ldfld, syncVar));
|
serWorker.Append(serWorker.Create(OpCodes.Ldfld, syncVar));
|
||||||
|
|
||||||
MethodReference writeFunc = Weaver.GetWriteFunc(syncVar.FieldType);
|
MethodReference writeFunc = Weaver.GetWriteFunc(syncVar.FieldType);
|
||||||
if (writeFunc != null)
|
if (writeFunc != null)
|
||||||
{
|
{
|
||||||
@ -629,27 +628,6 @@ void GenerateSerialization()
|
|||||||
m_td.Methods.Add(serialize);
|
m_td.Methods.Add(serialize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int GetChannelId(FieldDefinition field)
|
|
||||||
{
|
|
||||||
int channel = 0;
|
|
||||||
foreach (var ca in field.CustomAttributes)
|
|
||||||
{
|
|
||||||
if (ca.AttributeType.FullName == Weaver.SyncVarType.FullName)
|
|
||||||
{
|
|
||||||
foreach (CustomAttributeNamedArgument customField in ca.Fields)
|
|
||||||
{
|
|
||||||
if (customField.Name == "channel")
|
|
||||||
{
|
|
||||||
channel = (int)customField.Argument.Value;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
// returns false for error, not for no-hook-exists
|
// returns false for error, not for no-hook-exists
|
||||||
bool CheckForHookFunction(FieldDefinition syncVar, out MethodDefinition foundMethod)
|
bool CheckForHookFunction(FieldDefinition syncVar, out MethodDefinition foundMethod)
|
||||||
{
|
{
|
||||||
@ -694,20 +672,6 @@ bool CheckForHookFunction(FieldDefinition syncVar, out MethodDefinition foundMet
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenerateNetworkChannelSetting(int channel)
|
|
||||||
{
|
|
||||||
MethodDefinition meth = new MethodDefinition("GetNetworkChannel", MethodAttributes.Public |
|
|
||||||
MethodAttributes.Virtual |
|
|
||||||
MethodAttributes.HideBySig,
|
|
||||||
Weaver.int32Type);
|
|
||||||
|
|
||||||
ILProcessor worker = meth.Body.GetILProcessor();
|
|
||||||
|
|
||||||
worker.Append(worker.Create(OpCodes.Ldc_I4, channel));
|
|
||||||
worker.Append(worker.Create(OpCodes.Ret));
|
|
||||||
m_td.Methods.Add(meth);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GenerateNetworkIntervalSetting(float interval)
|
void GenerateNetworkIntervalSetting(float interval)
|
||||||
{
|
{
|
||||||
MethodDefinition meth = new MethodDefinition("GetNetworkSendInterval", MethodAttributes.Public |
|
MethodDefinition meth = new MethodDefinition("GetNetworkSendInterval", MethodAttributes.Public |
|
||||||
@ -732,22 +696,6 @@ void GenerateNetworkSettings()
|
|||||||
// generate virtual functions
|
// generate virtual functions
|
||||||
foreach (var field in ca.Fields)
|
foreach (var field in ca.Fields)
|
||||||
{
|
{
|
||||||
if (field.Name == "channel")
|
|
||||||
{
|
|
||||||
// 0 is Channels.DefaultChannel
|
|
||||||
if ((int)field.Argument.Value == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (HasMethod("GetNetworkChannel"))
|
|
||||||
{
|
|
||||||
Log.Error(
|
|
||||||
"GetNetworkChannel, is already implemented, please make sure you either use NetworkSettings or GetNetworkChannel");
|
|
||||||
Weaver.fail = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_QosChannel = (int)field.Argument.Value;
|
|
||||||
GenerateNetworkChannelSetting(m_QosChannel);
|
|
||||||
}
|
|
||||||
if (field.Name == "sendInterval")
|
if (field.Name == "sendInterval")
|
||||||
{
|
{
|
||||||
const float stdValue = 0.1f;
|
const float stdValue = 0.1f;
|
||||||
@ -1102,7 +1050,7 @@ public void CallCmdThrust(float thrusting, int spin)
|
|||||||
NetworkWriter networkWriter = new NetworkWriter();
|
NetworkWriter networkWriter = new NetworkWriter();
|
||||||
networkWriter.Write(thrusting);
|
networkWriter.Write(thrusting);
|
||||||
networkWriter.WritePackedUInt32((uint)spin);
|
networkWriter.WritePackedUInt32((uint)spin);
|
||||||
base.SendCommandInternal(ShipControl.kCmdCmdThrust, networkWriter, channelId, cmdName);
|
base.SendCommandInternal(ShipControl.kCmdCmdThrust, networkWriter, cmdName);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
MethodDefinition ProcessCommandCall(MethodDefinition md, CustomAttribute ca)
|
MethodDefinition ProcessCommandCall(MethodDefinition md, CustomAttribute ca)
|
||||||
@ -1131,7 +1079,6 @@ MethodDefinition ProcessCommandCall(MethodDefinition md, CustomAttribute ca)
|
|||||||
WriteClientActiveCheck(cmdWorker, md.Name, label, "Command function");
|
WriteClientActiveCheck(cmdWorker, md.Name, label, "Command function");
|
||||||
|
|
||||||
// local client check
|
// local client check
|
||||||
|
|
||||||
Instruction localClientLabel = cmdWorker.Create(OpCodes.Nop);
|
Instruction localClientLabel = cmdWorker.Create(OpCodes.Nop);
|
||||||
cmdWorker.Append(cmdWorker.Create(OpCodes.Ldarg_0));
|
cmdWorker.Append(cmdWorker.Create(OpCodes.Ldarg_0));
|
||||||
cmdWorker.Append(cmdWorker.Create(OpCodes.Call, Weaver.UBehaviourIsServer));
|
cmdWorker.Append(cmdWorker.Create(OpCodes.Call, Weaver.UBehaviourIsServer));
|
||||||
@ -1160,16 +1107,6 @@ MethodDefinition ProcessCommandCall(MethodDefinition md, CustomAttribute ca)
|
|||||||
if (!WriteArguments(cmdWorker, md, "Command", false))
|
if (!WriteArguments(cmdWorker, md, "Command", false))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// find channel for Command
|
|
||||||
int channel = 0;
|
|
||||||
foreach (var field in ca.Fields)
|
|
||||||
{
|
|
||||||
if (field.Name == "channel")
|
|
||||||
{
|
|
||||||
channel = (int)field.Argument.Value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var cmdName = md.Name;
|
var cmdName = md.Name;
|
||||||
int index = cmdName.IndexOf(k_CmdPrefix);
|
int index = cmdName.IndexOf(k_CmdPrefix);
|
||||||
if (index > -1)
|
if (index > -1)
|
||||||
@ -1181,7 +1118,6 @@ MethodDefinition ProcessCommandCall(MethodDefinition md, CustomAttribute ca)
|
|||||||
cmdWorker.Append(cmdWorker.Create(OpCodes.Ldarg_0)); // load 'base.' to call the SendCommand function with
|
cmdWorker.Append(cmdWorker.Create(OpCodes.Ldarg_0)); // load 'base.' to call the SendCommand function with
|
||||||
cmdWorker.Append(cmdWorker.Create(OpCodes.Ldsfld, cmdConstant)); // cmdHash
|
cmdWorker.Append(cmdWorker.Create(OpCodes.Ldsfld, cmdConstant)); // cmdHash
|
||||||
cmdWorker.Append(cmdWorker.Create(OpCodes.Ldloc_0)); // writer
|
cmdWorker.Append(cmdWorker.Create(OpCodes.Ldloc_0)); // writer
|
||||||
cmdWorker.Append(cmdWorker.Create(OpCodes.Ldc_I4, channel)); // QoS transport channel (reliable/unreliable)
|
|
||||||
cmdWorker.Append(cmdWorker.Create(OpCodes.Ldstr, cmdName));
|
cmdWorker.Append(cmdWorker.Create(OpCodes.Ldstr, cmdName));
|
||||||
cmdWorker.Append(cmdWorker.Create(OpCodes.Call, Weaver.sendCommandInternal));
|
cmdWorker.Append(cmdWorker.Create(OpCodes.Call, Weaver.sendCommandInternal));
|
||||||
|
|
||||||
@ -1259,7 +1195,7 @@ public void CallTargetTest (NetworkConnection conn, int param)
|
|||||||
} else {
|
} else {
|
||||||
NetworkWriter writer = new NetworkWriter ();
|
NetworkWriter writer = new NetworkWriter ();
|
||||||
writer.WritePackedUInt32 ((uint)param);
|
writer.WritePackedUInt32 ((uint)param);
|
||||||
base.SendTargetRPCInternal (conn, Player.kTargetRpcTargetTest, val, 0, "TargetTest");
|
base.SendTargetRPCInternal (conn, Player.kTargetRpcTargetTest, val, "TargetTest");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
@ -1306,16 +1242,6 @@ MethodDefinition ProcessTargetRpcCall(MethodDefinition md, CustomAttribute ca)
|
|||||||
if (!WriteArguments(rpcWorker, md, "TargetRPC", true))
|
if (!WriteArguments(rpcWorker, md, "TargetRPC", true))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// find channel for TargetRpc
|
|
||||||
int channel = 0;
|
|
||||||
foreach (var field in ca.Fields)
|
|
||||||
{
|
|
||||||
if (field.Name == "channel")
|
|
||||||
{
|
|
||||||
channel = (int)field.Argument.Value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var rpcName = md.Name;
|
var rpcName = md.Name;
|
||||||
int index = rpcName.IndexOf(k_TargetRpcPrefix);
|
int index = rpcName.IndexOf(k_TargetRpcPrefix);
|
||||||
if (index > -1)
|
if (index > -1)
|
||||||
@ -1328,7 +1254,6 @@ MethodDefinition ProcessTargetRpcCall(MethodDefinition md, CustomAttribute ca)
|
|||||||
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldarg_1)); // connection
|
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldarg_1)); // connection
|
||||||
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldsfld, rpcConstant)); // rpcHash
|
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldsfld, rpcConstant)); // rpcHash
|
||||||
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldloc_0)); // writer
|
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldloc_0)); // writer
|
||||||
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldc_I4, channel)); // QoS transport channel (reliable/unreliable)
|
|
||||||
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldstr, rpcName));
|
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldstr, rpcName));
|
||||||
rpcWorker.Append(rpcWorker.Create(OpCodes.Callvirt, Weaver.sendTargetRpcInternal));
|
rpcWorker.Append(rpcWorker.Create(OpCodes.Callvirt, Weaver.sendTargetRpcInternal));
|
||||||
|
|
||||||
@ -1380,16 +1305,6 @@ MethodDefinition ProcessRpcCall(MethodDefinition md, CustomAttribute ca)
|
|||||||
if (!WriteArguments(rpcWorker, md, "RPC", false))
|
if (!WriteArguments(rpcWorker, md, "RPC", false))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// find channel for Rpc
|
|
||||||
int channel = 0;
|
|
||||||
foreach (var field in ca.Fields)
|
|
||||||
{
|
|
||||||
if (field.Name == "channel")
|
|
||||||
{
|
|
||||||
channel = (int)field.Argument.Value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var rpcName = md.Name;
|
var rpcName = md.Name;
|
||||||
int index = rpcName.IndexOf(k_RpcPrefix);
|
int index = rpcName.IndexOf(k_RpcPrefix);
|
||||||
if (index > -1)
|
if (index > -1)
|
||||||
@ -1401,7 +1316,6 @@ MethodDefinition ProcessRpcCall(MethodDefinition md, CustomAttribute ca)
|
|||||||
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldarg_0)); // this
|
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldarg_0)); // this
|
||||||
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldsfld, rpcConstant)); // rpcHash
|
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldsfld, rpcConstant)); // rpcHash
|
||||||
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldloc_0)); // writer
|
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldloc_0)); // writer
|
||||||
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldc_I4, channel)); // QoS transport channel (reliable/unreliable)
|
|
||||||
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldstr, rpcName));
|
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldstr, rpcName));
|
||||||
rpcWorker.Append(rpcWorker.Create(OpCodes.Callvirt, Weaver.sendRpcInternal));
|
rpcWorker.Append(rpcWorker.Create(OpCodes.Callvirt, Weaver.sendRpcInternal));
|
||||||
|
|
||||||
@ -1807,21 +1721,10 @@ MethodDefinition ProcessEventCall(EventDefinition ed, CustomAttribute ca)
|
|||||||
if (!WriteArguments(evtWorker, invoke.Resolve(), "SyncEvent", false))
|
if (!WriteArguments(evtWorker, invoke.Resolve(), "SyncEvent", false))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// find channel for ClientRpc
|
|
||||||
int channel = 0;
|
|
||||||
foreach (var field in ca.Fields)
|
|
||||||
{
|
|
||||||
if (field.Name == "channel")
|
|
||||||
{
|
|
||||||
channel = (int)field.Argument.Value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// invoke interal send and return
|
// invoke interal send and return
|
||||||
evtWorker.Append(evtWorker.Create(OpCodes.Ldarg_0)); // this
|
evtWorker.Append(evtWorker.Create(OpCodes.Ldarg_0)); // this
|
||||||
evtWorker.Append(evtWorker.Create(OpCodes.Ldsfld, evtConstant)); // eventHash
|
evtWorker.Append(evtWorker.Create(OpCodes.Ldsfld, evtConstant)); // eventHash
|
||||||
evtWorker.Append(evtWorker.Create(OpCodes.Ldloc_0)); // writer
|
evtWorker.Append(evtWorker.Create(OpCodes.Ldloc_0)); // writer
|
||||||
evtWorker.Append(evtWorker.Create(OpCodes.Ldc_I4, channel)); // QoS transport channel (reliable/unreliable)
|
|
||||||
evtWorker.Append(evtWorker.Create(OpCodes.Ldstr, ed.Name));
|
evtWorker.Append(evtWorker.Create(OpCodes.Ldstr, ed.Name));
|
||||||
evtWorker.Append(evtWorker.Create(OpCodes.Call, Weaver.sendEventInternal));
|
evtWorker.Append(evtWorker.Create(OpCodes.Call, Weaver.sendEventInternal));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user