Exemplo n.º 1
0
        static void Main(string[] args)
        {
            RequestHandler rh = new RequestHandler();
            Console.WriteLine("Adding user");

            string guid = Guid.NewGuid().ToString("N");
            string s = String.Format("Hi, \n You can play the game at:\n http://89.147.71.220/Monopoly/Home/ViewAnonymGame?UId={0}\n" +
                                    "Cheers,\nOnline Monopoly Team", guid);
            Console.WriteLine(s);

            //rh.ShutdownService(); return;
            List<string> emails = new List<string>() { @"*****@*****.**", @"*****@*****.**"};
            Task t0 = rh.RegisterUserAsync(emails[0], true);
            Task t1 = rh.RegisterUserAsync(emails[1], true);
            t0.Wait();
            t1.Wait();
            Console.WriteLine("Users added");
            rh.CreateGameAsync(emails);
            Console.WriteLine("Started creating game, waiting ...");
            int id = 1;
            Console.WriteLine("Game created with id " + id);
            rh.AcceptAsync(emails[0], id);
            Console.WriteLine("can start? " + rh.CanStart(id));
            rh.AcceptAsync(emails[1], id);
            Console.WriteLine("can start? " + rh.CanStart(id));
            rh.StartGameAsync(id);
            Console.WriteLine("starting  ... " );
            List<Move> moves = rh.GetPossibilites(emails[0], id);
            Console.WriteLine("--- Moves");
            foreach (Move m in moves)
            {
                Console.WriteLine(m.Description);
            }

            Console.WriteLine("---");
            Console.WriteLine("Making move .. {0}", moves[0].Type);
            rh.MakeMoveAsync(moves[0].Id, "");
            moves = rh.GetPossibilites(emails[0], id);
            Console.WriteLine("--- Moves");
            foreach (Move m in moves)
            {
                Console.WriteLine("{0} : {1}",m.Description, m.Param);
            }
            Console.WriteLine("---");
            Console.WriteLine("Making move .. {0}", moves[0].Type);
            rh.MakeMoveAsync(moves[0].Id, "");
            moves = rh.GetPossibilites(emails[0], id);
            Console.WriteLine("--- Moves");
            foreach (Move m in moves)
            {
                Console.WriteLine("{0} : {1}", m.Description, m.Param);
            }
            Console.WriteLine("---");
            UIGame game = rh.GetUIGameState(emails[0], id);
            Console.WriteLine("Actmoney {0}", game.ActUserMoney);
            Console.WriteLine(game.GameState.ToString());
            Console.WriteLine(Enum.GetName(typeof(UIGame.UIGameStatus), game.GameState));
            rh.ShutdownService();
        }
Exemplo n.º 2
0
 public ActionResult CreateGame(List<String> ListBox, String player0, String player1, String player2, String player3, String player4, String player5, String player6)
 {
     if (!WebSecurity.IsAuthenticated) return RedirectToAction("ErrorPage", new { ErrorMessage = "You must be logged in to create a game" });
     string CurrentUserMail = GetUserEmail(WebSecurity.CurrentUserName);
     RequestHandler rh = new RequestHandler();
     rh.RegisterUserAsync(CurrentUserMail, false);
     List<string> listOfUsers = new List<string>();
     listOfUsers.Add(CurrentUserMail);
     if (ListBox != null)
     {
         foreach (var item in ListBox)
         {
             string uMail = GetUserEmail(item);
             rh.RegisterUserAsync(uMail, false);
             if (!listOfUsers.Contains(uMail)) listOfUsers.Add(uMail);
         }
     }
     String[] paramHolder = new String[7] { player0, player1, player2, player3, player4, player5, player6 };
     foreach (var item in paramHolder)
     {
         if (item != "")
         {
             if (IsEmailRegistered(item))
             {
                 rh.RegisterUserAsync(item, false);
             }
             else
             {
                 rh.RegisterUserAsync(item, true);
             }
             if (!listOfUsers.Contains(item)) listOfUsers.Add(item);
         }
     }
     UsersContext ctxu = new UsersContext();
     var qu = from users in ctxu.UserProfiles
              select users;
     List<string> UserList = qu.Select(u => u.UserName).ToList();
     ViewBag.testList = UserList;
     if (listOfUsers.Count > 8 || listOfUsers.Count == 0)
     {
         ViewBag.Error = true;
         ViewBag.ErrorMessage = "You can not add more than 7 players";
         return View();
     }
     //If we get here we can create the game
     rh.CreateGameAsync(listOfUsers);
     return RedirectToAction("Index");
 }
Exemplo n.º 3
0
 public ActionResult GameList(string UId = "")
 {
     RequestHandler rh = new RequestHandler();
     string userEmail = "";
     if (UId != "")
     {
         userEmail = rh.VerifyUniqueID(UId);
         if (userEmail == null) return RedirectToAction("ErrorPage", new { ErrorMessage = "The unique id is invalid" });
     }
     else
     {
         if (!WebSecurity.IsAuthenticated) return RedirectToAction("ErrorPage", new { ErrorMessage = "You are not logged in. Only registered users can view a list of their games" });
         userEmail = GetUserEmail(WebSecurity.CurrentUserName);
     }
     //RH.getgamelist, foreach game in gamelist getusers...
     List<GameModel> gameList = new List<GameModel>();
     List<int> gameIDs = rh.GetAllGamesForUser(userEmail);
     //List<int> gameIDs = gamesTask.Result;
     foreach (var item in gameIDs)
     {
         UIGame game = rh.GetUIGameState(userEmail, item);
         GameModel gm = new GameModel();
         gm.GameID = item;
         gm.Status = game.GameState.ToString();
         gm.GameName = "Game #" + item.ToString();
         gm.Users.Add(GetUserName(game.CreatorEmail));
         gm.UserStatus.Add("Creator");
         foreach (var innerItem in game.UIUserInfo)
         {
             string Email = innerItem.UserEmail;
             string userName = GetUserName(Email);
             if (userName != "") gm.Users.Add(userName);
             else gm.Users.Add(Email);
             gm.UserStatus.Add(innerItem.State.ToString());
         }
         gameList.Add(gm);
     }
     ViewBag.testList = gameList;
     return View();
 }
Exemplo n.º 4
0
 public ActionResult ViewStatus(int gameId = -1, string UId = "")
 {
     string userMail = "";
     UIGame game = null;
     RequestHandler rh = new RequestHandler();
     if (UId != "")
     {
         userMail = rh.VerifyUniqueID(UId);
         if (userMail == null) return RedirectToAction("ErrorPage", new { ErrorMessage = "The unique id is invalid" });
         //if (gameId != gi.GameId) return RedirectToAction("ErrorPage", new { ErrorMessage = "There was an error while processing the request. The requested game does not match with the given UID." });
         //userMail = gi.ActUserEmail;
         game = rh.GetUIGameState(userMail, gameId);
     }
     else if (!WebSecurity.IsAuthenticated) return RedirectToAction("ErrorPage", new { ErrorMessage = "You have to be logged in or provide the UId to view the requested page" });
     else
     {
         userMail = GetUserEmail(WebSecurity.CurrentUserName);
         game = rh.GetUIGameState(userMail, gameId);
     }
     GameModel gm = new GameModel();
     gm.GameName = "Game #" + gameId.ToString();
     gm.GameID = gameId;
     gm.Status = game.GameState.ToString();
     ViewBag.CreatorName = GetUserName(game.CreatorEmail);
     foreach (var item in game.UIUserInfo)
     {
         string userName = GetUserName(item.UserEmail);
         if (userName != "") gm.Users.Add(userName);
         else gm.Users.Add(item.UserEmail);
         gm.UserStatus.Add(item.State.ToString());
         if (userMail == item.UserEmail) ViewBag.PlayerStatus = item.State.ToString();
     }
     bool showstartLink = true;
     if (game.CreatorEmail == userMail && rh.CanStart(gameId)) showstartLink = true;
     else showstartLink = false;
     ViewBag.UId = UId;
     ViewBag.ShowStartLink = showstartLink;
     ViewBag.GameId = gameId.ToString();
     ViewBag.Game = gm;
     return View();
 }
Exemplo n.º 5
0
 public ActionResult ViewGame(int gameId = -1, string UId = "")
 {
     RequestHandler rh = new RequestHandler();
     string userMail = "";
     UIGame game = null;
     if (UId != "")
     {
         userMail = rh.VerifyUniqueID(UId);
         if (userMail == null) return RedirectToAction("ErrorPage", new { ErrorMessage = "The unique id is invalid" });
         //userMail = gi.UserEmail;
         if (gameId != game.GameId) return RedirectToAction("ErrorPage", new { ErrorMessage = "There was an error while processing the request. The requested game does not match with the given UID." });
         //game = rh.GetUIGameState(userMail,gameId);
         if (game.GameState == UIGame.UIGameStatus.PENDING) return RedirectToAction("ViewStatus", new { gameId = game.GameId, UId = UId }); //Or viewBoard regarding the status of the game
         return RedirectToAction("ViewBoard", new { gameId = game.GameId, UId = UId });
     }
     if (!WebSecurity.IsAuthenticated) return RedirectToAction("ErrorPage", new { ErrorMessage = "You have to be logged in or provide the UId to view the requested page" });
     userMail = GetUserEmail(WebSecurity.CurrentUserName);
     game = rh.GetUIGameState(userMail, gameId);
     if(game.GameState == UIGame.UIGameStatus.PENDING) return RedirectToAction("ViewStatus", new { gameId = gameId}); //Or ViewBoard regarding the status of the game
     return RedirectToAction("ViewBoard", new { gameId = gameId});
 }
Exemplo n.º 6
0
        public ActionResult ViewBoard(int gameId = -1, string UId = "")
        {
            RequestHandler rh = new RequestHandler();
            string userEmail = "";
            if (UId != "")
            {
                userEmail = rh.VerifyUniqueID(UId);
                if (userEmail == null) return RedirectToAction("ErrorPage", new { ErrorMessage = "The unique id is invalid" });
                //if (gameId != gi.GameId) return RedirectToAction("ErrorPage", new { ErrorMessage = "There was an error while processing the request. The requested game does not match with the given UID." });
                //userEmail = gi.ActUserEmail;
            }
            else
            {
                if (!WebSecurity.IsAuthenticated) return RedirectToAction("ErrorPage", new { ErrorMessage = "You have to be logged in or provide the UId to view the requested page" });
                else userEmail = GetUserEmail(WebSecurity.CurrentUserName);
            }
            UIGame game = rh.GetUIGameState(userEmail, gameId);
            ViewBag.gameId = gameId;
            ViewBag.UId = UId;

            ViewBag.UpperRow = this.UpperRow();
            ViewBag.LowerRow = this.LowerRow();
            ViewBag.InnerRows = this.InnerRows();

            List<string> userNames = new List<string>();
            List<string> userField = new List<string>();
            List<List<string>> userProperties = new List<List<string>>();
            foreach (var item in game.UIUserInfo)
            {
                string uName = GetUserName(item.UserEmail);
                if (uName == "") userNames.Add(item.UserEmail);
                else userNames.Add(uName);
                if (item.ActPosition != null)
                {
                    userField.Add(item.ActPosition.Name);
                    /*for (int i = 0; i< ViewBag.UpperRow.Count ; i++)
                    {
                        if (ViewBag.UpperRow[i].Contains(item.ActPosition.Name)) ViewBag.UpperRow[i] = (uName == "" ? item.UserEmail : uName) + "\n" + ViewBag.UpperRow[i];
                    }
                    for (int i = 0; i < ViewBag.LowerRow.Count; i++)
                    {
                        if (ViewBag.LowerRow[i].Contains(item.ActPosition.Name)) ViewBag.LowerRow[i] = (uName == "" ? item.UserEmail : uName) + "\n" + ViewBag.LowerRow[i];
                    }
                    for (int i = 0; i < ViewBag.InnerRows.Count; i++)
                    {
                        if (ViewBag.InnerRows[i].RightName.Contains(item.ActPosition.Name)) ViewBag.InnerRows[i].RightName = (uName == "" ? item.UserEmail : uName) + "\n" + ViewBag.InnerRows[i].RightName;
                        if (ViewBag.InnerRows[i].LeftName.Contains(item.ActPosition.Name)) ViewBag.InnerRows[i].LeftName = (uName == "" ? item.UserEmail : uName) + "\n" + ViewBag.InnerRows[i].LeftName;
                    }*/
                }
                else
                {
                    userField.Add("N/A");
                }

                List<string> propstrings = new List<string>();
                if (item.UIFieldInfo != null && item.UIFieldInfo.Count > 0)
                {
                    foreach (var inneritem in item.UIFieldInfo)
                    {
                        string propString = inneritem.Name + " - " + inneritem.Houses.ToString() + " houses and " + inneritem.Hotels + " hotels";
                        if (inneritem.IsMortgaged) propString += " (Mortgaged)";
                        propstrings.Add(propString);
                    }
                    userProperties.Add(propstrings);
                }
                else
                {
                    propstrings.Add("No property yet");
                    userProperties.Add(propstrings);
                }
            }
            ViewBag.userField = userField;
            ViewBag.UserNames = userNames;
            ViewBag.userProperties = userProperties;

            ViewBag.currentPlayer = "Zoli";
            List<Move> possibilities = rh.GetPossibilites(userEmail, gameId);
            List<string> possibleMoves = new List<string>();
            possibleMoves.AddRange(possibilities.Where(x => x.Type != Move.MoveType.MSG).Select(x => x.Type.ToString()));
            ViewBag.message = possibilities.Where(x => x.Type.ToString() == "MSG").Select(x => x.Description).SingleOrDefault();
            ViewBag.playerMoney = game.ActUserMoney;
            ViewBag.possibleMoves = possibilities;
            string helpText = "";
            foreach (var item in possibilities)
            {
                helpText += item.Help + "\n";
            }
            ViewBag.HelpText = helpText;

            return View();
        }
Exemplo n.º 7
0
 public ActionResult ViewAnonymGame(string UId)
 {
     RequestHandler rh = new RequestHandler();
     string userEmail = rh.VerifyUniqueID(UId);
     if (userEmail != null)
     {
         return RedirectToAction("GameList", new { UId = UId });
     }
     else
     {
         return RedirectToAction("ErrorPage", new {ErrorMessage = "The ID is invalid" });
     }
 }
Exemplo n.º 8
0
 public ActionResult StartGame(int gameId = -1)
 {
     if (!WebSecurity.IsAuthenticated) return RedirectToAction("ErrorPage", new { ErrorMessage = "You are not logged in. You dont have the rights to start the game" });
     RequestHandler rh = new RequestHandler();
     if (rh.CanStart(gameId)) rh.StartGameAsync(gameId);
     else return RedirectToAction("ErrorPage", new { ErrorMessage = "The game can not be started just yet." });
     return RedirectToAction("ViewGame", new { gameId = gameId });
 }
Exemplo n.º 9
0
 public ActionResult RejectGame(int gameId = -1, string UId = "")
 {
     RequestHandler rh = new RequestHandler();
     string usermail = "";
     if (WebSecurity.IsAuthenticated)
     {
         usermail = GetUserEmail(WebSecurity.CurrentUserName);
     }
     else //Anonymous user
     {
         if (UId != "")
         {
             usermail = rh.VerifyUniqueID(UId);
             if (usermail == null) return RedirectToAction("ErrorPage", new { ErrorMessage = "The unique id is invalid" });
             //if (gameId != gi.GameId) return RedirectToAction("ErrorPage", new { ErrorMessage = "There was an error while processing the request. The requested game does not match with the given UID" });
             //usermail = gi.ActUserEmail;
         }
         else
         {
             return RedirectToAction("ErrorPage", new { ErrorMessage = "You are not logged in and you have not provided an UID either." });
         }
     }
     rh.DeclineAsync(usermail, gameId);
     if (UId != "") return RedirectToAction("ViewGame", new { gameId = gameId, UId = UId });
     else return RedirectToAction("ViewGame", new { gameId = gameId });
 }
Exemplo n.º 10
0
 public ActionResult MakeMove(int move, string movementParam, int gameId, string optionalInput = "", string UId = "")
 {
     RequestHandler rh = new RequestHandler();
     if (UId != "")
     {
         string userEmail = rh.VerifyUniqueID(UId);
         if (userEmail == null) return RedirectToAction("ErrorPage", new { ErrorMessage = "You have provided an invalid UId" });
         //if (gi.GameId != gameId) return RedirectToAction("ErrorPage", new { ErrorMessage = "You are not eligible to make a move in the given game." });
     }
     else
     {
         if (!WebSecurity.IsAuthenticated) return RedirectToAction("ErrorPage", new { ErrorMessage = "You are not logged in and neither have provided a UID" });
     }
     string param = movementParam;
     int index = optionalInput.IndexOf('\r') == -1 ? optionalInput.Length : optionalInput.IndexOf('\r');
     if (optionalInput != "") param = optionalInput.Substring(0, index) + ";" + param;
     rh.MakeMoveAsync(move, movementParam);
     return RedirectToAction("ViewBoard", new { gameId = gameId, UId = UId });
 }
Exemplo n.º 11
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
                    WebSecurity.Login(model.UserName, model.Password);
                    using (UsersContext ctx = new UsersContext())
                    {
                        ctx.UserProfiles.First(x => x.UserName == model.UserName).UserEMail = model.EMail;
                        ctx.SaveChanges();
                    }
                    RequestHandler rh = new RequestHandler();
                    rh.RegisterUserAsync(model.EMail, false);
                    return RedirectToAction("Index", "Home");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }