forked from OMARATION/mcforge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Server.cs
1403 lines (1259 loc) · 57.7 KB
/
Server.cs
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
/*
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCForge)
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using System;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Text;
using System.ComponentModel;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Data;
using System.Security.Cryptography;
//using MySql.Data.MySqlClient;
//using MySql.Data.Types;
using MonoTorrent.Client;
using MCForge.SQL;
namespace MCForge
{
public class Server : IDisposable
{
public static bool cancelcommand/* = false*/;
public static bool canceladmin/* = false*/;
public static bool cancellog/* = false*/;
public static bool canceloplog/* = false*/;
public static string apppath = Application.StartupPath;
public delegate void OnConsoleCommand(string cmd, string message);
public static event OnConsoleCommand ConsoleCommand;
public delegate void OnServerError(Exception error);
public static event OnServerError ServerError = null;
public delegate void OnServerLog(string message);
public static event OnServerLog ServerLog;
public static event OnServerLog ServerAdminLog;
public static event OnServerLog ServerOpLog;
public delegate void HeartBeatHandler();
public delegate void MessageEventHandler(string message);
public delegate void PlayerListHandler(List<Player> playerList);
public delegate void VoidHandler();
public delegate void LogHandler(string message);
public event LogHandler OnLog;
public event LogHandler OnSystem;
public event LogHandler OnCommand;
public event LogHandler OnError;
public event LogHandler OnOp;
public event LogHandler OnAdmin;
public event HeartBeatHandler HeartBeatFail;
public event MessageEventHandler OnURLChange;
public event PlayerListHandler OnPlayerListChange;
public event VoidHandler OnSettingsUpdate;
public static ForgeBot IRC;
public static GlobalChatBot GlobalChat;
public static Thread locationChecker;
public static bool UseTextures/* = false*/;
public static Thread blockThread;
//public static List<MySql.Data.MySqlClient.MySqlCommand> mySQLCommands = new List<MySql.Data.MySqlClient.MySqlCommand>();
public static int speedPhysics = 250;
public static Version Version { get { return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; } }
// URL hash for connecting to the server
public static string Hash = String.Empty;
public static string URL = String.Empty;
public static Socket listen;
public static System.Diagnostics.Process process = System.Diagnostics.Process.GetCurrentProcess();
public static System.Timers.Timer updateTimer = new System.Timers.Timer(100);
//static System.Timers.Timer heartbeatTimer = new System.Timers.Timer(60000); //Every 45 seconds
static System.Timers.Timer messageTimer = new System.Timers.Timer(60000 * 5); //Every 5 mins
public static System.Timers.Timer cloneTimer = new System.Timers.Timer(5000);
//public static Thread physThread;
//public static bool physPause;
//public static DateTime physResume = DateTime.Now;
//public static System.Timers.Timer physTimer = new System.Timers.Timer(1000);
// static Thread botsThread;
//Chatrooms
public static List<string> Chatrooms = new List<string>();
//Other
public static bool higherranktp = true;
public static bool agreetorulesonentry/* = false*/;
public static bool UseCTF/* = false*/;
public static bool ServerSetupFinished/* = false*/;
public static Auto_CTF ctf = null;
public static PlayerList bannedIP;
public static PlayerList whiteList;
public static PlayerList ircControllers;
public static PlayerList muted;
public static PlayerList ignored;
// The MCForge Developer List
internal static readonly List<string> devs = new List<string>(new string[] { "dmitchell94", "501st_commander", "edh649", "shade2010", "hypereddie10", "erickilla", "fredlllll", "soccer101nic", "headdetect", "merlin33069", "jasonbay13", "cazzar", "snowl", "techjar", "nerketur", "anthonyani", "wouto1997", "lavoaster", "bemacized", "meinigeshandwerk" });
public static List<string> Devs { get { return new List<string>(devs); } }
public static List<TempBan> tempBans = new List<TempBan>();
public struct TempBan { public string name; public DateTime allowedJoin; }
public static MapGenerator MapGen;
public static PerformanceCounter PCCounter = null;
public static PerformanceCounter ProcessCounter = null;
public static Level mainLevel;
public static List<Level> levels;
//reviewlist intitialize
public static List<string> reviewlist = new List<string>();
//Translate settings initialize
public static bool transenabled/* = false*/;
public static string translang = "en";
public static List<string> transignore = new List<string>();
//Global Chat Rules Accepted list
public static List<string> gcaccepted = new List<string>();
//public static List<levelID> allLevels = new List<levelID>();
public struct levelID { public int ID; public string name; }
public static List<string> afkset = new List<string>();
public static List<string> ircafkset = new List<string>();
public static List<string> afkmessages = new List<string>();
public static List<string> messages = new List<string>();
public static DateTime timeOnline;
public static string IP;
//auto updater stuff
public static bool autoupdate;
public static bool autonotify;
public static bool notifyPlayers;
public static string restartcountdown = "";
public static string selectedrevision = "";
public static bool autorestart;
public static DateTime restarttime;
public static bool chatmod/* = false*/;
//Global VoteKick In Progress Flag
public static bool voteKickInProgress/* = false*/;
public static int voteKickVotesNeeded/* = 0*/;
//WoM Direct
public static string Server_ALT = "";
public static string Server_Disc = "";
public static string Server_Flag = "";
public static Dictionary<string, string> customdollars = new Dictionary<string, string>();
// Extra storage for custom commands
public ExtrasCollection Extras = new ExtrasCollection();
//Color list as a char array
public static Char[] ColourCodesNoPercent = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
//Zombie
public static ZombieGame zombie;
public static bool ZombieModeOn/* = false*/;
public static bool startZombieModeOnStartup/* = false*/;
public static bool noRespawn = true;
public static bool noLevelSaving = true;
public static bool noPillaring = true;
public static string ZombieName = "";
public static int gameStatus/* = 0*/; //0 = not started, 1 = always on, 2 = one time, 3 = certain amount of rounds, 4 = stop game next round
public static bool queLevel/* = false*/;
public static bool queZombie/* = false*/;
public static string nextZombie = "";
public static string nextLevel = "";
public static bool zombieRound/* = false*/;
public static string lastPlayerToInfect = "";
public static int infectCombo/* = 0*/;
public static int YesVotes/* = 0*/;
public static int NoVotes/* = 0*/;
public static bool voting/* = false*/;
public static bool votingforlevel/* = false*/;
public static int Level1Vote/* = 0*/;
public static int Level2Vote/* = 0*/;
public static int Level3Vote/* = 0*/;
public static bool ChangeLevels = true;
public static bool UseLevelList/* = false*/;
public static bool ZombieOnlyServer = true;
public static List<String> LevelList = new List<String>();
public static string lastLevelVote1 = "";
public static string lastLevelVote2 = "";
public static bool bufferblocks = true;
public static string mcforgeUser = "";
public static string mcforgePass = "";
// Lava Survival
public static LavaSurvival lava;
// OmniBan
public static OmniBan omniban;
public static System.Timers.Timer omnibanCheckTimer = new System.Timers.Timer(60000 * 120);
//Settings
#region Server Settings
public const byte version = 7;
public static string salt = "";
public static string name = "[MCForge] Default";
public static string motd = "Welcome!";
public static byte players = 12;
//for the limiting no. of guests:
public static byte maxGuests = 10;
public static byte maps = 5;
public static int port = 25565;
public static bool pub = true;
public static bool verify = true;
public static bool worldChat = true;
// public static bool guestGoto = false;
//Spam Prevention
public static bool checkspam/* = false*/;
public static int spamcounter = 8;
public static int mutespamtime = 60;
public static int spamcountreset = 5;
public static string ZallState = "Alive";
//public static string[] userMOTD;
public static string level = "main";
public static string errlog = "error.log";
// public static bool console = false; // never used
public static bool reportBack = true;
public static bool irc/* = false*/;
public static bool ircColorsEnable/* = false*/;
// public static bool safemode = false; //Never used
public static int ircPort = 6667;
public static string ircNick = "ForgeBot";
public static string ircServer = "irc.esper.net";
public static string ircChannel = "#changethis";
public static string ircOpChannel = "#changethistoo";
public static bool ircIdentify/* = false*/;
public static string ircPassword = "";
public static bool verifyadmins = true;
public static LevelPermission verifyadminsrank = LevelPermission.Operator;
public static bool restartOnError = true;
public static bool antiTunnel = true;
public static byte maxDepth = 4;
public static int Overload = 1500;
public static int rpLimit = 500;
public static int rpNormLimit = 10000;
public static int backupInterval = 300;
public static int blockInterval = 60;
public static string backupLocation = Application.StartupPath + "/levels/backups";
public static bool physicsRestart = true;
public static bool deathcount = true;
public static bool AutoLoad/* = false*/;
public static int physUndo = 20000;
public static int totalUndo = 200;
public static bool rankSuper = true;
public static bool oldHelp/* = false*/;
public static bool parseSmiley = true;
public static bool useWhitelist/* = false*/;
public static bool PremiumPlayersOnly/* = false*/;
public static bool forceCuboid/* = false*/;
public static bool profanityFilter/* = false*/;
public static bool notifyOnJoinLeave/* = false*/;
public static bool repeatMessage/* = false*/;
public static bool globalignoreops/* = false*/;
public static bool checkUpdates = true;
public static bool useMySQL/* = false*/;
public static string MySQLHost = "127.0.0.1";
public static string MySQLPort = "3306";
public static string MySQLUsername = "root";
public static string MySQLPassword = "password";
public static string MySQLDatabaseName = "MCZallDB";
public static bool DatabasePooling = true;
public static string DefaultColor = "&e";
public static string IRCColour = "&5";
public static bool UseGlobalChat = true;
public static string GlobalChatNick = "MCF" + new Random().Next();
public static string GlobalChatColor = "&6";
public static int afkminutes = 10;
public static int afkkick = 45;
public static LevelPermission afkkickperm = LevelPermission.AdvBuilder;
//public static int RemotePort = 1337; // Never used
public static string defaultRank = "guest";
public static bool dollardollardollar = true;
public static bool unsafe_plugin = true;
public static bool cheapMessage = true;
public static string cheapMessageGiven = " is now being cheap and being immortal";
public static bool customBan/* = false*/;
public static string customBanMessage = "You're banned!";
public static bool customShutdown/* = false*/;
public static string customShutdownMessage = "Server shutdown. Rejoin in 10 seconds.";
public static bool customGrieferStone/* = false*/;
public static string customGrieferStoneMessage = "Oh noes! You were caught griefing!";
public static string customPromoteMessage = "&6Congratulations for working hard and getting &2PROMOTED!";
public static string customDemoteMessage = "&4DEMOTED! &6We're sorry for your loss. Good luck on your future endeavors! &1:'(";
public static string moneys = "moneys";
public static LevelPermission opchatperm = LevelPermission.Operator;
public static LevelPermission adminchatperm = LevelPermission.Admin;
public static bool logbeat/* = false*/;
public static bool adminsjoinsilent/* = false*/;
public static bool mono { get { return (Type.GetType("Mono.Runtime") != null); } }
public static string server_owner = "Notch";
public static bool WomDirect/* = false*/;
public static bool UseSeasons/* = false*/;
public static bool guestLimitNotify/* = false*/;
public static bool guestJoinNotify = true;
public static bool guestLeaveNotify = true;
public static bool flipHead/* = false*/;
public static bool shuttingDown/* = false*/;
public static bool restarting/* = false*/;
//hackrank stuff
public static bool hackrank_kick = true;
public static int hackrank_kick_time = 5; //seconds, it converts it to milliseconds in the command.
// lol useless junk here lolololasdf poop
public static bool showEmptyRanks/* = false*/;
public static byte grieferStoneType = 1;
public static bool grieferStoneBan = true;
public static LevelPermission grieferStoneRank = LevelPermission.Guest;
//reviewoptions intitialize
public static int reviewcooldown = 600;
public static LevelPermission reviewenter = LevelPermission.Guest;
public static LevelPermission reviewleave = LevelPermission.Guest;
public static LevelPermission reviewview = LevelPermission.Operator;
public static LevelPermission reviewnext = LevelPermission.Operator;
public static LevelPermission reviewclear = LevelPermission.Operator;
#endregion
public static MainLoop ml;
public static Server s;
public Server()
{
ml = new MainLoop("server");
Server.s = this;
}
//True = cancel event
//Fale = dont cacnel event
public static bool Check(string cmd, string message)
{
if (ConsoleCommand != null)
ConsoleCommand(cmd, message);
return cancelcommand;
}
public void Start()
{
shuttingDown = false;
Log("Starting Server");
{
try
{
if (File.Exists("Restarter.exe"))
{
File.Delete("Restarter.exe");
}
}
catch { }
try
{
if (File.Exists("Restarter.pdb"))
{
File.Delete("Restarter.pdb");
}
}
catch { }
//dl restarter stuff [Restarter is no longer needed]
//if (!File.Exists("Restarter.exe"))
//{
// Log("Restarter.exe doesn't exist, Downloading");
// try
// {
// using (WebClient WEB = new WebClient())
// {
// WEB.DownloadFile("http://mcforge.net/uploads/Restarter.exe", "Restarter.exe");
// }
// if (File.Exists("Restarter.exe"))
// {
// Log("Restarter.exe download succesful!");
// }
// }
// catch
// {
// Log("Downloading Restarter.exe failed, please try again later");
// }
//}
//if (!File.Exists("Restarter.pdb"))
//{
// Log("Restarter.pdb doesn't exist, Downloading");
// try
// {
// using (WebClient WEB = new WebClient())
// {
// WEB.DownloadFile("http://mcforge.net/uploads/Restarter.pdb", "Restarter.pdb");
// }
// if (File.Exists("Restarter.pdb"))
// {
// Log("Restarter.pdb download succesful!");
// }
// }
// catch
// {
// Log("Downloading Restarter.pdb failed, please try again later");
// }
//}
if (!File.Exists("MySql.Data.dll"))
{
Log("MySql.Data.dll doesn't exist, Downloading");
try
{
using (WebClient WEB = new WebClient())
{
WEB.DownloadFile("http://mcforge.net/uploads/MySql.Data.dll", "MySql.Data.dll");
}
if (File.Exists("MySql.Data.dll"))
{
Log("MySql.Data.dll download succesful!");
}
}
catch
{
Log("Downloading MySql.Data.dll failed, please try again later");
}
}
if (!File.Exists("System.Data.SQLite.dll"))
{
Log("System.Data.SQLite.dll doesn't exist, Downloading");
try
{
using (WebClient WEB = new WebClient())
{
WEB.DownloadFile("http://mcforge.net/uploads/System.Data.SQLite.dll", "System.Data.SQLite.dll");
}
if (File.Exists("System.Data.SQLite.dll"))
{
Log("System.Data.SQLite.dll download succesful!");
}
}
catch
{
Log("Downloading System.Data.SQLite.dll failed, please try again later");
}
}
if (!File.Exists("sqlite3.dll"))
{
Log("sqlite3.dll doesn't exist, Downloading");
try
{
using (WebClient WEB = new WebClient())
{
WEB.DownloadFile("http://www.mcforge.net/sqlite3.dll", "sqlite3.dll");
}
if (File.Exists("sqlite3.dll"))
{
Log("sqlite3.dll download succesful!");
}
}
catch
{
Log("Downloading sqlite3.dll failed, please try again later");
}
}
if (!File.Exists("Sharkbite.Thresher.dll"))
{
Log("Sharkbite.Thresher.dll doesn't exist, Downloading");
try
{
using (WebClient WEB = new WebClient())
{
//WEB.DownloadFile("http://www.mediafire.com/?4rkpqvcji3va8rp", "Sharkbite.Thresher.dll");
WEB.DownloadFile("http://mcforge.net/uploads/Sharkbite.Thresher.dll", "Sharkbite.Thresher.dll");
}
if (File.Exists("Sharkbite.Thresher.dll"))
{
Log("Sharkbite.Thresher.dll download succesful!");
}
}
catch
{
Log("Downloading Sharkbite.Thresher.dll failed, please try again later");
}
}
}
if (!Directory.Exists("properties")) Directory.CreateDirectory("properties");
if (!Directory.Exists("levels")) Directory.CreateDirectory("levels");
if (!Directory.Exists("bots")) Directory.CreateDirectory("bots");
if (!Directory.Exists("text")) Directory.CreateDirectory("text");
if (!File.Exists("text/tempranks.txt")) File.CreateText("text/tempranks.txt").Dispose();
if (!File.Exists("text/rankinfo.txt")) File.CreateText("text/rankinfo.txt").Dispose();
if (!File.Exists("text/transexceptions.txt")) File.CreateText("text/transexceptions.txt").Dispose();
if (!File.Exists("text/gcaccepted.txt")) File.CreateText("text/gcaccepted.txt").Dispose();
if (!File.Exists("text/bans.txt")) File.CreateText("text/bans.txt").Dispose();
// DO NOT STICK ANYTHING IN BETWEEN HERE!!!!!!!!!!!!!!!
else
{
string bantext = File.ReadAllText("text/bans.txt");
if (!bantext.Contains("%20") && bantext != "")
{
bantext = bantext.Replace("~", "%20");
bantext = bantext.Replace("-", "%20");
File.WriteAllText("text/bans.txt", bantext);
}
}
if (!Directory.Exists("extra")) Directory.CreateDirectory("extra");
if (!Directory.Exists("extra/undo")) Directory.CreateDirectory("extra/undo");
if (!Directory.Exists("extra/undoPrevious")) Directory.CreateDirectory("extra/undoPrevious");
if (!Directory.Exists("extra/copy/")) { Directory.CreateDirectory("extra/copy/"); }
if (!Directory.Exists("extra/copyBackup/")) { Directory.CreateDirectory("extra/copyBackup/"); }
if (!Directory.Exists("extra/Waypoints")) { Directory.CreateDirectory("extra/Waypoints"); }
try
{
if (File.Exists("server.properties")) File.Move("server.properties", "properties/server.properties");
if (File.Exists("rules.txt")) File.Move("rules.txt", "text/rules.txt");
if (File.Exists("welcome.txt")) File.Move("welcome.txt", "text/welcome.txt");
if (File.Exists("messages.txt")) File.Move("messages.txt", "text/messages.txt");
if (File.Exists("externalurl.txt")) File.Move("externalurl.txt", "text/externalurl.txt");
if (File.Exists("autoload.txt")) File.Move("autoload.txt", "text/autoload.txt");
if (File.Exists("IRC_Controllers.txt")) File.Move("IRC_Controllers.txt", "ranks/IRC_Controllers.txt");
if (Server.useWhitelist) if (File.Exists("whitelist.txt")) File.Move("whitelist.txt", "ranks/whitelist.txt");
}
catch { }
if (File.Exists("text/custom$s.txt"))
{
using (StreamReader r = new StreamReader("text/custom$s.txt"))
{
string line;
while ((line = r.ReadLine()) != null)
{
if (!line.StartsWith("//"))
{
var split = line.Split(new char[] { ':' }, 2);
if (split.Length == 2 && !String.IsNullOrEmpty(split[0]))
{
customdollars.Add(split[0], split[1]);
}
}
}
}
}
else
{
s.Log("custom$s.txt does not exist, creating");
using (StreamWriter SW = File.CreateText("text/custom$s.txt"))
{
SW.WriteLine("// This is used to create custom $s");
SW.WriteLine("// If you start the line with a // it wont be used");
SW.WriteLine("// It should be formatted like this:");
SW.WriteLine("// $website:mcforge.net");
SW.WriteLine("// That would replace '$website' in any message to 'mcforge.net'");
SW.WriteLine("// It must not start with a // and it must not have a space between the 2 sides and the colon (:)");
SW.Close();
}
}
LoadAllSettings();
if (File.Exists("text/emotelist.txt"))
{
foreach (string s in File.ReadAllLines("text/emotelist.txt"))
{
Player.emoteList.Add(s);
}
}
else
{
File.Create("text/emotelist.txt").Dispose();
}
// LavaSurvival constructed here...
lava = new LavaSurvival();
zombie = new ZombieGame();
// OmniBan
omniban = new OmniBan();
timeOnline = DateTime.Now;
{//MYSQL stuff
try
{
Database.executeQuery("CREATE DATABASE if not exists `" + MySQLDatabaseName + "`", true); // works in both now, SQLite simply ignores this.
}
//catch (MySql.Data.MySqlClient.MySqlException e)
//{
// Server.s.Log("MySQL settings have not been set! Many features will not be available if MySQL is not enabled");
// // Server.ErrorLog(e);
//}
catch (Exception e)
{
Server.ErrorLog(e);
Server.s.Log("MySQL settings have not been set! Please Setup using the properties window.");
//process.Kill();
return;
}
Database.executeQuery("CREATE TABLE if not exists Players (ID INTEGER " + (Server.useMySQL ? "" : "PRIMARY KEY ") + "AUTO" + (Server.useMySQL ? "_" : "") + "INCREMENT NOT NULL, Name VARCHAR(20), IP CHAR(15), FirstLogin DATETIME, LastLogin DATETIME, totalLogin MEDIUMINT, Title CHAR(20), TotalDeaths SMALLINT, Money MEDIUMINT UNSIGNED, totalBlocks BIGINT, totalCuboided BIGINT, totalKicked MEDIUMINT, TimeSpent VARCHAR(20), color VARCHAR(6), title_color VARCHAR(6)" + (Server.useMySQL ? ", PRIMARY KEY (ID)" : "") + ");");
Database.executeQuery("CREATE TABLE if not exists Playercmds (ID INTEGER " + (Server.useMySQL ? "" : "PRIMARY KEY ") + "AUTO" + (Server.useMySQL ? "_" : "") + "INCREMENT NOT NULL, Time DATETIME, Name VARCHAR(20), Rank VARCHAR(20), Mapname VARCHAR(40), Cmd VARCHAR(40), Cmdmsg VARCHAR(40)" + (Server.useMySQL ? ", PRIMARY KEY (ID)" : "") + ");");
// Here, since SQLite is a NEW thing from 5.3.0.0, we do not have to check for existing tables in SQLite.
if (Server.useMySQL) {
// Check if the color column exists.
DataTable colorExists = MySQL.fillData("SHOW COLUMNS FROM Players WHERE `Field`='color'");
if (colorExists.Rows.Count == 0)
{
MySQL.executeQuery("ALTER TABLE Players ADD COLUMN color VARCHAR(6) AFTER totalKicked");
//else SQLite.executeQuery("ALTER TABLE Players ADD COLUMN color VARCHAR(6) AFTER totalKicked");
}
colorExists.Dispose();
// Check if the title color column exists.
DataTable tcolorExists = MySQL.fillData("SHOW COLUMNS FROM Players WHERE `Field`='title_color'");
if (tcolorExists.Rows.Count == 0)
{
MySQL.executeQuery("ALTER TABLE Players ADD COLUMN title_color VARCHAR(6) AFTER color");
// else SQLite.executeQuery("ALTER TABLE Players ADD COLUMN title_color VARCHAR(6) AFTER color");
}
tcolorExists.Dispose();
DataTable timespent = MySQL.fillData("SHOW COLUMNS FROM Players WHERE `Field`='TimeSpent'");
if (timespent.Rows.Count == 0)
MySQL.executeQuery("ALTER TABLE Players ADD COLUMN TimeSpent VARCHAR(20) AFTER totalKicked"); //else SQLite.executeQuery("ALTER TABLE Players ADD COLUMN TimeSpent VARCHAR(20) AFTER totalKicked");
timespent.Dispose();
DataTable totalCuboided = MySQL.fillData("SHOW COLUMNS FROM Players WHERE `Field`='totalCuboided'");
if (totalCuboided.Rows.Count == 0)
MySQL.executeQuery("ALTER TABLE Players ADD COLUMN totalCuboided BIGINT AFTER totalBlocks"); //else SQLite.executeQuery("ALTER TABLE Players ADD COLUMN totalCuboided BIGINT AFTER totalBlocks");
totalCuboided.Dispose();
}
}
if (levels != null)
foreach (Level l in levels) { l.Unload(); }
ml.Queue(delegate
{
try
{
levels = new List<Level>(Server.maps);
MapGen = new MapGenerator();
if (File.Exists("levels/" + Server.level + ".lvl"))
{
mainLevel = Level.Load(Server.level);
mainLevel.unload = false;
if (mainLevel == null)
{
if (File.Exists("levels/" + Server.level + ".lvl.backup"))
{
Log("Attempting to load backup of " + Server.level + ".");
File.Copy("levels/" + Server.level + ".lvl.backup", "levels/" + Server.level + ".lvl", true);
mainLevel = Level.Load(Server.level);
if (mainLevel == null)
{
Log("BACKUP FAILED!");
Console.ReadLine(); return;
}
}
else
{
Log("mainlevel not found");
mainLevel = new Level(Server.level, 128, 64, 128, "flat") { permissionvisit = LevelPermission.Guest, permissionbuild = LevelPermission.Guest };
mainLevel.Save();
Level.CreateLeveldb(Server.level);
}
}
//Wom Textures
/*if (Server.UseTextures)
{
mainLevel.textures.sendwomid = true;
mainLevel.textures.MOTD = Server.motd;
mainLevel.textures.CreateCFG();
}*/
}
else
{
Log("mainlevel not found");
mainLevel = new Level(Server.level, 128, 64, 128, "flat") { permissionvisit = LevelPermission.Guest, permissionbuild = LevelPermission.Guest };
mainLevel.Save();
Level.CreateLeveldb(Server.level);
}
addLevel(mainLevel);
// fenderrock - Make sure the level does have a physics thread
if (mainLevel.physThread == null)
mainLevel.StartPhysics();
}
catch (Exception e) { Server.ErrorLog(e); }
});
Plugin.Load();
ml.Queue(delegate
{
bannedIP = PlayerList.Load("banned-ip.txt", null);
ircControllers = PlayerList.Load("IRC_Controllers.txt", null);
muted = PlayerList.Load("muted.txt", null);
foreach (Group grp in Group.GroupList)
grp.playerList = PlayerList.Load(grp.fileName, grp);
if (Server.useWhitelist)
whiteList = PlayerList.Load("whitelist.txt", null);
});
ml.Queue(delegate
{
transignore.AddRange(File.ReadAllLines("text/transexceptions.txt"));
if (File.Exists("text/autoload.txt"))
{
try
{
string[] lines = File.ReadAllLines("text/autoload.txt");
foreach (string line in lines)
{
//int temp = 0;
string _line = line.Trim();
try
{
if (_line == "") { continue; }
if (_line[0] == '#') { continue; }
int index = _line.IndexOf("=");
string key = _line.Split('=')[0].Trim();
string value;
try
{
value = _line.Split('=')[1].Trim();
}
catch
{
value = "0";
}
if (!key.Equals(mainLevel.name))
{
Command.all.Find("load").Use(null, key + " " + value);
Level l = Level.FindExact(key);
//Not needed, as load does it for us.
//try
//{
// Gui.Window.thisWindow.UpdateMapList("'");
// Gui.Window.thisWindow.UnloadedlistUpdate();
//}
//catch { }
}
else
{
try
{
int temp = int.Parse(value);
if (temp >= 0 && temp <= 3)
{
mainLevel.setPhysics(temp);
}
}
catch
{
Server.s.Log("Physics variable invalid");
}
}
}
catch
{
Server.s.Log(_line + " failed.");
}
}
}
catch
{
Server.s.Log("autoload.txt error");
}
GC.Collect();
GC.WaitForPendingFinalizers();
}
else
{
Log("autoload.txt does not exist");
}
});
ml.Queue(delegate
{
Translate.Init();
foreach (string line in File.ReadAllLines("text/transexceptions.txt"))
{
transignore.Add(line); //loading all playernames of people who turned off translation
}
foreach (string line in File.ReadAllLines("text/gcaccepted.txt"))
{
gcaccepted.Add(line); //loading all playernames of people who turned off translation
}
Log("Creating listening socket on port " + Server.port + "... ");
if (Setup())
{
s.Log("Done.");
}
else
{
s.Log("Could not create socket connection. Shutting down.");
return;
}
});
ml.Queue(delegate
{
Remote.RemoteServer webServer;
Remote.RemoteProperties.Load();
(webServer = new Remote.RemoteServer()).Start();
});
ml.Queue(delegate
{
updateTimer.Elapsed += delegate
{
Player.GlobalUpdate();
PlayerBot.GlobalUpdatePosition();
};
updateTimer.Start();
});
// Heartbeat code here:
ml.Queue(delegate
{
try
{
Heart.Init();
}
catch (Exception e)
{
Server.ErrorLog(e);
}
});
ml.Queue(delegate
{
if (mcforgeUser != String.Empty && mcforgePass != String.Empty)
{
new Thread(new ThreadStart(delegate { MCForgeAccount.Login(); })).Start();
}
});
// END Heartbeat code
/*
Thread processThread = new Thread(new ThreadStart(delegate
{
try
{
PCCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
ProcessCounter = new PerformanceCounter("Process", "% Processor Time", Process.GetCurrentProcess().ProcessName);
PCCounter.BeginInit();
ProcessCounter.BeginInit();
PCCounter.NextValue();
ProcessCounter.NextValue();
}
catch { }
}));
processThread.Start();
*/
ml.Queue(delegate
{
messageTimer.Elapsed += delegate
{
RandomMessage();
};
messageTimer.Start();
process = System.Diagnostics.Process.GetCurrentProcess();
if (File.Exists("text/messages.txt"))
{
using (StreamReader r = File.OpenText("text/messages.txt"))
{
while (!r.EndOfStream)
messages.Add(r.ReadLine());
}
}
else File.Create("text/messages.txt").Close();
// We always construct this to prevent errors...
IRC = new ForgeBot(Server.ircChannel, Server.ircOpChannel, Server.ircNick, Server.ircServer);
GlobalChat = new GlobalChatBot(GlobalChatNick);
if (Server.irc) IRC.Connect();
if (Server.UseGlobalChat) GlobalChat.Connect();
// OmniBan stuff!
new Thread(new ThreadStart(delegate
{
omniban.Load(true);
})).Start();
omnibanCheckTimer.Elapsed += delegate
{
omniban.Load(true);
omniban.KickAll();
};
omnibanCheckTimer.Start();
// string CheckName = "FROSTEDBUTTS";
// if (Server.name.IndexOf(CheckName.ToLower())!= -1){ Server.s.Log("FROSTEDBUTTS DETECTED");}
new AutoSaver(Server.backupInterval); //2 and a half mins
blockThread = new Thread(new ThreadStart(delegate
{
while (true)
{
Thread.Sleep(blockInterval * 1000);
levels.ForEach(delegate(Level l)
{
try
{
l.saveChanges();
}
catch (Exception e)
{
Server.ErrorLog(e);
}
});
}
}));
blockThread.Start();
locationChecker = new Thread(new ThreadStart(delegate
{
Player p, who;
ushort x, y, z;
int i;
while (true)
{
Thread.Sleep(3);
for (i = 0; i < Player.players.Count; i++)
{
try
{
p = Player.players[i];
if (p.frozen)
{
unchecked { p.SendPos((byte)-1, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1]); } continue;
}
else if (p.following != "")
{
who = Player.Find(p.following);
if (who == null || who.level != p.level)
{
p.following = "";
if (!p.canBuild)
{
p.canBuild = true;
}
if (who != null && who.possess == p.name)
{
who.possess = "";
}