fix mid-game join

This commit is contained in:
RandomityGuy 2024-06-23 01:16:22 +05:30
parent 8b612fd089
commit d7acac9227
3 changed files with 55 additions and 39 deletions

View file

@ -240,6 +240,8 @@ class MarbleWorld extends Scheduler {
public var _ready:Bool = false;
var _skipPreGame:Bool = false;
var _loadBegin:Bool = false;
var _loaded:Bool = false;
@ -553,7 +555,12 @@ class MarbleWorld extends Scheduler {
// }
if (this.isMultiplayer) {
// Push the pre - game
showPreGame();
if (!_skipPreGame) {
showPreGame();
} else {
_skipPreGame = false;
NetCommands.requestMidGameJoinState(Net.clientId);
}
}
this.gameMode.onMissionLoad();
}
@ -1360,14 +1367,17 @@ class MarbleWorld extends Scheduler {
}
// Scoreboard!
// var b = new OutputBitStream();
// b.writeByte(NetPacketType.ScoreBoardInfo);
// var sbPacket = new ScoreboardPacket();
// for (player in @:privateAccess this.playGui.playerList) {
// sbPacket.scoreBoard.set(player.id, player.score);
// }
// sbPacket.serialize(b);
// packets.push(b.getBytes());
var b = new OutputBitStream();
b.writeByte(NetPacketType.ScoreBoardInfo);
var sbPacket = new ScoreboardPacket();
for (player in @:privateAccess this.playGui.playerList) {
sbPacket.scoreBoard.set(player.id, player.score);
sbPacket.rBoard.set(player.id, player.r);
sbPacket.yBoard.set(player.id, player.y);
sbPacket.bBoard.set(player.id, player.b);
}
sbPacket.serialize(b);
packets.push(b.getBytes());
return packets;
}

View file

@ -589,7 +589,7 @@ class Net {
// if (MultiplayerLevelSelectGui.custSelected) {
// NetCommands.playCustomLevelMidJoinClient(conn, MultiplayerLevelSelectGui.custPath);
// } else
// NetCommands.playLevelMidJoinClient(conn, MPPlayMissionGui.currentCategoryStatic, MPPlayMissionGui.currentSelectionStatic);
NetCommands.playLevelMidJoinClient(conn, MPPlayMissionGui.currentCategoryStatic, MPPlayMissionGui.currentSelectionStatic);
MarbleGame.instance.world.addJoiningClient(conn, () -> {});
var playerInfoBytes = sendPlayerInfosBytes();
for (dc => cc in clients) {

View file

@ -56,11 +56,13 @@ class NetCommands {
// }
// }
@:rpc(server) public static function playLevelMidJoin(index:Int) {
@:rpc(server) public static function playLevelMidJoin(category:String, levelIndex:Int) {
if (Net.isClient) {
var difficultyMissions = MissionList.missionList['ultra']["multiplayer"];
var curMission = difficultyMissions[index];
MissionList.buildMissionList();
var difficultyMissions = MissionList.missionList['multiplayer'][category];
var curMission = difficultyMissions[levelIndex];
MarbleGame.instance.playMission(curMission, true);
@:privateAccess MarbleGame.instance.world._skipPreGame = true;
}
}
@ -146,35 +148,39 @@ class NetCommands {
Net.serverInfo.state = "PLAYING";
MasterServerClient.instance.sendServerInfo(Net.serverInfo); // notify the server of the playing state
}
} else {
// Mid game join
Console.log("Mid game join for client " + clientId);
// Send em our present world state
if (MarbleGame.instance.world != null) {
var packets = MarbleGame.instance.world.getWorldStateForClientJoin();
var c = Net.clientIdMap[clientId];
for (packet in packets) {
c.sendBytes(packet);
}
Net.clientIdMap[clientId].ready();
} else {}
}
}
if (MarbleGame.instance.world.serverStartTicks == 0) {
var allReady = true;
for (id => client in Net.clientIdMap) {
if (client.state != GameplayState.GAME) {
allReady = false;
break;
}
@:rpc(client) public static function requestMidGameJoinState(clientId:Int) {
if (Net.isHost) {
// Mid game join
Console.log("Mid game join for client " + clientId);
// Send em our present world state
if (MarbleGame.instance.world != null) {
var packets = MarbleGame.instance.world.getWorldStateForClientJoin();
var c = Net.clientIdMap[clientId];
for (packet in packets) {
c.sendBytes(packet);
}
Net.clientIdMap[clientId].ready();
if (MarbleGame.instance.world.serverStartTicks == 0) {
var allReady = true;
for (id => client in Net.clientIdMap) {
if (client.state != GameplayState.GAME) {
allReady = false;
break;
}
if (allReady) {
if (MarbleGame.instance.world != null) {
MarbleGame.instance.world.allClientsReady();
}
}
} else {
// Send the start ticks
NetCommands.setStartTicksMidJoinClient(c, MarbleGame.instance.world.serverStartTicks, MarbleGame.instance.world.timeState.ticks);
}
if (allReady) {
if (MarbleGame.instance.world != null) {
MarbleGame.instance.world.allClientsReady();
}
}
} else {
// Send the start ticks
NetCommands.setStartTicksMidJoinClient(c, MarbleGame.instance.world.serverStartTicks, MarbleGame.instance.world.timeState.ticks);
}
}
}