Inventory syncing, objHeader is passed to the ClientRead/ServerRead methods so they can determine how to read the msg (is it an inventory update, position, input, etc)

This commit is contained in:
Regalis
2016-12-10 16:39:58 +02:00
parent 108dddf082
commit 1f454d593e
21 changed files with 262 additions and 166 deletions
@@ -186,7 +186,7 @@ namespace Barotrauma
}
}
public void ClientRead(Lidgren.Network.NetIncomingMessage message, float sendingTime)
public void ClientRead(ServerNetObject type, Lidgren.Network.NetIncomingMessage message, float sendingTime)
{
if (GameMain.Server != null) return;
+2 -2
View File
@@ -724,7 +724,7 @@ namespace Barotrauma.Networking
}
else
{
entity.ClientRead(inc, sendingTime);
entity.ClientRead(objHeader, inc, sendingTime);
}
inc.ReadPadBits();
@@ -736,7 +736,7 @@ namespace Barotrauma.Networking
ChatMessage.ClientRead(inc);
break;
case ServerNetObject.ENTITY_SPAWN:
Item.Spawner.ClientRead(inc, sendingTime);
Item.Spawner.ClientRead(objHeader, inc, sendingTime);
inc.ReadPadBits();
break;
default:
+1 -1
View File
@@ -638,7 +638,7 @@ namespace Barotrauma.Networking
case ClientNetObject.CHARACTER_INPUT:
if (c.Character != null && !c.Character.IsDead && !c.Character.IsUnconscious)
{
c.Character.ServerRead(inc, c);
c.Character.ServerRead(objHeader, inc, c);
}
break;
case ClientNetObject.ENTITY_STATE:
@@ -11,7 +11,7 @@ namespace Barotrauma.Networking
interface IClientSerializable : INetSerializable
{
void ClientWrite(NetBuffer msg, object[] extraData = null);
void ServerRead(NetIncomingMessage msg, Client c);
void ServerRead(ClientNetObject type, NetIncomingMessage msg, Client c);
}
/// <summary>
@@ -20,6 +20,6 @@ namespace Barotrauma.Networking
interface IServerSerializable : INetSerializable
{
void ServerWrite(NetBuffer msg, Client c, object[] extraData = null);
void ClientRead(NetIncomingMessage msg, float sendingTime);
void ClientRead(ServerNetObject type, NetIncomingMessage msg, float sendingTime);
}
}
@@ -65,7 +65,7 @@ namespace Barotrauma.Networking
break;
}
eventsToSync.Add(events[i]);
eventsToSync.Insert(0, events[i]);
}
if (eventsToSync.Count == 0) return;
@@ -96,7 +96,7 @@ namespace Barotrauma.Networking
var serverEntity = entity as IServerSerializable;
if (serverEntity == null) return;
serverEntity.ClientRead(buffer, sendingTime);
serverEntity.ClientRead(ServerNetObject.ENTITY_STATE, buffer, sendingTime);
}
public void Clear()
@@ -9,6 +9,11 @@ namespace Barotrauma.Networking
{
abstract class NetEntityEvent
{
public enum Type
{
Default, ComponentState, InventoryState
}
public readonly Entity Entity;
public readonly UInt32 ID;
@@ -24,7 +24,7 @@ namespace Barotrauma.Networking
public void CreateEvent(IServerSerializable entity, object[] extraData = null)
{
if (!(entity is Entity))
if (entity == null || !(entity is Entity))
{
DebugConsole.ThrowError("Can't create an entity event for " + entity + "!");
return;
@@ -91,7 +91,7 @@ namespace Barotrauma.Networking
var clientEntity = entity as IClientSerializable;
if (clientEntity == null) return;
clientEntity.ServerRead(buffer, sender);
clientEntity.ServerRead(ClientNetObject.ENTITY_STATE, buffer, sender);
}
public void Read(NetIncomingMessage msg, Client client)