public static void PrintState(NetworkBehaviour script) { string print = "NetworkServer.active " + NetworkServer.active + ", " + "isServer " + script.isServer + ", " + "isClient " + script.isClient + ", " + "isLocalPlayer " + script.isLocalPlayer; Debug.Log(print); }
public override void Fire(NetworkBehaviour parent) { if (FireTime > Time.time) return; FireTime = Time.time + FireRate; FlashDisableTime = Time.time + GunFlashRate; firePos++; if (firePos >= HardPods.Length) firePos = 0; Transform fire_position = HardPods[firePos].transform; HardPods[firePos].light.enabled = true; GameObject bolt = MonoBehaviour.Instantiate(HardPods[firePos].Bolt, fire_position.position, fire_position.rotation) as GameObject; Bolt bolt_manager = bolt.GetComponent<Bolt> (); bolt_manager.rotation = fire_position.rotation; //NetworkServer.Spawn (bolt); }
// weaver generates this from [Command] // but for tests we need to add it manually public static void CommandGenerated(NetworkBehaviour comp, NetworkReader reader, NetworkConnection senderConnection) { ++((CommandTestNetworkBehaviour)comp).called; ((CommandTestNetworkBehaviour)comp).senderConnectionInCall = senderConnection; }
// weaver generates this from [SyncEvent] // but for tests we need to add it manually public static void SyncEventGenerated(NetworkBehaviour comp, NetworkReader reader) { ++((SyncEventTestNetworkBehaviour)comp).called; }
protected PlayerState(NetworkBehaviour thisObj) { thisObject = thisObj; player = thisObject.gameObject; }
// Token: 0x0600209C RID: 8348 RVA: 0x0008D2E8 File Offset: 0x0008B4E8 static NetworkedViewAngles() { NetworkBehaviour.RegisterCommandDelegate(typeof(NetworkedViewAngles), NetworkedViewAngles.kCmdCmdUpdateViewAngles, new NetworkBehaviour.CmdDelegate(NetworkedViewAngles.InvokeCmdCmdUpdateViewAngles)); NetworkCRC.RegisterBehaviour("NetworkedViewAngles", 0); }
public RemoteCallCollection(NetworkBehaviour behaviour) { remoteCalls = new RemoteCall[behaviour.GetRpcCount()]; }
public virtual void Init(NetworkBehaviour parent) { }
// weaver generates this from [Rpc] // but for tests we need to add it manually public static void RpcGenerated(NetworkBehaviour comp, NetworkReader reader) { ++((RpcTestNetworkBehaviour)comp).called; }
static Door() { NetworkBehaviour.RegisterRpcDelegate(typeof(Door), Door.kRpcRpcDoSound, new NetworkBehaviour.CmdDelegate(Door.InvokeRpcRpcDoSound)); NetworkCRC.RegisterBehaviour("Door", 0); }
public void AddSpawn(NetworkBehaviour spawnBehav, NetworkBehaviour playerBehav) { dictSpawnPlayer[spawnBehav.netId] = playerBehav.netId; }
private bool GetInvokeComponent(int cmdHash, System.Type invokeClass, out NetworkBehaviour invokeComponent) { NetworkBehaviour behaviour = null; for (int i = 0; i < this.m_NetworkBehaviours.Length; i++) { NetworkBehaviour behaviour2 = this.m_NetworkBehaviours[i]; if ((behaviour2.GetType() == invokeClass) || behaviour2.GetType().IsSubclassOf(invokeClass)) { behaviour = behaviour2; break; } } if (behaviour == null) { string cmdHashHandlerName = NetworkBehaviour.GetCmdHashHandlerName(cmdHash); if (LogFilter.logError) { Debug.LogError(string.Concat(new object[] { "Found no behaviour for incoming [", cmdHashHandlerName, "] on ", base.gameObject, ", the server and client should have the same NetworkBehaviour instances [netId=", this.netId, "]." })); } invokeComponent = null; return false; } invokeComponent = behaviour; return true; }
private bool GetInvokeComponent(int cmdHash, System.Type invokeClass, out NetworkBehaviour invokeComponent) { NetworkBehaviour networkBehaviour1 = (NetworkBehaviour) null; for (int index = 0; index < this.m_NetworkBehaviours.Length; ++index) { NetworkBehaviour networkBehaviour2 = this.m_NetworkBehaviours[index]; if (networkBehaviour2.GetType() == invokeClass || networkBehaviour2.GetType().IsSubclassOf(invokeClass)) { networkBehaviour1 = networkBehaviour2; break; } } if ((UnityEngine.Object) networkBehaviour1 == (UnityEngine.Object) null) { string cmdHashHandlerName = NetworkBehaviour.GetCmdHashHandlerName(cmdHash); if (LogFilter.logError) Debug.LogError((object) ("Found no behaviour for incoming [" + cmdHashHandlerName + "] on " + (object) this.gameObject + ", the server and client should have the same NetworkBehaviour instances [netId=" + (object) this.netId + "].")); invokeComponent = (NetworkBehaviour) null; return false; } invokeComponent = networkBehaviour1; return true; }
public virtual void Update(NetworkBehaviour parent) { }
// Token: 0x06000AFB RID: 2811 RVA: 0x000369DF File Offset: 0x00034BDF static AchievementGranter() { NetworkBehaviour.RegisterRpcDelegate(typeof(AchievementGranter), AchievementGranter.kRpcRpcGrantAchievement, new NetworkBehaviour.CmdDelegate(AchievementGranter.InvokeRpcRpcGrantAchievement)); NetworkCRC.RegisterBehaviour("AchievementGranter", 0); }
/// <inheritdoc /> public void SetNetworkBehaviour(NetworkBehaviour behaviour) { m_NetworkBehaviour = behaviour; }
public static void Delegate2(NetworkBehaviour comp, NetworkReader reader) { }
public override void Init(NetworkBehaviour parent) { FireTime = Time.time; FlashDisableTime = Time.time; firePos = 0; }
static AmmoBox() { NetworkBehaviour.RegisterCommandDelegate(typeof(AmmoBox), AmmoBox.kCmdCmdDrop, new NetworkBehaviour.CmdDelegate(AmmoBox.InvokeCmdCmdDrop)); NetworkCRC.RegisterBehaviour("AmmoBox", 0); }
// Token: 0x0600100E RID: 4110 RVA: 0x00046A10 File Offset: 0x00044C10 static PlayerCharacterMasterController() { NetworkBehaviour.RegisterRpcDelegate(typeof(PlayerCharacterMasterController), PlayerCharacterMasterController.kRpcRpcIncrementRunCount, new NetworkBehaviour.CmdDelegate(PlayerCharacterMasterController.InvokeRpcRpcIncrementRunCount)); NetworkCRC.RegisterBehaviour("PlayerCharacterMasterController", 0); }
// InvokeCmd/Rpc Delegate can all use the same function here // => invoke by index to save bandwidth (2 bytes instead of 4 bytes) internal static bool Invoke(ushort functionIndex, RemoteCallType remoteCallType, NetworkReader reader, NetworkBehaviour component, NetworkConnectionToClient senderConnection = null) { // IMPORTANT: we check if the message's componentIndex component is // actually of the right type. prevents attackers trying // to invoke remote calls on wrong components. if (GetInvoker(functionIndex, remoteCallType, out Invoker invoker) && invoker.componentType.IsInstanceOfType(component)) { // invoke function on this component invoker.function(component, reader, senderConnection); return(true); } return(false); }
internal void Invoke(NetworkReader reader, NetworkBehaviour invokingType, INetworkPlayer senderPlayer = null, int replyId = 0) { function(invokingType, reader, senderPlayer, replyId); }
public override void OnInspectorGUI() { if (!this.m_Initialized) { base.serializedObject.Update(); SerializedProperty property = base.serializedObject.FindProperty("m_Script"); if (property == null) { return; } MonoScript objectReferenceValue = property.objectReferenceValue as MonoScript; this.Init(objectReferenceValue); } EditorGUI.BeginChangeCheck(); base.serializedObject.Update(); SerializedProperty iterator = base.serializedObject.GetIterator(); for (bool flag = true; iterator.NextVisible(flag); flag = false) { bool flag2 = this.m_SyncVarNames.Contains(iterator.name); if (iterator.propertyType == SerializedPropertyType.ObjectReference) { EditorGUILayout.PropertyField(iterator, true, new GUILayoutOption[0]); } else { EditorGUILayout.BeginHorizontal(new GUILayoutOption[0]); EditorGUILayout.PropertyField(iterator, true, new GUILayoutOption[0]); if (flag2) { GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(52f) }; GUILayout.Label("SyncVar", EditorStyles.miniLabel, options); } EditorGUILayout.EndHorizontal(); } } base.serializedObject.ApplyModifiedProperties(); EditorGUI.EndChangeCheck(); int index = 0; foreach (System.Reflection.FieldInfo info in base.serializedObject.targetObject.GetType().GetFields()) { if ((info.FieldType.BaseType != null) && info.FieldType.BaseType.Name.Contains("SyncList")) { this.m_ShowSyncLists[index] = EditorGUILayout.Foldout(this.m_ShowSyncLists[index], "SyncList " + info.Name + " [" + info.FieldType.Name + "]"); if (this.m_ShowSyncLists[index]) { EditorGUI.indentLevel++; IEnumerable enumerable = info.GetValue(base.serializedObject.targetObject) as IEnumerable; if (enumerable != null) { int num3 = 0; IEnumerator enumerator = enumerable.GetEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Current != null) { EditorGUILayout.LabelField("Item:" + num3, enumerator.Current.ToString(), new GUILayoutOption[0]); } num3++; } } EditorGUI.indentLevel--; } index++; } } if (this.m_HasOnSerialize) { NetworkBehaviour target = base.target as NetworkBehaviour; if (target != null) { EditorGUILayout.LabelField(this.m_NetworkChannelLabel, new GUIContent(target.GetNetworkChannel().ToString()), new GUILayoutOption[0]); EditorGUILayout.LabelField(this.m_NetworkSendIntervalLabel, new GUIContent(target.GetNetworkSendInterval().ToString()), new GUILayoutOption[0]); } } }
public ForestState(NetworkBehaviour thisObj) : base(thisObj) { stateName = "ForestLevel"; }
// Token: 0x060020A7 RID: 8359 RVA: 0x0008D4D4 File Offset: 0x0008B6D4 static NetworkLoadout() { NetworkBehaviour.RegisterCommandDelegate(typeof(NetworkLoadout), NetworkLoadout.kCmdCmdSendLoadout, new NetworkBehaviour.CmdDelegate(NetworkLoadout.InvokeCmdCmdSendLoadout)); NetworkCRC.RegisterBehaviour("NetworkLoadout", 0); }
public RiverState(NetworkBehaviour thisObj) : base(thisObj) { stateName = "RiverLevel"; GameData.gamePlayStart = Time.time; }
// Token: 0x06000D0D RID: 3341 RVA: 0x0004094C File Offset: 0x0003EB4C static CharacterMaster() { NetworkBehaviour.RegisterCommandDelegate(typeof(CharacterMaster), CharacterMaster.kCmdCmdRespawn, new NetworkBehaviour.CmdDelegate(CharacterMaster.InvokeCmdCmdRespawn)); NetworkCRC.RegisterBehaviour("CharacterMaster", 0); }
public void CommandMessageCallsCommandTest() { // listen NetworkServer.Listen(1); Assert.That(NetworkServer.connections.Count, Is.EqualTo(0)); // add connection ULocalConnectionToClient connection = new ULocalConnectionToClient(); connection.connectionToServer = new ULocalConnectionToServer(); NetworkServer.AddConnection(connection); // set as authenticated, otherwise removeplayer is rejected connection.isAuthenticated = true; // add an identity with two networkbehaviour components GameObject go = new GameObject(); NetworkIdentity identity = go.AddComponent <NetworkIdentity>(); identity.netId = 42; identity.connectionToClient = connection; // for authority check CommandTestNetworkBehaviour comp0 = go.AddComponent <CommandTestNetworkBehaviour>(); Assert.That(comp0.called, Is.EqualTo(0)); CommandTestNetworkBehaviour comp1 = go.AddComponent <CommandTestNetworkBehaviour>(); Assert.That(comp1.called, Is.EqualTo(0)); connection.identity = identity; // register the command delegate, otherwise it's not found NetworkBehaviour.RegisterCommandDelegate(typeof(CommandTestNetworkBehaviour), nameof(CommandTestNetworkBehaviour.CommandGenerated), CommandTestNetworkBehaviour.CommandGenerated); // identity needs to be in spawned dict, otherwise command handler // won't find it NetworkIdentity.spawned[identity.netId] = identity; // serialize a removeplayer message into an arraysegment CommandMessage message = new CommandMessage { componentIndex = 0, functionHash = NetworkBehaviour.GetMethodHash(typeof(CommandTestNetworkBehaviour), nameof(CommandTestNetworkBehaviour.CommandGenerated)), netId = identity.netId, payload = new ArraySegment <byte>(new byte[0]) }; NetworkWriter writer = new NetworkWriter(); MessagePacker.Pack(message, writer); ArraySegment <byte> segment = writer.ToArraySegment(); // call transport.OnDataReceived with the message // -> calls NetworkServer.OnRemovePlayerMessage // -> destroys conn.identity and sets it to null Transport.activeTransport.OnServerDataReceived.Invoke(0, segment, 0); // was the command called in the first component, not in the second one? Assert.That(comp0.called, Is.EqualTo(1)); Assert.That(comp1.called, Is.EqualTo(0)); // send another command for the second component comp0.called = 0; message.componentIndex = 1; writer = new NetworkWriter(); MessagePacker.Pack(message, writer); segment = writer.ToArraySegment(); Transport.activeTransport.OnServerDataReceived.Invoke(0, segment, 0); // was the command called in the second component, not in the first one? Assert.That(comp0.called, Is.EqualTo(0)); Assert.That(comp1.called, Is.EqualTo(1)); // sending a command without authority should fail // (= if connectionToClient is not what we received the data on) identity.connectionToClient = new ULocalConnectionToClient(); // set wrong authority comp0.called = 0; comp1.called = 0; Transport.activeTransport.OnServerDataReceived.Invoke(0, segment, 0); Assert.That(comp0.called, Is.EqualTo(0)); Assert.That(comp1.called, Is.EqualTo(0)); identity.connectionToClient = connection; // restore authority // sending a component with wrong netId should fail message.netId += 1; // wrong netid writer = new NetworkWriter(); MessagePacker.Pack(message, writer); // need to serialize the message again with wrong netid ArraySegment <byte> segmentWrongNetId = writer.ToArraySegment(); comp0.called = 0; comp1.called = 0; Transport.activeTransport.OnServerDataReceived.Invoke(0, segmentWrongNetId, 0); Assert.That(comp0.called, Is.EqualTo(0)); Assert.That(comp1.called, Is.EqualTo(0)); // clean up NetworkBehaviour.ClearDelegates(); NetworkIdentity.spawned.Clear(); NetworkBehaviour.ClearDelegates(); NetworkServer.Shutdown(); // destroy the test gameobject AFTER server was stopped. // otherwise isServer is true in OnDestroy, which means it would try // to call Destroy(go). but we need to use DestroyImmediate in // Editor GameObject.DestroyImmediate(go); }
static AlphaWarheadController() { NetworkBehaviour.RegisterRpcDelegate(typeof(AlphaWarheadController), AlphaWarheadController.kRpcRpcShake, new NetworkBehaviour.CmdDelegate(AlphaWarheadController.InvokeRpcRpcShake)); NetworkCRC.RegisterBehaviour("AlphaWarheadController", 0); }
// weaver generates this from [Rpc] // but for tests we need to add it manually public static void RpcGenerated(NetworkBehaviour comp, NetworkReader reader, NetworkConnection senderConnection) { ++((RpcTestNetworkBehaviour)comp).called; }
public Test_MessageHandlerClass(NetworkBehaviour _behaviour) : base(_behaviour) { _behaviour.AddMessageHandler(NetworkProtocal.EmptyMessage, OnEmptyMessage); }
// InvokeCmd/Rpc Delegate can all use the same function here internal static bool InvokeHandlerDelegate(int cmdHash, MirrorInvokeType invokeType, NetworkReader reader, NetworkBehaviour invokingType, NetworkConnectionToClient senderConnection = null) { if (GetInvokerForHash(cmdHash, invokeType, out Invoker invoker) && invoker.invokeClass.IsInstanceOfType(invokingType)) { invoker.invokeFunction(invokingType, reader, senderConnection); return(true); } return(false); }
public MessagesHandlerClass(NetworkBehaviour _behaviour) { our_networkBehaviour = _behaviour; }
// weaver generates this from [Command] // but for tests we need to add it manually public static void CommandGenerated(NetworkBehaviour comp, NetworkReader reader) { ++((CommandTestNetworkBehaviour)comp).called; }
static Medkit() { NetworkBehaviour.RegisterCommandDelegate(typeof(Medkit), Medkit.kCmdCmdUseMedkit, new NetworkBehaviour.CmdDelegate(Medkit.InvokeCmdCmdUseMedkit)); NetworkCRC.RegisterBehaviour("Medkit", 0); }
public void SendNetworkBehaviourToServer(NetworkBehaviour value) { onSendNetworkBehaviourCalled?.Invoke(value); }
// Token: 0x06000D81 RID: 3457 RVA: 0x0003CC17 File Offset: 0x0003AE17 static Inventory() { NetworkBehaviour.RegisterRpcDelegate(typeof(Inventory), Inventory.kRpcRpcItemAdded, new NetworkBehaviour.CmdDelegate(Inventory.InvokeRpcRpcItemAdded)); NetworkCRC.RegisterBehaviour("Inventory", 0); }
public override void Update(NetworkBehaviour parent) { disableLighs (); }
public virtual void Fire(NetworkBehaviour parent) { }