diff options
Diffstat (limited to 'src/main/kotlin/io/dico/parcels2/storage/exposed')
-rw-r--r-- | src/main/kotlin/io/dico/parcels2/storage/exposed/ExposedBacking.kt | 19 | ||||
-rw-r--r-- | src/main/kotlin/io/dico/parcels2/storage/exposed/ListTables.kt | 18 |
2 files changed, 22 insertions, 15 deletions
diff --git a/src/main/kotlin/io/dico/parcels2/storage/exposed/ExposedBacking.kt b/src/main/kotlin/io/dico/parcels2/storage/exposed/ExposedBacking.kt index d0b1296..e3ed21b 100644 --- a/src/main/kotlin/io/dico/parcels2/storage/exposed/ExposedBacking.kt +++ b/src/main/kotlin/io/dico/parcels2/storage/exposed/ExposedBacking.kt @@ -6,7 +6,7 @@ import com.zaxxer.hikari.HikariDataSource import io.dico.parcels2.* import io.dico.parcels2.PlayerProfile.Star.name import io.dico.parcels2.storage.* -import io.dico.parcels2.util.ext.clampMax +import io.dico.parcels2.util.math.ext.clampMax import io.dico.parcels2.util.ext.synchronized import kotlinx.coroutines.* import kotlinx.coroutines.channels.ArrayChannel @@ -193,6 +193,10 @@ class ExposedBacking(private val dataSourceFactory: () -> DataSource, val poolSi PrivilegesLocalT.setPrivilege(parcel, profile, privilege) } + data.privilegeOfStar.takeIf { it != Privilege.DEFAULT }?.let { privilege -> + PrivilegesLocalT.setPrivilege(parcel, PlayerProfile.Star, privilege) + } + setParcelOptionsInteractConfig(parcel, data.interactableConfig) } @@ -242,13 +246,13 @@ class ExposedBacking(private val dataSourceFactory: () -> DataSource, val poolSi } } - override fun transmitAllGlobalAddedData(channel: SendChannel<AddedDataPair<PlayerProfile>>) { - PrivilegesGlobalT.sendAllAddedData(channel) + override fun transmitAllGlobalPrivileges(channel: SendChannel<PrivilegePair<PlayerProfile>>) { + PrivilegesGlobalT.sendAllPrivilegesH(channel) channel.close() } - override fun readGlobalPrivileges(owner: PlayerProfile): MutablePrivilegeMap { - return PrivilegesGlobalT.readPrivileges(ProfilesT.getId(owner.toOwnerProfile()) ?: return hashMapOf()) + override fun readGlobalPrivileges(owner: PlayerProfile): PrivilegesHolder? { + return PrivilegesGlobalT.readPrivileges(ProfilesT.getId(owner.toOwnerProfile()) ?: return null) } override fun setGlobalPrivilege(owner: PlayerProfile, player: PlayerProfile, privilege: Privilege) { @@ -267,7 +271,10 @@ class ExposedBacking(private val dataSourceFactory: () -> DataSource, val poolSi System.arraycopy(source, 0, target, 0, source.size.clampMax(target.size)) } - privilegeMap = PrivilegesLocalT.readPrivileges(id) + val privileges = PrivilegesLocalT.readPrivileges(id) + if (privileges != null) { + copyPrivilegesFrom(privileges) + } } } diff --git a/src/main/kotlin/io/dico/parcels2/storage/exposed/ListTables.kt b/src/main/kotlin/io/dico/parcels2/storage/exposed/ListTables.kt index d22316a..6a0a41b 100644 --- a/src/main/kotlin/io/dico/parcels2/storage/exposed/ListTables.kt +++ b/src/main/kotlin/io/dico/parcels2/storage/exposed/ListTables.kt @@ -15,7 +15,7 @@ object ParcelOptionsT : Table("parcel_options") { val interact_bitmask = binary("interact_bitmask", 4) } -typealias PrivilegesSendChannel<AttachT> = SendChannel<Pair<AttachT, MutablePrivilegeMap>> +typealias PrivilegesSendChannel<AttachT> = SendChannel<Pair<AttachT, PrivilegesHolder>> sealed class PrivilegesTable<AttachT>(name: String, val idTable: IdTransactionsTable<*, AttachT>) : Table(name) { val attach_id = integer("attach_id").references(idTable.id, ReferenceOption.CASCADE) @@ -43,32 +43,32 @@ sealed class PrivilegesTable<AttachT>(name: String, val idTable: IdTransactionsT } } - fun readPrivileges(id: Int): MutablePrivilegeMap { + fun readPrivileges(id: Int): PrivilegesHolder? { val list = slice(profile_id, privilege).select { attach_id eq id } - val result = MutablePrivilegeMap() + val result = PrivilegesHolder() for (row in list) { val profile = ProfilesT.getRealItem(row[profile_id]) ?: continue - result[profile] = Privilege.getByNumber(row[privilege]) ?: continue + result.setRawStoredPrivilege(profile, Privilege.getByNumber(row[privilege]) ?: continue) } return result } - fun sendAllAddedData(channel: PrivilegesSendChannel<AttachT>) { + fun sendAllPrivilegesH(channel: PrivilegesSendChannel<AttachT>) { val iterator = selectAll().orderBy(attach_id).iterator() if (iterator.hasNext()) { val firstRow = iterator.next() var id: Int = firstRow[attach_id] var attach: AttachT? = null - var map: MutablePrivilegeMap? = null + var map: PrivilegesHolder? = null fun initAttachAndMap() { attach = idTable.getItem(id) - map = attach?.let { mutableMapOf() } + map = attach?.let { PrivilegesHolder() } } fun sendIfPresent() { - if (attach != null && map != null && map!!.isNotEmpty()) { + if (attach != null && map != null) { channel.offer(attach!! to map!!) } attach = null @@ -91,7 +91,7 @@ sealed class PrivilegesTable<AttachT>(name: String, val idTable: IdTransactionsT val profile = ProfilesT.getRealItem(row[profile_id]) ?: continue val privilege = Privilege.getByNumber(row[privilege]) ?: continue - map!![profile] = privilege + map!!.setRawStoredPrivilege(profile, privilege) } sendIfPresent() |