/// <summary>
        /// Remove player's registration (deregister).
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>The <see cref="object"/>.</returns>
        public object Delete(RegistrationCommand request)
        {
            var result = GameController.Deregister(request.Slug);

            if (result) ServerEvents.NotifyChannel("spectator", new SpectatorMessage { MessageType = MessageTypes.Player, Name = request.Name, Avatar = request.Hash, Message = $"`@{request.Slug}` has left the demo" });

            return new HttpResult(HttpStatusCode.NoContent);
        }
Ejemplo n.º 2
0
        public void CanCreateRegistrationCommandTest()
        {
            var instance = new RegistrationCommand("or1", "dest1", "arr1");

            Assert.IsNotNull(instance);
            Assert.AreEqual(instance.OriginUnlocode, "or1");
            Assert.AreEqual(instance.DestinationUnlocode, "dest1");
            Assert.AreEqual(instance.ArrivalDeadline, "arr1");
        }
        /// <summary>
        /// Register a player.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>The <see cref="object"/>.</returns>
        public object Post(RegistrationCommand request)
        {
            var result = GameController.Register(request.Slug, request.Hash, request.Name);

            if (!result) throw new HttpError(HttpStatusCode.NotAcceptable, "DuplicatePlayerID");

            ServerEvents.NotifyChannel("spectator", new SpectatorMessage { MessageType = MessageTypes.Player, Name = request.Name, Avatar = request.Hash, Message = $"`@{request.Slug}` has joined the demo" });

            return new HttpResult(HttpStatusCode.Created);
        }