public void Join(ulong steamId) { if (CanJoin) { Communication.RedirectClient(steamId, IP); } if (CurrentUsers == 0) { Start(); } CurrentUsers++; }
/// <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(); }
/// <summary> /// DANGER WILL ROBINSON! DANGER! /// </summary> public static void ScrubServer() { var players = new List <IMyPlayer>(); MyAPIGateway.Players.GetPlayers(players); foreach (IMyPlayer p in players) { 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); } } } }