CommandTerm v1.1 (securing user input)

This commit is contained in:
SeekDaSky 2017-05-04 12:45:29 +02:00
parent dc7016355a
commit 139de56401
2 changed files with 47 additions and 25 deletions

Binary file not shown.

View File

@ -125,35 +125,55 @@ public class ControlTerminal {
socket.send(p);
System.out.println("Request sent, waiting for response");
}else{
}else if(input.equals("u")){
System.out.println("Please enter plane number");
planeNumber = s.nextInt();
keys = new ArrayList(container.getMap().keySet());
plane = container.getMap().get(keys.get(planeNumber-1));
try{
planeNumber = s.nextInt();
}catch(Exception e){
System.out.println("Wrong input please retry");
s.nextLine();
continue;
}
try{
keys = new ArrayList(container.getMap().keySet());
plane = container.getMap().get(keys.get(planeNumber-1));
}catch(Exception e){
System.out.println("Unknown plane please retry");
s.nextLine();
continue;
}
flags = 0x01;
while(true){
System.out.println("Enter the information you want to update (1: alt,2:cap,3:speed)");
data = s.nextInt();
switch(data){
case 1:
System.out.println("Enter the new altitude");
data = s.nextInt();
plane.setZ(data);
flags = (byte) (flags|0x08);
break;
case 2:
System.out.println("Enter the new cap");
data = s.nextInt();
plane.setCap(data);
flags = (byte) (flags|0x02);
break;
case 3:
System.out.println("Enter the new speed");
data = s.nextInt();
plane.setSpeed(data);
flags = (byte) (flags|0x04);
break;
}
try{
data = s.nextInt();
switch(data){
case 1:
System.out.println("Enter the new altitude");
data = s.nextInt();
plane.setZ(data);
flags = (byte) (flags|0x08);
break;
case 2:
System.out.println("Enter the new cap");
data = s.nextInt();
plane.setCap(data);
flags = (byte) (flags|0x02);
break;
case 3:
System.out.println("Enter the new speed");
data = s.nextInt();
plane.setSpeed(data);
flags = (byte) (flags|0x04);
break;
}
}catch(Exception e){
System.out.println("Wrong input please retry");
s.nextLine();
continue;
}
System.out.println("Do you want to update more data on this plane (y/n)");
if(s.next().equals("n")){
@ -168,6 +188,8 @@ public class ControlTerminal {
socket.send(p);
System.out.println("Request sent, waiting for response");
s.nextLine();
}else{
System.out.println("Unknown command, please retry");
}
}