1macro_rules! codes {
7 ($(#[$meta:meta])* $name:ident: $repr:ty { $($variant:ident = $value:literal,)* }) => {
8 $(#[$meta])*
9 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
10 #[non_exhaustive]
11 #[repr($repr)]
12 pub enum $name {
13 $($variant = $value,)*
14 }
15
16 impl $name {
17 #[cfg(test)]
18 pub(crate) const ALL: &[Self] = &[$(Self::$variant,)*];
19
20 pub fn from_code(code: u32) -> Option<Self> {
24 match code {
25 $($value => Some(Self::$variant),)*
26 _ => None,
27 }
28 }
29
30 pub fn code(self) -> u32 {
32 self as u32
33 }
34
35 pub fn name(self) -> &'static str {
37 match self {
38 $(Self::$variant => stringify!($variant),)*
39 }
40 }
41 }
42 };
43}
44
45codes! {
46 ServerCode: u32 {
50 Login = 1,
51 SetListenPort = 2,
52 GetPeerAddress = 3,
53 WatchUser = 5,
54 UnwatchUser = 6,
55 GetStatus = 7,
56 IgnoreUser = 11,
57 UnignoreUser = 12,
58 SayInChatRoom = 13,
59 JoinRoom = 14,
60 LeaveRoom = 15,
61 UserJoinedRoom = 16,
62 UserLeftRoom = 17,
63 ConnectToPeer = 18,
64 PrivateMessage = 22,
65 AcknowledgePrivateMessage = 23,
66 FileSearchRoom = 25,
67 FileSearch = 26,
68 SetOnlineStatus = 28,
69 Ping = 32,
70 SendConnectToken = 33,
71 SendSpeed = 34,
72 SharedFoldersAndFiles = 35,
73 GetUserStats = 36,
74 QueuedDownloads = 40,
75 KickedFromServer = 41,
76 UserSearch = 42,
77 SimilarRecommendations = 50,
78 LikedInterestAdd = 51,
79 LikedInterestRemove = 52,
80 GetPersonalRecommendations = 54,
81 MyRecommendations = 55,
82 GetGlobalRecommendations = 56,
83 GetUserInterests = 57,
84 AdminCommand = 58,
85 PlaceInLineRequest = 59,
86 PlaceInLineResponse = 60,
87 RoomAdded = 62,
88 RoomRemoved = 63,
89 RoomList = 64,
90 ExactFileSearch = 65,
91 GlobalAdminMessage = 66,
92 GlobalUserList = 67,
93 TunneledMessage = 68,
94 PrivilegedUsers = 69,
95 HaveNoParents = 71,
96 ParentsIP = 73,
97 ParentMinSpeed = 83,
98 ParentSpeedRatio = 84,
99 ParentInactivityTimeout = 86,
100 SearchInactivityTimeout = 87,
101 MinimumParentsInCache = 88,
102 DistributedAliveInterval = 90,
103 AddPrivilegedUser = 91,
104 CheckPrivileges = 92,
105 EmbeddedMessage = 93,
106 AcceptChildren = 100,
107 NetInfo = 102,
108 WishlistSearch = 103,
109 WishlistInterval = 104,
110 GetPersonalSimilarUsers = 110,
111 GetInterestRecommendations = 111,
112 GetInterestSimilarUsers = 112,
113 RoomTickers = 113,
114 RoomTickerAdd = 114,
115 RoomTickerRemove = 115,
116 SetRoomTicker = 116,
117 HatedInterestAdd = 117,
118 HatedInterestRemove = 118,
119 RoomSearch = 120,
120 SendUploadSpeed = 121,
121 UserPrivileges = 122,
122 GivePrivileges = 123,
123 NotifyPrivileges = 124,
124 AcknowledgeNotifyPrivileges = 125,
125 BranchLevel = 126,
126 BranchRoot = 127,
127 ChildDepth = 129,
128 DistributedReset = 130,
129 PrivateRoomUsers = 133,
130 PrivateRoomAddUser = 134,
131 PrivateRoomRemoveUser = 135,
132 PrivateRoomDropMembership = 136,
133 PrivateRoomDropOwnership = 137,
134 PrivateRoomUnknown = 138,
135 PrivateRoomAdded = 139,
136 PrivateRoomRemoved = 140,
137 PrivateRoomToggle = 141,
138 NewPassword = 142,
139 PrivateRoomAddOperator = 143,
140 PrivateRoomRemoveOperator = 144,
141 PrivateRoomOperatorAdded = 145,
142 PrivateRoomOperatorRemoved = 146,
143 PrivateRoomOwned = 148,
144 MessageUsers = 149,
145 AskPublicChat = 150,
146 StopPublicChat = 151,
147 PublicChat = 152,
148 RelatedSearch = 153,
149 ExcludedSearchPhrases = 160,
150 CannotConnect = 1001,
151 CannotJoinRoom = 1003,
152 }
153}
154
155codes! {
156 PeerCode: u32 {
161 PrivateMessage = 1,
162 BrowseRequest = 4,
163 BrowseResponse = 5,
164 SearchRequest = 8,
165 SearchResponse = 9,
166 PrivateRoomInvitation = 10,
167 CancelledQueuedTransfer = 14,
168 InfoRequest = 15,
169 InfoResponse = 16,
170 SendConnectToken = 33,
171 MoveDownloadToTop = 34,
172 FolderContentsRequest = 36,
173 FolderContentsResponse = 37,
174 TransferRequest = 40,
175 TransferResponse = 41,
176 UploadPlacehold = 42,
177 QueueDownload = 43,
178 PlaceInQueueResponse = 44,
179 UploadFailed = 46,
180 ExactFileSearchRequest = 47,
181 QueuedDownloads = 48,
182 IndirectFileSearchRequest = 49,
183 UploadDenied = 50,
184 PlaceInQueueRequest = 51,
185 UploadQueueNotification = 52,
186 }
187}
188
189codes! {
190 DistributedCode: u8 {
194 Ping = 0,
195 SearchRequest = 3,
196 BranchLevel = 4,
197 BranchRoot = 5,
198 ChildDepth = 7,
199 EmbeddedMessage = 93,
200 }
201}
202
203codes! {
204 InitCode: u8 {
208 PierceFirewall = 0,
209 PeerInit = 1,
210 }
211}