123 lines
2.8 KiB
Rust
123 lines
2.8 KiB
Rust
use iris::core::util::HashSet;
|
|
|
|
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
|
pub struct RequestUserInfo {
|
|
pub id: UserId,
|
|
}
|
|
|
|
pub type RequestUserInfoResp = UserInfo;
|
|
|
|
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
|
pub struct UserInfo {
|
|
pub username: String,
|
|
}
|
|
|
|
pub type UserId = u64;
|
|
pub type AccountToken = String;
|
|
|
|
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
|
pub struct CreateAccount {
|
|
pub username: String,
|
|
pub password: String,
|
|
pub token: String,
|
|
}
|
|
|
|
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
|
pub enum CreateAccountResp {
|
|
Ok { id: UserId },
|
|
UsernameExists,
|
|
InvalidToken,
|
|
}
|
|
|
|
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
|
pub struct Login {
|
|
pub username: String,
|
|
pub password: String,
|
|
}
|
|
|
|
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
|
pub enum LoginResp {
|
|
Ok { id: UserId },
|
|
UnknownUsername,
|
|
InvalidPassword,
|
|
}
|
|
|
|
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
|
pub struct RequestUsers;
|
|
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
|
pub struct RequestUsersResp {
|
|
pub users: Vec<ServerUser>,
|
|
}
|
|
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
|
pub struct ServerUser {
|
|
pub id: UserId,
|
|
pub username: String,
|
|
}
|
|
|
|
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
|
pub struct RequestFriends;
|
|
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
|
pub struct RequestFriendsResp {
|
|
pub current: HashSet<UserId>,
|
|
pub incoming: HashSet<UserId>,
|
|
pub outgoing: HashSet<UserId>,
|
|
}
|
|
|
|
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
|
pub struct AddFriend {
|
|
pub username: String,
|
|
}
|
|
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
|
pub enum AddFriendResp {
|
|
Ok,
|
|
UnknownUser,
|
|
CannotAddSelf,
|
|
AlreadySent,
|
|
AlreadyFriends,
|
|
}
|
|
|
|
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
|
pub struct RemoveFriend {
|
|
pub id: UserId,
|
|
}
|
|
|
|
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
|
pub struct AnswerFriendRequest {
|
|
pub id: UserId,
|
|
pub action: FriendRequestAction,
|
|
}
|
|
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
|
pub enum FriendRequestAction {
|
|
Accept,
|
|
Deny,
|
|
}
|
|
|
|
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
|
pub struct GenerateToken {
|
|
pub perms: ServerPerms,
|
|
}
|
|
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
|
pub struct GenerateTokenResp {
|
|
pub token: AccountToken,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, bitcode::Encode, bitcode::Decode)]
|
|
pub struct ServerPerms(u32);
|
|
impl ServerPerms {
|
|
pub const NONE: Self = Self(0);
|
|
pub const ACCOUNT_TOKENS: Self = Self(1 << 0);
|
|
pub const ALL: Self = Self(u32::MAX);
|
|
}
|
|
impl ServerPerms {
|
|
pub fn contains(&self, other: Self) -> bool {
|
|
(self.0 & other.0) == other.0
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
|
pub struct NotLoggedIn;
|
|
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
|
pub struct NoPermission;
|
|
#[derive(Debug, bitcode::Encode, bitcode::Decode)]
|
|
pub struct InvalidUser;
|