- server doesn't send the STARTGAME message to all clients when someone joins mid-round

- team ID is included in character spawn messages even if no-one is controlling the character anymore
- living characters are taken into account when assigning jobs for respawned characters (e.g. there can't be two captains alive at the same time)
This commit is contained in:
Regalis
2017-02-05 21:58:31 +02:00
parent 89e881cb57
commit 9bda79036a
2 changed files with 57 additions and 46 deletions
+9 -9
View File
@@ -1740,15 +1740,15 @@ namespace Barotrauma
if (info != null) if (info != null)
{ {
Vector2 namePos = new Vector2(pos.X, pos.Y - 110.0f - (5.0f/cam.Zoom)) - GUI.Font.MeasureString(Info.Name) * 0.5f / cam.Zoom; Vector2 namePos = new Vector2(pos.X, pos.Y - 110.0f - (5.0f / cam.Zoom)) - GUI.Font.MeasureString(Info.Name) * 0.5f / cam.Zoom;
Color nameColor = Color.White; Color nameColor = Color.White;
if (Character.Controlled != null && TeamID!=Character.Controlled.TeamID) if (Character.Controlled != null && TeamID != Character.Controlled.TeamID)
{ {
nameColor = Color.Red; nameColor = Color.Red;
} }
spriteBatch.DrawString(GUI.Font, Info.Name, namePos + new Vector2(1.0f/cam.Zoom, 1.0f / cam.Zoom), Color.Black, 0.0f,Vector2.Zero, 1.0f / cam.Zoom,SpriteEffects.None,0.001f); spriteBatch.DrawString(GUI.Font, Info.Name, namePos + new Vector2(1.0f / cam.Zoom, 1.0f / cam.Zoom), Color.Black, 0.0f, Vector2.Zero, 1.0f / cam.Zoom, SpriteEffects.None, 0.001f);
spriteBatch.DrawString(GUI.Font, Info.Name, namePos, nameColor, 0.0f, Vector2.Zero, 1.0f/cam.Zoom, SpriteEffects.None, 0.0f); spriteBatch.DrawString(GUI.Font, Info.Name, namePos, nameColor, 0.0f, Vector2.Zero, 1.0f / cam.Zoom, SpriteEffects.None, 0.0f);
if (GameMain.DebugDraw) if (GameMain.DebugDraw)
{ {
@@ -2461,20 +2461,19 @@ namespace Barotrauma
{ {
msg.Write(true); msg.Write(true);
msg.Write(ownerClient.ID); msg.Write(ownerClient.ID);
msg.Write(TeamID);
} }
else if (GameMain.Server.Character == this) else if (GameMain.Server.Character == this)
{ {
msg.Write(true); msg.Write(true);
msg.Write((byte)0); msg.Write((byte)0);
msg.Write(TeamID);
} }
else else
{ {
msg.Write(false); msg.Write(false);
} }
msg.Write(Info.Name); msg.Write(Info.Name);
msg.Write(TeamID);
msg.Write(this is AICharacter); msg.Write(this is AICharacter);
msg.Write(Info.Gender == Gender.Female); msg.Write(Info.Gender == Gender.Female);
@@ -2508,9 +2507,10 @@ namespace Barotrauma
{ {
bool hasOwner = inc.ReadBoolean(); bool hasOwner = inc.ReadBoolean();
int ownerId = hasOwner ? inc.ReadByte() : -1; int ownerId = hasOwner ? inc.ReadByte() : -1;
byte teamID = hasOwner ? inc.ReadByte() : (byte)0;
string newName = inc.ReadString(); string newName = inc.ReadString();
byte teamID = inc.ReadByte();
bool hasAi = inc.ReadBoolean(); bool hasAi = inc.ReadBoolean();
bool isFemale = inc.ReadBoolean(); bool isFemale = inc.ReadBoolean();
+48 -37
View File
@@ -546,7 +546,7 @@ namespace Barotrauma.Networking
//game already started -> send start message immediately //game already started -> send start message immediately
if (gameStarted) if (gameStarted)
{ {
SendStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset, connectedClients); SendStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset, connectedClient);
} }
} }
break; break;
@@ -1097,46 +1097,50 @@ namespace Barotrauma.Networking
{ {
foreach (Client client in clients) foreach (Client client in clients)
{ {
NetOutgoingMessage msg = server.CreateMessage(); SendStartMessage(seed, selectedSub, selectedMode, client);
msg.Write((byte)ServerPacketHeader.STARTGAME); }
}
msg.Write(seed); private void SendStartMessage(int seed, Submarine selectedSub, GameModePreset selectedMode, Client client)
{
NetOutgoingMessage msg = server.CreateMessage();
msg.Write((byte)ServerPacketHeader.STARTGAME);
msg.Write(GameMain.NetLobbyScreen.LevelSeed); msg.Write(seed);
msg.Write((byte)GameMain.NetLobbyScreen.MissionTypeIndex); msg.Write(GameMain.NetLobbyScreen.LevelSeed);
msg.Write(selectedSub.Name); msg.Write((byte)GameMain.NetLobbyScreen.MissionTypeIndex);
msg.Write(selectedSub.MD5Hash.Hash);
msg.Write(GameMain.NetLobbyScreen.SelectedShuttle.Name); msg.Write(selectedSub.Name);
msg.Write(GameMain.NetLobbyScreen.SelectedShuttle.MD5Hash.Hash); msg.Write(selectedSub.MD5Hash.Hash);
msg.Write(selectedMode.Name); msg.Write(GameMain.NetLobbyScreen.SelectedShuttle.Name);
msg.Write(GameMain.NetLobbyScreen.SelectedShuttle.MD5Hash.Hash);
bool missionAllowRespawn = msg.Write(selectedMode.Name);
!(GameMain.GameSession.gameMode is MissionMode) ||
((MissionMode)GameMain.GameSession.gameMode).Mission.AllowRespawn;
msg.Write(AllowRespawn && missionAllowRespawn); bool missionAllowRespawn =
msg.Write(Submarine.MainSubs[1] != null); //loadSecondSub !(GameMain.GameSession.gameMode is MissionMode) ||
((MissionMode)GameMain.GameSession.gameMode).Mission.AllowRespawn;
if (TraitorManager != null && msg.Write(AllowRespawn && missionAllowRespawn);
TraitorManager.TraitorCharacter != null && msg.Write(Submarine.MainSubs[1] != null); //loadSecondSub
TraitorManager.TargetCharacter != null &&
TraitorManager.TraitorCharacter == client.Character) if (TraitorManager != null &&
{ TraitorManager.TraitorCharacter != null &&
msg.Write(true); TraitorManager.TargetCharacter != null &&
msg.Write(TraitorManager.TargetCharacter.Name); TraitorManager.TraitorCharacter == client.Character)
} {
else msg.Write(true);
{ msg.Write(TraitorManager.TargetCharacter.Name);
msg.Write(false);
}
server.SendMessage(msg, client.Connection, NetDeliveryMethod.ReliableUnordered);
} }
else
{
msg.Write(false);
}
server.SendMessage(msg, client.Connection, NetDeliveryMethod.ReliableUnordered);
} }
public void EndGame() public void EndGame()
@@ -1468,6 +1472,7 @@ namespace Barotrauma.Networking
if (type == ChatMessageType.Server) if (type == ChatMessageType.Server)
{ {
senderName = null; senderName = null;
senderCharacter = null;
} }
var chatMsg = ChatMessage.Create( var chatMsg = ChatMessage.Create(
@@ -1716,18 +1721,24 @@ namespace Barotrauma.Networking
unassigned = new List<Client>(unassigned); unassigned = new List<Client>(unassigned);
int[] assignedClientCount = new int[JobPrefab.List.Count]; int[] assignedClientCount = new int[JobPrefab.List.Count];
if (characterInfo!=null && assignHost) if (characterInfo != null && assignHost)
{ {
assignedClientCount[JobPrefab.List.FindIndex(jp => jp == GameMain.NetLobbyScreen.JobPreferences[0])]=1; assignedClientCount[JobPrefab.List.FindIndex(jp => jp == GameMain.NetLobbyScreen.JobPreferences[0])] = 1;
}
else if (myCharacter != null && !myCharacter.IsDead)
{
assignedClientCount[JobPrefab.List.IndexOf(myCharacter.Info.Job.Prefab)] = 1;
} }
//count the clients who already have characters with an assigned job
foreach (Client c in connectedClients) foreach (Client c in connectedClients)
{ {
if (unassigned.Contains(c)) continue; if (unassigned.Contains(c)) continue;
if (c.Character == null || !c.Character.IsDead) continue; if (c.Character != null && !c.Character.IsDead)
{
assignedClientCount[JobPrefab.List.IndexOf(c.Character.Info.Job.Prefab)]++; 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 //if any of the players has chosen a job that is Always Allowed, give them that job