/// <summary> /// DANGER WILL ROBINSON! DANGER! /// </summary> public static void ScrubServer() { var players = new List <IMyPlayer>(); MyAPIGateway.Players.GetPlayers(players); foreach (IMyPlayer p in players) { var block = p?.Controller?.ControlledEntity?.Entity as IMyCubeBlock; IMyCubeGrid grid = block?.CubeGrid; if (grid == null) { LinkModCore.Instance.PlayerGrids.TryGetValue(p.SteamUserId, out grid); } if (grid != null) { byte[] payload = Utilities.SerializeAndSign(grid, p, block?.Position ?? Vector3I.Zero); Communication.SegmentAndSend(Communication.MessageType.ClientGridPart, payload, MyAPIGateway.Multiplayer.ServerId, p.SteamUserId); } Communication.RedirectClient(p.SteamUserId, Settings.Instance.HubIP); } var timer = new Timer(10000); timer.AutoReset = false; timer.Elapsed += (a, b) => { MyAPIGateway.Utilities.InvokeOnGameThread(() => { var entities = new HashSet <IMyEntity>(); MyAPIGateway.Entities.GetEntities(entities); foreach (IMyEntity ent in entities) { if (ent is IMyCharacter) { continue; } ent.Close(); } foreach (KeyValuePair <long, IMyFaction> fac in MyAPIGateway.Session.Factions.Factions) { MyAPIGateway.Session.Factions.RemoveFaction(fac.Key); } }); }; timer.Start(); }
public void HandleChatCommand(ulong steamId, string command) { MyPromoteLevel level = MyAPIGateway.Session.GetUserPromoteLevel(steamId); Logging.Instance.WriteLine($"Got chat command from {steamId} : {command}"); if (command.Equals("!join", StringComparison.CurrentCultureIgnoreCase)) { if (!Settings.Instance.Hub) { Communication.SendServerChat(steamId, "Join commands are not valid in battle servers!"); return; } Communication.SendServerChat(steamId, $"There are {Servers.Count} battle servers. Please select the one you want by sending '!join [number]'"); List <int> availableServers = (from server in Servers.Values where server.CanJoin select server.Index + 1).ToList(); if (availableServers.Count < Servers.Count) { Communication.SendServerChat(steamId, $"These servers are ready for matches: {string.Join(", ", availableServers)}"); } else { Communication.SendServerChat(steamId, $"All {Servers.Count} servers are available for new matches!"); } return; } if (command.StartsWith("!join", StringComparison.CurrentCultureIgnoreCase)) { int ind = command.IndexOf(" "); if (ind == -1) { Communication.SendServerChat(steamId, "Couldn't parse your server selection!"); return; } string numtex = command.Substring(ind); ServerItem server; int num; if (!int.TryParse(numtex, out num)) { Communication.SendServerChat(steamId, "Couldn't parse your server selection!"); return; } if (!Servers.TryGetValue(num - 1, out server)) { Communication.SendServerChat(steamId, $"Couldn't find server {num}"); return; } if (!server.CanJoin) { Communication.SendServerChat(steamId, "Sorry, this server is not open to new members. Please try another."); return; } IMyPlayer player = Utilities.GetPlayerBySteamId(steamId); var block = player?.Controller?.ControlledEntity?.Entity as IMyCubeBlock; IMyCubeGrid grid = block?.CubeGrid; if (grid == null) { Communication.SendServerChat(steamId, "Can't find your ship. Make sure you're seated in the ship you want to take with you."); return; } var blocks = new List <IMySlimBlock>(); grid.GetBlocks(blocks); if (blocks.Count > Settings.Instance.MaxBlockCount) { Communication.SendServerChat(steamId, $"Your ship has {blocks.Count} blocks. The limit for this server is {Settings.Instance.MaxBlockCount}"); return; } byte[] payload = Utilities.SerializeAndSign(grid, Utilities.GetPlayerBySteamId(steamId), block.Position); Communication.SegmentAndSend(Communication.MessageType.ClientGridPart, payload, MyAPIGateway.Multiplayer.ServerId, steamId); server.Join(steamId); var timer = new Timer(10000); timer.AutoReset = false; timer.Elapsed += (a, b) => MyAPIGateway.Utilities.InvokeOnGameThread(() => grid.Close()); timer.Start(); return; } if (command.Equals("!hub", StringComparison.CurrentCultureIgnoreCase)) { if (Settings.Instance.Hub) { Communication.SendServerChat(steamId, "You're already in the hub!"); return; } Communication.RedirectClient(steamId, Settings.Instance.HubIP); return; } if (level >= MyPromoteLevel.Moderator) { if (command.StartsWith("!spectate", StringComparison.CurrentCultureIgnoreCase)) { int ind = command.IndexOf(" "); if (ind == -1) { Communication.SendServerChat(steamId, "Couldn't parse your server selection!"); return; } string numtex = command.Substring(ind); ServerItem server; int num; if (!int.TryParse(numtex, out num)) { Communication.SendServerChat(steamId, "Couldn't parse your server selection!"); return; } if (!Servers.TryGetValue(num - 1, out server)) { Communication.SendServerChat(steamId, $"Couldn't find server {num}"); return; } MyAPIGateway.Utilities.DeleteFileInLocalStorage("Ship.bin", typeof(LinkModCore)); Communication.RedirectClient(steamId, server.IP); return; } } if (level >= MyPromoteLevel.Admin) { if (command.Equals("!endjoin", StringComparison.CurrentCultureIgnoreCase)) { _lobbyTimer.Stop(); _lobbyRunning = false; _matchRunning = true; Communication.SendNotification(0, "MATCH START!", MyFontEnum.Green); Logging.Instance.WriteLine("Starting match"); _matchTimer.Start(); return; } if (command.Equals("!endmatch", StringComparison.CurrentCultureIgnoreCase)) { _matchTimer.Stop(); _matchRunning = false; Communication.SendNotification(0, "MATCH OVER!", MyFontEnum.Red, 10000); Logging.Instance.WriteLine("Ending match"); Utilities.ScrubServer(); return; } if (command.Equals("!reload", StringComparison.CurrentCultureIgnoreCase)) { Settings.LoadSettings(); Communication.SendServerChat(steamId, "Okay."); return; } if (command.Equals("!save", StringComparison.CurrentCultureIgnoreCase)) { Settings.SaveSettings(); Communication.SendServerChat(steamId, "Okay."); return; } if (command.StartsWith("!reset", StringComparison.CurrentCultureIgnoreCase)) { int ind = command.IndexOf(" "); if (ind == -1) { foreach (var s in Servers.Values) { s.Reset(); } Communication.SendServerChat(steamId, "Reset all servers"); return; } string numtex = command.Substring(ind); ServerItem server; int num; if (!int.TryParse(numtex, out num)) { Communication.SendServerChat(steamId, "Couldn't parse your server selection!"); return; } if (Servers.TryGetValue(num - 1, out server)) { server.Reset(); Communication.SendServerChat(steamId, $"Reset server {num}"); } } } if (command.Equals("!help", StringComparison.CurrentCultureIgnoreCase)) { if (level >= MyPromoteLevel.Admin) { Communication.SendServerChat(steamId, ADMIN_HELP); } else { if (level >= MyPromoteLevel.Moderator) { Communication.SendServerChat(steamId, MODERATOR_HELP); } else { Communication.SendServerChat(steamId, HELP_TEXT); } } } }
public override void UpdateBeforeSimulation() { try { if (MyAPIGateway.Session == null) { return; } _updateCount++; if (!_init) { Initialize(); } if (!_playerInit && MyAPIGateway.Session?.Player?.Character != null) { _playerInit = true; if (MyAPIGateway.Utilities.FileExistsInLocalStorage("Ship.bin", typeof(LinkModCore))) { BinaryReader reader = MyAPIGateway.Utilities.ReadBinaryFileInLocalStorage("Ship.bin", typeof(LinkModCore)); int count = reader.ReadInt32(); byte[] bytes = reader.ReadBytes(count); Logging.Instance.WriteLine($"Sending grid parts: {count} bytes."); Communication.SegmentAndSend(Communication.MessageType.ServerGridPart, bytes, MyAPIGateway.Session.Player.SteamUserId); } else { var character = MyAPIGateway.Session.Player.Character; var pos = Utilities.RandomPositionFromPoint(character.GetPosition(), 500000); var newPos = MyAPIGateway.Entities.FindFreePlace(pos, 5f); character.SetPosition(newPos ?? pos); } //if (!MyAPIGateway.Utilities.FileExistsInLocalStorage("Greeting.cfm", typeof(LinkModCore))) //{ // MyAPIGateway.Utilities.ShowMissionScreen("ServerLink", // "", // null, // "Welcome to the server link demo! Important rules and explanations:\r\n" + // "Pistons and rotors are prohibited.\r\n" + // "Grids are limited to 5k blocks.\r\n" + // "Grids in the hub will always be static, and all weapons are disabled.\r\n" + // "Grids in the hub MUST be owned! Unowned grids and grids beloning to offline players will be deleted every 10 minutes.\r\n\r\n" + // "Hub server provided by Neimoh of Galaxy Strike Force\r\n" + // "Match server #1 provided by Franky500 of Frankys Space\r\n" + // "Be sure to visit their regular servers!\r\n" + // "All other servers provided by X_Wing_Ian\r\n\r\n" + // "Use !join to get a list of servers you can join. Use !help for a full list of commands you can use.\r\n\r\n\r\n" + // "Enjoy!\r\n" + // "-rexxar", // null, // "Close"); // var w = MyAPIGateway.Utilities.WriteFileInLocalStorage("Greeting.cfm", typeof(LinkModCore)); // w.Write("true"); // w.Flush(); // w.Close(); //} //else if (!Settings.Instance.Hub && !Exempt.Contains(MyAPIGateway.Session.Player.SteamUserId)) //{ // MyAPIGateway.Utilities.ShowMessage("System", "You shouldn't be here!"); // Communication.RedirectClient(MyAPIGateway.Session.Player.SteamUserId, Utilities.ZERO_IP); //} } if (MyAPIGateway.Session.Player != null) { if (LobbyTime.HasValue && LobbyTime > DateTime.UtcNow) { IMyHudObjectiveLine line = MyAPIGateway.Utilities.GetObjectiveLine(); line.Title = "Match starting in:"; line.Objectives.Clear(); line.Objectives.Add((DateTime.UtcNow - LobbyTime.Value).ToString(@"mm\:ss")); if (_countdown && !line.Visible) { line.Show(); } } else { if (MatchTime.HasValue && MatchTime >= DateTime.UtcNow) { IMyHudObjectiveLine line = MyAPIGateway.Utilities.GetObjectiveLine(); line.Title = "Match ending in:"; line.Objectives.Clear(); line.Objectives.Add((DateTime.UtcNow - MatchTime.Value).ToString(@"mm\:ss")); if (_countdown && !line.Visible) { line.Show(); } } } } if (MyAPIGateway.Multiplayer.IsServer) { if (Settings.Instance == null) { MyAPIGateway.Utilities.ShowMessage("LinkMod", "Settings not defined on this server! Link mod will not work!"); MyAPIGateway.Utilities.SendMessage("Settings not defined on this server! Link mod will not work!"); return; } if (Settings.Instance.Hub) { if (_updateCount % 10 == 0) { ProcessEnforcement(); } } else { if (_updateCount % 120 == 0) { ProcessCleanup(); } if (_lobbyRunning) { var entities = new HashSet <IMyEntity>(); MyAPIGateway.Entities.GetEntities(entities); foreach (var entity in entities) { var grid = entity as IMyCubeGrid; if (grid?.Physics != null) { entity.Physics.LinearVelocity = Vector3D.ClampToSphere(entity.Physics.LinearVelocity, 10); } } } } } } catch (Exception ex) { Logging.Instance.WriteLine($"Exception during update:\r\n{ex}"); } }
public override void UpdateBeforeSimulation() { if (MyAPIGateway.Multiplayer.IsServer) { return; } if (MyAPIGateway.Session == null) { return; } _updateCount++; if (!_init) { Initialize(); } if (!_playerInit && MyAPIGateway.Session?.Player?.Character != null) { _playerInit = true; if (MyAPIGateway.Utilities.FileExistsInLocalStorage("Ship.bin", typeof(LinkModCore))) { BinaryReader reader = MyAPIGateway.Utilities.ReadBinaryFileInLocalStorage("Ship.bin", typeof(LinkModCore)); int count = reader.ReadInt32(); byte[] bytes = reader.ReadBytes(count); Logging.Instance.WriteLine($"Sending grid parts: {count} bytes."); Communication.SegmentAndSend(Communication.MessageType.ServerGridPart, bytes, MyAPIGateway.Session.Player.SteamUserId); } if (!MyAPIGateway.Utilities.FileExistsInLocalStorage("Greeting.cfm", typeof(LinkModCore))) { MyAPIGateway.Utilities.ShowMissionScreen("ServerLink", "", null, "Welcome to the server link demo! Important rules and explanations:\r\n" + "Pistons and rotors are prohibited.\r\n" + "Grids are limited to 5k blocks.\r\n" + "Grids in the hub will always be static, and all weapons are disabled.\r\n" + "Grids in the hub MUST be owned! Unowned grids and grids beloning to offline players will be deleted every 10 minutes.\r\n\r\n" + "Hub server provided by Neimoh of Galaxy Strike Force\r\n" + "Match server #1 provided by Franky500 of Frankys Space\r\n" + "Be sure to visit their regular servers!\r\n" + "All other servers provided by X_Wing_Ian\r\n\r\n" + "Use !join to get a list of servers you can join. Use !help for a full list of commands you can use.\r\n\r\n\r\n" + "Enjoy!\r\n" + "-rexxar", null, "Close"); var w = MyAPIGateway.Utilities.WriteFileInLocalStorage("Greeting.cfm", typeof(LinkModCore)); w.Write("true"); w.Flush(); w.Close(); } //else if (!Settings.Instance.Hub && !Exempt.Contains(MyAPIGateway.Session.Player.SteamUserId)) //{ // MyAPIGateway.Utilities.ShowMessage("System", "You shouldn't be here!"); // Communication.RedirectClient(MyAPIGateway.Session.Player.SteamUserId, Utilities.ZERO_IP); //} } /* if (MyAPIGateway.Session.Player != null) * { * if (LobbyTime.HasValue && LobbyTime > DateTime.Now) * { * IMyHudObjectiveLine line = MyAPIGateway.Utilities.GetObjectiveLine(); * line.Title = "Match starting in:"; * line.Objectives.Clear(); * line.Objectives.Add((DateTime.Now - LobbyTime.Value).ToString(@"mm\:ss")); * if (_countdown && !line.Visible) * line.Show(); * } * else * { * if (MatchTime.HasValue && MatchTime >= DateTime.Now) * { * IMyHudObjectiveLine line = MyAPIGateway.Utilities.GetObjectiveLine(); * line.Title = "Match ending in:"; * line.Objectives.Clear(); * line.Objectives.Add((DateTime.Now - MatchTime.Value).ToString(@"mm\:ss")); * if (_countdown && !line.Visible) * line.Show(); * } * } * }*/ }