Esempio n. 1
0
        public async Task <(MyChessGame?Game, HandlerError?Error)> CreateGameAsync(AuthenticatedUser authenticatedUser, MyChessGame game)
        {
            var opponentID = game.Players.Black.ID;
            var opponent   = await GetUserByUserIDAsync(opponentID);

            if (opponent == null)
            {
                return(null, new HandlerError()
                {
                    Instance = LoggingEvents.CreateLinkToProblemDescription(LoggingEvents.GameHandlerOpponentNotFound),
                    Status = (int)HttpStatusCode.NotFound,
                    Title = "User not found",
                    Detail = "For some reason your opponent could not be found"
                });
            }

            var user = await GetOrCreateUserAsync(authenticatedUser);

            game.ID = Guid.NewGuid().ToString("D");
            game.Players.White.ID = user.UserID;
            var data = _compactor.Compact(game);

            // TODO: Validate game data
            var comment = game.Moves[0].Comment;

            await _context.UpsertAsync(TableNames.GamesWaitingForYou, new GameEntity
            {
                PartitionKey = opponentID,
                RowKey       = game.ID,
                Data         = data
            });

            await _context.UpsertAsync(TableNames.GamesWaitingForOpponent, new GameEntity
            {
                PartitionKey = user.UserID,
                RowKey       = game.ID,
                Data         = data
            });

            await _notificationHandler.SendNotificationAsync(opponentID, game.ID, comment);

            return(game, null);
        }
Esempio n. 2
0
        public void Compress_Decompress_Test()
        {
            // Arrange
            var expected = new MyChessGame
            {
                ID = "abc"
            };

            expected.Players.Black.ID = "def";
            var buffer = _compactor.Compact(expected);

            // Act
            var actual = _compactor.Decompress(buffer);

            // Assert
            Assert.Equal(expected.ID, actual.ID);
            Assert.Equal(expected.Players.Black.ID, actual.Players.Black.ID);
        }
Esempio n. 3
0
        public async Task Get_Games_As_Existing_User_With_Game()
        {
            // Arrange
            var expected = "123";
            var user     = new AuthenticatedUser()
            {
                Name = "abc",
                PreferredUsername  = "******",
                UserIdentifier     = "u",
                ProviderIdentifier = "p"
            };

            var compactor = new Compactor();
            await _context.UpsertAsync(TableNames.Users, new UserEntity()
            {
                PartitionKey = "u",
                RowKey       = "p",
                UserID       = "user123"
            });

            await _context.UpsertAsync(TableNames.GamesWaitingForYou, new GameEntity()
            {
                PartitionKey = "user123",
                RowKey       = "123",
                Data         = compactor.Compact(new MyChessGame()
                {
                    ID = "123"
                })
            });

            // Act
            var actual = await _gamesHandler.GetGameAsync(user, "123", null);

            // Assert
            Assert.NotNull(actual);
            Assert.Equal(expected, actual?.ID);
        }
Esempio n. 4
0
        public async Task Move_Game_To_Archive()
        {
            // Arrange
            var expectedWaitingForYou      = 0;
            var expectedWaitingForOpponent = 0;
            var expectedArchive            = 2;

            var user1 = new AuthenticatedUser()
            {
                Name = "abc",
                PreferredUsername  = "******",
                UserIdentifier     = "u1",
                ProviderIdentifier = "p1"
            };

            // Player creating the game
            await _context.UpsertAsync(TableNames.Users, new UserEntity()
            {
                PartitionKey = "u1",
                RowKey       = "p1",
                UserID       = "user123"
            });

            await _context.UpsertAsync(TableNames.UserID2User, new UserID2UserEntity()
            {
                PartitionKey   = "user123",
                RowKey         = "user123",
                UserPrimaryKey = "u1",
                UserRowKey     = "p1"
            });

            // Opponent
            await _context.UpsertAsync(TableNames.Users, new UserEntity()
            {
                PartitionKey = "u2",
                RowKey       = "p2",
                UserID       = "user456"
            });

            var game = new MyChessGame
            {
                ID = "aaa"
            };

            game.Players.White.ID = "user123";
            game.Players.Black.ID = "user456";
            var moves = new string[]
            {
                "E2E4", // White Pawn
                "A7A6", // Black Pawn
                "F1C4", // White Bishop
                "H7H6", // Black Pawn
                "D1F3", // White Queen
                "A6A5"  // Black Pawn
            };

            foreach (var m in moves)
            {
                game.Moves.Add(new MyChessGameMove()
                {
                    Move = m
                });
            }

            var compactor = new Compactor();
            var data      = compactor.Compact(game);
            await _context.UpsertAsync(TableNames.GamesWaitingForYou, new GameEntity()
            {
                PartitionKey = "user123",
                RowKey       = "aaa",
                Data         = data
            });

            // White Queen
            var finalMove = new MyChessGameMove()
            {
                Move = "F3F7"
            };

            // Act
            var actual = await _gamesHandler.AddMoveAsync(user1, "aaa", finalMove);

            // Assert
            Assert.Null(actual);
            var actualWaitingForYou      = _context.Tables[TableNames.GamesWaitingForYou].Count;
            var actualWaitingForOpponent = _context.Tables[TableNames.GamesWaitingForOpponent].Count;
            var actualWaitingArchive     = _context.Tables[TableNames.GamesArchive].Count;

            Assert.Equal(expectedWaitingForYou, actualWaitingForYou);
            Assert.Equal(expectedWaitingForOpponent, actualWaitingForOpponent);
            Assert.Equal(expectedArchive, actualWaitingArchive);
        }
Esempio n. 5
0
        static int Main(string[] args)
        {
            var compactor = new Compactor();

            var returnValue = 0;

            compactor.EmitLineDirectives = false;
            compactor.Minify             = false;

            if (args.Length == 3 || args.Length == 4)
            {
                var target        = args[0];
                var directoryPath = args[1];

                var forZilch = (target == "-Zilch");
                var forZero  = !forZilch;

                var zeroPath  = directoryPath;
                var zilchPath = directoryPath;

                if (forZero)
                {
                    zilchPath = Path.Combine(directoryPath, @"ZeroLibraries\Zilch");
                }

                compactor.FilesToProcess.AddFilesFromDirectory(Path.Combine(zilchPath, @"Project\Zilch"), "*.cpp");

                var standardLibraries = Path.Combine(zilchPath, @"Project\StandardLibraries");

                if (forZero)
                {
                    standardLibraries = Path.Combine(zeroPath, @"ZeroLibraries");
                }

                compactor.FilesToProcess.AddFilesFromDirectory(Path.Combine(standardLibraries, @"Common"), "*.cpp");
                compactor.FilesToProcess.AddFilesFromDirectory(Path.Combine(standardLibraries, @"Math"), "*.cpp");
                compactor.FilesToProcess.AddFilesFromDirectory(Path.Combine(standardLibraries, @"Platform"), "*.cpp", false);

                // These files get conditionally included into the 'Debugging.cpp'
                compactor.FilesToProcess.RemoveFilesByName("DebuggingWindows.cpp");
                compactor.FilesToProcess.RemoveFilesByName("DebuggingGeneric.cpp");

                // At the moment, we don't use regex, so just only include NoRegex.cpp
                compactor.FilesToProcess.RemoveFilesByName("Regex.cpp");

                // We explicitly need to process the platform selector header file first
                compactor.FilesToProcess.Add(Path.Combine(standardLibraries, @"Platform\PlatformSelector.hpp"));

                // Windows platform
                {
                    compactor.DirectoryDirectives.Add(Compactor.NormalizePath(Path.Combine(standardLibraries, @"Platform\Windows")), new CompacterDirectives()
                    {
                        PreprocessorCondition = "defined(PLATFORM_WINDOWS)",
                        CppOnly = true,
                    });
                    compactor.FilesToProcess.AddFilesFromDirectory(Path.Combine(standardLibraries, @"Platform\Windows"), "*.cpp");
                }

                // Posix platform
                {
                    compactor.DirectoryDirectives.Add(Compactor.NormalizePath(Path.Combine(standardLibraries, @"Platform\Posix")), new CompacterDirectives()
                    {
                        PreprocessorCondition = "defined(PLATFORM_POSIX)",
                        CppOnly = true,
                    });
                    compactor.FilesToProcess.AddFilesFromDirectory(Path.Combine(standardLibraries, @"Platform\Posix"), "*.cpp");
                }

                // Empty platform
                {
                    compactor.DirectoryDirectives.Add(Compactor.NormalizePath(Path.Combine(standardLibraries, @"Platform\Empty")), new CompacterDirectives()
                    {
                        PreprocessorCondition = "defined(PLATFORM_EMSCRIPTEN)",
                        CppOnly = true,
                    });
                    compactor.FilesToProcess.AddFilesFromDirectory(Path.Combine(standardLibraries, @"Platform\Empty"), "*.cpp");
                }

                // This file brings in dependencies upon the engine and other bad things!
                compactor.FilesToProcess.RemoveFilesByName("CrashHandler.cpp");
                compactor.FilesToProcess.RemoveFilesByName("StackWalker.cpp");

                compactor.HppDirectories.Add(Path.Combine(standardLibraries, @"Common"));
                compactor.HppDirectories.Add(standardLibraries);

                var hppPath = args[2];

                var cppPath = String.Empty;
                if (args.Length == 4)
                {
                    cppPath = args[3];
                }

                //var output = Path.Combine(zilchPath, @"Project\ZilchAll\NonCompacted\");
                compactor.Compact(cppPath, hppPath, null);

                Console.WriteLine("Done compacting");
            }
            else
            {
                Console.Error.WriteLine("Expected: <-Zilch or -Zero> <Zilch or Zero directory> <output.hpp> [output.cpp]");
                Console.Error.WriteLine("Given: `" + Environment.CommandLine + "`");
                returnValue = -1;
            }

            if (Debugger.IsAttached)
            {
                Console.WriteLine("Press enter to continue...");
                Console.ReadLine();
            }

            if (compactor.WasError)
            {
                returnValue = -1;
            }

            return(returnValue);
        }