heartbeat fixes + guest support

This commit is contained in:
Luuk van Oijen 2023-11-20 13:33:07 +01:00
parent 4e985bc0e0
commit 5097244c76
4 changed files with 12 additions and 10 deletions

View File

@ -60,8 +60,9 @@ async fn main() {
let new_status = server.get_server_status(); let new_status = server.get_server_status();
if status != new_status { if status != new_status {
trace!("WHAT");
status = new_status; status = new_status;
hb_tx.send(status.clone()); hb_tx.send(status.clone()).await;
} }
} }
} }

View File

@ -40,8 +40,7 @@ pub enum ClientState {
#[derive(Deserialize, Debug, PartialEq, Clone)] #[derive(Deserialize, Debug, PartialEq, Clone)]
pub struct UserData { pub struct UserData {
#[serde(deserialize_with = "deserialize_number_from_string")] pub uid: String,
pub uid: u64,
pub createdAt: String, pub createdAt: String,
pub guest: bool, pub guest: bool,
pub roles: String, pub roles: String,
@ -127,12 +126,14 @@ impl Client {
return Err(ClientError::AuthenticateError.into()); return Err(ClientError::AuthenticateError.into());
} }
let mut json = HashMap::new(); let mut json = HashMap::new();
json.insert("key".to_string(), packet.data_as_string()); let key = packet.data_as_string();
debug!("[AUTH] key: {}", key);
json.insert("key".to_string(), key);
let user_data: UserData = let user_data: UserData =
authentication_request("pkToUser", json) authentication_request("pkToUser", json)
.await .await
.map_err(|e| { .map_err(|e| {
error!("{:?}", e); error!("[AUTH] {:?}", e);
e e
})?; })?;
debug!("user_data: {:?}", user_data); debug!("user_data: {:?}", user_data);

View File

@ -71,7 +71,7 @@ fn load_plugins() -> Vec<Plugin> {
plugins plugins
} }
#[derive(PartialEq, Clone, Debug)] #[derive(PartialEq, Eq, Clone, Debug)]
pub struct ServerStatus { pub struct ServerStatus {
pub player_count: usize, pub player_count: usize,
pub player_list: String, pub player_list: String,
@ -382,7 +382,7 @@ impl Server {
.info .info
.as_ref() .as_ref()
.unwrap(); .unwrap();
(client.username.clone(), client.roles.clone(), client.guest, client.uid) (client.username.clone(), client.roles.clone(), client.guest, client.uid.clone())
}; };
info!("Welcome {name}!"); info!("Welcome {name}!");
joined_names.push(name.clone()); joined_names.push(name.clone());
@ -391,7 +391,7 @@ impl Server {
let (tx, rx) = tokio::sync::oneshot::channel(); let (tx, rx) = tokio::sync::oneshot::channel();
plugin.send_event(PluginBoundPluginEvent::CallEventHandler((ScriptEvent::OnPlayerAuthenticated { name: name.clone(), role: role.clone(), is_guest, identifiers: PlayerIdentifiers { plugin.send_event(PluginBoundPluginEvent::CallEventHandler((ScriptEvent::OnPlayerAuthenticated { name: name.clone(), role: role.clone(), is_guest, identifiers: PlayerIdentifiers {
ip: String::from("not yet implemented"), ip: String::from("not yet implemented"),
beammp_id, beammp_id: beammp_id.clone(),
} }, Some(tx)))).await; } }, Some(tx)))).await;
// TODO: This never returns, because it blocks the entire process function // TODO: This never returns, because it blocks the entire process function
// from running, so it never manages to run the function correctly. // from running, so it never manages to run the function correctly.

View File

@ -30,14 +30,14 @@ pub enum Argument {
#[derive(Debug)] #[derive(Debug)]
pub struct PlayerIdentifiers { pub struct PlayerIdentifiers {
pub ip: String, pub ip: String,
pub beammp_id: u64, pub beammp_id: String,
} }
impl PlayerIdentifiers { impl PlayerIdentifiers {
pub fn to_map(&self) -> HashMap<String, Argument> { pub fn to_map(&self) -> HashMap<String, Argument> {
let mut m = HashMap::new(); let mut m = HashMap::new();
m.insert(String::from("ip"), Argument::String(self.ip.clone())); m.insert(String::from("ip"), Argument::String(self.ip.clone()));
m.insert(String::from("beammp"), Argument::Integer(self.beammp_id as i64)); // TODO: Uhh we could lose data here m.insert(String::from("beammp"), Argument::String(self.beammp_id.clone()));
m m
} }
} }