diff options
Diffstat (limited to 'engine')
6 files changed, 113 insertions, 0 deletions
diff --git a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/channel/modal/Channel.kt b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/channel/modal/Channel.kt new file mode 100644 index 0000000..427e526 --- /dev/null +++ b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/channel/modal/Channel.kt @@ -0,0 +1,40 @@ +package dev.m1sk9.lunaticChat.engine.channel.modal + +import dev.m1sk9.lunaticChat.engine.settings.UUIDSerializer +import kotlinx.serialization.Serializable +import java.util.UUID + +/** + * Represents a communication channel within the LunaticChat application. + * + * @property id Unique identifier for the channel. + * @property name Name of the channel. + * @property description Optional description of the channel. + * @property isPrivate Indicates whether the channel is private or public. + * @property ownerId UUID of the user who owns the channel. + * @property createdAt Timestamp of when the channel was created. + */ +@Serializable +data class Channel( + val id: String, + val name: String, + val description: String? = null, + val isPrivate: Boolean = false, + @Serializable(with = UUIDSerializer::class) + val ownerId: UUID, + val createdAt: Long = System.currentTimeMillis(), +) { + init { + require(id.matches(CHANNEL_ID_PATTERN)) { + "Channel ID must be 3-30 characters long and can only contain letters, numbers, underscores, and hyphens." + } + + require(name.isNotBlank()) { + "Channel name cannot be blank." + } + } + + companion object { + val CHANNEL_ID_PATTERN = Regex("^[a-zA-Z0-9_-]{3,30}$") + } +} diff --git a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/channel/modal/ChannelData.kt b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/channel/modal/ChannelData.kt new file mode 100644 index 0000000..6196ab7 --- /dev/null +++ b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/channel/modal/ChannelData.kt @@ -0,0 +1,10 @@ +package dev.m1sk9.lunaticChat.engine.channel.modal + +import kotlinx.serialization.Serializable + +@Serializable +data class ChannelData( + val version: Int = 1, + val channels: Map<String, Channel> = emptyMap(), + val members: Map<String, List<ChannelMember>> = emptyMap(), +) diff --git a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/channel/modal/ChannelMember.kt b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/channel/modal/ChannelMember.kt new file mode 100644 index 0000000..3bc2b67 --- /dev/null +++ b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/channel/modal/ChannelMember.kt @@ -0,0 +1,22 @@ +package dev.m1sk9.lunaticChat.engine.channel.modal + +import dev.m1sk9.lunaticChat.engine.settings.UUIDSerializer +import kotlinx.serialization.Serializable +import java.util.UUID + +/** + * Represents a member of a channel with their role and join timestamp. + * + * @property channelId The ID of the channel. + * @property playerId The UUID of the player. + * @property role The role of the member in the channel. + * @property joinedAt The timestamp when the member joined the channel. + */ +@Serializable +data class ChannelMember( + val channelId: String, + @Serializable(with = UUIDSerializer::class) + val playerId: UUID, + val role: ChannelRole, + val joinedAt: Long = System.currentTimeMillis(), +) diff --git a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/channel/modal/ChannelRole.kt b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/channel/modal/ChannelRole.kt new file mode 100644 index 0000000..6a3309a --- /dev/null +++ b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/channel/modal/ChannelRole.kt @@ -0,0 +1,17 @@ +package dev.m1sk9.lunaticChat.engine.channel.modal + +import kotlinx.serialization.Serializable + +/** + * Represents the role of a user within a channel. + * + * - OWNER: The creator and primary administrator of the channel. + * - MODERATOR: A user with elevated permissions to manage channel content and users. + * - MEMBER: A regular user with standard access to the channel. + */ +@Serializable +enum class ChannelRole { + OWNER, + MODERATOR, + MEMBER, +} diff --git a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/exception/ChannelStorageLoadException.kt b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/exception/ChannelStorageLoadException.kt new file mode 100644 index 0000000..21bd654 --- /dev/null +++ b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/exception/ChannelStorageLoadException.kt @@ -0,0 +1,12 @@ +package dev.m1sk9.lunaticChat.engine.exception + +/** + * Exception thrown when there is an error loading channel storage. + * + * @param message The detail message for the exception. + * @param cause The cause of the exception, if any. + */ +class ChannelStorageLoadException( + message: String, + cause: Throwable? = null, +) : Exception(message, cause) diff --git a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/exception/ChannelStorageSaveException.kt b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/exception/ChannelStorageSaveException.kt new file mode 100644 index 0000000..0e9990b --- /dev/null +++ b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/exception/ChannelStorageSaveException.kt @@ -0,0 +1,12 @@ +package dev.m1sk9.lunaticChat.engine.exception + +/** + * Exception thrown when there is an error saving channel storage. + * + * @param message The detail message for the exception. + * @param cause The cause of the exception, if any. + */ +class ChannelStorageSaveException( + message: String, + cause: Throwable? = null, +) : Exception(message, cause) |
