minetest_protocol/services/
conn.rs1use std::net::SocketAddr;
6
7use crate::peer::peer::Peer;
8use crate::wire::command::*;
9use crate::wire::types::*;
10use anyhow::bail;
11use anyhow::Result;
12
13pub struct MinetestConnection {
15 peer: Peer,
16}
17
18impl MinetestConnection {
19 pub fn new(peer: Peer) -> Self {
20 Self { peer: peer }
21 }
22
23 pub fn remote_addr(&self) -> SocketAddr {
24 self.peer.remote_addr()
25 }
26
27 pub async fn send(&self, command: ToClientCommand) -> Result<()> {
29 self.peer.send(Command::ToClient(command)).await
30 }
31
32 pub async fn send_access_denied(&self, code: AccessDeniedCode) -> Result<()> {
33 self.send(AccessDeniedSpec { code }.into()).await
34 }
35
36 pub async fn recv(&mut self) -> Result<ToServerCommand> {
40 match self.peer.recv().await? {
41 Command::ToServer(command) => Ok(command),
42 Command::ToClient(_) => {
43 bail!("Received wrong direction command from SocketPeer")
44 }
45 }
46 }
47}
48
49pub struct MinetestConnectionRecord {}