Skip to content

Commit

Permalink
fix bug where you couldnt start MP in 1 player mode and handle connec…
Browse files Browse the repository at this point in the history
…ting clients leaving
  • Loading branch information
RandomityGuy committed Mar 13, 2024
1 parent 2280672 commit 1a1f798
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion game/marble/server/scripts/game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,7 @@ function SetupGems(%numGemGroups)

function GameConnection::onClientLeaveGame(%this)
{
%this.isReady = true;
// Check to see if we need to set a new $timeKeeper
if (%this == $timeKeeper && ClientGroup.getCount() > 1)
{
Expand All @@ -1099,6 +1100,25 @@ function SetupGems(%numGemGroups)
}
}

if ($Server::ServerType $= "MultiPlayer" && $Game::State $= "start") // We didnt start the game yet somebody left so check if we can start
{
%allReady = true;

for (%i = 0; %i < ClientGroup.getCount(); %i++)
{
%client = ClientGroup.getObject(%i);
if (!%client.isReady)
{
%allReady = false;
break;
}
}
if (%allReady) {
cancel($stateSchedule);
$stateSchedule = schedule(500, 0, "setGameState", "ready");
}
}

if (isObject(%this.camera) && %this.camera != $previewCamera)
%this.camera.delete();
if (isObject(%this.player))
Expand Down Expand Up @@ -2120,7 +2140,7 @@ function setGameState(%state)
switch$ (%state)
{
case "start" :
if ($Server::ServerType !$= "Multiplayer")
if ($Server::ServerType !$= "Multiplayer" || ClientGroup.getCount() == 1) // Don't do RSG yet unless we are the only one - or we are not MP
$stateSchedule = schedule(500, 0, "setGameState", "ready");
case "ready" :
$stateSchedule = schedule(3000, 0, "setGameState", "go");
Expand Down

0 comments on commit 1a1f798

Please sign in to comment.