-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHackingMinigame.java
More file actions
879 lines (766 loc) · 27.9 KB
/
Copy pathHackingMinigame.java
File metadata and controls
879 lines (766 loc) · 27.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
import java.util.Scanner;
/*
-Escape sequences were found at:
https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797
*/
//Object
class queryIP {
public String address;
public String location;
public int time;
public int successRate, detectionRate, latency, securityLevel;
public boolean knownLocation;
/**
* Constructs an empty IP object
*/
public queryIP() {
address = null;
location = null;
knownLocation = false;
latency = 0;
successRate = 0;
time = 0;
securityLevel = 0; //(1 to 5; 1 = Weak, 2 = Low, 3 = Normal, 4 = Strong, 5 = Secure)
}
/**
* Calculates the risk for the given ip object
* @param - none
* @return - none
*/
private void calculateRisks() {
int failureRate = (int) Math.pow(latency/15,1.65);
successRate = Math.max(100-failureRate,0);
time = (latency/10);
}
/**
* Finds the security level of the ip (can't be found using a formula)
* @param - base security level
* @return - the security level as an int
*/
private void findSecurityLevel(int baseLevel) {
if (baseLevel > 3) {
securityLevel++;
securityLevel = Math.min(securityLevel, 5);
}
else if (baseLevel < 3) {
securityLevel--;
}
}
/**
* Gives an it's attributes based on it's predefined location
* @param - location; the location of the ip
* @return - returns the ip
*/
public String assignAttributes(String location) {
String ip = "";
switch (location) {
//(10 - 50)
case "Evalia":
ip += "106";
latency = (int) (Math.random() * 40 + 10);
detectionRate = (int) (Math.random() * 30 + 15);
securityLevel = 4;
break;
//(35 - 105)
case "Alxaco":
ip += "052";
latency = (int) (Math.random() * 70 + 35);
detectionRate = (int) (Math.random() * 15 + 15);
securityLevel = 3;
break;
//(40 - 90)
case "Wehntyr":
ip += "897";
latency = (int) (Math.random() * 50 + 40);
detectionRate = (int) (Math.random() * 20 + 10);
securityLevel = 4;
break;
//(60 - 120)
case "Asquence":
ip += "763";
latency = (int) (Math.random() * 60 + 60);
detectionRate = (int) (Math.random() * 15 + 15);
securityLevel = 3;
break;
//(80 - 150)
case "Kiroah":
ip += "267";
latency = (int) (Math.random() * 70 + 80);
detectionRate = (int) (Math.random() * 12 + 8);
securityLevel = 3;
break;
//(100 - 210)
case "Iunefriss":
ip += "674";
latency = (int) (Math.random() * 110 + 100);
detectionRate = (int) (Math.random() * 12);
securityLevel = 2;
break;
//(150 - 230)
case "Veyleigh":
ip += "883";
latency = (int) (Math.random() * 80 + 150);
detectionRate = (int) (Math.random() * 7);
securityLevel = 2;
break;
}
ip += "." + (int) (Math.random() * 99) + "." + (int) (Math.random() * 999) + "." + (int) (Math.random() * 99);
address = ip;
calculateRisks();
findSecurityLevel(securityLevel);
return ip;
}
/**
* Generates a random location based on the set difficulty
* @param - dif; the set difficulty
* @return - the location as a string
*/
public static String randomLocation(int dif) {
int rand = (int) (Math.random() * (dif + 2) );
switch (rand) {
case 0:
return "Evalia";
case 1:
return "Alxaco";
case 2:
return "Wehntyr";
case 3:
return "Asquence";
case 4:
return "Kiroah";
case 5:
return "Iunefriss";
case 6:
return "Veyleigh";
}
return null;
}
}
public class HackingMinigame {
private static boolean doRandomDifficulty = true;
private static int difficulty = 0;
//Hacking Minigame
private static int timeRemaining = 0;
private static int verificationAttempts = 3;
private static int minigameSection = 1;
private static queryIP connectedIP;
private static String[] sequences;
private static String objective = "USE LIST COMMANDS TO GET INFO.";
private static Scanner input = new Scanner(System.in);
private static boolean connectionVerified = false, failed = false;
private static queryIP[] queryIPS;
private static boolean completed = false;
/**
* Sets the difficulty for the minigames and IPs for the hacking minigame
* @param - none
* @return - none
*/
public static void setMinigame() {
System.out.println("Which difficulty would you like?\nFOR ALL DECISIONS TYPE THE NUMBER");
while (true) {
System.out.println("1. Easy\n2. Medium\n3. Difficult\n4. Extreme\n5. Insanity");
// System.out.println("1. I'm here for the story\n2. Don't want to try too hard.\n3. I want a challenge\n4. I think I'm better than others so I do this difficulty\n5. I'm a maco");
int action = input.nextInt();
if (action >= 1 && action <= 5) {
difficulty = action;
break;
}
else {
System.out.print("Decision not avaliable");
}
}
//Sets up the IPS
queryIPS = new queryIP[difficulty + 3 + (difficulty/2)];
makeIPs();
//Sets time
timeRemaining = 150 - (difficulty*10);
verificationAttempts -= (int) (difficulty * (2.0/5));
// System.out.println(verificationAttempts);
System.out.print("\033[2J\033[H");
}
/**
* Prints out an empty terminal line; used for whitespace
* @param - none
* @return - none
*/
private static void terminalLine() {
System.out.println("-\t\t\t\t\t\t-");
}
/**
* Prints out a terminal line from the parameter
* @param - s, message printed in terminal
* @return - none
*/
private static void terminalLine(String s) {
String line = "- " + s;
int tabs = 5;
tabs -= (int) (s.length()/7);
for (int i = 0; i <= tabs; i++) {
line += "\t";
}
if (tabs <= 0) {
line += "\t";
}
line += "-";
System.out.println(line);
}
/**
* Adds a line to an already displayed terminal
* @param - s, message added to terminal
* @return - none
*/
private static void addLine(String s) {
System.out.print("\033[1A\033[0J");
terminalLine(s);
System.out.println("=================================================");
}
/**
* Erases the previous line in the terminal
* @param - none
* @return - none
*/
private static void clearPreviousLine() {
System.out.print("\033[2A\033[0K");
addLine("");
}
/**
* Clears multiple lines
* @param - num; amount of lines that are cleared
* @return - none
*/
private static void clearLines(int num) {
for (int i = num; i > 0; i--) {
clearPreviousLine();
}
}
/**
* Displays the terminal for the user to use
* @param - none
* @return - none
*/
private static void displayTerminal() {
System.out.println("=================================================");
terminalLine("COMMANDS");
terminalLine();
//Active Commands
terminalLine("*UPLINK_CONNECT");
terminalLine("*UPLINK_VERIFY (KEYWORD)");
terminalLine("*ADMIN_ACCESS (PASS)");
terminalLine("*VERIFY_ACCESS (KEYWORD)");
terminalLine("*PING (IP)");
terminalLine("*CONNECT (IP)");
terminalLine("*DEPLOY_PROBES (TIMING)");
//Passive Commands
terminalLine("*LIST_IPS");
terminalLine("*LIST_TIMINGS");
terminalLine("*LIST_LOCATIONS");
terminalLine("*COMMANDS");
terminalLine("*TIME TILL DETECTION: " + timeRemaining);
terminalLine("*OBJECTIVE: " + objective);
for (int i = 5; i > 0; i--) {
terminalLine();
}
System.out.println("=================================================");
// System.out.print("\033[2A\033[2C>");
}
/**
* This method is used to process the user input and commands
* @param - none
* @return - none
*/
private static void terminal() {
System.out.print("\033[2A\033[2C>");
Scanner s1 = new Scanner(System.in);
String action = s1.nextLine();
clearLines(2);
addLine(">" + action);
addLine("");
if (action.indexOf("UPLINK_CONNECT") == 0) {
if (connectedIP == null) {
addLine("CONNECTION HAS NOT BEEN ESTABLISHED");
}
else if (sequences == null) {
uplinkConnect();
}
else if (connectionVerified) {
addLine("CONNECTION HAS BEEN ESTABLISHED");
}
else {
sequences = null;
// addLine("VERIFICATION HAS STARTED");
}
}
else if (action.indexOf("UPLINK_VERIFY") == 0) {
addLine("CONNECTION HAS NOT BEEN ESTABLISHED");
}
else if (action.indexOf("PING") == 0 || action.indexOf("CONNECT") == 0) {
String ip = action.substring(action.indexOf(" ")+1);
boolean isPing = (action.indexOf("PING") == 0);
boolean validIP = false;
for (queryIP IP : queryIPS) {
if (ip.equals(IP.address)) {
if (isPing) {
ping(IP);
}
else {
connect(IP);
}
validIP = true;
}
}
if (!validIP) {
addLine("INVALID IP");
}
if (minigameSection == 2 && isPing) {
objective = "CONNECT TO AN IP";
minigameSection++;
}
else if (minigameSection == 3 && !isPing && connectedIP != null) {
objective = "USE UPLINK_CONNECT";
minigameSection++;
}
}
else if (action.equals("LIST_IPS")) {
for (queryIP ip : queryIPS) {
if (ip.address != null && ip.location != null) {
addLine("IP >" + ip.address);
if (ip.knownLocation) {
addLine("LOCATION >" + ip.location);
addLine("Ping >" + ip.latency + "ms");
addLine("Packet Loss >" + (100 - ip.successRate) + "%");
}
else {
addLine("LOCATION >???");
}
addLine("");
}
}
if (minigameSection == 1) {
objective = "PING AN IP";
minigameSection = 2;
}
}
else if (action.equals("LIST_TIMINGS")) {
addLine("How aggressively device scans network");
addLine("T0: Paranoid");
addLine("T1: Stealthy");
addLine("T2: Polite");
addLine("T3: Normal");
addLine("T4: Aggressive");
addLine("T5: Insane");
addLine("T0: Extremely slow; good for evading systems");
addLine("Detection Rate: None");
addLine("Time Taken: Very High (~50s)");
addLine("");
addLine("T1: Slow; also good for evasion");
addLine("Detection Rate: Low");
addLine("Time Taken: High (~40s)");
addLine("");
addLine("T2: Slows down scan; susceptible to systems");
addLine("Detection Rate: Medium");
addLine("Time Taken: Medium (~25s)");
addLine("");
addLine("T3: Default Speed");
addLine("Detection Rate: High");
addLine("Time Taken: Medium (~15s)");
addLine("");
addLine("T4: Faster scan");
addLine("Detection Rate: High");
addLine("Time Taken: Low (~10s)");
addLine("");
addLine("T5: Fastest scan but most risky");
addLine("Detection Rate: Very High");
addLine("Time Taken: Very Low (~5s)");
}
else if (action.equals("LIST_LOCATIONS")) {
addLine("> Evalia: The capital of the country");
addLine("> Alexco: A country in rebellion due to");
addLine(" two twin brothers fighting");
addLine("> Wehtynr: Active military complex located");
addLine(" north used for experimental weaponary.");
addLine("> Asquence: The city in the skies");
addLine("> Kiroah: A large desert covered by");
addLine(" small villages in a rebellion.");
addLine("> Iunefriss: Abandoned cyberpunk city");
addLine(" devastated by The Plague");
addLine("> Veyleigh: Located near Iunefriss, this is");
addLine(" a bustling trade hub");
addLine("");
printLocations("Evalia","High",110);
printLocations("Alexco","Medium",380);
printLocations("Wehtynr","High",520);
printLocations("Asquence","Medium",1380);
printLocations("Kiroah","Medium",1120);
printLocations("Iunefriss","Low",2150);
printLocations("Veyleigh","Low",2760);
}
else if (action.indexOf("DEPLOY_PROBES") == 0) {
String timing = action.substring(action.indexOf(" ") + 1);
if (timing.length() > 2) {
addLine("INVALID TIMING");
}
else if (connectionVerified) {
deployProbes(timing);
}
else {
addLine("NO VERIFIED CONNECTION");
}
}
else if (action.equals("COMMANDS")) {
addLine(" ALL TERMINAL COMMANDS");
addLine("*UPLINK_CONNECT");
addLine("*UPLINK_VERIFY (KEYWORD)");
addLine("*ADMIN_ACCESS (PASS)");
addLine("*VERIFY_ACCESS (KEYWORD)");
addLine("*PING (IP)");
addLine("*CONNECT (IP)");
addLine("*DEPLOY_PROBES (TIMING)");
addLine("*LIST_IPS");
addLine("*LIST_TIMINGS");
addLine("*LIST_LOCATIONS");
addLine("");
addLine("");
}
else {
addLine("INVALID COMMAND");
}
addLine("");
addLine("TIME REMAINING: " + timeRemaining);
addLine("OBJECTIVE: " + objective);
addLine("");
if (timeRemaining <= 0) {
failed = true;
}
}
/**
* Used for the LOCATIONS command; makes the displaying easier
* @param - location, security, distance; all are printed in the terminal
* @return - none
*/
private static void printLocations(String location, String security, int distance) {
addLine("*" + location);
addLine("Security: " + security);
addLine("Distance: " + distance + " miles");
addLine("");
}
/**
* Used for to process the UPLINK_VERIFY command to determine
* if the user is correct
* @param - the correct word in the random list
* @return - boolean; returns whether the user was correct or not
*/
private static boolean uplinkVerify(String correct) {
System.out.print("\033[2A\033[2C>");
Scanner s1 = new Scanner(System.in);
String action = s1.nextLine();
String cmd = "UPLINK_VERIFY " + correct;
while (action.indexOf("UPLINK_VERIFY") < 0) {
addLine("USE UPLINK_VERIFY (word)");
addLine("");
System.out.print("\033[2A\033[2C>");
action = s1.nextLine();
cmd = "UPLINK_VERIFY " + correct;
clearPreviousLine();
clearPreviousLine();
}
addLine(">" + action);
addLine("");
return action.equals(cmd);
}
/**
* Used for the UPLINK_CONNECT command and leads to the uplinkVerify method
* @param - none
* @return - none
*/
private static void uplinkConnect() {
addLine("CONNECTING TO PROXY SERVER " + connectedIP.address);
StoryText.sleep(2000);
clearPreviousLine();
addLine("VERIFICATION FAILED");
StoryText.sleep(2000);
clearPreviousLine();
addLine("MANUAL VERIFICATION NEEDED");
StoryText.sleep(2000);
clearPreviousLine();
int numOfSequences = connectedIP.securityLevel + (difficulty/2);
int numOfDupes = (connectedIP.securityLevel + difficulty/2);
int attempts = verificationAttempts;
sequences = createVerification(numOfSequences);
String s = "";
for (String seq : sequences) {
s += seq + " ";
}
addLine("You will be given a sequence (ie. 6x3)");
addLine("Words are shown with the sequences.");
addLine("EX: 6x3 - TEST");
addLine("9x6 - TIME");
addLine("Use UPLINK_VERIFY and type correct word.");
addLine("EX: UPLINK_VERIFY TEST");
addLine("Remember this sequence.");
addLine("Verification Sequence:");
addLine(s);
Scanner s1 = new Scanner(System.in);
s1.nextLine();
clearLines(2); //Needed Later
String[] wordList = {"TEST","ALFA","BETA","ECHO","GOLF","WORD","FLOW","LIMA","FILE","KILO","MIKE","PAPA","TIME","GONE","DEAD","FIRE","ACED","USED","THIS","SUCK","QUIT","JUMP","EVIL","EVEN","ZULU","NONE","NULL","NILL"};
for (int i = 0; i < numOfSequences; i++) {
String correct = "";
int wordPos = (int) (Math.random() * numOfDupes);
String[] usedWords = new String[numOfDupes];
for (int j = 0; j < numOfDupes; j++) {
if (wordPos == j) {
int randPos = (int) (Math.random() * wordList.length);
correct = randomUniqueWord(wordList, usedWords);
usedWords[j] = correct;
addLine(sequences[i] + " - " + correct);
}
else {
int randPos = (int) (Math.random() * wordList.length);
String randWord = randomUniqueWord(wordList, usedWords);
usedWords[j] = randWord;
addLine(generateUniqueSequence() + " - " + randWord);
}
}
addLine("");
boolean complete = false;
complete = uplinkVerify(correct);
clearLines(numOfDupes + 2);
if (!complete) {
verificationAttempts--;
addLine("VERIFICATION FAILED");
addLine("ATTEMPTS REMAINING: " + verificationAttempts);
if (verificationAttempts <= 0) {
failed = true;
}
sequences = null;
return;
}
}
connectionVerified = true;
addLine("CONNECTION VERIFIED");
objective = "LIST T-TIMINGS";
}
/**
* Loops through the getWord method until a unique word is provided
* @param - wordList: array containing the avaliable list of words
* @param - usedWords: The words already used
* @return - a random word from the given list of words
*/
private static String randomUniqueWord(String[] wordList, String[] usedWords) {
String randomWord = null;
while (randomWord == null) {
randomWord = getWord(wordList, usedWords);
}
return randomWord;
}
/**
* Generates a random unique word for the minigame
* @param - wordList: array containing the avaliable list of words
* @param - usedWords: The words already used
* @return - a random word from the given list of words
*/
private static String getWord(String[] wordList, String[] usedWords) {
int rand = (int) (Math.random() * wordList.length);
String randomWord = wordList[rand];
for (String word : usedWords) {
if (randomWord.equals(word)) {
return null;
}
}
return randomWord;
}
/**
* Generates a unique sequence using the createSequence method
* @param - none
* @return - returns the sequence
*/
private static String generateUniqueSequence() {
String generatedSequence = "";
boolean isDupe = true;
while (isDupe) {
generatedSequence = createSequence();
isDupe = false;
for (String sequence : sequences) {
if (sequence.equals(generatedSequence)) {
isDupe = true;
}
}
}
return generatedSequence;
}
private static void deployProbes(String timing) {
int detectionChance = 0, timeUsed = 0;
boolean successful;
if (timing.equals("T0") || timing.equals("0")) {
successful = probeResult(0.0, 50);
}
else if (timing.equals("T1") || timing.equals("1")) {
successful = probeResult(0.1, 40);
}
else if (timing.equals("T2") || timing.equals("2")) {
successful = probeResult(0.25, 25);
}
else if (timing.equals("T3") || timing.equals("3")) {
successful = probeResult(0.65, 15);
}
else if (timing.equals("T4") || timing.equals("4")) {
successful = probeResult(0.8, 10);
}
else if (timing.equals("T5") || timing.equals("5")) {
successful = probeResult(0.95, 5);
}
else {
addLine("INVALID TIMING");
return;
}
if (!successful) {
failed = true;
}
else {
completed = true;
}
}
private static boolean probeResult(double detection, int time) {
timeRemaining -= time;
return (detection < Math.random());
}
/**
* Creates a the series of verification sequences
* @param - num: amount of sequences
* @return - array of the sequences
*/
private static String[] createVerification(int num) {
String[] sequences = new String[num];
for (int i = 0; i < num; i++) {
sequences[i] = createSequence();
}
return sequences;
}
/**
* Creates a sequence based on the difficulty and provided characters
* @param - none
* @return - given sequence
*/
private static String createSequence() {
//1 = 2 char & 6 aval. char.
//2-3 = 3 char & 8 aval. char.
//4-5 = 4 char & 10 aval. char.
int seqLen = (difficulty/2) + 2;
int charLimit = ((difficulty/2)*2) + 5;
char[] l = {'x','X','y','Y','z','Z' , 'w','W' , 'v','V'};
String sequence = "";
if (difficulty < 5) {
for (int i = 0; i < seqLen; i++) {
if (i % 2 == 0) {
int rand = (int) (Math.random() * charLimit);
sequence += "" + l[rand];
}
else {
sequence += "" + (int) (Math.random() * 9);
}
}
}
else {
for (int i = 5; i > 0; i--) {
double choice = Math.random();
if (choice > 0.5) {
int rand = (int) (Math.random() * charLimit);
sequence += "" + l[rand];
}
else {
sequence += "" + (int) (Math.random() * 9);
}
}
}
return sequence;
}
/**
* Used for the CONNECT command; testes whether ip is valid and tests connection
* @param - ip: the ip the user inputs
* @return - none
*/
private static void connect(queryIP ip) {
int latency = ip.latency;
int successRate = ip.successRate;
timeRemaining -= ip.time;
int detection = ip.detectionRate;
int connectRepeat = (latency/10) + 10;
boolean successfulConnection = ((int) (Math.random()*100)) < successRate;
boolean notDetected = ((int) (Math.random() * 100)) > detection;
for (int i = connectRepeat; i >= 0; i--) {
if (i % 3 == 0) {addLine("CONNECTING TO " + ip.address + ".");}
else if (i % 3 == 1) {addLine("CONNECTING TO " + ip.address + "..");}
else {addLine("CONNECTING TO " + ip.address + "...");}
StoryText.sleep(200);
clearPreviousLine();
}
if (notDetected && successfulConnection) {
addLine("CONNECTED TO " + ip.address);
connectedIP = ip;
}
else {
if (!successfulConnection) {
addLine("FAILED TO ESTABLISH CONNECTION!");
}
else {
addLine("DETECTED!");
failed = true;
}
}
}
/**
* Used for the PING command; shows and saves the location, latency,
* failure rate (packet loss), and detection rate attributes of an ip.
* @param - ip: reference for queryIP object
* @return - none
*/
private static void ping(queryIP ip) {
int latency = ip.latency;
int packetLoss = 100 - ip.successRate;
timeRemaining -= ip.time;
int detection = ip.detectionRate;
addLine("PINGING " + ip.address + " with 32 bytes of data:");
for (int i = 4; i > 0; i--) {
int randLat = latency + (int) (Math.random() * 3);
StoryText.sleep(latency*3);
addLine("Reply from " + ip.address + ": bytes=32 time=" + randLat);
}
addLine("");
addLine("LATENCY: " + latency + "ms PACKET LOSS: " + packetLoss + "%");
addLine("DETECTION RISK: " + detection);
addLine("LOCATION: " + ip.location);
ip.knownLocation = true;
}
/**
* Creates a list of ips based on the difficulty
* @param - none
* @return - none
*/
private static void makeIPs() {
for (int i = queryIPS.length-1; i >= 0; i--) {
String loc = queryIP.randomLocation(difficulty);
queryIP newIP = new queryIP();
newIP.assignAttributes(loc);
newIP.location = loc;
queryIPS[i] = newIP;
}
}
/**
* Used to start the hacking minigame and display the terminal
* @param - none
* @return - none
*/
public static boolean start() {
displayTerminal();
while (!failed && !completed) {
terminal();
}
return completed;
}
// public static void quickTime() {
// }
// public static void aimGame() {
// }
// public static void breathing() {
// }
}