Notifying clients when the round ends

This commit is contained in:
Regalis
2017-01-06 19:06:11 +02:00
parent 65d64af041
commit 5d83a33876
3 changed files with 55 additions and 1 deletions

View File

@@ -557,6 +557,15 @@ namespace Barotrauma.Networking
case ServerPacketHeader.STARTGAME:
startGameCoroutine = GameMain.ShowLoading(StartGame(inc), false);
break;
case ServerPacketHeader.ENDGAME:
string endMessage = inc.ReadString();
bool missionSuccessful = inc.ReadBoolean();
if (missionSuccessful && GameMain.GameSession.Mission != null)
{
GameMain.GameSession.Mission.Completed = true;
}
CoroutineManager.StartCoroutine(EndGame(endMessage));
break;
}
break;
}
@@ -634,6 +643,41 @@ namespace Barotrauma.Networking
yield return CoroutineStatus.Success;
}
public IEnumerable<object> EndGame(string endMessage)
{
if (!gameStarted) yield return CoroutineStatus.Success;
if (GameMain.GameSession != null) GameMain.GameSession.gameMode.End(endMessage);
gameStarted = false;
Character.Controlled = null;
GameMain.GameScreen.Cam.TargetPos = Vector2.Zero;
GameMain.LightManager.LosEnabled = false;
respawnManager = null;
float endPreviewLength = 10.0f;
if (Screen.Selected == GameMain.GameScreen)
{
new TransitionCinematic(Submarine.MainSub, GameMain.GameScreen.Cam, endPreviewLength);
float secondsLeft = endPreviewLength;
do
{
secondsLeft -= CoroutineManager.UnscaledDeltaTime;
yield return CoroutineStatus.Running;
} while (secondsLeft > 0.0f);
}
Submarine.Unload();
GameMain.NetLobbyScreen.Select();
myCharacter = null;
foreach (Client c in otherClients)
{
c.inGame = false;
c.Character = null;
}
yield return CoroutineStatus.Success;
}
private void ReadLobbyUpdate(NetIncomingMessage inc)
{
ServerNetObject objHeader;

View File

@@ -1065,6 +1065,15 @@ namespace Barotrauma.Networking
if (connectedClients.Count > 0)
{
NetOutgoingMessage msg = server.CreateMessage();
msg.Write((byte)ServerPacketHeader.ENDGAME);
msg.Write(endMessage);
msg.Write(mission != null && mission.Completed);
if (server.ConnectionsCount > 0)
{
server.SendMessage(msg, server.Connections, NetDeliveryMethod.ReliableOrdered, 0);
}
foreach (Client client in connectedClients)
{
client.Character = null;

View File

@@ -37,7 +37,8 @@ namespace Barotrauma.Networking
UPDATE_INGAME, //update state ingame (character input and chat messages)
QUERY_STARTGAME, //ask the clients whether they're ready to start
STARTGAME //start a new round
STARTGAME, //start a new round
ENDGAME
}
enum ServerNetObject
{