Skip to content

Commit

Permalink
Added RCON support
Browse files Browse the repository at this point in the history
  • Loading branch information
Snowiiii committed Aug 10, 2024
1 parent 50dcbfe commit 414cf31
Show file tree
Hide file tree
Showing 12 changed files with 386 additions and 16 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

![CI](https://github.com/Snowiiii/Pumpkin/actions/workflows/rust.yml/badge.svg)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
![Current version)](https://img.shields.io/badge/current_version-1.21-blue)
![Current version)](https://img.shields.io/badge/current_version-1.21.1-blue)

</div>

Expand All @@ -27,13 +27,10 @@ Pumpkin is currently under heavy development.
### Features (WIP)
- [x] Configuration (toml)
- [x] Server Status/Ping
- [x] Custom maximum player amout
- [x] Custom maximum player amount
- [x] Custom Icon
- [x] Custom Status (MOTD)
- Login
- [x] Authentication
- [x] Encryption
- [x] Packet Compression
- [x] Login
- Player Configuration
- [x] Registries (biome types, paintings, dimensions)
- [x] Server Brand
Expand All @@ -57,6 +54,7 @@ Pumpkin is currently under heavy development.
- [ ] Player Inventory
- [ ] Player Attack
- Server
- [x] RCON
- [x] Inventories
- [x] Chat
- [x] Commands
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-registry/src/chat_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ pub struct ChatType {}

pub struct Decoration {
translation_key: String,
// style: Option,
// style: Option,
parameters: Vec<String>,
}
2 changes: 1 addition & 1 deletion pumpkin-text/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,4 @@ impl Default for TextContent {
fn default() -> Self {
Self::Text { text: "".into() }
}
}
}
2 changes: 2 additions & 0 deletions pumpkin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
toml = "0.8.19"

bytes = "1.7"

rand = "0.8.5"

num-traits = "0.2"
Expand Down
4 changes: 2 additions & 2 deletions pumpkin/src/client/authentication.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::{collections::HashMap, net::IpAddr, time::Duration};
use std::{collections::HashMap, net::IpAddr};

use base64::{engine::general_purpose, Engine};
use num_bigint::BigInt;
use pumpkin_protocol::Property;
use reqwest::{header::CONTENT_TYPE, StatusCode, Url};
use reqwest::{StatusCode, Url};
use serde::{Deserialize, Serialize};
use thiserror::Error;
use uuid::Uuid;
Expand Down
7 changes: 4 additions & 3 deletions pumpkin/src/client/player_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use pumpkin_protocol::{
server::play::{
SChatCommand, SChatMessage, SConfirmTeleport, SPlayerCommand, SPlayerPosition,
SPlayerPositionRotation, SPlayerRotation, SSwingArm,
}, VarInt,
};
},
VarInt,
};
use pumpkin_text::TextComponent;

use crate::{
Expand Down Expand Up @@ -156,7 +157,7 @@ impl Client {
}

pub fn handle_chat_command(&mut self, _server: &mut Server, command: SChatCommand) {
handle_command(&mut CommandSender::Player(self), command.command);
handle_command(&mut CommandSender::Player(self), &command.command);
}

pub fn handle_player_command(&mut self, _server: &mut Server, command: SPlayerCommand) {
Expand Down
7 changes: 6 additions & 1 deletion pumpkin/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub trait Command<'a> {
}

pub enum CommandSender<'a> {
Rcon(&'a mut Vec<String>),
Console,
Player(&'a mut Client),
}
Expand All @@ -33,30 +34,34 @@ impl<'a> CommandSender<'a> {
// TODO: add color and stuff to console
CommandSender::Console => log::info!("{:?}", text.content),
CommandSender::Player(c) => c.send_system_message(text),
CommandSender::Rcon(s) => s.push(format!("{:?}", text.content)),
}
}

pub fn is_player(&mut self) -> bool {
match self {
CommandSender::Console => false,
CommandSender::Player(_) => true,
CommandSender::Rcon(_) => false,
}
}

pub fn is_console(&mut self) -> bool {
match self {
CommandSender::Console => true,
CommandSender::Player(_) => false,
CommandSender::Rcon(_) => true,
}
}
pub fn as_mut_player(&mut self) -> Option<&mut Client> {
match self {
CommandSender::Player(client) => Some(client),
CommandSender::Console => None,
CommandSender::Rcon(_) => None,
}
}
}
pub fn handle_command(sender: &mut CommandSender, command: String) {
pub fn handle_command(sender: &mut CommandSender, command: &str) {
let command = command.to_lowercase();
// an ugly mess i know
if command.starts_with(PumpkinCommand::NAME) {
Expand Down
23 changes: 22 additions & 1 deletion pumpkin/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@ pub struct AdvancedConfiguration {
pub authentication: Authentication,
pub packet_compression: Compression,
pub resource_pack: ResourcePack,
pub rcon: RCONConfig,
}

#[derive(Deserialize, Serialize, Clone)]
pub struct RCONConfig {
pub enabled: bool,
pub ip: String,
pub port: u16,
pub password: String,
}

impl Default for RCONConfig {
fn default() -> Self {
Self {
enabled: false,
ip: "0.0.0.0".to_string(),
port: 25575,
password: "".to_string(),
}
}
}

#[derive(Deserialize, Serialize)]
Expand Down Expand Up @@ -67,6 +87,7 @@ impl Default for AdvancedConfiguration {
commands: Commands::default(),
packet_compression: Compression::default(),
resource_pack: ResourcePack::default(),
rcon: RCONConfig::default(),
}
}
}
Expand Down Expand Up @@ -107,7 +128,7 @@ impl Default for BasicConfiguration {
fn default() -> Self {
Self {
config_version: CURRENT_BASE_VERSION.to_string(),
server_address: "127.0.0.1".to_string(),
server_address: "0.0.0.0".to_string(),
server_port: 25565,
seed: "".to_string(),
max_players: 100000,
Expand Down
11 changes: 10 additions & 1 deletion pumpkin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub mod client;
pub mod commands;
pub mod config;
pub mod entity;
pub mod rcon;
pub mod server;
pub mod util;

Expand All @@ -27,6 +28,8 @@ pub mod util;
async fn main() -> io::Result<()> {
use std::{cell::RefCell, time::Instant};

use rcon::RCONServer;

let time = Instant::now();
let basic_config = BasicConfiguration::load("configuration.toml");

Expand Down Expand Up @@ -58,6 +61,7 @@ async fn main() -> io::Result<()> {
let mut unique_token = Token(SERVER.0 + 1);

let use_console = advanced_configuration.commands.use_console;
let rcon = advanced_configuration.rcon.clone();

let mut connections: HashMap<Token, Rc<RefCell<Client>>> = HashMap::new();

Expand All @@ -73,10 +77,15 @@ async fn main() -> io::Result<()> {
stdin
.read_line(&mut out)
.expect("Failed to read console line");
handle_command(&mut commands::CommandSender::Console, out);
handle_command(&mut commands::CommandSender::Console, &out);
}
});
}
if rcon.enabled {
tokio::spawn(async move {
RCONServer::new(&rcon).await.unwrap();
});
}
loop {
if let Err(err) = poll.poll(&mut events, None) {
if interrupted(&err) {
Expand Down
Loading

0 comments on commit 414cf31

Please sign in to comment.