nanoMMO 0.97.8Test coverage / Every file / client/local_connection.h

Created: 2026-11-26 01:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/client/local_connection.h
Line
Count
Source
1
#ifndef NANOMMO_CLIENT_LOCAL_CONNECTION_H_
2
#define NANOMMO_CLIENT_LOCAL_CONNECTION_H_
3
4
#include <chrono>
5
#include <cstdint>
6
#include <deque>
7
#include <memory>
8
#include <optional>
9
#include <string>
10
#include <vector>
11
12
#include "client/link.h"
13
#include "content/content.h"
14
#include "protocol/nanommo.pb.h"
15
#include "protocol/parts.h"
16
#include "server/inputs.h"
17
#include "server/interest.h"
18
#include "server/world.h"
19
20
namespace nanommo {
21
22
/// A world of the client's own, without a server: the world's library, run
23
/// in the client at the server's tick, for one player, in the first land.
24
/// Nothing is saved, and there's nobody else.
25
class LocalConnection final : public Link {
26
 public:
27
  LocalConnection(const Content& content, std::string name);
28
29
  void Poll() override;
30
  void Send(const protocol::Input& input) override;
31
0
  bool connected() const override { return true; }
32
0
  const protocol::World& world() const override { return shown_; }
33
0
  const std::deque<protocol::Chat>& chat() const override { return chat_; }
34
0
  int64_t whole() const override { return parts_.whole(); }
35
0
  const std::optional<protocol::Move>& move() const override { return move_; }
36
0
  const protocol::Inventory& inventory() const override { return inventory_; }
37
0
  const protocol::Quests& quests() const override { return quests_; }
38
0
  const protocol::Guild& guild() const override { return guild_; }
39
0
  const protocol::Trade& trade() const override { return trade_; }
40
0
  const protocol::Duel& duel() const override { return duel_; }
41
  std::vector<protocol::Event> TakeEvents() override;
42
  std::optional<protocol::GuildInvite> TakeInvite() override;
43
44
 private:
45
  void Tick();
46
  void Show();
47
  void Notify(const std::string& text,
48
              protocol::Channel channel = protocol::CHANNEL_WORLD);
49
  /// A sentence of the world's, as a server sends one.
50
  void Notify(const protocol::Message& message,
51
              protocol::Channel channel = protocol::CHANNEL_WORLD);
52
  void Say(const std::string& name, const std::string& text,
53
           protocol::Channel channel = protocol::CHANNEL_WORLD);
54
  /// Adds a line to the chat, which keeps the newest.
55
  void Add(protocol::Chat line);
56
57
  static constexpr uint32_t kYou = 1;
58
  static constexpr uint32_t kSeed = 1;
59
  static constexpr int kLand = 0;
60
61
  std::shared_ptr<const Content> content_;
62
  World world_;
63
  Inputs inputs_;
64
  Cells npc_cells_;
65
  std::chrono::steady_clock::time_point next_tick_;
66
  int ticks_ = 0;
67
  bool in_gate_ = false;
68
  Parts parts_;
69
  protocol::World shown_;
70
  std::deque<protocol::Chat> chat_;
71
  std::optional<protocol::Move> move_;
72
  protocol::Inventory inventory_;
73
  protocol::Quests quests_;
74
  protocol::Guild guild_;
75
  protocol::Trade trade_;
76
  protocol::Duel duel_;
77
  std::vector<protocol::Event> events_;
78
};
79
80
}  // namespace nanommo
81
82
#endif  // NANOMMO_CLIENT_LOCAL_CONNECTION_H_