added Play state
This commit is contained in:
1 parent
8a5e69f8e3
commit
4b8720efdc
17 files changed
+522
-48
No files matched your search
@@ -1,10 +1,13 @@
|
||||
use std::{rc::Rc, sync::Mutex};
|
||||
|
||||
use crate::protocol::{
|
||||
client::{
|
||||
config::CFinishConfig,
|
||||
login::{CEncryptionRequest, CLoginSuccess},
|
||||
status::{CPingResponse, CStatusResponse},
|
||||
},
|
||||
server::{
|
||||
config::{SAcknowledgeFinishConfig, SClientInformation},
|
||||
handshake::SHandShake,
|
||||
login::{SEncryptionResponse, SLoginAcknowledged, SLoginPluginResponse, SLoginStart},
|
||||
status::{SPingRequest, SStatusRequest},
|
||||
@@ -12,7 +15,7 @@ use crate::protocol::{
|
||||
ConnectionState,
|
||||
};
|
||||
|
||||
use super::Client;
|
||||
use super::{Client, PlayerConfig};
|
||||
|
||||
pub trait ClientPacketProcessor {
|
||||
// Handshake
|
||||
@@ -25,6 +28,9 @@ pub trait ClientPacketProcessor {
|
||||
fn handle_encryption_response(&mut self, encryption_response: SEncryptionResponse);
|
||||
fn handle_plugin_response(&mut self, plugin_response: SLoginPluginResponse);
|
||||
fn handle_login_acknowledged(&mut self, login_acknowledged: SLoginAcknowledged);
|
||||
// Config
|
||||
fn handle_client_information(&mut self, client_information: SClientInformation);
|
||||
fn handle_config_acknowledged(&mut self, config_acknowledged: SAcknowledgeFinishConfig);
|
||||
}
|
||||
|
||||
impl ClientPacketProcessor for Client {
|
||||
@@ -37,9 +43,15 @@ impl ClientPacketProcessor for Client {
|
||||
fn handle_status_request(&mut self, _status_request: SStatusRequest) {
|
||||
dbg!("sending status");
|
||||
|
||||
self.send_packet(CStatusResponse::new(
|
||||
serde_json::to_string(&self.server.status_response).unwrap(),
|
||||
))
|
||||
dbg!("test first");
|
||||
|
||||
let guard = self.server.try_lock().unwrap();
|
||||
dbg!("test");
|
||||
|
||||
let response = serde_json::to_string(&guard.status_response).unwrap();
|
||||
drop(guard);
|
||||
|
||||
self.send_packet(CStatusResponse::new(response));
|
||||
}
|
||||
|
||||
fn handle_ping_request(&mut self, ping_request: SPingRequest) {
|
||||
@@ -53,11 +65,17 @@ impl ClientPacketProcessor for Client {
|
||||
self.name = Some(login_start.name);
|
||||
self.uuid = Some(login_start.uuid);
|
||||
let verify_token: [u8; 4] = rand::random();
|
||||
let public_key_der = &self.server.to_owned().public_key_der;
|
||||
let public_key_der = self
|
||||
.server
|
||||
.to_owned()
|
||||
.lock()
|
||||
.unwrap()
|
||||
.public_key_der
|
||||
.clone(); // todo do not clone
|
||||
let packet = CEncryptionRequest::new(
|
||||
"".into(),
|
||||
public_key_der.len() as i32,
|
||||
public_key_der,
|
||||
&public_key_der,
|
||||
verify_token.len() as i32,
|
||||
&verify_token,
|
||||
false, // TODO
|
||||
@@ -85,4 +103,25 @@ impl ClientPacketProcessor for Client {
|
||||
self.connection_state = ConnectionState::Config;
|
||||
dbg!("login achnowlaged");
|
||||
}
|
||||
fn handle_client_information(&mut self, client_information: SClientInformation) {
|
||||
self.config = Some(PlayerConfig {
|
||||
locale: client_information.locale,
|
||||
view_distance: client_information.view_distance,
|
||||
chat_mode: client_information.chat_mode,
|
||||
chat_colors: client_information.chat_colors,
|
||||
skin_parts: client_information.skin_parts,
|
||||
main_hand: client_information.main_hand,
|
||||
text_filtering: client_information.text_filtering,
|
||||
server_listing: client_information.server_listing,
|
||||
});
|
||||
// We are done with configuring
|
||||
self.send_packet(CFinishConfig::new());
|
||||
}
|
||||
|
||||
fn handle_config_acknowledged(&mut self, config_acknowledged: SAcknowledgeFinishConfig) {
|
||||
dbg!("config acknowledged");
|
||||
self.connection_state = ConnectionState::Play;
|
||||
// generate a player
|
||||
self.server.lock().unwrap().spawn_player(&self.token);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user