nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
accounts.h
Go to the documentation of this file.
1#ifndef NANOMMO_SERVER_ACCOUNTS_H_
2#define NANOMMO_SERVER_ACCOUNTS_H_
3
4#include <cstdint>
5#include <string>
6#include <string_view>
7
8#include "absl/status/status.h"
9#include "absl/status/statusor.h"
10#include "server/database.h"
11
12namespace nanommo {
13
14/// An InvalidArgument error says what's wrong, in words for the player.
15absl::Status CheckUsername(std::string_view username);
16
17absl::Status CheckPassword(std::string_view password);
18
19struct Account {
20 uint32_t id = 0;
21 std::string password_hash;
22};
23
24class Accounts {
25 public:
26 explicit Accounts(Database& database) : database_(database) {}
27
28 /// Returns an AlreadyExists error if the name is taken.
29 absl::StatusOr<uint32_t> Create(const std::string& username,
30 const std::string& password_hash);
31
32 /// Returns a NotFound error if there's no account by that name.
33 absl::StatusOr<Account> Find(const std::string& username);
34
35 private:
36 Database& database_;
37};
38
39} // namespace nanommo
40
41#endif // NANOMMO_SERVER_ACCOUNTS_H_
absl::StatusOr< Account > Find(const std::string &username)
Returns a NotFound error if there's no account by that name.
Definition accounts.cc:53
Accounts(Database &database)
Definition accounts.h:26
absl::StatusOr< uint32_t > Create(const std::string &username, const std::string &password_hash)
Returns an AlreadyExists error if the name is taken.
Definition accounts.cc:40
Definition chat.cc:9
absl::Status CheckUsername(std::string_view username)
An InvalidArgument error says what's wrong, in words for the player.
Definition accounts.cc:13
absl::Status CheckPassword(std::string_view password)
Definition accounts.cc:28
std::string password_hash
Definition accounts.h:21