nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
inbox.h
Go to the documentation of this file.
1#ifndef NANOMMO_CLIENT_INBOX_H_
2#define NANOMMO_CLIENT_INBOX_H_
3
4#include <cstdint>
5#include <deque>
6#include <optional>
7#include <string_view>
8#include <vector>
9
10#include "absl/status/status.h"
11#include "protocol/nanommo.pb.h"
12#include "protocol/parts.h"
13
14namespace nanommo {
15
16/// What a world server has sent us, filed by kind, for the game to read each
17/// frame: the world, put together from its parts, and the chat, our bag, our
18/// quests, our guild, our trade, our duel, the moves and the events, which
19/// each come on their own. Whatever carries the messages, a socket on a
20/// computer or a WebSocket in a browser, hands them to one of these.
21class Inbox {
22 public:
23 /// Files one of the server's messages, or returns why it isn't one.
24 absl::Status Take(std::string_view message);
25
26 /// A part of the world that came on its own, as a datagram brings it.
27 void Add(const protocol::World& part);
28
29 const protocol::World& world() const { return world_; }
30 /// The newest lines said in the world, oldest first.
31 const std::deque<protocol::Chat>& chat() const { return chat_; }
32 int64_t whole() const { return parts_.whole(); }
33 const std::optional<protocol::Move>& move() const { return move_; }
34 const protocol::Inventory& inventory() const { return inventory_; }
35 const protocol::Quests& quests() const { return quests_; }
36 const protocol::Guild& guild() const { return guild_; }
37 const protocol::Trade& trade() const { return trade_; }
38 const protocol::Duel& duel() const { return duel_; }
39
40 /// The events since the last time, oldest first, handed over once.
41 std::vector<protocol::Event> TakeEvents();
42 /// The guild that asked us to join since the last time, once.
43 std::optional<protocol::GuildInvite> TakeInvite();
44
45 private:
46 Parts parts_;
47 protocol::World world_;
48 std::deque<protocol::Chat> chat_;
49 std::optional<protocol::Move> move_;
50 protocol::Inventory inventory_;
51 protocol::Quests quests_;
52 protocol::Guild guild_;
53 protocol::Trade trade_;
54 protocol::Duel duel_;
55 std::optional<protocol::GuildInvite> invite_;
56 std::vector<protocol::Event> events_;
57};
58
59} // namespace nanommo
60
61#endif // NANOMMO_CLIENT_INBOX_H_
const protocol::Inventory & inventory() const
Definition inbox.h:34
const std::optional< protocol::Move > & move() const
Definition inbox.h:33
void Add(const protocol::World &part)
A part of the world that came on its own, as a datagram brings it.
Definition inbox.cc:51
const protocol::World & world() const
Definition inbox.h:29
std::vector< protocol::Event > TakeEvents()
The events since the last time, oldest first, handed over once.
Definition inbox.cc:56
std::optional< protocol::GuildInvite > TakeInvite()
The guild that asked us to join since the last time, once.
Definition inbox.cc:60
const protocol::Quests & quests() const
Definition inbox.h:35
const protocol::Duel & duel() const
Definition inbox.h:38
const protocol::Guild & guild() const
Definition inbox.h:36
int64_t whole() const
Definition inbox.h:32
absl::Status Take(std::string_view message)
Files one of the server's messages, or returns why it isn't one.
Definition inbox.cc:17
const protocol::Trade & trade() const
Definition inbox.h:37
const std::deque< protocol::Chat > & chat() const
The newest lines said in the world, oldest first.
Definition inbox.h:31
Definition chat.cc:9