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

Commit

Permalink
update kritor
Browse files Browse the repository at this point in the history
  • Loading branch information
Simplxss committed Mar 27, 2024
1 parent 4a396b0 commit c014e85
Show file tree
Hide file tree
Showing 25 changed files with 759 additions and 733 deletions.
7 changes: 4 additions & 3 deletions kritor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@ android {
dependencies {
protobuf(files("kritor/protos"))

implementation("com.google.protobuf:protobuf-java:4.26.0")

implementation(kotlinx("coroutines-core", "1.8.0"))
implementation("com.google.protobuf:protobuf-java:3.25.3")

implementation(grpc("stub", "1.62.2"))
implementation(grpc("kotlin-stub", "1.4.1"))
implementation(grpc("protobuf", "1.62.2"))
implementation(grpc("kotlin-stub", "1.4.1"))
}

protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.25.3"
artifact = "com.google.protobuf:protoc:4.26.0"
}
plugins {
create("grpc") {
Expand Down
26 changes: 7 additions & 19 deletions processor/src/main/java/moe/fuqiuluo/ksp/impl/GrpcProcessor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,9 @@ package moe.fuqiuluo.ksp.impl

import com.google.devtools.ksp.KspExperimental
import com.google.devtools.ksp.getAnnotationsByType
import com.google.devtools.ksp.getClassDeclarationByName
import com.google.devtools.ksp.getJavaClassByName
import com.google.devtools.ksp.getKotlinClassByName
import com.google.devtools.ksp.processing.CodeGenerator
import com.google.devtools.ksp.processing.Dependencies
import com.google.devtools.ksp.processing.KSPLogger
import com.google.devtools.ksp.processing.Resolver
import com.google.devtools.ksp.processing.SymbolProcessor
import com.google.devtools.ksp.processing.*
import com.google.devtools.ksp.symbol.KSAnnotated
import com.google.devtools.ksp.symbol.KSClassDeclaration
import com.google.devtools.ksp.symbol.KSDeclaration
import com.google.devtools.ksp.symbol.KSFunctionDeclaration
import com.google.devtools.ksp.symbol.KSType
import com.google.devtools.ksp.symbol.KSTypeParameter
import com.google.devtools.ksp.symbol.Modifier
import com.google.devtools.ksp.validate
import com.squareup.kotlinpoet.FileSpec
import com.squareup.kotlinpoet.FunSpec
import com.squareup.kotlinpoet.KModifier
Expand Down Expand Up @@ -67,15 +54,16 @@ class GrpcProcessor(
}
funcBuilder.addStatement("return EMPTY_BYTE_ARRAY")
fileSpec
.addStatement("import io.kritor.*")
.addStatement("import io.kritor.authentication.*")
.addStatement("import io.kritor.core.*")
.addStatement("import io.kritor.contact.*")
.addStatement("import io.kritor.group.*")
.addStatement("import io.kritor.friend.*")
.addStatement("import io.kritor.customization.*")
.addStatement("import io.kritor.developer.*")
.addStatement("import io.kritor.file.*")
.addStatement("import io.kritor.friend.*")
.addStatement("import io.kritor.group.*")
.addStatement("import io.kritor.guild.*")
.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
15 changes: 8 additions & 7 deletions xposed/src/main/java/kritor/client/KritorClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ package kritor.client
import com.google.protobuf.ByteString
import io.grpc.ManagedChannel
import io.grpc.ManagedChannelBuilder
import io.kritor.ReverseServiceGrpcKt
import io.kritor.event.*
import io.kritor.ReqCode
import io.kritor.Request
import io.kritor.Response
import io.kritor.common.Request
import io.kritor.common.Response
import io.kritor.event.EventServiceGrpcKt
import io.kritor.event.EventStructure
import io.kritor.event.EventType
import io.kritor.reverse.ReverseServiceGrpcKt
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
Expand Down Expand Up @@ -113,15 +114,15 @@ internal class KritorClient(
val rsp = handleGrpc(request.cmd, request.buf.toByteArray())
senderChannel.emit(Response.newBuilder()
.setCmd(request.cmd)
.setCode(ReqCode.SUCCESS)
.setCode(Response.ResponseCode.SUCCESS)
.setMsg("success")
.setSeq(request.seq)
.setBuf(ByteString.copyFrom(rsp))
.build())
}.onFailure {
senderChannel.emit(Response.newBuilder()
.setCmd(request.cmd)
.setCode(ReqCode.INTERNAL)
.setCode(Response.ResponseCode.INTERNAL)
.setMsg(it.stackTraceToString())
.setSeq(request.seq)
.setBuf(ByteString.EMPTY)
Expand Down
3 changes: 1 addition & 2 deletions xposed/src/main/java/kritor/server/KritorServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class KritorServer(
private val server = Grpc.newServerBuilderForPort(port, InsecureServerCredentials.create())
.executor(Dispatchers.IO.asExecutor())
.intercept(AuthInterceptor)
.addService(Authentication)
.addService(ContactService)
.addService(AuthenticationService)
.addService(CoreService)
.addService(FriendService)
.addService(GroupService)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,19 @@ package kritor.service

import io.grpc.Status
import io.grpc.StatusRuntimeException
import io.kritor.AuthCode
import io.kritor.AuthReq
import io.kritor.AuthRsp
import io.kritor.AuthenticationServiceGrpcKt
import io.kritor.GetAuthStateReq
import io.kritor.GetAuthStateRsp
import io.kritor.authentication.*
import io.kritor.authentication.AuthenticateResponse.AuthenticateResponseCode
import kritor.auth.AuthInterceptor
import moe.fuqiuluo.shamrock.config.ActiveTicket
import moe.fuqiuluo.shamrock.config.ShamrockConfig
import qq.service.QQInterfaces

internal object Authentication: AuthenticationServiceGrpcKt.AuthenticationServiceCoroutineImplBase() {
@Grpc("Authentication", "Auth")
override suspend fun auth(request: AuthReq): AuthRsp {
internal object AuthenticationService: AuthenticationServiceGrpcKt.AuthenticationServiceCoroutineImplBase() {
@Grpc("AuthenticationService", "Authenticate")
override suspend fun authenticate(request: AuthenticateRequest): AuthenticateResponse {
if (QQInterfaces.app.account != request.account) {
return AuthRsp.newBuilder().apply {
code = AuthCode.NO_ACCOUNT
return AuthenticateResponse.newBuilder().apply {
code = AuthenticateResponseCode.NO_ACCOUNT
msg = "No such account"
}.build()
}
Expand All @@ -29,36 +25,36 @@ internal object Authentication: AuthenticationServiceGrpcKt.AuthenticationServic
val ticket = ShamrockConfig.getProperty(activeTicketName + if (index == 0) "" else ".$index", null)
if (ticket.isNullOrEmpty()) {
if (index == 0) {
return AuthRsp.newBuilder().apply {
code = AuthCode.OK
return AuthenticateResponse.newBuilder().apply {
code = AuthenticateResponseCode.OK
msg = "OK"
}.build()
} else {
break
}
} else if (ticket == request.ticket) {
return AuthRsp.newBuilder().apply {
code = AuthCode.OK
return AuthenticateResponse.newBuilder().apply {
code = AuthenticateResponseCode.OK
msg = "OK"
}.build()
}
index++
}

return AuthRsp.newBuilder().apply {
code = AuthCode.NO_TICKET
return AuthenticateResponse.newBuilder().apply {
code = AuthenticateResponseCode.NO_TICKET
msg = "Invalid ticket"
}.build()
}

@Grpc("Authentication", "GetAuthState")
override suspend fun getAuthState(request: GetAuthStateReq): GetAuthStateRsp {
@Grpc("AuthenticationService", "GetAuthenticationState")
override suspend fun getAuthenticationState(request: GetAuthenticationStateRequest): GetAuthenticationStateResponse {
if (request.account != QQInterfaces.app.account) {
throw StatusRuntimeException(Status.CANCELLED.withDescription("No such account"))
}

return GetAuthStateRsp.newBuilder().apply {
isRequiredAuth = AuthInterceptor.getAllTicket().isNotEmpty()
return GetAuthenticationStateResponse.newBuilder().apply {
isRequired = AuthInterceptor.getAllTicket().isNotEmpty()
}.build()
}
}
187 changes: 0 additions & 187 deletions xposed/src/main/java/kritor/service/ContactService.kt

This file was deleted.

Loading

0 comments on commit c014e85

Please sign in to comment.