Esempio n. 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);
        }
        /// <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;
        }
Esempio n. 3
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;
        }
Esempio n. 4
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;
        }
 public PlayerEntitySpawnEventPayload(NetworkEntityGuid entityGuid, Vector3Surrogate position, QuaternionSurrogate rotation)
     : base(entityGuid, position, rotation)
 {
     //Nothing at the moment. Can extend for future use.
 }