mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-23 14:20:24 +08:00
update
This commit is contained in:
parent
a7d3e62fa6
commit
801d727629
@ -1,6 +1,6 @@
|
|||||||
package net.mamoe.mirai.contact
|
package net.mamoe.mirai.contact
|
||||||
|
|
||||||
import net.mamoe.mirai.message.At
|
import net.mamoe.mirai.message.defaults.At
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Him188moe
|
* @author Him188moe
|
||||||
|
@ -47,14 +47,17 @@ public class MiraiEventManager {
|
|||||||
if (!hook.isMount()) {
|
if (!hook.isMount()) {
|
||||||
hook.setMount(true);
|
hook.setMount(true);
|
||||||
hooksLock.writeLock().lock();
|
hooksLock.writeLock().lock();
|
||||||
if (!hooks.containsKey(hook.getEventClass())) {
|
try {
|
||||||
hooks.put(hook.getEventClass(), new LinkedList<>() {{
|
if (!hooks.containsKey(hook.getEventClass())) {
|
||||||
add(hook);
|
hooks.put(hook.getEventClass(), new LinkedList<>() {{
|
||||||
}});
|
add(hook);
|
||||||
} else {
|
}});
|
||||||
hooks.get(hook.getEventClass()).add(hook);
|
} else {
|
||||||
|
hooks.get(hook.getEventClass()).add(hook);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
hooksLock.writeLock().unlock();
|
||||||
}
|
}
|
||||||
hooksLock.writeLock().unlock();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,16 +101,19 @@ public class MiraiEventManager {
|
|||||||
|
|
||||||
public void broadcastEvent(MiraiEvent event) {
|
public void broadcastEvent(MiraiEvent event) {
|
||||||
hooksLock.readLock().lock();
|
hooksLock.readLock().lock();
|
||||||
if (hooks.containsKey(event.getClass())) {
|
try {
|
||||||
hooks.put(event.getClass(),
|
if (hooks.containsKey(event.getClass())) {
|
||||||
hooks.get(event.getClass())
|
hooks.put(event.getClass(),
|
||||||
.stream()
|
hooks.get(event.getClass())
|
||||||
.sorted(Comparator.comparingInt(MiraiEventHook::getPriority))
|
.stream()
|
||||||
.filter(a -> !a.accept(event))
|
.sorted(Comparator.comparingInt(MiraiEventHook::getPriority))
|
||||||
.collect(Collectors.toList())
|
.filter(a -> !a.accept(event))
|
||||||
);
|
.collect(Collectors.toList())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
hooksLock.readLock().unlock();
|
||||||
}
|
}
|
||||||
hooksLock.readLock().unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package net.mamoe.mirai.event
|
package net.mamoe.mirai.event
|
||||||
|
|
||||||
import net.mamoe.mirai.event.events.MiraiEvent
|
import net.mamoe.mirai.event.events.MiraiEvent
|
||||||
import net.mamoe.mirai.event.events.robot.RobotLoginSucceedEvent
|
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
|
|
||||||
@ -13,17 +12,27 @@ fun <C : Class<E>, E : MiraiEvent> C.hookOnce(hook: (E) -> Unit) {
|
|||||||
MiraiEventManager.getInstance().hookOnce(MiraiEventHook<E>(this, hook))
|
MiraiEventManager.getInstance().hookOnce(MiraiEventHook<E>(this, hook))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun <C : Class<E>, E : MiraiEvent> C.hookWhile(hook: (E) -> Boolean) {
|
||||||
|
MiraiEventManager.getInstance().hookAlways(MiraiEventHookSimple<E>(this, hook))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fun <C : KClass<E>, E : MiraiEvent> C.hookAlways(hook: (E) -> Unit) {
|
fun <C : KClass<E>, E : MiraiEvent> C.hookAlways(hook: (E) -> Unit) {
|
||||||
this.java.hookOnce(hook)
|
this.java.hookAlways(hook)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <C : KClass<E>, E : MiraiEvent> C.hookOnce(hook: (E) -> Unit) {
|
fun <C : KClass<E>, E : MiraiEvent> C.hookOnce(hook: (E) -> Unit) {
|
||||||
this.java.hookOnce(hook)
|
this.java.hookOnce(hook)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun <C : KClass<E>, E : MiraiEvent> C.hookWhile(hook: (E) -> Boolean) {
|
||||||
|
this.java.hookWhile(hook)
|
||||||
|
}
|
||||||
|
|
||||||
fun main() {
|
|
||||||
RobotLoginSucceedEvent::class.hookOnce {
|
private class MiraiEventHookSimple<E : MiraiEvent>(clazz: Class<E>, val hook: (E) -> Boolean) : MiraiEventHook<E>(clazz) {
|
||||||
|
override fun accept(event: MiraiEvent?): Boolean {
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
return hook.invoke(event as E)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,9 @@
|
|||||||
package net.mamoe.mirai.message;
|
package net.mamoe.mirai.message;
|
||||||
|
|
||||||
import net.mamoe.mirai.contact.QQ;
|
import net.mamoe.mirai.contact.QQ;
|
||||||
|
import net.mamoe.mirai.message.defaults.At;
|
||||||
|
import net.mamoe.mirai.message.defaults.MessageChain;
|
||||||
|
import net.mamoe.mirai.message.defaults.PlainText;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package net.mamoe.mirai.message
|
package net.mamoe.mirai.message
|
||||||
|
|
||||||
|
import net.mamoe.mirai.message.defaults.PlainText
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 实现使用 '+' 操作符连接 [Message] 与 [Message]
|
* 实现使用 '+' 操作符连接 [Message] 与 [Message]
|
||||||
*/
|
*/
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.mamoe.mirai.message;
|
package net.mamoe.mirai.message.defaults;
|
||||||
|
|
||||||
import net.mamoe.mirai.contact.QQ;
|
import net.mamoe.mirai.contact.QQ;
|
||||||
|
import net.mamoe.mirai.message.Message;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
@ -1,9 +1,12 @@
|
|||||||
package net.mamoe.mirai.message;
|
package net.mamoe.mirai.message.defaults;
|
||||||
|
|
||||||
|
import net.mamoe.mirai.message.FaceID;
|
||||||
|
import net.mamoe.mirai.message.Message;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Him188moe
|
* @author Him188moe
|
||||||
*/
|
*/
|
||||||
public class Face extends Message {
|
public final class Face extends Message {
|
||||||
private final FaceID id;
|
private final FaceID id;
|
||||||
|
|
||||||
public Face(FaceID id) {
|
public Face(FaceID id) {
|
@ -1,4 +1,6 @@
|
|||||||
package net.mamoe.mirai.message;
|
package net.mamoe.mirai.message.defaults;
|
||||||
|
|
||||||
|
import net.mamoe.mirai.message.Message;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
@ -1,5 +1,6 @@
|
|||||||
package net.mamoe.mirai.message;
|
package net.mamoe.mirai.message.defaults;
|
||||||
|
|
||||||
|
import net.mamoe.mirai.message.Message;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@ -12,7 +13,7 @@ import java.util.stream.Collectors;
|
|||||||
public final class MessageChain extends Message {
|
public final class MessageChain extends Message {
|
||||||
private LinkedList<Message> list = new LinkedList<>();
|
private LinkedList<Message> list = new LinkedList<>();
|
||||||
|
|
||||||
MessageChain(@NotNull Message head, @NotNull Message tail) {
|
public MessageChain(@NotNull Message head, @NotNull Message tail) {
|
||||||
Objects.requireNonNull(head);
|
Objects.requireNonNull(head);
|
||||||
Objects.requireNonNull(tail);
|
Objects.requireNonNull(tail);
|
||||||
|
|
@ -1,4 +1,6 @@
|
|||||||
package net.mamoe.mirai.message;
|
package net.mamoe.mirai.message.defaults;
|
||||||
|
|
||||||
|
import net.mamoe.mirai.message.Message;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Him188moe
|
* @author Him188moe
|
@ -9,8 +9,7 @@ import net.mamoe.mirai.network.packet.message.ClientSendFriendMessagePacket
|
|||||||
import net.mamoe.mirai.network.packet.verification.ServerVerificationCodePacket
|
import net.mamoe.mirai.network.packet.verification.ServerVerificationCodePacket
|
||||||
import net.mamoe.mirai.network.packet.verification.ServerVerificationCodePacketEncrypted
|
import net.mamoe.mirai.network.packet.verification.ServerVerificationCodePacketEncrypted
|
||||||
import net.mamoe.mirai.task.MiraiThreadPool
|
import net.mamoe.mirai.task.MiraiThreadPool
|
||||||
import net.mamoe.mirai.util.*
|
import net.mamoe.mirai.utils.*
|
||||||
import net.mamoe.mirai.utils.MiraiLogger
|
|
||||||
import java.io.ByteArrayInputStream
|
import java.io.ByteArrayInputStream
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.net.DatagramPacket
|
import java.net.DatagramPacket
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package net.mamoe.mirai.network.packet
|
package net.mamoe.mirai.network.packet
|
||||||
|
|
||||||
import net.mamoe.mirai.network.Protocol
|
import net.mamoe.mirai.network.Protocol
|
||||||
import net.mamoe.mirai.util.TEACryptor
|
import net.mamoe.mirai.utils.TEACryptor
|
||||||
import java.io.DataInputStream
|
import java.io.DataInputStream
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,7 +2,8 @@ package net.mamoe.mirai.network.packet
|
|||||||
|
|
||||||
import lombok.Getter
|
import lombok.Getter
|
||||||
import net.mamoe.mirai.network.Protocol
|
import net.mamoe.mirai.network.Protocol
|
||||||
import net.mamoe.mirai.util.*
|
import net.mamoe.mirai.util.TestedSuccessfully
|
||||||
|
import net.mamoe.mirai.utils.*
|
||||||
import java.io.DataOutputStream
|
import java.io.DataOutputStream
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package net.mamoe.mirai.network.packet
|
package net.mamoe.mirai.network.packet
|
||||||
|
|
||||||
import net.mamoe.mirai.network.Protocol
|
import net.mamoe.mirai.network.Protocol
|
||||||
import net.mamoe.mirai.util.TEACryptor
|
import net.mamoe.mirai.utils.TEACryptor
|
||||||
import net.mamoe.mirai.util.toUHexString
|
import net.mamoe.mirai.utils.toUHexString
|
||||||
import java.io.DataInputStream
|
import java.io.DataInputStream
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package net.mamoe.mirai.network.packet
|
package net.mamoe.mirai.network.packet
|
||||||
|
|
||||||
import net.mamoe.mirai.network.Protocol
|
import net.mamoe.mirai.network.Protocol
|
||||||
import net.mamoe.mirai.util.TEACryptor
|
import net.mamoe.mirai.utils.TEACryptor
|
||||||
import java.io.DataInputStream
|
import java.io.DataInputStream
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package net.mamoe.mirai.network.packet
|
package net.mamoe.mirai.network.packet
|
||||||
|
|
||||||
import net.mamoe.mirai.util.toUHexString
|
import net.mamoe.mirai.utils.toUHexString
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
import java.io.DataInputStream
|
import java.io.DataInputStream
|
||||||
import java.util.zip.GZIPInputStream
|
import java.util.zip.GZIPInputStream
|
||||||
|
@ -2,9 +2,9 @@ package net.mamoe.mirai.network.packet
|
|||||||
|
|
||||||
import net.mamoe.mirai.network.packet.login.*
|
import net.mamoe.mirai.network.packet.login.*
|
||||||
import net.mamoe.mirai.network.packet.verification.ServerVerificationCodePacketEncrypted
|
import net.mamoe.mirai.network.packet.verification.ServerVerificationCodePacketEncrypted
|
||||||
import net.mamoe.mirai.util.getAllDeclaredFields
|
import net.mamoe.mirai.utils.getAllDeclaredFields
|
||||||
import net.mamoe.mirai.util.hexToBytes
|
import net.mamoe.mirai.utils.hexToBytes
|
||||||
import net.mamoe.mirai.util.toUHexString
|
import net.mamoe.mirai.utils.toUHexString
|
||||||
import java.io.DataInputStream
|
import java.io.DataInputStream
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package net.mamoe.mirai.network.packet
|
package net.mamoe.mirai.network.packet
|
||||||
|
|
||||||
import net.mamoe.mirai.network.Protocol
|
import net.mamoe.mirai.network.Protocol
|
||||||
import net.mamoe.mirai.util.ByteArrayDataOutputStream
|
import net.mamoe.mirai.utils.ByteArrayDataOutputStream
|
||||||
import net.mamoe.mirai.util.TEACryptor
|
import net.mamoe.mirai.utils.TEACryptor
|
||||||
import net.mamoe.mirai.util.getRandomKey
|
import net.mamoe.mirai.utils.getRandomKey
|
||||||
import net.mamoe.mirai.util.lazyEncode
|
import net.mamoe.mirai.utils.lazyEncode
|
||||||
import java.io.DataInputStream
|
import java.io.DataInputStream
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package net.mamoe.mirai.network.packet
|
package net.mamoe.mirai.network.packet
|
||||||
|
|
||||||
import net.mamoe.mirai.network.Protocol
|
import net.mamoe.mirai.network.Protocol
|
||||||
import net.mamoe.mirai.util.*
|
import net.mamoe.mirai.utils.*
|
||||||
import java.io.DataInputStream
|
import java.io.DataInputStream
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
|
@ -2,7 +2,11 @@ package net.mamoe.mirai.network.packet.login
|
|||||||
|
|
||||||
import net.mamoe.mirai.network.Protocol
|
import net.mamoe.mirai.network.Protocol
|
||||||
import net.mamoe.mirai.network.packet.*
|
import net.mamoe.mirai.network.packet.*
|
||||||
import net.mamoe.mirai.util.*
|
import net.mamoe.mirai.util.TestedSuccessfully
|
||||||
|
import net.mamoe.mirai.utils.ByteArrayDataOutputStream
|
||||||
|
import net.mamoe.mirai.utils.TEACryptor
|
||||||
|
import net.mamoe.mirai.utils.hexToBytes
|
||||||
|
import net.mamoe.mirai.utils.toUHexString
|
||||||
import java.io.DataOutputStream
|
import java.io.DataOutputStream
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,7 +2,7 @@ package net.mamoe.mirai.network.packet.login
|
|||||||
|
|
||||||
import net.mamoe.mirai.network.Protocol
|
import net.mamoe.mirai.network.Protocol
|
||||||
import net.mamoe.mirai.network.packet.*
|
import net.mamoe.mirai.network.packet.*
|
||||||
import net.mamoe.mirai.util.ClientLoginStatus
|
import net.mamoe.mirai.utils.ClientLoginStatus
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Him188moe
|
* @author Him188moe
|
||||||
|
@ -2,8 +2,8 @@ package net.mamoe.mirai.network.packet.login
|
|||||||
|
|
||||||
import net.mamoe.mirai.network.Protocol
|
import net.mamoe.mirai.network.Protocol
|
||||||
import net.mamoe.mirai.network.packet.*
|
import net.mamoe.mirai.network.packet.*
|
||||||
import net.mamoe.mirai.util.ByteArrayDataOutputStream
|
import net.mamoe.mirai.utils.ByteArrayDataOutputStream
|
||||||
import net.mamoe.mirai.util.TEACryptor
|
import net.mamoe.mirai.utils.TEACryptor
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Him188moe
|
* @author Him188moe
|
||||||
|
@ -5,10 +5,10 @@ import net.mamoe.mirai.network.packet.ServerPacket
|
|||||||
import net.mamoe.mirai.network.packet.goto
|
import net.mamoe.mirai.network.packet.goto
|
||||||
import net.mamoe.mirai.network.packet.readNBytes
|
import net.mamoe.mirai.network.packet.readNBytes
|
||||||
import net.mamoe.mirai.network.packet.readVarString
|
import net.mamoe.mirai.network.packet.readVarString
|
||||||
import net.mamoe.mirai.util.TEACryptor
|
|
||||||
import net.mamoe.mirai.util.TestedSuccessfully
|
import net.mamoe.mirai.util.TestedSuccessfully
|
||||||
import net.mamoe.mirai.util.hexToBytes
|
import net.mamoe.mirai.utils.TEACryptor
|
||||||
import net.mamoe.mirai.util.toUHexString
|
import net.mamoe.mirai.utils.hexToBytes
|
||||||
|
import net.mamoe.mirai.utils.toUHexString
|
||||||
import java.io.DataInputStream
|
import java.io.DataInputStream
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,10 +4,10 @@ import net.mamoe.mirai.network.packet.PacketId
|
|||||||
import net.mamoe.mirai.network.packet.ServerPacket
|
import net.mamoe.mirai.network.packet.ServerPacket
|
||||||
import net.mamoe.mirai.network.packet.dataInputStream
|
import net.mamoe.mirai.network.packet.dataInputStream
|
||||||
import net.mamoe.mirai.network.packet.goto
|
import net.mamoe.mirai.network.packet.goto
|
||||||
import net.mamoe.mirai.util.TEACryptor
|
|
||||||
import net.mamoe.mirai.util.TestedSuccessfully
|
import net.mamoe.mirai.util.TestedSuccessfully
|
||||||
import net.mamoe.mirai.util.hexToUBytes
|
import net.mamoe.mirai.utils.TEACryptor
|
||||||
import net.mamoe.mirai.util.toUHexString
|
import net.mamoe.mirai.utils.hexToUBytes
|
||||||
|
import net.mamoe.mirai.utils.toUHexString
|
||||||
import java.io.DataInputStream
|
import java.io.DataInputStream
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,7 +3,7 @@ package net.mamoe.mirai.network.packet.login
|
|||||||
import net.mamoe.mirai.network.packet.ServerPacket
|
import net.mamoe.mirai.network.packet.ServerPacket
|
||||||
import net.mamoe.mirai.network.packet.dataInputStream
|
import net.mamoe.mirai.network.packet.dataInputStream
|
||||||
import net.mamoe.mirai.network.packet.goto
|
import net.mamoe.mirai.network.packet.goto
|
||||||
import net.mamoe.mirai.util.TEACryptor
|
import net.mamoe.mirai.utils.TEACryptor
|
||||||
import java.io.DataInputStream
|
import java.io.DataInputStream
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,7 +2,8 @@ package net.mamoe.mirai.network.packet.message
|
|||||||
|
|
||||||
import net.mamoe.mirai.network.Protocol
|
import net.mamoe.mirai.network.Protocol
|
||||||
import net.mamoe.mirai.network.packet.*
|
import net.mamoe.mirai.network.packet.*
|
||||||
import net.mamoe.mirai.util.lazyEncode
|
import net.mamoe.mirai.utils.lazyEncode
|
||||||
|
import net.mamoe.mirai.utils.toUHexString
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Him188moe
|
* @author Him188moe
|
||||||
@ -55,3 +56,14 @@ class ClientSendFriendMessagePacket(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
println(lazyEncode {
|
||||||
|
val bytes = "hahaha".toByteArray()
|
||||||
|
it.writeByte(0x01)
|
||||||
|
it.writeShort(bytes.size)
|
||||||
|
it.writeByte(0x01)
|
||||||
|
it.writeShort(bytes.size - 1)
|
||||||
|
it.write(bytes)
|
||||||
|
}.toUHexString())
|
||||||
|
}
|
@ -3,7 +3,7 @@ package net.mamoe.mirai.network.packet.verification
|
|||||||
import net.mamoe.mirai.network.packet.ServerPacket
|
import net.mamoe.mirai.network.packet.ServerPacket
|
||||||
import net.mamoe.mirai.network.packet.dataInputStream
|
import net.mamoe.mirai.network.packet.dataInputStream
|
||||||
import net.mamoe.mirai.network.packet.goto
|
import net.mamoe.mirai.network.packet.goto
|
||||||
import net.mamoe.mirai.util.TEACryptor
|
import net.mamoe.mirai.utils.TEACryptor
|
||||||
import java.io.DataInputStream
|
import java.io.DataInputStream
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
package net.mamoe.mirai.util
|
|
||||||
|
|
||||||
import net.mamoe.mirai.network.packet.ClientPacket
|
|
||||||
import net.mamoe.mirai.network.packet.ServerPacket
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Him188moe
|
|
||||||
*/
|
|
||||||
object DebugLogger {
|
|
||||||
val buff = StringBuilder()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun ByteArray.encryptionDebugLogging() {
|
|
||||||
DebugLogger.buff.append("TEA encrypt: " + this.toUHexString()).append("\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun ByteArray.packetSentDebugLogging() {
|
|
||||||
DebugLogger.buff.append("packet sent: " + this.toUHexString()).append("\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun ByteArray.decryptionDebugLogging() {
|
|
||||||
DebugLogger.buff.append("TEA decrypted: " + this.toUHexString()).append("\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun ServerPacket.logging() {
|
|
||||||
DebugLogger.buff.append(this.toString()).append("\n")
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@ExperimentalUnsignedTypes
|
|
||||||
fun ClientPacket.logging() {
|
|
||||||
DebugLogger.buff.append(this.toString()).append("\n")
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
package net.mamoe.mirai.util;
|
package net.mamoe.mirai.utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Him188moe
|
* @author Him188moe
|
@ -38,4 +38,8 @@ object MiraiLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun log(any: Any?) = MiraiLogger.info(any)
|
fun Any.logInfo() = MiraiLogger.info(this)
|
||||||
|
|
||||||
|
fun Any.logDebug() = MiraiLogger.debug(this)
|
||||||
|
|
||||||
|
fun Any.logError() = MiraiLogger.error(this)
|
@ -1,4 +1,4 @@
|
|||||||
package net.mamoe.mirai.util;
|
package net.mamoe.mirai.utils;
|
||||||
|
|
||||||
import net.mamoe.mirai.network.Protocol;
|
import net.mamoe.mirai.network.Protocol;
|
||||||
|
|
||||||
@ -239,13 +239,10 @@ public class TEACryptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public byte[] encrypt(byte[] plaintext) {
|
public byte[] encrypt(byte[] plaintext) {
|
||||||
DebugLoggerKt.encryptionDebugLogging(plaintext);
|
|
||||||
//System.out.println("TEA加密, 原文=" + Utils.INSTANCE.toHexString(plaintext, ""));
|
|
||||||
return encrypt(plaintext, 0, plaintext.length);
|
return encrypt(plaintext, 0, plaintext.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] decrypt(byte[] ciphertext) {
|
public byte[] decrypt(byte[] ciphertext) {
|
||||||
DebugLoggerKt.decryptionDebugLogging(ciphertext);
|
|
||||||
return decrypt(ciphertext, 0, ciphertext.length);
|
return decrypt(ciphertext, 0, ciphertext.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,73 +0,0 @@
|
|||||||
package net.mamoe.mirai.utils;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
public class Utils {
|
|
||||||
/**
|
|
||||||
* File supporting from Nukkit
|
|
||||||
* */
|
|
||||||
public static void writeFile(String fileName, String content) throws IOException {
|
|
||||||
writeFile(fileName, new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void writeFile(String fileName, InputStream content) throws IOException {
|
|
||||||
writeFile(new File(fileName), content);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void writeFile(File file, String content) throws IOException {
|
|
||||||
writeFile(file, new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void writeFile(File file, InputStream content) throws IOException {
|
|
||||||
if (content == null) {
|
|
||||||
throw new IllegalArgumentException("content must not be null");
|
|
||||||
}
|
|
||||||
if (!file.exists()) {
|
|
||||||
file.createNewFile();
|
|
||||||
}
|
|
||||||
try (FileOutputStream stream = new FileOutputStream(file)) {
|
|
||||||
byte[] buffer = new byte[1024];
|
|
||||||
int length;
|
|
||||||
while ((length = content.read(buffer)) != -1) {
|
|
||||||
stream.write(buffer, 0, length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
content.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String readFile(File file) throws IOException {
|
|
||||||
if (!file.exists() || file.isDirectory()) {
|
|
||||||
throw new FileNotFoundException();
|
|
||||||
}
|
|
||||||
return readFile(new FileInputStream(file));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String readFile(String filename) throws IOException {
|
|
||||||
File file = new File(filename);
|
|
||||||
if (!file.exists() || file.isDirectory()) {
|
|
||||||
throw new FileNotFoundException();
|
|
||||||
}
|
|
||||||
return readFile(new FileInputStream(file));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String readFile(InputStream inputStream) throws IOException {
|
|
||||||
return readFile(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String readFile(Reader reader) throws IOException {
|
|
||||||
try (BufferedReader br = new BufferedReader(reader)) {
|
|
||||||
String temp;
|
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
|
||||||
temp = br.readLine();
|
|
||||||
while (temp != null) {
|
|
||||||
if (stringBuilder.length() != 0) {
|
|
||||||
stringBuilder.append("\n");
|
|
||||||
}
|
|
||||||
stringBuilder.append(temp);
|
|
||||||
temp = br.readLine();
|
|
||||||
}
|
|
||||||
return stringBuilder.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
package net.mamoe.mirai.util
|
package net.mamoe.mirai.utils
|
||||||
|
|
||||||
import net.mamoe.mirai.network.Protocol
|
import net.mamoe.mirai.network.Protocol
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
@ -8,30 +8,15 @@ import java.lang.reflect.Field
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.zip.CRC32
|
import java.util.zip.CRC32
|
||||||
|
|
||||||
/**
|
fun ByteArray.toHexString(): String = toHexString(" ")
|
||||||
* @author Him188moe
|
fun ByteArray.toHexString(separator: String = " "): String = this.joinToString(separator) {
|
||||||
*/
|
var ret = it.toString(16).toUpperCase()
|
||||||
object Utils {
|
if (ret.length == 1) {
|
||||||
fun toHexString(byteArray: ByteArray, separator: String = " "): String = byteArray.joinToString(separator) {
|
ret = "0$ret"
|
||||||
var ret = it.toString(16).toUpperCase()
|
|
||||||
if (ret.length == 1) {
|
|
||||||
ret = "0$ret"
|
|
||||||
}
|
|
||||||
return@joinToString ret
|
|
||||||
}
|
|
||||||
|
|
||||||
@ExperimentalUnsignedTypes
|
|
||||||
fun toHexString(byteArray: UByteArray, separator: String = " "): String = byteArray.joinToString(separator) {
|
|
||||||
var ret = it.toString(16).toUpperCase()
|
|
||||||
if (ret.length == 1) {
|
|
||||||
ret = "0$ret"
|
|
||||||
}
|
|
||||||
return@joinToString ret
|
|
||||||
}
|
}
|
||||||
|
return@joinToString ret
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ByteArray.toHexString(): String = toHexString(" ")
|
|
||||||
fun ByteArray.toHexString(separator: String = " "): String = Utils.toHexString(this, separator)
|
|
||||||
@ExperimentalUnsignedTypes
|
@ExperimentalUnsignedTypes
|
||||||
fun ByteArray.toUHexString(separator: String = " "): String = this.toUByteArray().toUHexString(separator)
|
fun ByteArray.toUHexString(separator: String = " "): String = this.toUByteArray().toUHexString(separator)
|
||||||
|
|
||||||
@ -39,7 +24,13 @@ fun ByteArray.toUHexString(separator: String = " "): String = this.toUByteArray(
|
|||||||
fun ByteArray.toUHexString(): String = this.toUByteArray().toUHexString()
|
fun ByteArray.toUHexString(): String = this.toUByteArray().toUHexString()
|
||||||
|
|
||||||
@ExperimentalUnsignedTypes
|
@ExperimentalUnsignedTypes
|
||||||
fun UByteArray.toUHexString(separator: String = " "): String = Utils.toHexString(this, separator)
|
fun UByteArray.toUHexString(separator: String = " "): String = this.joinToString(separator) {
|
||||||
|
var ret = it.toString(16).toUpperCase()
|
||||||
|
if (ret.length == 1) {
|
||||||
|
ret = "0$ret"
|
||||||
|
}
|
||||||
|
return@joinToString ret
|
||||||
|
}
|
||||||
|
|
||||||
@ExperimentalUnsignedTypes
|
@ExperimentalUnsignedTypes
|
||||||
fun UByteArray.toUHexString(): String = this.toUHexString(" ")
|
fun UByteArray.toUHexString(): String = this.toUHexString(" ")
|
||||||
@ -94,10 +85,6 @@ fun getGTK(sKey: String): Int {
|
|||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() {
|
|
||||||
println(getGTK("ABCDEFGEFC"))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getCrc32(key: ByteArray): Int = CRC32().let { it.update(key); it.value.toInt() }
|
fun getCrc32(key: ByteArray): Int = CRC32().let { it.update(key); it.value.toInt() }
|
||||||
|
|
||||||
|
|
@ -1,14 +1,18 @@
|
|||||||
package net.mamoe.mirai.utils.config;
|
package net.mamoe.mirai.utils.config;
|
||||||
|
|
||||||
|
import kotlin.io.FilesKt;
|
||||||
import net.mamoe.mirai.MiraiServer;
|
import net.mamoe.mirai.MiraiServer;
|
||||||
import net.mamoe.mirai.utils.Utils;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.yaml.snakeyaml.DumperOptions;
|
import org.yaml.snakeyaml.DumperOptions;
|
||||||
import org.yaml.snakeyaml.Yaml;
|
import org.yaml.snakeyaml.Yaml;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* YAML-TYPE CONFIG
|
* YAML-TYPE CONFIG
|
||||||
@ -35,7 +39,7 @@ public class MiraiConfig extends MiraiConfigSection<Object> {
|
|||||||
Yaml yaml = new Yaml(dumperOptions);
|
Yaml yaml = new Yaml(dumperOptions);
|
||||||
String content = yaml.dump(this.sortedMap);
|
String content = yaml.dump(this.sortedMap);
|
||||||
try {
|
try {
|
||||||
Utils.writeFile(this.root, content);
|
new ByteArrayInputStream(content.getBytes()).transferTo(new FileOutputStream(this.root));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -59,12 +63,7 @@ public class MiraiConfig extends MiraiConfigSection<Object> {
|
|||||||
DumperOptions dumperOptions = new DumperOptions();
|
DumperOptions dumperOptions = new DumperOptions();
|
||||||
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||||
Yaml yaml = new Yaml(dumperOptions);
|
Yaml yaml = new Yaml(dumperOptions);
|
||||||
try {
|
return yaml.loadAs(String.join("\n", FilesKt.readLines(file, Charset.defaultCharset())), LinkedHashMap.class);
|
||||||
return yaml.loadAs(Utils.readFile(file), LinkedHashMap.class);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return new LinkedHashMap<>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import net.mamoe.mirai.network.packet.login.ClientPasswordSubmissionPacket
|
import net.mamoe.mirai.network.packet.login.ClientPasswordSubmissionPacket
|
||||||
import net.mamoe.mirai.util.toUHexString
|
import net.mamoe.mirai.utils.toUHexString
|
||||||
|
|
||||||
@ExperimentalUnsignedTypes
|
@ExperimentalUnsignedTypes
|
||||||
fun main(){
|
fun main(){
|
||||||
|
Loading…
Reference in New Issue
Block a user