Add project files.
This commit is contained in:
68
Messages/ClientMessages.cs
Normal file
68
Messages/ClientMessages.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using ProtoBuf;
|
||||
using Sandbox.Game.World;
|
||||
using Sandbox.ModAPI;
|
||||
using SeamlessClientPlugin.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SeamlessClientPlugin.ClientMessages
|
||||
{
|
||||
public enum ClientMessageType
|
||||
{
|
||||
FirstJoin,
|
||||
TransferServer
|
||||
}
|
||||
|
||||
|
||||
[ProtoContract]
|
||||
public class ClientMessage
|
||||
{
|
||||
[ProtoMember(1)]
|
||||
public ClientMessageType MessageType;
|
||||
[ProtoMember(2)]
|
||||
public byte[] MessageData;
|
||||
[ProtoMember(3)]
|
||||
public long IdentityID;
|
||||
[ProtoMember(4)]
|
||||
public ulong SteamID;
|
||||
[ProtoMember(5)]
|
||||
public string PluginVersion = "0";
|
||||
|
||||
|
||||
|
||||
public ClientMessage(ClientMessageType Type)
|
||||
{
|
||||
MessageType = Type;
|
||||
|
||||
if (!MyAPIGateway.Multiplayer.IsServer)
|
||||
{
|
||||
if(MyAPIGateway.Session.LocalHumanPlayer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IdentityID = MySession.Static?.LocalHumanPlayer?.Identity?.IdentityId ?? 0;
|
||||
SteamID = MySession.Static?.LocalHumanPlayer?.Id.SteamId ?? 0;
|
||||
PluginVersion = SeamlessClient.Version;
|
||||
}
|
||||
}
|
||||
|
||||
public ClientMessage() { }
|
||||
|
||||
public void SerializeData<T>(T Data)
|
||||
{
|
||||
MessageData = Utility.Serialize(Data);
|
||||
}
|
||||
|
||||
public T DeserializeData<T>()
|
||||
{
|
||||
if (MessageData == null)
|
||||
return default(T);
|
||||
|
||||
return Utility.Deserialize<T>(MessageData);
|
||||
}
|
||||
}
|
||||
}
|
65
Messages/WorldRequest.cs
Normal file
65
Messages/WorldRequest.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using NLog;
|
||||
using ProtoBuf;
|
||||
using Sandbox.Engine.Multiplayer;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VRage.Game;
|
||||
using VRage.ObjectBuilders;
|
||||
|
||||
namespace SeamlessClientPlugin.ClientMessages
|
||||
{
|
||||
[ProtoContract]
|
||||
public class WorldRequest
|
||||
{
|
||||
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
[ProtoMember(1)]
|
||||
public ulong PlayerID;
|
||||
[ProtoMember(2)]
|
||||
public long IdentityID;
|
||||
[ProtoMember(3)]
|
||||
public string PlayerName;
|
||||
[ProtoMember(4)]
|
||||
public byte[] WorldData;
|
||||
|
||||
public WorldRequest(ulong PlayerID,long PlayerIdentity, string Name)
|
||||
{
|
||||
this.PlayerID = PlayerID;
|
||||
this.PlayerName = Name;
|
||||
this.IdentityID = PlayerIdentity;
|
||||
}
|
||||
|
||||
public WorldRequest() { }
|
||||
|
||||
public void SerializeWorldData(MyObjectBuilder_World WorldData)
|
||||
{
|
||||
MethodInfo CleanupData = typeof(MyMultiplayerServerBase).GetMethod("CleanUpData", BindingFlags.Static | BindingFlags.NonPublic, null, new Type[3]
|
||||
{
|
||||
typeof(MyObjectBuilder_World),
|
||||
typeof(ulong),
|
||||
typeof(long),
|
||||
}, null);
|
||||
object[] Data = new object[] { WorldData, PlayerID, IdentityID };
|
||||
CleanupData.Invoke(null, Data);
|
||||
WorldData = (MyObjectBuilder_World)Data[0];
|
||||
using (MemoryStream memoryStream = new MemoryStream())
|
||||
{
|
||||
MyObjectBuilderSerializer.SerializeXML(memoryStream, WorldData, MyObjectBuilderSerializer.XmlCompression.Gzip);
|
||||
this.WorldData = memoryStream.ToArray();
|
||||
Log.Warn("Successfully Converted World");
|
||||
}
|
||||
}
|
||||
|
||||
public MyObjectBuilder_World DeserializeWorldData()
|
||||
{
|
||||
MyObjectBuilderSerializer.DeserializeGZippedXML<MyObjectBuilder_World>(new MemoryStream(WorldData), out var objectBuilder);
|
||||
return objectBuilder;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user