Exemplo n.º 1
0
        public static PostHandlerOutput[] InviteCommand(
            IDocumentSession documentSession,
            IMember sender,
            IRoom room,
            string source)
        {
            documentSession.Ensure("documentSession");
            sender.Ensure("sender");
            room.Ensure("sender");
            source.Ensure("source");

            var match = inviteRegex.Match(source);
            if (!match.Success)
                return null;

            if (!sender.IsRoomOwner(room))
                return new[]
                {
                    new PostHandlerOutput
                    {
                        message = "Only the room's owner can invite players.",
                        type= "error"
                    }
                };

            var playerInvitation = documentSession.CreatePlayerInvitation(room.Id);

            return new[]
            {
                new PostHandlerOutput
                {
                    message = string.Format(
                        CultureInfo.CurrentUICulture,
                        "Give this URL to someone to join the game:{0}{1}?invitation-code={2}",
                        Environment.NewLine,
                        fn.MakeAbsoluteUri(Paths.AcceptInvitationForm()),
                        playerInvitation.Code),
                    type= "system"
                }
            };
        }