-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
97 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
login-server/src/main/kotlin/work/fking/pangya/login/session/HandoverInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package work.fking.pangya.login.session | ||
|
||
data class HandoverInfo( | ||
val targetServerId: Int, | ||
val loginKey: String, | ||
val uid: Int, | ||
val username: String, | ||
val nickname: String, | ||
val characterIffId: Int?, | ||
val characterHairColor: Int? | ||
) |
38 changes: 20 additions & 18 deletions
38
.../fking/pangya/login/auth/SessionClient.kt → ...ing/pangya/login/session/SessionClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,48 @@ | ||
package work.fking.pangya.login.auth | ||
package work.fking.pangya.login.session | ||
|
||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper | ||
import io.lettuce.core.RedisClient | ||
import io.lettuce.core.api.sync.RedisCommands | ||
import work.fking.pangya.login.Player | ||
|
||
class SessionClient( | ||
private val redisCommands: RedisCommands<String, String> | ||
private val redis: RedisCommands<String, String> | ||
) { | ||
private val objectMapper = jacksonObjectMapper() | ||
|
||
constructor(redisClient: RedisClient) : this(redisClient.connect().sync()) | ||
|
||
fun registerSession(player: Player, serverId: Int) { | ||
fun sessionKeyForUsername(username: String): String? { | ||
return redis["session-$username"] | ||
} | ||
|
||
fun registerSession(player: Player) { | ||
redis["session-${player.username}"] = player.sessionKey | ||
} | ||
|
||
fun unregisterSession(player: Player) { | ||
redis.del("session-${player.username}") | ||
} | ||
|
||
fun registerHandoverInfo(player: Player, serverId: Int) { | ||
val nickname = player.nickname | ||
requireNotNull(nickname) { "Cannot register session for ${player.username} because it doesn't have a nickname set" } | ||
|
||
val userInfo = SessionInfo( | ||
val userInfo = HandoverInfo( | ||
targetServerId = serverId, | ||
sessionKey = player.sessionKey, | ||
loginKey = player.loginKey, | ||
uid = player.uid, | ||
username = player.username, | ||
nickname = nickname, | ||
characterIffId = player.pickedCharacterIffId, | ||
characterHairColor = player.pickedCharacterHairColor | ||
) | ||
redisCommands[player.sessionKey] = objectMapper.writeValueAsString(userInfo) | ||
redis[player.loginKey] = objectMapper.writeValueAsString(userInfo) | ||
} | ||
|
||
fun unregisterSession(player: Player) { | ||
fun expireHandoverInfo(player: Player) { | ||
// This is called once the player disconnects from the login server, then, | ||
// the game server has around 10 seconds to retrieve the session before it expires | ||
redisCommands.expire(player.sessionKey, 10) | ||
redis.expire(player.loginKey, 10) | ||
} | ||
|
||
private data class SessionInfo( | ||
val targetServerId: Int, | ||
val sessionKey: String, | ||
val uid: Int, | ||
val username: String, | ||
val nickname: String, | ||
val characterIffId: Int?, | ||
val characterHairColor: Int? | ||
) | ||
} |
8 changes: 8 additions & 0 deletions
8
login-server/src/main/kotlin/work/fking/pangya/login/session/SessionInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package work.fking.pangya.login.session | ||
|
||
import java.time.ZonedDateTime | ||
|
||
data class SessionInfo( | ||
val key: String, | ||
val createdAt: ZonedDateTime = ZonedDateTime.now() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters