nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
characters.h
Go to the documentation of this file.
1#ifndef NANOMMO_SERVER_CHARACTERS_H_
2#define NANOMMO_SERVER_CHARACTERS_H_
3
4#include <cstdint>
5#include <optional>
6#include <string>
7#include <vector>
8
9#include "absl/status/status.h"
10#include "absl/status/statusor.h"
11#include "protocol/nanommo.pb.h"
12#include "server/database.h"
13
14namespace nanommo {
15
16/// An account's characters, which the login server lists, makes and deletes.
17/// Each is in one world, by its id, with a name nobody else in that world has.
18/// What a world saves of them, it saves by that id (Players).
20 public:
21 /// The most each of a character's looks can be, as its column keeps it.
22 static constexpr uint32_t kMostLook = 255;
23
24 explicit Characters(Database& database) : database_(database) {}
25
26 /// All the account's characters, in all the worlds, the oldest first, with
27 /// what they wear, from what MySQL has: what a world has saved in Redis and
28 /// not yet flushed shows a few seconds later.
29 absl::StatusOr<std::vector<protocol::CharacterListing>> List(
30 uint32_t account);
31
32 /// A new character, which gets the starting kit as it first enters its
33 /// world, and looks as the player chose, or, without looks, as its id
34 /// picks. An InvalidArgument error says what's wrong with the name or the
35 /// looks, an AlreadyExists error that it's taken in the world, and a
36 /// ResourceExhausted one that the account has kCharactersPerWorld there
37 /// already.
38 absl::StatusOr<uint32_t> Create(
39 uint32_t account, const std::string& world, const std::string& name,
40 const std::optional<protocol::Looks>& looks = std::nullopt);
41
42 /// Deletes the account's character, with its skills and its bag, or says
43 /// NotFound when the account has no character with that id.
44 absl::Status Delete(uint32_t account, uint32_t id);
45
46 /// The world the account's character is in, or NotFound when the account
47 /// has no character with that id.
48 absl::StatusOr<std::string> WorldOf(uint32_t account, uint32_t id);
49
50 private:
51 Database& database_;
52};
53
54} // namespace nanommo
55
56#endif // NANOMMO_SERVER_CHARACTERS_H_
absl::StatusOr< uint32_t > Create(uint32_t account, const std::string &world, const std::string &name, const std::optional< protocol::Looks > &looks=std::nullopt)
absl::Status Delete(uint32_t account, uint32_t id)
absl::StatusOr< std::vector< protocol::CharacterListing > > List(uint32_t account)
Definition characters.cc:19
static constexpr uint32_t kMostLook
The most each of a character's looks can be, as its column keeps it.
Definition characters.h:22
Characters(Database &database)
Definition characters.h:24
absl::StatusOr< std::string > WorldOf(uint32_t account, uint32_t id)
Definition chat.cc:9