Fixed exception when attempting to start a round with no clients, spawning host's character

This commit is contained in:
Regalis
2016-10-04 19:22:23 +03:00
parent 050f7ffc83
commit 65006c5da1
+43 -23
View File
@@ -788,28 +788,31 @@ namespace Barotrauma.Networking
{
GameMain.NetLobbyScreen.StartButton.Enabled = false;
NetOutgoingMessage msg = server.CreateMessage();
msg.Write((byte)ServerPacketHeader.QUERY_STARTGAME);
msg.Write(selectedSub.Name);
msg.Write(selectedSub.MD5Hash.Hash);
msg.Write(selectedShuttle.Name);
msg.Write(selectedShuttle.MD5Hash.Hash);
connectedClients.ForEach(c => c.ReadyToStart = false);
server.SendMessage(msg, connectedClients.Select(c => c.Connection).ToList(), NetDeliveryMethod.ReliableUnordered, 0);
//give the clients a few seconds to request missing sub/shuttle files before starting the round
float waitForResponseTimer = 3.0f;
while (connectedClients.Any(c => !c.ReadyToStart) && waitForResponseTimer > 0.0f)
if (connectedClients.Any())
{
waitForResponseTimer -= CoroutineManager.UnscaledDeltaTime;
yield return CoroutineStatus.Running;
}
NetOutgoingMessage msg = server.CreateMessage();
msg.Write((byte)ServerPacketHeader.QUERY_STARTGAME);
//todo: wait until file transfers are finished/cancelled
msg.Write(selectedSub.Name);
msg.Write(selectedSub.MD5Hash.Hash);
msg.Write(selectedShuttle.Name);
msg.Write(selectedShuttle.MD5Hash.Hash);
connectedClients.ForEach(c => c.ReadyToStart = false);
server.SendMessage(msg, connectedClients.Select(c => c.Connection).ToList(), NetDeliveryMethod.ReliableUnordered, 0);
//give the clients a few seconds to request missing sub/shuttle files before starting the round
float waitForResponseTimer = 3.0f;
while (connectedClients.Any(c => !c.ReadyToStart) && waitForResponseTimer > 0.0f)
{
waitForResponseTimer -= CoroutineManager.UnscaledDeltaTime;
yield return CoroutineStatus.Running;
}
//todo: wait until file transfers are finished/cancelled
}
GameMain.ShowLoading(StartGame(selectedSub, selectedShuttle, selectedMode), false);
@@ -848,7 +851,7 @@ namespace Barotrauma.Networking
WayPoint spawnPoint = WayPoint.GetRandom(SpawnType.Human, null, selectedSub);
Vector2 spawnPosition = spawnPoint.WorldPosition;
DebugConsole.NewMessage(Convert.ToString(spawnPosition.X) + "," + Convert.ToString(spawnPosition.Y), Color.Lime);
DebugConsole.NewMessage(spawnPosition.ToString(), Color.Lime);
Character spawnedCharacter = Character.Create(Character.HumanConfigFile, spawnPosition, c.characterInfo, true, false);
spawnedCharacter.AnimController.Frozen = true;
c.Character = spawnedCharacter;
@@ -856,6 +859,15 @@ namespace Barotrauma.Networking
GameMain.GameSession.CrewManager.characters.Add(c.Character);
}
if (characterInfo!=null)
{
WayPoint spawnPoint = WayPoint.GetRandom(SpawnType.Human, null, selectedSub);
myCharacter = Character.Create(Character.HumanConfigFile, spawnPoint.WorldPosition, characterInfo, false, false);
GameMain.GameSession.CrewManager.characters.Add(myCharacter);
Character.Controlled = myCharacter;
}
SendStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset, connectedClients);
//var startMessage = CreateStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset);
//server.SendMessage(startMessage, connectedClients.Select(c => c.Connection).ToList(), NetDeliveryMethod.ReliableUnordered, 0);
@@ -908,12 +920,21 @@ namespace Barotrauma.Networking
var clientsWithCharacter = clients.FindAll(c => c.Character != null);
msg.Write((byte)clientsWithCharacter.Count);
int characterCount = clientsWithCharacter.Count;
if (myCharacter != null) characterCount++;
msg.Write((byte)characterCount);
foreach (Client c in clientsWithCharacter)
{
c.Character.WriteSpawnData(msg);
msg.Write(c == client);
}
if (myCharacter != null)
{
myCharacter.WriteSpawnData(msg);
msg.Write(false);
}
server.SendMessage(msg, client.Connection, NetDeliveryMethod.ReliableUnordered);
}
@@ -1291,7 +1312,6 @@ namespace Barotrauma.Networking
if (c.Character == null || !c.Character.IsDead) continue;
assignedClientCount[JobPrefab.List.IndexOf(c.Character.Info.Job.Prefab)]++;
}
//if any of the players has chosen a job that is Always Allowed, give them that job