public static void Init() { MyAPIGateway.Multiplayer.RegisterSecureMessageHandler(QuantumHangarNexusModID, ReceivePacket); ThisServerID = NexusAPI.GetThisServer().ServerID; Log.Info("QuantumHangar -> Nexus integration has been initilized with serverID " + ThisServerID); if (!NexusAPI.IsRunningNexus()) { return; } Log.Error("Running Nexus!"); RunningNexus = true; NexusAPI.Server ThisServer = NexusAPI.GetAllServers().FirstOrDefault(x => x.ServerID == ThisServerID); if (ThisServer.ServerType >= 1) { RequireTransfer = true; Log.Info("QuantumHangar -> This server is Non-Sectored!"); } }
// RelayLoadIfNecessary relays the load grid command to another server if necessary. // // The conditions are: // - this server runs with the Nexus plugin and connected to a controller // - the spawn position belongs to another server linked with Nexus // // Relaying the command allows the load to run locally on the target server, and running // all the checks and extra work (e.g. digging voxels) that would otherwise not happen, // as the grid would simply be transferred to the other sector after being loaded. // // Returns true if the load grid command was relayed and there is nothing else to do, // false otherwise, meaning the load must happen locally. // // If the target server is offline, it will refuse to load the grid and the player // must try again later when the target server is online. public static bool RelayLoadIfNecessary(Vector3D spawnPos, int ID, bool loadNearPlayer, Chat Chat, ulong SteamID, long IdentityID, Vector3D PlayerPosition) { //Dont contiue if we arent running nexus, or we dont require transfer due to non-Sectored instances if (!RunningNexus || !RequireTransfer) { return(false); } var target = NexusAPI.GetServerIDFromPosition(spawnPos); if (target == ThisServerID) { return(false); } if (!NexusAPI.IsServerOnline(target)) { Chat?.Respond("Sorry, this grid belongs to another server that is currently offline. Please try again later."); return(true); } Chat?.Respond("Sending hangar load command to the corresponding server, please wait..."); NexusHangarMessage msg = new NexusHangarMessage { Type = NexusHangarMessageType.LoadGrid, SteamID = SteamID, LoadGridID = ID, LoadNearPlayer = loadNearPlayer, IdentityID = IdentityID, PlayerPosition = PlayerPosition, ServerID = ThisServerID }; API.SendMessageToServer(target, MyAPIGateway.Utilities.SerializeToBinary <NexusHangarMessage>(msg)); return(true); }