This repository was archived by the owner on Aug 21, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainForm.cs
More file actions
1201 lines (1183 loc) · 54 KB
/
MainForm.cs
File metadata and controls
1201 lines (1183 loc) · 54 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
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System.Diagnostics;
namespace Minecraft_Server_GUI
{
public partial class MainForm : Form
{
#region Form Definition
AboutBox about = new AboutBox();
License license = new License();
GetServer getServer = new GetServer();
#endregion
#region Other Definitions
StreamWriter? inputWriter;
public static bool newServer = false;
private static bool startServerOnStart = false;
public static string serverPath = Settings1.Default.serverPath;
#endregion
public MainForm(bool forceGetValue)
{
InitializeComponent();
if (!Settings1.Default.licenseShown)
{
// Show the license dialog if the user has not seen the license dialog yet
license.ShowDialog();
}
if (!Settings1.Default.startServerOnStart)
{
MessageBox.Show("This application is very early in development.\nExpect missing functionality and bugs.\nIf you have any issues make sure to open an issue in the github at:\nhttps://github.com/Soniczac7/Minecraft-Server-GUI/issues", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
startServerOnStart = true;
}
if (serverPath == null || serverPath == "")
{
// If the user has not navigated to a server before then show open server dialog
getServer.ShowDialog();
serverPath = GetServer.serverPath;
newServer = GetServer.newServer;
}
Initialize();
}
internal void Initialize()
{
if (newServer)
{
string[] eula = new string[]{
"#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://account.mojang.com/documents/minecraft_eula).",
"#Wed Apr 13 18:25:21 BST 2022",
"eula = true"
};
string[] defaultProperties = new string[]
{
"#Minecraft server properties",
"#Tue Apr 19 14:56:11 BST 2022",
"spawn-protection=0",
"generator-settings=",
"force-gamemode=false",
"allow-nether=true",
"gamemode=0",
"broadcast-console-to-ops=true",
"enable-query=false",
"player-idle-timeout=0",
"difficulty=1",
"spawn-monsters=true",
"op-permission-level=4",
"resource-pack-hash=",
"announce-player-achievements=true",
"pvp=true",
"snooper-enabled=true",
"level-type=DEFAULT",
"hardcore=false",
"enable-command-block=false",
"max-players=16",
"network-compression-threshold=256",
"max-world-size=29999984",
"server-port=25565",
"debug=false",
"server-ip=",
"spawn-npcs=true",
"allow-flight=false",
"level-name=world",
"view-distance=10",
"resource-pack=",
"spawn-animals=true",
"white-list=false",
"generate-structures=true",
"online-mode=true",
"max-build-height=256",
"level-seed=",
"enable-rcon=false",
"motd=A Minecraft Server!"
};
try
{
FileStream eulaFile = File.Create(serverPath + "eula.txt");
eulaFile.Close();
FileStream propertiesFile = File.Create(serverPath + "server.properties");
propertiesFile.Close();
File.WriteAllLines(serverPath + "eula.txt", eula);
File.WriteAllLines(serverPath + "server.properties", defaultProperties);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Debug.WriteLine(ex.Message);
Debug.WriteLine(ex.StackTrace);
return;
}
DialogResult result = MessageBox.Show("Would you like to start your server with default settings?", "Start Server?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
startServerOnStart = true;
}
}
if (serverPath == null || serverPath == "")
{
// If there is no server specified then finish loading
toolStripProgressBar1.Style = ProgressBarStyle.Blocks;
toolStripStatusLabel1.Text = "Done!";
return;
}
// A server has been specified and loading will continue
toolStripStatusLabel1.Text = "Loading: " + serverPath + "server.properties";
console.AppendText("[Server] Reading server.properties");
try
{
// Read all lines of server.properties
string[] serverProperties = File.ReadAllLines(serverPath + "server.properties");
// Process spawn-protection
string spawnprotectionSetting = serverProperties[2];
if (spawnprotectionSetting.Contains("spawn-protection"))
{
Debug.WriteLine("Found spawn-protection");
string spawnprotection;
spawnprotection = spawnprotectionSetting.Remove(0, 17);
Debug.WriteLine("spawn-protection value is " + spawnprotection);
decimal spawnprotectionValue = Convert.ToDecimal(spawnprotection);
spawnProtection.Value = spawnprotectionValue;
}
else
{
// spawn-protection line did not contain "spawn-protection"
Debug.WriteLine("Failed to find spawn-protection");
console.AppendText("\n[Error] Failed to find spawn-protection in server.properties");
}
// Process generator-settings
string generatorsettingsSetting = serverProperties[3];
if (generatorsettingsSetting.Contains("generator-settings"))
{
Debug.WriteLine("Found generator-settings");
string generatorsettings;
generatorsettings = generatorsettingsSetting.Remove(0, 19);
Debug.WriteLine("generator-settings value is " + generatorsettings);
generatorSettings.Text = generatorsettings;
}
else
{
// generator-settings line did not contain "generator-settings"
Debug.WriteLine("Failed to find generator-settings");
console.AppendText("\n[Error] Failed to find generator-settings in server.properties");
}
// Process force-gamemode
string forcegamemodeSetting = serverProperties[4];
if (forcegamemodeSetting.Contains("force-gamemode"))
{
Debug.WriteLine("Found force-gamemode");
string forcegamemode;
forcegamemode = forcegamemodeSetting.Remove(0, 15);
Debug.WriteLine("force-gamemode value is " + forcegamemode);
if (forcegamemode == "true")
{
forceGamemode.SelectedIndex = 0;
}
else if (forcegamemode == "false")
{
forceGamemode.SelectedIndex = 1;
}
else
{
// force-gamemode is invalid
console.AppendText("\n[Error] force-gamemode in server.properties contains an invalid value");
}
}
else
{
// force-gamemode line did not contain "force-gamemode"
Debug.WriteLine("Failed to find force-gamemode");
console.AppendText("\n[Error] Failed to find force-gamemode in server.properties");
}
// Process allow-nether
string allownetherSetting = serverProperties[5];
if (allownetherSetting.Contains("allow-nether"))
{
Debug.WriteLine("Found allow-nether");
string allownether;
allownether = allownetherSetting.Remove(0, 13);
Debug.WriteLine("allow-nether value is " + allownether);
if (allownether == "true")
{
allowNether.SelectedIndex = 0;
}
else if (allownether == "false")
{
allowNether.SelectedIndex = 1;
}
else
{
// allow-nether is invalid
console.AppendText("\n[Error] allow-nether in server.properties contains an invalid value");
}
}
else
{
// allow-nether line did not contain "allow-nether"
Debug.WriteLine("Failed to find allow-nether");
console.AppendText("\n[Error] Failed to find allow-nether in server.properties");
}
// Process gamemode
string gamemodeSetting = serverProperties[6];
if (gamemodeSetting.Contains("gamemode"))
{
Debug.WriteLine("Found gamemode");
string gamemode;
gamemode = gamemodeSetting.Remove(0, 9);
Debug.WriteLine("gamemode value is " + gamemode);
if (gamemode == "0")
{
this.gamemode.Value = 0;
}
else if (gamemode == "1")
{
this.gamemode.Value = 1;
}
else if (gamemode == "2")
{
this.gamemode.Value = 2;
}
else if (gamemode == "3")
{
this.gamemode.Value = 3;
}
else
{
// gamemode is invalid
console.AppendText("\n[Error] gamemode in server.properties contains an invalid value");
}
}
else
{
// gamemode line did not contain "gamemode"
Debug.WriteLine("Failed to find gamemode");
console.AppendText("\n[Error] Failed to find gamemode in server.properties");
}
// Process broadcast-console-to-ops
string consoletoopSetting = serverProperties[7];
if (consoletoopSetting.Contains("broadcast-console-to-ops"))
{
Debug.WriteLine("Found broadcast-console-to-ops");
string consoletoop;
consoletoop = consoletoopSetting.Remove(0, 25);
Debug.WriteLine("broadcast-console-to-ops value is " + consoletoop);
if (consoletoop == "true")
{
broadcastConsoleToOps.SelectedIndex = 0;
}
else if (consoletoop == "false")
{
broadcastConsoleToOps.SelectedIndex = 1;
}
else
{
// broadcast-console-to-ops is invalid
console.AppendText("\n[Error] broadcast-console-to-ops in server.properties contains an invalid value");
}
}
else
{
// broadcast-console-to-ops line did not contain "broadcast-console-to-ops"
Debug.WriteLine("Failed to find broadcast-console-to-ops");
console.AppendText("\n[Error] Failed to find broadcast-console-to-ops in server.properties");
}
// Process enable-query
string enablequerySetting = serverProperties[8];
if (enablequerySetting.Contains("enable-query"))
{
Debug.WriteLine("Found enable-query");
string enablequery;
enablequery = enablequerySetting.Remove(0, 13);
Debug.WriteLine("enable-query value is " + enablequery);
if (enablequery == "true")
{
enableQuery.SelectedIndex = 0;
}
else if (enablequery == "false")
{
enableQuery.SelectedIndex = 1;
}
else
{
// enable-query is invalid
console.AppendText("\n[Error] enable-query in server.properties contains an invalid value");
}
}
else
{
// enable-query line did not contain "enable-query"
Debug.WriteLine("Failed to find enable-query");
console.AppendText("\n[Error] Failed to find enable-query in server.properties");
}
// Process player-idle-timeout
string playeridletimeoutSetting = serverProperties[9];
if (playeridletimeoutSetting.Contains("player-idle-timeout"))
{
Debug.WriteLine("Found player-idle-timeout");
string playeridletimeout;
playeridletimeout = playeridletimeoutSetting.Remove(0, 20);
Debug.WriteLine("player-idle-timeout value is " + playeridletimeout);
decimal playeridletimeoutValue = Convert.ToDecimal(playeridletimeout);
playerIdleTimeout.Value = playeridletimeoutValue;
}
else
{
// player-idle-timeout line did not contain "player-idle-timeout"
Debug.WriteLine("Failed to find player-idle-timeout");
console.AppendText("\n[Error] Failed to find player-idle-timeout in server.properties");
}
// Process difficulty
string difficultySetting = serverProperties[10];
if (difficultySetting.Contains("difficulty"))
{
Debug.WriteLine("Found difficulty");
string difficulty;
difficulty = difficultySetting.Remove(0, 11);
Debug.WriteLine("difficulty value is " + difficulty);
decimal difficultyValue = Convert.ToDecimal(difficulty);
this.difficulty.Value = difficultyValue;
}
else
{
// difficulty line did not contain "difficulty"
Debug.WriteLine("Failed to find difficulty");
console.AppendText("\n[Error] Failed to find difficulty in server.properties");
}
// Process spawn-monsters
string spawnmonstersSetting = serverProperties[11];
if (spawnmonstersSetting.Contains("spawn-monsters"))
{
Debug.WriteLine("Found spawn-monsters");
string spawnmonsters;
spawnmonsters = spawnmonstersSetting.Remove(0, 15);
Debug.WriteLine("spawn-monsters value is " + spawnmonsters);
if (spawnmonsters == "true")
{
spawnMonsters.SelectedIndex = 0;
}
else if (spawnmonsters == "false")
{
spawnMonsters.SelectedIndex = 1;
}
else
{
// spawn-monsters is invalid
console.AppendText("\n[Error] spawn-monsters in server.properties contains an invalid value");
}
}
else
{
// spawn-monsters line did not contain "spawn-monsters"
Debug.WriteLine("Failed to find spawn-monsters");
console.AppendText("\n[Error] Failed to find spawn-monsters in server.properties");
}
// Process op-permission-level
string oppermissionlevelSetting = serverProperties[12];
if (oppermissionlevelSetting.Contains("op-permission-level"))
{
Debug.WriteLine("Found op-permission-level");
string oppermissionlevel;
oppermissionlevel = oppermissionlevelSetting.Remove(0, 20);
Debug.WriteLine("op-permission-level value is " + oppermissionlevel);
decimal oppermissionlevelValue = Convert.ToDecimal(oppermissionlevel);
opPermLvl.Value = oppermissionlevelValue;
}
else
{
// op-permission-level is invalid
Debug.WriteLine(serverProperties[12]);
console.AppendText("\n[Error op-permission-level in server.properties contains an invalid value");
}
// Process resource-pack-hash
string resourcepackhashSetting = serverProperties[13];
if (resourcepackhashSetting.Contains("resource-pack-hash"))
{
Debug.WriteLine("Found resource-pack-hash");
string resourcepackhash;
resourcepackhash = resourcepackhashSetting.Remove(0, 19);
Debug.WriteLine("resource-pack-hash value is " + resourcepackhash);
resourcePackHash.Text = resourcepackhash;
}
else
{
// resource-pack-hash line did not contain "resource-pack-hash"
Debug.WriteLine("Failed to find resource-pack-hash");
console.AppendText("\n[Error] Failed to find resource-pack-hash in server.properties");
}
// Process announce-player-achievements
string announceplayerachivementsSetting = serverProperties[14];
if (announceplayerachivementsSetting.Contains("announce-player-achievements"))
{
Debug.WriteLine("Found announce-player-achievements");
string announceplayerachivements;
announceplayerachivements = announceplayerachivementsSetting.Remove(0, 29);
Debug.WriteLine("announce-player-achievements value is " + announceplayerachivements);
if (announceplayerachivements == "true")
{
achivements.SelectedIndex = 0;
}
else if (announceplayerachivements == "false")
{
achivements.SelectedIndex = 1;
}
}
else
{
// announce-player-achievements is invalid
console.AppendText("\n[Error] announce-player-achievements in server.properties contains an invalid value");
}
// Process pvp
string pvpSetting = serverProperties[15];
if (pvpSetting.Contains("pvp"))
{
Debug.WriteLine("Found pvp");
string pvp;
pvp = pvpSetting.Remove(0, 4);
Debug.WriteLine("pvp value is " + pvp);
if (pvp == "true")
{
this.pvp.SelectedIndex = 0;
}
else if (pvp == "false")
{
this.pvp.SelectedIndex = 1;
}
else
{
// pvp is invalid
console.AppendText("\n[Error] pvp in server.properties contains an invalid value");
}
}
else
{
// pvp line did not contain "pvp"
Debug.WriteLine("Failed to find pvp");
console.AppendText("\n[Error] Failed to find pvp in server.properties");
}
// Process snooper-enabled
string snooperenabledSetting = serverProperties[16];
if (snooperenabledSetting.Contains("snooper-enabled"))
{
Debug.WriteLine("Found snooper-enabled");
string snooperenabled;
snooperenabled = snooperenabledSetting.Remove(0, 16);
Debug.WriteLine("snooper-enabled value is " + snooperenabled);
if (snooperenabled == "true")
{
snooperEnabled.SelectedIndex = 0;
}
else if (snooperenabled == "false")
{
snooperEnabled.SelectedIndex = 1;
}
else
{
// snooper-enabled is invalid
console.AppendText("\n[Error] snooper-enabled in server.properties contains an invalid value");
}
}
else
{
// snooper-enabled line did not contain "snooper-enabled"
Debug.WriteLine("Failed to find snooper-enabled");
console.AppendText("\n[Error] Failed to find snooper-enabled in server.properties");
}
// Process level-type
string leveltypeSetting = serverProperties[17];
if (leveltypeSetting.Contains("level-type"))
{
Debug.WriteLine("Found leveltype");
string leveltype;
leveltype = leveltypeSetting.Remove(0, 11);
Debug.WriteLine("level-type value is " + leveltype);
if (leveltype == "DEFAULT")
{
worldType.SelectedIndex = 0;
}
else if (leveltype == "FLAT")
{
worldType.SelectedIndex = 1;
}
else if (leveltype == "AMPLIFIED")
{
worldType.SelectedIndex = 2;
}
else
{
// level-type is invalid
console.AppendText("\n[Error] level-type in server.properties contains an invalid value");
}
}
else
{
// level-type line did not contain "level-type"
Debug.WriteLine("Failed to find level-type");
console.AppendText("\n[Error] Failed to find level-type in server.properties");
}
// Process hardcore
string hardcoreSetting = serverProperties[18];
if (hardcoreSetting.Contains("hardcore"))
{
Debug.WriteLine("Found hardcore");
string hardcore;
hardcore = hardcoreSetting.Remove(0, 9);
Debug.WriteLine("hardcore value is " + hardcore);
if (hardcore == "true")
{
this.hardcore.SelectedIndex = 0;
}
else if (hardcore == "false")
{
this.hardcore.SelectedIndex = 1;
}
else
{
// hardcore is invalid
console.AppendText("\n[Error] hardcore in server.properties contains an invalid value");
}
}
else
{
// hardcore line did not contain "hardcore"
Debug.WriteLine("Failed to find hardcore");
console.AppendText("\n[Error] Failed to find hardcore in server.properties");
}
// Process enable-command-block
string commandblocksSetting = serverProperties[19];
if (commandblocksSetting.Contains("enable-command-block"))
{
Debug.WriteLine("Found enable-command-block");
string commandblocks;
commandblocks = commandblocksSetting.Remove(0, 21);
Debug.WriteLine("enable-command-block value is " + commandblocks);
if (commandblocks == "true")
{
commandBlocks.SelectedIndex = 0;
}
else if (commandblocks == "false")
{
commandBlocks.SelectedIndex = 1;
}
else
{
// enable-command-block is invalid
console.AppendText("\n[Error] enable-command-block in server.properties contains an invalid value");
}
}
else
{
// enable-command-block line did not contain "enable-command-block"
Debug.WriteLine("Failed to find enable-command-block");
console.AppendText("\n[Error] Failed to find enable-command-block in server.properties");
}
// Process max-players
string maxplayersSetting = serverProperties[20];
if (maxplayersSetting.Contains("max-players"))
{
Debug.WriteLine("Found max-players");
string maxplayers;
maxplayers = maxplayersSetting.Remove(0, 12);
Debug.WriteLine("max-players value is " + maxplayers);
decimal maxplayersValue = Convert.ToDecimal(maxplayers);
maxPlayers.Value = maxplayersValue;
}
else
{
// max-players line did not contain "max-players"
Debug.WriteLine("Failed to find max-players");
console.AppendText("\n[Error] Failed to find max-players in server.properties");
}
// Process network-compression-threshold
string networkcompressionthresholdSetting = serverProperties[21];
if (networkcompressionthresholdSetting.Contains("network-compression-threshold"))
{
Debug.WriteLine("Found network-compression-threshold");
string networkcompressionthreshold;
networkcompressionthreshold = networkcompressionthresholdSetting.Remove(0, 30);
Debug.WriteLine("network-compression-threshold value is " + networkcompressionthreshold);
decimal networkcompressionthresholdValue = Convert.ToDecimal(networkcompressionthreshold);
netCompression.Value = networkcompressionthresholdValue;
}
else
{
// network-compression-threshold line did not contain "network-compression-threshold"
Debug.WriteLine("Failed to find network-compression-threshold");
console.AppendText("\n[Error] Failed to find network-compression-threshold in server.properties");
}
// Process max-world-size
string maxworldsizeSetting = serverProperties[22];
if (maxworldsizeSetting.Contains("max-world-size"))
{
Debug.WriteLine("Found max-world-size");
string maxworldsize;
maxworldsize = maxworldsizeSetting.Remove(0, 15);
Debug.WriteLine("max-world-size value is " + maxworldsize);
decimal maxworldsizeValue = Convert.ToDecimal(maxworldsize);
maxWorldSize.Value = maxworldsizeValue;
}
else
{
// max-world-size line did not contain "max-world-size"
Debug.WriteLine("Failed to find max-world-size");
console.AppendText("\n[Error] Failed to find max-world-size in server.properties");
}
// Process server-port
string portSetting = serverProperties[23];
if (portSetting.Contains("server-port"))
{
Debug.WriteLine("Found server-port");
string port;
port = portSetting.Remove(0, 12);
Debug.WriteLine("server-port value is " + port);
decimal portValue = Convert.ToDecimal(port);
serverPort.Value = portValue;
}
else
{
// server-port line did not contain "server-port"
Debug.WriteLine("Failed to find server-port");
console.AppendText("\n[Error] Failed to find server-port in server.properties");
}
// Process debug
string debugSetting = serverProperties[24];
if (debugSetting.Contains("debug"))
{
Debug.WriteLine("Found debug");
string debug;
debug = debugSetting.Remove(0, 6);
Debug.WriteLine("debug value is " + debug);
if (debug == "true")
{
this.debug.SelectedIndex = 0;
}
else if (debug == "false")
{
this.debug.SelectedIndex = 1;
}
else
{
// debug is invalid
console.AppendText("\n[Error] debug in server.properties contains an invalid value");
}
}
else
{
// debug line did not contain "debug"
Debug.WriteLine("Failed to find debug");
console.AppendText("\n[Error] Failed to find debug in server.properties");
}
// Process server-ip
string ipSetting = serverProperties[25];
if (ipSetting.Contains("server-ip"))
{
Debug.WriteLine("Found server-ip");
string ip;
ip = ipSetting.Remove(0, 10);
Debug.WriteLine("server-ip value is " + ip);
serverIP.Text = ip;
}
else
{
// server-ip line did not contain "server-ip"
Debug.WriteLine("Failed to find server-ip");
console.AppendText("\n[Error] Failed to find server-ip in server.properties");
}
// Process spawn-npcs
string npcsSetting = serverProperties[26];
if (npcsSetting.Contains("spawn-npcs"))
{
Debug.WriteLine("Found spawn-npcs");
string npcs;
npcs = npcsSetting.Remove(0, 11);
Debug.WriteLine("spawn-npcs value is " + npcs);
if (npcs == "true")
{
spawnNpcs.SelectedIndex = 0;
}
else if (npcs == "false")
{
spawnNpcs.SelectedIndex = 1;
}
else
{
// spawn-npcs is invalid
console.AppendText("\n[Error] spawn-npcs in server.properties contains an invalid value");
}
}
else
{
// spawn-npcs line did not contain "spawn-npcs"
Debug.WriteLine("Failed to find spawn-npcs");
console.AppendText("\n[Error] Failed to find spawn-npcs in server.properties");
}
// Process allow-flight
string allowflightSetting = serverProperties[27];
if (allowflightSetting.Contains("allow-flight"))
{
Debug.WriteLine("Found allow-flight");
string allowflight;
allowflight = allowflightSetting.Remove(0, 13);
Debug.WriteLine("allow-flight value is " + allowflight);
if (allowflight == "true")
{
allowFlight.SelectedIndex = 0;
}
else if (allowflight == "false")
{
allowFlight.SelectedIndex = 1;
}
else
{
// allow-flight is invalid
console.AppendText("\n[Error] allow-flight in server.properties contains an invalid value");
}
}
else
{
// allow-flight line did not contain "allow-flight"
Debug.WriteLine("Failed to find allow-flight");
console.AppendText("\n[Error] Failed to find allow-flight in server.properties");
}
// Process level-name
string levelnameSetting = serverProperties[28];
if (levelnameSetting.Contains("level-name"))
{
Debug.WriteLine("Found level-name");
string levelname;
levelname = levelnameSetting.Remove(0, 11);
Debug.WriteLine("level-name value is " + levelname);
worldName.Text = levelname;
}
else
{
// level-name line did not contain "level-name"
Debug.WriteLine("Failed to find level-name");
console.AppendText("\n[Error] Failed to find level-name in server.properties");
}
// Process view-distance
string viewSetting = serverProperties[29];
if (viewSetting.Contains("view-distance"))
{
Debug.WriteLine("Found view-distance");
string view;
view = viewSetting.Remove(0, 14);
Debug.WriteLine("view-distance value is " + view);
decimal viewValue = Convert.ToDecimal(view);
viewDistance.Value = viewValue;
}
else
{
// view-distance line did not contain "view-distance"
Debug.WriteLine("Failed to find view-distance");
console.AppendText("\n[Error] Failed to find view-distance in server.properties");
}
// Process resource-pack
string resourceSetting = serverProperties[30];
if (resourceSetting.Contains("resource-pack"))
{
Debug.WriteLine("Found resource-pack");
string resource;
resource = resourceSetting.Remove(0, 14);
Debug.WriteLine("resource-pack value is " + resource);
resourcePack.Text = resource;
}
else
{
// resource-pack line did not contain "resource-pack"
Debug.WriteLine("Failed to find resource-pack");
console.AppendText("\n[Error] Failed to find resource-pack in server.properties");
}
// Process spawn-animals
string spawnanimalsSetting = serverProperties[31];
if (spawnanimalsSetting.Contains("spawn-animals"))
{
Debug.WriteLine("Found spawn-animals");
string spawnanimals;
spawnanimals = spawnanimalsSetting.Remove(0, 14);
Debug.WriteLine("spawn-animals value is " + spawnanimals);
if (spawnanimals == "true")
{
spawnAnimals.SelectedIndex = 0;
}
else if (spawnanimals == "false")
{
spawnAnimals.SelectedIndex = 1;
}
else
{
// spawn-animals is invalid
console.AppendText("\n[Error] spawn-animals in server.properties contains an invalid value");
}
}
else
{
// spawn-animals line did not contain "spawn-animals"
Debug.WriteLine("Failed to find spawn-animals");
console.AppendText("\n[Error] Failed to find spawn-animals in server.properties");
}
// Process white-list
string whitelistSetting = serverProperties[32];
if (whitelistSetting.Contains("white-list"))
{
Debug.WriteLine("Found white-list");
string whitelist;
whitelist = whitelistSetting.Remove(0, 11);
Debug.WriteLine("white-list value is " + whitelist);
if (whitelist == "true")
{
this.whitelist.SelectedIndex = 0;
}
else if (whitelist == "false")
{
this.whitelist.SelectedIndex = 1;
}
else
{
// white-list is invalid
console.AppendText("\n[Error] white-list in server.properties contains an invalid value");
}
}
else
{
// white-list line did not contain "white-list"
Debug.WriteLine("Failed to find white-list");
console.AppendText("\n[Error] Failed to find white-list in server.properties");
}
// Process generate-structures
string generatestructuresSetting = serverProperties[33];
if (generatestructuresSetting.Contains("generate-structures"))
{
Debug.WriteLine("Found generate-structures");
string generatestructures;
generatestructures = generatestructuresSetting.Remove(0, 20);
Debug.WriteLine("generate-structures value is " + generatestructures);
if (generatestructures == "true")
{
generateStructures.SelectedIndex = 0;
}
else if (generatestructures == "false")
{
generateStructures.SelectedIndex = 1;
}
else
{
// generate-structures is invalid
console.AppendText("\n[Error] generate-structures in server.properties contains an invalid value");
}
}
else
{
// generate-structures line did not contain "generate-structures"
Debug.WriteLine("Failed to find generate-structures");
console.AppendText("\n[Error] Failed to find generate-structures in server.properties");
}
// Process online-mode
string onlineSetting = serverProperties[34];
if (onlineSetting.Contains("online-mode"))
{
Debug.WriteLine("Found online-mode");
string online;
online = onlineSetting.Remove(0, 12);
Debug.WriteLine("online-mode value is " + online);
if (online == "true")
{
onlineMode.SelectedIndex = 0;
}
else if (online == "false")
{
onlineMode.SelectedIndex = 1;
}
else
{
// online-mode is invalid
console.AppendText("\n[Error] online-mode in server.properties contains an invalid value");
}
}
else
{
// online-mode line did not contain "online-mode"
Debug.WriteLine("Failed to find online-mode");
console.AppendText("\n[Error] Failed to find online-mode in server.properties");
}
// Process max-build-height
string buildheightSetting = serverProperties[35];
if (buildheightSetting.Contains("max-build-height"))
{
Debug.WriteLine("Found max-build-height");
string buildheight;
buildheight = buildheightSetting.Remove(0, 17);
Debug.WriteLine("max-build-height value is " + buildheight);
decimal buildheightValue = Convert.ToDecimal(buildheight);
maxBuildHeight.Value = buildheightValue;
}
else
{
// max-build-height line did not contain "max-build-height"
Debug.WriteLine("Failed to find max-build-height");
console.AppendText("\n[Error] Failed to find max-build-height in server.properties");
}
// Process level-seed
string seedSetting = serverProperties[36];
if (seedSetting.Contains("level-seed"))
{
Debug.WriteLine("Found level-seed");
string seed;
seed = seedSetting.Remove(0, 11);
Debug.WriteLine("level-seed value is " + seed);
worldSeed.Text = seed;
}
else
{
// level-seed line did not contain "level-seed"
Debug.WriteLine("Failed to find level-seed");
console.AppendText("\n[Error] Failed to find level-seed in server.properties");
}
// Process motd
string motdSetting = serverProperties[37];
if (motdSetting.Contains("motd"))
{
Debug.WriteLine("Found motd");
string motd;
motd = motdSetting.Remove(0, 5);
Debug.WriteLine("motd value is " + motd);
this.motd.Text = motd;
}
else
{
// motd line did not contain "motd"
Debug.WriteLine("Failed to find motd");
console.AppendText("\n[Error] Failed to find motd in server.properties");
}
// Process enable-rcon
string rconSetting = serverProperties[38];
if (rconSetting.Contains("enable-rcon"))
{
Debug.WriteLine("Found enable-rcon");
string rcon;
rcon = rconSetting.Remove(0, 12);
Debug.WriteLine("enable-rcon value is " + rcon);
if (rcon == "true")
{
enableRcon.SelectedIndex = 0;
}
else if (rcon == "false")
{
enableRcon.SelectedIndex = 1;
}
else
{
// enable-rcon is invalid
console.AppendText("\n[Error] enable-rcon in server.properties contains an invalid value");
}
}
else
{
// enable-rcon line did not contain "enable-rcon"
Debug.WriteLine("Failed to find enable-rcon");
console.AppendText("\n[Error] Failed to find enable-rcon in server.properties");
}
}
catch (Exception ex)
{
console.AppendText("\n[Error] " + ex.Message);
}
toolStripStatusLabel1.Text = "Done!";
toolStripProgressBar1.Style = ProgressBarStyle.Blocks;
if (startServerOnStart)
{
StartServer();
}
}
private void settingsButton_Click(object sender, EventArgs e)
{
// Show the settings form
Settings settings = new Settings();
settings.Show();
}