@@ -46,7 +46,8 @@ namespace SeamlessClientPlugin.SeamlessTransfer
|
||||
[ProtoMember(9)]
|
||||
public MyObjectBuilder_Toolbar PlayerToolbar;
|
||||
|
||||
public List<Vector3> PlayerBuildSlots;
|
||||
[ProtoMember(10)]
|
||||
public string ServerName;
|
||||
|
||||
public Transfer(ulong ServerID, string IPAdress)
|
||||
{
|
||||
|
@@ -180,7 +180,6 @@ namespace SeamlessClientPlugin
|
||||
|
||||
public static void RunInitilizations()
|
||||
{
|
||||
TryShow("Initilizing Communications!");
|
||||
MyAPIGateway.Multiplayer.RegisterSecureMessageHandler(SeamlessClientNetID, MessageHandler);
|
||||
Initilized = true;
|
||||
}
|
||||
@@ -203,6 +202,8 @@ namespace SeamlessClientPlugin
|
||||
{
|
||||
Transfer TransferMessage = Recieved.GetTransferData();
|
||||
|
||||
|
||||
|
||||
ServerPing.StartServerPing(TransferMessage);
|
||||
}
|
||||
}
|
||||
|
@@ -13,7 +13,7 @@ namespace SeamlessClientPlugin.SeamlessTransfer
|
||||
public class ServerPing
|
||||
{
|
||||
|
||||
private static WorldRequest Request;
|
||||
private static WorldRequest Request { get { return Transfer.WorldRequest; } }
|
||||
private static Transfer Transfer;
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ namespace SeamlessClientPlugin.SeamlessTransfer
|
||||
{
|
||||
// We need to first ping the server to make sure its running and so we can get a connection
|
||||
Transfer = ClientTransfer;
|
||||
Request = Transfer.WorldRequest;
|
||||
|
||||
|
||||
if (Transfer.TargetServerID == 0)
|
||||
@@ -32,38 +31,22 @@ namespace SeamlessClientPlugin.SeamlessTransfer
|
||||
|
||||
|
||||
|
||||
MyGameServerItem E = new MyGameServerItem();
|
||||
E.ConnectionString = Transfer.IPAdress;
|
||||
E.SteamID = Transfer.TargetServerID;
|
||||
E.Name = Transfer.ServerName;
|
||||
|
||||
|
||||
|
||||
SeamlessClient.TryShow("Beginning Redirect to server: " + Transfer.TargetServerID);
|
||||
MyGameService.OnPingServerResponded += PingResponded;
|
||||
MyGameService.OnPingServerFailedToRespond += FailedToRespond;
|
||||
|
||||
MyGameService.PingServer(Transfer.IPAdress);
|
||||
}
|
||||
|
||||
private static void PingResponded(object sender, MyGameServerItem e)
|
||||
{
|
||||
//If server ping was successful we need to begin the switching proccess
|
||||
UnRegisterEvents();
|
||||
|
||||
SeamlessClient.TryShow($"{e.Name} was successfully pinged!");
|
||||
SwitchServers Switcher = new SwitchServers(e, Request.DeserializeWorldData());
|
||||
SwitchServers Switcher = new SwitchServers(E, Request.DeserializeWorldData());
|
||||
Switcher.BeginSwitch();
|
||||
// LoadServer.LoadWorldData(e, Request.DeserializeWorldData());
|
||||
}
|
||||
|
||||
// MyGameService.OnPingServerResponded += PingResponded;
|
||||
//MyGameService.OnPingServerFailedToRespond += FailedToRespond;
|
||||
|
||||
private static void FailedToRespond(object sender, EventArgs e)
|
||||
{
|
||||
// If the target server failed to respond, we need to exit/return to menu
|
||||
UnRegisterEvents();
|
||||
}
|
||||
|
||||
|
||||
private static void UnRegisterEvents()
|
||||
{
|
||||
//Un-register ping events
|
||||
MyGameService.OnPingServerResponded -= PingResponded;
|
||||
MyGameService.OnPingServerFailedToRespond -= FailedToRespond;
|
||||
//MyGameService.PingServer(Transfer.IPAdress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -15,9 +15,11 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VRage;
|
||||
using VRage.Game;
|
||||
using VRage.Game.ModAPI;
|
||||
using VRage.GameServices;
|
||||
using VRage.Steam;
|
||||
using VRage.Utils;
|
||||
using VRageMath;
|
||||
using VRageRender;
|
||||
@@ -69,15 +71,24 @@ namespace SeamlessClientPlugin.SeamlessTransfer
|
||||
MyMultiplayer.Static = Utility.CastToReflected(instance, Patches.ClientType);
|
||||
MyMultiplayer.Static.ExperimentalMode = true;
|
||||
|
||||
// Set the new SyncLayer to the MySession.Static.SyncLayer
|
||||
Patches.MySessionLayer.SetValue(MySession.Static, MyMultiplayer.Static.SyncLayer);
|
||||
|
||||
SeamlessClient.TryShow("Successfully set MyMultiplayer.Static");
|
||||
|
||||
MyHud.Chat.RegisterChat(MyMultiplayer.Static);
|
||||
|
||||
Sync.Clients.SetLocalSteamId(Sync.MyId, false, MyGameService.UserName);
|
||||
Sync.Players.RegisterEvents();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void OnJoinEvent(object sender, VRage.Network.JoinResultMsg e)
|
||||
{
|
||||
ForceClientConnection();
|
||||
@@ -90,8 +101,11 @@ namespace SeamlessClientPlugin.SeamlessTransfer
|
||||
|
||||
private void ForceClientConnection()
|
||||
{
|
||||
// Set the new SyncLayer to the MySession.Static.SyncLayer
|
||||
Patches.MySessionLayer.SetValue(MySession.Static, MyMultiplayer.Static.SyncLayer);
|
||||
|
||||
|
||||
MyHud.Chat.RegisterChat(MyMultiplayer.Static);
|
||||
|
||||
MyMultiplayer.Static.OnSessionReady();
|
||||
|
||||
LoadConnectedClients();
|
||||
LoadOnlinePlayers();
|
||||
@@ -181,7 +195,6 @@ namespace SeamlessClientPlugin.SeamlessTransfer
|
||||
MySession.Static.ElapsedGameTime = new TimeSpan(TargetWorld.Checkpoint.ElapsedGameTime);
|
||||
MySession.Static.Settings.EnableSpectator = false;
|
||||
|
||||
|
||||
MySession.Static.Password = TargetWorld.Checkpoint.Password;
|
||||
MySession.Static.PreviousEnvironmentHostility = TargetWorld.Checkpoint.PreviousEnvironmentHostility;
|
||||
MySession.Static.RequiresDX = TargetWorld.Checkpoint.RequiresDX;
|
||||
@@ -289,7 +302,7 @@ namespace SeamlessClientPlugin.SeamlessTransfer
|
||||
}
|
||||
|
||||
//typeof(MyGuiScreenTerminal).GetMethod("CreateTabs")
|
||||
MyMultiplayer.Static.OnSessionReady();
|
||||
|
||||
MySession.Static.LoadDataComponents();
|
||||
//MyGuiSandbox.LoadData(false);
|
||||
//MyGuiSandbox.AddScreen(MyGuiSandbox.CreateScreen(MyPerGameSettings.GUI.HUDScreen));
|
||||
@@ -299,7 +312,7 @@ namespace SeamlessClientPlugin.SeamlessTransfer
|
||||
SeamlessClient.TryShow("OnlinePlayers: " + MySession.Static.Players.GetOnlinePlayers().Count);
|
||||
SeamlessClient.TryShow("Loading Complete!");
|
||||
|
||||
MyMultiplayer.Static.OnSessionReady();
|
||||
|
||||
//Recreate all controls... Will fix weird gui/paint/crap
|
||||
MyGuiScreenHudSpace.Static.RecreateControls(true);
|
||||
}
|
||||
|
@@ -30,6 +30,7 @@ namespace SeamlessClientPlugin.SeamlessTransfer
|
||||
public static readonly Type VirtualClientsType = Type.GetType("Sandbox.Engine.Multiplayer.MyVirtualClients, Sandbox.Game");
|
||||
public static readonly Type GUIScreenChat = Type.GetType("Sandbox.Game.Gui.MyGuiScreenChat, Sandbox.Game");
|
||||
public static readonly Type MyMultiplayerClientBase = Type.GetType("Sandbox.Engine.Multiplayer.MyMultiplayerClientBase, Sandbox.Game");
|
||||
public static readonly Type MySteamServerDiscovery = Type.GetType("VRage.Steam.MySteamServerDiscovery, Vrage.Steam");
|
||||
|
||||
/* Harmony Patcher */
|
||||
private static Harmony Patcher = new Harmony("SeamlessClientPatcher");
|
||||
@@ -58,6 +59,8 @@ namespace SeamlessClientPlugin.SeamlessTransfer
|
||||
public static MethodInfo LoadMembersFromWorld { get; private set; }
|
||||
public static MethodInfo LoadMultiplayer { get; private set; }
|
||||
|
||||
public static MethodInfo SendPlayerData;
|
||||
|
||||
|
||||
public static event EventHandler<JoinResultMsg> OnJoinEvent;
|
||||
|
||||
@@ -97,9 +100,9 @@ namespace SeamlessClientPlugin.SeamlessTransfer
|
||||
LoadPlayerInternal = GetMethod(typeof(MyPlayerCollection), "LoadPlayerInternal", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
LoadMembersFromWorld = GetMethod(typeof(MySession), "LoadMembersFromWorld", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
LoadMultiplayer = GetMethod(typeof(MySession), "LoadMultiplayer", BindingFlags.Static | BindingFlags.NonPublic);
|
||||
SendPlayerData = GetMethod(ClientType, "SendPlayerData", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
|
||||
|
||||
|
||||
MethodInfo ConnectToServer = GetMethod(typeof(MyGameService), "ConnectToServer", BindingFlags.Static | BindingFlags.Public);
|
||||
|
||||
|
||||
|
||||
@@ -108,6 +111,7 @@ namespace SeamlessClientPlugin.SeamlessTransfer
|
||||
|
||||
Patcher.Patch(OnJoin, postfix: new HarmonyMethod(GetPatchMethod(nameof(OnUserJoined))));
|
||||
Patcher.Patch(LoadingAction, prefix: new HarmonyMethod(GetPatchMethod(nameof(LoadMultiplayerSession))));
|
||||
//Patcher.Patch(ConnectToServer, prefix: new HarmonyMethod(GetPatchMethod(nameof(OnConnectToServer))));
|
||||
}
|
||||
|
||||
private static MethodInfo GetPatchMethod(string v)
|
||||
@@ -222,6 +226,15 @@ namespace SeamlessClientPlugin.SeamlessTransfer
|
||||
}
|
||||
}
|
||||
|
||||
private static bool OnConnectToServer(MyGameServerItem server, Action<JoinResult> onDone)
|
||||
{
|
||||
if (SeamlessClient.IsSwitching)
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user