added basics of an event system
This commit is contained in:
parent
3631b30867
commit
447f8c3169
|
|
@ -0,0 +1,5 @@
|
|||
use crate::event::Event;
|
||||
|
||||
pub(crate) trait IResponder {
|
||||
fn accepts_event<'a, 'b>(&'a self, event: Event<'b>) -> bool;
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
pub enum EventType<'str> {
|
||||
NewConnection,
|
||||
Custom(&'str str)
|
||||
}
|
||||
|
||||
pub struct Event<'str> {
|
||||
Type: EventType<'str>,
|
||||
args: HashMap<&'str str, String>
|
||||
}
|
||||
|
||||
pub struct Builder<'str> {
|
||||
Type: EventType<'str>,
|
||||
args: HashMap<&'str str, String>
|
||||
}
|
||||
|
||||
impl<'str> Builder<'str> {
|
||||
pub(super) fn new(Type: EventType<'str>) -> Builder {
|
||||
Builder {
|
||||
Type,
|
||||
args: HashMap::new()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_arg<T: Into<String>>(mut self, key: &'str str, value: T) -> Self {
|
||||
self.args.insert(key, value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn build(self) -> Event<'str> {
|
||||
Event {
|
||||
Type: self.Type,
|
||||
args: self.args
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
#[path = "IResponder.rs"]
|
||||
mod IResponderMod;
|
||||
mod event;
|
||||
|
||||
pub(crate) use self::{IResponderMod::IResponder};
|
||||
pub use event::{Builder, EventType, Event};
|
||||
|
|
@ -1,11 +1,10 @@
|
|||
// mod chat_manager;
|
||||
mod client;
|
||||
mod client_manager;
|
||||
mod event;
|
||||
mod messages;
|
||||
mod network_manager;
|
||||
mod server;
|
||||
mod lua;
|
||||
mod plugin_manager;
|
||||
pub mod plugin;
|
||||
mod server;
|
||||
|
||||
pub use server::Server;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ use tokio::time::sleep;
|
|||
use crate::plugin::plugin::Plugin;
|
||||
use crate::plugin::plugin_entry::PluginExecutionState::{Paused, Running, Stopped};
|
||||
|
||||
pub type PluginEntryObj = Arc<PluginEntry>;
|
||||
pub(crate) type PluginEntryObj = Arc<PluginEntry>;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Ord, PartialOrd, Eq, PartialEq)]
|
||||
pub enum PluginPermission {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
use crate::event::Event;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
pub trait IPluginInterface {
|
||||
fn get_string<T: Into<String>>() -> T;
|
||||
fn get_next_event(&self) -> Option<Event>;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue