@@ 21,7 21,6 @@ static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
use std::collections::HashMap;
use std::net::IpAddr;
-use std::num::NonZeroUsize;
use crate::mathutil::rot2d;
use crate::ws::{StkTungsteniteServerConfig, StkTungsteniteServerPlugin, WsEvent};
@@ 34,11 33,13 @@ use bevy::{
};
use bevy_rapier2d::prelude::*;
use component::*;
-//use hmac::Mac;
+use hmac::{Hmac, Mac};
+use jwt::VerifyWithKey;
use packet::*;
use part::{HEARTY_THRUST_ENERGY, LANDING_THRUSTER_ENERGY};
use rand::Rng;
use serde::{Deserialize, Serialize};
+use sha2::Sha256;
use starkingdoms_common::SaveModule;
use starkingdoms_common::{pack_savefile, unpack_savefile, SaveData};
use std::f32::consts::PI;
@@ 316,47 317,45 @@ fn on_message(
Packet::ClientLogin {
username,
save,
- jwt: _,
+ jwt,
} => {
// auth
// plz no remove
- /*
- if let Some(token) = jwt {
- let key: Hmac<Sha256> = Hmac::new_from_slice(&app_keys.app_key).unwrap();
- let claims: UserToken = match token.verify_with_key(&key) {
- Ok(c) => c,
- Err(e) => {
- event_queue.push(WsEvent::Send {
- to: *from,
- message: Packet::Message { message_type: MessageType::Error, actor: "SERVER".to_string(), content: format!("Token is invalid or verification failed: {e}. Please log in again, or contact StarKingdoms staff if the problem persists.") }.into(),
- });
- event_queue.push(WsEvent::Close { addr: *from });
- continue;
- }
- };
-
- if claims.permission_level < REQUIRED_PERM_LEVEL {
- event_queue.push(WsEvent::Send {
- to: *from,
- message: Packet::Message { message_type: MessageType::Error, actor: "SERVER".to_string(), content: format!("Permission level {} is too low, {REQUIRED_PERM_LEVEL} is required. If your permissions were just changed, you need to log out and log back in for the change to take effect. If you believe this is a mistake, contact StarKingdoms staff.", claims.permission_level) }.into(),
- });
- event_queue.push(WsEvent::Close { addr: *from });
- continue;
- }
-
- event_queue.push(WsEvent::Send {
- to: *from,
- message: Packet::Message { message_type: MessageType::Server, actor: "StarKingdoms Team".to_string(), content: "Thank you for participating in the StarKingdoms private alpha! Your feedback is essential to improving the game, so please give us any feedback you have in the Discord! <3".to_string() }.into(),
- });
- } else if REQUIRED_PERM_LEVEL != 0 {
- event_queue.push(WsEvent::Send {
- to: *from,
- message: Packet::Message { message_type: MessageType::Error, actor: "SERVER".to_string(), content: "Authentication is required to join this server at the moment. Log in and try again, or try again later.".to_string() }.into(),
- });
- event_queue.push(WsEvent::Close { addr: *from });
- continue;
- }
- */
+ if let Some(token) = jwt {
+ let key: Hmac<Sha256> = Hmac::new_from_slice(&app_keys.app_key).unwrap();
+ let claims: UserToken = match token.verify_with_key(&key) {
+ Ok(c) => c,
+ Err(e) => {
+ event_queue.push(WsEvent::Send {
+ to: *from,
+ message: Packet::Message { message_type: MessageType::Error, actor: "SERVER".to_string(), content: format!("Token is invalid or verification failed: {e}. Please log in again, or contact StarKingdoms staff if the problem persists.") }.into(),
+ });
+ event_queue.push(WsEvent::Close { addr: *from });
+ continue;
+ }
+ };
+
+ if claims.permission_level < REQUIRED_PERM_LEVEL {
+ event_queue.push(WsEvent::Send {
+ to: *from,
+ message: Packet::Message { message_type: MessageType::Error, actor: "SERVER".to_string(), content: format!("Permission level {} is too low, {REQUIRED_PERM_LEVEL} is required. If your permissions were just changed, you need to log out and log back in for the change to take effect. If you believe this is a mistake, contact StarKingdoms staff.", claims.permission_level) }.into(),
+ });
+ event_queue.push(WsEvent::Close { addr: *from });
+ continue;
+ }
+
+ event_queue.push(WsEvent::Send {
+ to: *from,
+ message: Packet::Message { message_type: MessageType::Server, actor: "StarKingdoms Team".to_string(), content: "Thank you for participating in the StarKingdoms private alpha! Your feedback is essential to improving the game, so please give us any feedback you have in the Discord! <3".to_string() }.into(),
+ });
+ } else if REQUIRED_PERM_LEVEL != 0 {
+ event_queue.push(WsEvent::Send {
+ to: *from,
+ message: Packet::Message { message_type: MessageType::Error, actor: "SERVER".to_string(), content: "Authentication is required to join this server at the moment. Log in and try again, or try again later.".to_string() }.into(),
+ });
+ event_queue.push(WsEvent::Close { addr: *from });
+ continue;
+ }
let angle: f32 = {
let mut rng = rand::thread_rng();
rng.gen::<f32>() * std::f32::consts::PI * 2.
@@ 1814,10 1813,6 @@ fn on_position_change(
message: packet.into(),
});
}
- /*let packet = Packet::SaveEligibility { eligible: true };
- for _ in 0..10000 {
- packet_send.send(WsEvent::Broadcast { message: packet.clone().into() });
- }*/
let mut planets = Vec::new();
for (entity, planet_type, transform) in planet_query.iter() {