Example #1
0
        /// <summary>
        /// Dispatched when a guid is generated.
        /// </summary>
        /// <typeparam name="TPeer">The peer type.</typeparam>
        /// <param name="response"></param>
        /// <param name="peer">The peer.</param>
        protected virtual void OnSessionClaimResponse <TPeer>(ServerSessionClaimResponse response, TPeer peer)
            where TPeer : INetPeer, IResponsePayloadSender
        {
            //TODO: Logging
            //TODO: Should we disconnect them? Should we just prevent them from sending more requests?
            //If the session inquiry failed then we should fail the session claim request.
            if (!response.isSuccessful)
            {
                peer.SendResponse(new ClaimSessionResponsePayload(PlayerSpawnResponseCode.Unknown), DeliveryMethod.ReliableUnordered, true, 0);
                return;
            }

            NetworkEntityGuid guid = NetworkEntityGuidBuilder.New()
                                     .WithId(response.UserId)
                                     .WithType(EntityType.Player)
                                     .Build();

            IEntitySpawnResults details = PlayerEntityFactory.SpawnPlayerEntity(new NetworkPlayerSpawnContext(guid, peer));

            if (details.Result != SpawnResult.Success)
            {
                throw new InvalidOperationException($"Failed to create Entity for {peer}. Failure: {details.Result}");
            }

            //TODO: Clean this up
            Vector3Surrogate pos = details.EntityGameObject.transform.position.ToSurrogate();

            QuaternionSurrogate rot = details.EntityGameObject.transform.rotation.ToSurrogate();

            //Send the response to the player who requested to spawn
            peer.SendResponse(new ClaimSessionResponsePayload(pos, rot, guid), DeliveryMethod.ReliableUnordered, true, 0);
        }
Example #2
0
        public bool TryInteract(NetworkEntityGuid entityInteracting)
        {
            //Send the interaction request for the server to handle.
            SendRequest(new EntityInteractionRequestPayload(guidContainer.NetworkGuid), DeliveryMethod.ReliableOrdered, false, 0);

            return(true);
        }
Example #3
0
        public bool TryInteract([NotNull] NetworkEntityGuid entityInteracting)
        {
            if (entityInteracting == null)
            {
                throw new ArgumentNullException(nameof(entityInteracting));
            }

            //TODO: Distance checking.
            return(TryInteract());
        }
Example #4
0
        /// <summary>
        /// Creates a new <see cref="PlayerMoveRequestPayload"/> payload.
        /// </summary>
        public EntityInteractionRequestPayload(NetworkEntityGuid guidOfEntityToInteractWith)
        {
            if (guidOfEntityToInteractWith == null)
            {
                throw new ArgumentNullException(nameof(guidOfEntityToInteractWith));
            }

            //TODO: Check refs
            NetworkGuid = guidOfEntityToInteractWith;
        }
Example #5
0
        /// <inheritdoc />
        public void Unlock(NetworkEntityGuid entityInteracting)
        {
            if (entityInteracting != null)
            {
                Debug.Log($"Door {nameof(Unlock)} called by Entity: {entityInteracting.EntityId}.");
                Unlock();
            }


            //TODO: Implement entity handling
        }
        protected override void OnIncomingHandlableMessage(IRequestMessage message, PlayerMoveRequestPayload payload, IMessageParameters parameters, InstanceClientSession peer)
        {
            NetworkEntityGuid guid = GuidLookupService.Lookup(peer.PeerDetails.ConnectionID);

            if (guid == null)
            {
                throw new InvalidOperationException($"Couldn't find GUID for Connection ID: {peer.PeerDetails.ConnectionID}.");
            }

            EntityCollection[guid].WorldObject.transform.position = payload.Position.ToVector3();
        }
        public EntityContainer([NotNull] NetworkEntityGuid networkGuid, [NotNull] GameObject worldObject)
        {
            if (networkGuid == null)
            {
                throw new ArgumentNullException(nameof(networkGuid));
            }
            if (worldObject == null)
            {
                throw new ArgumentNullException(nameof(worldObject));
            }

            NetworkGuid = networkGuid;
            WorldObject = worldObject;
        }
Example #8
0
        public NetworkPlayerSpawnContext([NotNull] NetworkEntityGuid guid, [NotNull] INetPeer peer)
        {
            if (guid == null)
            {
                throw new ArgumentNullException(nameof(guid));
            }
            if (peer == null)
            {
                throw new ArgumentNullException(nameof(peer));
            }

            EntityGuid = guid;
            OwnerPeer  = peer;
        }
Example #9
0
        public GameObjectEntitySpawnEventPayload(NetworkEntityGuid entityGuid, Vector3Surrogate position, QuaternionSurrogate rotation,
                                                 Vector3Surrogate scale /*, GameObjectPrefab prefabId*/, byte state)
            : base(entityGuid, position, rotation)
        {
            if (scale == null)
            {
                throw new ArgumentNullException(nameof(scale));
            }
            //if (!Enum.IsDefined(typeof(GameObjectPrefab), prefabId)) throw new InvalidEnumArgumentException(nameof(prefabId), (int) prefabId, typeof(GameObjectPrefab));

            //TODO: Check values/refs
            Scale = scale;
            //PrefabId = prefabId;
            CurrentState = state;
        }
        /// <summary>
        /// Creates a new payload for the <see cref="BoomaPayloadMessageType.EntitySpawnEvent"/> packet.
        /// </summary>
        /// <param name="entityGuid">The entity's GUID.</param>
        /// <param name="position">Position of the entity.</param>
        /// <param name="rotation">Rotation of the entity.</param>
        public EntitySpawnEventPayload(NetworkEntityGuid entityGuid, Vector3Surrogate position, QuaternionSurrogate rotation)
        {
            if (position == null)
            {
                throw new ArgumentNullException(nameof(position), $"Provided {nameof(Vector3Surrogate)} must not be null.");
            }

            if (rotation == null)
            {
                throw new ArgumentNullException(nameof(rotation), $"Provided {nameof(QuaternionSurrogate)} must not be null.");
            }

            EntityGuid = entityGuid;
            Position   = position;
            Rotation   = rotation;
        }
        public EntityStateChangedEvent(byte state, NetworkEntityGuid entityGuid, float timeStamp)
        {
            if (entityGuid == null)
            {
                throw new ArgumentNullException(nameof(entityGuid));
            }
            if (timeStamp < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(timeStamp));
            }

            //TODO: Check refs
            //TODO: Verify args
            State            = state;
            EntityGuid       = entityGuid;
            CurrentTimeStamp = timeStamp;
        }
Example #12
0
        /// <summary>
        /// Creates a new <see cref="BoomaPayloadMessageType.ClaimSessionResponse"/> payload.
        /// </summary>
        public ClaimSessionResponsePayload(Vector3Surrogate position, QuaternionSurrogate rotation, NetworkEntityGuid entityGuid)
        {
            if (position == null)
            {
                throw new ArgumentNullException(nameof(position));
            }
            if (rotation == null)
            {
                throw new ArgumentNullException(nameof(rotation));
            }
            if (entityGuid == null)
            {
                throw new ArgumentNullException(nameof(entityGuid));
            }

            ResponseCode = PlayerSpawnResponseCode.Success;
            EntityGuid   = entityGuid;
            Position     = position;
            Rotation     = rotation;
        }
        public EntityPositionUpdateEvent(Vector3Surrogate position, NetworkEntityGuid entityGuid, float timeStamp)
        {
            if (position == null)
            {
                throw new ArgumentNullException(nameof(position));
            }
            if (entityGuid == null)
            {
                throw new ArgumentNullException(nameof(entityGuid));
            }
            if (timeStamp < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(timeStamp));
            }

            //TODO: Check refs
            //TODO: Verify args
            EntityGuid       = entityGuid;
            Position         = position;
            CurrentTimeStamp = timeStamp;
        }
 public PlayerEntitySpawnEventPayload(NetworkEntityGuid entityGuid, Vector3Surrogate position, QuaternionSurrogate rotation)
     : base(entityGuid, position, rotation)
 {
     //Nothing at the moment. Can extend for future use.
 }
 public void Register(int connectionId, NetworkEntityGuid guid)
 {
     GuidToConnectionMap[guid]         = connectionId;
     ConnectionToGuidMap[connectionId] = guid;
 }
 public int Lookup(NetworkEntityGuid guid)
 {
     return(GuidToConnectionMap[guid]);
 }
 public bool Contains(NetworkEntityGuid guid)
 {
     return(GuidToConnectionMap.ContainsKey(guid));
 }