Commit 30/09/2025
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package commandServer
|
||||
|
||||
import codes.Somecodes.Companion.ValidString
|
||||
import database.Messagebank
|
||||
import database.Soundbank
|
||||
import db
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -156,7 +158,127 @@ class TCP_Android_Command_Server {
|
||||
}
|
||||
|
||||
"STARTINITIALIZE" -> {
|
||||
// TODO read coding here
|
||||
val username = parts.getOrElse(1) { "" }
|
||||
if (ValidString(username)){
|
||||
val userlogin = listUserLogin.find { it.username == username }
|
||||
if (userlogin != null){
|
||||
val userdb = db.userDB.List.find { it.username == username }
|
||||
if (userdb != null){
|
||||
val result = StringBuilder()
|
||||
result.append("ZONE")
|
||||
userdb.broadcastzones.split(";").map { it.trim() }.filter { it.isNotBlank() }.forEach {
|
||||
result.append(";")
|
||||
result.append(it)
|
||||
}
|
||||
result.append("@")
|
||||
val VARMESSAGES = mutableListOf<Messagebank>()
|
||||
userdb.messagebank_ann_id
|
||||
// messagebank_ann_id adalah rentengan ANN_ID (digit) yang dipisah dengan ;
|
||||
.split(";")
|
||||
// trim dulu
|
||||
.map { it.trim() }
|
||||
// bukan string kosong antar dua tanda ;
|
||||
.filter { it.isNotBlank() }
|
||||
// beneran digit semua
|
||||
.filter { xx -> xx.all{it.isDigit()} }
|
||||
// iterasi setiap ANN_ID
|
||||
.forEach { annid ->
|
||||
// masukin ke VARMESSAGES yang unik secara ANN_ID dan Description
|
||||
VARMESSAGES.addAll(db.messageDB.List.distinctBy { it.ANN_ID }.distinctBy { it.Description })
|
||||
}
|
||||
result.append("MSGTOTAL;").append(VARMESSAGES.size).append("@")
|
||||
// VAR AP TOTAL
|
||||
val VARAPTOTAL = mutableListOf<Soundbank>()
|
||||
val sb_split = userdb.soundbank_tags.split(";").map { it.trim() }.filter { it.isNotBlank() }
|
||||
sb_split.forEach {
|
||||
val sb = db.Find_Soundbank_AirplaneName(it).firstOrNull()
|
||||
if (sb != null) VARAPTOTAL.add(sb)
|
||||
}
|
||||
result.append("VARAPTOTAL;").append(VARAPTOTAL.size).append("@")
|
||||
// VAR CITY TOTAL
|
||||
val VARCITYTOTAL = mutableListOf<Soundbank>()
|
||||
sb_split.forEach {
|
||||
val sb = db.Find_Soundbank_City(it).firstOrNull()
|
||||
if (sb != null) VARCITYTOTAL.add(sb)
|
||||
}
|
||||
result.append("VARCITYTOTAL;").append(VARCITYTOTAL.size).append("@")
|
||||
// VAR PLACES TOTAL
|
||||
val VARPLACESTOTAL = mutableListOf<Soundbank>()
|
||||
sb_split.forEach {
|
||||
val sb = db.Find_Soundbank_Places(it).firstOrNull()
|
||||
if (sb != null) VARPLACESTOTAL.add(sb)
|
||||
}
|
||||
result.append("VARPLACESTOTAL;").append(VARPLACESTOTAL.size).append("@")
|
||||
// VAR SHALAT TOTAL
|
||||
val VARSHALATTOTAL = mutableListOf<Soundbank>()
|
||||
sb_split.forEach {
|
||||
val sb = db.Find_Soundbank_Shalat(it).firstOrNull()
|
||||
if (sb != null) VARSHALATTOTAL.add(sb)
|
||||
}
|
||||
result.append("VARSHALATTOTAL;").append(VARSHALATTOTAL.size).append("@")
|
||||
// VAR SEQUENCE TOTAL
|
||||
val VARSEQUENCETOTAL = mutableListOf<Soundbank>()
|
||||
sb_split.forEach {
|
||||
val sb = db.Find_Soundbank_Sequence(it).firstOrNull()
|
||||
if (sb != null) VARSEQUENCETOTAL.add(sb)
|
||||
}
|
||||
// VAR REASON TOTAL
|
||||
val VARREASONTOTAL = mutableListOf<Soundbank>()
|
||||
sb_split.forEach {
|
||||
val sb = db.Find_Soundbank_Reason(it).firstOrNull()
|
||||
if (sb != null) VARREASONTOTAL.add(sb)
|
||||
}
|
||||
result.append("VARREASONTOTAL;").append(VARREASONTOTAL.size).append("@")
|
||||
// VAR PROCEDURE TOTAL
|
||||
val VARPROCEDURETOTAL = mutableListOf<Soundbank>()
|
||||
sb_split.forEach {
|
||||
val sb = db.Find_Soundbank_Procedure(it).firstOrNull()
|
||||
if (sb != null) VARPROCEDURETOTAL.add(sb)
|
||||
}
|
||||
result.append("VARPROCEDURETOTAL;").append(VARPROCEDURETOTAL.size).append("@")
|
||||
// send to sender
|
||||
cb.accept(result.toString())
|
||||
|
||||
result.clear()
|
||||
//TODO append MSG
|
||||
|
||||
// append VARAP
|
||||
VARAPTOTAL.distinctBy { it.Description }.forEachIndexed { index, soundbank ->
|
||||
result.append("VARAP;").append(index).append(";").append(soundbank.TAG).append(";").append(soundbank.Description).append("@")
|
||||
}
|
||||
// append VARCITY
|
||||
VARCITYTOTAL.distinctBy { it.Description }.forEachIndexed { index, soundbank ->
|
||||
result.append("VARCITY;").append(index).append(";").append(soundbank.TAG).append(";").append(soundbank.Description).append("@")
|
||||
}
|
||||
// append VARPLACES
|
||||
VARPLACESTOTAL.distinctBy { it.Description }.forEachIndexed { index, soundbank ->
|
||||
result.append("VARPLACES;").append(index).append(";").append(soundbank.TAG).append(";").append(soundbank.Description).append("@")
|
||||
}
|
||||
// append VARSHALAT
|
||||
VARSHALATTOTAL.distinctBy { it.Description }.forEachIndexed { index, soundbank ->
|
||||
result.append("VARSHALAT;").append(index).append(";").append(soundbank.TAG).append(";").append(soundbank.Description).append("@")
|
||||
}
|
||||
// append VARSEQUENCE
|
||||
VARSEQUENCETOTAL.distinctBy { it.Description }.forEachIndexed { index, soundbank ->
|
||||
result.append("VARSEQUENCE;").append(index).append(";").append(soundbank.TAG).append(";").append(soundbank.Description).append("@")
|
||||
}
|
||||
// append VARREASON
|
||||
VARREASONTOTAL.distinctBy { it.Description }.forEachIndexed { index, soundbank ->
|
||||
result.append("VARREASON;").append(index).append(";").append(soundbank.TAG).append(";").append(soundbank.Description).append("@")
|
||||
}
|
||||
// append VARPROCEDURE
|
||||
VARPROCEDURETOTAL.distinctBy { it.Description }.forEachIndexed { index, soundbank ->
|
||||
result.append("VARPROCEDURE;").append(index).append(";").append(soundbank.TAG).append(";").append(soundbank.Description).append("@")
|
||||
}
|
||||
// send to sender
|
||||
cb.accept(result.toString())
|
||||
logcb.accept("All variables sent to $key with username $username")
|
||||
|
||||
|
||||
} else logcb.accept("STARTINITIALIZE failed from $key with username $username not found in userDB")
|
||||
} else logcb.accept("STARTINITIALIZE failed from $key with unregistered username $username")
|
||||
} else logcb.accept("STARTINITIALIZE failed from $key with empty username")
|
||||
cb.accept("STARTINITIALIZE;FALSE@")
|
||||
}
|
||||
|
||||
"BROADCASTAND" -> {
|
||||
|
||||
@@ -13,5 +13,6 @@ enum class Category(name: String) {
|
||||
Year("Year"),
|
||||
Birthday("Birthday"),
|
||||
Reason("Reason"),
|
||||
Sequence("Sequence"),
|
||||
Procedure("Procedure");
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package database
|
||||
|
||||
import codes.Somecodes.Companion.ValiDateForLogHtml
|
||||
import codes.Somecodes.Companion.toJsonString
|
||||
import content.Category
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
@@ -2239,6 +2240,63 @@ class MariaDB(
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Find all city soundbank by tag
|
||||
* @param tag The tags to search for
|
||||
* @return a list of Soundbank with Category City and matching tag
|
||||
*/
|
||||
fun Find_Soundbank_City(tag: String) : List<Soundbank>{
|
||||
val lowerTag = tag.lowercase()
|
||||
return soundDB.List
|
||||
.filter{ it.Category== Category.City.name }
|
||||
.filter { it.TAG.lowercase()==lowerTag}
|
||||
}
|
||||
|
||||
fun Find_Soundbank_AirplaneName(tag: String) : List<Soundbank>{
|
||||
val lowerTag = tag.lowercase()
|
||||
return soundDB.List
|
||||
.filter{ it.Category== Category.Airplane_Name.name }
|
||||
.filter { it.TAG.lowercase()==lowerTag}
|
||||
}
|
||||
|
||||
fun Find_Soundbank_Places(tag: String) : List<Soundbank>{
|
||||
val lowerTag = tag.lowercase()
|
||||
return soundDB.List
|
||||
.filter{ it.Category== Category.Places.name }
|
||||
.filter { it.TAG.lowercase()==lowerTag}
|
||||
}
|
||||
|
||||
fun Find_Soundbank_Shalat(tag: String) : List<Soundbank>{
|
||||
val lowerTag = tag.lowercase()
|
||||
return soundDB.List
|
||||
.filter{ it.Category== Category.Shalat.name }
|
||||
.filter { it.TAG.lowercase()==lowerTag}
|
||||
}
|
||||
|
||||
fun Find_Soundbank_Sequence(tag: String) : List<Soundbank>{
|
||||
val lowerTag = tag.lowercase()
|
||||
|
||||
return soundDB.List
|
||||
.filter{ it.Category== Category.Sequence.name }
|
||||
.filter { it.TAG.lowercase()==lowerTag}
|
||||
}
|
||||
|
||||
fun Find_Soundbank_Reason(tag: String) : List<Soundbank>{
|
||||
val lowerTag = tag.lowercase()
|
||||
return soundDB.List
|
||||
.filter{ it.Category== Category.Reason.name }
|
||||
.filter { it.TAG.lowercase()==lowerTag}
|
||||
}
|
||||
|
||||
fun Find_Soundbank_Procedure(tag: String) : List<Soundbank> {
|
||||
val lowerTag = tag.lowercase()
|
||||
return soundDB.List
|
||||
.filter { it.Category == Category.Procedure.name }
|
||||
.filter { it.TAG.lowercase() == lowerTag }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user