Port Android server runtime to GaCy Go
This commit is contained in:
1 parent
92a4b4f545
commit
3c1186c781
20 files changed
+830
-798
No files matched your search
@@ -10,7 +10,9 @@ import java.util.Locale
|
||||
object LogBuffer {
|
||||
|
||||
private const val MAX_LOG_LINES = 500
|
||||
private const val MAX_DIAGNOSTIC_LINES = 100
|
||||
private val timeFormat = SimpleDateFormat("HH:mm:ss", Locale.getDefault())
|
||||
private val diagnostics = ArrayDeque<String>()
|
||||
|
||||
private val _logs = MutableStateFlow<List<String>>(emptyList())
|
||||
val logs: StateFlow<List<String>> = _logs.asStateFlow()
|
||||
@@ -19,6 +21,10 @@ object LogBuffer {
|
||||
fun append(message: String) {
|
||||
val timestamp = timeFormat.format(Date())
|
||||
val formatted = "[$timestamp] $message"
|
||||
if (isDiagnostic(message)) {
|
||||
diagnostics.addLast(formatted)
|
||||
if (diagnostics.size > MAX_DIAGNOSTIC_LINES) diagnostics.removeFirst()
|
||||
}
|
||||
val current = _logs.value.toMutableList()
|
||||
current.add(formatted)
|
||||
if (current.size > MAX_LOG_LINES) {
|
||||
@@ -30,9 +36,18 @@ object LogBuffer {
|
||||
@Synchronized
|
||||
fun clear() {
|
||||
_logs.value = emptyList()
|
||||
diagnostics.clear()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun getAllText(): String {
|
||||
return _logs.value.joinToString("\n")
|
||||
val recent = _logs.value
|
||||
val olderDiagnostics = diagnostics.filterNot { it in recent }
|
||||
return (olderDiagnostics + recent).joinToString("\n")
|
||||
}
|
||||
|
||||
private fun isDiagnostic(message: String): Boolean =
|
||||
"[gateway]" in message || "[DISPATCH]" in message ||
|
||||
"[KCP] handshake rejected:" in message || "[KCP] packet rejected:" in message ||
|
||||
"New connection from addr:" in message || "[Server error]" in message
|
||||
}
|
||||
Reference in new issue
Block a user