1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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/>.
20 #include "nel/misc/co_task.h"
23 #include "game_share/security_check.h"
26 class CLoginStateMachine
: private NLMISC::CCoTask
34 /// display login screen and options
36 /// auto login using cmd lien parameters (used with patch reboot)
38 /// display the shard list
40 /// lauch the configurator and close ryzom
42 /// run the scan data thread
44 /// display the eula and wait for validation
46 /// check the data to determine need for patch
48 /// display the list of optional patch category for patching
52 /// run the patch process and display progress
54 /// terminate the client and quit
56 /// display the reboot screen and wait validation
58 /// restart the client with login bypass params
60 /// connect to the FS (start the 'in game' mode)
62 /// show the outgame browser
66 /// leave the current shard (the exit action progress, Far TP part 1.1; Server Hop part 1-2)
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)
72 /// connect to a new FS (Far TP & Server Hop part 3.1)
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)
78 /// between global menu exit and sending ready (Server Hop part 3.3)
80 /// error while reconnecting
82 /// Rate a ring session. should pop a web windows pointing the rate session page
86 /// try to login with alternate login system
88 /// pseudo state to leave the state machine
95 static const std::string
& toString(TState state
);
99 /// the client click the 'quit' button
101 /// the client is connecting without authentication (dev mode)
105 /// the client push the 'config' button
107 /// the client push the 'scan data' button
109 /// the client push the 'scan data' button
111 /// the login is validated and cookie is received
113 /// the login check as failed
115 /// the client has selected a shard
117 /// the patch checker says we need to ev_patch_needed
119 /// the patch check says we are clean, no patch needed
121 /// the user validate the category screen, patch can begin
123 /// the client validate the patch result
125 /// Client accept the eula screen
127 /// Client decline the eula screen
129 /// the client valide the reboot message box
131 /// the ingame session terminates (CONNECTION:SERVER_QUIT_OK msg)
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
137 /// the connection fail for some reason
139 /// the connection was dropped by the server
141 /// the client enters the game main loop
143 // a self reconnetion is complete, get back to outgame menu
145 /// characters received (CONNECTION:USER_CHARS msg)
147 /// characters received but empty (CONNECTION:NO_USER_CHAR msg)
149 /// ready received (CONNECTION:READY msg)
151 /// reselect character (CONNECTION:RECO
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
159 /// the client push the 'create account' button
161 /// the client push the 'create account' button
162 ev_close_create_account
,
163 /// the client want to use alternate login system
170 static const std::string
& toString(TEvent event
);
174 TState _CurrentState
;
175 std::list
<TEvent
> _NextEvents
;
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
);
202 extern CLoginStateMachine LoginSM
;
204 void initLoginScreen();
205 void initShardDisplay();
207 bool initCreateAccount();
209 void initPatchCheck();
210 void initCatDisplay();
211 void initAutoLogin();
214 //void initWebBrowser();
217 void ConnectToShard();
219 void waitForUserCharReceived();
228 // See definition of _URLTable for url binding
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();
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
; }
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