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

View file

@ -589,7 +589,7 @@ class Net {
// if (MultiplayerLevelSelectGui.custSelected) { // if (MultiplayerLevelSelectGui.custSelected) {
// NetCommands.playCustomLevelMidJoinClient(conn, MultiplayerLevelSelectGui.custPath); // NetCommands.playCustomLevelMidJoinClient(conn, MultiplayerLevelSelectGui.custPath);
// } else // } else
// NetCommands.playLevelMidJoinClient(conn, MPPlayMissionGui.currentCategoryStatic, MPPlayMissionGui.currentSelectionStatic); NetCommands.playLevelMidJoinClient(conn, MPPlayMissionGui.currentCategoryStatic, MPPlayMissionGui.currentSelectionStatic);
MarbleGame.instance.world.addJoiningClient(conn, () -> {}); MarbleGame.instance.world.addJoiningClient(conn, () -> {});
var playerInfoBytes = sendPlayerInfosBytes(); var playerInfoBytes = sendPlayerInfosBytes();
for (dc => cc in clients) { 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) { if (Net.isClient) {
var difficultyMissions = MissionList.missionList['ultra']["multiplayer"]; MissionList.buildMissionList();
var curMission = difficultyMissions[index]; var difficultyMissions = MissionList.missionList['multiplayer'][category];
var curMission = difficultyMissions[levelIndex];
MarbleGame.instance.playMission(curMission, true); MarbleGame.instance.playMission(curMission, true);
@:privateAccess MarbleGame.instance.world._skipPreGame = true;
} }
} }
@ -146,35 +148,39 @@ class NetCommands {
Net.serverInfo.state = "PLAYING"; Net.serverInfo.state = "PLAYING";
MasterServerClient.instance.sendServerInfo(Net.serverInfo); // notify the server of the playing state MasterServerClient.instance.sendServerInfo(Net.serverInfo); // notify the server of the playing state
} }
} else { } 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();
if (MarbleGame.instance.world.serverStartTicks == 0) { @:rpc(client) public static function requestMidGameJoinState(clientId:Int) {
var allReady = true; if (Net.isHost) {
for (id => client in Net.clientIdMap) { // Mid game join
if (client.state != GameplayState.GAME) { Console.log("Mid game join for client " + clientId);
allReady = false; // Send em our present world state
break; 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);
} }
} }
} }