-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEDI.cs
More file actions
890 lines (790 loc) · 37.7 KB
/
EDI.cs
File metadata and controls
890 lines (790 loc) · 37.7 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
880
881
882
883
884
885
886
887
888
889
890
using Sandbox;
using Sandbox.ModAPI.Ingame;
using Sandbox.ModAPI.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VRage;
using VRageMath;
using CoreOs;
namespace core.edi
{
public class EDI
{
///<SUMMARY>
///
IMyGridTerminalSystem GridTerminalSystem;
const string creator = "Mahtrok";
const string title = "$IOS <EDI> ";
const string version = "v1.0";
const string created = "10-15-15";
const string updated = "10-17-15";
const string contact = "Mahtrok@mahtrok.de";
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Exodus Systems - $IOS - Self installing operating system <EDI>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// ATTENTION: The <EDI> is NOT A STAND-A-LONE Script! You have to install the $IOS <CORE> on your
/// GRID first, or there will not be any blocks that could be managed by this Script.
///
/// After installing the $IOS Core all blocks on your grid should be renamed correct. If the Core doesn't give any
/// Errors or Crashes you can set up the <EDI> Script.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// >>> What is the $IOS <EDI>? <<<
///
/// This Script checks your Platform/Ship Grid (and only yours, even if there are docked ships), identified by a
/// passed in platformID, for any incoming damage through hacking or attacks.
/// Besides that it detects unpressurized AirVents and is able to close doors around this AirVent to prevent further
/// loss of atmospheric pressure.
/// The Script can change the $IOS <CORE>s Condition Managers state and therefor trigger alarms, change light
/// -ing and LCD Colors, start timers, automatically close security doors, deactivate gravity generators and activate
/// turrets to defend all vital systems in case of an attack.
/// The hole $IOS system depends on an external configuration screen that is also used as external data storage.
/// An exact explanation of how this works can be find inside the $IOS <CORE> Scripts Manual.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* >> 1.0 ATTACK & HACKING DEFENCE SETTINGS << */
/// THERE ARE A FEW THINGS TO BE SET UP CORRECT SO READ CAREFULLY!
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// If you want to have a block be controlled automatically when condition orange or red is called you will have
/// to go to this block and adding a divider "|" and the following ID inside the [ ] Brackets at the end of the $IOS
/// info. "|$Sec"
/// For Example an Alarm Block should be called like: "[paltformID|$Spea|$Sec] Sound Block 2"
/// If so, the block will start playing as soon as "condition: red" is called by either this or any other $IOS script.
const char divider = '|';
const string securityID = "$Sec";
/// You can add the "|$Sec" statement to the following blocktypes:
/// >> Doors - will be closed in case of an alert automatically
/// >> Gravity Generators - will be turned off in case of an alert so be sure you want that!
/// >> Lights - will be turned ON in case of an alert (normally for blinking warning lights)
/// >> Sound Blocks - will be playing in case of an alert, stopping when condition: GREEN or ORANGE is set
/// >> Turrets - will be activated in case of a RED alert ( not ORANGE ) and deactivated when GREEN or ORANGE
/// >> Timers - will be STARTED in case of a RED alert ( not ORANGE ) and stopped when GREEN or ORANGE
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// NOTE: If the alarm has been triggered at least One time, you will have to manually reset the program!
/// This has to be done by running the programmable block, providing the argument "secured". Then and
/// ONLY then alarm stops and condition is set to green.
/// If you want to you can set the programmable blocks argument to secured by default then the alarm stops
/// automatically if no damage or hacking is detected any longer.
/// For example if all repairs have been done, after the Intruder has been catched or killed.
/// If you don't want to hear the alarm continuesly you will have to run the program "secured" manually.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* >> 2.0 ANTI DEPRESSURIZATION SETTINGS << */
/// THE $IOS <CORE> renames all AirVents to something like [platformID|$Vent|$0000], [platformID|$Vent|$0001],
/// [platformID|$Vent|$0002] aso. so every AirVent has its unique identifier ("|$0002").
/// You will have to copy this ID and paste it into any surrounding Doors name at the end (before the "]" bracket)
/// You can add as much IDs as you would like to a single door but you do only need 1 AirVent per room
/// (for they all will be not pressurized so you could safe some character space)
/// Example: A door is between AirVent 0000 and 0001 so you could make it [platformID|$Vent|$0000|$0001]
/// Now if any of those rooms will be depressurized the door will close automatically.
/*
AVAILABLE PASS-IN ARGUMENTS:
secured // Resets the <EDI> after a hack or an attack has been detected and secured
*/
///</SUMMARY>
/// <Command API>
const string API_RAISE_ALARM = "API_RAISE_ALARM";
const string API_DISABLE_ALARM = "API_DISABLE_ALARM";
const string API_SHUTDOWN_SHIP = "API_SHUTDOWN_SHIP";
const string API_BOOT_SHIP = "API_BOOT_SHIP";
const string API_DISABLE_BLOCK = "API_DISABLE_BLOCK";
const string API_ENABLE_BLOCK = "API_ENABLE_BLOCK";
const string API_ATTACK_DETECTED = "API_ATTACK_DETECTED";
const string API_ATTACK_DEFENDET = "API_ATTACK_DEFENDET";
const string API_COLLISION_ALERT = "API_ATTACK_DEFENDET";
const string API_STATUS_GREEN = "API_STATUS_GREEN";
const string API_STATUS_ORANGE = "API_STATUS_ORANGE";
const string API_STATUS_RED = "API_STATUS_RED";
const string API_CANT_PRESURISE = "API_CANT_PRESURISE";
const string API_EDI_LOGON = "API_EDI_LOGON";
const string API_EDI_LOGOFF = "API_EDI_LOGOFF";
const string API_TVI_LOGON = "API_TVI_LOGON";
const string API_TVI_LOGOFF = "API_TVI_LOGOFF";
const string API_COM_LOGON = "API_COM_LOGON";
const string API_COM_LOGOFF = "API_COM_LOGOFF ";
/// </Command API>
// << 1.0 BLOCK ID SETTINGS >> //
// To use a Debugger Screen you have to set the desired Screens PUBLIC TITLE to the following ID:
const string debugID = "$IOS <EDI> Debug";
// These Shortcuts will should've been added to your Grids blocks names by the $IOS <CORE> Script.
// If you want to change these IDs you will first have to uninstall the Script from the CORE, then change the IDs in
// EVERY SINGLE Exodus Systems $IOS Script you are using, starting with the CORE and reinstalling it.
const string infoID = "$Info <EDI>";
const string gravID = "$Grav";
const string airVentID = "$Vent";
const string doorID = "$Door";
const string speakerID = "$Spea";
const string lightID = "$Light";
const string panelID = "$LCD";
const string programID = "$Prog";
const string timerID = "$Time";
const string missileID = "$MTur";
const string gatlingID = "$GTur";
const string turretID = "$ITur";
const string coreID = "$IOS <CORE> Mainframe";
const string configID = "$IOS Config";
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// THERE IS NO NEED TO CHANGE ANYTHING BELOW THIS LINE, AS LONG AS YOU DO NOT EXACTLY KNOW //
// WHAT YOU ARE DOING! //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Condition Manager: To define the background and font Color for your LCDs
Color conditionRedBG = new Color(40, 0, 0);
Color conditionOrangeBG = new Color(40, 10, 0);
Color panelDefaultBG = new Color(40, 40, 40);
Color conditionRedFC = new Color(255, 255, 255);
Color conditionOrangeFC = new Color(255, 255, 255);
Color panelDefaultFC = new Color(0, 0, 0);
// Condition Manager: To define the Colors for the Interior Lights
Color conditionRedLight = new Color(255, 0, 0);
Color conditionOrangeLight = new Color(255, 110, 0);
string platformID = "";
const char listDivider = ',';
const char configDivider = '$';
const char suffix = ']';
const string prefix = "[";
bool debugEnabled = false;
bool securityActive = false;
bool hackDetected = false;
bool attackDetected = false;
bool installEnabled = false;
bool hideVersionInfoOnScreen = false;
bool allowBeaconRename = false;
bool booted = false;
List<string> debugMessages;
List<IMyGravityGenerator> gravs;
List<IMyAirVent> airvents;
List<IMySoundBlock> alerts;
List<IMyInteriorLight> lights;
List<IMyDoor> doors;
List<IMyDoor> securityDoors;
List<IMyTextPanel> panels;
List<IMyTextPanel> debugger;
IMyTextPanel config;
List<IMyProgrammableBlock> programs;
List<IMyTimerBlock> timers;
IMyTimerBlock securityTimer;
IMyProgrammableBlock SiosMainframe;
List<IMyLargeInteriorTurret> turrets;
List<IMyLargeGatlingTurret> gatlings;
List<IMyLargeMissileTurret> missiles;
int platformRoleID;
int airVentCnt = 0;
int initLoop = 0;
const string blank = "\n";
const string tab = " ";
const string empty = " ";
string condition = "green";
//////////////////////////////////////////////////////////////////////////////////////////////////////////
/* GETTER */
//////////////////////////////////////////////////////////////////////////////////////////////////////////
string GetTimeStamp()
{
return prefix + System.DateTime.Now.Hour.ToString() + ":"
+ System.DateTime.Now.Minute.ToString() + ":"
+ System.DateTime.Now.Second.ToString() + suffix;
}
string GetVersionInfo()
{
return title + empty + version + " by " + creator + ", last Update: " + updated + blank;
}
string GetDebugInfo()
{
string _info = GetVersionInfo();
for (int i = 0; i < debugMessages.Count; i++)
{
_info += debugMessages[i];
}
return _info;
}
bool IsBeingHacked(IMyTerminalBlock _block)
{
return _block.IsBeingHacked;
}
bool IsBeingAttacked(IMyTerminalBlock _block)
{
IMySlimBlock _slimBlock = _block.CubeGrid.GetCubeBlock(_block.Position);
if (_slimBlock.DamageRatio > 1 || _slimBlock.CurrentDamage > _slimBlock.MaxIntegrity * 0.1f)
{
if (_slimBlock.DamageRatio > 1.66 || _slimBlock.CurrentDamage > _slimBlock.MaxIntegrity * 0.3f)
{
Debug("Heavy Damage detected!");
}
else if (_slimBlock.DamageRatio > 1.33 || _slimBlock.CurrentDamage > _slimBlock.MaxIntegrity * 0.6f)
{
Debug("Medium Damage detected!");
}
else
Debug("Light Damage detected!");
return true;
}
else
return false;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
/* MAIN METHOD */
//////////////////////////////////////////////////////////////////////////////////////////////////////////
void _FindDebugScreen()
{
List<IMyTerminalBlock> _debugs = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyTextPanel>(_debugs);
if (_debugs.Count > 0)
{
for (int i = 0; i < _debugs.Count; i++)
{
if (_debugs[i].CustomNameWithFaction.Contains(debugID))
{
debugger.Add((IMyTextPanel)_debugs[0]);
debugEnabled = true;
}
}
}
}
void _FindConfigScreen()
{
List<IMyTerminalBlock> _configScreens = new List<IMyTerminalBlock>();
// make sure that we only gather TextPanels
GridTerminalSystem.GetBlocksOfType<IMyTextPanel>(_configScreens);
int _screens = 0;
Debug("Screens found:" + _configScreens.Count);
for (int i = 0; i < _configScreens.Count; i++)
{
if (_configScreens[i].CustomName.Contains(configID))
{
_screens++; // there should`nt be more than 1!
config = (IMyTextPanel)_configScreens[i];
Debug("ConfigScreen found who contains the name:" + configID);
Debug("External config file found! Loading DATA...");
LoadExternalConfigData();
}
if (_screens == 0)
{
Debug("No Configscreen found");
}
}
}
bool _FindCoreOS()
{
List<IMyTerminalBlock> _blocks = new List<IMyTerminalBlock>();
// CoreOS has to be a TerminalBlock
GridTerminalSystem.GetBlocksOfType<IMyProgrammableBlock>(_blocks);
for (int i = 0; i < _blocks.Count; i++)
{
if (_blocks[i].CustomName.Contains(coreID))
{
IMyProgrammableBlock _program = (IMyProgrammableBlock)_blocks[i];
SiosMainframe = _program;
return true;
}
}
return false;
}
public void Init()
{
debugMessages = new List<string>();
_FindDebugScreen();
gravs = new List<IMyGravityGenerator>();
airvents = new List<IMyAirVent>();
alerts = new List<IMySoundBlock>();
lights = new List<IMyInteriorLight>();
doors = new List<IMyDoor>();
securityDoors = new List<IMyDoor>();
panels = new List<IMyTextPanel>();
debugger = new List<IMyTextPanel>();
programs = new List<IMyProgrammableBlock>();
timers = new List<IMyTimerBlock>();
turrets = new List<IMyLargeInteriorTurret>();
gatlings = new List<IMyLargeGatlingTurret>();
missiles = new List<IMyLargeMissileTurret>();
if (_FindCoreOS())
SendApiCommand(API_EDI_LOGON);
_FindConfigScreen();
// Calling Core: Hello EDI is active
SendApiCommand(API_EDI_LOGON);
}
void Main(string argument)
{
////////////////////// INITIALIZATION
Init();
///////////////////// DEBUGGER
if (debugEnabled)
DisplayDebug();
////////////////////// GETTING ALL BLOCKs
if (!booted)
GetBlocks();
////////////////////// SECURITY
securityState();
///////////////////// DISPLAY
Display();
///////////////////// RESET SCRIPT
Reset();
initLoop++;
}
void Reset()
{
installEnabled = false;
airVentCnt = 0;
booted = false;
}
void securityState()
{
if (securityActive)
{
Debug("<EDI>: Active");
if (hackDetected || attackDetected)
{
//IMyTerminalBlock CORE = GridTerminalSystem.GetBlockWithName("$IOS CORE");
//core = (IMyProgrammableBlock)CORE;
//core.TryRun("API: attack detected");
}
else
{
Debug("-> Systems: Secured");
}
if (CheckPressureState())
{
Debug("ALERT: Hullbreach detected!");
}
else
{
Debug("-> Pressure: Stable");
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
/* INITIALIZATION */
//////////////////////////////////////////////////////////////////////////////////////////////////////////
void GetBlocks()
{
List<IMyTerminalBlock> _blocks = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyTerminalBlock>(_blocks);
for (int i = 0; i < _blocks.Count; i++)
{
if (_blocks[i].CustomName.Contains(platformID))
{
///////////////////////// CHECK FOR HACKED BLOCKs
if (IsBeingHacked(_blocks[i]))
{
Debug("->" + _blocks[i].CustomName + " is being hacked!");
hackDetected = true;
}
///////////////////////// CHECK FOR DAMAGED BLOCKs
if (IsBeingAttacked(_blocks[i]))
{
Debug("->" + _blocks[i].CustomName + " is damaged!");
attackDetected = true;
}
/////////////////////// GETTING GRAV GENs //////////////////////
if (_blocks[i].CustomName.Contains(gravID) && _blocks[i].CustomName.Contains(securityID))
{
gravs.Add((IMyGravityGenerator)_blocks[i]);
}
/////////////////////// GETTING AIRVENTS //////////////////////
if (_blocks[i].CustomName.Contains(airVentID))
{
IMyAirVent _vent = (IMyAirVent)_blocks[i];
airvents.Add(_vent);
}
////////////////// GETTING ALERT SPEAKERS ////////////////////
if (_blocks[i].CustomName.Contains(speakerID) && _blocks[i].CustomName.Contains(securityID))
{
alerts.Add((IMySoundBlock)_blocks[i]);
}
/////////////////// GETTING INTERIOR LIGHTS ////////////////////
if (_blocks[i].CustomName.Contains(lightID) && _blocks[i].CustomName.Contains(securityID))
{
lights.Add((IMyInteriorLight)_blocks[i]);
}
/////////////////////// GETTING DOORS //////////////////////////
if (_blocks[i].CustomName.Contains(doorID))
{
doors.Add((IMyDoor)_blocks[i]);
if (_blocks[i].CustomName.Contains(securityID))
{
securityDoors.Add((IMyDoor)_blocks[i]);
}
}
///////////////////// GETTING TEXT PANELS /////////////////////
if (_blocks[i].CustomName.Contains(panelID))
{
IMyTextPanel _panel = (IMyTextPanel)_blocks[i];
if (_panel.GetPublicTitle().Contains(debugID))
{
//debugger.Add(_panel);
//debugEnabled = true;
}
else
{
if (!_panel.CustomName.Contains(configID) && _panel.GetPublicTitle() == infoID)
{
_panel.ShowPublicTextOnScreen();
_panel.SetValue("FontSize", 0.8f);
panels.Add(_panel);
}
}
}
////////////////////// GETTING PROGRAMS //////////////////////
if (_blocks[i].CustomName.Contains(programID))
{
IMyProgrammableBlock _program = (IMyProgrammableBlock)_blocks[i];
if (!_program.CustomName.Contains(coreID))
programs.Add(_program);
}
///////////////////// GETTING TIMERBLOCKS ////////////////////
if (_blocks[i].CustomName.Contains(timerID) && _blocks[i].CustomName.Contains(securityID))
{
timers.Add((IMyTimerBlock)_blocks[i]);
}
/////////////////// GETTING GATLING TURRETS /////////////////
if (_blocks[i].CustomName.Contains(gatlingID))
{
gatlings.Add((IMyLargeGatlingTurret)_blocks[i]);
}
if (_blocks[i].CustomName.Contains(missileID))
{
missiles.Add((IMyLargeMissileTurret)_blocks[i]);
}
if (_blocks[i].CustomName.Contains(turretID))
{
turrets.Add((IMyLargeInteriorTurret)_blocks[i]);
}
}
}
booted = true;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
/* EXTERNAL DATA PROCESSING */
//////////////////////////////////////////////////////////////////////////////////////////////////////////
void LoadExternalConfigData()
{
string _file = config.GetPublicText();
if (_file.Contains(configDivider.ToString()))
{
string[] _data = _file.Split(configDivider);
//////////////////////// GETTING PLATFORM ID ////////////////////////////
if (_data.Length > 1)
platformID = _data[1].Replace("platformID: ", "").Replace(blank, "");
if (platformID == "")
{
Debug("<SEC>: No valid platformID found!");
}
Debug("PlatformID: " + platformID);
///////////////////// GETTING PLATFORM ROLE ID /////////////////////////
if (_data.Length > 2)
platformRoleID = int.Parse(_data[2].Replace("platformRoleID: ", "").Replace(blank, ""));
Debug("Platform Role ID: " + platformRoleID.ToString());
//////////////////// GETTING CURRENT CONDITION /////////////////////////
if (_data.Length > 3)
condition = _data[3].Replace("condition: ", "").Replace(blank, "");
Debug("Condition: " + condition);
if (_data.Length > 4)
{
////////////////////// GETTING INSTALL ENABLED /////////////////////////
if (_data[4].ToLower().Contains("true") || _data[4].ToLower().Contains("yes"))
installEnabled = true;
else
installEnabled = false;
Debug("Install Enabled: " + installEnabled.ToString());
}
else ///////////////////////// CORRECTING FORMAT
StoreExternalConfigData();
if (_data.Length > 5)
{
///////////////////// GETTING HIDE VERSION INFO ////////////////////////
if (_data[5].ToLower().Contains("true") || _data[5].ToLower().Contains("yes"))
hideVersionInfoOnScreen = true;
else
hideVersionInfoOnScreen = false;
Debug("Hide Version Info: " + hideVersionInfoOnScreen.ToString());
}
else ///////////////////////// CORRECTING FORMAT
StoreExternalConfigData();
if (_data.Length > 6)
{
/////////////////// GETTING ALLOW BEACON RENAME //////////////////////
if (_data[6].ToLower().Contains("true") || _data[6].ToLower().Contains("yes"))
allowBeaconRename = true;
else
allowBeaconRename = false;
Debug("Allow beacon rename: " + allowBeaconRename.ToString());
}
else ///////////////////////// CORRECTING FORMAT
StoreExternalConfigData();
if (_data.Length > 7)
{
/////////////////// GETTING SECURITY ACTIVE //////////////////////
if (_data[7].ToLower().Contains("true") || _data[7].ToLower().Contains("yes"))
securityActive = true;
else
securityActive = false;
Debug("activate security: " + securityActive.ToString());
}
else ///////////////////////// CORRECTING FORMAT
StoreExternalConfigData();
if (_data.Length > 9)
{
///////////////////////// GET DEFAULT PANEL BG COLOR
string[] _temp = _data[8].Split('}');
_temp[0] = _temp[0].Replace("LCD BG Color: {", "");
string[] _colors = _temp[0].Split(' ');
_colors[0] = _colors[0].Replace("R:", "");
_colors[1] = _colors[1].Replace("G:", "");
_colors[2] = _colors[2].Replace("B:", "");
panelDefaultBG = new Color(int.Parse(_colors[0]), int.Parse(_colors[1]), int.Parse(_colors[2]));
///////////////////////// GET DEFAULT PANEL FONT COLOR
_temp = _data[9].Split('}');
_temp[0] = _temp[0].Replace("LCD Font Color: {", "");
_colors = _temp[0].Split(' ');
_colors[0] = _colors[0].Replace("R:", "");
_colors[1] = _colors[1].Replace("G:", "");
_colors[2] = _colors[2].Replace("B:", "");
panelDefaultFC = new Color(int.Parse(_colors[0]), int.Parse(_colors[1]), int.Parse(_colors[2]));
}
else ///////////////////////// CORRECTING FORMAT
StoreExternalConfigData();
// StoreExternalConfigData ();
}
else
{
///////////////////////// CORRECTING FORMAT
StoreExternalConfigData();
}
SetCondition(condition);
}
void StoreExternalConfigData()
{
/* string _file = "$platformID: " + platformID + blank;
_file += "$programID: " + programID + blank;
_file += "$platformRoleID: " + platformRoleID.ToString() + blank;
_file += "$condition: " + condition + blank;
_file += "$install enabled: " + installEnabled.ToString() + blank;
_file += "$activate security: " + securityActive.ToString() + blank;
_file += "$edi Debug: " + debugEnabled.ToString() + blank;
config.WritePublicText(_file); */
}
void Display()
{
string _info = GetVersionInfo();
if (hideVersionInfoOnScreen)
_info = "";
for (int i = 0; i < panels.Count; i++)
{
panels[i].WritePublicText(_info);
}
}
string GetAirVentID(string _airVentName)
{
string[] _temp = _airVentName.Split(divider);
_temp[2] = _temp[2].Substring(0, 5).Replace("$", "");
return _temp[2];
}
bool CheckPressureState()
{
bool _found = false;
for (int i = 0; i < airvents.Count; i++)
{
if (airvents[i].CustomName.Contains(platformID))
{
if (!airvents[i].IsPressurized())
{
CloseSecurityDoors(GetAirVentID(airvents[i].CustomName));
_found = true;
}
}
}
return _found;
}
void CloseSecurityDoors()
{
for (int i = 0; i < doors.Count; i++)
{
doors[i].GetActionWithName("Open_Off").Apply(doors[i]);
}
}
void CloseSecurityDoors(string _id)
{
for (int i = 0; i < doors.Count; i++)
{
if (doors[i].CustomName.Contains(_id))
{
doors[i].GetActionWithName("Open_Off").Apply(doors[i]);
}
}
}
void StartTimers()
{
for (int i = 0; i < timers.Count; i++)
{
timers[i].GetActionWithName("Start").Apply(timers[i]);
}
}
void StopTimers()
{
for (int i = 0; i < timers.Count; i++)
{
timers[i].GetActionWithName("Stop").Apply(timers[i]);
}
}
void ShutDownGravity()
{
for (int i = 0; i < gravs.Count; i++)
{
gravs[i].GetActionWithName("OnOff_Off").Apply(gravs[i]);
}
}
void ActivateGravity()
{
for (int i = 0; i < gravs.Count; i++)
{
gravs[i].GetActionWithName("OnOff_On").Apply(gravs[i]);
}
}
void ActivateTurrets()
{
for (int i = 0; i < turrets.Count; i++)
{
turrets[i].GetActionWithName("OnOff_On").Apply(turrets[i]);
}
for (int i = 0; i < gatlings.Count; i++)
{
gatlings[i].GetActionWithName("OnOff_On").Apply(gatlings[i]);
}
for (int i = 0; i < missiles.Count; i++)
{
missiles[i].GetActionWithName("OnOff_On").Apply(missiles[i]);
}
}
void DeactivateTurrets()
{
Debug("Deactivating turrets.");
for (int i = 0; i < turrets.Count; i++)
{
turrets[i].GetActionWithName("OnOff_Off").Apply(turrets[i]);
}
for (int i = 0; i < gatlings.Count; i++)
{
gatlings[i].GetActionWithName("OnOff_Off").Apply(gatlings[i]);
}
for (int i = 0; i < missiles.Count; i++)
{
missiles[i].GetActionWithName("OnOff_Off").Apply(missiles[i]);
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
/* CONDITION MANAGEMENT */
//////////////////////////////////////////////////////////////////////////////////////////////////////////
void SetCondition(string _condition)
{
Debug("New Condition: [" + _condition + "]");
switch (_condition)
{
case "green":
condition = _condition;
StopAlerts();
ActivateGravity();
StopBlinking();
StopTimers();
DeactivateTurrets();
StoreExternalConfigData();
break;
case "orange":
condition = _condition;
CloseSecurityDoors();
StopAlerts();
StopTimers();
StartBlinking();
ActivateGravity();
StoreExternalConfigData();
break;
case "red":
condition = _condition;
PlayAlerts();
CloseSecurityDoors();
StartTimers();
StartBlinking();
ShutDownGravity();
ActivateTurrets();
StoreExternalConfigData();
break;
default:
break;
}
}
void StartBlinking()
{
for (int i = 0; i < lights.Count; i++)
{
lights[i].GetActionWithName("OnOff_On").Apply(lights[i]);
}
}
void StopBlinking()
{
for (int i = 0; i < lights.Count; i++)
{
lights[i].GetActionWithName("OnOff_Off").Apply(lights[i]);
}
}
void PlayAlerts()
{
for (int i = 0; i < alerts.Count; i++)
{
alerts[i].GetActionWithName("OnOff_On").Apply(alerts[i]);
alerts[i].GetActionWithName("PlaySound").Apply(alerts[i]);
}
}
void StopAlerts()
{
for (int i = 0; i < alerts.Count; i++)
{
alerts[i].GetActionWithName("StopSound").Apply(alerts[i]);
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
/* API COMMUNICATION */
//////////////////////////////////////////////////////////////////////////////////////////////////////////
bool SendApiCommand(string _msg)
{
Debug("Sending Message to $IOS: " + _msg);
try
{
SiosMainframe.TryRun(_msg);
}
catch (Exception)
{
Debug("Exeption thrown (Command Send): ");
Debug("$IOS Not Available?");
return false;
}
return true;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
/* DEBUGGER */
//////////////////////////////////////////////////////////////////////////////////////////////////////////
void Debug(string _msg)
{
debugMessages.Add(GetTimeStamp() + ": " + _msg + blank);
}
void DisplayDebug()
{
try
{
for (int i = 0; i < debugger.Count; i++)
{
if (debugger[i] != null)
{
debugger[i].ShowPublicTextOnScreen();
debugger[i].SetValue("BackgroundColor", new Color(0, 0, 255));
debugger[i].SetValue("FontColor", new Color(255, 255, 0));
debugger[i].SetValue("FontSize", 0.6f);
debugger[i].WritePublicText(GetDebugInfo());
}
else
throw new ArgumentNullException("Missing Block!");
}
}
catch (NullReferenceException ex)
{
Debug(ex.ToString());
}
}
}
}