Etterna 0.75.1
Loading...
Searching...
No Matches
NetworkSyncManager.h
1#ifndef NetworkSyncManager_H
2#define NetworkSyncManager_H
3
4#include "Etterna/Models/Misc/Difficulty.h"
5#include "Etterna/Models/HighScore/HighScore.h"
6
7#include "Etterna/Models/Network/NetworkConstants.h"
8
9class LoadingWindow;
10class RoomData;
11class Song;
13class NetProtocol;
14
15const int ETTPCVERSION = 5;
16const int NETNUMTAPSCORES = 8;
17
19{
20 public:
21 int name{0};
22 std::string nameStr;
23 int grade;
24 int score;
25 Difficulty difficulty;
26 int tapScores[NETNUMTAPSCORES]; // This will be a const soon enough
27 HighScore hs;
28 std::string playerOptions;
29};
30
31enum NSMANStartupStatus
32{
33 INIT,
34 SUCCESSFUL,
35 NOT_SUCCESSFUL, // also "connection attempt in progress"
36};
37
39#define FOREACH_NSScoreBoardColumn(sc) FOREACH_ENUM(NSScoreBoardColumn, sc)
40
42{
43 public:
44 ChartRequest(const char* ck, const char* requester, int rate)
45 : chartkey(ck)
46 , user(requester)
47 , rate(rate)
48 {
49 }
50 const std::string chartkey;
51 const std::string user; // User that requested this chart
52 const int rate; // rate * 1000
53 void PushSelf(lua_State* L);
54};
55
57{
58 public:
59 float wife;
60 std::string jdgstr;
61};
62
63// Regular pair map except [anyString, 0] is the same key
64class Chat
65{
66 public:
67 std::map<std::pair<std::string, int>, std::vector<std::string>> rawMap;
68
69 auto operator[](const std::pair<std::string, int>& p)
70 -> std::vector<std::string>&
71 {
72 if (p.second == 0) {
73 return rawMap.operator[](std::make_pair(std::string(""), 0));
74 }
75 {
76 return rawMap.operator[](p);
77 }
78 }
79};
80
82{
83 public:
84 NetworkSyncManager(LoadingWindow* ld = nullptr);
86 NetProtocol* curProtocol{ nullptr };
87
88 void ReportHighScore(HighScore* hs, PlayerStageStats& pss);
89 void ReportSongOver();
90
91 // triggered by button presses in gameplay
92 void ReportReplayInput(bool isPress,
93 int col,
94 int row,
95 float fMusicSeconds,
96 float fNoteOffset,
97 int tapNoteType,
98 int tapNoteSubType);
99
100 // triggered by a miss in gameplay
101 void ReportReplayMiss(int col,
102 int row,
103 int tapNoteType,
104 int tapNoteSubType);
105
106 // triggered by completing or dropping a hold in gameplay
107 void ReportReplayHold(int col, int row, int subType);
108
109 // triggered by hitting a mine in gameplay
110 void ReportReplayMine(int row, int col);
111
112 // triggered by a judgment
113 void ReportV2Data(int col, int row, float offset, int tapNoteType);
114
115 void OnMusicSelect();
116 void OffMusicSelect();
117
118 void OnOptions();
119 void OffOptions();
120
121 void OnEval();
122 void OffEval();
123
124 // Request a start; Block until granted.
125 void StartRequest(short position);
126
127 auto GetServerName() const -> std::string;
128
129 void CreateNewRoom(std::string name,
130 std::string desc = "",
131 std::string password = "");
132 bool CreatingRoom();
133 void EnterRoom(std::string name, std::string password = "");
134 void LeaveRoom();
135 std::string GetRoomName();
136
137 void PostStartUp(const std::string& ServerIP);
138
139 auto IsETTP() -> bool;
140
141 void CloseConnection();
142
143 // Notify user if connect attempt was
144 // successful or not.
145 void DisplayStartupStatus() const;
146
147 void Update(float fDeltaTime);
148
149 bool need_to_disconnect = false;
150 bool useSMserver;
151 bool isSMOnline;
152 bool loggedIn;
153 std::string loggedInUsername;
154 std::string loginResponse; // Failure reason
155
156 // [{Tabname, int}] = std::vector<line>
157 Chat chat;
158
159 std::vector<int> m_PlayerStatus;
160 int m_ActivePlayers;
161 std::vector<int> m_ActivePlayer;
162 std::vector<std::string> m_PlayerNames;
163 std::vector<bool> m_PlayerReady;
164 std::vector<std::string> commonpacks;
165
166 // Used for ScreenNetEvaluation
167 std::vector<EndOfGame_PlayerData> m_EvalPlayerData;
168
169 std::set<std::string> lobbyuserlist;
170
171 void SendMPLeaderboardUpdate(float wife, std::string& jdgstr);
172
173 // Used for chatting
174 // 0=lobby (ettp only)
175 void SendChat(const std::string& message,
176 std::string tab = "",
177 int type = 0);
178
180 // Used for song checking/changing
181 std::string m_sMainTitle;
182 std::string m_sArtist;
183 std::string m_sSubTitle;
184 std::string m_sFileHash;
185 std::string chartkey;
186 Song* song{ nullptr };
187 Steps* steps{ nullptr };
188 std::map<std::string, GameplayScore> mpleaderboard;
189 void PushMPLeaderboard(lua_State* L);
190 Difficulty difficulty;
191 int meter;
192 int rate;
194
195 int m_iSelectMode;
196 void SelectUserSong();
197
198 std::string m_sChatText;
199
200 // Used to see if attempt was successful or not.
201 NSMANStartupStatus m_startupStatus;
202
203 void Login(std::string user, std::string pass);
204 void Logout();
205 auto GetServerVersion() -> int;
206
207 std::vector<RoomData> m_Rooms;
208 std::vector<ChartRequest*> requests;
209 std::vector<ChartRequest*> staleRequests;
210
211 bool spectating = false;
212 std::string spectatingWho{};
213
214 // Lua
215 void PushSelf(lua_State* L);
216
217 private:
218 void StartUp();
219 bool ShouldSendMessage(bool requiresLogin = false) const;
220};
221
222extern NetworkSyncManager* NSMAN;
223
224#endif
Definition NetworkSyncManager.h:42
Definition NetworkSyncManager.h:65
Definition NetworkSyncManager.h:19
Definition NetworkSyncManager.h:57
Opens and displays the loading banner.
Definition LoadingWindow.h:9
Definition NetProtocol.h:11
Definition NetworkSyncManager.h:82
Contains statistics for one stage of play - either one song, or a whole course.
Definition PlayerStageStats.h:19
Definition RoomWheel.h:10
Holds all music metadata and steps for one song.
Definition Song.h:65
Holds note information for a Song.
Definition Steps.h:42
The high score that is earned by a player.
Definition HighScore.h:18