mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-08 17:20:11 +08:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
712d8cac8b
@ -3,8 +3,14 @@ package net.mamoe.mirai
|
||||
import net.mamoe.mirai.contact.Group
|
||||
import net.mamoe.mirai.contact.QQ
|
||||
import net.mamoe.mirai.network.protocol.tim.packet.ClientPacket
|
||||
import net.mamoe.mirai.network.protocol.tim.packet.ServerPacket
|
||||
import net.mamoe.mirai.network.protocol.tim.packet.goto
|
||||
import net.mamoe.mirai.network.protocol.tim.packet.login.LoginState
|
||||
import net.mamoe.mirai.utils.ContactList
|
||||
import net.mamoe.mirai.utils.LoggerTextFormat
|
||||
import net.mamoe.mirai.utils.toUHexString
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* The mirror of functions in inner classes of [Bot]
|
||||
@ -30,4 +36,38 @@ suspend fun Bot.sendPacket(packet: ClientPacket) = this.network.socket.sendPacke
|
||||
suspend fun Bot.login(): LoginState = this.network.login()
|
||||
|
||||
//BotAccount
|
||||
val Bot.qqNumber: Long get() = this.account.qqNumber
|
||||
val Bot.qqNumber: Long get() = this.account.qqNumber
|
||||
|
||||
|
||||
//logging
|
||||
fun Bot.log(o: Any?) = info(o)
|
||||
|
||||
fun Bot.println(o: Any?) = info(o)
|
||||
fun Bot.info(o: Any?) = print(this, o.toString(), LoggerTextFormat.RESET)
|
||||
|
||||
fun Bot.error(o: Any?) = print(this, o.toString(), LoggerTextFormat.RED)
|
||||
|
||||
fun Bot.notice(o: Any?) = print(this, o.toString(), LoggerTextFormat.LIGHT_BLUE)
|
||||
|
||||
fun Bot.purple(o: Any?) = print(this, o.toString(), LoggerTextFormat.PURPLE)
|
||||
|
||||
fun Bot.cyan(o: Any?) = print(this, o.toString(), LoggerTextFormat.LIGHT_CYAN)
|
||||
fun Bot.green(o: Any?) = print(this, o.toString(), LoggerTextFormat.GREEN)
|
||||
|
||||
fun Bot.debug(o: Any?) = print(this, o.toString(), LoggerTextFormat.YELLOW)
|
||||
|
||||
fun Bot.debugPacket(packet: ServerPacket) {
|
||||
debug("Packet=$packet")
|
||||
debug("Packet size=" + packet.input.goto(0).readAllBytes().size)
|
||||
debug("Packet data=" + packet.input.goto(0).readAllBytes().toUHexString())
|
||||
}
|
||||
|
||||
private fun print(bot: Bot, value: String?, color: LoggerTextFormat = LoggerTextFormat.WHITE) {
|
||||
val s = SimpleDateFormat("MM-dd HH:mm:ss").format(Date())
|
||||
kotlin.io.println("$color[Mirai] $s #R${bot.id}: $value")
|
||||
}
|
||||
|
||||
private fun print(value: String?, color: LoggerTextFormat = LoggerTextFormat.WHITE) {
|
||||
val s = SimpleDateFormat("MM-dd HH:mm:ss").format(Date())
|
||||
kotlin.io.println("$color[Mirai] $s : $value")
|
||||
}
|
@ -3,7 +3,7 @@ package net.mamoe.mirai.network.protocol.tim
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.*
|
||||
import net.mamoe.mirai.event.ListeningStatus
|
||||
import net.mamoe.mirai.event.broadcast
|
||||
import net.mamoe.mirai.event.events.BeforePacketSendEvent
|
||||
@ -56,7 +56,7 @@ internal class TIMBotNetworkHandler(private val bot: Bot) : BotNetworkHandler {
|
||||
}
|
||||
|
||||
//嵌套进 login 会导致 kotlin internal CompilationException
|
||||
suspend fun loginInternal(ipQueue: LinkedList<String>): LoginState {
|
||||
private suspend fun loginInternal(ipQueue: LinkedList<String>): LoginState {
|
||||
this.socket.close()
|
||||
val ip = ipQueue.poll() ?: return LoginState.UNKNOWN//所有服务器均返回 UNKNOWN
|
||||
|
||||
|
@ -50,8 +50,6 @@ object TIMProtocol {
|
||||
const val constantData2 = "00 00 04 53 00 00 00 01 00 00 15 85 "
|
||||
|
||||
/**
|
||||
* 0825 key
|
||||
*
|
||||
* Touch 发出时写入, 并用于加密, 接受 touch response 时解密.
|
||||
*/
|
||||
const val touchKey = "A4 F1 91 88 C9 82 14 99 0C 9E 56 55 91 23 C8 3D"//16
|
||||
@ -62,12 +60,12 @@ object TIMProtocol {
|
||||
const val redirectionKey = "A8 F2 14 5F 58 12 60 AF 07 63 97 D6 76 B2 1A 3B"//16
|
||||
|
||||
/**
|
||||
*
|
||||
* 并非常量. 设置为常量是为了让 [shareKey] 为常量
|
||||
*/
|
||||
const val publicKey = "02 6D 28 41 D2 A5 6F D2 FC 3E 2A 1F 03 75 DE 6E 28 8F A8 19 3E 5F 16 49 D3"//25
|
||||
|
||||
/**
|
||||
* fix_0836_1
|
||||
* 并非常量. 设置为常量是为了让 [shareKey] 为常量
|
||||
*
|
||||
* LoginResend 和 PasswordSubmission 时写入, 但随后都使用 shareKey 加密, 收到回复也是用的 share key
|
||||
*/
|
||||
@ -79,7 +77,7 @@ object TIMProtocol {
|
||||
}
|
||||
|
||||
/**
|
||||
* 没有任何地方写入了这个 key
|
||||
* 并非常量. 是 publicKey 与 key0836 的算法计算结果
|
||||
*/
|
||||
//const val shareKey = "5B 6C 91 55 D9 92 F5 A7 99 85 37 76 3D 0F 08 B7"//16
|
||||
const val shareKey = "1A E9 7F 7D C9 73 75 98 AC 02 E0 80 5F A9 C6 AF"//16//original
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.mamoe.mirai.network.protocol.tim.packet
|
||||
|
||||
import net.mamoe.mirai.network.protocol.tim.TIMProtocol
|
||||
import net.mamoe.mirai.utils.TEA
|
||||
import java.io.DataInputStream
|
||||
|
||||
/**
|
||||
@ -39,10 +38,6 @@ class ServerAccountInfoResponsePacket(input: DataInputStream) : ServerPacket(inp
|
||||
|
||||
@PacketId("00 5C")
|
||||
class Encrypted(inputStream: DataInputStream) : ServerPacket(inputStream) {
|
||||
fun decrypt(sessionKey: ByteArray): ServerAccountInfoResponsePacket {
|
||||
this.input goto 14
|
||||
val data = this.input.readAllBytes().let { it.copyOfRange(0, it.size - 1) }
|
||||
return ServerAccountInfoResponsePacket(TEA.decrypt(data, sessionKey).dataInputStream()).setId(this.idHex)
|
||||
}
|
||||
fun decrypt(sessionKey: ByteArray): ServerAccountInfoResponsePacket = ServerAccountInfoResponsePacket(this.decryptBy(sessionKey)).setId(this.idHex)
|
||||
}
|
||||
}
|
@ -179,6 +179,8 @@ abstract class ServerPacket(val input: DataInputStream) : Packet {
|
||||
input.goto(14)
|
||||
return TEA.decrypt(input.readAllBytes().cutTail(1), key)
|
||||
}
|
||||
|
||||
fun decryptAsByteArray(keyHex: String): ByteArray = this.decryptAsByteArray(keyHex.hexToBytes())
|
||||
}
|
||||
|
||||
|
||||
@ -243,7 +245,7 @@ fun ByteArray.dataInputStream(): DataInputStream = DataInputStream(this.inputStr
|
||||
/**
|
||||
* Reset and skip(position)
|
||||
*/
|
||||
infix fun <N : Number> DataInputStream.goto(position: N): DataInputStream {
|
||||
fun <N : Number> DataInputStream.goto(position: N): DataInputStream {
|
||||
this.reset()
|
||||
this.skip(position.toLong())
|
||||
return this
|
||||
|
@ -2,7 +2,6 @@ package net.mamoe.mirai.network.protocol.tim.packet.login
|
||||
|
||||
import net.mamoe.mirai.network.protocol.tim.TIMProtocol
|
||||
import net.mamoe.mirai.network.protocol.tim.packet.*
|
||||
import net.mamoe.mirai.utils.TEA
|
||||
import java.io.DataInputStream
|
||||
|
||||
|
||||
@ -58,10 +57,6 @@ class ServerSKeyResponsePacket(input: DataInputStream) : ServerPacket(input) {
|
||||
|
||||
|
||||
class Encrypted(inputStream: DataInputStream) : ServerPacket(inputStream) {
|
||||
fun decrypt(sessionKey: ByteArray): ServerSKeyResponsePacket {
|
||||
this.input goto 14
|
||||
val data = this.input.readAllBytes().let { it.copyOfRange(0, it.size - 1) }
|
||||
return ServerSKeyResponsePacket(TEA.decrypt(data, sessionKey).dataInputStream()).setId(this.idHex)
|
||||
}
|
||||
fun decrypt(sessionKey: ByteArray): ServerSKeyResponsePacket = ServerSKeyResponsePacket(this.decryptBy(sessionKey)).setId(this.idHex)
|
||||
}
|
||||
}
|
@ -55,7 +55,7 @@ class ServerLoginResponseSuccessPacket(input: DataInputStream) : ServerPacket(in
|
||||
class Encrypted(input: DataInputStream) : ServerPacket(input) {
|
||||
|
||||
fun decrypt(privateKey: ByteArray): ServerLoginResponseSuccessPacket {
|
||||
input goto 14
|
||||
input.goto(14)
|
||||
return ServerLoginResponseSuccessPacket(this.decryptBy(TIMProtocol.shareKey, privateKey)).setId(this.idHex)
|
||||
}
|
||||
}
|
||||
|
@ -40,16 +40,14 @@ class ServerLoginResponseVerificationCodeInitPacket(input: DataInputStream, priv
|
||||
|
||||
}
|
||||
|
||||
fun decrypt(): ServerLoginResponseVerificationCodeInitPacket {
|
||||
this.input goto 14
|
||||
val data = this.decryptBy(TIMProtocol.shareKey).goto(0).readAllBytes()
|
||||
return ServerLoginResponseVerificationCodeInitPacket(data.dataInputStream(), data.size).setId(this.idHex)
|
||||
fun decrypt(): ServerLoginResponseVerificationCodeInitPacket = this.decryptAsByteArray(TIMProtocol.shareKey).let {
|
||||
ServerLoginResponseVerificationCodeInitPacket(it.dataInputStream(), it.size).setId(this.idHex)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val data = "FB 01 04 03 33 00 01 00 BA 02 03 2C 13 00 05 01 00 00 01 23 00 38 D5 01 05 8B 67 4D 52 5A FA 92 DB 99 18 D4 F0 72 03 E0 17 71 7C 8A 45 74 1F C3 2D F8 61 96 0D 93 0D 8C 51 95 70 F8 F9 CB B9 2D 5D BC 4F 5D 89 5F E7 59 8C E4 E5 A2 04 56 02 BC 89 50 4E 47 0D 0A 1A 0A 00 00 00 0D 49 48 44 52 00 00 00 82 00 00 00 35 08 03 00 00 00 BA 12 C3 02 00 00 00 04 67 41 4D 41 00 00 B1 8F 0B FC 61 05 00 00 00 01 73 52 47 42 00 AE CE 1C E9 00 00 00 45 50 4C 54 45 FE F6 ED E2 F1 DF F3 FF F2 11 77 48 FE FE F3 F1 F9 EA D7 FD E7 F8 F9 EC FC EF E7 E8 FF EE 2D 69 48 2A 8A 5D 29 7A 52 F0 ED E1 A9 C7 B1 65 96 79 AB E0 C2 C3 F0 D5 42 7D 5C 4A 99 72 89 AA 93 51 73 5C 6E BA 94 42 BD 7A 0B 00 00 09 C5 49 44 41 54 58 C3 AC 99 8B 76 AB 3A 12 44 91 D0 1B 10 08 04 FF FF A9 B3 5B 60 C7 AF 38 77 EE 0C EB C4 76 6C 07 95 BA AB AB AB 75 BA EE 1F 5D DE CB 63 08 C1 C7 A8 AD BC B6 31 46 6B 3B A3 79 94 E7 F3 63 79 E4 D9 98 89 37 7D F7 FF BB 3C 10 82 6F B7 F7 2A B6 5B 07 EF B5 16 60 DE 1B 63 3A 1F 7E BE 6D 0C 50 EC 09 E1 FE 76 B8 3F FC 6B 0C 1D 5B 37 1F 3E E1 AE 61 9A D8 B6 07 93 B7 56 4D 66 22 06 9D FC EE 5F BF F9 3F 81 90 BB 99 F3 49 E2 1D DA 43 38 13 44 14 8C 9D B4 8E E7 65 40 11 E4 BB FE 8C 5B 78 41 F1 AF 01 48 2E 08 6D 8B AD F1 BA 05 F9 C4 E0 25 E6 31 BA EB 2A 90 C3 74 26 FC 1E 80 CF 14 91 44 7F FC 39 FF D4 37 10 82 C0 B3 B0 67 BF 2E 5E 5B F4 46 E5 3A 5F D7 BE A6 54 17 2D 7C 0D D7 DA E1 7E 93 C7 E5 DB 9E 6E 9F FD A3 14 9C 7F 23 97 55 FA DC 6F 74 8A CC 04 49 03 3F DE 4E 5C 4A 95 9C 53 8D 7A EA 82 F9 10 77 7F EE E5 43 28 C2 9F 00 BA 5B C0 59 A4 CE DB BA AE DB BC 14 D5 2A 82 A5 83 E0 30 92 19 A8 99 36 A7 15 7C BC DF F6 BE D7 86 C0 7F C9 C5 ED 93 C7 1F B9 E0 56 CB AC 61 F5 5D 2E 00 F0 93 D2 5A 9D B6 B0 3F 4B 4D 5C B9 0F C1 EE 29 46 65 4E 40 46 E2 E4 1B 91 C3 A5 2E FE D3 7A 3C 84 0B E3 F3 E2 57 16 2F 08 B9 E6 5A 73 29 65 29 4E B9 25 CF 6B 9A 97 48 20 B2 35 46 1B 6D AD D6 9A 57 69 45 B2 1A 00 90 05 51 8D C7 24 F8 1B B9 FE A6 41 B8 83 6C 59 05 84 9F 44 0F 85 05 9A 97 5A 97 BC A6 6D 81 FE 59 DE 2F 4B 5E E4 DF B2 A4 19 AA 06 D9 FE F9 33 4D 7E 6A 40 FC 97 34 BF 84 E4 81 81 ED E9 DC 85 32 56 47 E5 A4 F0 2D 6F 4D 2A BA 65 4B 73 89 B6 58 5E D7 35 8D 69 E4 4A 6B 76 50 C1 5C 3A D9 59 11 CF 37 99 FA 48 88 70 7F F4 9F 22 12 F2 24 91 3E 2B BF 28 A5 34 68 C0 50 A3 55 DD A4 E3 9C 6E 85 99 95 B6 24 2E 18 D9 3C 5C B1 4D AA 2F 08 E1 75 F1 F0 6B 49 FC BC E3 8D 00 01 00 28 42 E6 18 57 D4 B1 4D AE 51 27 D5 EF A2 38 91 39 15 37 6C 5A FE 75 93 49 DB FC 57 3C 12 3F 26 D9 16 1D 83 45 8B 78 39 D8 01 15 00 10 F6 F0 50 03 74 BB 18 91 D3 55 8D 7F BB 53 15 7A".hexToUBytes().toByteArray();
|
||||
val data = "FB 01 04 03 33 00 01 00 BA 02 03 2C 13 00 05 01 00 00 01 23 00 38 D5 01 05 8B 67 4D 52 5A FA 92 DB 99 18 D4 F0 72 03 E0 17 71 7C 8A 45 74 1F C3 2D F8 61 96 0D 93 0D 8C 51 95 70 F8 F9 CB B9 2D 5D BC 4F 5D 89 5F E7 59 8C E4 E5 A2 04 56 02 BC 89 50 4E 47 0D 0A 1A 0A 00 00 00 0D 49 48 44 52 00 00 00 82 00 00 00 35 08 03 00 00 00 BA 12 C3 02 00 00 00 04 67 41 4D 41 00 00 B1 8F 0B FC 61 05 00 00 00 01 73 52 47 42 00 AE CE 1C E9 00 00 00 45 50 4C 54 45 FE F6 ED E2 F1 DF F3 FF F2 11 77 48 FE FE F3 F1 F9 EA D7 FD E7 F8 F9 EC FC EF E7 E8 FF EE 2D 69 48 2A 8A 5D 29 7A 52 F0 ED E1 A9 C7 B1 65 96 79 AB E0 C2 C3 F0 D5 42 7D 5C 4A 99 72 89 AA 93 51 73 5C 6E BA 94 42 BD 7A 0B 00 00 09 C5 49 44 41 54 58 C3 AC 99 8B 76 AB 3A 12 44 91 D0 1B 10 08 04 FF FF A9 B3 5B 60 C7 AF 38 77 EE 0C EB C4 76 6C 07 95 BA AB AB AB 75 BA EE 1F 5D DE CB 63 08 C1 C7 A8 AD BC B6 31 46 6B 3B A3 79 94 E7 F3 63 79 E4 D9 98 89 37 7D F7 FF BB 3C 10 82 6F B7 F7 2A B6 5B 07 EF B5 16 60 DE 1B 63 3A 1F 7E BE 6D 0C 50 EC 09 E1 FE 76 B8 3F FC 6B 0C 1D 5B 37 1F 3E E1 AE 61 9A D8 B6 07 93 B7 56 4D 66 22 06 9D FC EE 5F BF F9 3F 81 90 BB 99 F3 49 E2 1D DA 43 38 13 44 14 8C 9D B4 8E E7 65 40 11 E4 BB FE 8C 5B 78 41 F1 AF 01 48 2E 08 6D 8B AD F1 BA 05 F9 C4 E0 25 E6 31 BA EB 2A 90 C3 74 26 FC 1E 80 CF 14 91 44 7F FC 39 FF D4 37 10 82 C0 B3 B0 67 BF 2E 5E 5B F4 46 E5 3A 5F D7 BE A6 54 17 2D 7C 0D D7 DA E1 7E 93 C7 E5 DB 9E 6E 9F FD A3 14 9C 7F 23 97 55 FA DC 6F 74 8A CC 04 49 03 3F DE 4E 5C 4A 95 9C 53 8D 7A EA 82 F9 10 77 7F EE E5 43 28 C2 9F 00 BA 5B C0 59 A4 CE DB BA AE DB BC 14 D5 2A 82 A5 83 E0 30 92 19 A8 99 36 A7 15 7C BC DF F6 BE D7 86 C0 7F C9 C5 ED 93 C7 1F B9 E0 56 CB AC 61 F5 5D 2E 00 F0 93 D2 5A 9D B6 B0 3F 4B 4D 5C B9 0F C1 EE 29 46 65 4E 40 46 E2 E4 1B 91 C3 A5 2E FE D3 7A 3C 84 0B E3 F3 E2 57 16 2F 08 B9 E6 5A 73 29 65 29 4E B9 25 CF 6B 9A 97 48 20 B2 35 46 1B 6D AD D6 9A 57 69 45 B2 1A 00 90 05 51 8D C7 24 F8 1B B9 FE A6 41 B8 83 6C 59 05 84 9F 44 0F 85 05 9A 97 5A 97 BC A6 6D 81 FE 59 DE 2F 4B 5E E4 DF B2 A4 19 AA 06 D9 FE F9 33 4D 7E 6A 40 FC 97 34 BF 84 E4 81 81 ED E9 DC 85 32 56 47 E5 A4 F0 2D 6F 4D 2A BA 65 4B 73 89 B6 58 5E D7 35 8D 69 E4 4A 6B 76 50 C1 5C 3A D9 59 11 CF 37 99 FA 48 88 70 7F F4 9F 22 12 F2 24 91 3E 2B BF 28 A5 34 68 C0 50 A3 55 DD A4 E3 9C 6E 85 99 95 B6 24 2E 18 D9 3C 5C B1 4D AA 2F 08 E1 75 F1 F0 6B 49 FC BC E3 8D 00 01 00 28 42 E6 18 57 D4 B1 4D AE 51 27 D5 EF A2 38 91 39 15 37 6C 5A FE 75 93 49 DB FC 57 3C 12 3F 26 D9 16 1D 83 45 8B 78 39 D8 01 15 00 10 F6 F0 50 03 74 BB 18 91 D3 55 8D 7F BB 53 15 7A".hexToUBytes().toByteArray()
|
||||
ServerLoginResponseVerificationCodeInitPacket(
|
||||
data.dataInputStream(),
|
||||
data.size
|
||||
|
@ -2,7 +2,6 @@ package net.mamoe.mirai.network.protocol.tim.packet.login
|
||||
|
||||
import net.mamoe.mirai.network.protocol.tim.TIMProtocol
|
||||
import net.mamoe.mirai.network.protocol.tim.packet.*
|
||||
import net.mamoe.mirai.utils.TEA
|
||||
import net.mamoe.mirai.utils.dataEncode
|
||||
import java.io.DataInputStream
|
||||
import java.net.InetAddress
|
||||
@ -74,7 +73,7 @@ class ServerSessionKeyResponsePacket(inputStream: DataInputStream, private val d
|
||||
override fun decode() {
|
||||
when (dataLength) {
|
||||
407 -> {
|
||||
input goto 25
|
||||
input.goto(25)
|
||||
sessionKey = input.readNBytes(16)
|
||||
}
|
||||
|
||||
@ -106,10 +105,8 @@ class ServerSessionKeyResponsePacket(inputStream: DataInputStream, private val d
|
||||
}
|
||||
|
||||
class Encrypted(inputStream: DataInputStream) : ServerPacket(inputStream) {
|
||||
fun decrypt(sessionResponseDecryptionKey: ByteArray): ServerSessionKeyResponsePacket {
|
||||
this.input goto 14
|
||||
val data = this.input.readAllBytes().let { it.copyOfRange(0, it.size - 1) }
|
||||
return ServerSessionKeyResponsePacket(TEA.decrypt(data, sessionResponseDecryptionKey).dataInputStream(), data.size).setId(this.idHex)
|
||||
fun decrypt(sessionResponseDecryptionKey: ByteArray): ServerSessionKeyResponsePacket = this.decryptAsByteArray(sessionResponseDecryptionKey).let {
|
||||
ServerSessionKeyResponsePacket(it.dataInputStream(), it.size).setId(this.idHex)
|
||||
}
|
||||
}
|
||||
}
|
@ -2,10 +2,7 @@ package net.mamoe.mirai.network.protocol.tim.packet.login
|
||||
|
||||
import net.mamoe.mirai.network.protocol.tim.TIMProtocol
|
||||
import net.mamoe.mirai.network.protocol.tim.packet.*
|
||||
import net.mamoe.mirai.utils.TEA
|
||||
import net.mamoe.mirai.utils.Tested
|
||||
import net.mamoe.mirai.utils.cutTail
|
||||
import net.mamoe.mirai.utils.hexToBytes
|
||||
import java.io.DataInputStream
|
||||
|
||||
/**
|
||||
@ -192,8 +189,7 @@ abstract class ServerCaptchaPacket(input: DataInputStream) : ServerPacket(input)
|
||||
class Encrypted(input: DataInputStream, private val id: String) : ServerPacket(input) {
|
||||
|
||||
fun decrypt(): ServerCaptchaPacket {
|
||||
this.input goto 14
|
||||
val data = TEA.decrypt(this.input.readAllBytes().cutTail(1), TIMProtocol.key00BA.hexToBytes())
|
||||
val data = this.decryptAsByteArray(TIMProtocol.key00BA)
|
||||
if (id.startsWith("00 BA 32")) {
|
||||
return when (data.size) {
|
||||
66,
|
||||
|
@ -6,6 +6,6 @@ import java.awt.image.BufferedImage
|
||||
* @author NaturalHG
|
||||
*/
|
||||
@JvmOverloads
|
||||
fun BufferedImage.createCharImg(sizeWeight: Int = 100, sizeHeight: Int = 20): String {
|
||||
fun BufferedImage.createCharImg(sizeWeight: Int = 100): String {
|
||||
return CharImageConverter(this, sizeWeight).call()
|
||||
}
|
@ -1,8 +1,5 @@
|
||||
package net.mamoe.mirai.utils
|
||||
|
||||
import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.network.protocol.tim.packet.ServerPacket
|
||||
import net.mamoe.mirai.network.protocol.tim.packet.goto
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
@ -55,44 +52,9 @@ open class Console(
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun print(value: String?, color: LoggerTextFormat = LoggerTextFormat.YELLOW) {
|
||||
val s = SimpleDateFormat("MM-dd HH:mm:ss").format(Date())
|
||||
|
||||
println("$color$identity $s : $value")
|
||||
}
|
||||
}
|
||||
|
||||
fun Bot.log(o: Any?) = info(o)
|
||||
fun Bot.println(o: Any?) = info(o)
|
||||
fun Bot.info(o: Any?) = print(this, o.toString(), LoggerTextFormat.RESET)
|
||||
|
||||
fun Bot.error(o: Any?) = print(this, o.toString(), LoggerTextFormat.RED)
|
||||
|
||||
fun Bot.notice(o: Any?) = print(this, o.toString(), LoggerTextFormat.LIGHT_BLUE)
|
||||
|
||||
fun Bot.purple(o: Any?) = print(this, o.toString(), LoggerTextFormat.PURPLE)
|
||||
|
||||
fun Bot.cyan(o: Any?) = print(this, o.toString(), LoggerTextFormat.LIGHT_CYAN)
|
||||
fun Bot.green(o: Any?) = print(this, o.toString(), LoggerTextFormat.GREEN)
|
||||
|
||||
fun Bot.debug(o: Any?) = print(this, o.toString(), LoggerTextFormat.YELLOW)
|
||||
|
||||
fun Bot.debugPacket(packet: ServerPacket) {
|
||||
debug("Packet=$packet")
|
||||
debug("Packet size=" + packet.input.goto(0).readAllBytes().size)
|
||||
debug("Packet data=" + packet.input.goto(0).readAllBytes().toUHexString())
|
||||
}
|
||||
|
||||
|
||||
@Synchronized
|
||||
private fun print(bot: Bot, value: String?, color: LoggerTextFormat = LoggerTextFormat.WHITE) {
|
||||
val s = SimpleDateFormat("MM-dd HH:mm:ss").format(Date())
|
||||
kotlin.io.println("$color[Mirai] $s #R${bot.id}: $value")
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
private fun print(value: String?, color: LoggerTextFormat = LoggerTextFormat.WHITE) {
|
||||
val s = SimpleDateFormat("MM-dd HH:mm:ss").format(Date())
|
||||
kotlin.io.println("$color[Mirai] $s : $value")
|
||||
}
|
@ -2,10 +2,8 @@ package net.mamoe.mirai.utils.setting
|
||||
|
||||
|
||||
import org.ini4j.Profile
|
||||
|
||||
import java.io.IOException
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import java.util.stream.Collectors
|
||||
import kotlin.streams.toList
|
||||
|
||||
|
||||
@ -19,6 +17,7 @@ class MiraiSettingMapSection : ConcurrentHashMap<String, Any>(), MiraiSettingSec
|
||||
return defaultValue
|
||||
}
|
||||
return if (super.containsKey(key)) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
super.get(key) as T
|
||||
} else defaultValue
|
||||
}
|
||||
@ -28,10 +27,6 @@ class MiraiSettingMapSection : ConcurrentHashMap<String, Any>(), MiraiSettingSec
|
||||
this[key] = value
|
||||
}
|
||||
|
||||
override fun remove(key: String) {
|
||||
super.remove(key)
|
||||
}
|
||||
|
||||
fun getInt(key: String): Int {
|
||||
return this.getInt(key, 0)
|
||||
}
|
||||
|
@ -14,13 +14,12 @@ import java.util.concurrent.ConcurrentHashMap
|
||||
*
|
||||
* @author NaturalHG
|
||||
*/
|
||||
class MiraiSettings
|
||||
class MiraiSettings(file: File)
|
||||
/*
|
||||
public MiraiSettings(MiraiPluginBase pluginBase, String filename) {
|
||||
// TODO: 2019/9/6 每个插件独立文件夹存放
|
||||
this(new File(filename));
|
||||
}*/
|
||||
(file: File) {
|
||||
}*/ {
|
||||
|
||||
private val file: File
|
||||
|
||||
@ -29,14 +28,10 @@ class MiraiSettings
|
||||
private val cacheSection = ConcurrentHashMap<String, MiraiSettingSection>()
|
||||
|
||||
init {
|
||||
var file = file
|
||||
Objects.requireNonNull(file)
|
||||
if (!file.name.contains(".")) {
|
||||
file = File(file.path + ".ini")
|
||||
}
|
||||
this.file = file
|
||||
if (!file.exists() && !file.createNewFile()) {
|
||||
throw RuntimeException("cannot create config file $file")
|
||||
val f = file.takeIf { it.name.contains(".") } ?: File(file.path + ".ini")
|
||||
this.file = f
|
||||
if (!f.exists() && !f.createNewFile()) {
|
||||
throw RuntimeException("cannot create config file $f")
|
||||
}
|
||||
val config = Config()
|
||||
config.isMultiSection = true
|
||||
|
@ -1,31 +0,0 @@
|
||||
/**
|
||||
* @author Him188moe
|
||||
*/
|
||||
public class NetworkTest {
|
||||
public static void main(String[] args) {
|
||||
|
||||
/*
|
||||
System.out.println(Short.valueOf("37 13", 16));
|
||||
|
||||
System.out.println(1040400290L & 0x0FFFFFFFF);
|
||||
System.out.println(Long.valueOf("3E033FA2", 16));
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static String bytesToHex(byte[] bytes) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for(int i = 0; i < bytes.length; i++) {
|
||||
String hex = Integer.toHexString(bytes[i] & 0xFF);
|
||||
if(hex.length() < 2){
|
||||
sb.append(0);
|
||||
}
|
||||
sb.append(hex);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package event
|
||||
|
||||
import net.mamoe.mirai.event.Event
|
||||
import net.mamoe.mirai.event.broadcast
|
||||
import net.mamoe.mirai.event.subscribeAll
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
/**
|
||||
* @author Him188moe
|
||||
*/
|
||||
open class SuperEvent : Event() {
|
||||
companion object : KClass<SuperEvent> by SuperEvent::class//方便 subscribe
|
||||
}
|
||||
|
||||
open class ChildEvent : SuperEvent()
|
||||
|
||||
open class ChildChildEvent : ChildEvent()
|
||||
|
||||
class ChildChildChildEvent : ChildChildEvent()
|
||||
|
||||
|
||||
suspend fun main() {
|
||||
SuperEvent.subscribeAll {
|
||||
always {
|
||||
println(it.javaClass.simpleName)//ChildChildChildEvent
|
||||
}
|
||||
}
|
||||
|
||||
ChildChildChildEvent().broadcast()
|
||||
}
|
Loading…
Reference in New Issue
Block a user