Shamrock: 提供开发者服务支持

Signed-off-by: 白池 <whitechi73@outlook.com>
This commit is contained in:
白池 2024-03-18 21:02:05 +08:00
parent ee5fcc3403
commit d66358a1f3
8 changed files with 57 additions and 7 deletions

View File

@ -30,8 +30,6 @@ class GrpcProcessor(
private val codeGenerator: CodeGenerator, private val codeGenerator: CodeGenerator,
private val logger: KSPLogger private val logger: KSPLogger
): SymbolProcessor { ): SymbolProcessor {
private val subPackage = arrayOf("contact", "core", "file", "friend", "group", "message", "web")
override fun process(resolver: Resolver): List<KSAnnotated> { override fun process(resolver: Resolver): List<KSAnnotated> {
val symbols = resolver.getSymbolsWithAnnotation(Grpc::class.qualifiedName!!) val symbols = resolver.getSymbolsWithAnnotation(Grpc::class.qualifiedName!!)
val actions = (symbols as Sequence<KSFunctionDeclaration>).toList() val actions = (symbols as Sequence<KSFunctionDeclaration>).toList()
@ -77,6 +75,7 @@ class GrpcProcessor(
.addStatement("import io.kritor.file.*") .addStatement("import io.kritor.file.*")
.addStatement("import io.kritor.message.*") .addStatement("import io.kritor.message.*")
.addStatement("import io.kritor.web.*") .addStatement("import io.kritor.web.*")
.addStatement("import io.kritor.developer.*")
.addFunction(funcBuilder.build()) .addFunction(funcBuilder.build())
.addImport("moe.fuqiuluo.symbols", "EMPTY_BYTE_ARRAY") .addImport("moe.fuqiuluo.symbols", "EMPTY_BYTE_ARRAY")
runCatching { runCatching {

View File

@ -28,6 +28,7 @@ class KritorServer(
.addService(EventService) .addService(EventService)
.addService(ForwardMessageService) .addService(ForwardMessageService)
.addService(WebService) .addService(WebService)
.addService(DeveloperService)
.build()!! .build()!!
fun start(block: Boolean = false) { fun start(block: Boolean = false) {

View File

@ -15,7 +15,7 @@ import moe.fuqiuluo.shamrock.config.ActiveTicket
import moe.fuqiuluo.shamrock.config.ShamrockConfig import moe.fuqiuluo.shamrock.config.ShamrockConfig
import qq.service.QQInterfaces import qq.service.QQInterfaces
object Authentication: AuthenticationGrpcKt.AuthenticationCoroutineImplBase() { internal object Authentication: AuthenticationGrpcKt.AuthenticationCoroutineImplBase() {
@Grpc("Authentication", "Auth") @Grpc("Authentication", "Auth")
override suspend fun auth(request: AuthReq): AuthRsp { override suspend fun auth(request: AuthReq): AuthRsp {
if (QQInterfaces.app.account != request.account) { if (QQInterfaces.app.account != request.account) {

View File

@ -33,7 +33,7 @@ import qq.service.contact.ContactHelper
import kotlin.coroutines.resume import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine import kotlin.coroutines.suspendCoroutine
object ContactService: ContactServiceGrpcKt.ContactServiceCoroutineImplBase() { internal object ContactService: ContactServiceGrpcKt.ContactServiceCoroutineImplBase() {
@Grpc("ContactService", "VoteUser") @Grpc("ContactService", "VoteUser")
override suspend fun voteUser(request: VoteUserRequest): VoteUserResponse { override suspend fun voteUser(request: VoteUserRequest): VoteUserResponse {
ContactHelper.voteUser(when(request.accountCase!!) { ContactHelper.voteUser(when(request.accountCase!!) {

View File

@ -0,0 +1,50 @@
package kritor.service
import com.google.protobuf.ByteString
import com.tencent.mobileqq.fe.FEKit
import com.tencent.mobileqq.qsec.qsecdandelionsdk.Dandelion
import io.kritor.developer.DeveloperServiceGrpcKt
import io.kritor.developer.EnergyRequest
import io.kritor.developer.EnergyResponse
import io.kritor.developer.SendPacketRequest
import io.kritor.developer.SendPacketResponse
import io.kritor.developer.SignRequest
import io.kritor.developer.SignResponse
import io.kritor.developer.energyResponse
import io.kritor.developer.sendPacketResponse
import io.kritor.developer.signResponse
import qq.service.QQInterfaces
internal object DeveloperService: DeveloperServiceGrpcKt.DeveloperServiceCoroutineImplBase() {
@Grpc("DeveloperService", "Sign")
override suspend fun sign(request: SignRequest): SignResponse {
return signResponse {
val result = FEKit.getInstance().getSign(request.command, request.buffer.toByteArray(), request.seq, request.uin)
this.sign = ByteString.copyFrom(result.sign)
this.token = ByteString.copyFrom(result.token)
this.extra = ByteString.copyFrom(result.extra)
}
}
@Grpc("DeveloperService", "Energy")
override suspend fun energy(request: EnergyRequest): EnergyResponse {
return energyResponse {
this.result = ByteString.copyFrom(Dandelion.getInstance().fly(request.data, request.salt.toByteArray()))
}
}
@Grpc("DeveloperService", "SendPacket")
override suspend fun sendPacket(request: SendPacketRequest): SendPacketResponse {
return sendPacketResponse {
val fromServiceMsg = QQInterfaces.sendBufferAW(request.command, request.isProtobuf, request.requestBuffer.toByteArray())
if (fromServiceMsg?.wupBuffer == null) {
this.isSuccess = false
} else {
this.isSuccess = true
this.responseBuffer = ByteString.copyFrom(fromServiceMsg.wupBuffer)
}
}
}
}

View File

@ -12,7 +12,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.channelFlow import kotlinx.coroutines.flow.channelFlow
import moe.fuqiuluo.shamrock.internals.GlobalEventTransmitter import moe.fuqiuluo.shamrock.internals.GlobalEventTransmitter
object EventService: EventServiceGrpcKt.EventServiceCoroutineImplBase() { internal object EventService: EventServiceGrpcKt.EventServiceCoroutineImplBase() {
override fun registerActiveListener(request: RequestPushEvent): Flow<EventStructure> { override fun registerActiveListener(request: RequestPushEvent): Flow<EventStructure> {
return channelFlow { return channelFlow {
when(request.type!!) { when(request.type!!) {

View File

@ -11,7 +11,7 @@ import io.kritor.friend.getFriendListResponse
import qq.service.contact.ContactHelper import qq.service.contact.ContactHelper
import qq.service.friend.FriendHelper import qq.service.friend.FriendHelper
object FriendService: FriendServiceGrpcKt.FriendServiceCoroutineImplBase() { internal object FriendService: FriendServiceGrpcKt.FriendServiceCoroutineImplBase() {
@Grpc("FriendService", "GetFriendList") @Grpc("FriendService", "GetFriendList")
override suspend fun getFriendList(request: GetFriendListRequest): GetFriendListResponse { override suspend fun getFriendList(request: GetFriendListRequest): GetFriendListResponse {
val friendList = FriendHelper.getFriendList(if(request.hasRefresh()) request.refresh else false).onFailure { val friendList = FriendHelper.getFriendList(if(request.hasRefresh()) request.refresh else false).onFailure {

View File

@ -35,7 +35,7 @@ import qq.service.QQInterfaces.Companion.app
import qq.service.contact.ContactHelper import qq.service.contact.ContactHelper
import java.io.File import java.io.File
object KritorService: KritorServiceGrpcKt.KritorServiceCoroutineImplBase() { internal object KritorService: KritorServiceGrpcKt.KritorServiceCoroutineImplBase() {
@Grpc("KritorService", "GetVersion") @Grpc("KritorService", "GetVersion")
override suspend fun getVersion(request: GetVersionRequest): GetVersionResponse { override suspend fun getVersion(request: GetVersionRequest): GetVersionResponse {
return getVersionResponse { return getVersionResponse {