Пример #1
0
        public TableResponse acceptInvitation(String sessionToken, String SidGame)
        {
            int idGame = Int16.Parse(SidGame);
            Login LoginService = new Login();
            Boolean accepted = false;
            String message = "Game not found";
            if (LoginService.session(sessionToken).Authorized == true)
            {
                mUser userInv = DBControler.acceptInvite(sessionToken, idGame);
                if (userInv.getId() > 0)
                {
                    accepted = true;
                    message = "" + idGame;
                }
                if (userInv.getId() == -3)
                {
                    accepted = false;
                    message = ""+idGame;
                }
                if (userInv.getId()==-5)
                {
                    accepted = false;
                    message = "" + idGame;
                }
            }
            else sessionToken = "";

            return new TableResponse
            {
                Session = sessionToken,
                Successful = accepted,
                Message = message
            };
        }
Пример #2
0
 public PlayersResponse getFriends(String sessionToken)
 {
     Login LoginService= new Login();
     List<mUser> users=new List<mUser>();
     if(LoginService.session(sessionToken).Authorized==true)
     {
          users=DBControler.getFriends(sessionToken);
     }
     else sessionToken="";
     return new PlayersResponse
     {
         Session=sessionToken,
         Users = userListToJson(users)
     };
 }
Пример #3
0
 public FriendResponse addFriend(String sessionToken, String friendName)
 {
     Login LoginService = new Login();
         Boolean added = false;
         if (LoginService.session(sessionToken).Authorized == true)
         {
             added = DBControler.addFriend(sessionToken, friendName);
         }
         else sessionToken = "";
         return new FriendResponse
         {
             Session = sessionToken,
             Successful = added
         };
 }
Пример #4
0
 public GameResponse finishMove(String sessionToken, String sidGame)
 {
     Login LoginService = new Login();
     Boolean finished = false;
     int idGame = Int16.Parse(sidGame);
     String message = "Failed to finish move";
     if (LoginService.session(sessionToken).Authorized == true)
     {
         message= ""+DBControler.finishMove(sessionToken, idGame);
         finished = true;
     }
     return new GameResponse
     {
         Session = sessionToken,
         Successful = finished,
         Message = message
     };
 }
Пример #5
0
        public GamesResponse getGames(String sessionToken)
        {
            Login LoginService = new Login();
            Boolean responded = false;
            List<mGame> games = new List<mGame>();
            if (LoginService.session(sessionToken).Authorized == true)
            {
                games = DBControler.getGames(sessionToken);
                responded = true;
            }
            else sessionToken = "";

            return new GamesResponse
            {
                Session = sessionToken,
                Successful = responded,
                Games = gamesListToJson(games)
            };
        }
Пример #6
0
        //Poprawic responsa
        public InvitationsResponse getInvitations(String sessionToken)
        {
            Login LoginService = new Login();
            Boolean responded = false;
            List<mInvite> invites = new List<mInvite>();
            if (LoginService.session(sessionToken).Authorized == true)
            {
                invites = DBControler.getInvitations(sessionToken);
                responded = true;
            }
            else sessionToken = "";

            return new InvitationsResponse
            {
                Session = sessionToken,
                Successful = responded,
                Invites = invitesListToJson(invites)
            };
        }
Пример #7
0
 public TableResponse createTable(String sessionToken)
 {
     Login LoginService = new Login();
     Boolean created = false;
     String message = "Failed to create";
     if (LoginService.session(sessionToken).Authorized == true)
     {
         mTable table = DBControler.newTable(sessionToken);
         if (table != null)
         {
             message = "" + table.getGameId();
             created = true;
         }
     }
     return new TableResponse
     {
         Session = sessionToken,
         Successful = created,
         Message = message
     };
 }
Пример #8
0
 public MovesResponse getLastMoves(String sessionToken, String sidGame, String sidLastMove)
 {
     Login LoginService = new Login();
     Boolean send = false;
     int idGame = Int16.Parse(sidGame);
     int idLastMove = Int16.Parse(sidLastMove);
     List<mLog> move = null;
     if (LoginService.session(sessionToken).Authorized == true)
     {
         move=DBControler.getLastMoves(sessionToken, idGame, idLastMove);
         send = true;
     }
     return new MovesResponse
     {
         Session = sessionToken,
         Successful = send,
         Moves = movesListToJson(move)
     };
 }
Пример #9
0
 //needs fix
 public GameResponse newGame(String sessionToken, String SidGame)
 {
     Login LoginService = new Login();
     Boolean created = false;
     int idGame = Int16.Parse(SidGame);
     String message = "Failed to create";
     if (LoginService.session(sessionToken).Authorized == true)
     {
         mTable table = DBControler.newTable(sessionToken);
         if (table != null)
         {
             message = "Created table with ID:" + table.getId();
             created = true;
         }
     }
     return new GameResponse
     {
         Session = sessionToken,
         Successful = created,
         Message = message
     };
 }
Пример #10
0
 public GameResponse movePawn(String sessionToken, String sidGame, String spreX, String spreY, String spostX, String spostY)
 {
     Login LoginService = new Login();
     Boolean moved = false;
     int idGame = Int16.Parse(sidGame);
     int preX = Int16.Parse(spreX);
     int preY = Int16.Parse(spreY);
     int postX = Int16.Parse(spostX);
     int postY = Int16.Parse(spostY);
     mMove move = null;
     String message = "Login fail";
     if (LoginService.session(sessionToken).Authorized == true)
     {
         message = "Pawn doesn't exist";
         move = DBControler.movePawn(sessionToken, idGame, preX, preY, postX, postY);
         if (move != null)
         {
             message = move.idMove+"";
             moved = true;
         }
     }
     return new GameResponse
     {
         Session = sessionToken,
         Successful = moved,
         Message = message
     };
 }
Пример #11
0
        //TODO Obsluga komunikatow
        public TableResponse invitePlayer(String sessionToken, String friendName, String SidGame)
        {
            int idGame = Int16.Parse(SidGame);
            Login LoginService = new Login();
            Boolean invited = false;
            String message = "Failed to invite";
            if (LoginService.session(sessionToken).Authorized == true)
            {
                mUser userInv = DBControler.newInvite(sessionToken, friendName, idGame);
                if (userInv.getId() > 0)
                {
                    invited = true;
                    message = "Invited user with name:" + friendName;
                }
                else if (userInv.getId() == -4) message = "Invite already sent to:" + friendName;

            }
            else sessionToken = "";

            return new TableResponse
            {
                Session = sessionToken,
                Successful = invited,
                Message = message
            };
        }
Пример #12
0
        //TODO Obsluga komunikatow
        public TableResponse revokeInvitation(String sessionToken, String friendName, String SidGame)
        {
            int idGame = Int16.Parse(SidGame);
            Login LoginService = new Login();
            Boolean revoked = false;
            String message = "Failed to revoke";
            if (LoginService.session(sessionToken).Authorized == true)
            {
                mUser userInv = DBControler.removeInvite(sessionToken, friendName, idGame);
                if (userInv.getId() > 0) revoked = true;
                message = "Revoked invitation for user with name:" + friendName;
            }
            else sessionToken = "";

            return new TableResponse
            {
                Session = sessionToken,
                Successful = revoked,
                Message = message
            };
        }