Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
4d1ce5cd
Commit
4d1ce5cd
authored
Feb 15, 2020
by
Him188
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
a40dbaa4
bcf6a2a9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
104 additions
and
44 deletions
+104
-44
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/MiraiHttpAPIServer.kt
...ain/kotlin/net/mamoe/mirai/api/http/MiraiHttpAPIServer.kt
+12
-10
mirai-console/src/main/kotlin/net/mamoe/mirai/MiraiConsole.kt
...i-console/src/main/kotlin/net/mamoe/mirai/MiraiConsole.kt
+1
-2
mirai-console/src/main/kotlin/net/mamoe/mirai/MiraiConsoleUI.kt
...console/src/main/kotlin/net/mamoe/mirai/MiraiConsoleUI.kt
+91
-32
No files found.
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/MiraiHttpAPIServer.kt
View file @
4d1ce5cd
...
@@ -15,15 +15,18 @@ import io.ktor.server.engine.applicationEngineEnvironment
...
@@ -15,15 +15,18 @@ import io.ktor.server.engine.applicationEngineEnvironment
import
io.ktor.server.engine.connector
import
io.ktor.server.engine.connector
import
io.ktor.server.engine.embeddedServer
import
io.ktor.server.engine.embeddedServer
import
io.ktor.util.KtorExperimentalAPI
import
io.ktor.util.KtorExperimentalAPI
import
kotlinx.coroutines.CoroutineExceptionHandler
import
kotlinx.coroutines.CoroutineScope
import
kotlinx.coroutines.launch
import
net.mamoe.mirai.api.http.route.mirai
import
net.mamoe.mirai.api.http.route.mirai
import
net.mamoe.mirai.utils.DefaultLogger
import
net.mamoe.mirai.utils.DefaultLogger
import
org.slf4j.LoggerFactory
import
org.slf4j.helpers.NOPLogger
import
org.slf4j.helpers.NOPLoggerFactory
import
org.slf4j.helpers.NOPLoggerFactory
import
kotlin.coroutines.CoroutineContext
object
MiraiHttpAPIServer
{
object
MiraiHttpAPIServer
:
CoroutineScope
{
private
val
logger
=
DefaultLogger
(
"Mirai HTTP API"
)
private
val
logger
=
DefaultLogger
(
"Mirai HTTP API"
)
override
val
coroutineContext
:
CoroutineContext
=
CoroutineExceptionHandler
{
_
,
throwable
->
logger
.
error
(
throwable
)
}
init
{
init
{
SessionManager
.
authKey
=
generateSessionKey
()
//用于验证的key, 使用和SessionKey相同的方法生成, 但意义不同
SessionManager
.
authKey
=
generateSessionKey
()
//用于验证的key, 使用和SessionKey相同的方法生成, 但意义不同
...
@@ -43,20 +46,19 @@ object MiraiHttpAPIServer {
...
@@ -43,20 +46,19 @@ object MiraiHttpAPIServer {
SessionManager
.
authKey
=
authKey
SessionManager
.
authKey
=
authKey
// TODO: start是无阻塞的,理应获取启动状态后再执行后续代码
// TODO: start是无阻塞的,理应获取启动状态后再执行后续代码
try
{
launch
{
embeddedServer
(
CIO
,
environment
=
applicationEngineEnvironment
{
embeddedServer
(
CIO
,
environment
=
applicationEngineEnvironment
{
this
.
parentCoroutineContext
=
coroutineContext
this
.
log
=
NOPLoggerFactory
().
getLogger
(
"NMYSL"
)
this
.
log
=
NOPLoggerFactory
().
getLogger
(
"NMYSL"
)
this
.
module
(
Application
::
mirai
)
this
.
module
(
Application
::
mirai
)
connector
{
connector
{
this
.
port
=
port
this
.
port
=
port
}
}
}).
start
()
}).
start
(
wait
=
true
)
}
logger
.
info
(
"Http api server is running with authKey: ${SessionManager.authKey}"
)
logger
.
info
(
"Http api server is running with authKey: ${SessionManager.authKey}"
)
callback
?.
invoke
()
callback
?.
invoke
()
}
catch
(
e
:
Exception
)
{
logger
.
error
(
"Http api server launch error"
)
}
}
}
}
}
\ No newline at end of file
mirai-console/src/main/kotlin/net/mamoe/mirai/MiraiConsole.kt
View file @
4d1ce5cd
...
@@ -237,7 +237,7 @@ object MiraiConsole {
...
@@ -237,7 +237,7 @@ object MiraiConsole {
object
CommandListener
{
object
CommandListener
{
fun
start
()
{
fun
start
()
{
thread
{
thread
{
processNextCommandLine
()
//
processNextCommandLine()
}
}
}
}
...
@@ -281,7 +281,6 @@ class MiraiConsoleLoader {
...
@@ -281,7 +281,6 @@ class MiraiConsoleLoader {
companion
object
{
companion
object
{
@JvmStatic
@JvmStatic
fun
main
(
args
:
Array
<
String
>)
{
fun
main
(
args
:
Array
<
String
>)
{
MiraiConsole
.
start
()
MiraiConsole
.
start
()
Runtime
.
getRuntime
().
addShutdownHook
(
thread
(
start
=
false
)
{
Runtime
.
getRuntime
().
addShutdownHook
(
thread
(
start
=
false
)
{
MiraiConsole
.
stop
()
MiraiConsole
.
stop
()
...
...
mirai-console/src/main/kotlin/net/mamoe/mirai/MiraiConsoleUI.kt
View file @
4d1ce5cd
...
@@ -11,11 +11,15 @@ import com.googlecode.lanterna.terminal.Terminal
...
@@ -11,11 +11,15 @@ import com.googlecode.lanterna.terminal.Terminal
import
com.googlecode.lanterna.terminal.TerminalResizeListener
import
com.googlecode.lanterna.terminal.TerminalResizeListener
import
com.googlecode.lanterna.terminal.swing.SwingTerminal
import
com.googlecode.lanterna.terminal.swing.SwingTerminal
import
com.googlecode.lanterna.terminal.swing.SwingTerminalFrame
import
com.googlecode.lanterna.terminal.swing.SwingTerminalFrame
import
net.mamoe.mirai.MiraiConsoleUI.LoggerDrawer.drawLog
import
net.mamoe.mirai.MiraiConsoleUI.LoggerDrawer.redrawLogs
import
net.mamoe.mirai.utils.currentTimeSeconds
import
java.io.OutputStream
import
java.io.OutputStream
import
java.io.PrintStream
import
java.io.PrintStream
import
java.
lang.StringBuilder
import
java.
nio.charset.Charset
import
java.util.*
import
java.util.*
import
kotlin.concurrent.thread
import
kotlin.concurrent.thread
import
kotlin.math.ceil
object
MiraiConsoleUI
{
object
MiraiConsoleUI
{
...
@@ -36,12 +40,17 @@ object MiraiConsoleUI {
...
@@ -36,12 +40,17 @@ object MiraiConsoleUI {
lateinit
var
textGraphics
:
TextGraphics
lateinit
var
textGraphics
:
TextGraphics
var
hasStart
=
false
var
hasStart
=
false
private
lateinit
var
internalPrinter
:
PrintStream
fun
start
()
{
fun
start
()
{
if
(
hasStart
)
{
if
(
hasStart
)
{
return
return
}
}
internalPrinter
=
System
.
out
hasStart
=
true
hasStart
=
true
val
defaultTerminalFactory
=
DefaultTerminalFactory
()
val
defaultTerminalFactory
=
DefaultTerminalFactory
(
internalPrinter
,
System
.
`in`
,
Charset
.
defaultCharset
()
)
try
{
try
{
terminal
=
defaultTerminalFactory
.
createTerminal
()
terminal
=
defaultTerminalFactory
.
createTerminal
()
terminal
.
enterPrivateMode
()
terminal
.
enterPrivateMode
()
...
@@ -64,8 +73,27 @@ object MiraiConsoleUI {
...
@@ -64,8 +73,27 @@ object MiraiConsoleUI {
inited
=
false
inited
=
false
update
()
update
()
redrawCommand
()
redrawCommand
()
redrawLogs
(
log
[
screens
[
currentScreenId
]]
!!
)
})
})
if
(
terminal
!
is
SwingTerminalFrame
)
{
System
.
setOut
(
PrintStream
(
object
:
OutputStream
()
{
var
builder
=
java
.
lang
.
StringBuilder
()
override
fun
write
(
b
:
Int
)
{
with
(
b
.
toChar
())
{
if
(
this
==
'\n'
)
{
pushLog
(
0
,
builder
.
toString
())
builder
=
java
.
lang
.
StringBuilder
()
}
else
{
builder
.
append
(
this
)
}
}
}
}))
}
System
.
setErr
(
System
.
out
)
update
()
update
()
val
charList
=
listOf
(
','
,
'.'
,
'/'
,
'@'
,
'#'
,
'$'
,
'%'
,
'^'
,
'&'
,
'*'
,
'('
,
')'
,
'_'
,
'='
,
'+'
,
'!'
,
' '
)
val
charList
=
listOf
(
','
,
'.'
,
'/'
,
'@'
,
'#'
,
'$'
,
'%'
,
'^'
,
'&'
,
'*'
,
'('
,
')'
,
'_'
,
'='
,
'+'
,
'!'
,
' '
)
...
@@ -197,24 +225,23 @@ object MiraiConsoleUI {
...
@@ -197,24 +225,23 @@ object MiraiConsoleUI {
textGraphics
.
putString
(
width
-
2
-
"Add admins via commands|"
.
length
,
4
,
"Add admins via commands|"
)
textGraphics
.
putString
(
width
-
2
-
"Add admins via commands|"
.
length
,
4
,
"Add admins via commands|"
)
}
}
fun
drawLogs
(
values
:
List
<
String
>)
{
val
width
=
terminal
.
terminalSize
.
columns
-
6
val
heightMin
=
5
var
currentHeight
=
terminal
.
terminalSize
.
rows
-
5
object
LoggerDrawer
{
var
currentHeight
=
6
for
(
index
in
heightMin
until
currentHeight
)
{
fun
drawLog
(
string
:
String
,
flush
:
Boolean
=
true
)
{
clearRows
(
index
)
val
maxHeight
=
terminal
.
terminalSize
.
rows
-
6
val
heightNeed
=
(
string
.
length
/
(
terminal
.
terminalSize
.
columns
-
6
))
+
1
if
(
currentHeight
+
heightNeed
>
maxHeight
)
{
cleanPage
()
}
}
values
.
forEach
{
if
(
currentHeight
>
heightMin
)
{
var
x
=
it
while
(
currentHeight
>
heightMin
)
{
if
(
x
.
isEmpty
()
||
x
.
isBlank
())
break
textGraphics
.
foregroundColor
=
TextColor
.
ANSI
.
GREEN
textGraphics
.
foregroundColor
=
TextColor
.
ANSI
.
GREEN
textGraphics
.
backgroundColor
=
TextColor
.
ANSI
.
DEFAULT
textGraphics
.
backgroundColor
=
TextColor
.
ANSI
.
DEFAULT
val
towrite
=
if
(
x
.
length
>
width
)
{
val
width
=
terminal
.
terminalSize
.
columns
-
6
var
x
=
string
while
(
true
)
{
if
(
x
==
""
)
break
val
toWrite
=
if
(
x
.
length
>
width
)
{
x
.
substring
(
0
,
width
).
also
{
x
.
substring
(
0
,
width
).
also
{
x
=
x
.
substring
(
width
)
x
=
x
.
substring
(
width
)
}
}
...
@@ -223,26 +250,58 @@ object MiraiConsoleUI {
...
@@ -223,26 +250,58 @@ object MiraiConsoleUI {
x
=
""
x
=
""
}
}
}
}
textGraphics
.
putString
(
3
,
currentHeight
,
towrite
,
SGR
.
ITALIC
)
try
{
--
currentHeight
textGraphics
.
putString
(
3
,
currentHeight
,
toWrite
,
SGR
.
ITALIC
)
}
catch
(
ignored
:
Exception
)
{
//
}
++
currentHeight
}
if
(
flush
&&
terminal
is
SwingTerminalFrame
)
{
terminal
.
flush
()
}
}
}
}
fun
cleanPage
()
{
for
(
index
in
6
until
terminal
.
terminalSize
.
rows
-
6
)
{
clearRows
(
index
)
}
}
currentHeight
=
6
}
textGraphics
.
putString
(
3
,
9
,
"AAAAAAAAAAAAAAAAAAAAAAa"
,
SGR
.
ITALIC
)
fun
redrawLogs
(
toDraw
:
List
<
String
>)
{
this
.
cleanPage
()
var
logsToDraw
=
0
var
vara
=
0
toDraw
.
reversed
().
forEach
{
val
heightNeed
=
(
it
.
length
/
(
terminal
.
terminalSize
.
columns
-
6
))
+
1
vara
+=
heightNeed
if
(
currentHeight
+
vara
<
terminal
.
terminalSize
.
rows
-
6
)
{
logsToDraw
++
}
else
{
return
}
}
for
(
index
in
(
toDraw
.
size
-
logsToDraw
)
until
toDraw
.
size
-
1
)
{
drawLog
(
toDraw
[
index
],
false
)
}
if
(
terminal
is
SwingTerminalFrame
)
{
terminal
.
flush
()
terminal
.
flush
()
}
}
}
}
fun
pushLog
(
uin
:
Long
,
str
:
String
)
{
fun
pushLog
(
uin
:
Long
,
str
:
String
)
{
log
[
uin
]
!!
.
push
(
str
)
log
[
uin
]
!!
.
push
(
str
)
if
(
uin
==
screens
[
currentScreenId
])
{
if
(
uin
==
screens
[
currentScreenId
])
{
drawLog
s
(
log
[
screens
[
currentScreenId
]]
!!
)
drawLog
(
str
)
}
}
}
}
var
commandBuilder
=
StringBuilder
()
var
commandBuilder
=
StringBuilder
()
fun
redrawCommand
()
{
fun
redrawCommand
()
{
val
height
=
terminal
.
terminalSize
.
rows
val
height
=
terminal
.
terminalSize
.
rows
val
width
=
terminal
.
terminalSize
.
columns
val
width
=
terminal
.
terminalSize
.
columns
...
@@ -303,7 +362,7 @@ object MiraiConsoleUI {
...
@@ -303,7 +362,7 @@ object MiraiConsoleUI {
drawBotFrame
(
screens
[
currentScreenId
],
0
)
drawBotFrame
(
screens
[
currentScreenId
],
0
)
}
}
}
}
terminal
.
flush
(
)
redrawLogs
(
log
[
screens
[
currentScreenId
]]
!!
)
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment