-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add dungeon syncing through ws
chore: update ws URL fix: rebase errors fix: rebase error fix: queue room packets from before dungeon start fix: rebase error didn't close SkytilsWS connection
- Loading branch information
1 parent
5dace83
commit ab0088b
Showing
12 changed files
with
261 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
[submodule "hypixel-api"] | ||
path = hypixel-api | ||
url = https://github.com/Skytils/hypixel-api | ||
|
||
[submodule "ws-shared"] | ||
path = ws-shared | ||
url = https://github.com/Skytils/ws-shared |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/main/kotlin/gg/skytils/skytilsws/client/PacketHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Skytils - Hypixel Skyblock Quality of Life Mod | ||
* Copyright (C) 2020-2024 Skytils | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package gg.skytils.skytilsws.client | ||
|
||
import gg.skytils.skytilsmod.Reference | ||
import gg.skytils.skytilsmod.Skytils.Companion.mc | ||
import gg.skytils.skytilsmod.features.impl.dungeons.catlas.core.map.Room | ||
import gg.skytils.skytilsmod.features.impl.dungeons.catlas.core.map.Unknown | ||
import gg.skytils.skytilsmod.features.impl.dungeons.catlas.handlers.DungeonInfo | ||
import gg.skytils.skytilsmod.features.impl.dungeons.catlas.utils.ScanUtils | ||
import gg.skytils.skytilsws.shared.IPacketHandler | ||
import gg.skytils.skytilsws.shared.SkytilsWS | ||
import gg.skytils.skytilsws.shared.packet.* | ||
import io.ktor.websocket.* | ||
import kotlinx.coroutines.coroutineScope | ||
import java.util.* | ||
|
||
object PacketHandler : IPacketHandler { | ||
suspend fun handleLogin(session: WebSocketSession, packet: S2CPacketAcknowledge) { | ||
val serverId = UUID.randomUUID().toString().replace("-".toRegex(), "") | ||
mc.sessionService.joinServer(mc.session.profile, mc.session.token, serverId) | ||
WSClient.sendPacket(C2SPacketLogin(mc.session.username, mc.session.profile.id.toString(), Reference.VERSION, SkytilsWS.version, serverId)) | ||
} | ||
|
||
override suspend fun processPacket(session: WebSocketSession, packet: Packet) { | ||
println("Received packet: $packet") | ||
when (packet) { | ||
is S2CPacketAcknowledge -> { | ||
if (packet.wsVersion != SkytilsWS.version) { | ||
session.close(CloseReason(CloseReason.Codes.CANNOT_ACCEPT, "Incompatible WS version")) | ||
} else { | ||
coroutineScope { | ||
handleLogin(session, packet) | ||
} | ||
} | ||
} | ||
is S2CPacketDungeonRoomSecret -> { | ||
DungeonInfo.uniqueRooms.find { it.mainRoom.data.name == packet.roomId }?.let { | ||
if (packet.secretCount > (it.foundSecrets ?: -1)) { | ||
it.foundSecrets = packet.secretCount | ||
} | ||
} | ||
} | ||
is S2CPacketDungeonRoom -> { | ||
val room = DungeonInfo.dungeonList[packet.row * 11 + packet.col] | ||
if (room is Unknown || (room as? Room)?.data?.name == "Unknown") { | ||
val data = ScanUtils.roomList.find { it.name == packet.roomId } | ||
DungeonInfo.dungeonList[packet.row * 11 + packet.col] = Room(packet.x, packet.z, data ?: return).apply { | ||
isSeparator = packet.isSeparator | ||
core = packet.core | ||
addToUnique(packet.row, packet.col) | ||
} | ||
} | ||
} | ||
else -> { | ||
session.close(CloseReason(CloseReason.Codes.CANNOT_ACCEPT, "Unknown packet type")) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.