- DockingPort syncing fix: server waits until the port is locked before sending hull/gap IDs, clients can't lock the port until the server tells them to

- fixed crew commands being disabled in single player instead of multiplayer
- server-side ID error logging fix
This commit is contained in:
Regalis
2017-04-09 20:51:57 +03:00
parent 0301457a8f
commit 887735ff32
4 changed files with 58 additions and 41 deletions
+1 -1
View File
@@ -158,7 +158,7 @@ namespace Barotrauma
guiFrame.Update(deltaTime); guiFrame.Update(deltaTime);
//TODO: implement AI commands in multiplayer? //TODO: implement AI commands in multiplayer?
if (GameMain.NetworkMember != null && if (GameMain.NetworkMember == null &&
GameMain.Config.KeyBind(InputType.CrewOrders).IsHit()) GameMain.Config.KeyBind(InputType.CrewOrders).IsHit())
{ {
//deselect construction unless it's the ladders the character is climbing //deselect construction unless it's the ladders the character is climbing
@@ -236,8 +236,10 @@ namespace Barotrauma.Items.Components
} }
} }
public void Lock() public void Lock(bool isNetworkMessage)
{ {
if (GameMain.Client != null && !isNetworkMessage) return;
if (dockingTarget==null) if (dockingTarget==null)
{ {
DebugConsole.ThrowError("Error - attempted to lock a docking port that's not connected to anything"); DebugConsole.ThrowError("Error - attempted to lock a docking port that's not connected to anything");
@@ -245,7 +247,7 @@ namespace Barotrauma.Items.Components
} }
else if (joint is WeldJoint) else if (joint is WeldJoint)
{ {
DebugConsole.ThrowError("Error - attempted to lock a docking port that's already locked"); //DebugConsole.ThrowError("Error - attempted to lock a docking port that's already locked");
return; return;
} }
@@ -260,11 +262,14 @@ namespace Barotrauma.Items.Components
CreateJoint(true); CreateJoint(true);
if (GameMain.Server != null)
{
item.CreateServerEvent(this);
}
if (!item.linkedTo.Any(e => e is Hull) && !dockingTarget.item.linkedTo.Any(e => e is Hull)) if (!item.linkedTo.Any(e => e is Hull) && !dockingTarget.item.linkedTo.Any(e => e is Hull))
{ {
CreateHull(); CreateHull();
//item.NewComponentEvent(this, false, true);
} }
} }
@@ -601,7 +606,7 @@ namespace Barotrauma.Items.Components
if (Vector2.Distance(joint.WorldAnchorA, joint.WorldAnchorB) < 0.05f) if (Vector2.Distance(joint.WorldAnchorA, joint.WorldAnchorB) < 0.05f)
{ {
Lock(); Lock(false);
} }
} }
else else
@@ -656,18 +661,17 @@ namespace Barotrauma.Items.Components
if (dockingDir == 1) if (dockingDir == 1)
{ {
spriteBatch.Draw(overlaySprite.Texture, spriteBatch.Draw(overlaySprite.Texture,
drawPos, drawPos - Vector2.UnitY * (rect.Height / 2 * dockingState),
new Rectangle( new Rectangle(
rect.X, rect.Y + rect.Height/2 + (int)(rect.Height / 2 * (1.0f - dockingState)), rect.X, rect.Y,
rect.Width, (int)(rect.Height / 2 * dockingState)), Color.White); rect.Width, (int)(rect.Height / 2 * dockingState)), Color.White);
} }
else else
{ {
spriteBatch.Draw(overlaySprite.Texture, spriteBatch.Draw(overlaySprite.Texture,
drawPos - Vector2.UnitY * (rect.Height / 2 * dockingState), drawPos,
new Rectangle( new Rectangle(
rect.X, rect.Y, rect.X, rect.Y + rect.Height / 2 + (int)(rect.Height / 2 * (1.0f - dockingState)),
rect.Width, (int)(rect.Height / 2 * dockingState)), Color.White); rect.Width, (int)(rect.Height / 2 * dockingState)), Color.White);
} }
} }
@@ -750,9 +754,17 @@ namespace Barotrauma.Items.Components
{ {
msg.Write(dockingTarget.item.ID); msg.Write(dockingTarget.item.ID);
msg.Write((ushort)hullIds[0]); if (hullIds[0] != null && hullIds[1] != null && gapId != null)
msg.Write((ushort)hullIds[1]); {
msg.Write((ushort)gapId); msg.Write(true);
msg.Write((ushort)hullIds[0]);
msg.Write((ushort)hullIds[1]);
msg.Write((ushort)gapId);
}
else
{
msg.Write(false);
}
} }
} }
@@ -762,11 +774,16 @@ namespace Barotrauma.Items.Components
if (isDocked) if (isDocked)
{ {
ushort dockingTargetID = msg.ReadUInt16(); ushort dockingTargetID = msg.ReadUInt16();
hullIds[0] = msg.ReadUInt16(); bool isLocked = msg.ReadBoolean();
hullIds[1] = msg.ReadUInt16();
gapId = msg.ReadUInt16(); if (isLocked)
{
hullIds[0] = msg.ReadUInt16();
hullIds[1] = msg.ReadUInt16();
gapId = msg.ReadUInt16();
}
Entity targetEntity = Entity.FindEntityByID(dockingTargetID); Entity targetEntity = Entity.FindEntityByID(dockingTargetID);
if (targetEntity == null || !(targetEntity is Item)) if (targetEntity == null || !(targetEntity is Item))
@@ -782,16 +799,16 @@ namespace Barotrauma.Items.Components
return; return;
} }
if (hulls != null)
{
if (hulls[0] != null) hulls[0].ID = (ushort)hullIds[0];
if (hulls[1] != null) hulls[1].ID = (ushort)hullIds[1];
}
if (gap != null) gap.ID = (ushort)gapId;
Dock(dockingTarget); Dock(dockingTarget);
if (isLocked)
{
Lock(true);
hulls[0].ID = (ushort)hullIds[0];
hulls[1].ID = (ushort)hullIds[1];
gap.ID = (ushort)gapId;
}
} }
else else
{ {
+1 -1
View File
@@ -454,7 +454,7 @@ namespace Barotrauma
myPort.Dock(linkedPort); myPort.Dock(linkedPort);
myPort.Lock(); myPort.Lock(true);
} }
sub.SetPosition(sub.WorldPosition - Submarine.WorldPosition); sub.SetPosition(sub.WorldPosition - Submarine.WorldPosition);
+2 -2
View File
@@ -703,10 +703,10 @@ namespace Barotrauma.Networking
#if DEBUG #if DEBUG
//client thinks they've received a msg we haven't sent yet (corrupted packet, msg read/written incorrectly?) //client thinks they've received a msg we haven't sent yet (corrupted packet, msg read/written incorrectly?)
if (NetIdUtils.IdMoreRecent(lastRecvChatMsgID, c.lastChatMsgQueueID)) if (NetIdUtils.IdMoreRecent(lastRecvChatMsgID, c.lastChatMsgQueueID))
DebugConsole.ThrowError("client.lastRecvChatMsgID > lastChatMsgQueueID (" + c.lastRecvChatMsgID + " > " + c.lastChatMsgQueueID + ")"); DebugConsole.ThrowError("client.lastRecvChatMsgID > lastChatMsgQueueID (" + lastRecvChatMsgID + " > " + c.lastChatMsgQueueID + ")");
if (lastRecvEntityEventID > lastEntityEventID) if (lastRecvEntityEventID > lastEntityEventID)
DebugConsole.ThrowError("client.lastRecvEntityEventID > lastEntityEventID (" + c.lastRecvEntityEventID + " > " + lastEntityEventID + ")"); DebugConsole.ThrowError("client.lastRecvEntityEventID > lastEntityEventID (" + lastRecvEntityEventID + " > " + lastEntityEventID + ")");
#endif #endif
if (NetIdUtils.IdMoreRecent(lastRecvChatMsgID, c.lastRecvChatMsgID)) c.lastRecvChatMsgID = lastRecvChatMsgID; if (NetIdUtils.IdMoreRecent(lastRecvChatMsgID, c.lastRecvChatMsgID)) c.lastRecvChatMsgID = lastRecvChatMsgID;