public ReplicatedObject AddPreExistingInstance(ObjectRole role, ConnectionId hostConnectionId, GameObject instance, Guid globalId) { var objectId = RequestObjectId(); return(_store.ReplicateExistingInstance(role, hostConnectionId, instance, objectId, globalId)); }
protected AbstractObjectDefinition(SerializationInfo info, StreamingContext context) { constructorArgumentValues = (ConstructorArgumentValues)info.GetValue("constructorArgumentValues", typeof(ConstructorArgumentValues)); propertyValues = (MutablePropertyValues)info.GetValue("propertyValues", typeof(MutablePropertyValues)); eventHandlerValues = (EventValues)info.GetValue("eventHandlerValues", typeof(EventValues)); methodOverrides = (MethodOverrides)info.GetValue("methodOverrides", typeof(MethodOverrides)); resourceDescription = info.GetString("resourceDescription"); isSingleton = info.GetBoolean("isSingleton"); isPrototype = info.GetBoolean("isPrototype"); isLazyInit = info.GetBoolean("isLazyInit"); isAbstract = info.GetBoolean("isAbstract"); scope = info.GetString("scope"); role = (ObjectRole)info.GetValue("role", typeof(ObjectRole)); var objectTypeName = info.GetString("objectTypeName"); objectType = objectTypeName != null?Type.GetType(objectTypeName) : null; autowireMode = (AutoWiringMode)info.GetValue("autowireMode", typeof(AutoWiringMode)); dependencyCheck = (DependencyCheckingMode)info.GetValue("dependencyCheck", typeof(DependencyCheckingMode)); dependsOn = (IList <string>)info.GetValue("dependsOn", typeof(IList <string>)); autowireCandidate = info.GetBoolean("autowireCandidate"); primary = info.GetBoolean("primary"); qualifiers = (IDictionary <string, AutowireCandidateQualifier>)info.GetValue("qualifiers", typeof(IDictionary <string, AutowireCandidateQualifier>)); initMethodName = info.GetString("initMethodName"); destroyMethodName = info.GetString("destroyMethodName"); factoryMethodName = info.GetString("factoryMethodName"); factoryObjectName = info.GetString("factoryObjectName"); }
public Sender(ConnectionId connectionId, ObjectRole role, SequenceNumber sequenceNumber, float latency) { ConnectionId = connectionId; Role = role; SequenceNumber = sequenceNumber; Latency = latency; }
public static void ApplyTo(this ObjectRole objectRole, GameObject instance) { if (!instance.IsDestroyed()) { ComponentCache.Clear(); // TODO Optimize this by caching the INetworkBehaviors in the ReplicatedObject instance.GetComponentsInChildren(ComponentCache); for (int i = 0; i < ComponentCache.Count; i++) { var component = ComponentCache[i]; if (component is INetworkBehavior) { var networkBehavior = component as INetworkBehavior; // TODO Check if the role was already disabled/enabled if (networkBehavior.Role.Suits(objectRole)) { networkBehavior.OnRoleEnabled(objectRole); component.enabled = true; } else { networkBehavior.OnRoleDisabled(objectRole); component.enabled = false; } } } } }
public ReplicatedObject AddReplicatedInstance(ObjectType type, ObjectRole role, ObjectId objectId, ConnectionId connectionId) { var objectPool = _objectPools[type]; var replicatedObject = objectPool.Take(); AddReplicatedInstance(replicatedObject, type, role, objectId, connectionId); return(replicatedObject.Instance); }
public void Deserialize(NetBuffer reader) { ObjectType = reader.ReadObjectType(); ObjectId = reader.ReadObjectId(); ObjectRole = (ObjectRole)reader.ReadByte(); var additionalDataSize = reader.ReadVariableUInt32(); reader.ReadInto(AdditionalData, (int)additionalDataSize); }
public ReplicatedObject CreateReplicatedInstance( ObjectType type, ObjectRole role, ConnectionId connectionId) { var objectId = RequestObjectId(); return(_store.AddReplicatedInstance(type, role, objectId, connectionId)); }
public ReplicatedObject ReplicateExistingInstance(ObjectRole role, ConnectionId hostConnectionId, GameObject instance, ObjectId objectId, Guid globalId) { var replicatedObject = _replicationDecorator(instance, this); AddReplicatedInstance(new UnmanagedObject <ReplicatedObject>(replicatedObject), null, role, objectId, hostConnectionId); replicatedObject.IsPreExisting = true; replicatedObject.GlobalObjectId.CopyFrom(globalId); return(replicatedObject); }
public void Send <TMessage>(INetworkMessage <TMessage> message, ObjectRole recipient) where TMessage : IObjectMessage { if ((recipient & ObjectRole.Owner) != 0 || (recipient & ObjectRole.Authority) != 0) { var sequenceNumber = _sequenceNumberCounter; _messageRouter.Dispatch(new Sender(ConnectionId.NoConnection, ObjectRoles.Everyone, sequenceNumber, 0), message); _sequenceNumberCounter = sequenceNumber.Increment(); } message.Dispose(); }
public void Send <T>(NetworkMessage <T> message, ObjectRole recipient) where T : IObjectMessage { var activeConnections = _groupRouter.GetActiveConnections(_group); _receiverConnectionIds.Clear(); if ((recipient & ObjectRole.Authority) != 0 && (recipient & ObjectRole.Owner) != 0) { if (_object.AuthorityConnectionId == _object.OwnerConnectionId) { _receiverConnectionIds.Add(_object.AuthorityConnectionId); } else { _receiverConnectionIds.Add(_object.AuthorityConnectionId); _receiverConnectionIds.Add(_object.OwnerConnectionId); } } else if ((recipient & ObjectRole.Authority) != 0) { _receiverConnectionIds.Add(_object.AuthorityConnectionId); } else if ((recipient & ObjectRole.Owner) != 0) { _receiverConnectionIds.Add(_object.OwnerConnectionId); } if ((recipient & ObjectRole.Others) != 0) { for (int i = 0; i < activeConnections.Count; i++) { var connectionId = activeConnections[i]; if (connectionId != _object.OwnerConnectionId && connectionId != _object.AuthorityConnectionId) { _receiverConnectionIds.Add(connectionId); } } } var networkMessage = CreateMulticastMessage(message, usageCount: _receiverConnectionIds.Count); for (int i = 0; i < _receiverConnectionIds.Count; i++) { var connectionId = _receiverConnectionIds[i]; var sendToSelf = connectionId == ConnectionId.NoConnection; if (sendToSelf) { _object.MessageHandler.Dispatch(message.MessageType, message.Content, ConnectionId.NoConnection, _object.Role); networkMessage.Dispose(); } else { _sender.Send(connectionId, networkMessage); } } }
public static Maybe <ReplicatedObject> FindObject(this IReplicatedObjectDatabase db, ObjectType type, ObjectRole role = ObjectRoles.Everyone) { ObjectCache.Clear(); db.FindObjects(type, ObjectCache, role); if (ObjectCache.Count > 0) { return(Maybe.Just(ObjectCache[0])); } return(Maybe <ReplicatedObject> .Nothing); }
/// <summary> /// Check whether a role is suited for another. /// /// The ObjectRole.Others is a bit different. If the role /// explicity states that it only supports the Others role then the other role /// doesn't suit the Authority and Owner role unless it is explicity added like: /// ObjectRole.Others | ObjectRole.Authority | ObjectRole.Owner. /// </summary> /// <param name="role"></param> /// <param name="other"></param> /// <returns></returns> public static bool Suits(this ObjectRole role, ObjectRole other) { if ((role & ObjectRole.Others) != 0) { return (((other & ObjectRole.Owner) == 0 || (role & ObjectRole.Owner) != 0) && ((other & ObjectRole.Authority) == 0 || (role & ObjectRole.Authority) != 0) && other != ObjectRole.Nobody); } return((role & other) != 0); }
public void FindObjects(ObjectType type, IList <ReplicatedObject> results, ObjectRole role = ObjectRoles.Everyone) { for (int i = 0; i < _objectIds.Count; i++) { var objectId = _objectIds[i]; var instance = _instances[objectId.Value].Instance; if (instance.Type == type && (instance.Role & role) != 0) { results.Add(instance); } } }
public ReplicatedObject FindObject(ObjectType type, ObjectRole role = ObjectRoles.Everyone) { for (int i = 0; i < _objectIds.Count; i++) { var objectId = _objectIds[i]; var instance = _instances[objectId.Value].Instance; if (instance.Type == type && (instance.Role & role) != 0) { return(instance); } } return(null); }
public static void ApplyRoleTo(this ObjectRole objectRole, GameObject instance) { ComponentCache.Clear(); instance.GetComponentsInChildren(ComponentCache); for (int componentIndex = 0; componentIndex < ComponentCache.Count; componentIndex++) { var component = ComponentCache[componentIndex]; var networkRole = GetNetworkRole(component.GetType()); if (networkRole != null) { component.enabled = networkRole.IsAllowed(objectRole); } } }
public NetworkRole(ObjectRole roles) { _includedObjectRoles = roles; // Authority is mostly mutually exlusive with the Others role so // it is excluded unless it is explicitely included. if (roles.IsOther() && !roles.IsAuthority()) { _excludedObjectRoles = ObjectRole.Authority; } else { _excludedObjectRoles = ObjectRole.Nobody; } }
public ReplicatedObject AddExistingInstance(ObjectRole role, ConnectionId hostConnectionId, GameObject instance, ObjectId objectId, Guid globalId) { IPooledObject <ReplicatedObject> replicatedObject; if (!_instances.TryGetValue(objectId, out replicatedObject)) { replicatedObject = new UnmanagedObject <ReplicatedObject>(_replicationDecorator(instance, this)); Instantiate(replicatedObject, null, role, objectId, hostConnectionId); replicatedObject.Instance.IsPreExisting = true; replicatedObject.Instance.GlobalObjectId.CopyFrom(globalId); } return(replicatedObject.Instance); }
public ReplicatedObject Instantiate(ObjectType type, ObjectRole role, ObjectId objectId, ConnectionId connectionId, Vector3?position, Quaternion?rotation) { IPooledObject <ReplicatedObject> replicatedObject; if (!_instances.TryGetValue(objectId, out replicatedObject)) { var objectPool = _objectPools[type]; replicatedObject = objectPool.Take(); Instantiate(replicatedObject, type, role, objectId, connectionId); replicatedObject.Instance.GameObject.transform.position = position ?? Vector3.zero; replicatedObject.Instance.GameObject.transform.rotation = rotation ?? Quaternion.identity; } return(replicatedObject.Instance); }
public static void IntoList(this ObjectRole role, IList <ObjectRole> roles) { roles.Clear(); if (role.IsOwner()) { roles.Add(ObjectRole.Owner); } if (role.IsAuthority()) { roles.Add(ObjectRole.Authority); } if (role.IsOther()) { roles.Add(ObjectRole.Others); } }
public void Send <TMessage>(INetworkMessage <TMessage> message, ObjectRole recipient) where TMessage : IObjectMessage { var activeConnections = _groupRouter.GetActiveConnections(_group); _receiverConnectionIds.Clear(); if ((recipient & ObjectRole.Authority) != 0 && (recipient & ObjectRole.Owner) != 0) { if (_object.AuthorityConnectionId == _object.OwnerConnectionId) { _receiverConnectionIds.Add(_object.AuthorityConnectionId); } else { _receiverConnectionIds.Add(_object.AuthorityConnectionId); _receiverConnectionIds.Add(_object.OwnerConnectionId); } } else if ((recipient & ObjectRole.Authority) != 0) { _receiverConnectionIds.Add(_object.AuthorityConnectionId); } else if ((recipient & ObjectRole.Owner) != 0) { _receiverConnectionIds.Add(_object.OwnerConnectionId); } if ((recipient & ObjectRole.Others) != 0) { for (int i = 0; i < activeConnections.Count; i++) { var connectionId = activeConnections[i]; if (connectionId != _object.OwnerConnectionId && connectionId != _object.AuthorityConnectionId) { _receiverConnectionIds.Add(connectionId); } } } var networkMessage = CreateMulticastMessage(message, usageCount: _receiverConnectionIds.Count); for (int i = 0; i < _receiverConnectionIds.Count; i++) { var connectionId = _receiverConnectionIds[i]; //Debug.Log("sending message of type " + message.Content.GetType() + " to " + connectionId); _sender.Send(connectionId, networkMessage); } }
public void OnRoleDisabled(ObjectRole role) { _role = ObjectRole.Nobody; }
public void OnRoleEnabled(ObjectRole role) { _role = role; }
public IList <ReplicatedObject> FindObjects(ObjectType type, IList <ReplicatedObject> results, ObjectRole role = ObjectRoles.Everyone) { var objects = _instances.Values.ToListOptimized(); for (int i = 0; i < objects.Count; i++) { var replicatedObject = objects[i]; if (replicatedObject.Instance.Type == type && (replicatedObject.Instance.Role & role) != 0) { results.Add(replicatedObject.Instance); } } return(results); }
// TODO Add ObjectType: PreExisting private void Instantiate(IPooledObject <ReplicatedObject> pooledObject, ObjectType?type, ObjectRole role, ObjectId objectId, ConnectionId connectionId) { var @object = pooledObject.Instance; @object.GameObjectNetworkInfo.ObjectType = type.HasValue ? type.Value : new ObjectType(0); @object.GameObjectNetworkInfo.ObjectId = objectId; @object.GameObjectNetworkInfo.Role = role; @object.Type = type; @object.Role = role; @object.Id = objectId; @object.IsPreExisting = false; @object.GlobalObjectId.CopyFrom(Guid.Empty); @object.OwnerConnectionId = role.IsOwner() ? ConnectionId.Self : connectionId; @object.AuthorityConnectionId = role.IsAuthority() ? ConnectionId.Self : connectionId; role.ApplyTo(@object.GameObject); if (!_instances.ContainsKey(@object.Id)) { _instances[@object.Id] = pooledObject; } else { throw new Exception("Cannot replicate instance of " + type + " with " + objectId + " cause the object id is already assigned"); } }
public void OnRoleDisabled(ObjectRole role) { }
public void OnRoleEnabled(ObjectRole role) { }
public void Deserialize(NetBuffer reader) { GlobalObjectId.ReadFrom(reader); NetworkObjectId = reader.ReadObjectId(); ObjectRole = (ObjectRole)reader.ReadByte(); }
public MessageHandler(ObjectRole allowedSenders = ObjectRoles.Everyone) { AllowedSenders = allowedSenders; }
public static IList <ReplicatedObject> FindObjects(this IReplicatedObjectDatabase db, ObjectType type, ObjectRole role = ObjectRoles.Everyone) { ObjectCache.Clear(); return(db.FindObjects(type, ObjectCache, role)); }
public ObjectMessageMetadata(ObjectRole senderRole, float latency) { SenderRole = senderRole; Latency = latency; }