- clients don't spawn character jobitems themselves (item data is written in the StartGame network message)
- after receiving a StartGame message, clients will wait until the game is loaded before reading new messages from the server - the Item(prefab, position, submarine) constructor uses the position as the center of the item, not as top-left corner
This commit is contained in:
@@ -456,6 +456,8 @@ namespace Barotrauma.Networking
|
||||
updateTimer = DateTime.Now + updateInterval;
|
||||
}
|
||||
|
||||
private CoroutineHandle startGameCoroutine;
|
||||
|
||||
/// <summary>
|
||||
/// Check for new incoming messages from server
|
||||
/// </summary>
|
||||
@@ -463,6 +465,8 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
// Create new incoming message holder
|
||||
NetIncomingMessage inc;
|
||||
|
||||
if (startGameCoroutine != null && CoroutineManager.IsCoroutineRunning(startGameCoroutine)) return;
|
||||
|
||||
while ((inc = client.ReadMessage()) != null)
|
||||
{
|
||||
@@ -492,7 +496,7 @@ namespace Barotrauma.Networking
|
||||
case (byte)PacketTypes.StartGame:
|
||||
if (Screen.Selected == GameMain.GameScreen) continue;
|
||||
|
||||
GameMain.ShowLoading(StartGame(inc), false);
|
||||
startGameCoroutine = GameMain.ShowLoading(StartGame(inc), false);
|
||||
|
||||
break;
|
||||
case (byte)PacketTypes.EndGame:
|
||||
@@ -615,7 +619,9 @@ namespace Barotrauma.Networking
|
||||
case (byte)PacketTypes.RemoveItem:
|
||||
Item.Remover.ReadNetworkData(inc);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (packetType == (byte)PacketTypes.StartGame) break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -650,7 +656,6 @@ namespace Barotrauma.Networking
|
||||
yield return CoroutineStatus.Success;
|
||||
}
|
||||
|
||||
yield return CoroutineStatus.Running;
|
||||
|
||||
Rand.SetSyncedSeed(seed);
|
||||
//int gameModeIndex = inc.ReadInt32();
|
||||
@@ -660,7 +665,6 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (respawnAllowed) respawnManager = new RespawnManager(this);
|
||||
|
||||
yield return CoroutineStatus.Running;
|
||||
|
||||
//myCharacter = ReadCharacterData(inc);
|
||||
//Character.Controlled = myCharacter;
|
||||
@@ -699,7 +703,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
Character newCharacter = ReadCharacterData(inc, ownerId == myID);
|
||||
|
||||
if (id != myID)
|
||||
if (ownerId != myID)
|
||||
{
|
||||
var characterOwner = otherClients.Find(c => c.ID == ownerId);
|
||||
if (characterOwner != null) characterOwner.Character = newCharacter;
|
||||
@@ -707,7 +711,6 @@ namespace Barotrauma.Networking
|
||||
|
||||
crew.Add(newCharacter);
|
||||
}
|
||||
|
||||
//int count = inc.ReadByte();
|
||||
//for (int n = 0; n < count; n++)
|
||||
//{
|
||||
@@ -725,7 +728,8 @@ namespace Barotrauma.Networking
|
||||
// yield return CoroutineStatus.Running;
|
||||
//}
|
||||
}
|
||||
gameStarted = true;
|
||||
|
||||
gameStarted = true;
|
||||
|
||||
endRoundButton.Visible = Voting.AllowEndVoting && myCharacter != null;
|
||||
|
||||
@@ -1061,12 +1065,7 @@ namespace Barotrauma.Networking
|
||||
string jobName = inc.ReadString();
|
||||
JobPrefab jobPrefab = JobPrefab.List.Find(jp => jp.Name == jobName);
|
||||
|
||||
ushort spawnPointID = inc.ReadUInt16();
|
||||
|
||||
if (inc.Position > inc.LengthBits)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
//ushort spawnPointID = inc.ReadUInt16();
|
||||
|
||||
CharacterInfo ch = new CharacterInfo(Character.HumanConfigFile, newName, isFemale ? Gender.Female : Gender.Male, jobPrefab);
|
||||
ch.HeadSpriteId = headSpriteID;
|
||||
@@ -1076,32 +1075,13 @@ namespace Barotrauma.Networking
|
||||
|
||||
character.ID = ID;
|
||||
|
||||
WayPoint spawnPoint = Entity.FindEntityByID(spawnPointID) as WayPoint;
|
||||
if (spawnPoint != null)
|
||||
{
|
||||
character.GiveJobItems(spawnPoint);
|
||||
}
|
||||
//WayPoint spawnPoint = Entity.FindEntityByID(spawnPointID) as WayPoint;
|
||||
//if (spawnPoint != null)
|
||||
//{
|
||||
// //character.GiveJobItems(spawnPoint);
|
||||
//}
|
||||
|
||||
for (int i = 0; i < character.Inventory.Items.Length; i++)
|
||||
{
|
||||
ushort itemID = inc.ReadUInt16();
|
||||
|
||||
System.Diagnostics.Debug.Assert((itemID == 0) == (character.Inventory.Items[i] == null));
|
||||
if (character.Inventory.Items[i] == null) continue;
|
||||
|
||||
character.Inventory.Items[i].ID = itemID;
|
||||
|
||||
int containedCount = inc.ReadByte();
|
||||
if (containedCount > 0)
|
||||
{
|
||||
var containedItems = character.Inventory.Items[i].ContainedItems;
|
||||
for (int j = 0; j<containedCount; j++)
|
||||
{
|
||||
ushort containedID = inc.ReadUInt16();
|
||||
if (containedItems[j] != null) containedItems[j].ID = containedID;
|
||||
}
|
||||
}
|
||||
}
|
||||
Item.Spawner.ReadNetworkData(inc);
|
||||
|
||||
if (isMyCharacter)
|
||||
{
|
||||
|
||||
@@ -621,7 +621,7 @@ namespace Barotrauma.Networking
|
||||
if (gameStarted && AllowSpectating)
|
||||
{
|
||||
var startMessage = CreateStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset);
|
||||
server.SendMessage(startMessage, inc.SenderConnection, NetDeliveryMethod.ReliableUnordered);
|
||||
server.SendMessage(startMessage, inc.SenderConnection, NetDeliveryMethod.ReliableOrdered);
|
||||
|
||||
dataSender.Spectating = true;
|
||||
CoroutineManager.StartCoroutine(SyncSpectator(dataSender));
|
||||
@@ -828,7 +828,7 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
|
||||
SendItemRemoveMessage(Item.Remover.removedItems, new List<NetConnection>() { sender.Connection });
|
||||
SendItemSpawnMessage(Item.Spawner.spawnItems, null, new List<NetConnection>() { sender.Connection });
|
||||
SendItemSpawnMessage(Item.Spawner.spawnItems, new List<NetConnection>() { sender.Connection });
|
||||
|
||||
yield return new WaitForSeconds(1.0f);
|
||||
|
||||
@@ -1032,7 +1032,6 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
connectedClients[i].Character = Character.Create(
|
||||
connectedClients[i].characterInfo, assignedWayPoints[i].WorldPosition, true, false);
|
||||
connectedClients[i].Character.SpawnPoint = assignedWayPoints[i];
|
||||
connectedClients[i].Character.GiveJobItems(assignedWayPoints[i]);
|
||||
|
||||
GameMain.GameSession.CrewManager.characters.Add(connectedClients[i].Character);
|
||||
@@ -1043,15 +1042,17 @@ namespace Barotrauma.Networking
|
||||
myCharacter = Character.Create(characterInfo, assignedWayPoints[assignedWayPoints.Length - 1].WorldPosition, false, false);
|
||||
Character.Controlled = myCharacter;
|
||||
|
||||
myCharacter.SpawnPoint = assignedWayPoints[assignedWayPoints.Length - 1];
|
||||
myCharacter.GiveJobItems(assignedWayPoints[assignedWayPoints.Length - 1]);
|
||||
|
||||
GameMain.GameSession.CrewManager.characters.Add(myCharacter);
|
||||
}
|
||||
|
||||
|
||||
var startMessage = CreateStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset);
|
||||
SendMessage(startMessage, NetDeliveryMethod.ReliableUnordered);
|
||||
|
||||
SendMessage(startMessage, NetDeliveryMethod.ReliableOrdered);
|
||||
|
||||
//SendItemSpawnMessage(allItems, inventories);
|
||||
|
||||
yield return CoroutineStatus.Running;
|
||||
|
||||
UpdateCrewFrame();
|
||||
@@ -1747,33 +1748,8 @@ namespace Barotrauma.Networking
|
||||
message.Write(character.WorldPosition.Y);
|
||||
|
||||
message.Write(character.Info.Job.Name);
|
||||
message.Write(character.SpawnPoint == null ? (ushort)0 : character.SpawnPoint.ID);
|
||||
|
||||
for (int i = 0; i < character.Inventory.Items.Length; i++)
|
||||
{
|
||||
if (character.Inventory.Items[i] == null)
|
||||
{
|
||||
message.Write((ushort)0);
|
||||
}
|
||||
else
|
||||
{
|
||||
message.Write(character.Inventory.Items[i].ID);
|
||||
var containedItems = character.Inventory.Items[i].ContainedItems;
|
||||
if (containedItems == null || !containedItems.Any(c => c != null))
|
||||
{
|
||||
message.Write((byte)0);
|
||||
}
|
||||
else
|
||||
{
|
||||
message.Write((byte)containedItems.Length);
|
||||
for (int j = 0; j < containedItems.Length; j++)
|
||||
{
|
||||
message.Write(containedItems[j] == null ? (ushort)0 : containedItems[j].ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Item.Spawner.FillNetworkData(message, character.SpawnItems);
|
||||
}
|
||||
|
||||
public void SendCharacterSpawnMessage(Character character, List<NetConnection> recipients = null)
|
||||
@@ -1791,14 +1767,14 @@ namespace Barotrauma.Networking
|
||||
SendMessage(message, NetDeliveryMethod.ReliableUnordered, recipients);
|
||||
}
|
||||
|
||||
public void SendItemSpawnMessage(List<Item> items, List<Inventory> inventories = null, List<NetConnection> recipients = null)
|
||||
public void SendItemSpawnMessage(List<Item> items, List<NetConnection> recipients = null)
|
||||
{
|
||||
if (items == null || !items.Any()) return;
|
||||
|
||||
NetOutgoingMessage message = server.CreateMessage();
|
||||
message.Write((byte)PacketTypes.NewItem);
|
||||
|
||||
Item.Spawner.FillNetworkData(message, items, inventories);
|
||||
Item.Spawner.FillNetworkData(message, items);
|
||||
|
||||
SendMessage(message, NetDeliveryMethod.ReliableOrdered, recipients);
|
||||
}
|
||||
|
||||
@@ -223,6 +223,8 @@ namespace Barotrauma.Networking
|
||||
if (updateReturnTimer > 10.0f)
|
||||
{
|
||||
updateReturnTimer = 0.0f;
|
||||
|
||||
respawnShuttle.SubBody.Body.IgnoreCollisionWith(Level.Loaded.ShaftBodies[0]);
|
||||
|
||||
shuttleSteering.AutoPilot = true;
|
||||
shuttleSteering.MaintainPos = false;
|
||||
@@ -279,6 +281,8 @@ namespace Barotrauma.Networking
|
||||
|
||||
ResetShuttle();
|
||||
|
||||
shuttleSteering.TargetVelocity = Vector2.Zero;
|
||||
|
||||
server.SendChatMessage(ChatMessage.Create("", "Transportation shuttle dispatched", ChatMessageType.Server, null), server.ConnectedClients);
|
||||
|
||||
server.SendRespawnManagerMsg();
|
||||
@@ -346,6 +350,9 @@ namespace Barotrauma.Networking
|
||||
respawnShuttle.SetPosition(new Vector2(Level.Loaded.StartPosition.X, Level.Loaded.Size.Y + respawnShuttle.Borders.Height));
|
||||
|
||||
respawnShuttle.Velocity = Vector2.Zero;
|
||||
|
||||
respawnShuttle.SubBody.Body.RestoreCollisionWith(Level.Loaded.ShaftBodies[0]);
|
||||
|
||||
}
|
||||
|
||||
public void WriteNetworkEvent(NetOutgoingMessage msg)
|
||||
@@ -371,11 +378,34 @@ namespace Barotrauma.Networking
|
||||
|
||||
var waypoints = WayPoint.SelectCrewSpawnPoints(characterInfos, respawnShuttle);
|
||||
|
||||
ItemPrefab divingSuitPrefab = ItemPrefab.list.Find(ip => ip.Name == "Diving Suit") as ItemPrefab;
|
||||
ItemPrefab oxyPrefab = ItemPrefab.list.Find(ip => ip.Name == "Oxygen Tank") as ItemPrefab;
|
||||
|
||||
var cargoSp = WayPoint.WayPointList.Find(wp => wp.Submarine == respawnShuttle && wp.SpawnType == SpawnType.Cargo);
|
||||
|
||||
List<Item> spawnedItems = new List<Item>();
|
||||
|
||||
msg.Write((byte)characterInfos.Count);
|
||||
for (int i = 0; i < characterInfos.Count; i++)
|
||||
{
|
||||
var character = Character.Create(characterInfos[i], waypoints[i].WorldPosition, true, false);
|
||||
|
||||
if (divingSuitPrefab != null && oxyPrefab != null)
|
||||
{
|
||||
Vector2 pos = cargoSp == null ? character.Position : cargoSp.Position;
|
||||
|
||||
var divingSuit = new Item(divingSuitPrefab, pos, respawnShuttle);
|
||||
var oxyTank = new Item(oxyPrefab, pos, respawnShuttle);
|
||||
|
||||
oxyTank.Combine(divingSuit);
|
||||
|
||||
spawnedItems.Add(divingSuit);
|
||||
spawnedItems.Add(oxyTank);
|
||||
|
||||
Item.Spawner.AddToSpawnedList(divingSuit);
|
||||
Item.Spawner.AddToSpawnedList(oxyTank);
|
||||
}
|
||||
|
||||
if (i < clients.Count)
|
||||
{
|
||||
msg.Write((byte)clients[i].ID);
|
||||
@@ -388,14 +418,14 @@ namespace Barotrauma.Networking
|
||||
Character.Controlled = character;
|
||||
}
|
||||
|
||||
character.SpawnPoint = waypoints[i];
|
||||
character.GiveJobItems(waypoints[i]);
|
||||
|
||||
GameMain.GameSession.CrewManager.characters.Add(character);
|
||||
|
||||
server.WriteCharacterData(msg, character.Name, character);
|
||||
}
|
||||
|
||||
|
||||
GameMain.Server.SendItemSpawnMessage(spawnedItems);
|
||||
break;
|
||||
case State.Waiting:
|
||||
msg.Write(CountdownStarted);
|
||||
@@ -437,14 +467,11 @@ namespace Barotrauma.Networking
|
||||
case State.Waiting:
|
||||
CountdownStarted = true;
|
||||
|
||||
respawnShuttle.SubBody.Body.RestoreCollisionWith(Level.Loaded.ShaftBodies[0]);
|
||||
|
||||
ResetShuttle();
|
||||
|
||||
respawnTimer = inc.ReadSingle();
|
||||
break;
|
||||
case State.Returning:
|
||||
respawnShuttle.SubBody.Body.IgnoreCollisionWith(Level.Loaded.ShaftBodies[0]);
|
||||
|
||||
CountdownStarted = false;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user