CommandTerm v1.1 (securing user input)
This commit is contained in:
parent
dc7016355a
commit
139de56401
Binary file not shown.
|
@ -125,35 +125,55 @@ public class ControlTerminal {
|
||||||
socket.send(p);
|
socket.send(p);
|
||||||
System.out.println("Request sent, waiting for response");
|
System.out.println("Request sent, waiting for response");
|
||||||
|
|
||||||
}else{
|
}else if(input.equals("u")){
|
||||||
System.out.println("Please enter plane number");
|
System.out.println("Please enter plane number");
|
||||||
planeNumber = s.nextInt();
|
try{
|
||||||
keys = new ArrayList(container.getMap().keySet());
|
planeNumber = s.nextInt();
|
||||||
plane = container.getMap().get(keys.get(planeNumber-1));
|
}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;
|
flags = 0x01;
|
||||||
while(true){
|
while(true){
|
||||||
System.out.println("Enter the information you want to update (1: alt,2:cap,3:speed)");
|
System.out.println("Enter the information you want to update (1: alt,2:cap,3:speed)");
|
||||||
data = s.nextInt();
|
try{
|
||||||
switch(data){
|
data = s.nextInt();
|
||||||
case 1:
|
switch(data){
|
||||||
System.out.println("Enter the new altitude");
|
case 1:
|
||||||
data = s.nextInt();
|
System.out.println("Enter the new altitude");
|
||||||
plane.setZ(data);
|
data = s.nextInt();
|
||||||
flags = (byte) (flags|0x08);
|
plane.setZ(data);
|
||||||
break;
|
flags = (byte) (flags|0x08);
|
||||||
case 2:
|
break;
|
||||||
System.out.println("Enter the new cap");
|
case 2:
|
||||||
data = s.nextInt();
|
System.out.println("Enter the new cap");
|
||||||
plane.setCap(data);
|
data = s.nextInt();
|
||||||
flags = (byte) (flags|0x02);
|
plane.setCap(data);
|
||||||
break;
|
flags = (byte) (flags|0x02);
|
||||||
case 3:
|
break;
|
||||||
System.out.println("Enter the new speed");
|
case 3:
|
||||||
data = s.nextInt();
|
System.out.println("Enter the new speed");
|
||||||
plane.setSpeed(data);
|
data = s.nextInt();
|
||||||
flags = (byte) (flags|0x04);
|
plane.setSpeed(data);
|
||||||
break;
|
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)");
|
System.out.println("Do you want to update more data on this plane (y/n)");
|
||||||
|
|
||||||
if(s.next().equals("n")){
|
if(s.next().equals("n")){
|
||||||
|
@ -168,6 +188,8 @@ public class ControlTerminal {
|
||||||
socket.send(p);
|
socket.send(p);
|
||||||
System.out.println("Request sent, waiting for response");
|
System.out.println("Request sent, waiting for response");
|
||||||
s.nextLine();
|
s.nextLine();
|
||||||
|
}else{
|
||||||
|
System.out.println("Unknown command, please retry");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue