Exemplo n.º 1
0
        async public Task <IActionResult> Configuration(string roomId, [FromBody] RoomConfigurationViewModel roomConfiguration)
        {
            var normalisedRoomId = roomId.ToUpperInvariant();

            if (!RoomRepository.Exists(normalisedRoomId))
            {
                return(NotFound());
            }
            var room = RoomRepository.Get(normalisedRoomId);

            if (room.State.Creator.Id != SessionManager.GetCurrentUser().Id)
            {
                return(Unauthorized("Only the creator of the room can edit the library"));
            }

            await RoomHelpers.WithRoomLock(room, async() =>
            {
                if (!string.IsNullOrEmpty(roomConfiguration.LibraryScript))
                {
                    var limitations = new DiceScript.Contracts.Limitations
                    {
                        MaxProgramSize = 2000,
                        MaxRollNbr     = 100
                    };
                    var builder              = new DiceScript.Builder(limitations);
                    room.Library             = builder.BuildLib(roomConfiguration.LibraryScript);
                    room.State.Functions     = room.Library.GetFunctionList();
                    room.State.LibraryScript = roomConfiguration.LibraryScript;
                }
                room.State.DiscordWebHook = roomConfiguration.DiscordWebHook;
                await RoomHub.Update(room);
            });

            return(Ok());
        }
Exemplo n.º 2
0
        public IActionResult RunScript([FromBody] string script)
        {
            var limitations = new DiceScript.Contracts.Limitations
            {
                MaxProgramSize = 500,
                MaxRollNbr     = 100
            };
            var builder = new DiceScript.Builder(limitations);
            var runner  = builder.BuildScript(script);
            var results = runner();

            return(Json(GroupResults(results)));
        }