Commit f1b81120 authored by Him188moe's avatar Him188moe

Updated verification code

parent cf4eed6d
......@@ -183,9 +183,9 @@ public class MiraiServer {
//robot.network.tryLogin$mirai_core().whenComplete((state, e) -> {
if (state == LoginState.SUCCEED) {
Robot.instances.add(robot);
getLogger().info(" Succeed");
getLogger().success(" Login Succeed");
} else {
getLogger().error(" Failed with error " + state);
getLogger().error(" Login Failed with error " + state);
robot.close();
}
// }).get();
......
@file:JvmMultifileClass
@file:JvmName("RobotNetworkHandler")
package net.mamoe.mirai.network
import net.mamoe.mirai.MiraiServer
......@@ -28,7 +29,7 @@ import java.util.*
import java.util.concurrent.CompletableFuture
import java.util.concurrent.ScheduledFuture
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
import javax.imageio.ImageIO
import kotlin.reflect.KClass
......@@ -84,40 +85,32 @@ class RobotNetworkHandler(private val robot: Robot) : Closeable {
//private | internal
internal fun tryLogin(): CompletableFuture<LoginState> = this.tryLogin(500, TimeUnit.MILLISECONDS)
internal fun tryLogin(): CompletableFuture<LoginState> = this.tryLogin(200)
/**
* 仅当 [LoginState] 非 [LoginState.UNKNOWN] 且非 [LoginState.TIMEOUT] 才会调用 [loginHook].
* 如果要输入验证码, 那么会以参数 [LoginState.VERIFICATION_CODE] 调用 [loginHandler], 登录完成后再以 [LoginState.SUCCEED] 调用 [loginHandler]
*
* @param connectingTimeout 连接每个服务器的 timeout
* @param touchingTimeoutMillis 连接每个服务器的 timeout
*/
internal fun tryLogin(connectingTimeout: Long, unit: TimeUnit = TimeUnit.MILLISECONDS): CompletableFuture<LoginState> {
internal fun tryLogin(touchingTimeoutMillis: Long): CompletableFuture<LoginState> {
val ipQueue: LinkedList<String> = LinkedList(Protocol.SERVER_IP)
val future = CompletableFuture<LoginState>()
fun login() {
val ip = ipQueue.poll()
if (ip != null) {
// val future = this@RobotNetworkHandler.socketHandler.touch(ip)
this@RobotNetworkHandler.socketHandler.touch(ip).runCatching {
this@runCatching.get(connectingTimeout, unit).let { state ->
if (state == LoginState.UNKNOWN) {
login()
} else {
future.complete(state)
}
}
}.onFailure {
when (it) {
is TimeoutException -> login()
else -> throw it
}
}
} else {
if (ip == null) {
future.complete(LoginState.UNKNOWN)//所有服务器均返回 UNKNOWN
return
}
this@RobotNetworkHandler.socketHandler.touch(ip, touchingTimeoutMillis).get().let { state ->
if (state == LoginState.UNKNOWN || state == LoginState.TIMEOUT) {
login()
} else {
future.complete(state)
}
}
}
login()
......@@ -182,12 +175,15 @@ class RobotNetworkHandler(private val robot: Robot) : Closeable {
/**
* Start network and touch the server
*/
internal fun touch(serverAddress: String): CompletableFuture<LoginState> {
internal fun touch(serverAddress: String, timeoutMillis: Long): CompletableFuture<LoginState> {
MiraiLogger.info("Connecting server: $serverAddress")
this.loginFuture = CompletableFuture()
socketHandler.serverIP = serverAddress
sendPacket(ClientTouchPacket(robot.account.qqNumber, socketHandler.serverIP))
waitForPacket(ServerTouchResponsePacket::class, timeoutMillis) {
loginFuture!!.complete(LoginState.TIMEOUT)
}
return this.loginFuture!!
}
......@@ -197,7 +193,10 @@ class RobotNetworkHandler(private val robot: Robot) : Closeable {
*/
@ExperimentalUnsignedTypes
internal fun sendPacket(packet: ClientPacket) {
checkNotNull(socket) { "socket closed" }
checkNotNull(socket) { "network closed" }
if (socket!!.isClosed) {
return
}
try {
packet.encodePacket()
......@@ -297,9 +296,8 @@ class RobotNetworkHandler(private val robot: Robot) : Closeable {
*/
private lateinit var sessionResponseDecryptionKey: ByteArray
private var verificationCodeSequence: Int = 1//这两个验证码使用
private var verificationCodeSequence: Int = 0
private var verificationCodeCache: ByteArray? = null//每次包只发一部分验证码来
private var verificationCodeCacheCount: Int = 1//
private lateinit var verificationToken: ByteArray
......@@ -338,18 +336,23 @@ class RobotNetworkHandler(private val robot: Robot) : Closeable {
}
}
is ServerVerificationCodeRepeatPacket -> {//todo 这个名字正确么
this.tgtgtKey = packet.tgtgtKeyUpdate
is ServerVerificationCodeCorrectPacket -> {
this.tgtgtKey = getRandomByteArray(16)
this.token00BA = packet.token00BA
sendPacket(ClientLoginResendPacket3105(robot.account.qqNumber, robot.account.password, this.loginTime, this.loginIP, this.tgtgtKey!!, this.token0825, this.token00BA))
}
is ServerVerificationCodeTransmissionPacket -> {
if (packet is ServerVerificationCodeWrongPacket) {
this.verificationCodeSequence = 0
this.verificationCodeCache = byteArrayOf()
}
this.verificationCodeSequence++
this.verificationCodeCache = this.verificationCodeCache!! + packet.verificationCodePartN
this.verificationToken = packet.verificationToken
this.verificationCodeCacheCount++
this.token00BA = packet.token00BA
......@@ -358,9 +361,10 @@ class RobotNetworkHandler(private val robot: Robot) : Closeable {
if (packet.transmissionCompleted) {
(MiraiServer.getInstance().parentFolder + "VerificationCode.png").writeBytes(this.verificationCodeCache!!)
println(CharImageUtil.createCharImg(ImageIO.read(this.verificationCodeCache!!.inputStream())))
TODO("验证码好了")
} else {
sendPacket(ClientVerificationCodeTransmissionRequestPacket(this.verificationCodeCacheCount, robot.account.qqNumber, this.token0825, this.verificationCodeSequence, this.token00BA))
sendPacket(ClientVerificationCodeTransmissionRequestPacket(packet.count + 1, robot.account.qqNumber, this.token0825, this.verificationCodeSequence, this.token00BA))
}
}
......
......@@ -73,7 +73,7 @@ abstract class ServerPacket(val input: DataInputStream) : Packet {
"00 58" -> ServerHeartbeatResponsePacket(stream)
"00 BA" -> ServerVerificationCodePacket.Encrypted(stream)
"00 BA" -> ServerVerificationCodePacket.Encrypted(stream, idHex)
"00 CE", "00 17" -> ServerEventPacket.Raw.Encrypted(stream, idHex.hexToBytes())
......
......@@ -43,4 +43,9 @@ enum class LoginState {
* 未知. 更换服务器或等几分钟再登录可能解决.
*/
UNKNOWN,
/**
* 超时
*/
TIMEOUT,
}
\ No newline at end of file
......@@ -16,6 +16,8 @@ object MiraiLogger {
infix fun notice(o: Any?) = this.print(o.toString(), LoggerTextFormat.LIGHT_BLUE)
infix fun success(o: Any?) = this.print(o.toString(), LoggerTextFormat.GREEN)
infix fun debug(o: Any?) = this.print(o.toString(), LoggerTextFormat.YELLOW)
infix fun catching(e: Throwable) {
......
......@@ -35,7 +35,7 @@ public class MiraiSettings {
}
this.file = file;
try {
if(file.exists()){
if (!file.exists()) {
if (!file.createNewFile()) {
throw new RuntimeException("cannot create config file " + file);
}
......
......@@ -6,99 +6,61 @@ import net.mamoe.mirai.utils.RobotAccount
import java.util.*
/**
* 筛选掉无法登录(冻结/设备锁/UNKNOWN)的 qq
*
* @author Him188moe
*/
val qqList = "2258868346----123456789.\n" +
"1545483785----yuk7k1dxnf3jn5\n" +
"2948786488----123123123\n" +
"3059674084----qq123456\n" +
"1918079979----123456789.\n" +
"3050478794----18872590321\n" +
"3331537204----123456789.\n" +
"2128659972----123456789.\n" +
"3435376516----abc123456\n" +
"2980527804----a123456\n" +
"2752195782----qq123456789\n" +
"3130257966----13415986622\n" +
"1802730396----123456789\n" +
"3021732783----15866103923\n" +
"306499606----abc123456\n" +
"2893904328----abc123456\n" +
"1765904806----123456789\n" +
"3254202261----15223045268\n" +
"2947707697----abc123456\n" +
"3500959200----123456789.\n" +
"2169513531----123456789.\n" +
"2983688661----a123456\n" +
"1246882194----pz49779866\n" +
"2315275635----147258369\n" +
"2802294904----123456789\n" +
"2955364492----1234567890\n" +
"1753325115----123456789\n" +
"2642725191----qq123456\n" +
"2152972686----123456789.\n" +
"2845953617----123456789.\n" +
"3329641753----123456789.\n" +
"1458302685----123456789a\n" +
"2351156352----987654321\n" +
"2304786984----fkhwt53787\n" +
"3322756212----123456789.\n" +
"3187253283----123456789.\n" +
"3168715730----147258369\n" +
"2189916732----18831892323\n" +
"2965337631----123456789.\n" +
"1901802165----123456789.\n" +
"414015319----abc123456\n" +
"3400636089----123456789a\n" +
"3530336304----seoua80060\n" +
"3147312971----123456789.\n" +
"3011083526----yp70y9\n" +
"286888078----abc123456\n" +
"3126754112----1234567890\n" +
"2924643025----123123123\n" +
"341870356----ncvhZtQD\n" +
"3358177328----123456789a\n" +
"1396419201----eakuj14475\n" +
"3541159580----123456789.\n" +
"2540245592----1234567890\n" +
"2024802855----123456789.\n" +
"2578309660----1234567890\n" +
"1934965091----123456789.\n" +
"3449408956----a123456789\n" +
"2509348670----123456789.\n" +
"2305961679----123456789.\n" +
"3532858521----123456789.\n" +
"3308276898----123456789a\n" +
"1760897490----123456789\n" +
"2920800012----123123123\n" +
"2923942248----123123123\n" +
"3216600579----13882755274\n" +
"3100259299----qq123456\n" +
"3242723735----1234567890\n" +
"2142733062----123456789.\n" +
"1557689693----123456789\n" +
"3505693439----sb2662vqy6q\n" +
"3231125974----123456789.\n" +
"3433048975----13893690883\n" +
"3168017129----18780999209\n" +
"2922045831----123123123\n" +
"3578152022----a123456789\n" +
"2116254935----147258369\n" +
"3158479284----1234567890\n" +
"3149394424----qq123456789\n" +
"2829521712----123456789.\n" +
"3218671461----123456789.\n" +
"3035873094----123456789a\n" +
"2224518667----147258369\n" +
"3175801590----123456789.\n" +
"3203228181----123456789a\n" +
"3213497536----123456789a\n" +
"3377317115----123456789\n" +
"2672537341----qq123456789\n" +
"2945957617----123123123\n" +
"2763390197----123456789.\n" +
"3322711709----123456789."
val qqList = "2535777366----abc123456\n" +
"2535815148----abc123456\n" +
"2535704896----abc123456\n" +
"2535744882----abc123456\n" +
"2535656918----abc123456\n" +
"2535679286----abc123456\n" +
"2535606374----abc123456\n" +
"2535647743----abc123456\n" +
"2535543049----abc123456\n" +
"2535583893----abc123456\n" +
"2535508338----abc123456\n" +
"2535524178----abc123456\n" +
"2535363077----abc123456\n" +
"2535469090----abc123456\n" +
"2535263758----abc123456\n" +
"2535258328----abc123456\n" +
"2535175332----abc123456\n" +
"2535175855----abc123456\n" +
"2535126490----abc123456\n" +
"2535169081----abc123456\n" +
"2535054551----abc123456\n" +
"2535085068----abc123456\n" +
"2535041182----abc123456\n" +
"2535055583----abc123456\n" +
"2534883752----abc123456\n" +
"2534909231----abc123456\n" +
"2534715278----abc123456\n" +
"2534766467----abc123456\n" +
"2534696956----abc123456\n" +
"2534703892----abc123456\n" +
"2534597961----abc123456\n" +
"2534687923----abc123456\n" +
"2534573690----abc123456\n" +
"2534596747----abc123456\n" +
"2534467863----abc123456\n" +
"2534480141----abc123456\n" +
"2534377951----abc123456\n" +
"2534418547----abc123456\n" +
"2534315990----abc123456\n" +
"2534318348----abc123456\n" +
"2534220616----abc123456\n" +
"2534288430----abc123456\n" +
"2534205633----abc123456\n" +
"2534226589----abc123456\n" +
"2534182470----abc123456\n" +
"2534194558----abc123456\n" +
"2534106061----abc123456\n" +
"2534108283----abc123456\n" +
"2534026460----abc123456\n" +
"2534037598----abc123456\n"
fun main() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment