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
4b162c54
Commit
4b162c54
authored
Feb 07, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small fixes
parent
98669ca1
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
12 additions
and
62 deletions
+12
-62
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/ContactImpl.kt
...ommonMain/kotlin/net/mamoe/mirai/qqandroid/ContactImpl.kt
+5
-4
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/highway/Codec.kt
...kotlin/net/mamoe/mirai/qqandroid/network/highway/Codec.kt
+1
-1
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/highway/HighwayHelper.kt
...et/mamoe/mirai/qqandroid/network/highway/HighwayHelper.kt
+2
-0
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsAndroid.kt
...Main/kotlin/net/mamoe/mirai/utils/PlatformUtilsAndroid.kt
+0
-22
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/ExternalImage.kt
.../commonMain/kotlin/net.mamoe.mirai/utils/ExternalImage.kt
+1
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/PlatformUtils.kt
.../commonMain/kotlin/net.mamoe.mirai/utils/PlatformUtils.kt
+0
-17
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/ExternalImageJvm.kt
.../jvmMain/kotlin/net/mamoe/mirai/utils/ExternalImageJvm.kt
+3
-3
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt
.../jvmMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt
+0
-14
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/ContactImpl.kt
View file @
4b162c54
...
...
@@ -17,6 +17,7 @@ import net.mamoe.mirai.qqandroid.network.protocol.packet.chat.image.LongConn
import
net.mamoe.mirai.qqandroid.network.protocol.packet.chat.receive.MessageSvc
import
net.mamoe.mirai.qqandroid.utils.toIpV4AddressString
import
net.mamoe.mirai.utils.*
import
net.mamoe.mirai.utils.io.toUHexString
import
kotlin.coroutines.CoroutineContext
import
kotlin.properties.Delegates
...
...
@@ -59,12 +60,12 @@ internal class QQImpl(bot: QQAndroidBot, override val coroutineContext: Coroutin
fileId
=
0
,
fileMd5
=
image
.
md5
,
fileSize
=
image
.
inputSize
.
toInt
(),
fileName
=
image
.
filename
,
fileName
=
image
.
md5
.
toUHexString
(
""
)
+
".jpg"
,
imgOriginal
=
1
,
imgWidth
=
image
.
width
,
imgHeight
=
image
.
height
,
imgType
=
image
.
imageType
,
buType
=
1
buType
=
0
)
).
sendAndExpect
<
LongConn
.
OffPicUp
.
Response
>()
...
...
@@ -81,8 +82,8 @@ internal class QQImpl(bot: QQAndroidBot, override val coroutineContext: Coroutin
HighwayHelper
.
uploadImage
(
client
=
bot
.
client
,
uin
=
bot
.
uin
,
serverIp
=
response
.
serverIp
[
2
].
toIpV4AddressString
(),
serverPort
=
response
.
serverPort
[
2
],
serverIp
=
response
.
serverIp
[
0
].
toIpV4AddressString
(),
serverPort
=
response
.
serverPort
[
0
],
imageInput
=
image
.
input
,
inputSize
=
image
.
inputSize
.
toInt
(),
md5
=
image
.
md5
,
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/highway/Codec.kt
View file @
4b162c54
...
...
@@ -69,7 +69,7 @@ object Highway {
sequenceId
:
Int
,
appId
:
Int
=
537062845
,
dataFlag
:
Int
=
4096
,
commandId
:
Int
=
2
,
commandId
:
Int
,
localId
:
Int
=
2052
,
uKey
:
ByteArray
,
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/highway/HighwayHelper.kt
View file @
4b162c54
...
...
@@ -24,6 +24,8 @@ internal object HighwayHelper {
md5
:
ByteArray
,
commandId
:
Int
// group=2, friend=1
)
{
require
(
md5
.
size
==
16
)
{
"bad md5. Required size=16, got ${md5.size}"
}
require
(
uKey
.
size
==
128
)
{
"bad uKey. Required size=128, got ${uKey.size}"
}
val
socket
=
PlatformSocket
()
socket
.
connect
(
serverIp
,
serverPort
)
socket
.
use
{
...
...
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsAndroid.kt
View file @
4b162c54
...
...
@@ -3,8 +3,6 @@ package net.mamoe.mirai.utils
import
io.ktor.client.HttpClient
import
io.ktor.client.engine.cio.CIO
import
io.ktor.util.KtorExperimentalAPI
import
kotlinx.coroutines.CoroutineDispatcher
import
kotlinx.coroutines.asCoroutineDispatcher
import
kotlinx.io.pool.useInstance
import
net.mamoe.mirai.utils.io.ByteArrayPool
import
java.io.ByteArrayOutputStream
...
...
@@ -13,16 +11,9 @@ import java.io.EOFException
import
java.io.InputStream
import
java.net.InetAddress
import
java.security.MessageDigest
import
java.util.concurrent.Executors
import
java.util.zip.CRC32
import
java.util.zip.Inflater
/**
* 设备名
*/
actual
val
deviceName
:
String
get
()
=
InetAddress
.
getLocalHost
().
hostName
/**
* Ktor HttpClient. 不同平台使用不同引擎.
*/
...
...
@@ -75,16 +66,6 @@ private inline fun InputStream.readInSequence(block: (Int) -> Unit) {
}
}
/**
* CRC32 算法
*/
actual
fun
crc32
(
key
:
ByteArray
):
Int
=
CRC32
().
apply
{
update
(
key
)
}.
value
.
toInt
()
/**
* hostname 解析 ipv4
*/
actual
fun
solveIpAddress
(
hostname
:
String
):
String
=
InetAddress
.
getByName
(
hostname
).
hostAddress
actual
fun
ByteArray
.
unzip
(
offset
:
Int
,
length
:
Int
):
ByteArray
{
this
.
checkOffsetAndLength
(
offset
,
length
)
if
(
length
==
0
)
return
ByteArray
(
0
)
...
...
@@ -104,6 +85,3 @@ actual fun ByteArray.unzip(offset: Int, length: Int): ByteArray {
}
}
actual
fun
newCoroutineDispatcher
(
threadCount
:
Int
):
CoroutineDispatcher
{
return
Executors
.
newFixedThreadPool
(
threadCount
).
asCoroutineDispatcher
()
}
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/ExternalImage.kt
View file @
4b162c54
...
...
@@ -29,7 +29,7 @@ class ExternalImage(
val
filename
:
String
)
{
init
{
check
(
inputSize
in
Int
.
MIN_VALUE
.
toLong
()
..
Int
.
MAX_VALUE
.
toLong
())
{
"file is too big"
}
check
(
inputSize
in
0L
..
Int
.
MAX_VALUE
.
toLong
())
{
"file is too big"
}
}
companion
object
{
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/PlatformUtils.kt
View file @
4b162c54
...
...
@@ -14,16 +14,6 @@ inline val currentTimeMillis: Long get() = GMTDate().timestamp
inline
val
currentTimeSeconds
:
Long
get
()
=
currentTimeMillis
/
1000
/**
* 设备名
*/
expect
val
deviceName
:
String
/**
* CRC32 算法
*/
expect
fun
crc32
(
key
:
ByteArray
):
Int
/**
* 解 zip 压缩
...
...
@@ -39,11 +29,6 @@ expect fun md5(byteArray: ByteArray): ByteArray
inline
fun
md5
(
str
:
String
):
ByteArray
=
md5
(
str
.
toByteArray
())
/**
* hostname 解析 ipv4
*/
expect
fun
solveIpAddress
(
hostname
:
String
):
String
/**
* Localhost 解析
*/
...
...
@@ -54,8 +39,6 @@ expect fun localIpAddress(): String
*/
expect
val
Http
:
HttpClient
expect
fun
newCoroutineDispatcher
(
threadCount
:
Int
):
CoroutineDispatcher
internal
fun
ByteArray
.
checkOffsetAndLength
(
offset
:
Int
,
length
:
Int
)
{
require
(
offset
>=
0
)
{
"offset shouldn't be negative: $offset"
}
require
(
length
>=
0
)
{
"length shouldn't be negative: $length"
}
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/ExternalImageJvm.kt
View file @
4b162c54
...
...
@@ -44,7 +44,7 @@ fun BufferedImage.toExternalImage(formatName: String = "gif"): ExternalImage {
})
}
return
ExternalImage
(
width
,
height
,
digest
.
digest
(),
formatName
,
buffer
,
getRandomString
(
1
0
)
+
"."
+
formatName
)
return
ExternalImage
(
width
,
height
,
digest
.
digest
(),
formatName
,
buffer
,
getRandomString
(
1
6
)
+
"."
+
formatName
)
}
suspend
inline
fun
BufferedImage
.
suspendToExternalImage
():
ExternalImage
=
withContext
(
IO
)
{
toExternalImage
()
}
...
...
@@ -102,8 +102,8 @@ suspend inline fun URL.suspendToExternalImage(): ExternalImage = withContext(IO)
@Throws
(
IOException
::
class
)
fun
InputStream
.
toExternalImage
():
ExternalImage
{
val
file
=
createTempFile
().
apply
{
deleteOnExit
()
}
file
.
outputStream
().
asOutput
().
use
{
this
.
asInput
().
copyTo
(
it
)
file
.
outputStream
().
use
{
this
.
copyTo
(
it
)
}
this
.
close
()
return
file
.
toExternalImage
()
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt
View file @
4b162c54
...
...
@@ -4,21 +4,13 @@ package net.mamoe.mirai.utils
import
io.ktor.client.HttpClient
import
io.ktor.client.engine.cio.CIO
import
kotlinx.coroutines.CoroutineDispatcher
import
kotlinx.coroutines.asCoroutineDispatcher
import
kotlinx.io.pool.useInstance
import
net.mamoe.mirai.utils.io.ByteArrayPool
import
java.io.*
import
java.net.InetAddress
import
java.security.MessageDigest
import
java.util.concurrent.Executors
import
java.util.zip.CRC32
import
java.util.zip.Inflater
actual
val
deviceName
:
String
=
InetAddress
.
getLocalHost
().
hostName
actual
fun
crc32
(
key
:
ByteArray
):
Int
=
CRC32
().
let
{
it
.
update
(
key
);
it
.
value
.
toInt
()
}
actual
fun
md5
(
byteArray
:
ByteArray
):
ByteArray
=
MessageDigest
.
getInstance
(
"MD5"
).
digest
(
byteArray
)
fun
InputStream
.
md5
():
ByteArray
=
this
.
use
{
...
...
@@ -51,8 +43,6 @@ fun DataInput.md5(): ByteArray {
return
digest
.
digest
()
}
actual
fun
solveIpAddress
(
hostname
:
String
):
String
=
InetAddress
.
getByName
(
hostname
).
hostAddress
actual
fun
localIpAddress
():
String
=
InetAddress
.
getLocalHost
().
hostAddress
actual
val
Http
:
HttpClient
get
()
=
HttpClient
(
CIO
)
...
...
@@ -75,7 +65,3 @@ actual fun ByteArray.unzip(offset: Int, length: Int): ByteArray {
return
output
.
toByteArray
()
}
}
actual
fun
newCoroutineDispatcher
(
threadCount
:
Int
):
CoroutineDispatcher
{
return
Executors
.
newFixedThreadPool
(
threadCount
).
asCoroutineDispatcher
()
}
\ No newline at end of file
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