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
1dee5fe0
Commit
1dee5fe0
authored
Jan 17, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
ccf85456
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
17 deletions
+14
-17
mirai-api-http/src/main/kotlin/net.mamoe.mirai.api.http/Session.kt
...-http/src/main/kotlin/net.mamoe.mirai.api.http/Session.kt
+14
-17
No files found.
mirai-api-http/src/main/kotlin/net.mamoe.mirai.api.http/Session.kt
View file @
1dee5fe0
package
net.mamoe.mirai.api.http
package
net.mamoe.mirai.api.http
import
kotlinx.coroutines.CompletableJob
import
kotlinx.coroutines.CoroutineScope
import
kotlinx.coroutines.CoroutineScope
import
kotlinx.coroutines.SupervisorJob
import
kotlinx.coroutines.SupervisorJob
import
java.lang.StringBuilder
import
kotlin.coroutines.CoroutineContext
import
kotlin.coroutines.CoroutineContext
import
kotlin.coroutines.EmptyCoroutineContext
import
kotlin.coroutines.EmptyCoroutineContext
tailrec
fun
generateSessionKey
():
String
{
tailrec
fun
generateSessionKey
():
String
{
fun
generateRandomSessionKey
():
String
{
fun
generateRandomSessionKey
():
String
{
val
all
=
"QWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnm"
val
all
=
"QWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnm"
return
buildString
(
capacity
=
8
)
{
return
buildString
(
capacity
=
8
)
{
...
@@ -18,7 +16,7 @@ tailrec fun generateSessionKey():String{
...
@@ -18,7 +16,7 @@ tailrec fun generateSessionKey():String{
}
}
val
key
=
generateRandomSessionKey
()
val
key
=
generateRandomSessionKey
()
if
(!
SessionManager
.
allSession
.
containsKey
(
key
))
{
if
(!
SessionManager
.
allSession
.
containsKey
(
key
))
{
return
key
return
key
}
}
...
@@ -27,43 +25,42 @@ tailrec fun generateSessionKey():String{
...
@@ -27,43 +25,42 @@ tailrec fun generateSessionKey():String{
object
SessionManager
{
object
SessionManager
{
val
allSession
:
MutableMap
<
String
,
Session
>
=
mutableMapOf
()
val
allSession
:
MutableMap
<
String
,
Session
>
=
mutableMapOf
()
fun
createTempSession
():
TempSession
=
TempSession
(
EmptyCoroutineContext
).
also
{
allSession
[
it
.
key
]
=
it
}
fun
createTempSession
():
TempSession
=
TempSession
(
EmptyCoroutineContext
).
also
{
allSession
[
it
.
key
]
=
it
}
fun
closeSession
(
sessionKey
:
String
)
=
allSession
.
remove
(
sessionKey
)
?.
also
{
it
.
close
()
}
fun
closeSession
(
sessionKey
:
String
)
=
allSession
.
remove
(
sessionKey
)
?.
also
{
it
.
close
()
}
fun
closeSession
(
session
:
Session
)
=
closeSession
(
session
.
key
)
fun
closeSession
(
session
:
Session
)
=
closeSession
(
session
.
key
)
}
}
/**
/**
* @author NaturalHG
* @author NaturalHG
* 这个用于管理不同Client与Mirai HTTP的会话
* 这个用于管理不同Client与Mirai HTTP的会话
*/
*/
abstract
class
Session
internal
constructor
(
abstract
class
Session
internal
constructor
(
coroutineContext
:
CoroutineContext
)
:
CoroutineScope
{
private
val
supervisorJob
=
SupervisorJob
()
final
override
val
coroutineContext
:
CoroutineContext
=
supervisorJob
+
coroutineContext
):
CoroutineScope
{
val
key
:
String
=
generateSessionKey
()
private
val
sessionJob
=
SupervisorJob
()
val
key
:
String
=
generateSessionKey
()
internal
fun
close
(){
internal
fun
close
()
{
s
ession
Job
.
cancel
()
s
upervisor
Job
.
cancel
()
}
}
}
}
/**
/**
* 任何新链接建立后分配一个[TempSession]
* 任何新链接建立后分配一个[TempSession]
*
*
* TempSession在建立180s内没有转变为[AuthedSession]应被清除
* TempSession在建立180s内没有转变为[AuthedSession]应被清除
*/
*/
class
TempSession
internal
constructor
(
override
val
coroutineContext
:
CoroutineContext
)
:
Session
(
)
{
class
TempSession
internal
constructor
(
coroutineContext
:
CoroutineContext
)
:
Session
(
coroutineContext
)
{
}
}
...
@@ -71,7 +68,7 @@ class TempSession internal constructor(override val coroutineContext: CoroutineC
...
@@ -71,7 +68,7 @@ class TempSession internal constructor(override val coroutineContext: CoroutineC
* 任何[TempSession]认证后转化为一个[AuthedSession]
* 任何[TempSession]认证后转化为一个[AuthedSession]
* 在这一步[AuthedSession]应该已经有assigned的bot
* 在这一步[AuthedSession]应该已经有assigned的bot
*/
*/
class
AuthedSession
internal
constructor
(
botNumber
:
Int
,
override
val
coroutineContext
:
CoroutineContext
):
Session
()
{
class
AuthedSession
internal
constructor
(
botNumber
:
Int
,
coroutineContext
:
CoroutineContext
)
:
Session
(
coroutineContext
)
{
}
}
...
...
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