Skip to content

Commit 14bdf81

Browse files
committed
Listen for websocket on non-proto servers
1 parent 2733697 commit 14bdf81

File tree

4 files changed

+76
-62
lines changed

4 files changed

+76
-62
lines changed

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ fn main() {
147147
!= Some(true)
148148
{
149149
for server in config::get().pterodactyl_servers.iter().cloned() {
150-
if server.category.is_proto_minecraft() {
150+
if server.category.is_minecraft() {
151151
let protobot_data = protobot_data.clone();
152152
runtime.spawn(async move {
153153
let server_name = server.name.clone();

src/pterodactyl/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ pub struct PterodactylServer {
1313
pub name: String,
1414
pub display_name: String,
1515
pub category: PterodactylServerCategory,
16+
#[serde(default)]
17+
pub allow_commands: bool,
1618
}
1719

1820
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize)]
@@ -31,10 +33,10 @@ impl PterodactylServerCategory {
3133
*self != Self::OtherTechServer
3234
}
3335

34-
pub fn is_proto_minecraft(&self) -> bool {
36+
pub fn is_minecraft(&self) -> bool {
3537
match self {
36-
Self::Smp | Self::Cmp | Self::Copy | Self::Patreon => true,
37-
Self::Protobot | Self::OtherTechServer => false,
38+
Self::Smp | Self::Cmp | Self::Copy | Self::Patreon | Self::OtherTechServer => true,
39+
Self::Protobot => false,
3840
}
3941
}
4042

src/pterodactyl/smp_commands.rs

Lines changed: 65 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -63,69 +63,81 @@ async fn handle_chat_message<H: PteroWebSocketHandle>(
6363
sender: &str,
6464
message: &str,
6565
) -> Result<(), crate::Error> {
66+
let config = config::get();
67+
let Some(server) = config
68+
.pterodactyl_servers
69+
.iter()
70+
.find(|server| server.id == ptero_server_id)
71+
else {
72+
return Ok(());
73+
};
74+
6675
if let Some(command) = message.strip_prefix('!') {
67-
info!("Received command {} from {}", command, sender);
68-
let args: Vec<_> = command.split(' ').collect();
69-
match args[0] {
70-
"s" => {
71-
if args.len() > 1 {
72-
handle
73-
.send_command(&format!(
74-
"scoreboard objectives setdisplay sidebar {}",
75-
args[1]
76-
))
77-
.await?;
78-
} else {
79-
handle
80-
.send_command("scoreboard objectives setdisplay sidebar")
81-
.await?;
82-
}
83-
}
84-
"t" => {
85-
if args.len() > 1 {
86-
handle
87-
.send_command(&format!(
88-
"scoreboard objectives setdisplay list {}",
89-
args[1]
90-
))
91-
.await?;
92-
} else {
93-
handle
94-
.send_command("scoreboard objectives setdisplay list")
95-
.await?;
76+
if server.allow_commands {
77+
info!("Received command {} from {}", command, sender);
78+
let args: Vec<_> = command.split(' ').collect();
79+
match args[0] {
80+
"s" => {
81+
if args.len() > 1 {
82+
handle
83+
.send_command(&format!(
84+
"scoreboard objectives setdisplay sidebar {}",
85+
args[1]
86+
))
87+
.await?;
88+
} else {
89+
handle
90+
.send_command("scoreboard objectives setdisplay sidebar")
91+
.await?;
92+
}
9693
}
97-
}
98-
"backup" => {
99-
create_backup(
100-
ptero_server,
94+
"t" => {
10195
if args.len() > 1 {
102-
Some(args[1..].join(" "))
96+
handle
97+
.send_command(&format!(
98+
"scoreboard objectives setdisplay list {}",
99+
args[1]
100+
))
101+
.await?;
103102
} else {
104-
None
105-
},
106-
)
107-
.await?;
108-
handle
109-
.send_command(
110-
"tellraw @a \"Backup being created. Wait a minute to be sure the backup has finished\"",
103+
handle
104+
.send_command("scoreboard objectives setdisplay list")
105+
.await?;
106+
}
107+
}
108+
"backup" => {
109+
create_backup(
110+
ptero_server,
111+
if args.len() > 1 {
112+
Some(args[1..].join(" "))
113+
} else {
114+
None
115+
},
111116
)
112117
.await?;
118+
handle
119+
.send_command(
120+
"tellraw @a \"Backup being created. Wait a minute to be sure the backup has finished\"",
121+
)
122+
.await?;
123+
}
124+
_ => {}
113125
}
114-
_ => {}
126+
return Ok(());
115127
}
116-
} else {
117-
broadcast_message(
118-
&data.discord_handle,
119-
&data.pterodactyl,
120-
webhook_cache,
121-
ptero_server_id,
122-
Some(sender),
123-
false,
124-
message,
125-
)
126-
.await?;
127128
}
128129

130+
broadcast_message(
131+
&data.discord_handle,
132+
&data.pterodactyl,
133+
webhook_cache,
134+
ptero_server_id,
135+
Some(sender),
136+
false,
137+
message,
138+
)
139+
.await?;
140+
129141
Ok(())
130142
}
131143

src/pterodactyl/whitelist.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ pub(crate) async fn run(
6666
error!("Unknown category {}", category);
6767
return Ok(());
6868
};
69-
if !category.is_proto_minecraft() {
70-
error!("Can only whitelist on Minecraft servers");
69+
if !category.is_proto() || !category.is_minecraft() {
70+
error!("Can only whitelist on ProtoTech Minecraft servers");
7171
return Ok(());
7272
}
7373
whitelist_list(data, category).await?;
@@ -92,7 +92,7 @@ where
9292
.pterodactyl_servers
9393
.iter()
9494
.map(|server| server.category)
95-
.filter(PterodactylServerCategory::is_proto_minecraft)
95+
.filter(|category| category.is_proto() && category.is_minecraft())
9696
.collect();
9797
try_join_all(categories.into_iter().map(whitelist_operation)).await?;
9898
} else {
@@ -102,8 +102,8 @@ where
102102
error!("Unknown category {}", category);
103103
return Ok(());
104104
};
105-
if !category.is_proto_minecraft() {
106-
error!("Can only whitelist on Minecraft servers");
105+
if !category.is_proto() || !category.is_minecraft() {
106+
error!("Can only whitelist on ProtoTech Minecraft servers");
107107
return Ok(());
108108
}
109109
whitelist_operation(category).await?;

0 commit comments

Comments
 (0)