-
-
Save jdkula/781c0edf83943df5e6dc9293f487029e to your computer and use it in GitHub Desktop.
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
package pw.jonak.spyfall.common | |
import kotlinx.serialization.Optional | |
import kotlinx.serialization.Serializable | |
@Serializable | |
open class SpyfallMessage(val message_name: String, val sender_side: Side) | |
enum class Side { | |
SERVER, | |
CLIENT, | |
EITHER | |
} | |
@Serializable | |
class UserRequest(val user_name: String) : SpyfallMessage("user_request", Side.CLIENT) | |
@Serializable | |
class UserRegistrationInformation( | |
val user_id: Int, | |
val user_name: String | |
) : SpyfallMessage("user_registrartion_information", Side.SERVER) | |
@Serializable | |
class GameInformation( | |
@Optional val user_id: Int? = null, | |
val game_code: String, | |
val user_names: List<String>, | |
val game_has_started: Boolean, | |
@Optional val start_time: Long? = null, | |
@Optional val pause_time: Long? = null, | |
@Optional val game_length: Long? = null, | |
@Optional val is_spy: Boolean? = null, | |
@Optional val first_player: Int? = null, | |
@Optional val location: String? = null, | |
@Optional val role: String? = null | |
) : SpyfallMessage("game_information", Side.SERVER) | |
@Serializable | |
class JoinGameRequest( | |
val user_id: Int, | |
val user_name: String, | |
val game_code: String | |
) : SpyfallMessage("join_game_request", Side.CLIENT) | |
@Serializable | |
class LeaveGameRequest( | |
val user_id: Int, | |
val game_code: String | |
) : SpyfallMessage("leave_game_request", Side.CLIENT) | |
@Serializable | |
class StartGameRequest( | |
val user_id: Int, | |
val game_code: String | |
) : SpyfallMessage("start_game_request", Side.CLIENT) | |
@Serializable | |
class StopGameRequest( | |
val user_id: Int, | |
val game_code: String | |
) : SpyfallMessage("stop_game_request", Side.CLIENT) | |
@Serializable | |
open class MessageError( | |
val reason: String, | |
@Optional val request: SpyfallMessage? = null | |
) : SpyfallMessage("message_error", Side.EITHER) | |
@Serializable | |
class InvalidParameters : MessageError("invalid_parameters", null) | |
@Serializable | |
open class ActionFailure(val reason: String) : SpyfallMessage("action_failure", Side.EITHER) | |
@Serializable | |
class GameNotCreatedError : ActionFailure("game_not_created") | |
@Serializable | |
open class StatusMessage(val status: String) : SpyfallMessage("status_message", Side.EITHER) | |
@Serializable | |
class UserNotFound(val user_id: Int) : StatusMessage("user_not_found") | |
@Serializable | |
class GameNotFound(val game_id: String) : StatusMessage("game_not_found") | |
@Serializable | |
class PruneOK(val num_pruned: Int) : StatusMessage("prune_ok") | |
@Serializable | |
class ServerShutdownOK : StatusMessage("server_shutdown_ok") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment