From ae7dede791b96386c4cbea0b10e0ed6016fac093 Mon Sep 17 00:00:00 2001 From: elahe Date: Fri, 5 Feb 2021 22:06:59 +0330 Subject: [PATCH 1/2] FriendsTabController --- .../Controller/Menus/FriendsTabController.java | 13 +++++++++---- src/com/plato/Controller/Server.java | 13 ++++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/com/plato/Controller/Menus/FriendsTabController.java b/src/com/plato/Controller/Menus/FriendsTabController.java index c78ff4d..2e341a2 100644 --- a/src/com/plato/Controller/Menus/FriendsTabController.java +++ b/src/com/plato/Controller/Menus/FriendsTabController.java @@ -5,6 +5,7 @@ import Model.AccountRelated.Account; import Model.AccountRelated.Gamer; import Controller.Client; +import com.google.gson.Gson; import javafx.event.ActionEvent; import javafx.fxml.FXMLLoader; import javafx.fxml.Initializable; @@ -30,6 +31,7 @@ import java.io.File; import java.io.IOException; import java.net.URL; +import java.util.LinkedList; import java.util.ResourceBundle; public class FriendsTabController implements Initializable { @@ -50,10 +52,13 @@ public void updateFrndsList (ActionEvent actionEvent) throws IOException { dataInputStream = Client.getClient().getDataInputStream(); dataOutputStream = Client.getClient().getDataOutputStream(); frndsList.getItems().clear(); -// dataOutputStream.writeUTF("getCurrentAccLoggedIn"); -// dataOutputStream.flush(); - Gamer currentAccLoggedIn = (Gamer) AccountController.getInstance().getCurrentAccLoggedIn(); - for (String frndUN : currentAccLoggedIn.getFrnds()) { + dataOutputStream.writeUTF("getCurrentAccLoggedIn"); + dataOutputStream.flush(); + Gamer currentAccLoggedIn = MainController.getInstance().getGson().fromJson(dataInputStream.readUTF() , Gamer.class); + // TODO: 2/5/2021 + dataOutputStream.writeUTF("getFrnds_" + MainController.getInstance().getGson().toJson(currentAccLoggedIn.getFrnds())); + dataOutputStream.flush(); + for (String frndUN :MainController.getInstance().getGson().fromJson(dataInputStream.readUTF() , LinkedList.class)) { Gamer frndAcc = (Gamer) Account.getAccount(frndUN); Circle circle = new Circle(40); diff --git a/src/com/plato/Controller/Server.java b/src/com/plato/Controller/Server.java index 8b727ec..1cf0970 100644 --- a/src/com/plato/Controller/Server.java +++ b/src/com/plato/Controller/Server.java @@ -119,7 +119,7 @@ public void run () { //System.out.println(token); switch (receivedInfo[0]) { case "getAllAccounts": - dataOutputStream.writeUTF(new Gson().toJson(Account.getAccounts())); + dataOutputStream.writeUTF(MainController.getInstance().getGson().toJson(Account.getAccounts())); dataOutputStream.flush(); case "canThrowBomb": int x = Integer.parseInt(receivedInfo[1]); @@ -150,6 +150,12 @@ public void run () { dataOutputStream.flush(); break; + case "getCurrentAccLoggedInAsGamer": + Gamer gamer = (Gamer) AccountController.getInstance().getCurrentAccLoggedIn(); + dataOutputStream.writeUTF(MainController.getInstance().getGson().toJson(gamer)); + dataOutputStream.flush(); + break; + case "logOut": AccountController.getInstance().logout(); break; @@ -249,6 +255,11 @@ public void run () { case "acceptFriendReq": FriendRequestController.getInstance().acceptFriendReq(receivedInfo[1]); break; + case "getFrnds" : + gamer = (Gamer) AccountController.getInstance().getCurrentAccLoggedIn(); + dataOutputStream.writeUTF( MainController.getInstance().getGson().toJson(gamer.getFrnds())); + dataOutputStream.flush(); + break; } } catch (IOException e) { try { From 6f9487802beaf96f1ee3d365b5687cfb3ae823f5 Mon Sep 17 00:00:00 2001 From: elahe Date: Fri, 5 Feb 2021 23:32:23 +0330 Subject: [PATCH 2/2] fixed Login --- .../Resources/JSONs/AccountRelated/Admin.json | 11 +---- .../Resources/JSONs/AccountRelated/Gamer.json | 41 +------------------ src/com/Resources/JSONs/IDGenerator.json | 5 +-- .../AccountRelated/AccountController.java | 6 +-- .../Menus/FriendsTabController.java | 2 +- .../Controller/Menus/LoginMenuController.java | 17 ++++++-- .../Menus/RegisterFormController.java | 2 +- src/com/plato/Controller/Server.java | 5 +-- 8 files changed, 23 insertions(+), 66 deletions(-) diff --git a/src/com/Resources/JSONs/AccountRelated/Admin.json b/src/com/Resources/JSONs/AccountRelated/Admin.json index e23e5f7..ddbc6ea 100644 --- a/src/com/Resources/JSONs/AccountRelated/Admin.json +++ b/src/com/Resources/JSONs/AccountRelated/Admin.json @@ -1,10 +1 @@ -{ - "firstName": "fatemeh", - "lastName": "fotouhi", - "username": "fatemeh", - "password": "fo98", - "userID": "944106", - "email": "fatemeh@gmail.com", - "phoneNum": "09223456789", - "pfpUrl": "https://i.imgur.com/IIyNCG4.png" -} \ No newline at end of file +{"firstName":"fatemeh","lastName":"fotouhi","username":"fatemeh","password":"fo98","userID":"944106","email":"fatemeh@gmail.com","phoneNum":"09223456789","pfpUrl":"https://i.imgur.com/IIyNCG4.png"} \ No newline at end of file diff --git a/src/com/Resources/JSONs/AccountRelated/Gamer.json b/src/com/Resources/JSONs/AccountRelated/Gamer.json index b6207b6..6d61d3a 100644 --- a/src/com/Resources/JSONs/AccountRelated/Gamer.json +++ b/src/com/Resources/JSONs/AccountRelated/Gamer.json @@ -1,40 +1 @@ -[ - { - "awardsFromEvents": 0, - "money": 19.0, - "accountStartDate": { - "year": 2021, - "month": 1, - "day": 30 - }, - "frnds": [], - "faveGames": [], - "firstName": "fatemeh", - "lastName": "fo", - "username": "fatemehfo", - "password": "fo98", - "userID": "565519", - "email": "fatemeh23@gmail.com", - "phoneNum": "09123456789", - "pfpUrl": "file:/C:/Users/Persian%20Rayaneh/IdeaProjects/project-team-4/src/com/Resources/Images/noProfilePicture.png" - }, - { - "awardsFromEvents": 0, - "money": 0.0, - "accountStartDate": { - "year": 2021, - "month": 2, - "day": 5 - }, - "frnds": [], - "faveGames": [], - "firstName": "dorrin1", - "lastName": "11", - "username": "11", - "password": "11", - "userID": "816326", - "email": "11@gmail.com", - "phoneNum": "00041122233", - "pfpUrl": "file:/Users/dorrinsotoudeh/Desktop/project-team-4-2/src/com/Resources/Images/noProfilePicture.png" - } -] \ No newline at end of file +[{"awardsFromEvents":0,"money":19.0,"accountStartDate":{"year":2021,"month":1,"day":30},"frnds":[],"faveGames":[],"firstName":"fatemeh","lastName":"fo","username":"fatemehfo","password":"fo98","userID":"565519","email":"fatemeh23@gmail.com","phoneNum":"09123456789","pfpUrl":"file:/C:/Users/Persian%20Rayaneh/IdeaProjects/project-team-4/src/com/Resources/Images/noProfilePicture.png"},{"awardsFromEvents":0,"money":0.0,"accountStartDate":{"year":2021,"month":2,"day":5},"frnds":[],"faveGames":[],"firstName":"dorrin1","lastName":"11","username":"11","password":"11","userID":"816326","email":"11@gmail.com","phoneNum":"00041122233","pfpUrl":"file:/Users/dorrinsotoudeh/Desktop/project-team-4-2/src/com/Resources/Images/noProfilePicture.png"},{"awardsFromEvents":0,"money":0.0,"accountStartDate":{"year":2021,"month":2,"day":5},"frnds":[],"faveGames":[],"firstName":"x","lastName":"a","username":"a","password":"z","userID":"114424","email":"w@email.com","phoneNum":"09123333444","pfpUrl":"file:/D:/teamOtherFinal/src/com/Resources/Images/noProfilePicture.png"},{"awardsFromEvents":0,"money":0.0,"accountStartDate":{"year":2021,"month":2,"day":5},"frnds":[],"faveGames":[],"firstName":"asd","lastName":"123","username":"as","password":"d","userID":"035598","email":"d@EMAIL.COM","phoneNum":"09123333888","pfpUrl":"file:/D:/teamOtherFinal/src/com/Resources/Images/noProfilePicture.png"},{"awardsFromEvents":0,"money":0.0,"accountStartDate":{"year":2021,"month":2,"day":5},"frnds":[],"faveGames":[],"firstName":"asd","lastName":"123","username":"m","password":"k","userID":"582373","email":"m@email.com","phoneNum":"09123456789","pfpUrl":"file:/D:/teamOtherFinal/src/com/Resources/Images/noProfilePicture.png"},{"awardsFromEvents":0,"money":0.0,"accountStartDate":{"year":2021,"month":2,"day":5},"frnds":[],"faveGames":[],"firstName":"ed","lastName":"bos","username":"ed","password":"lk","userID":"511175","email":"l@email.com","phoneNum":"09123245679","pfpUrl":"file:/D:/teamOtherFinal/src/com/Resources/Images/noProfilePicture.png"}] \ No newline at end of file diff --git a/src/com/Resources/JSONs/IDGenerator.json b/src/com/Resources/JSONs/IDGenerator.json index 794313a..efcf8f2 100644 --- a/src/com/Resources/JSONs/IDGenerator.json +++ b/src/com/Resources/JSONs/IDGenerator.json @@ -1,4 +1 @@ -[ - "944106", - "565519" -] \ No newline at end of file +["944106","565519"] \ No newline at end of file diff --git a/src/com/plato/Controller/AccountRelated/AccountController.java b/src/com/plato/Controller/AccountRelated/AccountController.java index 193d828..d4eeeae 100644 --- a/src/com/plato/Controller/AccountRelated/AccountController.java +++ b/src/com/plato/Controller/AccountRelated/AccountController.java @@ -23,13 +23,13 @@ public void login (String username, String password, boolean rememberMe) throws if (!username.matches("[!-~]+")) throw new MainController.InvalidFormatException("Username"); - if (!Account.accountExists(username)) + else if (!Account.accountExists(username)) throw new NoAccountExistsWithUsernameException(); - if (!Account.getAccount(username).isPasswordCorrect(password)) + else if (!Account.getAccount(username).isPasswordCorrect(password)) throw new PaswordIncorrectException(); - throw new SuccessfulLogin(); + else throw new SuccessfulLogin(); // saveLoginInfo = rememberMe; // currentAccLoggedIn = Account.getAccount(username); } diff --git a/src/com/plato/Controller/Menus/FriendsTabController.java b/src/com/plato/Controller/Menus/FriendsTabController.java index 2e341a2..10f3c11 100644 --- a/src/com/plato/Controller/Menus/FriendsTabController.java +++ b/src/com/plato/Controller/Menus/FriendsTabController.java @@ -58,7 +58,7 @@ public void updateFrndsList (ActionEvent actionEvent) throws IOException { // TODO: 2/5/2021 dataOutputStream.writeUTF("getFrnds_" + MainController.getInstance().getGson().toJson(currentAccLoggedIn.getFrnds())); dataOutputStream.flush(); - for (String frndUN :MainController.getInstance().getGson().fromJson(dataInputStream.readUTF() , LinkedList.class)) { + for (String frndUN :currentAccLoggedIn.getFrnds()) { Gamer frndAcc = (Gamer) Account.getAccount(frndUN); Circle circle = new Circle(40); diff --git a/src/com/plato/Controller/Menus/LoginMenuController.java b/src/com/plato/Controller/Menus/LoginMenuController.java index 4b4d5f4..d774b0b 100644 --- a/src/com/plato/Controller/Menus/LoginMenuController.java +++ b/src/com/plato/Controller/Menus/LoginMenuController.java @@ -93,22 +93,31 @@ public void login (ActionEvent actionEvent) throws IOException { AccountController.getInstance().login(username.getText(), password, rememberMe.isSelected()); } catch (MainController.InvalidFormatException e) { e.printStackTrace(); + return; } catch (AccountController.NoAccountExistsWithUsernameException e) { e.printStackTrace(); + return; } catch (AccountController.PaswordIncorrectException e) { - e.printStackTrace(); + System.out.println("password Incorrect"); + return; } catch (AccountController.SuccessfulLogin successfulLogin) { - dataOutputStream.writeUTF("login_" + username.getText() + "_" + password + "_" + "true"); - dataOutputStream.flush(); + + System.out.println("logged In"); successfulLogin.printStackTrace(); } + dataOutputStream.writeUTF("login_" + username.getText() + "_" + password + "_" + "true"); + dataOutputStream.flush(); + dataOutputStream.writeUTF("getCurrentAccLoggedIn_"); dataOutputStream.flush(); - Account account = MainController.getInstance().getGson().fromJson(dataInputStream.readUTF() , Account.class); + + Account account = AccountController.getInstance().getCurrentAccLoggedIn(); + stage.close(); + try { MainMenuController.setGamerOrAdmin(account instanceof Gamer); Stage stage = MainController.getInstance().createAndReturnNewStage( diff --git a/src/com/plato/Controller/Menus/RegisterFormController.java b/src/com/plato/Controller/Menus/RegisterFormController.java index 305151a..62ccf91 100644 --- a/src/com/plato/Controller/Menus/RegisterFormController.java +++ b/src/com/plato/Controller/Menus/RegisterFormController.java @@ -117,7 +117,7 @@ public void signUp (ActionEvent actionEvent) { // public void register (String pfp, String username, String password, String firstName, String lastName, String email, String phoneNum, double initMoney) try { dataOutputStream.writeUTF( - "register" + (Admin.adminHasBeenCreated() ? Gamer.class : Admin.class).getSimpleName() + "_" + + "register_" + (Admin.adminHasBeenCreated() ? Gamer.class : Admin.class).getSimpleName() + "_" + pfp.getImage().getUrl() + "_" + username + "_" + password + "_" + diff --git a/src/com/plato/Controller/Server.java b/src/com/plato/Controller/Server.java index 1cf0970..f436591 100644 --- a/src/com/plato/Controller/Server.java +++ b/src/com/plato/Controller/Server.java @@ -145,7 +145,7 @@ public void run () { // ShipController.getClient().moveShip(BattleSeaEditBoardPageController.getClient().getCurrentBoard(),ship,x,y); // break; case "getCurrentAccLoggedIn": - Account account = AccountController.getInstance().getCurrentAccLoggedIn(); + //Account account = AccountController.getInstance().getCurrentAccLoggedIn(); dataOutputStream.writeUTF(MainController.getInstance().getGson().toJson(account)); dataOutputStream.flush(); break; @@ -170,8 +170,7 @@ public void run () { ReversiController.getInstance().placeDisk(x, y); break; - case "moveShip": - + //case "moveShip": case "ReversinextTurn": ReversiController.getInstance().nextTurn(); break;