Files
LuaCsForBarotraumaEP/Subsurface/Source/Networking/NetEntityEvent/NetEntityEvent.cs
Regalis c314b37029 Some classes for syncing entity state changes. Similar to the NetworkEvents in the old netcode, but the logic is split into separate classes which prevent the server from reading updates for entities that aren't IClientSerializable.
todo: add NetEntityEventManagers to server & client, some logic to prevent sending events that don't need to be sent (e.g. duplicate event state updates)
2016-11-12 20:56:06 +02:00

55 lines
1.2 KiB
C#

using Lidgren.Network;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Barotrauma.Networking
{
abstract class NetEntityEvent
{
public readonly Entity Entity;
public readonly UInt32 ID;
protected NetEntityEvent(INetSerializable entity, UInt32 id)
{
this.ID = id;
this.Entity = entity as Entity;
}
}
class ServerEntityEvent : NetEntityEvent
{
private IServerSerializable serializable;
public ServerEntityEvent(IServerSerializable entity, UInt32 id)
: base(entity, id)
{
serializable = entity;
}
public void Write(NetBuffer msg, Client recipient)
{
serializable.ServerWrite(msg, recipient);
}
}
class ClientEntityEvent : NetEntityEvent
{
private IClientSerializable serializable;
public ClientEntityEvent(IClientSerializable entity, UInt32 id)
: base(entity, id)
{
serializable = entity;
}
public void Write(NetBuffer msg)
{
serializable.ClientWrite(msg);
}
}
}