From 139de56401853d8c1e90e87a7c8014b056ef3273 Mon Sep 17 00:00:00 2001 From: SeekDaSky Date: Thu, 4 May 2017 12:45:29 +0200 Subject: [PATCH] CommandTerm v1.1 (securing user input) --- command-terminal/commandTerm.jar | Bin 12500 -> 12752 bytes .../src/ControlTerminal/ControlTerminal.java | 72 ++++++++++++------ 2 files changed, 47 insertions(+), 25 deletions(-) diff --git a/command-terminal/commandTerm.jar b/command-terminal/commandTerm.jar index 5b9dddf76e6b2c237a2f0ddb66ecb87e4c19e3b0..562e7b46dc97fd847bd2fca800bd2b94b2a765c1 100644 GIT binary patch delta 3675 zcmY+HcQ_kd8^&W5NxX;^sl8W1?Y&29RE^fI606kKqG*huB2=XI-W099TGXx*wW>j> zRin0|X8X0@b$!?O_MAWNbDr}%_jR80-#zItiUi*>AR}i4P*G6<5}a{h4Bn6zPP&P# z58<66`=e%poL7KkM`f&d|J^)T>0Qi^erh7$D>b^ek@^WNFRCYs_K*S*5ev>E#fB8{(z zbd;8#K$lD#p1xAZ7+I5L_unbV8YZ;1ZmfRR4eZF0_MG7w{prWKmh0c)|8wmq>=k?1 zF<1C~bA%QTw({T{oBze;6{V62N|j)vylxkhlGLtmQ^^z}V;{1goO-)$mJ1w6c=f`v z)y>K?%;uo=JKacZ= zud(?9pYE2b^B1Q)H_TFw{#6Ds9a2$!=8NcB5_03Rth}gxtSI)*1Q+LkMpaoqGqz{j zc`z1rWF2q8VtwgFn9Zk9SyIt$fU)P&IfQQe+9HrsHwnwgN_K)4LDcPf6wRrmt{`Cf z8<6#J8Ri;vDCVpOYjW3|xGeq>c_ZrU!)pB8)dA3oTv~Qo;(odilC&rTZPIsNK8K5v zd~j%LMIo8BXu;4W)6r1|rK3x-$cP^*yV~b3qvb*Co`dKNY4j@YiO3FMbgaV`cF2Ui zadS>9u!xzRIn2j68gdI|ei{P6z%xR6MjD=w5y^sb?LPAnzT%elHfE=k#E3VSp(P?N z_XK(%bTwE%a{&wCo{Zr$MYwwy_xsz~WFt|Ga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wAJ&F`gro? z?M1Y2pusYnDezO2Xtc`dHjv}j1g>Z6RPU zWmVcpi=RPaZkrX9jqo34vE0-5z|Op@QvV1ozD^Mz!mFsH@*U6YqbkW(1B;=(&`0Z{ zK-svl`gC-#WKrLpk9b!h@ij5SO%kSTed~-?DFIrxSx6f^((})REYOCS;~0ZzPOILu zmlK{nZVD4ezTH!Li>S0~jqMH>FxX=P?STx0dzf02wObQB0}7;qg!s~OcPm<&(@{r2 zWr26)+*xBRG%u{*9Lttr1ixSNF1;1|RrwQDfJS;KO!a#w-AwYkuX+wf!+VdnEFBE0 z-9#_<98#_a6ol2hNI8i7n?Jw|RcpJyZ>53$*SpWYAxd!4>A@P^~(iCK3Pu diff --git a/command-terminal/src/ControlTerminal/ControlTerminal.java b/command-terminal/src/ControlTerminal/ControlTerminal.java index b0f1765..fea2a93 100644 --- a/command-terminal/src/ControlTerminal/ControlTerminal.java +++ b/command-terminal/src/ControlTerminal/ControlTerminal.java @@ -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"); } }