Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
Shamrock: 提供开发者服务支持
Browse files Browse the repository at this point in the history
Signed-off-by: 白池 <whitechi73@outlook.com>
  • Loading branch information
whitechi73 committed Mar 18, 2024
1 parent ee5fcc3 commit d66358a
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ class GrpcProcessor(
private val codeGenerator: CodeGenerator,
private val logger: KSPLogger
): SymbolProcessor {
private val subPackage = arrayOf("contact", "core", "file", "friend", "group", "message", "web")

override fun process(resolver: Resolver): List<KSAnnotated> {
val symbols = resolver.getSymbolsWithAnnotation(Grpc::class.qualifiedName!!)
val actions = (symbols as Sequence<KSFunctionDeclaration>).toList()
Expand Down Expand Up @@ -77,6 +75,7 @@ class GrpcProcessor(
.addStatement("import io.kritor.file.*")
.addStatement("import io.kritor.message.*")
.addStatement("import io.kritor.web.*")
.addStatement("import io.kritor.developer.*")
.addFunction(funcBuilder.build())
.addImport("moe.fuqiuluo.symbols", "EMPTY_BYTE_ARRAY")
runCatching {
Expand Down
1 change: 1 addition & 0 deletions xposed/src/main/java/kritor/server/KritorServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class KritorServer(
.addService(EventService)
.addService(ForwardMessageService)
.addService(WebService)
.addService(DeveloperService)
.build()!!

fun start(block: Boolean = false) {
Expand Down
2 changes: 1 addition & 1 deletion xposed/src/main/java/kritor/service/Authentication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import moe.fuqiuluo.shamrock.config.ActiveTicket
import moe.fuqiuluo.shamrock.config.ShamrockConfig
import qq.service.QQInterfaces

object Authentication: AuthenticationGrpcKt.AuthenticationCoroutineImplBase() {
internal object Authentication: AuthenticationGrpcKt.AuthenticationCoroutineImplBase() {
@Grpc("Authentication", "Auth")
override suspend fun auth(request: AuthReq): AuthRsp {
if (QQInterfaces.app.account != request.account) {
Expand Down
2 changes: 1 addition & 1 deletion xposed/src/main/java/kritor/service/ContactService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import qq.service.contact.ContactHelper
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine

object ContactService: ContactServiceGrpcKt.ContactServiceCoroutineImplBase() {
internal object ContactService: ContactServiceGrpcKt.ContactServiceCoroutineImplBase() {
@Grpc("ContactService", "VoteUser")
override suspend fun voteUser(request: VoteUserRequest): VoteUserResponse {
ContactHelper.voteUser(when(request.accountCase!!) {
Expand Down
50 changes: 50 additions & 0 deletions xposed/src/main/java/kritor/service/DeveloperService.kt
Original file line number Diff line number Diff line change
@@ -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)
}
}
}

}
2 changes: 1 addition & 1 deletion xposed/src/main/java/kritor/service/EventService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.channelFlow
import moe.fuqiuluo.shamrock.internals.GlobalEventTransmitter

object EventService: EventServiceGrpcKt.EventServiceCoroutineImplBase() {
internal object EventService: EventServiceGrpcKt.EventServiceCoroutineImplBase() {
override fun registerActiveListener(request: RequestPushEvent): Flow<EventStructure> {
return channelFlow {
when(request.type!!) {
Expand Down
2 changes: 1 addition & 1 deletion xposed/src/main/java/kritor/service/FriendService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import io.kritor.friend.getFriendListResponse
import qq.service.contact.ContactHelper
import qq.service.friend.FriendHelper

object FriendService: FriendServiceGrpcKt.FriendServiceCoroutineImplBase() {
internal object FriendService: FriendServiceGrpcKt.FriendServiceCoroutineImplBase() {
@Grpc("FriendService", "GetFriendList")
override suspend fun getFriendList(request: GetFriendListRequest): GetFriendListResponse {
val friendList = FriendHelper.getFriendList(if(request.hasRefresh()) request.refresh else false).onFailure {
Expand Down
2 changes: 1 addition & 1 deletion xposed/src/main/java/kritor/service/KritorService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import qq.service.QQInterfaces.Companion.app
import qq.service.contact.ContactHelper
import java.io.File

object KritorService: KritorServiceGrpcKt.KritorServiceCoroutineImplBase() {
internal object KritorService: KritorServiceGrpcKt.KritorServiceCoroutineImplBase() {
@Grpc("KritorService", "GetVersion")
override suspend fun getVersion(request: GetVersionRequest): GetVersionResponse {
return getVersionResponse {
Expand Down

0 comments on commit d66358a

Please sign in to comment.