Libsaki
Core library of Pancake Mahjong
table_server.h
1 #ifndef SAKI_APP_SERVER_H
2 #define SAKI_APP_SERVER_H
3 
4 #include "table_msg.h"
5 #include "../table/table.h"
6 
7 
8 
9 namespace saki
10 {
11 
12 
13 
15 {
16 public:
17  using Msgs = std::vector<TableMsg>;
18 
19  explicit TableServer(Table::InitConfig config, std::vector<TableObserver *> obs,
20  const TableEnv &env);
21 
22  Msgs start();
23  Msgs action(Who who, const Action &action, int nonce);
24  Msgs resume(Who who);
25 
26  void onTableEvent(const Table &table, const TE::TableStarted &event) final;
27  void onTableEvent(const Table &table, const TE::FirstDealerChosen &event) final;
28  void onTableEvent(const Table &table, const TE::RoundStarted &event) final;
29  void onTableEvent(const Table &table, const TE::Cleaned &event) final;
30  void onTableEvent(const Table &table, const TE::Diced &event) final;
31  void onTableEvent(const Table &table, const TE::Dealt &event) final;
32  void onTableEvent(const Table &table, const TE::Flipped &event) final;
33  void onTableEvent(const Table &table, const TE::Drawn &event) final;
34  void onTableEvent(const Table &table, const TE::Discarded &event) final;
35  void onTableEvent(const Table &table, const TE::RiichiCalled &event) final;
36  void onTableEvent(const Table &table, const TE::RiichiEstablished &event) final;
37  void onTableEvent(const Table &table, const TE::Barked &event) final;
38  void onTableEvent(const Table &table, const TE::RoundEnded &event) final;
39  void onTableEvent(const Table &table, const TE::PointsChanged &event) final;
40  void onTableEvent(const Table &table, const TE::TableEnded &event) final;
41  void onTableEvent(const Table &table, const TE::PoppedUp &event) final;
42 
43  const Table &table() const;
44 
45 private:
46  void pushActivationMsgs();
47  void pushActivationMsg(Who who, bool isResume = false);
48  void pushPointsChanged(const Table &table);
49  void pushActionExpired(Who who);
50  void pushActionIllegal(Who who);
51 
52  void pushPeerMsg(Who who, const char *event, const nlohmann::json &args);
53  void pushBroadcastMsg(const char *event, const nlohmann::json &args);
54  void pushSystemMsg(const char *type, const nlohmann::json &args);
55  Msgs popMsgs();
56 
57  void activateDrawn(nlohmann::json &map, const TableView &view);
58  void activateBark(nlohmann::json &map, const TableView &view);
59  void activateIrsCheck(nlohmann::json &map, const TableView &view);
60 
61 private:
62  Table mTable;
63  Msgs mMsgs;
64  std::array<int, 4> mNonces;
65 };
66 
67 
68 
69 } // namespace saki
70 
71 
72 
73 #endif // SAKI_APP_TABLE_SERVER_H
Definition: table_event.h:60
Definition: table_event.h:82
Definition: table_observer.h:38
Definition: table.h:87
Definition: table_event.h:77
Definition: table_event.h:131
Definition: table_event.h:140
Definition: table_event.h:94
Definition: table_event.h:145
Definition: table_env.h:11
Definition: action.h:27
Definition: ai.cpp:18
Definition: table_event.h:66
Definition: table_event.h:105
Definition: table_event.h:99
Definition: table_view.h:18
Definition: table_event.h:89
Definition: table_event.h:123
Definition: table_event.h:117
Definition: table_event.h:152
Definition: table_server.h:14
Definition: table_event.h:54
Definition: table_event.h:111
Definition: who.h:14