use super::result::{EventResult, ResultedEvent};
use crate::event::PlayerInfo;
pub struct LoginEvent {
pub player: PlayerInfo,
result: LoginResult,
}
impl LoginEvent {
#[must_use]
pub const fn new(player: PlayerInfo) -> Self {
Self {
player,
result: LoginResult::Allow,
}
}
}
#[derive(Debug, Clone)]
pub enum LoginResult {
Allow,
Deny(String),
}
impl EventResult for LoginResult {
fn is_allowed(&self) -> bool {
matches!(self, Self::Allow)
}
}
impl ResultedEvent for LoginEvent {
type Result = LoginResult;
fn result(&self) -> &Self::Result {
&self.result
}
fn set_result(&mut self, result: Self::Result) {
self.result = result;
}
}
pub struct ChooseServerEvent {
pub player: PlayerInfo,
result: ChooseServerResult,
}
impl ChooseServerEvent {
#[must_use]
pub const fn new(player: PlayerInfo) -> Self {
Self {
player,
result: ChooseServerResult::Default,
}
}
}
#[derive(Debug, Clone)]
pub enum ChooseServerResult {
Default,
Override(String),
}
impl EventResult for ChooseServerResult {
fn is_allowed(&self) -> bool {
true }
}
impl ResultedEvent for ChooseServerEvent {
type Result = ChooseServerResult;
fn result(&self) -> &Self::Result {
&self.result
}
fn set_result(&mut self, result: Self::Result) {
self.result = result;
}
}
pub struct ServerSwitchEvent {
pub player: PlayerInfo,
pub from: String,
pub to: String,
result: ServerSwitchResult,
}
impl ServerSwitchEvent {
#[must_use]
pub const fn new(player: PlayerInfo, from: String, to: String) -> Self {
Self {
player,
from,
to,
result: ServerSwitchResult::Allow,
}
}
}
#[derive(Debug, Clone)]
pub enum ServerSwitchResult {
Allow,
Deny(String),
}
impl EventResult for ServerSwitchResult {
fn is_allowed(&self) -> bool {
matches!(self, Self::Allow)
}
}
impl ResultedEvent for ServerSwitchEvent {
type Result = ServerSwitchResult;
fn result(&self) -> &Self::Result {
&self.result
}
fn set_result(&mut self, result: Self::Result) {
self.result = result;
}
}
pub struct ServerConnectedEvent {
pub player: PlayerInfo,
pub server_id: String,
}
impl ServerConnectedEvent {
#[must_use]
pub const fn new(player: PlayerInfo, server_id: String) -> Self {
Self { player, server_id }
}
}
pub struct DisconnectEvent {
pub player: PlayerInfo,
}
impl DisconnectEvent {
#[must_use]
pub const fn new(player: PlayerInfo) -> Self {
Self { player }
}
}
pub struct PingEvent {
pub default_response: serde_json::Value,
pub client_protocol: i32,
result: PingResult,
}
impl PingEvent {
#[must_use]
pub const fn new(default_response: serde_json::Value, client_protocol: i32) -> Self {
Self {
default_response,
client_protocol,
result: PingResult::Default,
}
}
}
#[derive(Debug, Clone)]
pub enum PingResult {
Default,
Override(serde_json::Value),
}
impl EventResult for PingResult {
fn is_allowed(&self) -> bool {
true }
}
impl ResultedEvent for PingEvent {
type Result = PingResult;
fn result(&self) -> &Self::Result {
&self.result
}
fn set_result(&mut self, result: Self::Result) {
self.result = result;
}
}