diff --git a/SwitchMe/APIMethods.cs b/SwitchMe/APIMethods.cs new file mode 100644 index 0000000..9840ea9 --- /dev/null +++ b/SwitchMe/APIMethods.cs @@ -0,0 +1,196 @@ +using NLog; +using Sandbox.Game.World; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using VRage.Game.ModAPI; +using Torch.API; + + +namespace SwitchMe { + + public class APIMethods { + public static string API_URL = "http://switchplugin.net/api2/"; + public static ITorchBase Torch { get; } + public static readonly Logger Log = LogManager.GetCurrentClassLogger(); + private readonly SwitchMePlugin Plugin; + public APIMethods(SwitchMePlugin Plugin) { + this.Plugin = Plugin; + } + + + public async Task CheckExistance(string targetIP) { + utils.webdata.Add("TARGETIP", targetIP); + var api_reponse = await utils.SendAPIRequestAsync(Plugin.debug); + return api_reponse["responseCode"] == "0"; + } + + public async Task MarkCompleteAsync(ulong steamid) { + utils.webdata.Add("PROCESSED", steamid.ToString()); + utils.webdata.Add("STEAMID", steamid.ToString()); + utils.webdata.Add("CURRENTIP", Plugin.currentIP()); + utils.webdata.Add("FUNCTION", "MarkCompleteAsync"); + await utils.SendAPIRequestAsync(Plugin.debug); + } + + public async Task GetGateAsync(string steamid) { + utils.webdata.Add("STEAMID", steamid); + utils.webdata.Add("CURRENTIP", Plugin.currentIP()); + utils.webdata.Add("BINDKEY", Plugin.Config.BindingKey); + utils.webdata.Add("FUNCTION", "GetGateAsync"); + var api_response = await utils.SendAPIRequestAsync(Plugin.debug); + return api_response["gate"]; + } + + public async Task CheckConnectionAsync(IPlayer player) { + Log.Warn("Checking inbound conneciton for " + player.SteamId); + utils.webdata.Add("BINDKEY", Plugin.Config.BindingKey); + utils.webdata.Add("CURRENTIP", Plugin.currentIP()); + utils.webdata.Add("STEAMID", player.SteamId.ToString()); + utils.webdata.Add("FUNCTION", "CheckConnectionAsync"); + + var api_response = await utils.SendAPIRequestAsync(Plugin.debug); + return bool.Parse(api_response["connecting"]); + } + + public async Task AddConnectionAsync(ulong SteamUserId,string ip,string targetAlias) { + utils.webdata.Add("BINDKEY", Plugin.Config.BindingKey); + utils.webdata.Add("CURRENTIP", Plugin.currentIP()); + utils.webdata.Add("TARGETIP", ip); + utils.webdata.Add("TARGETALIAS", targetAlias); + utils.webdata.Add("STEAMID", SteamUserId.ToString()); + utils.webdata.Add("FUNCION", "AddConnectionAsync"); + await utils.SendAPIRequestAsync(Plugin.debug); + } + public async Task AddTransferAsync(string steamid, string ip, string filename, string targetpos, string grid_target) { + utils.webdata.Add("STEAMID", steamid); + utils.webdata.Add("TARGETIP", ip); + utils.webdata.Add("FILENAME", steamid + "-" + grid_target); + utils.webdata.Add("BINDKEY", Plugin.Config.BindingKey); + utils.webdata.Add("TARGETPOS", targetpos); + utils.webdata.Add("GRIDNAME", grid_target); + utils.webdata.Add("CURRENTIP", Plugin.currentIP()); + utils.webdata.Add("FUNCTION", "AddTransferAsync"); + await utils.SendAPIRequestAsync(Plugin.debug); + } + + public async Task CheckKeyAsync(string target) { + try { + + utils.webdata.Add("TARGETIP", target); + utils.webdata.Add("BINDKEY", Plugin.Config.BindingKey); + utils.webdata.Add("FUNCTION", "CheckKeyAsync"); + var api_response = await utils.SendAPIRequestAsync(Plugin.debug); + return Plugin.Config.BindingKey == api_response["key"]; + + } + catch (Exception e) { + return false; + } + } + + public async Task CheckSlotsAsync(string targetIP, string NumberOfPlayers) { + utils.webdata.Add("TARGETIP", targetIP); + utils.webdata.Add("FUNCTION", "CheckSlotsAsync"); + utils.webdata.Add("PLAYERCOUNT", NumberOfPlayers); + + var api_response = await utils.SendAPIRequestAsync(Plugin.debug); + return api_response["available"]; + } + + public async Task CheckInboundAsync(string target) { + try { + utils.webdata.Add("TARGETIP", target); + utils.webdata.Add("FUNCTION", "CheckInboundAsync"); + var api_response = await utils.SendAPIRequestAsync(Plugin.debug); + return api_response["allow"] == "Y"; + + } + catch (Exception e) { + Log.Warn("Error: " + e.ToString()); + return false; + } + } + + public async Task CheckStatusAsync(string target) { + try { + utils.webdata.Add("TARGETIP", target); + utils.webdata.Add("FUNCTION", "CheckStatusAsync"); + var api_response = await utils.SendAPIRequestAsync(Plugin.debug); + return bool.Parse(api_response["online"]); + + } + catch { + Log.Warn($"http connection error: Please check you can connect to '{API_URL}'"); + } + return false; + } + + public void AttemptHWIDLink() { + if (!utils.ReservedDicts.Contains("HWIDData")) { + utils.ReservedDicts.Add("HWIDData"); + utils.HWIDData.Add("FUNCTION", "AttemptHWIDLink"); + utils.HWIDData.Add("HWID", utils.GetMachineId()); + utils.HWIDData.Add("CURRENTIP", Plugin.currentIP()); + utils.SendHWIDData(false); + utils.ReservedDicts.Remove("HWIDData"); + } + } + + public async Task RemoveConnectionAsync(ulong player) { + Log.Warn("Removing conneciton flag for " + player); + utils.webdata.Add("BINDKEY", Plugin.Config.BindingKey); + utils.webdata.Add("CURRENTIP", Plugin.currentIP()); + utils.webdata.Add("STEAMID", player.ToString()); + utils.webdata.Add("FUNCTION", "RemoveConnectionAsync"); + await utils.SendAPIRequestAsync(Plugin.debug); + } + + public async Task> LoadOnlineConfig() { + utils.webdata.Add("FUNCTION", "DownloadConfigAsync"); + utils.webdata.Add("CURRENTIP", Plugin.currentIP()); + utils.webdata.Add("HWID", utils.GetMachineId()); + var api_reponse = await utils.SendAPIRequestAsync(Plugin.debug); + return api_reponse; + } + + public async Task> FindWebGridAsync(ulong steamid) { + utils.webdata.Add("STEAMID", steamid.ToString()); + utils.webdata.Add("CURRENTIP", Plugin.currentIP()); + utils.webdata.Add("FUNCTION", "FindWebGridAsync"); + return await utils.SendAPIRequestAsync(Plugin.debug); + } + + public async Task CheckServer(IMyPlayer player, string servername, string target) { + utils.ReservedDicts.Add("CheckServer"); + + if (target.Length < 1) { + Log.Warn("Unknown Server. Please use '!switch list' to see a list of valid servers!"); + utils.NotifyMessage("Unknown Server. Please use '!switch list' to see a list of valid servers!", player.SteamUserId); + return false; + } + + /*if (!await CheckExistance(target)) { + Log.Warn("Cannot communicate with target, please make sure SwitchMe is installed there!"); + utils.NotifyMessage("Cannot communicate with target, please make sure SwitchMe is installed there!", player.SteamUserId); + return false; + }*/ + + if (!await CheckKeyAsync(target)) { + Log.Warn("Unauthorised Switch! Please make sure the servers have the same Bind Key!"); + utils.NotifyMessage("Unauthorised Switch! Please make sure the servers have the same Bind Key!", player.SteamUserId, "Red"); + return false; + } + + /// Slot checking + bool slotsAvailable = bool.Parse(await CheckSlotsAsync(target, "1")); + if (!slotsAvailable && player.PromoteLevel != MyPromoteLevel.Admin) { + utils.NotifyMessage("Not enough slots free to use gate!", player.SteamUserId); + return false; + } + utils.ReservedDicts.Remove("CheckServer"); + return true; + } + + } +} diff --git a/SwitchMe/Commands.cs b/SwitchMe/Commands.cs index 3021986..d60cb85 100644 --- a/SwitchMe/Commands.cs +++ b/SwitchMe/Commands.cs @@ -30,27 +30,13 @@ using Sandbox.Common.ObjectBuilders; using VRage; using VRage.ObjectBuilders; +using Torch; namespace SwitchMe { [Category("switch")] public class Commands : CommandModule { - #pragma warning disable 649 - [ReflectedGetter(Name = "m_clientStates")] - private static Func _clientStates; - - private const string CLIENT_DATA_TYPE_NAME = "VRage.Network.MyClient, VRage"; - [ReflectedGetter(TypeName = CLIENT_DATA_TYPE_NAME, Name = "Replicables")] - private static Func> _replicables; - - [ReflectedMethod(Name = "RemoveForClient", OverrideTypeNames = new[] { null, CLIENT_DATA_TYPE_NAME, null })] - private static Action _removeForClient; - - [ReflectedMethod(Name = "ForceReplicable")] - private static Action _forceReplicable; - #pragma warning restore 649 - public static readonly Logger Log = LogManager.GetCurrentClassLogger(); public SwitchMePlugin Plugin => (SwitchMePlugin) Context.Plugin; @@ -71,6 +57,21 @@ public async Task SwitchLocalAsync() { await voidManager.PlayerTransfer("single", Sandbox.Game.Multiplayer.Sync.MyId); } + + [Command("debug")] + [Permission(MyPromoteLevel.Admin)] + public void debug(bool state) { + Plugin.debug = state; + Context.Respond($"Debug mode set to {Plugin.debug} "); + } + + [Command("update-debug")] + [Permission(MyPromoteLevel.Admin)] + public void Updatedebug(bool state) { + Plugin.update_debug = state; + Context.Respond($"Debug mode set to {Plugin.update_debug} "); + } + [Command("all", "Automatically connects all players to your server of choice within this network. USAGE: !switch all ")] [Permission(MyPromoteLevel.Admin)] public async Task SwitchAllAsync() { @@ -82,6 +83,7 @@ public async Task SwitchAllAsync() { [Command("list", "Displays a list of Valid Server names for the '!switch me ' command. ")] [Permission(MyPromoteLevel.None)] public async Task SwitchListAsync() { + APIMethods API = new APIMethods(Plugin); if (!Plugin.Config.Enabled) { Context.Respond("Switching is not enabled!"); @@ -91,15 +93,13 @@ public async Task SwitchListAsync() { StringBuilder sb = new StringBuilder(); string name; - IEnumerable channelIds = Plugin.Config.Servers; + - foreach (string chId in channelIds) { + foreach (ConfigObjects.Server server in Plugin.Config.Servers) { - name = chId.Split(':')[0]; - string ip = chId.Split(':')[1]; - string port = chId.Split(':')[2]; - string target = ip + ":" + port; - bool paired = await Plugin.CheckKeyAsync(target); + name = server.ServerName; + string target = server.ServerIP + ":" + server.ServerPort.ToString(); + bool paired = await API.CheckKeyAsync(target); if (paired == true) sb.Append("'" + name + "' "); @@ -122,23 +122,14 @@ public void SwitchHelp() { Context.Respond("`!switch gates` Displayes the GPS locations of valid jump gates."); } - [Command("verify", "Verify gate configuration")] - [Permission(MyPromoteLevel.Admin)] - public async void verify() { - - } - + [Command("gates","Get the gps locations of jump gates in this server")] [Permission(MyPromoteLevel.None)] public void GetGates() { + ConfigObjects configObjects = new ConfigObjects(); Context.Respond("Getting GPS locations for active jumpgates..."); - IEnumerable channelIds = Plugin.Config.Gates; - string name = ""; - string location = ""; - foreach (string chId in channelIds) { - name = chId.Split('/')[0]; - location = chId.Split('/')[1]; - Context.Respond($"GPS:{name}:{utils.GetSubstringByString("X:","Y", location)}:{utils.GetSubstringByString("Y:", "Z", location)}:{ utils.GetSubstringByString("Z:", "}", location)}"); + foreach (ConfigObjects.Gate gate in Plugin.Config.Gates) { + Context.Respond($"GPS:{configObjects.ParseConvertXYZObject(gate.GateLocation)}"); } } @@ -150,13 +141,14 @@ public async void Recover() { Context.Respond("Command cannot be ran from console"); return; } + APIMethods API = new APIMethods(Plugin); string externalIP = utils.CreateExternalIP(Plugin.Config); string currentIp = externalIP + ":" + MySandboxGame.ConfigDedicated.ServerPort; VoidManager voidManager = new VoidManager(Plugin); - Tuple data = await voidManager.DownloadGridAsync(currentIp, Context.Player.SteamUserId, Context.Player.GetPosition().ToString()); + Tuple data = await voidManager.DownloadGridAsync(currentIp, Context.Player.SteamUserId, Context.Player.GetPosition().ToString()); if (data == null) { @@ -164,197 +156,18 @@ public async void Recover() { } string targetFile = data.Item1; string filename = data.Item2; - Vector3D newPos = data.Item3; + GateObject gate = data.Item3; MyAPIGateway.Utilities.InvokeOnGameThread(() => { GridImporter gridManager = new GridImporter(Plugin, Context); - if (gridManager.DeserializeGridFromPath(targetFile, Context.Player.DisplayName, newPos)) + if (gridManager.DeserializeGridFromPath(targetFile, Context.Player.DisplayName, gate)) { File.Delete(targetFile); - Plugin.DeleteFromWeb(Context.Player.SteamUserId); } }); - await RemoveConnection(Context.Player.SteamUserId); - var playerEndpoint = new Endpoint(Context.Player.SteamUserId, 0); - var replicationServer = (MyReplicationServer)MyMultiplayer.ReplicationLayer; - var clientDataDict = _clientStates.Invoke(replicationServer); - object clientData; - - try { - clientData = clientDataDict[playerEndpoint]; - } catch { - return; - } - - var clientReplicables = _replicables.Invoke(clientData); - - var replicableList = new List(clientReplicables.Count); - foreach (var pair in clientReplicables) - replicableList.Add(pair.Key); - - foreach (var replicable in replicableList) { - - _removeForClient.Invoke(replicationServer, replicable, clientData, true); - _forceReplicable.Invoke(replicationServer, replicable, playerEndpoint); - } - } - - public async Task RemoveConnection(ulong player) {; - string externalIP = Sandbox.MySandboxExternal.ConfigDedicated.IP; - if (!externalIP.Contains("0.0") - || !externalIP.Contains("127.0") - || !externalIP.Contains("192.168")) { - externalIP = Plugin.Config.LocalIP; - } - - string currentIp = externalIP + ":" + Sandbox.MySandboxGame.ConfigDedicated.ServerPort; - Log.Warn("Removing conneciton flag for " + player); - using (HttpClient client = new HttpClient()) { - List> pairs = new List> - { - new KeyValuePair("BindKey", Plugin.Config.LocalKey), - new KeyValuePair("CurrentIP", currentIp ), - new KeyValuePair("RemoveConnection", player.ToString()) - }; - FormUrlEncodedContent content = new FormUrlEncodedContent(pairs); - await client.PostAsync(Plugin.API_URL, content); - } - } - - /* - [Command("grid", "Transfers the target grid to the target server")] - [Permission(MyPromoteLevel.None)] - public async Task GridAsync(string gridTarget, string serverTarget) { - - if (!Plugin.Config.Enabled) { - Context.Respond("SwitchMe not enabled"); - return; - } - if (Context.Player == null) { - Context.Respond("Console cannot run this command"); - return; - } - if (!Plugin.Config.EnabledTransfers) { - Context.Respond("Grid Transfers are not enabled!"); - return; - } - - int i = 0; - string ip = ""; - string name = ""; - string port = ""; - string existanceCheck = ""; - - IEnumerable channelIds = Plugin.Config.Servers; - foreach (string chId in channelIds) { - - ip = chId.Split(':')[1]; - name = chId.Split(':')[0]; - port = chId.Split(':')[2]; - i++; - } - channelIds = Plugin.Config.Servers.Where(c => c.Split(':')[0].Equals(serverTarget)); - foreach (string chId in channelIds) { - - ip = chId.Split(':')[1]; - name = chId.Split(':')[0]; - port = chId.Split(':')[2]; - } - - string target = ip + ":" + port; - ip += ":" + port; - if (ip == null || name == null || port == null) { - Context.Respond("Invalid Configuration!"); - return; - } - - - string slotinfo = await Plugin.CheckSlotsAsync(target); - existanceCheck = slotinfo.Split(';').Last(); - bool paired = await Plugin.CheckKeyAsync(target); - - if (target.Length < 1) { - Context.Respond("Unknown Server. Please use '!switch list' to see a list of validated servers!"); - return; - } - - if (existanceCheck != "1") { - Context.Respond("Cannot communicate with target, please make sure SwitchMe is installed there!"); - return; - } - - if (!paired) { - Context.Respond("Unauthorised Switch! Please make sure the servers have the same Bind Key!"); - return; - } - - if (!Plugin.CheckStatus(target)) { - Context.Respond("Target server is offline... preventing switch"); - return; - } - - bool InboundCheck = await Plugin.CheckInboundAsync(target); - if (!InboundCheck) { - Context.Respond("The target server does not allow inbound transfers"); - return; - } - - Log.Warn("Checking " + target); - int currentRemotePlayers = int.Parse(slotinfo.Substring(0, slotinfo.IndexOf(":"))); - string max = slotinfo.Substring(slotinfo.IndexOf(':') + 1, slotinfo.IndexOf(';') - slotinfo.IndexOf(':') - 1); - Log.Warn("MAX: " + max); - int maxi = int.Parse(max); - int maxcheck = 1 + currentRemotePlayers; - Context.Respond("Slot Checking..."); - Log.Warn(maxcheck + " Player Count Prediction|Player Count Threshold " + max); - if (maxcheck > maxi && Context.Player.PromoteLevel != MyPromoteLevel.Admin) { - Log.Warn("Not enough slots available."); - Context.Respond("No slots available."); - return; - } - var player = MySession.Static.Players.GetPlayerByName(Context.Player.DisplayName); - if (player != null) { - // If he is online we check if he is currently seated. If he is eject him. - if (player?.Controller.ControlledEntity is MyCockpit controller) { - MyAPIGateway.Utilities.InvokeOnGameThread(() => { - controller.Use(); - }); - } - try { - - string externalIP = utils.CreateExternalIP(Plugin.Config); - string pagesource = ""; - string currentIp = externalIP + ":" + MySandboxGame.ConfigDedicated.ServerPort; - - //Not sure what this does but it does not belong here - using (WebClient client = new WebClient()) { - NameValueCollection postData = new NameValueCollection() - { - {"steamID", Context.Player.SteamUserId + ""}, - {"currentIP", currentIp }, - {"gridCheck", ""} - }; - pagesource = Encoding.UTF8.GetString(client.UploadValues("http://switchplugin.net/gridHandle.php", postData)); - } - - if (pagesource == "0") { - if (!await new VoidManager(Plugin).SendGrid(gridTarget, serverTarget, Context.Player.DisplayName, Context.Player.IdentityId, target)) { - return; - } - Log.Warn("Connected clients to " + serverTarget + " @ " + ip); - } - else { - Log.Fatal(pagesource); - Context.Respond("Cannot transfer! You have a transfer ready to be recieved!"); - return; - } - } - catch (Exception e) { - Log.Fatal(e, e.Message); - Context.Respond("Failure"); - } - } + await API.MarkCompleteAsync(Context.Player.SteamUserId); + await API.RemoveConnectionAsync(Context.Player.SteamUserId); + utils.RefreshPlayer(Context.Player.SteamUserId); } - */ [Command("restore", "Completes the transfer of one grid from one server to another")] [Permission(MyPromoteLevel.None)] @@ -364,68 +177,29 @@ public void Restore() { [Command("reload", "Reload and refresh jumpgates with debug options")] [Permission(MyPromoteLevel.Admin)] - public void reload() { - //Delete all registered gates - int i = 0; - foreach (var zone in Plugin.zones) { - foreach (var entity in MyEntities.GetEntities()) { - if (entity?.DisplayName?.Contains(zone, StringComparison.CurrentCultureIgnoreCase) ?? false) { - i++; - entity.Close(); - } - } - } - IMyPlayer player = Context.Player; - if (player == null) { - Context.Respond($"{i} Jumpgates closed!"); - } - else { - utils.NotifyMessage($"{i} Jumpgates closed!", Context.Player.SteamUserId); - } - - //Rebuild all gates - int gates = 0; - IEnumerable channelIds = Plugin.Config.Gates; - string name = ""; - string location = ""; - foreach (string chId in channelIds) { - name = chId.Split('/')[0]; - location = chId.Split('/')[1]; - location = location.TrimStart('{').TrimEnd('}'); - Vector3D.TryParse(location, out Vector3D gps); - var ob = new MyObjectBuilder_SafeZone(); - ob.PositionAndOrientation = new MyPositionAndOrientation(gps, Vector3.Forward, Vector3.Up); - ob.PersistentFlags = MyPersistentEntityFlags2.InScene; - ob.Shape = MySafeZoneShape.Sphere; - ob.Radius = Plugin.Config.GateSize; - ob.Enabled = true; - ob.DisplayName = $"SM-{gps}"; - ob.AccessTypeGrids = MySafeZoneAccess.Blacklist; - ob.AccessTypeFloatingObjects = MySafeZoneAccess.Blacklist; - ob.AccessTypeFactions = MySafeZoneAccess.Blacklist; - ob.AccessTypePlayers = MySafeZoneAccess.Blacklist; - var zone = MyEntities.CreateFromObjectBuilderAndAdd(ob, true); - gates++; - if (!Plugin.zones.Contains(ob.DisplayName)) { - Plugin.zones.Add(ob.DisplayName); + public async void Reload() { + APIMethods API = new APIMethods(Plugin); + if (Plugin.Config.UseOnlineConfig) { + Context.Respond("Online config mode enabled! Reloading online config"); + var api_response = await API.LoadOnlineConfig(); + if (api_response["responseCode"] == "0") { + WebClient myWebClient = new WebClient(); + myWebClient.DownloadFile($"{Plugin.API_URL + api_response["path"]}", Path.Combine(Plugin.StoragePath, "SwitchMeOnline.cfg")); + Plugin._config = Persistent.Load(Path.Combine(Plugin.StoragePath, "SwitchMeOnline.cfg")); + Plugin.Save(); } } - if (player == null) { - Context.Respond($"{gates} Jumpgates created!"); - } - else { - utils.NotifyMessage($"{gates} Jumpgates created!", Context.Player.SteamUserId); - } + Plugin.CloseGates(); + Plugin.OpenGates(); + Context.Respond("Plugin reloaded!"); } - - /*[Command("link")] - [Permission(MyPromoteLevel.Admin)] - public void Link(string target) { - Vector3D Linkpos = Context.Player.GetPosition(); - Plugin.Config.Gates.Add(txtServerName.Text + ":" + txtServerIP.Text + ":" + txtServerPort.Text); + [Command("password", "retrieve pre-generated password for use on the online configuration panel")] + [Permission(MyPromoteLevel.Owner)] + public void Password() { + Context.Respond($"Your online config password is: {utils.GetMachineId()}"); + Log.Info($"Config panel password: {utils.GetMachineId()}"); } - */ } } diff --git a/SwitchMe/GridImporter.cs b/SwitchMe/GridImporter.cs index 2ec0ee2..f3eb034 100644 --- a/SwitchMe/GridImporter.cs +++ b/SwitchMe/GridImporter.cs @@ -33,7 +33,7 @@ public GridImporter(SwitchMePlugin Plugin, CommandContext Context) { this.Context = Context; } - public bool DeserializeGridFromPath(string targetFile, string playername, Vector3D newpos) { + public bool DeserializeGridFromPath(string targetFile, string playername, GateObject gate) { var player = utils.GetPlayerByNameOrId(playername); if (MyObjectBuilderSerializer.DeserializeXML(targetFile, out MyObjectBuilder_Definitions myObjectBuilder_Definitions)) { @@ -52,14 +52,14 @@ public bool DeserializeGridFromPath(string targetFile, string playername, Vector var grids = prefab.CubeGrids; /* Where do we want to paste the grids? Lets find out. */ - var pos = FindPastePosition(grids, newpos, player.DisplayName); + var pos = FindPastePosition(grids, gate, player.DisplayName); if (pos == null) { utils.NotifyMessage("No free place.", player.SteamUserId); return false; } /* Update GridsPosition if that doesnt work get out of here. */ - if (!UpdateGridsPosition(grids, newpos, player.DisplayName)) { + if (!UpdateGridsPosition(grids, gate.position, player.DisplayName)) { Log.Error("Failed to update grid position"); return false; } @@ -227,8 +227,8 @@ private void FixOwnerAndAuthorShip(MyCubeGrid myCubeGrid, string playername) { MyMultiplayer.RaiseEvent(myCubeGrid, x => new Action(x.TransferBlocksBuiltByID), author, player.IdentityId, new EndpointId()); } - private Vector3D? FindPastePosition(MyObjectBuilder_CubeGrid[] grids, Vector3D pos, string playername) { - var player = utils.GetPlayerByNameOrId(playername); + private Vector3D? FindPastePosition(MyObjectBuilder_CubeGrid[] grids, GateObject gate, string playername) { + //var player = utils.GetPlayerByNameOrId(playername); Vector3? vector = null; float radius = 0F; @@ -269,7 +269,7 @@ private void FixOwnerAndAuthorShip(MyCubeGrid myCubeGrid, string playername) { * used to determine the perfect place to paste the grids to. */ - return MyEntities.FindFreePlace(player.GetPosition(), radius); + return MyEntities.FindFreePlaceCustom(gate.position, radius, default, default, default, default, MyEntities.GetEntityById(gate.entityId)); } public bool UpdateGridsPosition(MyObjectBuilder_CubeGrid[] grids, Vector3D newPosition, string playername) { diff --git a/SwitchMe/SwitchMe.csproj b/SwitchMe/SwitchMe.csproj index b5cc7e3..efb4389 100644 --- a/SwitchMe/SwitchMe.csproj +++ b/SwitchMe/SwitchMe.csproj @@ -60,36 +60,40 @@ ..\GameBinaries\Sandbox.Graphics.dll False + + ..\..\..\..\Torch\DedicatedServer64\Sandbox.RenderDirect.dll + - ..\..\Torch\DedicatedServer64\SpaceEngineers.Game.dll + C:\Users\PC\Desktop\Torch\DedicatedServer64\SpaceEngineers.Game.dll False - ..\..\Torch\DedicatedServer64\SpaceEngineers.ObjectBuilders.dll + ..\..\..\..\Torch\DedicatedServer64\SpaceEngineers.ObjectBuilders.dll - ..\packages\System.Buffers.4.5.0\lib\netstandard2.0\System.Buffers.dll + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + - ..\packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll + ..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll - ..\packages\System.Runtime.CompilerServices.Unsafe.4.7.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll + ..\packages\System.Runtime.CompilerServices.Unsafe.4.7.1\lib\net461\System.Runtime.CompilerServices.Unsafe.dll - ..\packages\System.Text.Encodings.Web.4.7.0\lib\netstandard2.0\System.Text.Encodings.Web.dll + ..\packages\System.Text.Encodings.Web.4.7.1\lib\net461\System.Text.Encodings.Web.dll - - ..\packages\System.Text.Json.4.7.1\lib\net461\System.Text.Json.dll + + ..\packages\System.Text.Json.4.7.2\lib\net461\System.Text.Json.dll - - ..\packages\System.Threading.Tasks.Extensions.4.5.2\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll + + ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll ..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll @@ -152,6 +156,8 @@ + + diff --git a/SwitchMe/SwitchMeConfig.cs b/SwitchMe/SwitchMeConfig.cs index 39a56a2..c2bf8f2 100644 --- a/SwitchMe/SwitchMeConfig.cs +++ b/SwitchMe/SwitchMeConfig.cs @@ -1,4 +1,5 @@ -using System.Collections.ObjectModel; +using System.Collections.Generic; +using System.Collections.ObjectModel; using Torch; namespace SwitchMe { @@ -7,6 +8,9 @@ public class SwitchMeConfig : ViewModel { private bool _enabled = false; public bool Enabled { get => _enabled; set => SetValue(ref _enabled, value); } + private bool _useOnlineConfig = false; + public bool UseOnlineConfig { get => _useOnlineConfig; set => SetValue(ref _useOnlineConfig, value); } + private bool _debug = false; public bool Debug { get => _debug; set => SetValue(ref _debug, value); } @@ -25,15 +29,6 @@ public class SwitchMeConfig : ViewModel { private bool _inboundTransfersState = false; public bool InboundTransfersState { get => _inboundTransfersState; set => SetValue(ref _inboundTransfersState, value); } - private string _Xcord = ""; - public string XCord { get => _Xcord; set => SetValue(ref _Xcord, value); } - - private string _ycord = ""; - public string YCord { get => _ycord; set => SetValue(ref _ycord, value); } - - private string _zcord = ""; - public string ZCord { get => _zcord; set => SetValue(ref _zcord, value); } - private string _localIP = ""; public string LocalIP { get => _localIP; set => SetValue(ref _localIP, value); } @@ -42,8 +37,8 @@ public class SwitchMeConfig : ViewModel { public string ActivationKey { get => _ActivationKey; set => SetValue(ref _ActivationKey, value); } */ - private string _localKey = ""; - public string LocalKey { get => _localKey; set => SetValue(ref _localKey, value); } + private string _BindingKey = ""; + public string BindingKey { get => _BindingKey; set => SetValue(ref _BindingKey, value); } /* private bool _econEnabled = false; @@ -77,11 +72,11 @@ public class SwitchMeConfig : ViewModel { private int _confirmationInSeconds = 30; //30 Seconds public int CooldownInSeconds { get => _cooldownInSeconds; set => SetValue(ref _cooldownInSeconds, value); } - private ObservableCollection _switchServers = new ObservableCollection(); - public ObservableCollection Servers { get => _switchServers; set => SetValue(ref _switchServers, value); } + private List _gates = new List(); + public List Gates { get => _gates; set => SetValue(ref _gates, value); } - private ObservableCollection _switchGates = new ObservableCollection(); - public ObservableCollection Gates { get => _switchGates; set => SetValue(ref _switchGates, value); } + private List _servers = new List(); + public List Servers { get => _servers; set => SetValue(ref _servers, value); } } } diff --git a/SwitchMe/SwitchMeControl.xaml b/SwitchMe/SwitchMeControl.xaml index 3b4fc5f..740d662 100644 --- a/SwitchMe/SwitchMeControl.xaml +++ b/SwitchMe/SwitchMeControl.xaml @@ -3,192 +3,149 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - mc:Ignorable="d" Height="1299.924"> - -