public void Execute(IRocketPlayer caller, string[] command) { bool Console = caller is ConsolePlayer; if (command == null || command.Length == 0 || string.IsNullOrWhiteSpace(command[0])) { SendMessage(caller, $"Invalid Syntax, use /uploadschematic <Name>", Console); return; } var name = command[0].Replace(" ", ""); if (Schematics.Instance.Configuration.Instance.UseDatabase) { try { var file = new FileInfo(ReadWrite.PATH + ServerSavedata.directory + "/" + Provider.serverID + $"/Rocket/Plugins/Schematics/Saved/{name}.dat"); if (file == null || !file.Exists) { SendMessage(caller, $"Can't find file with name of {name} in files. May of never been on this server in first place.", Console); return; } var river = ServerSavedata.openRiver($"/Rocket/Plugins/Schematics/Saved/{name}.dat", isReading: true); try { var verison = river.readByte(); var useDatabase = river.readBoolean(); var Time = river.readUInt32(); var playerposition = river.readSingleVector3(); var barricadecountInt32 = river.readInt32(); var structurecountInt32 = river.readInt32(); river.closeRiver(); var fileStream = new FileStream(file.FullName, FileMode.Open, FileAccess.Read); var binaryReader = new BinaryReader(fileStream); Schematics.Instance.SchematicsDatabaseManager.AddSchematic(name, GetName(caller, Console), Provider.serverName, binaryReader.ReadBytes((int)fileStream.Length), (int)fileStream.Length, barricadecountInt32 + structurecountInt32); binaryReader.Close(); fileStream.Close(); SendMessage(caller, $"Successfully uploaded {name} to database.", Console); file.Delete(); } catch (Exception e) { river.closeRiver(); SendMessage(caller, "Issue uploading file to your database, bad name or file has wrong format.", Console); return; } } catch (Exception e) { SendMessage(caller, "Issue uploading file to your database, wrong name or file has wrong format.", Console); return; } } }
protected override void Load() { Instance = this; ConfigCheck(); // This is a very simple check to delete files that are saved to the Database from Local disk, because they aren't necessary to be saved twice. if (Configuration.Instance.UseDatabase) { SchematicsDatabaseManager = new DatabaseManager(); try { var di = new DirectoryInfo(ReadWrite.PATH + ServerSavedata.directory + "/" + Provider.serverID + "/Rocket/Plugins/Schematics/Saved/"); foreach (var file in di.GetFiles()) { var river = ServerSavedata.openRiver($"/Rocket/Plugins/Schematics/Saved/{file.Name}", true); try { // This is the version, discarded because it's useless to us, but we have to read it to get to the second variable _ = river.readByte(); var useDatabase = river.readBoolean(); if (!useDatabase) { file.Delete(); } river.closeRiver(); } // Failing to get Information, maybe corrupted, not worth logging catch (Exception _) { river.closeRiver(); } } } // This isn't critical catch (Exception _) { } } Logger.Log("Welcome to Schematics! -- If you need help, feel free to email [email protected], contact Miku#2402 or join Our Discord @ https://pandahut.net/discord"); }
public void Execute(IRocketPlayer caller, string[] command) { var Console = caller is ConsolePlayer; if (command == null || command.Length == 0 || string.IsNullOrWhiteSpace(command[0])) { SendMessage(caller, "Invalid Syntax, use /ViewSchematic <Name>", Console); return; } var name = command[0].Replace(" ", ""); if (Schematics.Instance.Configuration.Instance.UseDatabase) { var Schematic = Schematics.Instance.SchematicsDatabaseManager.GetSchematicByName(name); if (Schematic == null) { SendMessage(caller, $"Cannot find {name} in Database", Console); return; } var fs = new FileStream(ReadWrite.PATH + ServerSavedata.directory + "/" + Provider.serverID + $"/Rocket/Plugins/Schematics/Saved/{name}.dat", FileMode.Create, FileAccess.ReadWrite); fs.Write(Schematic.SchmeticBytes, 0, Schematic.Length); fs.Close(); } var river = ServerSavedata.openRiver($"/Rocket/Plugins/Schematics/Saved/{name}.dat", true); var verison = river.readByte(); var useDatabase = river.readBoolean(); var Time = river.readUInt32(); var playerposition = river.readSingleVector3(); var barricadecountInt32 = river.readInt32(); var structurecountInt32 = river.readInt32(); river.closeRiver(); SendMessage(caller, $"{name} was saved at {DateTimeOffset.FromUnixTimeSeconds(Time).ToLocalTime().ToString()} with Plugin Verison {verison}, it has {barricadecountInt32} barricades and {structurecountInt32} structures, total {barricadecountInt32 + structurecountInt32} elements.", Console); }
public void Execute(IRocketPlayer caller, string[] command) { var player = (UnturnedPlayer)caller; if (command == null || command.Length == 0 || string.IsNullOrWhiteSpace(command[0])) { UnturnedChat.Say(caller, "Invalid Syntax, use /Loadschematic <Name> [Optional: -KeepPos -NoState -KeepHealth -SetOwner -SetGroup, Input any Steamid64 to set owner to it]"); return; } if (!UnityEnginePhysics::UnityEngine.Physics.Raycast(player.Player.look.aim.position, player.Player.look.aim.forward, out var hit)) { UnturnedChat.Say(caller, "Cannot get what you're aiming at to spawn the schematic."); return; } // Trying to get better spot where they're aiming, so the schematic doesn't just spawn straight in the floor hit.point += new Vector3(0, 1, 0); var fullcommand = string.Join(" ", command).ToLower(); var keepLocation = false; var keepHealth = false; var keepState = true; ulong SpecificSteamid64 = 0; ulong specificgroup = 0; if (fullcommand.Contains("-keeppos")) { keepLocation = true; } if (keepLocation == false && Schematics.Instance.Configuration.Instance.MaxDistanceToLoadSchematic != 0 && hit.distance > Schematics.Instance.Configuration.Instance.MaxDistanceToLoadSchematic) { UnturnedChat.Say(caller, "You are aiming to somewhere past the configurable Max Distance to Load Schematic."); return; } if (fullcommand.Contains("-keephealth")) { keepHealth = true; } if (fullcommand.Contains("-nostate")) { keepState = false; } if (fullcommand.Contains("-setowner")) { SpecificSteamid64 = player.CSteamID.m_SteamID; } if (fullcommand.Contains("-setgroup")) { specificgroup = player.Player.quests.groupID.m_SteamID; } var match = Schematics.steamid64Regex.Match(fullcommand); if (match.Success && ulong.TryParse(match.Value, out var result)) { SpecificSteamid64 = result; } var name = command[0].Replace(" ", ""); if (Schematics.Instance.Configuration.Instance.UseDatabase) { var Schematic = Schematics.Instance.SchematicsDatabaseManager.GetSchematicByName(name); if (Schematic == null) { UnturnedChat.Say(caller, $"Cannot find {name} in Database"); return; } var fs = new FileStream(ReadWrite.PATH + ServerSavedata.directory + "/" + Provider.serverID + $"/Rocket/Plugins/Schematics/Saved/{name}.dat", FileMode.Create, FileAccess.Write); fs.Write(Schematic.SchmeticBytes, 0, Schematic.SchmeticBytes.Length); fs.Close(); } var river = ServerSavedata.openRiver($"/Rocket/Plugins/Schematics/Saved/{name}.dat", true); var verison = river.readByte(); if (verison == 1) { UnturnedChat.Say(caller, $"Cannot load {name} as it was saved on a different version which is no longer compatible"); return; } var useDatabase = river.readBoolean(); var Time = river.readUInt32(); if (DateTimeOffset.FromUnixTimeSeconds(Time).ToLocalTime() == DateTimeOffset.MinValue) { UnturnedChat.Say(caller, $"Cannot find {name}."); return; } var playerposition = river.readSingleVector3(); UnturnedChat.Say(player, $"Loading {name} saved at {DateTimeOffset.FromUnixTimeSeconds(Time).ToLocalTime().ToString()}"); var setgroupstring = specificgroup == 0 ? "false" : specificgroup.ToString(); var setsteamid64string = SpecificSteamid64 == 0 ? "false" : SpecificSteamid64.ToString(); Logger.Log($"Loading {name} for {player.CharacterName} with parameters Keep Position: {keepLocation}, Keep Health: {keepHealth}, Keep State: {keepState}, Set Group = {setgroupstring} Set Steamid64: {setsteamid64string}."); var barricadecountInt32 = river.readInt32(); var structurecountInt32 = river.readInt32(); var error = 0; for (var i = 0; i < barricadecountInt32; i++) { var barricadeid = river.readUInt16(); var barricadehealth = river.readUInt16(); var barricadestate = river.readBytes(); var point = river.readSingleVector3(); var angleX = river.readByte(); var angleY = river.readByte(); var angleZ = river.readByte(); var owner = river.readUInt64(); var group = river.readUInt64(); var barricade = new Barricade(barricadeid); if (keepHealth) { barricade.health = barricadehealth; } if (keepState) { barricade.state = barricadestate; } if (!keepLocation) { point = point - playerposition + hit.point; } if (SpecificSteamid64 != 0) { owner = SpecificSteamid64; } if (specificgroup != 0) { group = specificgroup; } var rotation = Quaternion.Euler(angleX * 2, angleY * 2, angleZ * 2); //rotation.eulerAngles = new Vector3(angleX, angleY, angleZ); var barricadetransform = BarricadeManager.dropNonPlantedBarricade(barricade, point, rotation, owner, group); if (barricadetransform == null) { error++; return; } var InteractableStorage = barricadetransform.GetComponent <InteractableStorage>(); if (InteractableStorage != null) { BarricadeManager.sendStorageDisplay(barricadetransform, InteractableStorage.displayItem, InteractableStorage.displaySkin, InteractableStorage.displayMythic, InteractableStorage.displayTags, InteractableStorage.displayDynamicProps); } } if (error != 0) { Logger.Log($"Unexpected Barricade Error occured {error} times"); } error = 0; for (var i = 0; i < structurecountInt32; i++) { var structureid = river.readUInt16(); var structurehealth = river.readUInt16(); var point = river.readSingleVector3(); var angleX = river.readByte(); var angleY = river.readByte(); var angleZ = river.readByte(); var owner = river.readUInt64(); var group = river.readUInt64(); var structure = new Structure(structureid); if (keepHealth) { structure.health = structurehealth; } // For when nelson adds proper way to add structures if (!keepLocation) { point = point - playerposition + hit.point; } if (SpecificSteamid64 != 0) { owner = SpecificSteamid64; } if (specificgroup != 0) { group = specificgroup; } var rotation = Quaternion.Euler(angleX * 2, angleY * 2, angleZ * 2); //rotation.eulerAngles = new Vector3(angleX, angleY, angleZ); if (!StructureManager.dropReplicatedStructure(structure, point, rotation, owner, group)) { error++; } } if (error != 0) { Logger.Log($"Unexpected Barricade Error occured {error} times"); } river.closeRiver(); UnturnedChat.Say(player, $"Done, we have loaded Structures: {structurecountInt32} and Barricades: {barricadecountInt32} from {name}"); }
private (List <MyItem>, List <Page>) GetPlayerItems(string steamIdstr)//look up a call of GetPlayerItems for "str" for more info { List <MyItem> myItems = new List <MyItem>(); List <Page> pages = new List <Page>(); Block block = ServerSavedata.readBlock("/Players/" + steamIdstr + "/" + Provider.map + "/Player/Inventory.dat", 0); if (block == null) { return(null, null); } byte num1 = block.readByte();//BUFFER_SIZE for (byte index1 = 0, counter = 0; counter < PlayerInventory.PAGES - 1; index1++, counter++) { byte width = block.readByte(); byte height = block.readByte(); //block.readByte(); //block.readByte(); byte itemCount = block.readByte(); pages.Add(new Page(index1, width, height)); //Console.WriteLine($"Page: {index1}, width: {width}, height: {height}, items on page: {itemCount}"); //if (ignore == EIgnore.MyItems) //{ // for (byte index = 0; index < itemCount; index++) // { // block.readByte(); // block.readByte(); // block.readByte(); // block.readUInt16(); // block.readByte(); // block.readByte(); // block.readByteArray(); // } // continue; //} for (byte index = 0; index < itemCount; index++) { byte x = block.readByte(); byte y = block.readByte(); //byte rot = 0; //if (block.readByte() % 2 != 0) // rot = 1; //else block.readByte(); ushort newID = block.readUInt16(); byte newAmount = block.readByte(); byte newQuality = block.readByte(); byte[] newState = block.readByteArray(); MyItem myItem = new MyItem(newID, newAmount, newQuality, newState);/*, newState, rot, x, y, index1, width, height);*/ //Console.WriteLine($"item: id: {newID}, amt: {newAmount}, qlt: {newQuality}, Page: {counter}"); if (HasItem(myItem, myItems)) { continue; } else { myItems.Add(myItem); } } } return(myItems, pages); }
internal static void HandleCleanup() { if (cleanupProcessingBuildables) { if (cleanupList.Count <= cdIdx) { if (cdIdxCount != 0) { Logger.Log(WreckingBall.Instance.Translate("wreckingball_complete", cdIdx)); } cleanupList.Clear(); cdIdx = 0; cdIdxCount = 0; try { if (!syncError && WreckingBall.isPlayerInfoLibLoaded) { PlayerInfoLib.Database.SetOption((CSteamID)((ulong)playersListBuildables[plbIdx][0]), OptionType.Buildables, true); } } catch (Exception ex) { Logger.LogException(ex); } plbIdx++; if (plbIdx >= WreckingBall.Instance.Configuration.Instance.CleanupPerInterval || plbIdx >= playersListBuildables.Count) { Logger.Log("Finished with cleaning up the player elements in this run."); plbIdx = 0; playersListBuildables.Clear(); cleanupProcessingBuildables = false; SaveManager.save(); } else { syncError = false; // Skip the player buildables cleanup if they have the right permission. if (R.Permissions.HasPermission(new RocketPlayer(playersListBuildables[plbIdx][0].ToString()), "wb.skipbuildables")) { Logger.Log(string.Format("Skipping buildables cleanup for player: {0} [{1}] ({2}).", playersListBuildables[plbIdx][1].ToString(), playersListBuildables[plbIdx][2].ToString(), (ulong)playersListBuildables[plbIdx][0])); } else { Wreck(new ConsolePlayer(), "*", 100000, new Vector3(0, 0, 0), WreckType.Cleanup, FlagType.SteamID, (ulong)playersListBuildables[plbIdx][0], 0); if (cdIdxCount == 0) { Logger.Log(string.Format("No elements found for player: {0} [{1}] ({2}).", playersListBuildables[plbIdx][1].ToString(), playersListBuildables[plbIdx][2].ToString(), (ulong)playersListBuildables[plbIdx][0])); } else { Logger.Log(string.Format("Cleaning up {0} elements for player: {1} [{2}] ({3}).", cdIdxCount, playersListBuildables[plbIdx][1].ToString(), playersListBuildables[plbIdx][2].ToString(), (ulong)playersListBuildables[plbIdx][0])); } } } } } if (cleanupProcessingFiles) { object[] pf = playersListFiles[plfIdx]; bool found = false; bool skipped = false; try { for (byte i = 0; i < Customization.FREE_CHARACTERS + Customization.PRO_CHARACTERS; i++) { // Skip the player data cleanup if they have the right permission. if (R.Permissions.HasPermission(new RocketPlayer(pf[0].ToString()), "wb.skipplayerdata")) { skipped = true; break; } else if (ServerSavedata.folderExists("/Players/" + (ulong)pf[0] + "_" + i)) { ServerSavedata.deleteFolder("/Players/" + (ulong)pf[0] + "_" + i); found = true; } } if (WreckingBall.isPlayerInfoLibLoaded) { PlayerInfoLib.Database.SetOption((CSteamID)(ulong)pf[0], OptionType.PlayerFiles, true); } } catch (Exception ex) { Logger.LogException(ex, "Error in removing player file data, possible files left behind."); } if (found) { Logger.Log(string.Format("Cleaning up player data folders for player: {0} [{1}] ({2}).", pf[1].ToString(), pf[2].ToString(), (ulong)pf[0])); } else if (skipped) { Logger.Log(string.Format("Skipping player data cleanup for player: {0} [{1}] ({2}).", pf[1].ToString(), pf[2].ToString(), (ulong)pf[0])); } else { Logger.Log(string.Format("Player data folders for player: {0} [{1}] ({2}) not found.", pf[1].ToString(), pf[2].ToString(), (ulong)pf[0])); } plfIdx++; if (plfIdx >= WreckingBall.Instance.Configuration.Instance.CleanupPerInterval || plfIdx >= playersListFiles.Count) { Logger.Log("Finished with cleaning up the player's data files in this run."); plfIdx = 0; playersListFiles.Clear(); cleanupProcessingFiles = false; } } if ((DateTime.Now - lastGetCleanupInfo).TotalSeconds > WreckingBall.Instance.Configuration.Instance.CleanupIntervalTime * 60) { lastGetCleanupInfo = DateTime.Now; if (WreckingBall.Instance.Configuration.Instance.BuildableCleanup) { if (playersListBuildables.Count == 0 && WreckingBall.isPlayerInfoLibLoaded) { GetCleanupList(OptionType.Buildables, WreckingBall.Instance.Configuration.Instance.BuildableWaitTime, WreckingBall.Instance.Configuration.Instance.CleanupPerInterval); if (playersListBuildables.Count != 0) { // Start cleanup sequence for the players elements. cleanupProcessingBuildables = true; syncError = false; // Skip the player buildables cleanup if they have the right permission. if (R.Permissions.HasPermission(new RocketPlayer(playersListBuildables[plbIdx][0].ToString()), "wb.skipbuildables")) { Logger.Log(string.Format("Skipping buildables cleanup for player: {0} [{1}] ({2}).", playersListBuildables[plbIdx][1].ToString(), playersListBuildables[plbIdx][2].ToString(), (ulong)playersListBuildables[plbIdx][0])); } else { Wreck(new ConsolePlayer(), "*", 100000, new Vector3(0, 0, 0), WreckType.Cleanup, FlagType.SteamID, (ulong)playersListBuildables[plbIdx][0], 0); if (cdIdxCount == 0) { Logger.Log(string.Format("No elements found for player: {0} [{1}] ({2}).", playersListBuildables[plbIdx][1].ToString(), playersListBuildables[plbIdx][2].ToString(), (ulong)playersListBuildables[plbIdx][0])); } else { Logger.Log(string.Format("Cleaning up {0} elements for player: {1} [{2}] ({3}).", cdIdxCount, playersListBuildables[plbIdx][1].ToString(), playersListBuildables[plbIdx][2].ToString(), (ulong)playersListBuildables[plbIdx][0])); } } } } } if (WreckingBall.Instance.Configuration.Instance.PlayerDataCleanup) { if (playersListFiles.Count == 0 && WreckingBall.isPlayerInfoLibLoaded) { GetCleanupList(OptionType.PlayerFiles, WreckingBall.Instance.Configuration.Instance.PlayerDataWaitTime, WreckingBall.Instance.Configuration.Instance.CleanupPerInterval); if (playersListFiles.Count != 0) { // Start cleanup sequence for the players files. cleanupProcessingFiles = true; } } } } }
public void Execute(IRocketPlayer caller, string[] command) { // Command: /saveSchematic var player = (UnturnedPlayer)caller; if (command == null || command.Length == 0 || command.Length == 1 || string.IsNullOrWhiteSpace(command[0])) { UnturnedChat.Say(player, "Invalid Syntax, use /SaveSchematic <name> <distance> [Optional Parameters: -Owner (Only gets structures placed by you) -Group (only gets structures placed by your current group), Input any Steamid64 to only get results from it"); return; } // Rectangles are planned but not done rn var Rectangle = false; if (!int.TryParse(command[1], out var radius)) { if (Schematics.Instance.RectangleSelectionDictionary.ContainsKey(player.CSteamID)) { if (Schematics.Instance.RectangleSelectionDictionary[player.CSteamID].Position1 != Vector3.zero && Schematics.Instance.RectangleSelectionDictionary[player.CSteamID].Position2 != Vector3.zero) { Rectangle = true; } } if (!Rectangle) { UnturnedChat.Say(player, "Invalid Syntax, use /SaveSchematic <name> <distance> [Optional Parameters: -Owner (Only gets structures placed by you) -Group (only gets structures placed by your current group), Input any Steamid64 to only get results from it"); //UnturnedChat.Say(player, "Invalid Syntax, use /SaveSchematic <name> <distance> or /select <1,2> [Optional Parameters: -Owner (Only gets structures placed by you) -Group (only gets structures placed by your current group), Input any Steamid64 to only get results from it"); return; } } // This is lazy, probably better way to do it then using Contains. var fullcommand = string.Join(" ", command).ToLower(); ulong SpecificSteamid64 = 0; var GroupOnly = false; if (fullcommand.Contains("-owner")) { SpecificSteamid64 = player.CSteamID.m_SteamID; } if (fullcommand.Contains("-group")) { GroupOnly = true; } var match = Schematics.steamid64Regex.Match(fullcommand); if (match.Success && ulong.TryParse(match.Value, out var result)) { SpecificSteamid64 = result; } var setsteamid64string = SpecificSteamid64 == 0 ? "false" : SpecificSteamid64.ToString(); Logger.Log($"Specific Steamid64: {setsteamid64string}, Group Only: {GroupOnly}"); radius += 92; var name = command[0].Replace(" ", ""); var Barricades = GetBarricadeTransforms(player, radius, SpecificSteamid64, GroupOnly, Rectangle); var Structures = GetStructureTransforms(player, radius, SpecificSteamid64, GroupOnly, Rectangle); //Logger.Log($"We have found Structures: {Structures.Count} and Barricades: {Barricades.Count}"); var river = ServerSavedata.openRiver($"/Rocket/Plugins/Schematics/Saved/{name}.dat", false); river.writeByte(Schematics.PluginVerison); river.writeBoolean(Schematics.Instance.Configuration.Instance.UseDatabase); river.writeUInt32(Provider.time); river.writeSingleVector3(player.Position); river.writeInt32(Barricades.Count); river.writeInt32(Structures.Count); foreach (var bdata in Barricades) { river.writeUInt16(bdata.bdata.barricade.id); river.writeUInt16(bdata.bdata.barricade.health); river.writeBytes(bdata.bdata.barricade.state); river.writeSingleVector3(bdata.bdata.point); river.writeByte(bdata.bdata.angle_x); river.writeByte(bdata.bdata.angle_y); river.writeByte(bdata.bdata.angle_z); river.writeUInt64(bdata.bdata.owner); river.writeUInt64(bdata.bdata.group); } foreach (var sdata in Structures) { river.writeUInt16(sdata.sdata.structure.id); river.writeUInt16(sdata.sdata.structure.health); river.writeSingleVector3(sdata.sdata.point); river.writeByte(sdata.sdata.angle_x); river.writeByte(sdata.sdata.angle_y); river.writeByte(sdata.sdata.angle_z); river.writeUInt64(sdata.sdata.owner); river.writeUInt64(sdata.sdata.group); } river.closeRiver(); if (Schematics.Instance.Configuration.Instance.UseDatabase) { try { var file = new FileInfo(ReadWrite.PATH + ServerSavedata.directory + "/" + Provider.serverID + $"/Rocket/Plugins/Schematics/Saved/{name}.dat"); var fileStream = new FileStream(file.FullName, FileMode.Open, FileAccess.Read); var binaryReader = new BinaryReader(fileStream); Schematics.Instance.SchematicsDatabaseManager.AddSchematic(name, player.CharacterName, Provider.serverName, binaryReader.ReadBytes((int)fileStream.Length), (int)fileStream.Length, Structures.Count + Barricades.Count); binaryReader.Close(); fileStream.Close(); } catch (Exception e) { Logger.Log("Issue uploading file to your database, it has been saved locally instead."); } } SendMessageAndLog(player, $"Done, we have saved Structures: {Structures.Count} and Barricades: {Barricades.Count} to {(Schematics.Instance.Configuration.Instance.UseDatabase ? "Database and Files" : "Files")} called {name}.", $"Saved {Structures.Count + Barricades.Count} elements for {player.CharacterName} to {(Schematics.Instance.Configuration.Instance.UseDatabase ? "Database and Files" : "Files")} called {name}."); }