private static void RunDekessler() { var removalCount = 0; var vesselList = VesselStoreSystem.CurrentVesselsInXmlFormat.ToArray(); foreach (var vesselKeyVal in vesselList) { if (IsVesselDebris(vesselKeyVal.Key, vesselKeyVal.Value)) { LunaLog.Normal($"Removing debris vessel: {vesselKeyVal.Key}"); VesselStoreSystem.RemoveVessel(vesselKeyVal.Key); //Send a vessel remove message var msgData = ServerContext.ServerMessageFactory.CreateNewMessageData <VesselRemoveMsgData>(); msgData.VesselId = vesselKeyVal.Key; MessageQueuer.SendToAllClients <VesselSrvMsg>(msgData); removalCount++; } } if (removalCount > 0) { LunaLog.Normal($"Removed {removalCount} debris"); } }
private static void RunDekessler() { var vesselList = FileHandler.GetFilesInPath(Path.Combine(ServerContext.UniverseDirectory, "Vessels")); var removalCount = 0; foreach (var vesselFilePath in vesselList) { var vesselId = Path.GetFileNameWithoutExtension(vesselFilePath); var vesselIsDebris = FileHandler.ReadFileLines(vesselFilePath).Select(l => l.ToLower()) .Any(l => l.Contains("type = ") && l.Contains("debris")); if (vesselId != null && vesselIsDebris) { LunaLog.Normal($"Removing debris vessel: {vesselId}"); //Delete it from the universe Universe.RemoveFromUniverse(vesselFilePath); //Send a vessel remove message //Send it with a delete time of 0 so it shows up for all Players. MessageQueuer.SendToAllClients <VesselSrvMsg>(new VesselRemoveMsgData { VesselId = Guid.Parse(vesselId) }); removalCount++; } } if (removalCount > 0) { LunaLog.Normal($"Removed {removalCount} debris"); } }
private static void HandleVesselDock(ClientStructure client, VesselBaseMsgData message) { var msgData = (VesselDockMsgData)message; LunaLog.Debug($"Docking message received! Dominant vessel: {msgData.DominantVesselId}"); if (VesselContext.RemovedVessels.Contains(msgData.WeakVesselId)) { return; } if (VesselStoreSystem.VesselExists(msgData.DominantVesselId)) { LunaLog.Debug($"Saving DOCKED vessel {msgData.DominantVesselId} from {client.PlayerName}. Bytes: {msgData.NumBytes}"); } VesselDataUpdater.RawConfigNodeInsertOrUpdate(msgData.DominantVesselId, Encoding.UTF8.GetString(msgData.FinalVesselData, 0, msgData.NumBytes)); //Now remove the weak vessel but DO NOT add to the removed vessels as they might undock!!! LunaLog.Debug($"Removing weak docked vessel {msgData.WeakVesselId}"); VesselStoreSystem.RemoveVessel(msgData.WeakVesselId); MessageQueuer.RelayMessage <VesselSrvMsg>(client, msgData); //Tell all clients to remove the weak vessel var removeMsgData = ServerContext.ServerMessageFactory.CreateNewMessageData <VesselRemoveMsgData>(); removeMsgData.VesselId = msgData.WeakVesselId; MessageQueuer.SendToAllClients <VesselSrvMsg>(removeMsgData); }
private static void RunDekessler() { var vesselList = FileHandler.GetFilesInPath(Path.Combine(ServerContext.UniverseDirectory, "Vessels")); var removalCount = 0; foreach (var vesselFilePath in vesselList) { var vesselId = Path.GetFileNameWithoutExtension(vesselFilePath); if (!File.Exists(vesselFilePath)) continue; var vesselIsDebris = FileHandler.ReadFileLines(vesselFilePath).Select(l=> l.ToLower()) .Any(l => l.Contains("type = ") && l.Contains("debris")); if (vesselId != null && vesselIsDebris) { LunaLog.Normal($"Removing debris vessel: {vesselId}"); //Delete it from the universe Universe.RemoveFromUniverse(vesselFilePath); //Send a vessel remove message var msgData = ServerContext.ServerMessageFactory.CreateNewMessageData<VesselRemoveMsgData>(); msgData.VesselId = Guid.Parse(vesselId); MessageQueuer.SendToAllClients<VesselSrvMsg>(msgData); removalCount++; } } if (removalCount > 0) LunaLog.Normal($"Removed {removalCount} debris"); }
private static void HandleVesselDock(ClientStructure client, VesselBaseMsgData message) { var msgData = (VesselDockMsgData)message; LunaLog.Debug($"Docking message received! Dominant vessel: {msgData.DominantVesselId}"); if (VesselContext.RemovedVessels.Contains(msgData.WeakVesselId)) { return; } var path = Path.Combine(ServerContext.UniverseDirectory, "Vessels", $"{msgData.DominantVesselId}.txt"); if (!File.Exists(path)) { LunaLog.Debug($"Saving vessel {msgData.DominantVesselId} from {client.PlayerName}"); } FileHandler.WriteToFile(path, msgData.FinalVesselData, msgData.NumBytes); //Now remove the weak vessel LunaLog.Debug($"Removing weak docked vessel {msgData.WeakVesselId}"); Universe.RemoveFromUniverse(Path.Combine(ServerContext.UniverseDirectory, "Vessels", $"{msgData.WeakVesselId}.txt")); VesselContext.RemovedVessels.Add(msgData.WeakVesselId); MessageQueuer.RelayMessage <VesselSrvMsg>(client, msgData); //Tell all clients to remove the weak vessel var removeMsgData = ServerContext.ServerMessageFactory.CreateNewMessageData <VesselRemoveMsgData>(); removeMsgData.VesselId = msgData.WeakVesselId; MessageQueuer.SendToAllClients <VesselSrvMsg>(removeMsgData); }
public static void RunNuke(string commandArgs) { var vesselList = FileHandler.GetFilesInPath(Path.Combine(ServerContext.UniverseDirectory, "Vessels")); var removalsCount = 0; foreach (var vesselFilePath in vesselList) { var vesselId = Path.GetFileNameWithoutExtension(vesselFilePath); var landed = FileHandler.ReadFileLines(vesselFilePath).Any(l => l.Contains("landed At = ") && (l.Contains("KSC") || l.Contains("Runway"))); if (landed) { LunaLog.Normal("Removing vessel " + vesselId + " from KSC"); //Delete it from the universe Universe.RemoveFromUniverse(vesselFilePath); //Send a vessel remove message //Send it with a delete time of 0 so it shows up for all Players. MessageQueuer.SendToAllClients <VesselSrvMsg>( new VesselRemoveMsgData { PlanetTime = 0, VesselId = Guid.Parse(vesselId) }); removalsCount++; } } LunaLog.Normal("Nuked " + removalsCount + " vessels around the KSC"); }
private static void RunNuke() { var vesselList = FileHandler.GetFilesInPath(Path.Combine(ServerContext.UniverseDirectory, "Vessels")); var removalCount = 0; foreach (var vesselFilePath in vesselList) { var vesselId = Path.GetFileNameWithoutExtension(vesselFilePath); var landed = FileHandler.ReadFileLines(vesselFilePath).Select(l => l.ToLower()) .Any(l => l.Contains("landedat = ") && (l.Contains("ksc") || l.Contains("runway"))); if (vesselId != null && landed && !LockSystem.LockQuery.ControlLockExists(new Guid(vesselId))) { LunaLog.Normal($"Removing vessel {vesselId} from KSC"); //Delete it from the universe Universe.RemoveFromUniverse(vesselFilePath); //Send a vessel remove message var msgData = ServerContext.ServerMessageFactory.CreateNewMessageData <VesselRemoveMsgData>(); msgData.VesselId = Guid.Parse(vesselId); MessageQueuer.SendToAllClients <VesselSrvMsg>(msgData); removalCount++; } } if (removalCount > 0) { LunaLog.Normal($"Nuked {removalCount} vessels around the KSC"); } }
private static void RunNuke() { var vesselList = FileHandler.GetFilesInPath(Path.Combine(ServerContext.UniverseDirectory, "Vessels")); var removalCount = 0; foreach (var vesselFilePath in vesselList) { var vesselId = Path.GetFileNameWithoutExtension(vesselFilePath); var landed = FileHandler.ReadFileLines(vesselFilePath).Select(l => l.ToLower()) .Any(l => l.Contains("landed at = ") && (l.Contains("ksc") || l.Contains("runway"))); if (vesselId != null && landed) { LunaLog.Normal($"Removing vessel {vesselId} from KSC"); //Delete it from the universe Universe.RemoveFromUniverse(vesselFilePath); //Send a vessel remove message //Send it with a delete time of 0 so it shows up for all Players. MessageQueuer.SendToAllClients <VesselSrvMsg>(new VesselRemoveMsgData { VesselId = Guid.Parse(vesselId) }); removalCount++; } } if (removalCount > 0) { LunaLog.Normal($"Nuked {removalCount} vessels around the KSC"); } }
private static void RunNuke() { uint removalCount = 0; var vesselList = VesselStoreSystem.CurrentVessels.ToArray(); foreach (var vesselKeyVal in vesselList) { if (vesselKeyVal.Value.Fields.GetSingle("landed").Value.ToLower() == "true" && vesselKeyVal.Value.Fields.GetSingle("landedAt").Value.ToLower().Contains("ksc") || vesselKeyVal.Value.Fields.GetSingle("landedAt").Value.ToLower().Contains("runway") || vesselKeyVal.Value.Fields.GetSingle("landedAt").Value.ToLower().Contains("launchpad")) { LunaLog.Normal($"Removing vessel: {vesselKeyVal.Key} from KSC"); VesselStoreSystem.RemoveVessel(vesselKeyVal.Key); //Send a vessel remove message var msgData = ServerContext.ServerMessageFactory.CreateNewMessageData <VesselRemoveMsgData>(); msgData.VesselId = vesselKeyVal.Key; MessageQueuer.SendToAllClients <VesselSrvMsg>(msgData); removalCount++; } } if (removalCount > 0) { LunaLog.Normal($"Nuked {removalCount} vessels around the KSC"); } }
public static void RunDekessler(string commandText) { var vesselList = FileHandler.GetFilesInPath(Path.Combine(ServerContext.UniverseDirectory, "Vessels")); var removalCount = 0; foreach (var vesselFilePath in vesselList) { var vesselIsDebris = FileHandler.ReadFileLines(vesselFilePath) .Any(l => l.Contains("Type = ") && l.Contains("Debris")); if (vesselIsDebris) { var vesselId = Path.GetFileNameWithoutExtension(vesselFilePath); LunaLog.Normal("Removing vessel: " + vesselId); //Delete it from the universe Universe.RemoveFromUniverse(vesselFilePath); //Send a vessel remove message //Send it with a delete time of 0 so it shows up for all Players. MessageQueuer.SendToAllClients <VesselSrvMsg>(new VesselRemoveMsgData { PlanetTime = 0, VesselId = Guid.Parse(vesselId) }); removalCount++; LunaLog.Debug("Removed debris vessel " + vesselId); } } LunaLog.Normal("Removed " + removalCount + " debris"); }
public static void UpdateGroup(string clientPlayerName, Group group) { if (Groups.TryGetValue(group.Name, out var existingGroup)) { if (existingGroup.Owner == clientPlayerName) { //We are the owner of the group so we can do whatever we want if (Groups.TryUpdate(group.Name, group, existingGroup)) { var msgData = ServerContext.ServerMessageFactory.CreateNewMessageData <GroupUpdateMsgData>(); msgData.Group = group; MessageQueuer.SendToAllClients <GroupSrvMsg>(msgData); Task.Run(() => SaveGroups()); } } else { //We are not the owner of the group so the only thing we can do is to add ourself to the "invited" hashset if (group.Owner == existingGroup.Owner && Common.ScrambledEquals(group.Members, existingGroup.Members)) { var invited = group.Invited.Except(existingGroup.Invited).ToArray(); if (invited.Length == 1 && invited[0] == clientPlayerName && Groups.TryUpdate(group.Name, group, existingGroup)) { var msgData = ServerContext.ServerMessageFactory.CreateNewMessageData <GroupUpdateMsgData>(); msgData.Group = group; MessageQueuer.SendToAllClients <GroupSrvMsg>(msgData); Task.Run(() => SaveGroups()); } } } } }
private static void HandleVesselRemove(ClientStructure client, VesselBaseMsgData message) { var data = (VesselRemoveMsgData)message; if (data.Force) { LunaLog.Debug($"Received a FORCED remove against vessel {data.VesselId} from {client.PlayerName}"); } if (!data.Force && LockSystem.LockQuery.ControlLockExists(data.VesselId) && !LockSystem.LockQuery.ControlLockBelongsToPlayer(data.VesselId, client.PlayerName)) { return; } if (VesselStoreSystem.VesselExists(data.VesselId)) { LunaLog.Debug($"Removing vessel {data.VesselId} from {client.PlayerName}"); VesselStoreSystem.RemoveVessel(data.VesselId); } if (data.AddToKillList) { VesselContext.RemovedVessels.Add(data.VesselId); } //Relay the message. MessageQueuer.SendToAllClients <VesselSrvMsg>(data); }
/// <summary> /// Sends a notification of new screenshot to all players /// </summary> private static void SendNotification(string folderName) { var msgData = ServerContext.ServerMessageFactory.CreateNewMessageData <ScreenshotNotificationMsgData>(); msgData.FolderName = folderName; MessageQueuer.SendToAllClients <ScreenshotSrvMsg>(msgData); }
public static void NotifyPlayersRemovedAdmin(string playerName) { var newMessage = ServerContext.ServerMessageFactory.CreateNewMessageData <AdminRemoveMsgData>(); newMessage.PlayerName = playerName; MessageQueuer.SendToAllClients <AdminSrvMsg>(newMessage); }
public void SendToLMP(string message) { var msgData = ServerContext.ServerMessageFactory.CreateNewMessageData <ChatMsgData>(); msgData.From = GeneralSettings.SettingsStore.ConsoleIdentifier; msgData.Text = message; MessageQueuer.SendToAllClients <ChatSrvMsg>(msgData); }
public static void RemoveGroup(string clientPlayerName, string groupName) { if (Groups.TryGetValue(groupName, out var existingGroup) && existingGroup.Owner == clientPlayerName && Groups.TryRemove(groupName, out _)) { var msgData = ServerContext.ServerMessageFactory.CreateNewMessageData <GroupRemoveMsgData>(); msgData.GroupName = groupName; MessageQueuer.SendToAllClients <GroupSrvMsg>(msgData); Task.Run(() => SaveGroups()); } }
public override void Execute(string commandArgs) { LunaLog.Normal($"Broadcasting {commandArgs}"); var msgData = ServerContext.ServerMessageFactory.CreateNewMessageData <ChatChannelMsgData>(); msgData.SendToAll = true; msgData.From = GeneralSettings.SettingsStore.ConsoleIdentifier; msgData.Text = commandArgs; MessageQueuer.SendToAllClients <ChatSrvMsg>(msgData); }
public override void Execute(string commandArgs) { LunaLog.Normal($"Broadcasting {commandArgs}"); var newMessageData = new ChatChannelMsgData { SendToAll = true, From = GeneralSettings.SettingsStore.ConsoleIdentifier, Text = commandArgs }; MessageQueuer.SendToAllClients <ChatSrvMsg>(newMessageData); }
public static void HandleFlagDataMessage(ClientStructure client, FlagDataMsgData message) { var playerFlagPath = Path.Combine(FlagPath, client.PlayerName); if (!FileHandler.FolderExists(playerFlagPath)) { FileHandler.FolderCreate(playerFlagPath); } LunaLog.Debug($"Saving flag {message.Flag.FlagName} from {client.PlayerName}"); FileHandler.WriteToFile(Path.Combine(playerFlagPath, message.Flag.FlagName), message.Flag.FlagData, message.Flag.NumBytes); MessageQueuer.SendToAllClients <FlagSrvMsg>(message); }
/// <summary> /// Saves a received craft /// </summary> public static void SaveCraft(ClientStructure client, CraftLibraryDataMsgData data) { Task.Run(() => { var playerFolderType = Path.Combine(CraftFolder, client.PlayerName, data.Craft.CraftType.ToString()); if (!Directory.Exists(playerFolderType)) { Directory.CreateDirectory(playerFolderType); } var lastTime = LastRequest.GetOrAdd(client.PlayerName, DateTime.MinValue); if (DateTime.Now - lastTime > TimeSpan.FromMilliseconds(CraftSettings.SettingsStore.MinCraftLibraryRequestIntervalMs)) { LastRequest.AddOrUpdate(client.PlayerName, DateTime.Now, (key, existingVal) => DateTime.Now); var fileName = $"{data.Craft.CraftName}.craft"; var fullPath = Path.Combine(playerFolderType, fileName); if (FileHandler.FileExists(fullPath)) { LunaLog.Normal($"Overwriting craft {data.Craft.CraftName} ({data.Craft.NumBytes} bytes) from: {client.PlayerName}."); //Send a msg to all the players so they remove the old copy var deleteMsg = ServerContext.ServerMessageFactory.CreateNewMessageData <CraftLibraryDeleteRequestMsgData>(); deleteMsg.CraftToDelete.CraftType = data.Craft.CraftType; deleteMsg.CraftToDelete.CraftName = data.Craft.CraftName; deleteMsg.CraftToDelete.FolderName = data.Craft.FolderName; MessageQueuer.SendToAllClients <CraftLibrarySrvMsg>(deleteMsg); } else { LunaLog.Normal($"Saving craft {data.Craft.CraftName} ({data.Craft.NumBytes} bytes) from: {client.PlayerName}."); FileHandler.WriteToFile(fullPath, data.Craft.Data, data.Craft.NumBytes); } SendNotification(client.PlayerName); } else { LunaLog.Warning($"{client.PlayerName} is sending crafts too fast!"); return; } //Remove oldest crafts if the player has too many RemovePlayerOldestCrafts(playerFolderType); //Checks if we are above the max folders limit CheckMaxFolders(); }); }
public static void SendLockAquireMessage(LockDefinition lockDefinition, bool force) { var lockResult = LockSystem.AcquireLock(lockDefinition, force); var newMessageData = new LockAcquireMsgData { Lock = lockDefinition, LockResult = lockResult, Force = force }; MessageQueuer.SendToAllClients <LockSrvMsg>(newMessageData); LunaLog.Debug(lockResult ? $"{lockDefinition.PlayerName} acquired lock {lockDefinition}" : $"{lockDefinition.PlayerName} failed to acquire lock {lockDefinition}"); }
//Sets given funds value private static void SetFunds(double funds) { //Fund update to server ScenarioDataUpdater.WriteFundsDataToFile(funds); //Fund update to all other clients var data = ServerContext.ServerMessageFactory.CreateNewMessageData <ShareProgressFundsMsgData>(); data.Funds = funds; data.Reason = "Server Command"; MessageQueuer.SendToAllClients <ShareProgressSrvMsg>(data); LunaLog.Debug($"Funds received: {data.Funds} Reason: {data.Reason}"); ScenarioDataUpdater.WriteFundsDataToFile(data.Funds); //var msgData = ServerContext.ServerMessageFactory.CreateNewMessageData<ChatMsgData>(); //msgData.From = GeneralSettings.SettingsStore.ConsoleIdentifier; //msgData.Text = "Funds were changed to " + funds.ToString(); //MessageQueuer.SendToAllClients<ChatSrvMsg>(msgData); }
//Sets given science value private static void SetScience(float science) { //Science update to server ScenarioDataUpdater.WriteScienceDataToFile(science); //Science update to all other clients var data = ServerContext.ServerMessageFactory.CreateNewMessageData <ShareProgressScienceMsgData>(); data.Science = science; data.Reason = "Server Command"; MessageQueuer.SendToAllClients <ShareProgressSrvMsg>(data); LunaLog.Debug($"Science received: {data.Science} Reason: {data.Reason}"); ScenarioDataUpdater.WriteScienceDataToFile(data.Science); //var msgData = ServerContext.ServerMessageFactory.CreateNewMessageData<ChatMsgData>(); //msgData.From = GeneralSettings.SettingsStore.ConsoleIdentifier; //msgData.Text = "Science was changed to " + science.ToString(); //MessageQueuer.SendToAllClients<ChatSrvMsg>(msgData); }
public static void HandleFlagDeleteMessage(ClientStructure client, FlagDeleteMsgData message) { var playerFlagPath = Path.Combine(FlagPath, client.PlayerName); if (FileHandler.FolderExists(playerFlagPath)) { var flagFile = Path.Combine(playerFlagPath, message.FlagName); if (FileHandler.FileExists(flagFile)) { FileHandler.FileDelete(flagFile); } if (FileHandler.GetFilesInPath(playerFlagPath).Length == 0) { FileHandler.FolderDelete(playerFlagPath); } } MessageQueuer.SendToAllClients <FlagSrvMsg>(message); }
public static void SendLockAquireMessage(string lockName, string playerName, bool force) { var lockResult = LockSystem.AcquireLock(lockName, playerName, force); var newMessageData = new LockAcquireMsgData { PlayerName = playerName, LockName = lockName, LockResult = lockResult, Force = force }; MessageQueuer.SendToAllClients <LockSrvMsg>(newMessageData); LunaLog.Debug(lockResult ? $"{playerName} acquired lock {lockName}" : $"{playerName} failed to acquire lock {lockName}"); }
/// <summary> /// Deletes a requested craft /// </summary> public static void DeleteCraft(ClientStructure client, CraftLibraryDeleteRequestMsgData data) { if (client.PlayerName != data.CraftToDelete.FolderName) { return; } var file = Path.Combine(CraftPath, data.CraftToDelete.FolderName, data.CraftToDelete.CraftType.ToString(), $"{data.CraftToDelete.CraftName}.craft"); if (FileHandler.FileExists(file)) { FileHandler.FileDelete(file); LunaLog.Debug($"Deleting craft {data.CraftToDelete.CraftName} as requested by {client.PlayerName}."); MessageQueuer.SendToAllClients <CraftLibrarySrvMsg>(data); } }
public static void CreateGroup(string clientPlayerName, string groupName) { if (!Groups.ContainsKey(groupName)) { var newGroup = new Group(); newGroup.Members = new[] { clientPlayerName }; newGroup.MembersCount = 1; newGroup.Owner = clientPlayerName; newGroup.Name = groupName; if (Groups.TryAdd(groupName, newGroup)) { var msgData = ServerContext.ServerMessageFactory.CreateNewMessageData <GroupUpdateMsgData>(); msgData.Group = newGroup; MessageQueuer.SendToAllClients <GroupSrvMsg>(msgData); Task.Run(() => SaveGroups()); } } }
public static void ReleaseAndSendLockReleaseMessage(LockDefinition lockDefinition) { var lockResult = LockSystem.ReleaseLock(lockDefinition); if (lockResult) { var newMessageData = new LockReleaseMsgData { Lock = lockDefinition, LockResult = true }; MessageQueuer.SendToAllClients <LockSrvMsg>(newMessageData); LunaLog.Debug($"{lockDefinition.PlayerName} released lock {lockDefinition}"); } else { LunaLog.Debug($"{lockDefinition.PlayerName} failed to release lock {lockDefinition}"); } }
public static void HandleMessage(ClientStructure client, IClientMessageBase message) { var messageData = (ChatMsgData)message.Data; if (messageData.From != client.PlayerName) { return; } if (messageData.Relay) { MessageQueuer.SendToAllClients <ChatSrvMsg>(messageData); LunaLog.ChatMessage($"{messageData.From}: {messageData.Text}"); } else //Is a PM to server msg { LunaLog.Warning($"{messageData.From}: {messageData.Text}"); } }
//Removes all matching vessels private static void RunRemove(string vesselType, string vesselSituation, string vesselSplashed, string vesselName) { var removalCount = 0; var vesselList = VesselStoreSystem.CurrentVessels.ToArray(); foreach (var vesselKeyVal in vesselList.Where(v => IsVesselFound(v.Value, vesselType, vesselSituation, vesselSplashed, vesselName))) { LunaLog.Normal($"Removing vessel: {vesselKeyVal.Key}"); VesselStoreSystem.RemoveVessel(vesselKeyVal.Key); var msgData = ServerContext.ServerMessageFactory.CreateNewMessageData <VesselRemoveMsgData>(); msgData.VesselId = vesselKeyVal.Key; MessageQueuer.SendToAllClients <VesselSrvMsg>(msgData); removalCount++; } LunaLog.Normal(removalCount > 0 ? $"Removed {removalCount} vessel(s) ..." : "Removed nothing ..."); }