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
50 /// run the patch process and display progress
52 /// terminate the client and quit
54 /// display the reboot screen and wait validation
56 /// restart the client with login bypass params
58 /// connect to the FS (start the 'in game' mode)
60 /// show the outgame browser
64 /// leave the current shard (the exit action progress, Far TP part 1.1; Server Hop part 1-2)
66 /// let the main loop finish the current frame and leave it (Far TP part 1.2)
67 st_enter_far_tp_main_loop
,
68 /// disconnect from the FS (Far TP part 2)
70 /// connect to a new FS (Far TP & Server Hop part 3.1)
72 /// after reconnecting, bypass character selection ui & select the same character (Far TP & Server Hop part 3.2)
73 st_reconnect_select_char
,
74 /// after reconnecting and receiving ready, send ready (Far TP part 3.3)
76 /// between global menu exit and sending ready (Server Hop part 3.3)
78 /// error while reconnecting
80 /// Rate a ring session. should pop a web windows pointing the rate session page
84 /// try to login with alternate login system
86 /// pseudo state to leave the state machine
93 static const std::string
& toString(TState state
);
97 /// the client click the 'quit' button
99 /// the client is connecting without authentication (dev mode)
103 /// the client push the 'config' button
105 /// the client push the 'scan data' button
107 /// the client push the 'scan data' button
109 /// the login is validated and cookie is received
111 /// the login check as failed
113 /// the client has selected a shard
115 /// the patch checker says we need to ev_patch_needed
117 /// the patch check says we are clean, no patch needed
119 /// the user validate the category screen, patch can begin
121 /// the client validate the patch result
123 /// Client accept the eula screen
125 /// Client decline the eula screen
127 /// the client valide the reboot message box
129 /// the ingame session terminates (CONNECTION:SERVER_QUIT_OK msg)
131 /// the far tp main loop is entered
132 ev_far_tp_main_loop_entered
,
133 /// the lua script (from web usually) starts the client connection to a shard
135 /// the connection fail for some reason
137 /// the connection was dropped by the server
139 /// the client enters the game main loop
141 // a self reconnetion is complete, get back to outgame menu
143 /// characters received (CONNECTION:USER_CHARS msg)
145 /// characters received but empty (CONNECTION:NO_USER_CHAR msg)
147 /// ready received (CONNECTION:READY msg)
149 /// reselect character (CONNECTION:RECO
151 /// reconnect ok received (CONNECTION:SERVER_RECONNECT_OK msg)
152 ev_reconnect_ok_received
,
153 /// global menu exited
154 ev_global_menu_exited
,
155 /// The client click the 'relog' button
157 /// the client push the 'create account' button
159 /// the client push the 'create account' button
160 ev_close_create_account
,
161 /// the client want to use alternate login system
168 static const std::string
& toString(TEvent event
);
172 TState _CurrentState
;
173 std::list
<TEvent
> _NextEvents
;
176 // Create the state machine with the wanted start.
177 // Note that, because it is a co-task, restarting the state machine after it has finished
178 // require to delete then recreate this object
179 CLoginStateMachine() :
180 _CurrentState(st_start
)
185 TState
getCurrentState()
187 return _CurrentState
;
190 void pushEvent(TEvent eventId
);
200 extern CLoginStateMachine LoginSM
;
202 void initLoginScreen();
203 void initShardDisplay();
205 bool initCreateAccount();
207 void initPatchCheck();
208 void initCatDisplay();
209 void initAutoLogin();
212 //void initWebBrowser();
215 void ConnectToShard();
217 void waitForUserCharReceived();
226 // See definition of _URLTable for url binding
235 CFarTP() : _Reason(NULL
), _SessionIdToJoinFast(0), _InGameMode(false), _PreviousR2EdEnabled(false), _ReselectingChar(false), _IsServerHopEmbedded(false), _HookedForEditor(false), _DSSDown(false) /*, _SelfReconnecting(false)*/ {}
237 // Get the address of a front-end service via http, then begin Far TP
238 bool requestFarTPToSession(TSessionId sessionId
, uint8 charSlot
, CFarTP::TJoinMode joinMode
, bool bailOutIfSessionVanished
);
240 // Ask the EGS to pop the top position if applicable
241 void requestReturnToPreviousSession(TSessionId rejectedSessionId
=TSessionId(0));
243 // Store the result of a JoinSession request for the next disconnection request
244 void setJoinSessionResult(TSessionId sessionId
, const CSecurityCode
& securityCode
);
246 // 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)
247 void hookNextFarTPForEditor();
249 /// Begin a Character Reselect sequence
250 void requestReconnection();
252 // These states can overlap
253 bool isIngame() const { return _InGameMode
; }
254 bool isFarTPInProgress() const;
255 bool isServerHopInProgress() const;
256 bool isLeavingEGS() const { return (LoginSM
.getCurrentState() == CLoginStateMachine::st_leave_shard
); }
257 bool isLeavingShard() const; // from begin of Far TP to disconnection
258 bool isJoiningShard() const; // from reconnection to game entering
259 bool isReselectingChar() const { return _ReselectingChar
; }
260 bool isServerHopEmbedded() const { return _IsServerHopEmbedded
; }
261 bool isFastDisconnectGranted() const { return _SessionIdToJoinFast
!= 0; }
263 // Far TP from the main loop
264 void farTPmainLoop();
265 void writeSecurityCodeForDisconnection(NLMISC::IStream
& msgout
);
266 void onServerQuitOk();
267 void onServerQuitAbort();
268 void disconnectFromPreviousShard();
269 void connectToNewShard();
270 bool reselectCharacter();
271 void selectCharAndEnter();
274 void onDssDown(bool forceReturn
=false);
276 void setIngame() { _InGameMode
= true; }
277 void setOutgame() { _InGameMode
= false; }
278 void setMainLoopEntered() { setIngame(); _ReselectingChar
= false; }
279 void beginEmbeddedServerHop() { _IsServerHopEmbedded
= true; setOutgame(); _ReselectingChar
= false; }
280 void endEmbeddedServerHop() { _IsServerHopEmbedded
= false; setIngame(); _ReselectingChar
= true; }
282 void setURLBase(const std::string
& urlBase
) { _URLBase
= urlBase
; }
286 // called back from session browser after a far tp request
287 void joinSessionResult(uint32 userId
, TSessionId sessionId
, uint32 result
, const std::string
&shardAddr
, const std::string
&participantStatus
);
290 std::string
*_Reason
;
292 static const char *_URLTable
[NbJoinModes
];
294 std::string _URLBase
;
296 TSessionId _SessionIdToJoinFast
; // if non 0, fast disconnection allowed to session
297 CSecurityCode _SecurityCodeForDisconnection
;
299 bool _InGameMode
; // formerly known as EnterWorld
300 bool _PreviousR2EdEnabled
;
301 bool _ReselectingChar
;
302 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)
303 bool _HookedForEditor
; // allows to Far TP to editor instead of following the next Far TP request
304 bool _DSSDown
; // remembers a DSSDown event if occurs during a FarTP
305 // bool _SelfReconnecting; // allows to disconnect after character selection and reconnect until the player can choose another character