Removed cheap timer hack

This commit is contained in:
Bob Da Ross
2021-09-13 23:00:18 -05:00
parent 5d89324b92
commit 5d281c9fb2
4 changed files with 46 additions and 40 deletions

View File

@@ -18,6 +18,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Forms;
using VRage.Game.ModAPI;
using VRage.Input;
using VRage.Plugins;
using VRage.Utils;
@@ -124,51 +125,31 @@ namespace SeamlessClientPlugin
{
Patches.GetPatches();
TryShow("Running Seamless Client Plugin v[" + Version + "]");
PingTimer.Elapsed += PingTimer_Elapsed;
PingTimer.Start();
// PingTimer.Elapsed += PingTimer_Elapsed;
// PingTimer.Start();
}
public void Update()
{
if (MyAPIGateway.Multiplayer == null)
return;
if (!Initilized)
{
TryShow("Initilizing Communications!");
RunInitilizations();
}
//OnNewPlayerRequest
//throw new NotImplementedException();
}
private void PingTimer_Elapsed(object sender, ElapsedEventArgs e)
{
// Terrible way to make sure server knows we are running seamless client
try
{
ClientMessage PingServer = new ClientMessage(ClientMessageType.FirstJoin);
MyAPIGateway.Multiplayer?.SendMessageToServer(SeamlessClientNetID, Utilities.Utility.Serialize(PingServer));
}
catch (Exception ex)
{
//TryShow(ex.ToString());
}
}
public static void RunInitilizations()
{
MyAPIGateway.Multiplayer.RegisterSecureMessageHandler(SeamlessClientNetID, MessageHandler);
@@ -189,12 +170,17 @@ namespace SeamlessClientPlugin
try
{
ClientMessage Recieved = Utilities.Utility.Deserialize<ClientMessage>(obj2);
if (Recieved.MessageType == ClientMessageType.TransferServer)
if(Recieved.MessageType == ClientMessageType.FirstJoin)
{
//Server sent a first join message! Send a reply back so the server knows what version we are on
ClientMessage PingServer = new ClientMessage(ClientMessageType.FirstJoin);
MyAPIGateway.Multiplayer?.SendMessageToServer(SeamlessClientNetID, Utilities.Utility.Serialize(PingServer));
}
else if (Recieved.MessageType == ClientMessageType.TransferServer)
{
//Server sent a transfer message! Begin transfer via seamless
Transfer TransferMessage = Recieved.GetTransferData();
ServerPing.StartServerPing(TransferMessage);
}
}
@@ -213,6 +199,8 @@ namespace SeamlessClientPlugin
MyLog.Default?.WriteLineAndConsole($"SeamlessClient: {message}");
}
public void Dispose()
{
DisposeInitilizations();

View File

@@ -42,11 +42,6 @@ namespace SeamlessClientPlugin.SeamlessTransfer
SwitchServers Switcher = new SwitchServers(E, Request.DeserializeWorldData());
Switcher.BeginSwitch();
// MyGameService.OnPingServerResponded += PingResponded;
//MyGameService.OnPingServerFailedToRespond += FailedToRespond;
//MyGameService.PingServer(Transfer.IPAdress);
}
}
}

View File

@@ -123,9 +123,10 @@ namespace SeamlessClientPlugin.SeamlessTransfer
RemoveOldEntities();
UpdateWorldGenerator();
StartEntitySync();
MyModAPIHelper.Initialize();
// Allow the game to start proccessing incoming messages in the buffer
MyMultiplayer.Static.StartProcessingClientMessages();

View File

@@ -9,6 +9,8 @@ using Sandbox.Game.World;
using Sandbox.Game.World.Generator;
using Sandbox.Graphics;
using Sandbox.Graphics.GUI;
using Sandbox.ModAPI;
using SeamlessClientPlugin.ClientMessages;
using System;
using System.Collections.Generic;
using System.IO;
@@ -115,23 +117,31 @@ namespace SeamlessClientPlugin.SeamlessTransfer
MethodInfo ConnectToServer = GetMethod(typeof(MyGameService), "ConnectToServer", BindingFlags.Static | BindingFlags.Public);
//MethodInfo ConnectToServer = GetMethod(typeof(MyGameService), "ConnectToServer", BindingFlags.Static | BindingFlags.Public);
MethodInfo LoadingScreenDraw = GetMethod(typeof(MyGuiScreenLoading), "DrawInternal", BindingFlags.Instance | BindingFlags.NonPublic);
Patcher.Patch(LoadingScreenDraw, prefix: new HarmonyMethod(GetPatchMethod(nameof(DrawInternal))));
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)
{
return typeof(Patches).GetMethod(v, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
}
#region LoadingScreen
/* Loading Screen Stuff */
@@ -142,6 +152,9 @@ namespace SeamlessClientPlugin.SeamlessTransfer
private static bool LoadMultiplayerSession(MyObjectBuilder_World world, MyMultiplayerBase multiplayerSession)
{
if (SeamlessClient.IsSwitching)
return true;
MyLog.Default.WriteLine("LoadSession() - Start");
if (!MyWorkshop.CheckLocalModsAllowed(world.Checkpoint.Mods, allowLocalMods: false))
@@ -150,6 +163,8 @@ namespace SeamlessClientPlugin.SeamlessTransfer
MyLog.Default.WriteLine("LoadSession() - End");
return false;
}
MyWorkshop.DownloadModsAsync(world.Checkpoint.Mods, delegate (bool success)
{
if (success)
@@ -302,6 +317,9 @@ namespace SeamlessClientPlugin.SeamlessTransfer
}
}
private static bool OnConnectToServer(MyGameServerItem server, Action<JoinResult> onDone)
{
if (SeamlessClient.IsSwitching)
@@ -315,6 +333,10 @@ namespace SeamlessClientPlugin.SeamlessTransfer
/* Patch Utils */
private static MethodInfo GetMethod(Type type, string MethodName, BindingFlags Flags)
{
try