2021-02-16 19:52:38 +00:00
|
|
|
|
|
|
|
use std::fmt;
|
|
|
|
|
2020-12-13 17:40:15 +00:00
|
|
|
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
2020-12-11 23:37:22 +00:00
|
|
|
|
2020-12-13 17:40:15 +00:00
|
|
|
#[derive(Deserialize, Serialize, Debug)]
|
2020-12-11 23:37:22 +00:00
|
|
|
pub enum Action {
|
|
|
|
ServerClose,
|
|
|
|
Print(String),
|
2020-12-13 23:08:15 +00:00
|
|
|
PlayerSendMessage(Uid, String),
|
|
|
|
KillEntity(Uid),
|
2020-12-11 23:37:22 +00:00
|
|
|
}
|
|
|
|
|
2021-02-15 16:38:55 +00:00
|
|
|
#[derive(Deserialize, Serialize, Debug)]
|
|
|
|
pub enum Retreive {
|
|
|
|
GetEntityName(Uid),
|
|
|
|
}
|
|
|
|
|
2020-12-13 17:40:15 +00:00
|
|
|
pub trait Event: Serialize + DeserializeOwned + Send + Sync {
|
2020-12-12 15:56:09 +00:00
|
|
|
type Response: Serialize + DeserializeOwned + Send + Sync;
|
2020-12-11 23:37:22 +00:00
|
|
|
}
|
|
|
|
|
2021-02-16 19:52:38 +00:00
|
|
|
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
|
|
|
|
pub struct Uid(pub u64);
|
|
|
|
|
|
|
|
impl Into<u64> for Uid {
|
|
|
|
fn into(self) -> u64 { self.0 }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<u64> for Uid {
|
|
|
|
fn from(uid: u64) -> Self { Self(uid) }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for Uid {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.0) }
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
|
|
|
|
pub enum GameMode {
|
|
|
|
/// The game is being played in server mode (i.e: the code is running
|
|
|
|
/// server-side)
|
|
|
|
Server,
|
|
|
|
/// The game is being played in client mode (i.e: the code is running
|
|
|
|
/// client-side)
|
|
|
|
Client,
|
|
|
|
/// The game is being played in singleplayer mode (i.e: both client and
|
|
|
|
/// server at once)
|
|
|
|
// To be used later when we no longer start up an entirely new server for singleplayer
|
|
|
|
Singleplayer,
|
|
|
|
}
|
2020-12-12 15:02:58 +00:00
|
|
|
|
2020-12-12 19:26:42 +00:00
|
|
|
pub mod event {
|
|
|
|
use super::*;
|
2020-12-13 17:40:15 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2020-12-12 13:01:54 +00:00
|
|
|
|
2020-12-12 15:02:58 +00:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
|
|
|
|
pub struct ChatCommandEvent {
|
|
|
|
pub command: String,
|
|
|
|
pub command_args: Vec<String>,
|
|
|
|
pub player: Player,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Event for ChatCommandEvent {
|
|
|
|
type Response = Result<Vec<String>, String>;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
|
|
|
|
pub struct Player {
|
2020-12-13 17:11:55 +00:00
|
|
|
pub id: Uid,
|
2020-12-12 15:02:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
|
2020-12-11 23:37:22 +00:00
|
|
|
pub struct PlayerJoinEvent {
|
|
|
|
pub player_name: String,
|
2020-12-13 23:08:15 +00:00
|
|
|
pub player_id: Uid,
|
2020-12-11 23:37:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Event for PlayerJoinEvent {
|
|
|
|
type Response = PlayerJoinResult;
|
|
|
|
}
|
|
|
|
|
2020-12-12 15:02:58 +00:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
|
2020-12-11 23:37:22 +00:00
|
|
|
pub enum PlayerJoinResult {
|
|
|
|
CloseConnection,
|
2020-12-13 17:40:15 +00:00
|
|
|
None,
|
2020-12-11 23:37:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for PlayerJoinResult {
|
2020-12-13 17:40:15 +00:00
|
|
|
fn default() -> Self { Self::None }
|
2020-12-11 23:37:22 +00:00
|
|
|
}
|
|
|
|
|
2020-12-12 15:02:58 +00:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
|
2020-12-12 19:26:42 +00:00
|
|
|
pub struct PluginLoadEvent {
|
2020-12-13 12:27:48 +00:00
|
|
|
pub game_mode: GameMode,
|
2020-12-12 19:26:42 +00:00
|
|
|
}
|
2020-12-11 23:37:22 +00:00
|
|
|
|
|
|
|
impl Event for PluginLoadEvent {
|
|
|
|
type Response = ();
|
|
|
|
}
|
|
|
|
|
|
|
|
// #[derive(Serialize, Deserialize, Debug)]
|
|
|
|
// pub struct EmptyResult;
|
|
|
|
|
|
|
|
// impl Default for PlayerJoinResult {
|
|
|
|
// fn default() -> Self {
|
|
|
|
// Self::None
|
|
|
|
// }
|
|
|
|
// }
|
2020-12-12 13:01:54 +00:00
|
|
|
}
|