From 3d065c116e907fa3885c953d2c76be886c23edf0 Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Sun, 21 Jul 2024 12:26:10 +0530 Subject: [PATCH] bugfixes for the reported issues --- .../hunt/intermediate/GemsInTheRoad.mis | 2 +- src/MarbleGame.hx | 3 +++ src/MarbleWorld.hx | 27 ++++++++++++++++--- src/Settings.hx | 4 +-- src/gui/MPKickBanDlg.hx | 4 +++ src/gui/MPPreGameDlg.hx | 2 ++ src/modes/HuntMode.hx | 15 ++++++++--- src/net/ClientConnection.hx | 1 + src/net/Net.hx | 4 +++ src/net/NetCommands.hx | 23 +--------------- src/touch/MovementInput.hx | 17 ++++++++++++ 11 files changed, 70 insertions(+), 32 deletions(-) diff --git a/data/multiplayer/hunt/intermediate/GemsInTheRoad.mis b/data/multiplayer/hunt/intermediate/GemsInTheRoad.mis index 53c118d9..aefe95e8 100644 --- a/data/multiplayer/hunt/intermediate/GemsInTheRoad.mis +++ b/data/multiplayer/hunt/intermediate/GemsInTheRoad.mis @@ -7,7 +7,7 @@ new SimGroup(MissionGroup) { desc = "Find the gems in the maze of roads!"; radiusFromGem = "20"; gameMode = "Hunt"; - level = "5"; + level = "4"; type = "Intermediate"; time = "300000"; maxGemsPerSpawn = "6"; diff --git a/src/MarbleGame.hx b/src/MarbleGame.hx index 07ba56d2..67435b43 100644 --- a/src/MarbleGame.hx +++ b/src/MarbleGame.hx @@ -262,6 +262,9 @@ class MarbleGame { if (paused && world._ready) { Console.log("Game paused"); world.setCursorLock(false); + if (Util.isTouchDevice()) { + this.touchInput.movementInput.forceRelease(); + } if (world.isMultiplayer) { exitGameDlg = new MPExitGameDlg(() -> { canvas.popDialog(exitGameDlg); diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index 66a73396..af78e350 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -1,5 +1,6 @@ package src; +import net.NetPacket.ExplodableUpdatePacket; import net.TrapdoorPredictionStore; import shapes.Explodable; import net.ExplodablePredictionStore; @@ -563,10 +564,10 @@ class MarbleWorld extends Scheduler { interior.onLevelStart(); for (shape in this.dtsObjects) shape.onLevelStart(); - // if (this.isMultiplayer && Net.isClient) - // NetCommands.clientIsReady(Net.clientId); + if (this.isMultiplayer && Net.isClient && !_skipPreGame) + NetCommands.clientIsReady(Net.clientId); if (this.isMultiplayer && Net.isHost) { - // NetCommands.clientIsReady(-1); + // NetCommands.clientIsReady(-1); // Sort all the marbles so that they are updated in a deterministic order this.marbles.sort((a, b) -> @:privateAccess { @@ -591,6 +592,7 @@ class MarbleWorld extends Scheduler { _skipPreGame = false; this.setCursorLock(true); NetCommands.requestMidGameJoinState(Net.clientId); + NetCommands.clientIsReady(Net.clientId); } } this.gameMode.onMissionLoad(); @@ -1417,7 +1419,11 @@ class MarbleWorld extends Scheduler { // Marble states for (marb in this.marbles) { var oldFlags = @:privateAccess marb.netFlags; - @:privateAccess marb.netFlags = MarbleNetFlags.DoBlast | MarbleNetFlags.DoMega | MarbleNetFlags.DoHelicopter | MarbleNetFlags.PickupPowerup | MarbleNetFlags.GravityChange | MarbleNetFlags.UsePowerup; + @:privateAccess marb.netFlags = MarbleNetFlags.DoBlast | MarbleNetFlags.DoMega | MarbleNetFlags.DoHelicopter | MarbleNetFlags.DoShockAbsorber | MarbleNetFlags.DoSuperBounce | MarbleNetFlags.PickupPowerup | MarbleNetFlags.GravityChange | MarbleNetFlags.UsePowerup; + + if (oldFlags & MarbleNetFlags.UpdateTrapdoor > 0) { + @:privateAccess marb.netFlags |= MarbleNetFlags.UpdateTrapdoor; + } var innerMove = @:privateAccess marb.lastMove; if (innerMove == null) { @@ -1452,6 +1458,19 @@ class MarbleWorld extends Scheduler { } } + // Explosion states + for (exp in this.explodables) { + if (this.timeState.ticks < (exp.lastContactTick + exp.renewTime >> 5)) { + var b = new OutputBitStream(); + b.writeByte(NetPacketType.ExplodableUpdate); + var explPacket = new ExplodableUpdatePacket(); + explPacket.explodableId = exp.netId; + explPacket.serverTicks = timeState.ticks; + explPacket.serialize(b); + packets.push(b.getBytes()); + } + } + // Scoreboard! var b = new OutputBitStream(); b.writeByte(NetPacketType.ScoreBoardInfo); diff --git a/src/Settings.hx b/src/Settings.hx index ac0fbcce..3c704198 100644 --- a/src/Settings.hx +++ b/src/Settings.hx @@ -422,8 +422,8 @@ class Settings { levelStatistics.set(key, value); } } - if (json.serverSettings != null) { - serverSettings = json.serverSettings; + if (json.server != null) { + serverSettings = json.server; } #if js if (serverSettings.oldSpawns == null) { diff --git a/src/gui/MPKickBanDlg.hx b/src/gui/MPKickBanDlg.hx index a759178f..c8ca7bea 100644 --- a/src/gui/MPKickBanDlg.hx +++ b/src/gui/MPKickBanDlg.hx @@ -1,5 +1,6 @@ package gui; +import net.ClientConnection; import net.NetCommands; import net.Net; import h2d.filter.DropShadow; @@ -91,6 +92,7 @@ class MPKickBanDlg extends GuiImage { var playerList = new GuiTextListCtrl(markerFelt18, playerNames, 0); playerList.position = new Vector(120, 60); playerList.extent = new Vector(188, 180); + playerList.scrollable = true; playerList.textYOffset = -6; playerList.onSelectedFunc = (sel) -> { kickBtn.disabled = false; @@ -106,6 +108,8 @@ class MPKickBanDlg extends GuiImage { playerList.setTexts(playerNames); kickBtn.disabled = true; NetCommands.getKickedClient(Net.clientIdMap.get(playerToKick)); + var cc = cast(Net.clientIdMap.get(playerToKick), ClientConnection); + cc.socket.close(); } } } diff --git a/src/gui/MPPreGameDlg.hx b/src/gui/MPPreGameDlg.hx index 41b6dfff..90153c78 100644 --- a/src/gui/MPPreGameDlg.hx +++ b/src/gui/MPPreGameDlg.hx @@ -289,6 +289,8 @@ class MPPreGameDlg extends GuiControl { playerListLeft.setTexts(playerListCompiled); playerListRight.setTexts(playerListStateCompiled); + playerListContainer.setScrollMax(playerListLeft.calculateFullHeight()); + if (playerListArr.length == 1) { // Disable spectating Net.hostSpectate = false; diff --git a/src/modes/HuntMode.hx b/src/modes/HuntMode.hx index 66ec0058..8876de84 100644 --- a/src/modes/HuntMode.hx +++ b/src/modes/HuntMode.hx @@ -120,10 +120,19 @@ class HuntMode extends NullMode { override function getSpawnTransform() { var idx = Net.connectedServerInfo.competitiveMode ? idealSpawnIndex : Math.floor(rng2.randRange(0, playerSpawnPoints.length - 1)); if (!Net.connectedServerInfo.competitiveMode) { - while (spawnPointTaken[idx]) { - idx = Math.floor(rng2.randRange(0, playerSpawnPoints.length - 1)); + var allTaken = true; + for (spw in spawnPointTaken) { + if (!spw) { + allTaken = false; + break; + } + } + if (!allTaken) { + while (spawnPointTaken[idx]) { + idx = Math.floor(rng2.randRange(0, playerSpawnPoints.length - 1)); + } + spawnPointTaken[idx] = true; } - spawnPointTaken[idx] = true; } var randomSpawn = playerSpawnPoints[idx]; diff --git a/src/net/ClientConnection.hx b/src/net/ClientConnection.hx index c3ca4691..f7672545 100644 --- a/src/net/ClientConnection.hx +++ b/src/net/ClientConnection.hx @@ -9,6 +9,7 @@ import src.TimeState; enum abstract GameplayState(Int) from Int to Int { var UNKNOWN; var LOBBY; + var LOADING; var GAME; } diff --git a/src/net/Net.hx b/src/net/Net.hx index fb958e11..aba5b989 100644 --- a/src/net/Net.hx +++ b/src/net/Net.hx @@ -433,6 +433,10 @@ class Net { for (dc => cc in clients) { if (cc is ClientConnection) { var conn = cast(cc, ClientConnection); + if (Net.isHost && conn.state == LOADING) + continue; + if (Net.isClient && MarbleGame.instance.world != null && !MarbleGame.instance.world._ready) + continue; // We still loading, don't disconnect if (conn.needsTimeoutWarn(t)) { conn.didWarnTimeout = true; if (Net.isClient) { diff --git a/src/net/NetCommands.hx b/src/net/NetCommands.hx index d8bce7b7..f7b96fd6 100644 --- a/src/net/NetCommands.hx +++ b/src/net/NetCommands.hx @@ -160,28 +160,7 @@ class NetCommands { @:rpc(client) public static function clientIsReady(clientId:Int) { if (Net.isHost) { - if (Net.serverInfo.state == "WAITING") { - Console.log('Client ${clientId} is ready!'); - if (clientId != -1) - Net.clientIdMap[clientId].ready(); - else - Net.hostReady = true; - var allReady = true; - for (id => client in Net.clientIdMap) { - if (client.state != GameplayState.GAME) { - allReady = false; - break; - } - } - if (allReady && Net.hostReady) { - if (MarbleGame.instance.world != null) { - Console.log('All are ready, starting'); - MarbleGame.instance.world.allClientsReady(); - } - Net.serverInfo.state = "PLAYING"; - MasterServerClient.instance.sendServerInfo(Net.serverInfo); // notify the server of the playing state - } - } else {} + Net.clientIdMap[clientId].state = GAME; } } diff --git a/src/touch/MovementInput.hx b/src/touch/MovementInput.hx index b99d32f2..ad62f40b 100644 --- a/src/touch/MovementInput.hx +++ b/src/touch/MovementInput.hx @@ -22,6 +22,8 @@ class MovementInput { public var value:Vector = new Vector(); + var releaseFn:() -> Void; + var touchId = -1; public function new() { @@ -69,6 +71,11 @@ class MovementInput { var stopped = false; + releaseFn = () -> { + stopped = true; + collider.stopCapture(); + } + collider.startCapture((emove) -> { if (e.touchId != emove.touchId) { emove.propagate = true; @@ -124,6 +131,16 @@ class MovementInput { } } + public function forceRelease() { + releaseFn(); + this.area.graphics.alpha = 0; + this.joystick.graphics.alpha = 0; + + pressed = false; + + this.value = new Vector(0, 0); + } + public function add(parentGui:GuiControl) { parentGui.addChild(this.area); added = true;