Merge branch '138-toggle-free-look-with-hotkey' into main/gingo-test
[ryzomcore.git] / ryzom / client / src / far_tp.h
blobbee040478d614f4dc02d4809f01497a459ffc8ed
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef FAR_TP_H
18 #define FAR_TP_H
20 #include "nel/misc/co_task.h"
21 #include <list>
22 #include <string>
23 #include "game_share/security_check.h"
26 class CLoginStateMachine : private NLMISC::CCoTask
29 public:
30 enum TState
32 /// initial state
33 st_start,
34 /// display login screen and options
35 st_login,
36 /// auto login using cmd lien parameters (used with patch reboot)
37 st_auto_login,
38 /// display the shard list
39 st_shard_list,
40 /// lauch the configurator and close ryzom
41 st_start_config,
42 /// run the scan data thread
43 st_scan_data,
44 /// display the eula and wait for validation
45 st_display_eula,
46 /// check the data to determine need for patch
47 st_check_patch,
48 /// display the list of optional patch category for patching
49 st_display_cat,
50 /// display an error
51 st_display_error,
52 /// run the patch process and display progress
53 st_patch,
54 /// terminate the client and quit
55 st_close_client,
56 /// display the reboot screen and wait validation
57 st_reboot_screen,
58 /// restart the client with login bypass params
59 st_restart_client,
60 /// connect to the FS (start the 'in game' mode)
61 st_connect,
62 /// show the outgame browser
63 st_browser_screen,
64 /// ingame state
65 st_ingame,
66 /// leave the current shard (the exit action progress, Far TP part 1.1; Server Hop part 1-2)
67 st_leave_shard,
68 /// let the main loop finish the current frame and leave it (Far TP part 1.2)
69 st_enter_far_tp_main_loop,
70 /// disconnect from the FS (Far TP part 2)
71 st_disconnect,
72 /// connect to a new FS (Far TP & Server Hop part 3.1)
73 st_reconnect_fs,
74 /// after reconnecting, bypass character selection ui & select the same character (Far TP & Server Hop part 3.2)
75 st_reconnect_select_char,
76 /// after reconnecting and receiving ready, send ready (Far TP part 3.3)
77 st_reconnect_ready,
78 /// between global menu exit and sending ready (Server Hop part 3.3)
79 st_exit_global_menu,
80 /// error while reconnecting
81 st_reconnect_error,
82 /// Rate a ring session. should pop a web windows pointing the rate session page
83 st_rate_session,
84 /// create account
85 st_create_account,
86 /// try to login with alternate login system
87 st_alt_login,
88 /// pseudo state to leave the state machine
89 st_end,
90 ///
91 st_unknown
94 /// For displaying
95 static const std::string& toString(TState state);
97 enum TEvent
99 /// the client click the 'quit' button
100 ev_quit,
101 /// the client is connecting without authentication (dev mode)
102 ev_skip_all_login,
103 /// the init is done
104 ev_init_done,
105 /// the client push the 'config' button
106 ev_game_conf,
107 /// the client push the 'scan data' button
108 ev_data_scan,
109 /// the client push the 'scan data' button
110 ev_close_data_scan,
111 /// the login is validated and cookie is received
112 ev_login_ok,
113 /// the login check as failed
114 ev_bad_login,
115 /// the client has selected a shard
116 ev_shard_selected,
117 /// the patch checker says we need to ev_patch_needed
118 ev_patch_needed,
119 /// the patch check says we are clean, no patch needed
120 ev_no_patch,
121 /// the user validate the category screen, patch can begin
122 ev_run_patch,
123 /// the client validate the patch result
124 ev_close_patch,
125 /// Client accept the eula screen
126 ev_accept_eula,
127 /// Client decline the eula screen
128 ev_decline_eula,
129 /// the client valide the reboot message box
130 ev_reboot,
131 /// the ingame session terminates (CONNECTION:SERVER_QUIT_OK msg)
132 ev_ingame_return,
133 /// the far tp main loop is entered
134 ev_far_tp_main_loop_entered,
135 /// the lua script (from web usually) starts the client connection to a shard
136 ev_connect,
137 /// the connection fail for some reason
138 ev_conn_failed,
139 /// the connection was dropped by the server
140 ev_conn_dropped,
141 /// the client enters the game main loop
142 ev_enter_game,
143 // a self reconnetion is complete, get back to outgame menu
144 ev_self_reconnected,
145 /// characters received (CONNECTION:USER_CHARS msg)
146 ev_chars_received,
147 /// characters received but empty (CONNECTION:NO_USER_CHAR msg)
148 ev_no_user_char,
149 /// ready received (CONNECTION:READY msg)
150 ev_ready_received,
151 /// reselect character (CONNECTION:RECO
152 // ev_reselect_char,
153 /// reconnect ok received (CONNECTION:SERVER_RECONNECT_OK msg)
154 ev_reconnect_ok_received,
155 /// global menu exited
156 ev_global_menu_exited,
157 /// The client click the 'relog' button
158 ev_relog,
159 /// the client push the 'create account' button
160 ev_create_account,
161 /// the client push the 'create account' button
162 ev_close_create_account,
163 /// the client want to use alternate login system
164 ev_login_not_alt,
166 ev_unknown
169 /// For displaying
170 static const std::string& toString(TEvent event);
173 private:
174 TState _CurrentState;
175 std::list<TEvent> _NextEvents;
176 public:
178 // Create the state machine with the wanted start.
179 // Note that, because it is a co-task, restarting the state machine after it has finished
180 // require to delete then recreate this object
181 CLoginStateMachine() :
182 _CurrentState(st_start)
187 TState getCurrentState()
189 return _CurrentState;
192 void pushEvent(TEvent eventId);
194 TEvent waitEvent();
197 private:
199 void run();
202 extern CLoginStateMachine LoginSM;
204 void initLoginScreen();
205 void initShardDisplay();
206 void initDataScan();
207 bool initCreateAccount();
208 void initEula();
209 void initPatchCheck();
210 void initCatDisplay();
211 void initAutoLogin();
212 void initAltLogin();
213 void initPatch();
214 //void initWebBrowser();
215 void initReboot();
217 void ConnectToShard();
219 void waitForUserCharReceived();
224 class CFarTP
226 public:
228 // See definition of _URLTable for url binding
229 enum TJoinMode
231 LaunchEditor,
232 JoinSession,
233 JoinMainland,
234 NbJoinModes
237 CFarTP() : _Reason(NULL), _SessionIdToJoinFast(0), _InGameMode(false), _PreviousR2EdEnabled(false), _ReselectingChar(false), _IsServerHopEmbedded(false), _HookedForEditor(false), _DSSDown(false) /*, _SelfReconnecting(false)*/ {}
239 // Get the address of a front-end service via http, then begin Far TP
240 bool requestFarTPToSession(TSessionId sessionId, uint8 charSlot, CFarTP::TJoinMode joinMode, bool bailOutIfSessionVanished);
242 // Ask the EGS to pop the top position if applicable
243 void requestReturnToPreviousSession(TSessionId rejectedSessionId=TSessionId(0));
245 // Store the result of a JoinSession request for the next disconnection request
246 void setJoinSessionResult(TSessionId sessionId, const CSecurityCode& securityCode);
248 // Tell to ignore the next Far TP request, it will be replaced by a Far TP to the edition session (allows to shortcut anim-mainland-edition by anim-edition)
249 void hookNextFarTPForEditor();
251 /// Begin a Character Reselect sequence
252 void requestReconnection();
254 // These states can overlap
255 bool isIngame() const { return _InGameMode; }
256 bool isFarTPInProgress() const;
257 bool isServerHopInProgress() const;
258 bool isLeavingEGS() const { return (LoginSM.getCurrentState() == CLoginStateMachine::st_leave_shard); }
259 bool isLeavingShard() const; // from begin of Far TP to disconnection
260 bool isJoiningShard() const; // from reconnection to game entering
261 bool isReselectingChar() const { return _ReselectingChar; }
262 bool isServerHopEmbedded() const { return _IsServerHopEmbedded; }
263 bool isFastDisconnectGranted() const { return _SessionIdToJoinFast != 0; }
265 // Far TP from the main loop
266 void farTPmainLoop();
267 void writeSecurityCodeForDisconnection(NLMISC::IStream& msgout);
268 void onServerQuitOk();
269 void onServerQuitAbort();
270 void disconnectFromPreviousShard();
271 void connectToNewShard();
272 bool reselectCharacter();
273 void selectCharAndEnter();
274 void sendReady();
275 void onFailure();
276 void onDssDown(bool forceReturn=false);
278 void setIngame() { _InGameMode = true; }
279 void setOutgame() { _InGameMode = false; }
280 void setMainLoopEntered() { setIngame(); _ReselectingChar = false; }
281 void beginEmbeddedServerHop() { _IsServerHopEmbedded = true; setOutgame(); _ReselectingChar = false; }
282 void endEmbeddedServerHop() { _IsServerHopEmbedded = false; setIngame(); _ReselectingChar = true; }
284 void setURLBase(const std::string& urlBase) { _URLBase = urlBase; }
286 private:
288 // called back from session browser after a far tp request
289 void joinSessionResult(uint32 userId, TSessionId sessionId, uint32 result, const std::string &shardAddr, const std::string &participantStatus);
292 std::string *_Reason;
294 static const char *_URLTable[NbJoinModes];
296 std::string _URLBase;
298 TSessionId _SessionIdToJoinFast; // if non 0, fast disconnection allowed to session
299 CSecurityCode _SecurityCodeForDisconnection;
301 bool _InGameMode; // formerly known as EnterWorld
302 bool _PreviousR2EdEnabled;
303 bool _ReselectingChar;
304 bool _IsServerHopEmbedded; // allows to embed a server hop inside a char reselect (e.g. click on Launch Editor of PLAY with a character on a remote shard)
305 bool _HookedForEditor; // allows to Far TP to editor instead of following the next Far TP request
306 bool _DSSDown; // remembers a DSSDown event if occurs during a FarTP
307 // bool _SelfReconnecting; // allows to disconnect after character selection and reconnect until the player can choose another character
311 extern CFarTP FarTP;
313 #endif // FAR_TP_H