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;
                }
            }
        }
Пример #2
0
        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");
        }
Пример #3
0
        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}");
        }
        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}.");
        }