1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use crate::codec as cyfs_base;
use crate::*;
use std::collections::HashMap;
use std::net::IpAddr;
pub const CYFS_NAME_MAX_LENGTH: usize = 40;
#[derive(Clone, Copy, Eq, PartialEq, Debug, RawEncode, RawDecode)]
#[repr(u8)]
pub enum NameState {
Normal = 0,
Lock = 1,
Auction = 2, ArrearsAuction = 3, ArrearsAuctionWait = 4, ActiveAuction = 5, }
impl From<i32> for NameState {
fn from(i: i32) -> Self {
match i {
0 => NameState::Normal,
1 => NameState::Lock,
2 => NameState::Auction,
3 => NameState::ArrearsAuction,
4 => NameState::ArrearsAuctionWait,
5 => NameState::ActiveAuction,
_ => {
unimplemented!()
}
}
}
}
#[derive(Clone, Debug, RawEncode, RawDecode)]
pub enum NameLink {
ObjectLink(ObjectId),
OtherNameLink(String),
IPLink(IpAddr),
}
impl std::fmt::Display for NameLink {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
NameLink::ObjectLink(id) => {
write!(f, "link to obj {}", id)
}
NameLink::OtherNameLink(name) => {
write!(f, "link to name {}", name)
}
NameLink::IPLink(ip) => {
write!(f, "link to ip {}", ip)
}
}
}
}
#[derive(Clone, Debug, RawEncode, RawDecode)]
pub struct NameRecord {
pub link: NameLink,
pub user_data: String,
}
#[derive(Clone, Debug, RawEncode, RawDecode)]
pub struct NameInfo {
pub sub_records: HashMap<String, NameRecord>,
pub record: NameRecord,
pub owner: Option<ObjectId>,
}