fsd_interface/
errors.rs

1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum FsdMessageParseError {
5    #[error("invalid field count. Expected {0}, found {1}.")]
6    InvalidFieldCount(usize, usize),
7    #[error("{0} is not a valid rating")]
8    InvalidRating(String),
9    #[error("{0} is not a valid protocol revision")]
10    InvalidProtocolRevison(String),
11    #[error("{0} is not a valid flight rules")]
12    InvalidFlightRules(String),
13    #[error("{0} is not a valid simulator type")]
14    InvalidSimulatorType(String),
15    #[error("{0} is not a valid ATC type")]
16    InvalidAtcType(String),
17    #[error("{0} is not a valid time")]
18    InvalidTime(String),
19    #[error("{0} is not a valid minute")]
20    InvalidMinute(String),
21    #[error("{0} is not a valid index")]
22    InvalidIndex(String),
23    #[error("{0} is not a valid ATC frequency")]
24    InvalidFrequency(String),
25    #[error("{0} is not a valid visibility range")]
26    InvalidVisRange(String),
27    #[error("{0} is not a valid lat / long coordinate")]
28    InvalidCoordinate(String),
29    #[error("{0} is not a transponder mode")]
30    InvalidTransponderMode(String),
31    #[error("{0} is not a transponder code")]
32    InvalidTransponderCode(String),
33    #[error("Unable to parse aircraft config: {0}")]
34    InvalidAircraftConfig(String),
35    #[error("{0} is not a valid pitch / bank / heading number")]
36    InvalidPitchBankHeading(String),
37    #[error("{0} is not a valid altitude")]
38    InvalidAltitude(String),
39    #[error("{0} is not a valid altitude difference")]
40    InvalidAltitudeDifference(String),
41    #[error("{0} is not a valid voice capability")]
42    InvalidVoiceCapability(String),
43    #[error("{0} is not a valid speed")]
44    InvalidSpeed(String),
45    #[error("{0} is not a valid client ID")]
46    InvalidClientID(String),
47    #[error("{0} is not a valid version number part")]
48    InvalidVersionNumber(String),
49    #[error("{0} is not a valid nosewheel angle")]
50    InvalidNosewheelAngle(String),
51    #[error("{0} is not a valid position velocity")]
52    InvalidPositionVelocity(String),
53    #[error("Unknown message type: {0}")]
54    UnknownMessageType(String),
55    #[error("{0} is not a valid ping time")]
56    InvalidPingTime(String),
57    #[error("{0} is not a valid server error")]
58    InvalidServerError(String),
59    #[error("{0} is not a valid client query type")]
60    InvalidClientQueryType(String),
61    #[error("{0} is not a valid new ATIS message")]
62    InvalidNewAtisMessage(String),
63    #[error("{0} is not a valid valid ATC status")]
64    InvalidValidAtcStatus(String),
65    #[error("{0} is not a valid valid ATIS line")]
66    InvalidATISLine(String),
67    #[error("{0} is not a valid valid shared state type")]
68    InvalidSharedStateType(String),
69    #[error("{0} is not a valid client capability")]
70    InvalidClientCapability(String),
71    #[error("{0} is not a valid IP addrees")]
72    InvalidIPAddress(String),
73    #[error("{0} is not a valid port")]
74    InvalidPort(String),
75}
76
77/// An error message received from the FSD server
78#[derive(Debug, Clone, Error)]
79pub enum FsdError {
80    /// Attempted to log in with a callsign that is already in use
81    #[error("Callsign in use")]
82    CallsignInUse,
83    /// Attempted to log in with an invalid callsign
84    #[error("Invalid callsign")]
85    InvalidCallsign,
86    /// Client attempted to register itself more than once on server
87    #[error("Already registered")]
88    AlreadyRegistered,
89    /// Packet with invalid syntax sent to the FSD server
90    #[error("Syntax error")]
91    SyntaxError,
92    /// Client attempted to send a server message with the wrong 'from' callsign
93    #[error("Invalid source callsign")]
94    InvalidSourceCallsign,
95    /// Attempted to log into the server with an invalid CID or password
96    #[error("Invalid CID / password")]
97    InvalidCidPassword,
98    /// Attempted to perform an action (e.g. kill, flight plan request) on an invalid callsign
99    #[error("No such callsign as {0}")]
100    NoSuchCallsign(String),
101    /// Attempted to retrieve a flight plan but no flight plan exists for that callsign
102    #[error("No flight plan for {0}")]
103    NoFlightPlan(String),
104    /// Requested a METAR or weather information but no weather profile was found for this location
105    #[error("No weather profile for {0}")]
106    NoWeatherProfile(String),
107    /// Attempted to connect using a protocol version not supported by the server
108    #[error("Invalid protocol revision")]
109    InvalidProtocolRevision,
110    /// Attempted to log in with too high a rating
111    #[error("Requested level too high")]
112    RequestedLevelTooHigh,
113    /// Server is full
114    #[error("Server full")]
115    ServerFull,
116    /// Attemped to log in with a CID that has been suspended
117    #[error("CID has been suspended")]
118    CertificateSuspended,
119    /// Attempted to perform an unauthorised ATC action (such as assume an aircraft)
120    #[error("Invalid control")]
121    InvalidControl,
122    /// Attempted to log in to an ATC position which the user's rating does not allow
123    #[error("Invalid position for rating")]
124    InvalidPositionForRating,
125    /// Connected with a client that is not approved for use on the network
126    #[error("Unauthorised client")]
127    UnauthorisedClient,
128    /// Client did not respond to server's authentication challenge in time
129    #[error("Authentication time out")]
130    AuthTimeOut,
131    /// Other error
132    #[error("Other: {0}")]
133    Other(String),
134}
135impl FsdError {
136    pub fn error_number(&self) -> u8 {
137        match *self {
138            FsdError::CallsignInUse => 1,
139            FsdError::InvalidCallsign => 2,
140            FsdError::AlreadyRegistered => 3,
141            FsdError::SyntaxError => 4,
142            FsdError::InvalidSourceCallsign => 5,
143            FsdError::InvalidCidPassword => 6,
144            FsdError::NoSuchCallsign(_) => 7,
145            FsdError::NoFlightPlan(_) => 8,
146            FsdError::NoWeatherProfile(_) => 9,
147            FsdError::InvalidProtocolRevision => 10,
148            FsdError::RequestedLevelTooHigh => 11,
149            FsdError::ServerFull => 12,
150            FsdError::CertificateSuspended => 13,
151            FsdError::InvalidControl => 14,
152            FsdError::InvalidPositionForRating => 15,
153            FsdError::UnauthorisedClient => 16,
154            FsdError::AuthTimeOut => 17,
155            FsdError::Other(_) => 18,
156        }
157    }
158}