Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
All done!
Browse files Browse the repository at this point in the history
  • Loading branch information
duartegithub committed May 13, 2020
1 parent c3d5f3f commit 2ef340b
Showing 1 changed file with 97 additions and 24 deletions.
121 changes: 97 additions & 24 deletions Client/src/main/java/sec/project/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,21 @@ public class Client {
public Client (Map<Integer, ClientAPI> stubs) {

this.scanner = new Scanner(System.in);
System.out.println("\nInsert the client number:");
this.clientNumber = scanner.nextLine();

while(true){

try{
System.out.println("\nInsert the client number:");
this.clientNumber = scanner.nextLine();
Integer.valueOf(this.clientNumber);
} catch (Exception e){
System.out.println("\n-------------------------------------------------------------\n" + "That's not a valid format for a client's number. Please try again.");
continue;
}
break;

}


while (true){
System.out.println("\nInsert your KeyStore's password:");
Expand Down Expand Up @@ -145,23 +158,40 @@ public void execute() {
if((seconds > 1000 || this.numberOfAborts.get() > this.serverPublicKeys.size() / 3)) {
System.out.println("\nUnable to register.");
} else {
System.out.println("\nSuccessful registration.");
System.out.println("\nSuccessfully registered!");
}

this.isRegistering = false;
break;

case "post":

System.out.println("\nWrite your announcement:");
message = scanner.nextLine() + "| ";
if (message.length() > 255) {
System.out.println("\nMessage is too long! Failed post.");
while(true){
System.out.println("\nWrite your announcement:");
message = scanner.nextLine() + "| ";
if (message.length() > 255) {
System.out.println("\nMessage is too long! Please, try again.");
continue;
}
break;
}

System.out.println("\nAny references? Insert like id1 id2 id3. If none just press enter.");
message += scanner.nextLine();
while(true){
System.out.println("\nAny references? Insert like id1 id2 id3. If none just press enter.");
String refs = scanner.nextLine();
String refsAux = " " + refs;
try{
String [] ref = refsAux.split(" ");
for(int i=1; i<ref.length; i++){
Integer.valueOf(ref[i]);
}
} catch (Exception e){
System.out.println("\nThat's not a valid format for the references. Please try again.");
continue;
}
message += refs;
break;
}

this.exception = false;

Expand Down Expand Up @@ -201,15 +231,32 @@ public void execute() {

case "postGeneral":

System.out.println("\nWrite your announcement:");
message = scanner.nextLine() + "| ";
if (message.length() > 255) {
System.out.println("\nMessage is too long! Failed post.");
while(true){
System.out.println("\nWrite your announcement:");
message = scanner.nextLine() + "| ";
if (message.length() > 255) {
System.out.println("\nMessage is too long! Failed post.");
continue;
}
break;
}

System.out.println("\nAny references? Insert like id1 id2 id3. If none just press enter.");
message += scanner.nextLine();
while(true){
System.out.println("\nAny references? Insert like id1 id2 id3. If none just press enter.");
String refs = scanner.nextLine();
String refsAux = " " + refs;
try{
String [] ref = refsAux.split(" ");
for(int i=1; i<ref.length; i++){
Integer.valueOf(ref[i]);
}
} catch (Exception e){
System.out.println("\nThat's not a valid format for the references. Please try again.");
continue;
}
message += refs;
break;
}

this.exception = false;

Expand Down Expand Up @@ -253,18 +300,35 @@ public void execute() {

PublicKey toReadClientPublicKey = null;

try{
while(true){
try{
System.out.println("\nWrite the number of the client whose announcement board you want to read:");
String toReadClientNumber = scanner.nextLine();
Integer.valueOf(toReadClientNumber);
toReadClientPublicKey = AsymmetricCrypto.getPublicKeyFromCert("data/keys/client" + toReadClientNumber + "_certificate.crt");
} catch (NumberFormatException e){
System.out.println("\nThat's not a valid format for a client's number. Please try again.");
continue;
} catch (FileNotFoundException e) {
System.out.println("\nThe client you indicated does not exist. Please try again.");
continue;
}
break;
}

System.out.println("\nWrite the number of the client whose announcement board you want to read:");
toReadClientPublicKey = AsymmetricCrypto.getPublicKeyFromCert("data/keys/client" + scanner.nextLine() + "_certificate.crt");

} catch (FileNotFoundException e){
System.out.println("\nThe client you indicated does not exist.");
while(true){
System.out.println("\nHow many announcements do you want to see?");
numberOfAnnouncements = scanner.nextLine();
try{
Integer.valueOf(numberOfAnnouncements);
} catch (Exception e){
System.out.println("\nThat's not a valid number. Please try again.");
continue;
}
break;
}

System.out.println("\nHow many announcements do you want to see?");
numberOfAnnouncements = scanner.nextLine();

this.exception = false;

Expand Down Expand Up @@ -384,8 +448,17 @@ public void execute() {

case "readGeneral":

System.out.println("\nHow many announcements do you want to see?");
numberOfAnnouncements = scanner.nextLine();
while(true){
System.out.println("\nHow many announcements do you want to see?");
numberOfAnnouncements = scanner.nextLine();
try{
Integer.valueOf(numberOfAnnouncements);
} catch (Exception e){
System.out.println("\nThat's not a valid number. Please try again.");
continue;
}
break;
}

this.exception = false;

Expand Down

0 comments on commit 2ef340b

Please sign in to comment.