Moved around some files and packets to start preping for modularizing the code
This commit is contained in:
parent
528395d102
commit
1d86b05a62
12 changed files with 179 additions and 101 deletions
|
@ -23,22 +23,24 @@ namespace SRMultiplayer.Networking
|
||||||
Globals.PacketSize[type] += im.LengthBytes;
|
Globals.PacketSize[type] += im.LengthBytes;
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
|
//Player amimations
|
||||||
|
case PacketType.PlayerAnimation: OnPlayerAnimation(new PacketPlayerAnimation(im)); break;
|
||||||
|
|
||||||
//Players
|
//Players
|
||||||
case PacketType.PlayerJoined: OnPlayerJoined(new PacketPlayerJoined(im)); break;
|
case PacketType.PlayerJoined: OnPlayerJoined(new PacketPlayerJoined(im)); break;
|
||||||
case PacketType.PlayerLeft: OnPlayerLeft(new PacketPlayerLeft(im)); break;
|
case PacketType.PlayerLeft: OnPlayerLeft(new PacketPlayerLeft(im)); break;
|
||||||
case PacketType.PlayerLoaded: OnPlayerLoaded(new PacketPlayerLoaded(im)); break;
|
case PacketType.PlayerLoaded: OnPlayerLoaded(new PacketPlayerLoaded(im)); break;
|
||||||
case PacketType.PlayerPosition: OnPlayerPosition(new PacketPlayerPosition(im)); break;
|
case PacketType.PlayerPosition: OnPlayerPosition(new PacketPlayerPosition(im)); break;
|
||||||
case PacketType.PlayerAnimationLayer: OnPlayerAnimationLayer(im); break;
|
|
||||||
case PacketType.PlayerAnimationParameters: OnPlayerAnimationParameters(im); break;
|
|
||||||
case PacketType.PlayerAnimationSpeed: OnPlayerAnimationSpeed(im); break;
|
|
||||||
case PacketType.PlayerFX: OnPlayerFX(new PacketPlayerFX(im)); break;
|
case PacketType.PlayerFX: OnPlayerFX(new PacketPlayerFX(im)); break;
|
||||||
case PacketType.PlayerCurrency: OnPlayerCurrency(new PacketPlayerCurrency(im)); break;
|
case PacketType.PlayerCurrency: OnPlayerCurrency(new PacketPlayerCurrency(im)); break;
|
||||||
case PacketType.PlayerCurrencyDisplay: OnPlayerCurrencyDisplay(new PacketPlayerCurrencyDisplay(im)); break;
|
case PacketType.PlayerCurrencyDisplay: OnPlayerCurrencyDisplay(new PacketPlayerCurrencyDisplay(im)); break;
|
||||||
case PacketType.PlayerUpgrade: OnPlayerUpgrade(new PacketPlayerUpgrade(im)); break;
|
case PacketType.PlayerUpgrade: OnPlayerUpgrade(new PacketPlayerUpgrade(im)); break;
|
||||||
case PacketType.PlayerUpgradeUnlock: OnPlayerUpgradeUnlock(new PacketPlayerUpgradeUnlock(im)); break;
|
case PacketType.PlayerUpgradeUnlock: OnPlayerUpgradeUnlock(new PacketPlayerUpgradeUnlock(im)); break;
|
||||||
case PacketType.PlayerChat: OnPlayerChat(new PacketPlayerChat(im)); break;
|
case PacketType.PlayerChat: OnPlayerChat(new PacketPlayerChat(im)); break;
|
||||||
|
|
||||||
// Region
|
// Region
|
||||||
case PacketType.RegionOwner: OnRegionOwner(new PacketRegionOwner(im)); break;
|
case PacketType.RegionOwner: OnRegionOwner(new PacketRegionOwner(im)); break;
|
||||||
|
|
||||||
//Actors
|
//Actors
|
||||||
case PacketType.Actors: OnActors(new PacketActors(im)); break;
|
case PacketType.Actors: OnActors(new PacketActors(im)); break;
|
||||||
case PacketType.ActorSpawn: OnActorSpawn(new PacketActorSpawn(im)); break;
|
case PacketType.ActorSpawn: OnActorSpawn(new PacketActorSpawn(im)); break;
|
||||||
|
@ -149,10 +151,10 @@ namespace SRMultiplayer.Networking
|
||||||
// Race
|
// Race
|
||||||
case PacketType.RaceActivate: OnRaceActivate(new PacketRaceActivate(im)); break;
|
case PacketType.RaceActivate: OnRaceActivate(new PacketRaceActivate(im)); break;
|
||||||
case PacketType.RaceEnd: OnRaceEnd(new PacketRaceEnd(im)); break;
|
case PacketType.RaceEnd: OnRaceEnd(new PacketRaceEnd(im)); break;
|
||||||
case PacketType.RaceTime: OnRaceTime(new PacketRaceTime(im)); break;
|
case PacketType.RaceTime: OnRaceTime(new PacketRaceTime(im)); break;
|
||||||
case PacketType.RaceTrigger: OnRaceTrigger(new PacketRaceTrigger(im)); break;
|
case PacketType.RaceTrigger: OnRaceTrigger(new PacketRaceTrigger(im)); break;
|
||||||
default:
|
default:
|
||||||
SRMP.Log($"Got unhandled packet: {type}");
|
SRMP.Log($"Got unhandled packet: {type} " + Enum.GetName(typeof(PacketType), type));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1926,30 +1928,21 @@ namespace SRMultiplayer.Networking
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void OnPlayerAnimationSpeed(NetIncomingMessage im)
|
private static void OnPlayerAnimation(PacketPlayerAnimation packet)
|
||||||
{
|
{
|
||||||
byte id = im.ReadByte();
|
//handle character animation triggers
|
||||||
if (Globals.Players.TryGetValue(id, out NetworkPlayer player) && player.HasLoaded)
|
PacketPlayerAnimation.AnimationType type = (PacketPlayerAnimation.AnimationType)packet.Type;
|
||||||
{
|
|
||||||
player.ReadAnimatorSpeed(im);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void OnPlayerAnimationParameters(NetIncomingMessage im)
|
|
||||||
{
|
|
||||||
byte id = im.ReadByte();
|
|
||||||
if (Globals.Players.TryGetValue(id, out NetworkPlayer player) && player.HasLoaded)
|
|
||||||
{
|
|
||||||
player.ReadParameters(im);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void OnPlayerAnimationLayer(NetIncomingMessage im)
|
|
||||||
{
|
if (Globals.Players.TryGetValue(packet.ID, out NetworkPlayer player) && player.HasLoaded)
|
||||||
byte id = im.ReadByte();
|
|
||||||
if (Globals.Players.TryGetValue(id, out NetworkPlayer player) && player.HasLoaded)
|
|
||||||
{
|
{
|
||||||
player.ReadAnimatorLayer(im);
|
if(type == PacketPlayerAnimation.AnimationType.Speed)
|
||||||
|
player.ReadAnimatorSpeed(packet.internalData);
|
||||||
|
else if (type == PacketPlayerAnimation.AnimationType.Parameters)
|
||||||
|
player.ReadParameters(packet.internalData);
|
||||||
|
else
|
||||||
|
player.ReadAnimatorLayer(packet.internalData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1968,7 +1961,9 @@ namespace SRMultiplayer.Networking
|
||||||
SRSingleton<SceneContext>.Instance.player.transform.eulerAngles = new Vector3(0, packet.Rotation, 0);
|
SRSingleton<SceneContext>.Instance.player.transform.eulerAngles = new Vector3(0, packet.Rotation, 0);
|
||||||
SRSingleton<SceneContext>.Instance.PlayerState.model.SetCurrRegionSet((RegionRegistry.RegionSetId)packet.RegionSet);
|
SRSingleton<SceneContext>.Instance.PlayerState.model.SetCurrRegionSet((RegionRegistry.RegionSetId)packet.RegionSet);
|
||||||
|
|
||||||
if (!Globals.IsServer)
|
|
||||||
|
//only reload inventory if this is a load up packet and NOT a tp packet
|
||||||
|
if (!Globals.IsServer && packet.OnLoad)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
|
@ -2,6 +2,7 @@
|
||||||
using Lidgren.Network;
|
using Lidgren.Network;
|
||||||
using MonomiPark.SlimeRancher.DataModel;
|
using MonomiPark.SlimeRancher.DataModel;
|
||||||
using MonomiPark.SlimeRancher.Regions;
|
using MonomiPark.SlimeRancher.Regions;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using SRMultiplayer.Packets;
|
using SRMultiplayer.Packets;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
@ -21,12 +22,11 @@ namespace SRMultiplayer.Networking
|
||||||
Globals.PacketSize[type] += im.LengthBytes;
|
Globals.PacketSize[type] += im.LengthBytes;
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
|
//Player animation
|
||||||
|
case PacketType.PlayerAnimation: OnPlayerAnimation(new PacketPlayerAnimation(im), player); break;
|
||||||
//Player
|
//Player
|
||||||
case PacketType.PlayerLoaded: OnPlayerLoaded(new PacketPlayerLoaded(im), player); break;
|
case PacketType.PlayerLoaded: OnPlayerLoaded(new PacketPlayerLoaded(im), player); break;
|
||||||
case PacketType.PlayerPosition: OnPlayerPosition(new PacketPlayerPosition(im), player); break;
|
case PacketType.PlayerPosition: OnPlayerPosition(new PacketPlayerPosition(im), player); break;
|
||||||
case PacketType.PlayerAnimationLayer: OnPlayerAnimationLayer(im, player); break;
|
|
||||||
case PacketType.PlayerAnimationParameters: OnPlayerAnimationParameters(im, player); break;
|
|
||||||
case PacketType.PlayerAnimationSpeed: OnPlayerAnimationSpeed(im, player); break;
|
|
||||||
case PacketType.PlayerCurrency: OnPlayerCurrency(new PacketPlayerCurrency(im), player); break;
|
case PacketType.PlayerCurrency: OnPlayerCurrency(new PacketPlayerCurrency(im), player); break;
|
||||||
case PacketType.PlayerCurrencyDisplay: OnPlayerCurrencyDisplay(new PacketPlayerCurrencyDisplay(im), player); break;
|
case PacketType.PlayerCurrencyDisplay: OnPlayerCurrencyDisplay(new PacketPlayerCurrencyDisplay(im), player); break;
|
||||||
case PacketType.PlayerUpgrade: OnPlayerUpgrade(new PacketPlayerUpgrade(im), player); break;
|
case PacketType.PlayerUpgrade: OnPlayerUpgrade(new PacketPlayerUpgrade(im), player); break;
|
||||||
|
@ -132,7 +132,7 @@ namespace SRMultiplayer.Networking
|
||||||
case PacketType.RaceTime: OnRaceTime(new PacketRaceTime(im), player); break;
|
case PacketType.RaceTime: OnRaceTime(new PacketRaceTime(im), player); break;
|
||||||
case PacketType.RaceTrigger: OnRaceTrigger(new PacketRaceTrigger(im), player); break;
|
case PacketType.RaceTrigger: OnRaceTrigger(new PacketRaceTrigger(im), player); break;
|
||||||
default:
|
default:
|
||||||
SRMP.Log($"Got unhandled packet from {player}: {type}");
|
SRMP.Log($"Got unhandled packet from {player}: {type}" + Enum.GetName(typeof(PacketType), type));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1639,42 +1639,25 @@ namespace SRMultiplayer.Networking
|
||||||
packet.SendToAllExcept(player);
|
packet.SendToAllExcept(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void OnPlayerAnimationSpeed(NetIncomingMessage im, NetworkPlayer player)
|
private static void OnPlayerAnimation(PacketPlayerAnimation packet, NetworkPlayer player)
|
||||||
{
|
{
|
||||||
if (player.HasLoaded)
|
if (player.HasLoaded)
|
||||||
{
|
{
|
||||||
byte id = im.ReadByte();
|
switch (packet.Type)
|
||||||
player.ReadAnimatorSpeed(im);
|
{
|
||||||
|
case (byte)PacketPlayerAnimation.AnimationType.Speed:
|
||||||
NetOutgoingMessage om = NetworkServer.Instance.CreateMessage();
|
player.ReadAnimatorSpeed(packet.internalData);
|
||||||
om.Write(im);
|
break;
|
||||||
NetworkServer.Instance.SendToAll(om, player);
|
case (byte)PacketPlayerAnimation.AnimationType.Layer:
|
||||||
}
|
player.ReadAnimatorLayer(packet.internalData);
|
||||||
}
|
break;
|
||||||
|
case (byte)PacketPlayerAnimation.AnimationType.Parameters:
|
||||||
private static void OnPlayerAnimationParameters(NetIncomingMessage im, NetworkPlayer player)
|
player.ReadParameters(packet.internalData);
|
||||||
{
|
break;
|
||||||
if (player.HasLoaded)
|
}
|
||||||
{
|
|
||||||
byte id = im.ReadByte();
|
//make the incoming message an out going message
|
||||||
player.ReadParameters(im);
|
packet.SendToAllExcept(player, NetDeliveryMethod.Unreliable);
|
||||||
|
|
||||||
NetOutgoingMessage om = NetworkServer.Instance.CreateMessage();
|
|
||||||
om.Write(im);
|
|
||||||
NetworkServer.Instance.SendToAll(om, player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void OnPlayerAnimationLayer(NetIncomingMessage im, NetworkPlayer player)
|
|
||||||
{
|
|
||||||
if (player.HasLoaded)
|
|
||||||
{
|
|
||||||
byte id = im.ReadByte();
|
|
||||||
player.ReadAnimatorLayer(im);
|
|
||||||
|
|
||||||
NetOutgoingMessage om = NetworkServer.Instance.CreateMessage();
|
|
||||||
om.Write(im);
|
|
||||||
NetworkServer.Instance.SendToAll(om, player);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -340,6 +340,7 @@ namespace SRMultiplayer.Networking
|
||||||
{
|
{
|
||||||
Globals.HandlePacket = true;
|
Globals.HandlePacket = true;
|
||||||
PacketType type = (PacketType)im.ReadUInt16();
|
PacketType type = (PacketType)im.ReadUInt16();
|
||||||
|
|
||||||
var player = Globals.Players.Values.FirstOrDefault(p => p.Connection != null && p.Connection.RemoteUniqueIdentifier == im.SenderConnection.RemoteUniqueIdentifier);
|
var player = Globals.Players.Values.FirstOrDefault(p => p.Connection != null && p.Connection.RemoteUniqueIdentifier == im.SenderConnection.RemoteUniqueIdentifier);
|
||||||
if (player != null)
|
if (player != null)
|
||||||
{
|
{
|
|
@ -62,17 +62,27 @@ namespace SRMultiplayer.Networking
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetOutgoingMessage writer = CreateMessage();
|
//NetOutgoingMessage writer = CreateMessage();
|
||||||
writer.Write((ushort)PacketType.PlayerAnimationLayer);
|
|
||||||
writer.Write(Globals.LocalID);
|
//add the object to the writer but dont send it yet
|
||||||
WriteAnimatorLayer(writer, stateHash, normalizedTime, i, layerWeight[i]);
|
var packet = new PacketPlayerAnimation()
|
||||||
Send(writer);
|
{
|
||||||
|
Type = (byte)PacketPlayerAnimation.AnimationType.Layer,
|
||||||
|
ID = Globals.LocalID,
|
||||||
|
internalData = new NetBuffer()
|
||||||
|
};
|
||||||
|
|
||||||
|
//add extra parameters
|
||||||
|
WriteAnimatorLayer(packet.internalData, stateHash, normalizedTime, i, layerWeight[i]);
|
||||||
|
|
||||||
|
//send the changes
|
||||||
|
//packet.Send();
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckSpeed();
|
CheckSpeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteAnimatorLayer(NetOutgoingMessage writer, int stateHash, float normalizedTime, int layerNumber, float layerWeight)
|
void WriteAnimatorLayer(NetBuffer writer, int stateHash, float normalizedTime, int layerNumber, float layerWeight)
|
||||||
{
|
{
|
||||||
writer.Write(stateHash);
|
writer.Write(stateHash);
|
||||||
writer.Write(normalizedTime);
|
writer.Write(normalizedTime);
|
||||||
|
@ -81,7 +91,7 @@ namespace SRMultiplayer.Networking
|
||||||
WriteParameters(writer);
|
WriteParameters(writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReadAnimatorLayer(NetIncomingMessage im)
|
public void ReadAnimatorLayer(NetBuffer im)
|
||||||
{
|
{
|
||||||
if (m_Animator == null) return;
|
if (m_Animator == null) return;
|
||||||
|
|
||||||
|
@ -106,20 +116,30 @@ namespace SRMultiplayer.Networking
|
||||||
if (Mathf.Abs(previousSpeed - newSpeed) > 0.001f)
|
if (Mathf.Abs(previousSpeed - newSpeed) > 0.001f)
|
||||||
{
|
{
|
||||||
previousSpeed = newSpeed;
|
previousSpeed = newSpeed;
|
||||||
NetOutgoingMessage writer = CreateMessage();
|
//NetOutgoingMessage writer = CreateMessage();
|
||||||
writer.Write((ushort)PacketType.PlayerAnimationSpeed);
|
|
||||||
writer.Write(Globals.LocalID);
|
//add the object to the writer but dont send it yet
|
||||||
WriteAnimatorSpeed(writer, newSpeed);
|
var packet = new PacketPlayerAnimation()
|
||||||
Send(writer);
|
{
|
||||||
|
Type = (byte)PacketPlayerAnimation.AnimationType.Speed,
|
||||||
|
ID = Globals.LocalID,
|
||||||
|
internalData = new NetBuffer()
|
||||||
|
};
|
||||||
|
|
||||||
|
//add extra parameters
|
||||||
|
WriteAnimatorSpeed(packet.internalData, newSpeed);
|
||||||
|
|
||||||
|
//send the speed change
|
||||||
|
//packet.Send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteAnimatorSpeed(NetOutgoingMessage writer, float newSpeed)
|
void WriteAnimatorSpeed(NetBuffer writer, float newSpeed)
|
||||||
{
|
{
|
||||||
writer.Write(newSpeed);
|
writer.Write(newSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReadAnimatorSpeed(NetIncomingMessage im)
|
public void ReadAnimatorSpeed(NetBuffer im)
|
||||||
{
|
{
|
||||||
if (m_Animator == null) return;
|
if (m_Animator == null) return;
|
||||||
|
|
||||||
|
@ -179,13 +199,18 @@ namespace SRMultiplayer.Networking
|
||||||
{
|
{
|
||||||
nextSendTime = now + syncInterval;
|
nextSendTime = now + syncInterval;
|
||||||
|
|
||||||
NetOutgoingMessage writer = CreateMessage();
|
//add the object to the writer but dont send it yet
|
||||||
writer.Write((ushort)PacketType.PlayerAnimationParameters);
|
var packet = new PacketPlayerAnimation()
|
||||||
writer.Write(Globals.LocalID);
|
|
||||||
if (WriteParameters(writer))
|
|
||||||
{
|
{
|
||||||
Send(writer);
|
Type = (byte)PacketPlayerAnimation.AnimationType.Parameters,
|
||||||
}
|
ID = Globals.LocalID,
|
||||||
|
internalData = new NetBuffer()
|
||||||
|
};
|
||||||
|
|
||||||
|
//add extra parameters
|
||||||
|
WriteParameters(packet.internalData);
|
||||||
|
|
||||||
|
//packet.Send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,7 +251,7 @@ namespace SRMultiplayer.Networking
|
||||||
return dirtyBits;
|
return dirtyBits;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WriteParameters(NetOutgoingMessage writer, bool forceAll = false)
|
bool WriteParameters(NetBuffer writer, bool forceAll = false)
|
||||||
{
|
{
|
||||||
ulong dirtyBits = forceAll ? (~0ul) : NextDirtyBits();
|
ulong dirtyBits = forceAll ? (~0ul) : NextDirtyBits();
|
||||||
writer.Write(dirtyBits);
|
writer.Write(dirtyBits);
|
||||||
|
@ -255,7 +280,7 @@ namespace SRMultiplayer.Networking
|
||||||
return dirtyBits != 0;
|
return dirtyBits != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReadParameters(NetIncomingMessage reader)
|
public void ReadParameters(NetBuffer reader)
|
||||||
{
|
{
|
||||||
if (m_Animator == null) return;
|
if (m_Animator == null) return;
|
||||||
|
|
||||||
|
|
|
@ -150,6 +150,11 @@ namespace SRMultiplayer.Networking
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float GetWeaponLocation()
|
||||||
|
{
|
||||||
|
return m_ActualWeaponY;
|
||||||
|
}
|
||||||
|
|
||||||
private void OnAnimatorIK()
|
private void OnAnimatorIK()
|
||||||
{
|
{
|
||||||
if(m_Animator != null && m_LeftHandTarget != null)
|
if(m_Animator != null && m_LeftHandTarget != null)
|
||||||
|
|
35
SRMP/Packets/Actors/PacketPlayerAnimation.cs
Normal file
35
SRMP/Packets/Actors/PacketPlayerAnimation.cs
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
using Lidgren.Network;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SRMultiplayer.Packets
|
||||||
|
{
|
||||||
|
[Packet(PacketType.PlayerAnimation)]
|
||||||
|
public class PacketPlayerAnimation : Packet
|
||||||
|
{
|
||||||
|
public enum AnimationType : int
|
||||||
|
{
|
||||||
|
Layer,
|
||||||
|
Speed,
|
||||||
|
Parameters
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte ID;
|
||||||
|
public byte Type;
|
||||||
|
public NetBuffer internalData;
|
||||||
|
/// <summary>
|
||||||
|
/// mark construction inheritance incase we need it
|
||||||
|
/// </summary>
|
||||||
|
public PacketPlayerAnimation():base() { }
|
||||||
|
/// <summary>
|
||||||
|
/// mark construction inheritance so the deserialization automatically happens for is
|
||||||
|
/// since the base decalres this
|
||||||
|
/// </summary>
|
||||||
|
public PacketPlayerAnimation(NetIncomingMessage im):base(im) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
using Lidgren.Network;
|
using Lidgren.Network;
|
||||||
|
using SRMultiplayer.Networking;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
@ -9,7 +10,15 @@ namespace SRMultiplayer.Packets
|
||||||
public interface IPacket
|
public interface IPacket
|
||||||
{
|
{
|
||||||
PacketType GetPacketType();
|
PacketType GetPacketType();
|
||||||
|
/// <summary>
|
||||||
|
/// Searilizes the given packet item
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="om">Outgoing Message that the packet should be added to</param>
|
||||||
void Serialize(NetOutgoingMessage om);
|
void Serialize(NetOutgoingMessage om);
|
||||||
void Deserialize(NetIncomingMessage im);
|
/// <summary>
|
||||||
|
/// Deserializes the given packet item
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="om">Incoming Message that the packet should be deserialized from</param>
|
||||||
|
void Deserialize(NetIncomingMessage im);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,16 +9,42 @@ namespace SRMultiplayer.Packets
|
||||||
{
|
{
|
||||||
public abstract class Packet : IPacket
|
public abstract class Packet : IPacket
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Parameterless constructor to be used through inheritance
|
||||||
|
/// </summary>
|
||||||
|
public Packet() { }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Incoming message based construtor that deserielizes the item for the message
|
||||||
|
/// </summary>
|
||||||
|
public Packet(NetIncomingMessage im) { Deserialize(im); }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Searilizes the given packet item
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="om">Outgoing Message that the packet should be added to</param>
|
||||||
|
public virtual void Serialize(NetOutgoingMessage om)
|
||||||
|
{
|
||||||
|
om.Write((ushort)GetPacketType());
|
||||||
|
//writes the object type using the gettype name
|
||||||
|
//this allows the object to assume its object packet type
|
||||||
|
//om.Write(this.GetType().AssemblyQualifiedName);
|
||||||
|
//
|
||||||
|
|
||||||
|
om.WriteAllFields(this, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deserializes the given packet item
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="om">Incoming Message that the packet should be deserialized from</param>
|
||||||
public virtual void Deserialize(NetIncomingMessage im)
|
public virtual void Deserialize(NetIncomingMessage im)
|
||||||
{
|
{
|
||||||
im.ReadAllFields(this, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
|
im.ReadAllFields(this, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Serialize(NetOutgoingMessage om)
|
|
||||||
{
|
|
||||||
om.Write((ushort)GetPacketType());
|
|
||||||
om.WriteAllFields(this, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PacketType GetPacketType()
|
public PacketType GetPacketType()
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,9 +7,7 @@
|
||||||
PlayerLeft,
|
PlayerLeft,
|
||||||
PlayerPosition,
|
PlayerPosition,
|
||||||
PlayerLoaded,
|
PlayerLoaded,
|
||||||
PlayerAnimationLayer,
|
PlayerAnimation,
|
||||||
PlayerAnimationSpeed,
|
|
||||||
PlayerAnimationParameters,
|
|
||||||
PlayerFX,
|
PlayerFX,
|
||||||
PlayAudio,
|
PlayAudio,
|
||||||
ActorSpawn,
|
ActorSpawn,
|
||||||
|
|
|
@ -15,7 +15,7 @@ using System.Resources;
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
// Version informationr(
|
// Version informationr(
|
||||||
[assembly: AssemblyVersion("0.0.0.1500")]
|
[assembly: AssemblyVersion("0.0.0.1510")]
|
||||||
[assembly: AssemblyFileVersion("0.0.0.1500")]
|
[assembly: AssemblyFileVersion("0.0.0.1510")]
|
||||||
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]
|
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]
|
||||||
|
|
||||||
|
|
|
@ -242,10 +242,13 @@
|
||||||
<Compile Include="Lidgren.Network\Platform\PlatformWinRT.cs" />
|
<Compile Include="Lidgren.Network\Platform\PlatformWinRT.cs" />
|
||||||
<Compile Include="MainSRML.cs" />
|
<Compile Include="MainSRML.cs" />
|
||||||
<Compile Include="MainStandalone.cs" />
|
<Compile Include="MainStandalone.cs" />
|
||||||
|
<Compile Include="Networking\Communication\NetworkClient.cs" />
|
||||||
|
<Compile Include="Networking\Communication\NetworkHandlerClient.cs" />
|
||||||
|
<Compile Include="Networking\Communication\NetworkHandlerServer.cs" />
|
||||||
|
<Compile Include="Networking\Communication\NetworkServer.cs" />
|
||||||
<Compile Include="Networking\NetworkAccessDoor.cs" />
|
<Compile Include="Networking\NetworkAccessDoor.cs" />
|
||||||
<Compile Include="Networking\NetworkActor.cs" />
|
<Compile Include="Networking\NetworkActor.cs" />
|
||||||
<Compile Include="Networking\NetworkAmmo.cs" />
|
<Compile Include="Networking\NetworkAmmo.cs" />
|
||||||
<Compile Include="Networking\NetworkClient.cs" />
|
|
||||||
<Compile Include="Networking\NetworkClientUI.cs" />
|
<Compile Include="Networking\NetworkClientUI.cs" />
|
||||||
<Compile Include="Networking\NetworkDirectedActorSpawner.cs" />
|
<Compile Include="Networking\NetworkDirectedActorSpawner.cs" />
|
||||||
<Compile Include="Networking\NetworkDrone.cs" />
|
<Compile Include="Networking\NetworkDrone.cs" />
|
||||||
|
@ -254,8 +257,6 @@
|
||||||
<Compile Include="Networking\NetworkFireColumn.cs" />
|
<Compile Include="Networking\NetworkFireColumn.cs" />
|
||||||
<Compile Include="Networking\NetworkGadgetSite.cs" />
|
<Compile Include="Networking\NetworkGadgetSite.cs" />
|
||||||
<Compile Include="Networking\NetworkGordo.cs" />
|
<Compile Include="Networking\NetworkGordo.cs" />
|
||||||
<Compile Include="Networking\NetworkHandlerClient.cs" />
|
|
||||||
<Compile Include="Networking\NetworkHandlerServer.cs" />
|
|
||||||
<Compile Include="Networking\NetworkHostUI.cs" />
|
<Compile Include="Networking\NetworkHostUI.cs" />
|
||||||
<Compile Include="Networking\NetworkKookadobaPatchNode.cs" />
|
<Compile Include="Networking\NetworkKookadobaPatchNode.cs" />
|
||||||
<Compile Include="Networking\NetworkLandplot.cs" />
|
<Compile Include="Networking\NetworkLandplot.cs" />
|
||||||
|
@ -269,11 +270,11 @@
|
||||||
<Compile Include="Networking\NetworkPuzzleSlot.cs" />
|
<Compile Include="Networking\NetworkPuzzleSlot.cs" />
|
||||||
<Compile Include="Networking\NetworkRaceTrigger.cs" />
|
<Compile Include="Networking\NetworkRaceTrigger.cs" />
|
||||||
<Compile Include="Networking\NetworkRegion.cs" />
|
<Compile Include="Networking\NetworkRegion.cs" />
|
||||||
<Compile Include="Networking\NetworkServer.cs" />
|
|
||||||
<Compile Include="Networking\NetworkSpawnResource.cs" />
|
<Compile Include="Networking\NetworkSpawnResource.cs" />
|
||||||
<Compile Include="Networking\NetworkTreasurePod.cs" />
|
<Compile Include="Networking\NetworkTreasurePod.cs" />
|
||||||
<Compile Include="Networking\NetworkWorldStateMasterSwitch.cs" />
|
<Compile Include="Networking\NetworkWorldStateMasterSwitch.cs" />
|
||||||
<Compile Include="Packets\AccessDoors\PacketAccessDoors.cs" />
|
<Compile Include="Packets\AccessDoors\PacketAccessDoors.cs" />
|
||||||
|
<Compile Include="Packets\Actors\PacketPlayerAnimation.cs" />
|
||||||
<Compile Include="Packets\Exchanges\PacketExchangeClear.cs" />
|
<Compile Include="Packets\Exchanges\PacketExchangeClear.cs" />
|
||||||
<Compile Include="Packets\Exchanges\PacketExchangeOffer.cs" />
|
<Compile Include="Packets\Exchanges\PacketExchangeOffer.cs" />
|
||||||
<Compile Include="Packets\Exchanges\PacketExchangeOffers.cs" />
|
<Compile Include="Packets\Exchanges\PacketExchangeOffers.cs" />
|
||||||
|
|
Loading…
Reference in a new issue