mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-08 17:20:11 +08:00
Cleanup
This commit is contained in:
parent
00d8e26850
commit
4d09010cf0
@ -8,9 +8,6 @@ import net.mamoe.mirai.network.protocol.tim.TIMBotNetworkHandler
|
||||
import net.mamoe.mirai.utils.BotAccount
|
||||
import net.mamoe.mirai.utils.ContactList
|
||||
import net.mamoe.mirai.utils.MiraiLogger
|
||||
import java.io.Closeable
|
||||
import java.util.*
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
/**
|
||||
* Mirai 的机器人. 一个机器人实例登录一个 QQ 账号.
|
||||
@ -40,9 +37,8 @@ import java.util.concurrent.atomic.AtomicInteger
|
||||
* @author NatrualHG
|
||||
* @see net.mamoe.mirai.contact.Contact
|
||||
*/
|
||||
class Bot(val account: BotAccount, val logger: MiraiLogger) : Closeable {
|
||||
|
||||
val id = createdBotsCount.getAndAdd(1)
|
||||
class Bot(val account: BotAccount, val logger: MiraiLogger) {
|
||||
val id = nextId()
|
||||
|
||||
val contacts = ContactSystem()
|
||||
|
||||
@ -88,7 +84,7 @@ class Bot(val account: BotAccount, val logger: MiraiLogger) : Closeable {
|
||||
}
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
fun close() {
|
||||
this.network.close()
|
||||
this.contacts.groups.values.forEach { it.close() }
|
||||
this.contacts.groups.clear()
|
||||
@ -96,8 +92,10 @@ class Bot(val account: BotAccount, val logger: MiraiLogger) : Closeable {
|
||||
}
|
||||
|
||||
companion object {
|
||||
val instances: MutableList<Bot> = Collections.synchronizedList(LinkedList())
|
||||
val instances: MutableList<Bot> = mutableListOf()
|
||||
|
||||
private val createdBotsCount = AtomicInteger(0)
|
||||
private var id = 0
|
||||
private val idLock = Any()
|
||||
fun nextId(): Int = synchronized(idLock) { id++ }
|
||||
}
|
||||
}
|
@ -58,7 +58,7 @@ 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) {
|
||||
fun Bot.printPacketDebugging(packet: ServerPacket) {
|
||||
debug("Packet=$packet")
|
||||
debug("Packet size=" + packet.input.goto(0).readAllBytes().size)
|
||||
debug("Packet data=" + packet.input.goto(0).readAllBytes().toUHexString())
|
||||
|
@ -26,8 +26,8 @@ abstract class Contact internal constructor(val bot: Bot, val number: Long) {
|
||||
return sendMessage(message.toChain())
|
||||
}
|
||||
|
||||
suspend fun sendMessage(message: String) {
|
||||
this.sendMessage(PlainText(message))
|
||||
suspend fun sendMessage(plain: String) {
|
||||
this.sendMessage(PlainText(plain))
|
||||
}
|
||||
|
||||
suspend fun sendMessage(message: List<Message>) {
|
||||
|
@ -42,6 +42,9 @@ class ClientPasswordSubmissionPacket(
|
||||
}
|
||||
}
|
||||
|
||||
//实际上这些包性质都是一样的. 31 04 仅是一个序列 id, 可随机
|
||||
//但为简化处理, 特固定这个 id
|
||||
|
||||
@PacketId("08 36 31 04")
|
||||
class ClientLoginResendPacket3104(qq: Long, password: String, loginTime: Int, loginIP: String, privateKey: ByteArray, token0825: ByteArray, token00BA: ByteArray, tlv0006: ByteArray? = null)
|
||||
: ClientLoginResendPacket(qq, password, loginTime, loginIP, privateKey, token0825, token00BA, tlv0006)
|
||||
|
@ -19,14 +19,14 @@ class ServerLoginResponseKeyExchangePacket(input: DataInputStream, val flag: Fla
|
||||
OTHER,
|
||||
}
|
||||
|
||||
lateinit var tlv0006: ByteArray;//120bytes
|
||||
lateinit var tlv0006: ByteArray//120bytes
|
||||
var tokenUnknown: ByteArray? = null
|
||||
lateinit var privateKey: ByteArray//16bytes
|
||||
lateinit var privateKeyUpdate: ByteArray//16bytes
|
||||
|
||||
@Tested
|
||||
override fun decode() {
|
||||
this.input.skip(5)
|
||||
privateKey = this.input.readNBytes(16)//22
|
||||
privateKeyUpdate = this.input.readNBytes(16)//22
|
||||
//this.input.skip(2)//25
|
||||
this.input.goto(25)
|
||||
tlv0006 = this.input.readNBytes(120)
|
||||
|
@ -5,5 +5,5 @@ package net.mamoe.mirai.utils
|
||||
*/
|
||||
data class BotAccount(
|
||||
val qqNumber: Long,//实际上是 UInt
|
||||
val password: String
|
||||
val password: String//todo 不保存 password?
|
||||
)
|
Loading…
Reference in New Issue
Block a user