Changed entity ids from int to ushort, inventory sync bugfixes

This commit is contained in:
Regalis
2015-10-21 18:58:36 +03:00
parent 0233579e37
commit 313d16d886
20 changed files with 155 additions and 78 deletions

View File

@@ -347,7 +347,7 @@ namespace Barotrauma.Networking
}
else if (gameStarted)
{
new NetworkEvent(myCharacter.ID, true);
myCharacter.SendNetworkEvent(true);
}
}
@@ -525,7 +525,7 @@ namespace Barotrauma.Networking
List<Character> crew = new List<Character>();
int count = inc.ReadInt32();
int count = inc.ReadByte();
for (int n = 0; n < count; n++)
{
int id = inc.ReadInt32();
@@ -631,7 +631,7 @@ namespace Barotrauma.Networking
msg.Write((byte)PacketTypes.CharacterInfo);
msg.Write(characterInfo.Name);
msg.Write(characterInfo.Gender == Gender.Male);
msg.Write(characterInfo.HeadSpriteId);
msg.Write((byte)characterInfo.HeadSpriteId);
var jobPreferences = GameMain.NetLobbyScreen.JobPreferences;
int count = Math.Min(jobPreferences.Count, 3);
@@ -647,10 +647,10 @@ namespace Barotrauma.Networking
private Character ReadCharacterData(NetIncomingMessage inc, bool isMyCharacter)
{
string newName = inc.ReadString();
int ID = inc.ReadInt32();
ushort ID = inc.ReadUInt16();
bool isFemale = inc.ReadBoolean();
int headSpriteID = inc.ReadInt32();
int headSpriteID = inc.ReadByte();
Vector2 position = new Vector2(inc.ReadFloat(), inc.ReadFloat());
@@ -719,7 +719,7 @@ namespace Barotrauma.Networking
{
case 0:
msg.Write((byte)PacketTypes.NetworkEvent);
msg.Write((byte)NetworkEventType.UpdateEntity);
msg.Write((byte)NetworkEventType.EntityUpdate);
msg.Write(Rand.Int(MapEntity.mapEntityList.Count));
break;
case 1:

View File

@@ -297,7 +297,7 @@ namespace Barotrauma.Networking
{
if (gameStarted)
{
if (myCharacter != null) new NetworkEvent(myCharacter.ID, true);
if (myCharacter != null) myCharacter.SendNetworkEvent(true);
foreach (Character c in Character.CharacterList)
{
@@ -305,7 +305,7 @@ namespace Barotrauma.Networking
if (c.SimPosition == Vector2.Zero || c.SimPosition.Length() < 100.0f)
{
new NetworkEvent(c.ID, false);
c.SendNetworkEvent(false);
}
}
}
@@ -678,8 +678,6 @@ namespace Barotrauma.Networking
}
else
{
if (server.ConnectionsCount>0)
{
server.SendMessage(message, recipientConnections, NetDeliveryMethod.Unreliable, 0);
@@ -777,7 +775,7 @@ namespace Barotrauma.Networking
//msg.Write(GameMain.NetLobbyScreen.GameDuration.TotalMinutes);
msg.Write((myCharacter == null) ? connectedClients.Count : connectedClients.Count + 1);
msg.Write((myCharacter == null) ? (byte)connectedClients.Count : (byte)(connectedClients.Count + 1));
foreach (Client client in connectedClients)
{
msg.Write(client.ID);
@@ -1036,7 +1034,7 @@ namespace Barotrauma.Networking
{
name = message.ReadString();
gender = message.ReadBoolean() ? Gender.Male : Gender.Female;
headSpriteId = message.ReadInt32();
headSpriteId = message.ReadByte();
}
catch
{
@@ -1072,7 +1070,7 @@ namespace Barotrauma.Networking
message.Write(character.ID);
message.Write(character.Info.Gender == Gender.Female);
message.Write(character.Info.HeadSpriteId);
message.Write((byte)character.Info.HeadSpriteId);
message.Write(character.SimPosition.X);
message.Write(character.SimPosition.Y);

View File

@@ -1,11 +1,12 @@
using System.Collections.Generic;
using Lidgren.Network;
using System;
namespace Barotrauma.Networking
{
enum NetworkEventType
{
UpdateEntity = 0,
EntityUpdate = 0,
KillCharacter = 1,
UpdateComponent = 2,
DropItem = 3,
@@ -13,17 +14,19 @@ namespace Barotrauma.Networking
PickItem = 5,
UpdateProperty = 6,
WallDamage = 7,
SelectCharacter = 8
SelectCharacter = 8,
EntityUpdateLarge = 9
}
class NetworkEvent
{
public static List<NetworkEvent> events = new List<NetworkEvent>();
private static bool[] isImportant = { false, true, false, true, true, true, true, true, true };
private static bool[] overridePrevious = { true, false, true, false, false, false, true, true, true };
private static bool[] isImportant = { false, true, false, true, true, true, true, true, true, false };
private static bool[] overridePrevious = { true, false, true, false, false, false, true, true, true, true };
private int id;
private ushort id;
private NetworkEventType eventType;
@@ -33,7 +36,7 @@ namespace Barotrauma.Networking
//private NetOutgoingMessage message;
public int ID
public ushort ID
{
get { return id; }
}
@@ -53,12 +56,12 @@ namespace Barotrauma.Networking
get { return eventType; }
}
public NetworkEvent(int id, bool isClient)
: this(NetworkEventType.UpdateEntity, id, isClient)
public NetworkEvent(ushort id, bool isClient)
: this(NetworkEventType.EntityUpdate, id, isClient)
{
}
public NetworkEvent(NetworkEventType type, int id, bool isClient, object data = null)
public NetworkEvent(NetworkEventType type, ushort id, bool isClient, object data = null)
{
if (isClient)
{
@@ -109,12 +112,12 @@ namespace Barotrauma.Networking
public static bool ReadData(NetIncomingMessage message)
{
NetworkEventType eventType;
int id;
ushort id;
try
{
eventType = (NetworkEventType)message.ReadByte();
id = message.ReadInt32();
id = message.ReadUInt16();
}
catch
{
@@ -129,16 +132,15 @@ namespace Barotrauma.Networking
return false;
}
//System.Diagnostics.Debug.WriteLine("Networkevent entity: "+e.ToString());
//System.Diagnostics.Debug.WriteLine("new message: " + eventType +" - "+e);
try
{
e.ReadNetworkData(eventType, message);
}
catch
catch (Exception exception)
{
DebugConsole.ThrowError("Received invalid network message");
#if DEBUG
DebugConsole.ThrowError("Received invalid network message", exception);
#endif
return false;
}