mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-21 17:34:45 +08:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
dc3d8063b7
@ -1,11 +1,8 @@
|
||||
package net.mamoe.mirai;
|
||||
|
||||
|
||||
import net.mamoe.mirai.event.MiraiEventHook;
|
||||
import net.mamoe.mirai.event.events.server.ServerDisableEvent;
|
||||
|
||||
/**
|
||||
* @author Him188moe @ Mirai Project
|
||||
* @author Him188moe
|
||||
*/
|
||||
public final class MiraiMain {
|
||||
private static MiraiServer server;
|
||||
|
@ -3,7 +3,7 @@ package net.mamoe.mirai.contact
|
||||
/**
|
||||
* A contact is a QQ account or a QQ Group.
|
||||
*
|
||||
* @author Him188moe @ Mirai Project
|
||||
* @author Him188moe
|
||||
*/
|
||||
abstract class Contact(val number: Int) {
|
||||
|
||||
|
@ -7,6 +7,10 @@ fun Int.asGroup(): Group = Instances.groups.stream().filter { t: Group? -> t?.nu
|
||||
|
||||
fun String.withImage(id: String, type: String) = "{$id}.$type"
|
||||
|
||||
fun String.withAt(qq: Int) = qq.asQQ().at()
|
||||
|
||||
fun String.withAt(qq: QQ) = qq.at()
|
||||
|
||||
object Instances {
|
||||
var qqs = arrayListOf<QQ>()
|
||||
var groups = arrayListOf<Group>()
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.mamoe.mirai.contact
|
||||
|
||||
/**
|
||||
* @author Him188moe @ Mirai Project
|
||||
* @author Him188moe
|
||||
*/
|
||||
class QQ(number: Int) : Contact(number) {
|
||||
init {
|
||||
|
@ -4,7 +4,7 @@ import net.mamoe.mirai.event.events.MiraiEvent
|
||||
import net.mamoe.mirai.network.Robot
|
||||
|
||||
/**
|
||||
* @author Him188moe @ Mirai Project
|
||||
* @author Him188moe
|
||||
*/
|
||||
class RobotLoginEvent(val robot: Robot) : MiraiEvent()
|
||||
|
||||
|
@ -5,7 +5,7 @@ import java.util.*
|
||||
import java.util.stream.Collectors
|
||||
|
||||
/**
|
||||
* @author Him188moe @ Mirai Project
|
||||
* @author Him188moe
|
||||
*/
|
||||
interface Protocol {
|
||||
companion object {
|
||||
|
@ -25,7 +25,7 @@ import java.net.InetSocketAddress
|
||||
/**
|
||||
* [number] is a QQ number.
|
||||
*
|
||||
* @author Him188moe @ Mirai Project
|
||||
* @author Him188moe
|
||||
*/
|
||||
class Robot(val number: Int, private val password: String) {
|
||||
private var sequence: Int = 0
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.mamoe.mirai.network.packet;
|
||||
|
||||
/**
|
||||
* @author Him188moe @ Mirai Project
|
||||
* @author Him188moe
|
||||
*/
|
||||
public interface Packet {
|
||||
|
||||
|
@ -6,7 +6,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @author Him188moe @ Mirai Project
|
||||
* @author Him188moe
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.mamoe.mirai.network.packet;
|
||||
|
||||
/**
|
||||
* @author Him188moe @ Mirai Project
|
||||
* @author Him188moe
|
||||
*/
|
||||
public final class PacketUtil {
|
||||
|
||||
|
@ -11,7 +11,7 @@ import java.net.InetAddress
|
||||
import java.security.MessageDigest
|
||||
|
||||
/**
|
||||
* @author Him188moe @ Mirai Project
|
||||
* @author Him188moe
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
abstract class ClientPacket : ByteArrayDataOutputStream(), Packet {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.mamoe.mirai.network.packet.client
|
||||
|
||||
/**
|
||||
* @author Him188moe @ Mirai Project
|
||||
* @author Him188moe
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
class ClientSendMessagePacket : ClientPacket() {
|
||||
|
@ -11,7 +11,7 @@ import net.mamoe.mirai.util.hexToBytes
|
||||
/**
|
||||
* Password submission (0836_622)
|
||||
*
|
||||
* @author Him188moe @ Mirai Project
|
||||
* @author Him188moe
|
||||
*/
|
||||
@PacketId("08 36 31 03")
|
||||
@ExperimentalUnsignedTypes
|
||||
@ -120,7 +120,7 @@ class ClientLoginSucceedConfirmationPacket(
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Him188moe @ Mirai Project
|
||||
* @author Him188moe
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
private fun ClientPacket.writePart1(qq: Int, password: String, loginTime: Int, loginIP: String, tgtgtKey: ByteArray, token0825: ByteArray) {
|
||||
|
@ -10,7 +10,7 @@ import net.mamoe.mirai.util.ByteArrayDataOutputStream
|
||||
import net.mamoe.mirai.util.TEACryptor
|
||||
|
||||
/**
|
||||
* @author Him188moe @ Mirai Project
|
||||
* @author Him188moe
|
||||
*/
|
||||
@PacketId("00 BA 31 01")
|
||||
@ExperimentalUnsignedTypes
|
||||
|
@ -13,7 +13,7 @@ import java.io.IOException
|
||||
/**
|
||||
* Server redirection (0825 response)
|
||||
*
|
||||
* @author Him188moe @ Mirai Project
|
||||
* @author Him188moe
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
@PacketId("08 25 31 02")
|
||||
@ -24,7 +24,7 @@ class ClientServerRedirectionPacket(private val serverIP: String, private val qq
|
||||
this.writeHex(Protocol.fixVer)
|
||||
this.writeHex(Protocol.redirectionKey)
|
||||
|
||||
//TEA 加密
|
||||
|
||||
this.write(TEACryptor.encrypt(object : ClientPacket() {
|
||||
@Throws(IOException::class)
|
||||
override fun encode() {
|
||||
|
@ -10,7 +10,7 @@ import net.mamoe.mirai.util.TEACryptor
|
||||
import java.io.IOException
|
||||
|
||||
/**
|
||||
* @author Him188moe @ Mirai Project
|
||||
* @author Him188moe
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
@PacketId("00 58")//todo check
|
||||
|
@ -16,7 +16,7 @@ import java.io.IOException
|
||||
*
|
||||
* @see net.mamoe.mirai.network.packet.server.ServerTouchResponsePacket
|
||||
*
|
||||
* @author Him188moe @ Mirai Project
|
||||
* @author Him188moe
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
@PacketId("08 25 31 01")
|
||||
@ -35,7 +35,7 @@ class ClientTouchPacket : ClientPacket() {
|
||||
this.writeHex(Protocol._0825key)
|
||||
|
||||
|
||||
//TEA 加密
|
||||
|
||||
this.write(TEACryptor.CRYPTOR_0825KEY.encrypt(object : ByteArrayDataOutputStream() {
|
||||
@Throws(IOException::class)
|
||||
override fun toByteArray(): ByteArray {
|
||||
|
@ -10,7 +10,7 @@ import net.mamoe.mirai.util.toHexString
|
||||
import java.io.DataInputStream
|
||||
|
||||
/**
|
||||
* @author Him188moe @ Mirai Project
|
||||
* @author Him188moe
|
||||
*/
|
||||
abstract class ServerPacket(val input: DataInputStream) : Packet {
|
||||
|
||||
@ -92,3 +92,32 @@ fun DataInputStream.readVarString(length:Int): String{
|
||||
|
||||
|
||||
fun ByteArray.dataInputStream(): DataInputStream = DataInputStream(this.inputStream())
|
||||
|
||||
/**
|
||||
* Reset and skip(position)
|
||||
*/
|
||||
infix fun <N : Number> DataInputStream.goto(position: N): DataInputStream {
|
||||
this.reset()
|
||||
this.skip(position.toLong());
|
||||
return this
|
||||
}
|
||||
|
||||
fun <N : Number> DataInputStream.readNBytes(position: N, length: Int): ByteArray {
|
||||
this.goto(position)
|
||||
return this.readNBytes(length)
|
||||
}
|
||||
|
||||
fun <N : Number> DataInputStream.readInt(position: N): Int {
|
||||
this.goto(position)
|
||||
return this.readInt();
|
||||
}
|
||||
|
||||
fun <N : Number> DataInputStream.readByte(position: N): Byte {
|
||||
this.goto(position)
|
||||
return this.readByte();
|
||||
}
|
||||
|
||||
fun <N : Number> DataInputStream.readShort(position: N): Short {
|
||||
this.goto(position)
|
||||
return this.readShort();
|
||||
}
|
@ -4,7 +4,7 @@ import net.mamoe.mirai.network.packet.server.ServerPacket
|
||||
import java.io.DataInputStream
|
||||
|
||||
/**
|
||||
* @author Him188moe @ Mirai Project
|
||||
* @author Him188moe
|
||||
*/
|
||||
class ServerLoginResponseFailedPacket(val state: State, input: DataInputStream) : ServerPacket(input) {
|
||||
enum class State {
|
||||
|
@ -5,7 +5,7 @@ import net.mamoe.mirai.network.packet.server.ServerPacket
|
||||
import java.io.DataInputStream
|
||||
|
||||
/**
|
||||
* @author Him188moe @ Mirai Project
|
||||
* @author Him188moe
|
||||
*/
|
||||
@PacketId("08 36 31 03")
|
||||
class ServerLoginResponseResendPacket(input: DataInputStream, val flag: Flag) : ServerPacket(input) {
|
||||
|
@ -11,8 +11,8 @@ import net.mamoe.mirai.util.toHexString
|
||||
import java.io.DataInputStream
|
||||
|
||||
/**
|
||||
* @author Him188moe @ Mirai Project
|
||||
* @author NaturalHG @ Mirai Project
|
||||
* @author Him188moe
|
||||
* @author NaturalHG
|
||||
*/
|
||||
class ServerLoginResponseSuccessPacket(input: DataInputStream, val packetDataLength: Int) : ServerPacket(input) {
|
||||
lateinit var _0828_rec_decr_key: ByteArray//16 bytes|
|
||||
|
@ -4,7 +4,7 @@ import net.mamoe.mirai.network.packet.server.ServerPacket
|
||||
import java.io.DataInputStream
|
||||
|
||||
/**
|
||||
* @author Him188moe @ Mirai Project
|
||||
* @author Him188moe
|
||||
*/
|
||||
class ServerLoginResponseVerificationCodePacket(input: DataInputStream) : ServerPacket(input) {
|
||||
var verifyCodeLength: Int = 0
|
||||
|
@ -8,7 +8,7 @@ import java.io.DataInputStream
|
||||
/**
|
||||
* Dispose_0828
|
||||
*
|
||||
* @author Him188moe @ Mirai Project
|
||||
* @author Him188moe
|
||||
*/
|
||||
class ServerSessionKeyResponsePacket(inputStream: DataInputStream) : ServerPacket(inputStream) {
|
||||
lateinit var sessionKey: ByteArray
|
||||
@ -39,7 +39,7 @@ class ServerSessionKeyResponsePacket(inputStream: DataInputStream) : ServerPacke
|
||||
/**
|
||||
* Encrypted using []0828_rec_decr_key], decrypting in Robot
|
||||
*
|
||||
* @author Him188moe @ Mirai Project
|
||||
* @author Him188moe
|
||||
*/
|
||||
class ServerSessionKeyResponsePacketEncrypted(inputStream: DataInputStream) : ServerPacket(inputStream) {
|
||||
override fun decode() {
|
||||
|
@ -11,7 +11,7 @@ import java.io.DataInputStream
|
||||
* @see net.mamoe.mirai.network.packet.client.login.ClientServerRedirectionPacket
|
||||
* @see net.mamoe.mirai.network.packet.client.login.ClientPasswordSubmissionPacket
|
||||
*
|
||||
* @author Him188moe @ Mirai Project
|
||||
* @author Him188moe
|
||||
*/
|
||||
class ServerTouchResponsePacket(private val type: Type, inputStream: DataInputStream) : ServerPacket(inputStream) {
|
||||
var serverIP: String? = null;
|
||||
|
@ -7,7 +7,7 @@ import java.util.*
|
||||
import java.util.zip.CRC32
|
||||
|
||||
/**
|
||||
* @author Him188moe @ Mirai Project
|
||||
* @author Him188moe
|
||||
*/
|
||||
object Utils {
|
||||
fun toHexString(byteArray: ByteArray, separator: String = " "): String = byteArray.joinToString(separator) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @author Him188moe @ Mirai Project
|
||||
* @author Him188moe
|
||||
*/
|
||||
public class NetworkTest {
|
||||
public static void main(String[] args) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.mamoe.mirai.util;
|
||||
|
||||
/**
|
||||
* @author Him188moe @ Mirai Project
|
||||
* @author Him188moe
|
||||
*/
|
||||
public final class TeaEncryption {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user