Exemple #1
0
    private void Receive(object sender, MessageEventArgs e)
    {
        PacketChecker packet = JsonUtility.FromJson <PacketChecker>(e.Data);

        if (packet == null)
        {
            return;
        }

        if (packet.packetType == null)
        {
            return;
        }

        switch (packet.packetType)
        {
        case (int)GameServerPackets.Handshake:
            ServerHandshake shake = JsonUtility.FromJson <ServerHandshake>(e.Data);
            Debug.Log(shake.welcomeMessage);
            break;

        case (int)GameServerPackets.GetLobbyCode:
            CreateLobby lobby = JsonUtility.FromJson <CreateLobby>(e.Data);
            info.currentGame = lobby.lobbyCode;
            actionsToRun.Add(() => SceneManager.LoadScene(joinScene));
            break;

        case (int)GameServerPackets.ErrorMessage:
            Disconnect();
            Application.Quit();
            break;
        }
    }
Exemple #2
0
        public void OnCreateLobby(CreateLobby createLobby)
        {
            // create new lobby and add to list
            string     id         = Guid.NewGuid().ToString();
            LobbyState lobbyState = new LobbyState(id, createLobby.DisplayName, createLobby.MaxPlayers);

            _lobbies.Add(id, lobbyState);
            _log.Output($"Lobby Created Id:[{id}] Name:[{createLobby.DisplayName}]");
        }
Exemple #3
0
        private static void Main(string[] args)
        {
            var container = AutofacSetup.Build();

            dispatcher = container.Resolve <CommandDispatcher>();

            var lobbyId = Guid.NewGuid();
            var gameId  = Guid.NewGuid();

            Console2.WriteLine("# Creating Game #", ConsoleColor.Red);
            var createLobby = new CreateLobby(lobbyId, gameId, "Test Game", Guid.NewGuid(), "Mat");

            dispatcher.Dispatch(createLobby);

            Console.ReadLine();
            Console2.WriteLine("# Inviting Richard #", ConsoleColor.Red);

            var invitationToken = Guid.NewGuid();
            var playerId        = Guid.NewGuid();
            var invitePlayer    = new InvitePlayer(lobbyId, playerId, "Richard", invitationToken);

            dispatcher.Dispatch(invitePlayer);

            Console.ReadLine();
            Console2.WriteLine("# Accepting Invitation #", ConsoleColor.Red);
            var acceptInvitation = new AcceptInvitation(lobbyId, invitationToken);

            dispatcher.Dispatch(acceptInvitation);

            Console.ReadLine();
            Console2.WriteLine("# Inviting Matt #", ConsoleColor.Red);
            var invitationToken2 = Guid.NewGuid();
            var invitePlayer2    = new InvitePlayer(lobbyId, Guid.NewGuid(), "Matt", invitationToken2);

            dispatcher.Dispatch(invitePlayer2);

            Console.ReadLine();
            Console2.WriteLine("# Accepting Invitation #", ConsoleColor.Red);
            var acceptInvitation2 = new AcceptInvitation(lobbyId, invitationToken2);

            dispatcher.Dispatch(acceptInvitation2);

            Console.ReadLine();
            Console2.WriteLine("# Starting Game #", ConsoleColor.Red);
            var gameSetupId = Guid.NewGuid();
            var startGame   = new StartGame(lobbyId, gameSetupId);

            dispatcher.Dispatch(startGame);

            Console.ReadLine();

            //var boardSetupId = new Guid("4c7e5f0fc0bf4d28a63ba9b0253bb9f1");
            //var playerId = new Guid("59fbb53f-2c86-4b13-a6e5-740ffefdb2a7");

            //var placeInfantryUnit = new PlaceInfantryUnit(boardSetupId, playerId, "Alaska");
            //dispatcher.Dispatch(placeInfantryUnit);
        }
Exemple #4
0
        void When(CreateLobby e)
        {
            var lobby = Id.From(e.LobbyName);

            if (LobbyExists(lobby))
            {
                Then(new LobbyFailed(lobby, "Already exists in the lobby list."));
                return;
            }
            var admins = new List <Id>()
            {
                Id.From(e.AdminName)
            };

            Lobbies.Add(new Lobby(lobby, admins));
            Then(new UpdatedLobbyList(Lobbies));
        }
Exemple #5
0
        public MenuManager(ContentManager Content, BannerManager bannerManager, NetworkingManager networkingManager)
        {
            this.bannerManager     = bannerManager;
            this.networkingManager = networkingManager;
            BackgroundTexture      = Content.Load <Texture2D>(@"menuBackground");
            mainMenu       = new MainMenu(Content);
            profile        = new Profile(Content);
            play           = new Play(Content);
            joinLobby      = new JoinLobby(Content);
            createLobby    = new CreateLobby(Content);
            about          = new About(Content);
            expansionLobby = new ExpansionLobby(Content);
            quitGame       = new QuitGame(Content);

            MenuState  = MenuStates.MainMenu;
            activeMenu = mainMenu;
            ExitGame   = false;
        }
        [HttpPost] public IActionResult Post([FromBody] CreateLobby lobby)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            // TODO/FIXME: reservations
            var err = createLobby.TryCreateLobby(lobby.UserId, lobby.Slots, lobby.Access, out string gameId);

            if (!err)
            {
                return(Created(gameId, null));
            }
            if (err == Error.Codes.E02UserNotFound)
            {
                return(NotFound(err));
            }
            if (err == Error.Codes.E05InvalidSlotCount)
            {
                return(UnprocessableEntity(err));
            }
            return(Status(500)); // (should never happen)
        }