Skip to content

Commit

Permalink
Merge pull request #119 from averak/release/v0.5.0
Browse files Browse the repository at this point in the history
Release/v0.5.0
  • Loading branch information
averak authored Jan 28, 2024
2 parents 29cc1fb + c4e4215 commit 4a85604
Show file tree
Hide file tree
Showing 19 changed files with 378 additions and 123 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ codegen:
--java_out=protobuf/src/main/java \
--java-gsync-server_out=protobuf/src/main/java \
--grpc-java_out=protobuf/src/main/java {}
#./gradlew mbGenerate
./gradlew mbGenerate
./gradlew spotlessApply

.PHONY: db-apply
Expand All @@ -56,3 +56,7 @@ check_dependencies:
.PHONY: update_dependencies
update_dependencies:
./gradlew versionCatalogUpdate

.PHONY: run-battle-server
run-battle-server:
kubectl create -f ./infra/k8s/battle-server.yaml
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ For more information, see [Makefile](./Makefile).
* Spring Boot 3.2
* Cloud Spanner
* Redis
* Agones

### Running the application in dev mode

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import net.averak.gsync.adapter.dao.mapper.base.RequiredClientVersionBaseMapper
import net.averak.gsync.core.config.Config
import net.averak.gsync.core.exception.ErrorCode
import net.averak.gsync.core.exception.GsyncException
import net.averak.gsync.domain.model.Platform
import net.averak.gsync.domain.model.Os
import net.averak.gsync.domain.model.Semver
import net.averak.gsync.infrastructure.grpc.player_api.metadata.IncomingHeaderKey
import net.averak.gsync.infrastructure.grpc.player_api.metadata.RequestScope
import org.springframework.core.annotation.Order
Expand All @@ -34,59 +35,44 @@ class ClientVersionInterceptor(
val clientVersion = headers.get(
Metadata.Key.of(IncomingHeaderKey.CLIENT_VERSION.key, Metadata.ASCII_STRING_MARSHALLER),
)
val platform = headers.get(
Metadata.Key.of(IncomingHeaderKey.PLATFORM.key, Metadata.ASCII_STRING_MARSHALLER),
)?.let { Platform.valueOf(it) }
val os = headers.get(
Metadata.Key.of(IncomingHeaderKey.CLIENT_OS.key, Metadata.ASCII_STRING_MARSHALLER),
)?.let { Os.valueOf(it) }

// デバッグモードの場合のみ、不正なクライアントをバイパスする
if ((clientVersion == null || platform == null) && config.debug) {
if ((clientVersion == null || os == null) && config.debug) {
return next.startCall(call, headers)
}

if (!verifyClientVersion(requestScope.gctx.masterVersion, clientVersion, platform)) {
if (!verifyClientVersion(requestScope.gctx.masterVersion, clientVersion, os)) {
throw GsyncException(ErrorCode.CLIENT_VERSION_IS_NOT_SUPPORTED)
}
return next.startCall(call, headers)
}

@Throws(GsyncException::class)
@VisibleForTesting
fun verifyClientVersion(masterVersion: UUID, clientVersion: String?, platform: Platform?): Boolean {
if (clientVersion == null && platform == null) {
fun verifyClientVersion(masterVersion: UUID, clientVersion: String?, os: Os?): Boolean {
if (clientVersion == null && os == null) {
return true
}

if (clientVersion == null) {
throw GsyncException(ErrorCode.CLIENT_VERSION_MUST_BE_SPECIFIED)
}
if (platform == null) {
throw GsyncException(ErrorCode.PLATFORM_MUST_BE_SPECIFIED)
if (os == null) {
throw GsyncException(ErrorCode.CLIENT_OS_MUST_BE_SPECIFIED)
}
// TODO: クライアントバージョン情報は Repository 経由で取得するようにする
val dtos = requiredClientVersionMapper.selectByExample(
RequiredClientVersionExample().apply {
createCriteria().andMasterVersionEqualTo(masterVersion.toString()).andPlatformEqualTo(platform.id.toLong())
createCriteria().andMasterVersionEqualTo(masterVersion.toString()).andOsEqualTo(os.id.toLong())
},
)
if (dtos.isEmpty()) {
throw GsyncException(ErrorCode.REQUIRED_CLIENT_VERSION_DEFINITION_IS_NOT_FOUND)
}

return compareSemver(clientVersion, dtos[0].clientVersion)
}

/**
* semver1 >= semver2 なら true を返す
*
* @param semver1 x.y.z 形式のバージョン文字列
* @param semver2 x.y.z 形式のバージョン文字列
*/
private fun compareSemver(semver1: String, semver2: String): Boolean {
val major1 = semver1.split(".")[0].toInt()
val minor1 = semver1.split(".")[1].toInt()
val patch1 = semver1.split(".")[2].toInt()
val major2 = semver2.split(".")[0].toInt()
val minor2 = semver2.split(".")[1].toInt()
val patch2 = semver2.split(".")[2].toInt()
return major1 > major2 || (major1 == major2 && minor1 > minor2) || (major1 == major2 && minor1 == minor2 && patch1 >= patch2)
return !Semver.parse(clientVersion).lessThan(Semver.parse(dtos[0].clientVersion))
}
}
Loading

0 comments on commit 4a85604

Please sign in to comment.