-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implemented mindustry server messenger requests
- Loading branch information
Showing
19 changed files
with
317 additions
and
278 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
30 changes: 0 additions & 30 deletions
30
imperium-common/src/main/kotlin/com/xpdustry/imperium/common/application/ImperiumMetadata.kt
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
imperium-common/src/main/kotlin/com/xpdustry/imperium/common/application/ImperiumPlatform.kt
This file was deleted.
Oops, something went wrong.
86 changes: 86 additions & 0 deletions
86
imperium-common/src/main/kotlin/com/xpdustry/imperium/common/bridge/PlayerTracker.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,86 @@ | ||
/* | ||
* Imperium, the software collection powering the Xpdustry network. | ||
* Copyright (C) 2023 Xpdustry | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package com.xpdustry.imperium.common.bridge | ||
|
||
import com.xpdustry.imperium.common.message.Message | ||
import com.xpdustry.imperium.common.message.Messenger | ||
import com.xpdustry.imperium.common.message.request | ||
import com.xpdustry.imperium.common.security.Identity | ||
import com.xpdustry.imperium.common.serialization.SerializableJInstant | ||
import java.time.Instant | ||
import kotlin.time.Duration.Companion.seconds | ||
import kotlinx.serialization.Serializable | ||
|
||
interface PlayerTracker { | ||
suspend fun getPlayerJoins(server: String): List<Entry>? | ||
|
||
suspend fun getPlayerQuits(server: String): List<Entry>? | ||
|
||
suspend fun getOnlinePlayers(server: String): List<Entry>? | ||
|
||
suspend fun getPlayerEntry(tid: Long): Entry? | ||
|
||
@Serializable | ||
data class Entry( | ||
val player: Identity.Mindustry, | ||
val tid: Long, | ||
val timestamp: SerializableJInstant = Instant.now() | ||
) | ||
} | ||
|
||
open class RequestingPlayerTracker(protected val messenger: Messenger) : PlayerTracker { | ||
|
||
override suspend fun getPlayerJoins(server: String): List<PlayerTracker.Entry>? = | ||
requestPlayerList(server, PlayerListRequest.Type.JOIN) | ||
|
||
override suspend fun getPlayerQuits(server: String): List<PlayerTracker.Entry>? = | ||
requestPlayerList(server, PlayerListRequest.Type.QUIT) | ||
|
||
override suspend fun getOnlinePlayers(server: String): List<PlayerTracker.Entry>? = | ||
requestPlayerList(server, PlayerListRequest.Type.ONLINE) | ||
|
||
private suspend fun requestPlayerList(server: String, type: PlayerListRequest.Type) = | ||
messenger | ||
.request<PlayerListResponse>(PlayerListRequest(server, type), timeout = 1.seconds) | ||
?.entries | ||
|
||
override suspend fun getPlayerEntry(tid: Long): PlayerTracker.Entry? = | ||
messenger | ||
.request<PlayerLookupResponse>(PlayerLookupRequest(tid), timeout = 1.seconds) | ||
?.entry | ||
|
||
@Serializable | ||
protected data class PlayerListRequest( | ||
val server: String, | ||
val type: Type, | ||
) : Message { | ||
enum class Type { | ||
JOIN, | ||
QUIT, | ||
ONLINE | ||
} | ||
} | ||
|
||
@Serializable | ||
protected data class PlayerListResponse(val entries: List<PlayerTracker.Entry>) : Message | ||
|
||
@Serializable protected data class PlayerLookupRequest(val tid: Long) : Message | ||
|
||
@Serializable | ||
protected data class PlayerLookupResponse(val entry: PlayerTracker.Entry) : Message | ||
} |
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
45 changes: 0 additions & 45 deletions
45
imperium-common/src/main/kotlin/com/xpdustry/imperium/common/network/MindustryServerInfo.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.