Used Configuration more often
This commit is contained in:
parent
37cac21899
commit
0632d4a60a
@ -1,7 +1,7 @@
|
||||
server_address = "127.0.0.1"
|
||||
server_port = 25565
|
||||
seed = ""
|
||||
max_plyers = -1
|
||||
max_plyers = 32
|
||||
view_distances = 10
|
||||
simulation_distance = 10
|
||||
resource_pack = ""
|
||||
|
||||
@ -148,7 +148,7 @@ impl ClientPacketProcessor for Client {
|
||||
fn handle_config_acknowledged(
|
||||
&mut self,
|
||||
server: &mut Server,
|
||||
config_acknowledged: SAcknowledgeFinishConfig,
|
||||
_config_acknowledged: SAcknowledgeFinishConfig,
|
||||
) {
|
||||
dbg!("config acknowledged");
|
||||
self.connection_state = ConnectionState::Play;
|
||||
|
||||
@ -21,7 +21,7 @@ use crate::{
|
||||
|
||||
use crate::protocol::ConnectionState;
|
||||
use anyhow::Context;
|
||||
use mio::{event::Event, net::TcpStream, Registry, Token};
|
||||
use mio::{event::Event, net::TcpStream, Token};
|
||||
use packet_decoder::PacketDecoder;
|
||||
use packet_encoder::PacketEncoder;
|
||||
use rsa::Pkcs1v15Encrypt;
|
||||
|
||||
@ -6,8 +6,8 @@ use crate::server::Difficulty;
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct AdvancedConfiguration {
|
||||
liquid_physics: bool,
|
||||
encryption: bool,
|
||||
pub liquid_physics: bool,
|
||||
pub encryption: bool,
|
||||
}
|
||||
|
||||
impl Default for AdvancedConfiguration {
|
||||
@ -24,7 +24,7 @@ pub struct BasicConfiguration {
|
||||
pub server_address: String,
|
||||
pub server_port: u16,
|
||||
pub seed: String,
|
||||
pub max_plyers: i32,
|
||||
pub max_plyers: u32,
|
||||
pub view_distances: u8,
|
||||
pub simulation_distance: u8,
|
||||
pub resource_pack: String,
|
||||
@ -43,7 +43,7 @@ impl Default for BasicConfiguration {
|
||||
server_address: "127.0.0.1".to_string(),
|
||||
server_port: 25565,
|
||||
seed: "".to_string(),
|
||||
max_plyers: -1,
|
||||
max_plyers: 0,
|
||||
view_distances: 10,
|
||||
simulation_distance: 10,
|
||||
resource_pack: "".to_string(),
|
||||
|
||||
@ -1,9 +1,4 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::{
|
||||
client::Client,
|
||||
protocol::{ClientPacket, RawPacket, VarInt},
|
||||
};
|
||||
use crate::protocol::VarInt;
|
||||
|
||||
use super::{Entity, EntityId};
|
||||
|
||||
|
||||
@ -2,8 +2,6 @@ use mio::net::TcpListener;
|
||||
use mio::{Events, Interest, Poll, Token};
|
||||
use std::io::{self};
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use client::interrupted;
|
||||
use configuration::BasicConfiguration;
|
||||
use server::Server;
|
||||
@ -38,7 +36,14 @@ fn main() -> io::Result<()> {
|
||||
let mut events = Events::with_capacity(128);
|
||||
|
||||
// Setup the TCP server socket.
|
||||
let addr = "127.0.0.1:25565".parse().unwrap();
|
||||
|
||||
let addr = format!(
|
||||
"{}:{}",
|
||||
basic_config.server_address, basic_config.server_port
|
||||
)
|
||||
.parse()
|
||||
.unwrap();
|
||||
|
||||
let mut listener = TcpListener::bind(addr)?;
|
||||
|
||||
// Register the server with poll we can receive events for it.
|
||||
@ -52,7 +57,7 @@ fn main() -> io::Result<()> {
|
||||
|
||||
log::info!("You now can connect to the server");
|
||||
|
||||
let mut server = Server::new();
|
||||
let mut server = Server::new((basic_config, advanced_configuration));
|
||||
|
||||
loop {
|
||||
if let Err(err) = poll.poll(&mut events, None) {
|
||||
|
||||
@ -18,7 +18,7 @@ impl ClientPacket for CRegistryData {
|
||||
fn write(&self, bytebuf: &mut crate::protocol::bytebuf::buffer::ByteBuffer) {
|
||||
bytebuf.write_string(&self.registry_id);
|
||||
bytebuf.write_var_int(self.entry_count);
|
||||
// bytebuf.write_array(self.entries);
|
||||
// bytebuf.write_array(self.entries);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1 @@
|
||||
|
||||
@ -1,18 +1,16 @@
|
||||
use std::{
|
||||
borrow::BorrowMut,
|
||||
collections::HashMap,
|
||||
io::Cursor,
|
||||
rc::Rc,
|
||||
sync::atomic::{AtomicI32, Ordering},
|
||||
};
|
||||
|
||||
use base64::{engine::general_purpose, Engine};
|
||||
use mio::{event::Event, net::TcpStream, Poll, Token};
|
||||
use mio::{event::Event, Poll};
|
||||
use rsa::{rand_core::OsRng, traits::PublicKeyParts, RsaPrivateKey, RsaPublicKey};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
client::Client,
|
||||
configuration::{AdvancedConfiguration, BasicConfiguration},
|
||||
entity::{
|
||||
player::{GameMode, Player},
|
||||
Entity, EntityId,
|
||||
@ -41,16 +39,11 @@ pub struct Server {
|
||||
pub difficulty: Difficulty,
|
||||
}
|
||||
|
||||
impl Default for Server {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Server {
|
||||
pub fn new() -> Self {
|
||||
pub fn new(config: (BasicConfiguration, AdvancedConfiguration)) -> Self {
|
||||
let max_players = 20;
|
||||
let status_response = Self::default_response(max_players);
|
||||
let config_clone = &config;
|
||||
let status_response = Self::default_response(config_clone);
|
||||
|
||||
// todo, only create when needed
|
||||
let (public_key, private_key) = Self::generate_keys();
|
||||
@ -65,15 +58,15 @@ impl Server {
|
||||
// 0 is invalid
|
||||
entity_id: 2.into(),
|
||||
world: World::new(),
|
||||
online_mode: true,
|
||||
encryption: true,
|
||||
online_mode: config.0.online_mode,
|
||||
encryption: config.1.encryption,
|
||||
compression_threshold: None, // 256
|
||||
public_key,
|
||||
private_key,
|
||||
max_players,
|
||||
status_response,
|
||||
public_key_der,
|
||||
difficulty: Difficulty::Normal,
|
||||
difficulty: config.0.default_difficulty,
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,10 +77,11 @@ impl Server {
|
||||
poll: &Poll,
|
||||
event: &Event,
|
||||
) -> anyhow::Result<bool> {
|
||||
let _ = poll;
|
||||
// todo, Poll players in every world
|
||||
client.poll(self, event)
|
||||
}
|
||||
//CLIENT KOMMT in den Player
|
||||
|
||||
pub fn spawn_player(&mut self, client: &mut Client) {
|
||||
let player = Player {
|
||||
entity: Entity {
|
||||
@ -128,7 +122,9 @@ impl Server {
|
||||
self.entity_id.fetch_add(1, Ordering::SeqCst)
|
||||
}
|
||||
|
||||
pub fn default_response(max_players: u32) -> StatusResponse {
|
||||
pub fn default_response(
|
||||
config: &(BasicConfiguration, AdvancedConfiguration),
|
||||
) -> StatusResponse {
|
||||
let path = concat!(env!("CARGO_MANIFEST_DIR"), "/icon.png");
|
||||
|
||||
StatusResponse {
|
||||
@ -137,14 +133,14 @@ impl Server {
|
||||
protocol: 767,
|
||||
},
|
||||
players: Players {
|
||||
max: max_players,
|
||||
max: config.0.max_plyers,
|
||||
online: 0,
|
||||
sample: vec![Sample {
|
||||
name: "".into(),
|
||||
id: "".into(),
|
||||
}],
|
||||
},
|
||||
description: "Pumpkin Server".into(),
|
||||
description: config.0.motd.clone(),
|
||||
favicon: Self::load_icon(path),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,13 +1,4 @@
|
||||
use mio::Token;
|
||||
|
||||
use crate::{
|
||||
entity::{
|
||||
player::{GameMode, Player},
|
||||
Entity,
|
||||
},
|
||||
protocol::{client::play::CLogin, VarInt},
|
||||
server::Difficulty,
|
||||
};
|
||||
use crate::entity::player::Player;
|
||||
|
||||
pub struct World {
|
||||
pub players: Vec<Player>,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user