public override void DoWork(IEnumerable<string> args)
 {
     if (Utils.CheckArgs(ArgsNeed, args.Count()))
     {
         if (Utils.IsLoggedIn() && Utils.IsNotInGame())
         {
             var request = new CreateGameRequest {NewPlayer = new User {Name = CurrentUser.Name}};
             var response = ServerProvider.MakeRequest<CreateGameResponse>(request);
             if (response.Status == Statuses.Ok)
             {
                 Console.WriteLine("You create game. ID: " + response.ID);
                 CurrentUser.CurrentGame = response.ID;
             }
             else
             {
                 Console.WriteLine("Bad status");
             }
         }
     }
 }
Exemple #2
0
        public ActionResult StartFree()
        {
            User newPlayer = null;
            if (Request.IsAuthenticated)
            {
                newPlayer = new User { Name = User.Identity.Name };
            }
            var requestCreateGame = new CreateGameRequest { NewPlayer = newPlayer };
            var responseCreateGame = ServerProvider.MakeRequest<CreateGameResponse>(requestCreateGame);

            int? gameId = null;
            if (responseCreateGame.Status == Statuses.Ok)
            {
                gameId = responseCreateGame.ID;
                FormsAuthentication.SetAuthCookie(responseCreateGame.FirstPlayer.Name, false);
                var requestJoinGame = new JoinGameRequest
                {
                    GameID = gameId.Value,
                    NewPlayer = responseCreateGame.FirstPlayer
                };
                var responseJoinGame = ServerProvider.MakeRequest(requestJoinGame);
                if (responseJoinGame.Status != Statuses.Ok)
                {
                    gameId = null;
                }
            }

            return Json(gameId, JsonRequestBehavior.AllowGet);
        }