pub struct Session { /* private fields */ }
Expand description
The session, that manages the server communication for a character
Implementations§
Source§impl Session
impl Session
Sourcepub fn new(username: &str, password: &str, server: ServerConnection) -> Self
pub fn new(username: &str, password: &str, server: ServerConnection) -> Self
Constructs a new session for a normal (not SSO) account with the
credentials provided. To use this session, you should call login()
to actually find out, if the credentials work and to get the initial
login response
Sourcepub fn new_hashed(
username: &str,
pw_hash: PWHash,
server: ServerConnection,
) -> Self
pub fn new_hashed( username: &str, pw_hash: PWHash, server: ServerConnection, ) -> Self
Does the same as new()
, but takes a hashed password directly
Sourcepub fn server_url(&self) -> &Url
pub fn server_url(&self) -> &Url
Returns a reference to the server URL, that this session is sending requests to
Sourcepub fn has_session_id(&self) -> bool
pub fn has_session_id(&self) -> bool
Checks if this session has ever been able to successfully login to the
server to establish a session id. You should not need to check this, as
login()
should return error on unsuccessful logins, but if you want
to make sure, you can make sure here
Sourcepub async fn login(&mut self) -> Result<Response, SFError>
pub async fn login(&mut self) -> Result<Response, SFError>
Logges in the session by sending a login response to the server and updating the internal cryptography values. If the session is currently logged in, this also clears the existing state beforehand.
§Errors
Look at send_command()
to get a full overview of all the
possible errors
Sourcepub async fn register(
username: &str,
password: &str,
server: ServerConnection,
gender: Gender,
race: Race,
class: Class,
) -> Result<(Self, Response), SFError>
pub async fn register( username: &str, password: &str, server: ServerConnection, gender: Gender, race: Race, class: Class, ) -> Result<(Self, Response), SFError>
Registers a new character on the server. If everything works, the logged in character session and its login response will be returned
§Errors
Look at send_command()
to get a full overview of all the
possible errors
Sourcepub async fn send_command_raw<T: Borrow<Command>>(
&self,
command: T,
) -> Result<Response, SFError>
pub async fn send_command_raw<T: Borrow<Command>>( &self, command: T, ) -> Result<Response, SFError>
The internal version send_command()
. It allows you to send
requests with only a normal ref, because this version does not
update the cryptography settings of this session, if the server
responds with them. If you do not expect the server to send you new
crypto settings, because you only do predictable simple requests (no
login, etc), or you want to update them yourself, because that is
easier to handle for you, you can use this function to increase your
commands/account/sec speed
§Errors
Look at send_command()
to get a full overview of all the
possible errors
Sourcepub async fn send_command<T: Borrow<Command>>(
&mut self,
command: T,
) -> Result<Response, SFError>
pub async fn send_command<T: Borrow<Command>>( &mut self, command: T, ) -> Result<Response, SFError>
Encode and send a command to the server, decrypts and parses its response and returns the response. When this returns an error, the Session might be in an invalid state, so you should login again just to be safe
§Errors
UnsupportedVersion
: Iferror_on_unsupported_version
is set and the server is running an unsupported versionEmptyResponse
: If the servers response was emptyInvalidRequest
: If your response was invalid to send in some wayConnectionError
: If the command could not be send, or the response could not successfully be receivedParsingError
: If the response from the server was unexpected in some wayServerError
: If the server itself responded with an ingame error like “you do not have enough silver to do that”
Sourcepub fn update(&mut self, res: &Response)
pub fn update(&mut self, res: &Response)
Manually updates the cryptography setting of this session with the response provided
Sourcepub fn username(&self) -> &str
pub fn username(&self) -> &str
The username of the character, that this session is responsible for
Sourcepub async fn renew_sso_creds(&mut self) -> Result<(), SFError>
pub async fn renew_sso_creds(&mut self) -> Result<(), SFError>
Retrieves new sso credentials from its sf account. If the account already has new creds stored, these are read, otherwise the account will be logged in again
§Errors
InvalidRequest
: If you call this function with anything other, than an SSO-Session- Other errors, depending on if the session is able to renew the credentials