-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOpenNexus.cs
3243 lines (3131 loc) · 173 KB
/
OpenNexus.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
// Reference: 0Harmony
//None of this code is to be used in any paid projects/plugins
using Facepunch.Utility;
using Oxide.Core;
using ProtoBuf;
using Rust.Modular;
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using Oxide.Core.Database;
using Rust;
using Oxide.Core.Plugins;
using System.Linq;
using Oxide.Game.Rust.Cui;
using Harmony;
namespace Oxide.Plugins
{
[Info("OpenNexus", "bmgjet", "1.0.0")]
[Description("Nexus system created by bmgjet")]
public class OpenNexus : RustPlugin
{
private string thisserverip = ""; //Over-ride auto detected ip
private string thisserverport = ""; //Over-ride auto detected port
//Permissions
private readonly string permbypass = "OpenNexus.bypass"; //bypass the single server at a time limit
private readonly string permadmin = "OpenNexus.admin"; //Allows to use admin commands
//MySQL
Core.MySql.Libraries.MySql sqlLibrary = Interface.Oxide.GetLibrary<Core.MySql.Libraries.MySql>();
Core.Database.Connection sqlConnection;
//Memory
public List<IslandData> FoundIslands = new List<IslandData>();
public List<Vector3> HeliPads = new List<Vector3>();
private Dictionary<ulong, int> SeatPlayers = new Dictionary<ulong, int>();
private List<BaseNetworkable> unloadable = new List<BaseNetworkable>();
private List<ulong> ProcessingPlayers = new List<ulong>();
private List<ulong> MovePlayers = new List<ulong>();
private List<BasePlayer> JoinedViaNexus = new List<BasePlayer>();
private List<ModuleData> CarModules = new List<ModuleData>();
private List<CargoShip> ActiveCargoShips = new List<CargoShip>();
public static OpenNexus plugin;
private Climate climate;
//Plugin Hooks
[PluginReference]
private Plugin Backpacks, Economics, ZLevelsRemastered, ServerRewards;
private HarmonyInstance _harmony; //Harmony Instance
#region Configuration
public ServerSettings _ServerSettings;
public class ServerSettings
{
public string MapName = plugin.Config["MapName"].ToString();
public float ServerDelay = float.Parse(plugin.Config["ServerDelay"].ToString());
public string MySQLHost = plugin.Config["MySQLHost"].ToString();
public int MySQLPort = int.Parse(plugin.Config["MySQLPort"].ToString());
public string MySQLDB = plugin.Config["MySQLDB"].ToString();
public string MySQLUsername = plugin.Config["MySQLUsername"].ToString();
public string MySQLPassword = plugin.Config["MySQLPassword"].ToString();
public int ExtendFerryDistance = int.Parse(plugin.Config["ExtendFerryDistance"].ToString());
public bool AutoDistance = bool.Parse(plugin.Config["AutoDistance"].ToString());
public bool SyncTimeWeather = bool.Parse(plugin.Config["SyncTimeWeather"].ToString());
public int SyncTimeWeaterEvery = int.Parse(plugin.Config["SyncTimeWeaterEvery"].ToString());
public bool UseCompression = bool.Parse(plugin.Config["UseCompression"].ToString());
public bool ShowDebugMsg = bool.Parse(plugin.Config["ShowDebugMsg"].ToString());
public float MoveSpeed = float.Parse(plugin.Config["MoveSpeed"].ToString());
public float TurnSpeed = float.Parse(plugin.Config["TurnSpeed"].ToString());
public float WaitTime = float.Parse(plugin.Config["WaitTime"].ToString());
public float EjectDelay = float.Parse(plugin.Config["EjectDelay"].ToString());
public int TransfereTime = int.Parse(plugin.Config["TransfereTime"].ToString());
public int TransfereSyncTime = int.Parse(plugin.Config["TransfereSyncTime"].ToString());
public int ProgressDelay = int.Parse(plugin.Config["ProgressDelay"].ToString());
public int RedirectDelay = int.Parse(plugin.Config["RedirectDelay"].ToString());
public int CargoDistance = int.Parse(plugin.Config["CargoDistance"].ToString());
public bool StatusMsg = bool.Parse(plugin.Config["StatusMsg"].ToString());
public int MSGDistance = int.Parse(plugin.Config["MSGDistance"].ToString());
public int FontSize = int.Parse(plugin.Config["FontSize"].ToString());
public string FontColour = plugin.Config["FontColour"].ToString();
public int FontFadeIn = int.Parse(plugin.Config["FontFadeIn"].ToString());
public string AnchorMin = plugin.Config["AnchorMin"].ToString();
public string AnchorMax = plugin.Config["AnchorMax"].ToString();
public string FailedMSG = plugin.Config["FailedMSG"].ToString();
public string WaitingMSG = plugin.Config["WaitingMSG"].ToString();
public string CastoffMSG = plugin.Config["CastoffMSG"].ToString();
public string ArriveMSG = plugin.Config["ArriveMSG"].ToString();
public bool BackPacks = bool.Parse(plugin.Config["BackPacks"].ToString());
public bool Economics = bool.Parse(plugin.Config["Economics"].ToString());
public bool ZLevelsRemastered = bool.Parse(plugin.Config["ZLevelsRemastered"].ToString());
public bool ServerRewards = bool.Parse(plugin.Config["ServerRewards"].ToString());
public bool BluePrints = bool.Parse(plugin.Config["BluePrints"].ToString());
public bool Modifiers = bool.Parse(plugin.Config["Modifiers"].ToString());
public bool Parented = bool.Parse(plugin.Config["Parented"].ToString());
}
protected override void LoadDefaultConfig()
{
Puts("Creating a new configuration file");
Config["MapName"] = "";
Config["ServerDelay"] = 1;
Config["MySQLHost"] = "localhost";
Config["MySQLPort"] = 3306;
Config["MySQLDB"] = "opennexus";
Config["MySQLUsername"] = "OpenNexus";
Config["MySQLPassword"] = "1234";
Config["ExtendFerryDistance"] = 0;
Config["AutoDistance"] = true;
Config["SyncTimeWeather"] = true;
Config["SyncTimeWeaterEvery"] = 300;
Config["UseCompression"] = true;
Config["ShowDebugMsg"] = false;
Config["MoveSpeed"] = 5;
Config["TurnSpeed"] = 0.6f;
Config["WaitTime"] = 60;
Config["EjectDelay"] = 60;
Config["TransfereTime"] = 60;
Config["TransfereSyncTime"] = 60;
Config["ProgressDelay"] = 60;
Config["RedirectDelay"] = 5;
Config["CargoDistance"] = 1000;
Config["StatusMsg"] = true;
Config["MSGDistance"] = 60;
Config["FontSize"] = 32;
Config["FontColour"] = "0.1 0.4 0.1 0.7";
Config["FontFadeIn"] = 3;
Config["AnchorMin"] = "0.100 0.800";
Config["AnchorMax"] = "0.900 0.900";
Config["FailedMSG"] = "Other Servers Failed To Reach Transfere Point In Time";
Config["WaitingMSG"] = "Waiting For Other Server";
Config["CastoffMSG"] = "Ferry Casting Off In <$T> Seconds";
Config["ArriveMSG"] = "You Have Arrived At The Next Server";
Config["BackPacks"] = true;
Config["Economics"] = true;
Config["ZLevelsRemastered"] = true;
Config["ServerRewards"] = true;
Config["BluePrints"] = true;
Config["Modifiers"] = true;
Config["Parented"] = true;
}
#endregion
#region Harmony
[HarmonyPatch(typeof(World), "GetServerBrowserMapName")] //Called on ServerInformation
internal class World_GetServerBrowserMapName
{
[HarmonyPrefix]
static bool Prefix(ref string __result)
{
if (string.IsNullOrEmpty(plugin._ServerSettings.MapName)) //Check if startup arg set
{
return true; //Not set so run normally
}
__result = plugin._ServerSettings.MapName; //Override result of orignal method
return false; //Block orignal method
}
}
#endregion
#region Commands
//Chat command to paste where admin is a transfered packet
//Command /OpenNexus.Paste $PacketID
[ChatCommand("OpenNexus.Paste")]
private void cmdPaste(BasePlayer player, string command, string[] args)
{
if (!HasPermission(player, permadmin)) { player.ChatMessage("You dont have OpenNexus.admin Perm!"); return; }
if (args.Length != 1)
{
player.ChatMessage("You must provide packet id!");
return;
}
int packetid = int.Parse(args[0]);
player.ChatMessage("Pasting Packet " + args[0]);
//Do Read Of Packet
MySQLRead("", null, packetid, player);
}
//Clears all the MySQL tables and sets back to default.
[ConsoleCommand("OpenNexus.resettables")]
private void cmdReset(ConsoleSystem.Arg arg)
{
//Resets database tables
if (!arg.IsAdmin) { Puts("You dont have OpenNexus.admin Perm!"); return; }
string sqlQuery = "DROP TABLE IF EXISTS players, packets, sync;";
Sql deleteCommand = Oxide.Core.Database.Sql.Builder.Append(sqlQuery);
sqlLibrary.ExecuteNonQuery(deleteCommand, sqlConnection);
if (bool.Parse(Config["ShowDebugMsg"].ToString())) Puts("cmdReset Dropped all tables");
timer.Once(_ServerSettings.ServerDelay, () =>
{
CreatesTables();
//Reset players data
timer.Once(_ServerSettings.ServerDelay, () => { foreach (BasePlayer bp in BasePlayer.activePlayerList) { if (bp.IsConnected && !bp.IsNpc) { NextTick(() => { UpdatePlayers(thisserverip + ":" + thisserverport, thisserverip + ":" + thisserverport, "Playing", bp.UserIDString); }); } } });
});
}
//Reloads the config with out having to restart, Not all changes will take effect
[ConsoleCommand("OpenNexus.reloadconfig")]
private void cmdReload(ConsoleSystem.Arg arg)
{
if (!arg.IsAdmin) {Puts("You dont have OpenNexus.admin Perm!"); return; }
ServerSettings oldconfig = _ServerSettings;
_ServerSettings = Config.ReadObject<ServerSettings>();
if (oldconfig != _ServerSettings)
{
Puts("Loaded changes, Not all settings will take effect with out a restart of plugin.");
Puts("You can restart plugin with /oxide.reload OpenNexus");
}
}
//toggle debug information
[ChatCommand("OpenNexus.debug")]
private void cmddebug(BasePlayer player, string command, string[] args)
{
if (!HasPermission(player, permadmin)) { player.ChatMessage("You dont have OpenNexus.admin Perm!"); return; }
if (_ServerSettings.ShowDebugMsg)
{
_ServerSettings.ShowDebugMsg = false;
player.ChatMessage("Debug messages disabled.");
}
else
{
_ServerSettings.ShowDebugMsg = true;
player.ChatMessage("Debug messages enabled.");
}
Config.Save();
}
#endregion
#region MySQL
//Read data from mysql database
private void MySQLRead(string Target, OpenNexusFerry OpenFerry, int findid = 0, BasePlayer player = null)
{
string sqlQuery;
Sql selectCommand;
//If passed as admin command to read given packet
if (player != null)
{
sqlQuery = "SELECT `id`, `spawned`,`data` FROM packets WHERE `id` = @0;";
selectCommand = Oxide.Core.Database.Sql.Builder.Append(sqlQuery, findid);
}
else
{
//Read last transfered packet waiting for us
sqlQuery = "SELECT `id`, `spawned`,`data` FROM packets WHERE `target`= @0 AND `sender` = @1 ORDER BY id DESC LIMIT 10;";
selectCommand = Oxide.Core.Database.Sql.Builder.Append(sqlQuery, Target, OpenFerry.ServerIP + ":" + OpenFerry.ServerPort);
}
sqlLibrary.Query(selectCommand, sqlConnection, list =>
{
if (list == null) { return; }
foreach (Dictionary<string, object> entry in list)
{
//Packet has already been spawned on server before so dont re-transfere
if (entry["spawned"].ToString() == "1" && findid == 0) { continue; }
//Process Packet
int id;
bool success = int.TryParse(entry["id"].ToString(), out id);
if (!success) { continue; }
string data = "";
if (_ServerSettings.UseCompression) { data = Encoding.UTF8.GetString(Compression.Uncompress(Convert.FromBase64String(entry["data"].ToString()))); } //compressed
else { data = entry["data"].ToString(); }
//Admin command
if (player != null) { ReadPacket(data, player, id); return; }
//Process mysql packet
ReadPacket(data, OpenFerry, id);
//Kill stray bots that might of followed players
List<BasePlayer> Bots = new List<BasePlayer>();
List<BasePlayer> KillBots = new List<BasePlayer>();
Vis.Entities<BasePlayer>(OpenFerry.transform.position + (OpenFerry.transform.rotation * Vector3.forward * 6), 14f, KillBots);
foreach (BasePlayer bp in KillBots) { if (!Bots.Contains(bp) && !bp.IsNpc) { Bots.Add(bp); } }
Vis.Entities<BasePlayer>(OpenFerry.transform.position + (OpenFerry.transform.rotation * Vector3.forward * -12), 14f, KillBots);
foreach (BasePlayer bp in KillBots) { if (!Bots.Contains(bp) && !bp.IsNpc) { Bots.Add(bp); } }
foreach (BasePlayer bot in Bots) { if (!IsSteamId(bot.UserIDString)) { bot.Kill(); } }
if (_ServerSettings.ShowDebugMsg) plugin.Puts("Read " + String.Format("{0:0.##}", (double)(entry["data"].ToString().Length / 1024f)) + " Kb");
return;
}
return;
});
}
//Write data to mysql database
private void MySQLWrite(string target = "", string sender = "", string data = "", int id = 0, int spawned = 0)
{
if (id != 0)
{
//If ID is given then update this as being spawned
string sqlQuery = "UPDATE packets SET `spawned` = @1 WHERE `id` = @0;";
Sql updateCommand = Oxide.Core.Database.Sql.Builder.Append(sqlQuery, id, spawned);
sqlLibrary.Update(updateCommand, sqlConnection, rowsAffected =>
{
if (rowsAffected > 0) { if (_ServerSettings.ShowDebugMsg) { Puts("MySQLWrite Record Updated"); } return; }
else { if (_ServerSettings.ShowDebugMsg) { Puts("MySQLWrite Record Update Failed!"); } return; }
});
return;
}
//No ID given so create new
if (target != "" && sender != "" && data != "")
{
string sqlQuery = "INSERT INTO packets (`spawned`, `timestamp`, `target`,`sender`,`data`) VALUES (@0, @1, @2, @3, @4);";
Sql insertCommand = Oxide.Core.Database.Sql.Builder.Append(sqlQuery, spawned, DateTime.Now.ToString("t"), target, sender, data);
sqlLibrary.Insert(insertCommand, sqlConnection, rowsAffected =>
{
if (rowsAffected > 0)
{
if (_ServerSettings.ShowDebugMsg) { Puts("MySQLWrite New record inserted with ID: {0}", sqlConnection.LastInsertRowId); }
return;
}
else
{
if (_ServerSettings.ShowDebugMsg) { Puts("MySQLWrite Failed to insert!"); }
return;
}
});
}
}
//Maintains table of each ferrys status
private void UpdateSync(string fromaddress, string target, string state)
{
//try Update
string sqlQuery = "UPDATE sync SET `state` = @0, `climate` = @3 WHERE `sender` = @1 AND `target` = @2;";
Sql updateCommand = Oxide.Core.Database.Sql.Builder.Append(sqlQuery, state, fromaddress, target, plugin.getclimate()); ;
sqlLibrary.Update(updateCommand, sqlConnection, rowsAffected =>
{
if (rowsAffected > 0) { if (_ServerSettings.ShowDebugMsg) { Puts("UpdateSync Record Updated"); } return; }
//Update failed so do insert
sqlQuery = "INSERT INTO sync (`state`, `sender`, `target`, `climate`) VALUES (@0, @1, @2, @3);";
Sql insertCommand = Oxide.Core.Database.Sql.Builder.Append(sqlQuery, state, fromaddress, target, plugin.getclimate());
sqlLibrary.Insert(insertCommand, sqlConnection, rowsAffectedwrite => { if (rowsAffectedwrite > 0) { if (_ServerSettings.ShowDebugMsg) { Puts("UpdateSync New Record inserted with ID: {0}", sqlConnection.LastInsertRowId); } } });
});
}
//Checks the state of players
private void ReadPlayers(string Target, ulong steamid, Network.Connection connection)
{
string sqlQuery = "SELECT `state`, `target`, `sender` FROM players WHERE `steamid` = @0;";
Sql selectCommand = Oxide.Core.Database.Sql.Builder.Append(sqlQuery, steamid.ToString());
sqlLibrary.Query(selectCommand, sqlConnection, list =>
{
if (list == null)
{
//creates new player data
if (_ServerSettings.ShowDebugMsg) { Puts("ReadPlayers No Player Data For " + steamid.ToString() + " Creating It"); }
UpdatePlayers(Target, Target, "Playing", steamid.ToString());
return;
}
foreach (Dictionary<string, object> entry in list)
{
//Redirect player to last server they were in.
if (entry["target"].ToString() != thisserverip + ":" + thisserverport && entry["state"].ToString() != "Moving" && entry["state"].ToString() != "Ready" && connection != null)
{
if (BasePlayer.FindByID(connection.ownerid).IPlayer.HasPermission(permbypass)) { return; }
string[] server = entry["target"].ToString().Split(':');
if (_ServerSettings.ShowDebugMsg) Puts("ReadPlayers Redirecting " + steamid);
ConsoleNetwork.SendClientCommand(connection, "nexus.redirect", new object[] { server[0], server[1], "" });
return;
}
//Waits for player moving
if (entry["state"].ToString() == "Moving")
{
if (_ServerSettings.ShowDebugMsg) { Puts("ReadPlayers Waiting for server to set player as ready " + steamid); }
return;
}
//Sets flag to move player
if (entry["state"].ToString() == "Ready")
{
if (_ServerSettings.ShowDebugMsg) { Puts("ReadPlayers Player Ready to move " + steamid); }
MovePlayers.Add(ulong.Parse(steamid.ToString()));
//Sets flag back to playing
UpdatePlayers(Target, Target, "Playing", steamid.ToString());
return;
}
return;
}
//Creates new player data
if (_ServerSettings.ShowDebugMsg) { Puts("No Player Data For " + steamid + " Creating It"); }
UpdatePlayers(Target, Target, "Playing", steamid.ToString());
});
}
//Updates players table
private void UpdatePlayers(string fromaddress, string target, string state, string steamid)
{
//trys to update
string sqlQuery = "UPDATE players SET `state` = @0, `target` = @1, `sender` = @2 WHERE `steamid` = @3;";
Sql updateCommand = Oxide.Core.Database.Sql.Builder.Append(sqlQuery, state, target, fromaddress, steamid);
sqlLibrary.Update(updateCommand, sqlConnection, rowsAffected =>
{
if (rowsAffected > 0) { if (_ServerSettings.ShowDebugMsg) { Puts("UpdatePlayers Record Updated"); } return; }
//Failed to update so create new
sqlQuery = "INSERT INTO players (`state`, `target`, `sender`,`steamid`) VALUES (@0, @1, @2, @3);";
Sql insertCommand = Oxide.Core.Database.Sql.Builder.Append(sqlQuery, state, target, fromaddress, steamid);
sqlLibrary.Insert(insertCommand, sqlConnection, rowsAffectedInsert => { if (rowsAffectedInsert > 0) { if (_ServerSettings.ShowDebugMsg) { Puts("UpdatePlayers New Record inserted with ID: {0}", sqlConnection.LastInsertRowId); } } });
});
}
//Connect to mysql database
private void ConnectToMysql(string host, int port, string database, string username, string password)
{
sqlConnection = sqlLibrary.OpenDb(host, port, database, username, password, this);
// Failed message
if (sqlConnection == null || sqlConnection.Con == null) { Puts("Couldn't open the MySQL Database: {0} ", sqlConnection.Con.State.ToString()); }
else { Puts("MySQL server connected: " + host); CreatesTables(); }
}
private void CreatesTables()
{
//Setup tables if they dont exsist
sqlLibrary.Insert(Core.Database.Sql.Builder.Append("CREATE TABLE IF NOT EXISTS `packets` (`id` int(11) unsigned NOT NULL AUTO_INCREMENT, `spawned` int(1) NOT NULL,`timestamp` varchar(64) NOT NULL,`target` varchar(21),`sender` varchar(21),`data` mediumtext, PRIMARY KEY (`id`)) DEFAULT CHARSET=utf8;"), sqlConnection);
sqlLibrary.Insert(Core.Database.Sql.Builder.Append("CREATE TABLE IF NOT EXISTS `sync` (`id` int(11) unsigned NOT NULL AUTO_INCREMENT,`sender` varchar(21),`target` varchar(21),`state` varchar(21),`climate` text, PRIMARY KEY (`id`)) DEFAULT CHARSET=utf8;"), sqlConnection);
sqlLibrary.Insert(Core.Database.Sql.Builder.Append("CREATE TABLE IF NOT EXISTS `players` (`id` int(11) unsigned NOT NULL AUTO_INCREMENT,`sender` varchar(21),`target` varchar(21),`state` varchar(21),`steamid` varchar(21), PRIMARY KEY (`id`)) DEFAULT CHARSET=utf8;"), sqlConnection);
}
#endregion
#region Oxidehooks
private void Init()
{
//Set up permissions
permission.RegisterPermission(permadmin, this);
permission.RegisterPermission(permbypass, this);
plugin = this;
_ServerSettings = new ServerSettings();
//Patch in harmony
//_harmony = new HarmonyLib.Harmony(Name + "PATCH");
_harmony = HarmonyInstance.Create(Name + "PATCH");
Type[] patchType =
{
AccessTools.Inner(typeof(OpenNexus), "World_GetServerBrowserMapName"),
};
foreach (var t in patchType) { new PatchProcessor(_harmony, t, HarmonyMethod.Merge(t.GetHarmonyMethods())).Patch(); }
}
private void OnServerInitialized(bool initial)
{
//Connect to database
ConnectToMysql(_ServerSettings.MySQLHost, _ServerSettings.MySQLPort, _ServerSettings.MySQLDB, _ServerSettings.MySQLUsername, _ServerSettings.MySQLPassword);
//Get Weather data
climate = SingletonComponent<Climate>.Instance;
//Sync weather repeat timer
if (_ServerSettings.SyncTimeWeather) { timer.Every(_ServerSettings.SyncTimeWeaterEvery, () => setclimate()); }
//Determing if need wait for first startup
if (initial) { Fstartup(); } else { Startup(); }
}
private void OnEntitySpawned(BaseEntity baseEntity)
{
//Keep track of cargo ship so they dont collide
if (baseEntity is CargoShip) { ActiveCargoShips.Add(baseEntity as CargoShip); }
}
//Remove cargoship from list when its leaving
private void OnCargoShipEgress(CargoShip cs) { if (ActiveCargoShips.Contains(cs)) { ActiveCargoShips.Remove(cs); } }
private void OnWorldPrefabSpawned(GameObject gameObject, string str)
{
//Remove Uncoded NexusFerry / NexusIsland / FerryTerminal
BaseEntity component = gameObject.GetComponent<BaseEntity>();
if (component != null) { if ((component.prefabID == 2508295857 || component.prefabID == 1924784290 || component.prefabID == 2795004596) && component.OwnerID == 0) { component.Kill(); } }
}
private void OnPlayerSetInfo(Network.Connection connection, string name, string value)
{
//Limits player to 1 server at a time.
if (ProcessingPlayers.Contains(connection.ownerid)) return;
ProcessingPlayers.Add(connection.ownerid);
timer.Once(10f, () => ProcessingPlayers.Remove(connection.ownerid));
if (_ServerSettings.ShowDebugMsg) Puts("Checking if " + connection.ownerid.ToString() + " is already on any OpenNexus servers");
ReadPlayers(thisserverip + ":" + thisserverport, connection.ownerid, connection);
}
private void OnPlayerSleepEnded(BasePlayer player)
{
//Mount players that were mounted.
if (SeatPlayers.ContainsKey(player.userID))
{
MountPlayer(player, SeatPlayers[player.userID]);
SeatPlayers.Remove(player.userID);
}
if (JoinedViaNexus.Contains(player))
{
DirectMessage(player, _ServerSettings.ArriveMSG);
JoinedViaNexus.Remove(player);
}
//Remove transfere protection
player.SetFlag(BaseEntity.Flags.Protected, false);
}
private object CanHelicopterTarget(PatrolHelicopterAI heli, BasePlayer player) { return FerryProtection(player); }
private object CanHelicopterStrafeTarget(PatrolHelicopterAI heli, BasePlayer player) { return FerryProtection(player); }
object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info) { return FerryProtection(entity); }
private void Unload()
{
//Remove plugin created stuff.
foreach (BaseNetworkable basenetworkable in unloadable)
{
//Ferry Terminal
if (basenetworkable.prefabID == 1924784290) { basenetworkable.Kill(); }
//Destroy island
else if (basenetworkable.prefabID == 2795004596) { basenetworkable.Kill(); }
//Distroy ferry
else if (basenetworkable.prefabID == 2508295857)
{
//Eject any entitys on the ferry so they dont drop in water
OpenNexusFerry Ferry = basenetworkable as OpenNexusFerry;
if (Ferry != null)
{
//Dissconnect database
if (sqlConnection != null && sqlConnection.Con != null) { sqlLibrary.CloseDb(sqlConnection); }
//Updates ferry contents list and ejects it to dock.
Ferry.UpdateDockedEntitys();
EjectEntitys(Ferry.GetFerryContents(), Ferry.DockedEntitys, Ferry.EjectionZone.position);
//Destroys Transform objects
UnityEngine.Object.Destroy(Ferry.Arrival.gameObject);
UnityEngine.Object.Destroy(Ferry.CastingOff.gameObject);
UnityEngine.Object.Destroy(Ferry.Departure.gameObject);
UnityEngine.Object.Destroy(Ferry.Docked.gameObject);
UnityEngine.Object.Destroy(Ferry.Docking.gameObject);
UnityEngine.Object.Destroy(Ferry.EjectionZone.gameObject);
Ferry.Kill();
}
}
}
//Remove CUI messaghes
foreach (BasePlayer player in BasePlayer.activePlayerList) { CuiHelper.DestroyUi(player, "FerryInfo"); }
_harmony.UnpatchAll(Name + "PATCH"); //Unpatch harmony
plugin = null;
}
#endregion
#region Startup
private void Fstartup()
{
//Waits for fully loaded before running
timer.Once(10f, () =>
{
//Still starting so run a timer again in 10 sec to check.
try { if (Rust.Application.isLoading) { Fstartup(); return; } } catch { }
//Starup script now.
Startup();
});
}
//Set IP and port of ferry from prefab name
private void SetFerryIPs(OpenNexusFerry OpenFerry, string[] FerrySettings)
{
foreach (string setting in FerrySettings)
{
string[] tempsetting = setting.Split(':');
foreach (string finalsetting in tempsetting)
{
string settingparsed = finalsetting.ToLower().Replace(":", "");
if (settingparsed.Contains("server=")) { OpenFerry.ServerIP = settingparsed.Replace("server=", ""); }
else if (settingparsed.Contains("port=")) { OpenFerry.ServerPort = settingparsed.Replace("port=", ""); }
}
}
}
private void Startup()
{
//Check avaliable plugins that are supported
if (Backpacks == null) { Puts("Backpacks plugin supported https://github.com/LaserHydra/Backpacks"); }
if (Economics == null) { Puts("Economics supported https://umod.org/plugins/economics"); }
if (ZLevelsRemastered == null) { Puts("ZLevels Remastered supported https://umod.org/plugins/zlevels-remastered"); }
if (ServerRewards == null) { Puts("ServerRewards supported https://umod.org/plugins/server-rewards"); }
//Find this servers IP and Port if not manually set
if (thisserverip == "") thisserverip = covalence.Server.Address.ToString();
if (thisserverport == "") thisserverport = covalence.Server.Port.ToString();
Quaternion rotation;
Vector3 position;
//Scan map prefabs
foreach (PrefabData prefabdata in World.Serialization.world.prefabs)
{
switch(prefabdata.id)
{
case 14651698://Heli pad
if (prefabdata.category.ToLower().Contains("opennexus"))
{
HeliPads.Add(prefabdata.position);
}
break;
case 1427415412://Search Lights
if (prefabdata.category.ToLower().Contains("opennexus"))
{
}
break;
case 1924784290://Dock terminal
if (prefabdata.category.ToLower().Contains("opennexus"))
{
NexusDockTerminal terminal = GameManager.server.CreateEntity(StringPool.Get(1924784290), prefabdata.position,prefabdata.rotation) as NexusDockTerminal;
if (terminal == null) continue;
NextFrame(() =>
{
terminal.CancelInvoke("UpdateFerrySchedule");
});
}
break;
case 2508295857://Nexus ferry
//Read settings from prefab name
string[] FerrySettings = prefabdata.category.Replace(@"\", "").Split(',');
if (FerrySettings == null || FerrySettings.Length < 3) { Debug.LogError("OpenNexus ferry not setup properly"); continue; }
//Create rotation/position data
rotation = Quaternion.Euler(new Vector3(prefabdata.rotation.x, prefabdata.rotation.y, prefabdata.rotation.z));
position = new Vector3(prefabdata.position.x, prefabdata.position.y, prefabdata.position.z);
//Create New Ferry
NexusFerry ferry = GameManager.server.CreateEntity(StringPool.Get(2508295857), position, rotation) as NexusFerry;
if (ferry == null) continue;
//Attach open nexus code
OpenNexusFerry OpenFerry = ferry.gameObject.AddComponent<OpenNexusFerry>();
if (OpenFerry == null) continue;
unloadable.Add(OpenFerry);
//Setup with setting in dock prefab name
SetFerryIPs(OpenFerry, FerrySettings);
//Finish creating OpenNexus Ferrys
OpenFerry.prefabID = ferry.prefabID;
OpenFerry.syncPosition = true;
OpenFerry.globalBroadcast = true;
UnityEngine.Object.DestroyImmediate(ferry);
OpenFerry.enableSaving = false;
OpenFerry.Spawn();
break;
case 2795004596://NexusIslands
//Create rotation/position data
rotation = Quaternion.Euler(new Vector3(prefabdata.rotation.x, prefabdata.rotation.y, prefabdata.rotation.z));
position = new Vector3(prefabdata.position.x, prefabdata.position.y, prefabdata.position.z);
NexusIsland island = GameManager.server.CreateEntity(StringPool.Get(2795004596), position, rotation) as NexusIsland;
if (island == null) continue;
OpenNexusIsland openNexusIsland = island.gameObject.AddComponent<OpenNexusIsland>();
unloadable.Add(openNexusIsland);
openNexusIsland.prefabID = island.prefabID;
openNexusIsland.syncPosition = true;
openNexusIsland.globalBroadcast = true;
UnityEngine.Object.DestroyImmediate(island);
openNexusIsland.enableSaving = false;
openNexusIsland.Spawn();
IslandData id = new IslandData();
id.Island = openNexusIsland;
id.location = position;
id.rotation = rotation;
FoundIslands.Add(id);
Puts("Found Island @ " + position.ToString());
break;
}
}
//Remove dead Ferry turrets at junk collection (happens on reboots might shoot though low ground maps)
List<NPCAutoTurret> Z = new List<NPCAutoTurret>();
Vis.Entities<NPCAutoTurret>(Vector3.zero, 25f, Z);
foreach (NPCAutoTurret ss in Z) { ss.Kill(); }
}
#endregion
#region functions
private Vector3 StringToVector3(string sVector) { if (sVector.StartsWith("(") && sVector.EndsWith(")")) { sVector = sVector.Substring(1, sVector.Length - 2); } string[] sArray = sVector.Split(','); Vector3 result = new Vector3(float.Parse(sArray[0]), float.Parse(sArray[1]), float.Parse(sArray[2])); return result; }
private Quaternion StringToQuaternion(string sVector) { if (sVector.StartsWith("(") && sVector.EndsWith(")")) { sVector = sVector.Substring(1, sVector.Length - 2); } string[] sArray = sVector.Split(','); Quaternion result = new Quaternion(float.Parse(sArray[0]), float.Parse(sArray[1]), float.Parse(sArray[2]), float.Parse(sArray[3])); return result; }
private void StartSleeping(BasePlayer player) { if (!player.IsSleeping()) { Interface.CallHook("OnPlayerSleep", player); player.SetPlayerFlag(BasePlayer.PlayerFlags.Sleeping, true); player.sleepStartTime = Time.time; BasePlayer.sleepingPlayerList.Add(player); player.CancelInvoke("InventoryUpdate"); player.CancelInvoke("TeamUpdate"); player.SendNetworkUpdateImmediate(); } }
private bool HasPermission(BasePlayer player, string perm) => permission.UserHasPermission(player.UserIDString, perm);
private bool IsSteamId(string id) { ulong userId; if (!ulong.TryParse(id, out userId)) { return false; } return userId > 76561197960265728L; }
private void DestroyMeshCollider(BaseEntity ent) { foreach (var mesh in ent.GetComponentsInChildren<MeshCollider>()) { UnityEngine.Object.DestroyImmediate(mesh); } }
private void DestroyGroundComp(BaseEntity ent)
{
foreach (var groundmissing in ent.GetComponentsInChildren<DestroyOnGroundMissing>().ToArray()) { UnityEngine.Object.DestroyImmediate(groundmissing); }
foreach (var groundwatch in ent.GetComponentsInChildren<GroundWatch>().ToArray()) { UnityEngine.Object.DestroyImmediate(groundwatch); }
}
private object FerryProtection(BaseEntity be)
{
BaseEntity Ferry = be.GetParentEntity();
if (Ferry != null && Ferry is OpenNexusFerry) { return false; }
return null;
}
private void MessageScreen(string msg, Vector3 pos, float radius, int delay = 8)
{
if (_ServerSettings.StatusMsg == false) { return; }
foreach (BasePlayer player in BasePlayer.activePlayerList)
{
if (player.Distance(pos) < _ServerSettings.MSGDistance)
{
if (!player.IsSleeping()) { DirectMessage(player, msg, delay); }
}
}
List<BasePlayer> PlayersInRange = new List<BasePlayer>();
//Scans area for players
Vis.Entities<BasePlayer>(pos, radius, PlayersInRange);
//Shows CUI to each player in range
if (PlayersInRange.Count != 0) { foreach (BasePlayer player in PlayersInRange.ToArray()) { if (!player.IsSleeping()) { DirectMessage(player, msg, delay); } } }
}
private void DirectMessage(BasePlayer player, string msg, int delay = 8)
{
CuiHelper.DestroyUi(player, "FerryInfo");
var elements = new CuiElementContainer();
elements.Add(new CuiLabel { Text = { Text = msg, FontSize = _ServerSettings.FontSize, Align = TextAnchor.MiddleCenter, FadeIn = _ServerSettings.FontFadeIn, Color = _ServerSettings.FontColour }, RectTransform = { AnchorMin = _ServerSettings.AnchorMin, AnchorMax = _ServerSettings.AnchorMax } }, "Overlay", "FerryInfo");
CuiHelper.AddUi(player, elements);
//Destroys message after delay
timer.Once(delay, () => { CuiHelper.DestroyUi(player, "FerryInfo"); });
}
private void AddLock(BaseEntity ent, string data)
{
//Recreates codelocks
string[] codedata = data.Split(new string[] { "<CodeLock>" }, System.StringSplitOptions.RemoveEmptyEntries);
string[] wlp = codedata[4].Split(new string[] { "<player>" }, System.StringSplitOptions.RemoveEmptyEntries);
CodeLock alock = GameManager.server.CreateEntity("assets/prefabs/locks/keypad/lock.code.prefab") as CodeLock;
alock.Spawn();
foreach (string wl in wlp) { alock.whitelistPlayers.Add(ulong.Parse(wl)); }
try { alock.OwnerID = alock.whitelistPlayers[0]; } catch { }
alock.code = codedata[2];
alock.SetParent(ent, ent.GetSlotAnchorName(BaseEntity.Slot.Lock));
alock.transform.localPosition = StringToVector3(codedata[0]);
alock.transform.localRotation = StringToQuaternion(codedata[1]);
ent.SetSlot(BaseEntity.Slot.Lock, alock);
alock.SetFlag(BaseEntity.Flags.Locked, bool.Parse(codedata[3]));
alock.enableSaving = true;
alock.SendNetworkUpdateImmediate(true);
}
private void MountPlayer(BasePlayer player, int seatnum)
{
//Try mount seat given in setting
List<BaseVehicle> bv = new List<BaseVehicle>();
Vis.Entities<BaseVehicle>(player.transform.position, 1f, bv);
try
{
foreach (BaseVehicle seat in bv)
{
if (!seat.GetMountPoint(seatnum).mountable.HasValidDismountPosition(player))
{
player.Teleport(player.transform.position += new Vector3(0, 3, 0));
return;
}
seat.GetMountPoint(seatnum).mountable.MountPlayer(player);
return;
}
}
catch { }
//Fall back to find nearest seat and mount
List<BaseMountable> Seats = new List<BaseMountable>();
Vis.Entities<BaseMountable>(player.transform.position, 0.5f, Seats);
BaseMountable closest_seat = null;
foreach (BaseMountable seat in Seats)
{
if (seat.HasFlag(BaseEntity.Flags.Busy)) continue;
if (closest_seat == null) closest_seat = seat;
if (Vector3.Distance(player.transform.position, seat.transform.position) <= Vector3.Distance(player.transform.position, closest_seat.transform.position))
closest_seat = seat;
}
//Trys to mount seat
if (closest_seat != null)
{
BaseMountable seat = closest_seat.GetComponent<BaseMountable>();
if (seat == null || !seat.HasValidDismountPosition(player))
{
player.Teleport(player.transform.position += new Vector3(0, 3, 0));
return;
}
seat.MountPlayer(player);
closest_seat.SendNetworkUpdateImmediate();
player.SendNetworkUpdateImmediate();
}
}
private bool TryFindEjectionPosition(out Vector3 position, Vector3 spawnpos, float radius = 1f)
{
//try 100 times or drop on center
Vector3 position2;
Vector3 position3;
for (int i = 0; i < 100; i++)
{
position2 = new Vector3(Core.Random.Range(spawnpos.x - 8f, spawnpos.x + 8f), spawnpos.y + 2.5f, Core.Random.Range(spawnpos.z - 8f, spawnpos.z + 8f));
if (!TransformUtil.GetGroundInfo(position2, out position2, out position3, 10, 413204481, null))
{
position = spawnpos + new Vector3(0, 5, 0);
return false;
}
if (GamePhysics.CheckSphere(position2, radius, Layers.Mask.Construction | Layers.Server.Deployed | Layers.World | Layers.Server.Players | Layers.Mask.Vehicle_World | Layers.Server.VehiclesSimple | Layers.Server.NPCs, QueryTriggerInteraction.Ignore)) { continue; }
position = position2;
return true;
}
position = spawnpos + new Vector3(0, 5, 0);
return false;
}
private void EjectEntitys(List<BaseNetworkable> currentcontents, List<BaseNetworkable> DockedEntitys, Vector3 EjectionZone)
{
//Ejects anything left on Ferry to dock.
if (currentcontents == null || currentcontents.Count == 0 || DockedEntitys == null || DockedEntitys.Count == 0) { return; }
foreach (BaseEntity entity in currentcontents.ToArray())
{
if (entity != null && DockedEntitys.Contains(entity))
{
//Remove item boxes that might end up on ferry when despawning things
if (entity.ToString().Contains("item_drop"))
{
entity.Kill();
continue;
}
Vector3 serverPosition;
if (plugin.TryFindEjectionPosition(out serverPosition, EjectionZone))
{
if (entity is BasePlayer)
{
BasePlayer player = entity as BasePlayer;
try
{
if (player.IsConnected)
{
player.EnsureDismounted();
if (player.HasParent()) { player.SetParent(null, true, true); }
player.RemoveFromTriggers();
player.SetServerFall(true);
player.SetPlayerFlag(BasePlayer.PlayerFlags.ReceivingSnapshot, true);
}
player.Teleport(serverPosition);
if (player.IsConnected) { player.SendEntityUpdate(); }
player.UpdateNetworkGroup();
player.SendNetworkUpdateImmediate(false);
}
finally
{
player.SetServerFall(false);
player.ForceUpdateTriggers();
}
}
else
{
entity.SetParent(null, false, false);
entity.ServerPosition = serverPosition;
entity.SendNetworkUpdateImmediate(false);
}
continue;
}
}
}
DockedEntitys.Clear();
}
#endregion
#region DatabaseFunctions
//Build database of current time/weather
private string getclimate() { return (TOD_Sky.Instance.Cycle.Year) + "|" + (TOD_Sky.Instance.Cycle.Month) + "|" + (TOD_Sky.Instance.Cycle.Day) + "|" + (TOD_Sky.Instance.Cycle.Hour) + "|" + (climate.WeatherState.Atmosphere.Brightness.ToString()) + "|" + (climate.WeatherState.Atmosphere.Contrast.ToString()) + "|" + (climate.WeatherState.Atmosphere.Directionality.ToString()) + "|" + (climate.WeatherState.Atmosphere.MieMultiplier.ToString()) + "|" + (climate.WeatherState.Atmosphere.RayleighMultiplier.ToString()) + "|" + (climate.WeatherState.Clouds.Attenuation.ToString()) + "|" + (climate.WeatherState.Clouds.Brightness.ToString()) + "|" + (climate.WeatherState.Clouds.Coloring.ToString()) + "|" + (climate.WeatherState.Clouds.Coverage.ToString()) + "|" + (climate.WeatherState.Clouds.Opacity.ToString()) + "|" + (climate.WeatherState.Clouds.Saturation.ToString()) + "|" + (climate.WeatherState.Clouds.Scattering.ToString()) + "|" + (climate.WeatherState.Clouds.Sharpness.ToString()) + "|" + (climate.WeatherState.Clouds.Size.ToString()) + "|" + (climate.Weather.DustChance.ToString()) + "|" + (climate.WeatherState.Atmosphere.Fogginess.ToString()) + "|" + (climate.Weather.FogChance.ToString()) + "|" + (climate.Weather.OvercastChance.ToString()) + "|" + (climate.WeatherState.Rain.ToString()) + "|" + (climate.Weather.RainChance.ToString()) + "|" + (climate.WeatherState.Rainbow.ToString()) + "|" + (climate.Weather.StormChance.ToString()) + "|" + (climate.WeatherState.Thunder.ToString()) + "|" + (climate.WeatherState.Wind.ToString()) + "|"; }
private void setclimate()
{
//Load from database time/weather from the first server in list.
string sqlQuery = "SELECT `sender`, `climate` FROM sync LIMIT 1";
Sql selectCommand = Oxide.Core.Database.Sql.Builder.Append(sqlQuery);
sqlLibrary.Query(selectCommand, sqlConnection, list =>
{
if (list == null) { return; }
foreach (Dictionary<string, object> entry in list)
{
if (entry["sender"].ToString() == thisserverip + ":" + thisserverport) { if (_ServerSettings.ShowDebugMsg) Puts("Dont Sync Weather/Time this is first server"); return; }
string[] settings = entry["climate"].ToString().Split('|');
TOD_Sky.Instance.Cycle.Year = int.Parse(settings[0]);
TOD_Sky.Instance.Cycle.Month = int.Parse(settings[1]);
TOD_Sky.Instance.Cycle.Day = int.Parse(settings[2]);
TOD_Sky.Instance.Cycle.Hour = float.Parse(settings[3]);
climate.WeatherState.Atmosphere.Brightness = float.Parse(settings[4]);
climate.WeatherState.Atmosphere.Contrast = float.Parse(settings[5]);
climate.WeatherState.Atmosphere.Directionality = float.Parse(settings[6]);
climate.WeatherState.Atmosphere.MieMultiplier = float.Parse(settings[7]);
climate.WeatherState.Atmosphere.RayleighMultiplier = float.Parse(settings[8]);
climate.WeatherState.Clouds.Attenuation = float.Parse(settings[9]);
climate.WeatherState.Clouds.Brightness = float.Parse(settings[10]);
climate.WeatherState.Clouds.Coloring = float.Parse(settings[11]);
climate.WeatherState.Clouds.Coverage = float.Parse(settings[12]);
climate.WeatherState.Clouds.Opacity = float.Parse(settings[13]);
climate.WeatherState.Clouds.Saturation = float.Parse(settings[14]);
climate.WeatherState.Clouds.Scattering = float.Parse(settings[15]);
climate.WeatherState.Clouds.Sharpness = float.Parse(settings[16]);
climate.WeatherState.Clouds.Size = float.Parse(settings[17]);
climate.Weather.DustChance = float.Parse(settings[18]);
climate.WeatherState.Atmosphere.Fogginess = float.Parse(settings[19]);
climate.Weather.FogChance = float.Parse(settings[20]);
climate.Weather.OvercastChance = float.Parse(settings[21]);
climate.WeatherState.Rain = float.Parse(settings[22]);
climate.Weather.RainChance = float.Parse(settings[23]);
climate.WeatherState.Rainbow = float.Parse(settings[24]);
climate.Weather.StormChance = float.Parse(settings[25]);
climate.WeatherState.Thunder = float.Parse(settings[26]);
climate.WeatherState.Wind = float.Parse(settings[27]);
if (_ServerSettings.ShowDebugMsg) Puts("Synced Weather/Time with first server");
return;
}
});
}
//Create team info
private string getteams(BasePlayer player)
{
string teams = "";
if (player != null)
{
foreach (var playerTeam in RelationshipManager.ServerInstance.teams.Values)
{
if (playerTeam.teamID == 0UL || !playerTeam.teamLeader.IsSteamId() || playerTeam.members.IsNullOrEmpty()) continue;
if (playerTeam.members.Contains(player.userID))
{
teams += playerTeam.teamLeader.ToString() + ",";
foreach (ulong p in playerTeam.members) { try { teams += p.ToString() + "<DN>" + BasePlayer.FindAwakeOrSleeping(p.ToString()).displayName + ","; } catch { } }
}
}
}
return teams;
}
//Restore team info
private void setteams(BasePlayer player, string teamdata)
{
if (teamdata == null || teamdata == "") { return; }
List<ulong> playersinteams = new List<ulong>();
bool alreadyinteam = false;
foreach (var playerTeam in RelationshipManager.ServerInstance.teams.Values)
{
foreach (ulong p in playerTeam.members) { playersinteams.Add(p); }
if (playerTeam.members.Contains(player.userID)) { alreadyinteam = true; }
}
if (alreadyinteam) { return; }
string[] teams = teamdata.Split(',');
ulong _ulong;
Unsubscribe("OnTeamCreated");
RelationshipManager.PlayerTeam aTeam = RelationshipManager.ServerInstance.CreateTeam();
if (ulong.TryParse(teams[0], out _ulong))
{
if (playersinteams.Contains(_ulong)) { aTeam.teamLeader = player.userID; }
else { aTeam.teamLeader = _ulong; }
for (int i = 1; i < teams.Length - 1; i++)
{
string[] userdetails = teams[i].Split(new string[] { "<DN>" }, StringSplitOptions.None);
if (!ulong.TryParse(userdetails[0], out _ulong)) { continue; }
if (playersinteams.Contains(_ulong)) { Puts("Player already in another team"); continue; }
playersinteams.Add(_ulong);
if (_ulong == player.userID) { aTeam.AddPlayer(player); }
else
{
BasePlayer bp = BasePlayer.FindAwakeOrSleeping(_ulong.ToString());
if (bp == null)
{
bp = GameManager.server.CreateEntity("assets/prefabs/player/player.prefab").ToPlayer();
bp.lifestate = BaseCombatEntity.LifeState.Dead;
bp.ResetLifeStateOnSpawn = true;
bp.SetFlag(BaseEntity.Flags.Protected, true);
bp.Spawn();
StartSleeping(bp);
bp.CancelInvoke(player.KillMessage);
bp.userID = _ulong;
bp.UserIDString = _ulong.ToString();
bp.displayName = userdetails[1];
bp.eyeHistory.Clear();
bp.lastTickTime = 0f;
bp.lastInputTime = 0f;
bp.stats.Init();
}
if (bp != null)
{
aTeam.AddPlayer(bp);
playersinteams.Add(_ulong);
}
}
}
}
Subscribe("OnTeamCreated");
}
private string getmodifiers(BasePlayer player)
{
//Build database of players current modifiers
string mods = "";
if (player != null && _ServerSettings.Modifiers == true) { foreach (Modifier m in player.modifiers.All) { mods += (m.Type.ToString()) + "," + (m.Source.ToString()) + "," + (m.Value.ToString()) + "," + (m.Duration.ToString()) + "," + (m.TimeRemaining.ToString()) + "<MF>"; } }
return mods;
}
private void setmodifiers(BasePlayer player, string[] mods)
{
//Read from database players modifiers
if (player != null && mods != null && mods.Length != 0 && _ServerSettings.Modifiers == true)
{
List<ModifierDefintion> md = new List<ModifierDefintion>();
foreach (string mod in mods)
{
if (mod == null || mod == "" || !mod.Contains(",")) { continue; }
string[] m = mod.Split(',');
if (m.Length == 5)
{
ModifierDefintion moddef = new ModifierDefintion();
switch (m[0])
{
case "Wood_Yield":
moddef.type = Modifier.ModifierType.Wood_Yield;
break;
case "Ore_Yield":
moddef.type = Modifier.ModifierType.Ore_Yield;
break;
case "Radiation_Resistance":
moddef.type = Modifier.ModifierType.Radiation_Resistance;
break;