- add: logout grpc function
- add: logout packet handler - add: connection state and service for storing connection data - add: session service calls to auth-service - fix: compile error on database service due to moved redis cache
This commit is contained in:
@@ -15,17 +15,17 @@ use crate::packets::*;
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::error::Error;
|
||||
use std::net::SocketAddr;
|
||||
use std::sync::Arc;
|
||||
use tokio::net::TcpStream;
|
||||
use tokio::sync::Mutex;
|
||||
use tonic::{Code, Status};
|
||||
use tracing::{debug, error, info, warn};
|
||||
use utils::service_discovery;
|
||||
use crate::connection_service::ConnectionService;
|
||||
use crate::packets::cli_logout_req::CliLogoutReq;
|
||||
|
||||
pub(crate) async fn handle_accept_req(stream: &mut TcpStream, packet: Packet) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
// let request = CliAcceptReq::decode(packet.payload.as_slice());
|
||||
|
||||
// We need to do reply to this packet
|
||||
let data = SrvAcceptReply { result: srv_accept_reply::Result::Accepted, rand_value: 0 };
|
||||
let response_packet = Packet::new(PacketType::PakssAcceptReply, &data)?;
|
||||
|
||||
@@ -39,7 +39,19 @@ pub(crate) async fn handle_join_server_req(stream: &mut TcpStream, packet: Packe
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn handle_login_req(stream: &mut TcpStream, packet: Packet, auth_client: Arc<Mutex<AuthClient>>) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
pub(crate) async fn handle_logout_req(stream: &mut TcpStream, packet: Packet, auth_client: Arc<Mutex<AuthClient>>, connection_service: Arc<ConnectionService>, connection_id: String) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
let request = CliLogoutReq::decode(packet.payload.as_slice());
|
||||
let mut auth_client = auth_client.lock().await;
|
||||
if let Some(mut state) = connection_service.get_connection(&connection_id) {
|
||||
let session_id = state.session_id.clone().unwrap();
|
||||
auth_client.logout(&session_id).await?;
|
||||
Ok(())
|
||||
} else {
|
||||
Err("Unable to find connection state".into())
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn handle_login_req(stream: &mut TcpStream, packet: Packet, auth_client: Arc<Mutex<AuthClient>>, connection_service: Arc<ConnectionService>, connection_id: String, addr: SocketAddr) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
debug!("decoding packet payload of size {}", packet.payload.as_slice().len());
|
||||
let data = CliLoginTokenReq::decode(packet.payload.as_slice())?;
|
||||
debug!("{:?}", data);
|
||||
@@ -56,6 +68,11 @@ pub(crate) async fn handle_login_req(stream: &mut TcpStream, packet: Packet, aut
|
||||
} else {
|
||||
debug!("Successfully logged in");
|
||||
|
||||
if let Some(mut state) = connection_service.get_connection(&connection_id) {
|
||||
state.user_id = Some(response.user_id.parse().unwrap());
|
||||
// auth_client.logout(&session_id).await?;
|
||||
}
|
||||
|
||||
let consul_url = env::var("CONSUL_URL").unwrap_or_else(|_| "http://127.0.0.1:8500".to_string());
|
||||
let servers = service_discovery::get_service_address(&consul_url, "character-service").await.unwrap_or_else(|err| {
|
||||
warn!(err);
|
||||
@@ -125,10 +142,10 @@ pub(crate) async fn handle_server_select_req(stream: &mut TcpStream, packet: Pac
|
||||
|
||||
let data = SrvSrvSelectReply {
|
||||
result: srv_srv_select_reply::Result::Failed,
|
||||
session_id: 0,
|
||||
crypt_val: 0,
|
||||
ip: NullTerminatedString::new(""),
|
||||
port: 0,
|
||||
session_id: 0, // Client should already have this value
|
||||
crypt_val: 0, // This is only for the old encryption
|
||||
ip: NullTerminatedString::new(""), // If this is empty, the client should stay connected (requires client change)
|
||||
port: 0, // See comment about ip above
|
||||
};
|
||||
|
||||
let response_packet = Packet::new(PacketType::PaklcSrvSelectReply, &data)?;
|
||||
|
||||
Reference in New Issue
Block a user