nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
events.h
Go to the documentation of this file.
1#ifndef NANOMMO_SERVER_EVENTS_H_
2#define NANOMMO_SERVER_EVENTS_H_
3
4#include <optional>
5#include <string>
6#include <string_view>
7#include <vector>
8
9#include "absl/status/status.h"
10#include "absl/time/time.h"
11#include "content/content.h"
12#include "protocol/nanommo.pb.h"
13#include "server/redis.h"
14#include "server/world.h"
15
16namespace nanommo {
17
18/// The Redis stream the worlds add the game's events to, and the recorder
19/// takes them from, into ClickHouse.
20inline constexpr char kEventStream[] = "events";
21
22/// An event as a row for ClickHouse: a line of JSON, as its JSONEachRow format
23/// reads them, with when it happened and in which world, and the name of what
24/// it's about, from the content.
25std::string Row(const Event& event, const Content& content,
26 std::string_view world, absl::Time time);
27
28/// Whether the analytics keep events of the kind. A fight is a hit a second
29/// or so for each player in it, and what the analytics count is the kills.
30bool ForAnalytics(Event::Kind kind);
31
32/// Where the worlds put the game's events, a Redis stream, so that a tick
33/// never waits on the analytics.
34class Events {
35 public:
36 /// The stream keeps about the newest this many, so that it can't fill
37 /// Redis's memory while the recorder's down.
38 static constexpr int kKeep = 1'000'000;
39
40 explicit Events(Redis& redis) : redis_(redis) {}
41
42 /// Adds the rows to the stream, all of them in a single round trip.
43 absl::Status Add(const std::vector<std::string>& rows);
44
45 private:
46 Redis& redis_;
47};
48
49} // namespace nanommo
50
51#endif // NANOMMO_SERVER_EVENTS_H_
Events(Redis &redis)
Definition events.h:40
static constexpr int kKeep
Definition events.h:38
absl::Status Add(const std::vector< std::string > &rows)
Adds the rows to the stream, all of them in a single round trip.
Definition events.cc:121
Definition chat.cc:9
constexpr char kEventStream[]
Definition events.h:20
bool ForAnalytics(Event::Kind kind)
Definition events.cc:101
std::string Row(const Event &event, const Content &content, std::string_view world, absl::Time time)
Definition events.cc:77