impl some more stuff

This commit is contained in:
Rusty Striker 2025-07-25 17:36:19 +03:00
parent 0d99649e56
commit 6e269c6b1f
Signed by: RustyStriker
GPG key ID: 87E4D691632DFF15
5 changed files with 23 additions and 1 deletions

View file

@ -9,6 +9,7 @@ pub struct LoginRequest {
#[derive(Serialize, Clone, Debug)]
pub struct LoginResult {
pub success: bool,
pub admin: bool,
pub username: String,
// TODO: Figure out what the user needs on successful login to reduce traffic
}

View file

@ -44,6 +44,7 @@ pub enum Request {
amount: usize,
from: usize,
},
/// TODO: Perhaps remove it, as the client should auto get it on login and use GetChatHistory when needed
GetLastMessages {
amount: usize,
},

View file

@ -101,6 +101,7 @@ impl GameServer {
SendTo::User(id.clone()),
api::Response::Login(api::login::LoginResult {
success: true,
admin,
username: login.username.clone(),
}),
));
@ -112,6 +113,7 @@ impl GameServer {
SendTo::User(id.clone()),
api::Response::Login(api::login::LoginResult {
success: false,
admin: false,
username: login.username,
}),
));

View file

@ -130,7 +130,7 @@ async fn handle_socket(
b = brecv.recv() => {
println!("{} trying to log in: {:?}", &temp_id, &b);
if let Ok((to_id, msg)) = b {
if let Response::Login(open_tavern::api::login::LoginResult { success, username }) = &msg {
if let Response::Login(open_tavern::api::login::LoginResult { success, username, admin: _ }) = &msg {
let to_id = to_id.should_send(&temp_id);
if to_id && *success && id.as_ref().map(|id| id == username).unwrap_or(false) {
_ = socket.send(Message::Text(serde_json::to_string(&msg).unwrap_or_default().into())).await;