You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.5 KiB
57 lines
1.5 KiB
use std::net::Ipv4Addr;
|
|
use serde::{Serialize, Deserialize};
|
|
use serde::de::DeserializeOwned;
|
|
use crate::entity::account::UserAccountId;
|
|
use crate::entity::character::CharacterEntityId;
|
|
|
|
#[derive(Debug, Copy, Clone, Serialize, Deserialize, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
|
pub struct ServerId(pub usize);
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
|
pub struct AuthToken(pub String);
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct Ship {
|
|
pub name: String,
|
|
pub ip: Ipv4Addr,
|
|
pub port: u16,
|
|
pub block_count: u32,
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
pub enum LoginMessage {
|
|
SendMail {
|
|
character_id: CharacterEntityId,
|
|
title: String,
|
|
message: String,
|
|
},
|
|
ShipList {
|
|
ships: Vec<Ship>,
|
|
},
|
|
RequestUsers,
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
pub enum ShipMessage {
|
|
Authenticate(AuthToken),
|
|
NewShip(Ship),
|
|
SendMail {
|
|
character_id: CharacterEntityId,
|
|
title: String,
|
|
message: String,
|
|
},
|
|
RequestShipList,
|
|
AddUser(UserAccountId),
|
|
RemoveUser(UserAccountId),
|
|
}
|
|
|
|
|
|
#[async_trait::async_trait]
|
|
pub trait InterserverActor {
|
|
type SendMessage: Serialize;
|
|
type RecvMessage: DeserializeOwned;
|
|
type Error;
|
|
|
|
async fn on_connect(&mut self, id: ServerId) -> Vec<(ServerId, Self::SendMessage)>;
|
|
async fn action(&mut self, id: ServerId, msg: Self::RecvMessage) -> Result<Vec<(ServerId, Self::SendMessage)>, Self::Error>;
|
|
async fn on_disconnect(&mut self, id: ServerId) -> Vec<(ServerId, Self::SendMessage)>;
|
|
}
|