- add: ability to refresh the current session
- add: delete type to delete character request - add: ability to update key in redis - add: handle alive packet to refresh the session - fix: delete now actually returns the time remaining correctly - fix: character list now has the correct time until character deletion
This commit is contained in:
@@ -41,7 +41,7 @@ impl SessionService for SessionServiceImpl {
|
||||
let session_data = serde_json::to_string(&session).map_err(|_| Status::internal("Failed to serialize session"))?;
|
||||
|
||||
let conn = self.redis.lock().await;
|
||||
conn.set(&session_id.clone(), &session_data, 0).await.map_err(|_| Status::internal("Failed to store session in Redis"))?;
|
||||
conn.set(&session_id.clone(), &session_data, 300).await.map_err(|_| Status::internal("Failed to store session in Redis"))?;
|
||||
|
||||
let response = SessionResponse {
|
||||
session_id,
|
||||
@@ -91,4 +91,29 @@ impl SessionService for SessionServiceImpl {
|
||||
|
||||
Ok(Response::new(Empty {}))
|
||||
}
|
||||
async fn refresh_session(
|
||||
&self,
|
||||
request: Request<GetSessionRequest>,
|
||||
) -> Result<Response<SessionResponse>, Status> {
|
||||
let req = request.into_inner();
|
||||
let conn = self.redis.lock().await;
|
||||
|
||||
if let Some(session_data) = conn.get::<String>(&req.session_id).await.map_err(|_| Status::internal("Failed to fetch session from Redis"))? {
|
||||
let _ = conn.update(&req.session_id, Some(&session_data), Some(300));
|
||||
let session: Session = serde_json::from_str(&session_data).map_err(|_| Status::internal("Failed to deserialize session"))?;
|
||||
|
||||
let response = SessionResponse {
|
||||
session_id: req.session_id,
|
||||
user_id: session.user_id,
|
||||
username: session.username,
|
||||
character_id: session.character_id,
|
||||
login_time: session.login_time,
|
||||
ip_address: session.ip_address,
|
||||
};
|
||||
|
||||
Ok(Response::new(response))
|
||||
} else {
|
||||
Err(Status::not_found("Session not found"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user