Commit 30/09/2025
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package commandServer
|
package commandServer
|
||||||
|
|
||||||
import codes.Somecodes.Companion.ValidString
|
import codes.Somecodes.Companion.ValidString
|
||||||
|
import db
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
@@ -20,6 +21,7 @@ class TCP_Android_Command_Server {
|
|||||||
private var job: Job? = null
|
private var job: Job? = null
|
||||||
private val socketMap = mutableMapOf<String, Socket>()
|
private val socketMap = mutableMapOf<String, Socket>()
|
||||||
lateinit var logcb: Consumer<String>
|
lateinit var logcb: Consumer<String>
|
||||||
|
private val listUserLogin = mutableListOf<userLogin>()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start TCP Command Server
|
* Start TCP Command Server
|
||||||
@@ -54,7 +56,7 @@ class TCP_Android_Command_Server {
|
|||||||
val str = String(bb, 4, bb.size - 4)
|
val str = String(bb, 4, bb.size - 4)
|
||||||
str.split("@").map { it.trim() }.filter { ValidString(it) }
|
str.split("@").map { it.trim() }.filter { ValidString(it) }
|
||||||
.map { it.uppercase() }.forEach {
|
.map { it.uppercase() }.forEach {
|
||||||
process_command(it) { reply ->
|
process_command(key,it) { reply ->
|
||||||
try {
|
try {
|
||||||
socket.getOutputStream().write(String_to_Byte_Android(reply))
|
socket.getOutputStream().write(String_to_Byte_Android(reply))
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -106,16 +108,31 @@ class TCP_Android_Command_Server {
|
|||||||
return ByteArray(0)
|
return ByteArray(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun process_command(cmd: String, cb: Consumer<String>) {
|
private fun process_command(key: String, cmd: String, cb: Consumer<String>) {
|
||||||
Logger.info { "Command from Android: $cmd" }
|
Logger.info { "Command from $key : $cmd" }
|
||||||
val parts = cmd.split(";").map { it.trim() }.filter { it.isNotBlank() }.map { it.uppercase() }
|
val parts = cmd.split(";").map { it.trim() }.filter { it.isNotBlank() }.map { it.uppercase() }
|
||||||
when (parts[0]) {
|
when (parts[0]) {
|
||||||
"GETLOGIN" -> {
|
"GETLOGIN" -> {
|
||||||
val username = parts.getOrElse(1) { "" }
|
val username = parts.getOrElse(1) { "" }
|
||||||
val password = parts.getOrElse(2) { "" }
|
val password = parts.getOrElse(2) { "" }
|
||||||
if (ValidString(username) && ValidString(password)) {
|
if (ValidString(username) && ValidString(password)) {
|
||||||
//TODO handle login here
|
if (db.userDB.List.any{it.username==username && it.password==password}) {
|
||||||
} else cb.accept("LOGIN;FALSE@")
|
cb.accept("LOGIN;TRUE@")
|
||||||
|
val existing = listUserLogin.find { it.ip == key}
|
||||||
|
if (existing!=null){
|
||||||
|
existing.username = username
|
||||||
|
} else{
|
||||||
|
listUserLogin.add(userLogin(key, username))
|
||||||
|
}
|
||||||
|
logcb.accept("Android Login success from $key as $username")
|
||||||
|
} else {
|
||||||
|
logcb.accept("Android Login failed from $key as $username")
|
||||||
|
cb.accept("LOGIN;FALSE@")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logcb.accept("Android Login failed from $key with empty username or password")
|
||||||
|
cb.accept("LOGIN;FALSE@")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
"PCMFILE_START" -> {
|
"PCMFILE_START" -> {
|
||||||
|
|||||||
3
src/commandServer/userLogin.kt
Normal file
3
src/commandServer/userLogin.kt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
package commandServer
|
||||||
|
|
||||||
|
data class userLogin(val ip : String, var username: String)
|
||||||
Reference in New Issue
Block a user