Use configured resolution for login/outgame/ingame
[ryzomcore.git] / ryzom / client / src / net_manager.h
blob5b445364e91e78647a939038ee8f0c0a76563e1e
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
7 //
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef CL_NET_MANAGER_H
24 #define CL_NET_MANAGER_H
26 //#define CLIENT_MULTI
28 /////////////
29 // INCLUDE //
30 /////////////
31 // Misc.
32 #include "nel/misc/types_nl.h"
33 // Client.
34 #include "network_connection.h"
35 // Game Share
36 #include "game_share/generic_xml_msg_mngr.h"
37 #include "game_share/chat_group.h"
41 //////////////
42 // FUNCTION //
43 //////////////
44 void initializeNetwork();
47 namespace NLMISC
49 class CBitMemStream;
50 class CCDBNodeLeaf;
54 ///////////
55 // CLASS //
56 ///////////
57 /**
58 * Class to manage the network.
59 * \author Guillaume PUZIN
60 * \author Nevrax France
61 * \date 2001
63 class CNetManager : public CNetworkConnection
65 public:
66 /// Constructor.
67 CNetManager();
69 /**
70 * Updates the whole connection with the frontend.
71 * Call this method evently.
73 * Behaviour in login state when a firewall does not grant the sending:
74 * - When a sending is refused (error "Blocking operation interrupted")
75 * the exception EBlockedByFirewall in thrown. The first time, a time-out is armed.
76 * - In a later attempt, if the time-out expired, the function sets state to
77 * Disconnect, then throws EBlockedByFirewall.
79 * \return bool 'true' if data were sent/received.
81 bool update();
83 bool getConnectionQuality();
85 /**
86 * Buffers a bitmemstream, that will be converted into a generic action, to be sent later to the server (at next update).
88 void push (NLMISC::CBitMemStream &msg);
90 /**
91 * Buffers a target action
93 void pushTarget(CLFECOMMON::TCLEntityId slot);
95 /**
96 * Buffers a pick-up action
98 void pushPickup(CLFECOMMON::TCLEntityId slot, LHSTATE::TLHState lootOrHarvest);
101 * Send
103 void send(NLMISC::TGameCycle);
106 * Send last information without changes (only acknowedges frontend)
108 void send();
111 * Disconnects the current connection
113 void disconnect();
116 * Reset data and reinit the socket
118 void reinit();
121 * Waits for server to answer
123 void waitForServer();
125 #ifdef ENABLE_INCOMING_MSG_RECORDER
126 /// Start/stop replaying the incoming messages (in offline mode)
127 void setReplayingMode( bool onOff, const std::string& filename = "");
128 bool isReplayStarting() const {return _IsReplayStarting;}
129 void startReplay();
131 protected:
132 bool _IsReplayStarting;
133 #endif
135 NLMISC::CRefPtr<NLMISC::CCDBNodeLeaf> m_PingLeaf;
136 NLMISC::CRefPtr<NLMISC::CCDBNodeLeaf> m_UploadLeaf;
137 NLMISC::CRefPtr<NLMISC::CCDBNodeLeaf> m_DownloadLeaf;
138 NLMISC::CRefPtr<NLMISC::CCDBNodeLeaf> m_PacketLostLeaf;
139 NLMISC::CRefPtr<NLMISC::CCDBNodeLeaf> m_ServerStateLeaf;
140 NLMISC::CRefPtr<NLMISC::CCDBNodeLeaf> m_ConnectionQualityLeaf;
144 //////////////
145 // FUNCTION //
146 //////////////
147 // The impulse callback to receive all msg from the frontend.
148 void impulseCallBack(NLMISC::CBitMemStream &, sint32 packet, void *arg);
150 #define ALL_MANAGERS std::vector<CNetManager*>::iterator inm; for( inm=_NetManagers.begin(); inm!=_NetManagers.end(); ++inm ) (*inm)
151 #define FIRST_MANAGER _NetManagers[0]
156 class CNetManagerMulti
158 public:
159 /// Constructor.
160 CNetManagerMulti() {}
162 /// Create the net managers
163 void init( const std::string& cookie, const std::string& addr );
165 /// Destructor
166 ~CNetManagerMulti() { std::vector<CNetManager*>::iterator inm; for( inm=_NetManagers.begin(); inm!=_NetManagers.end(); ++inm ) delete (*inm); }
169 * Updates the whole connection with the frontend.
170 * Call this method evently.
171 * \return bool : 'true' if data were sent/received.
173 bool update() { ALL_MANAGERS->update(); return true; }
176 * Buffers a bitmemstream, that will be converted into a generic action, to be sent later to the server (at next update).
178 void push (NLMISC::CBitMemStream &msg) { ALL_MANAGERS->push( msg ); }
181 * Buffers a target action
183 void pushTarget(CLFECOMMON::TCLEntityId slot) { ALL_MANAGERS->pushTarget( slot ); }
186 * Buffers a pick-up action
188 void pushPickup(CLFECOMMON::TCLEntityId slot, LHSTATE::TLHState lootOrHarvest) { ALL_MANAGERS->pushPickup( slot, lootOrHarvest ); }
191 * Send
193 void send(NLMISC::TGameCycle gc) { ALL_MANAGERS->send( gc ); }
196 * Send
198 void send() { ALL_MANAGERS->send(); }
201 * Disconnects the current connection
203 void disconnect() { ALL_MANAGERS->disconnect(); }
207 * Waits for server to answer
209 void waitForServer() { ALL_MANAGERS->waitForServer(); }
211 #ifdef ENABLE_INCOMING_MSG_RECORDER
212 void setRecordingMode( bool onOff, const std::string& filename = "") {}
213 void setReplayingMode( bool onOff, const std::string& filename = "") {}
214 bool isReplayStarting() const {return false;}
215 void startReplay() {}
216 bool isRecording() const {return false;}
217 bool isReplaying() const {return false;}
218 #endif
221 NLMISC::TTime getCurrentClientTime() { return FIRST_MANAGER->getCurrentClientTime(); } // the time currently played at this frame (in the past)
222 NLMISC::TGameCycle getCurrentClientTick() { return FIRST_MANAGER->getCurrentClientTick(); } // the tick for the current frame (also in the past)
223 NLMISC::TGameCycle getCurrentServerTick() { return FIRST_MANAGER->getCurrentServerTick(); } // the last tick sent by the server.
224 NLMISC::TTime getMachineTimeAtTick() { return FIRST_MANAGER->getMachineTimeAtTick(); } // the machine time at the beginning of the current tick
225 NLMISC::TTicks getMachineTicksAtTick() { return FIRST_MANAGER->getMachineTicksAtTick(); }
226 sint32 getMsPerTick() { return FIRST_MANAGER->getMsPerTick(); }
227 NLMISC::TGameCycle getSynchronize() { return FIRST_MANAGER->getSynchronize(); }
228 uint32 getBestPing() { return FIRST_MANAGER->getBestPing(); }
229 uint32 getPing() const { return FIRST_MANAGER->getPing(); }
230 NLMISC::TTime getLCT() { return FIRST_MANAGER->getLCT(); } // Lag compensation time
231 NLMISC::TTime getUpdateTime() { return FIRST_MANAGER->getUpdateTime(); }
232 NLMISC::TTicks getUpdateTicks() { return FIRST_MANAGER->getUpdateTicks(); }
233 uint32 getUserId() { return 0; }
234 const char* getConnectionStateCStr() { return ""; }
235 bool getConnectionQuality() { return true; }
237 // Return an estimated smooth server tick. Increment only and accelerate/decelerate according to network
238 sint64 getCurrentSmoothServerTick() const { return FIRST_MANAGER->getCurrentSmoothServerTick(); }
239 // Convert a GameCycle to a SmoothServerTick
240 sint32 convertToSmoothServerTick(NLMISC::TGameCycle t) const { return (sint32)(FIRST_MANAGER->convertToSmoothServerTick(t)); }
241 // @}
243 void flushSendBuffer() { ALL_MANAGERS->flushSendBuffer(); }
244 void quit() { ALL_MANAGERS->quit(); }
246 /// Set the Lag Compensation Time in ms (default: 1000)
247 void setLCT( NLMISC::TTime lct ) { ALL_MANAGERS->setLCT( lct ); }
249 const NLNET::CInetAddress& getAddress() { return FIRST_MANAGER->getAddress(); }
251 /// Set player's reference position
252 void setReferencePosition(const NLMISC::CVectorD &position) { ALL_MANAGERS->setReferencePosition( position ); }
254 const std::vector<CNetworkConnection::CChange> &getChanges() { return FIRST_MANAGER->getChanges(); }
256 //void clearChanges() { ALL_MANAGERS->clearChanges(); }
258 void setImpulseCallback(CNetworkConnection::TImpulseCallback callback, void *argument = NULL) { FIRST_MANAGER->setImpulseCallback( callback, argument ); }
259 void setDataBase(NLMISC::CCDBNodeBranch *database) { ALL_MANAGERS->setDataBase( database ); }
260 bool connect(std::string &result) { bool res = false; std::vector<CNetManager*>::iterator inm; for( inm=_NetManagers.begin(); inm!=_NetManagers.end(); ++inm ) if ( (*inm)->connect( result ) ) res = true; return res; }
261 CNetworkConnection::TConnectionState getConnectionState() const { return FIRST_MANAGER->getConnectionState(); }
263 float getMeanPacketLoss() { return FIRST_MANAGER->getMeanPacketLoss(); }
264 uint32 getTotalLostPackets() { return FIRST_MANAGER->getTotalLostPackets(); }
265 float getMeanUpload() { return FIRST_MANAGER->getMeanUpload(); }
266 float getMeanDownload() { return FIRST_MANAGER->getMeanDownload(); }
268 const NLNET::CLoginCookie& getLoginCookie() const { return FIRST_MANAGER->getLoginCookie(); }
269 private:
271 std::vector<CNetManager*> _NetManagers;
274 /* ----------------------------
275 * Access to web, for mail/forum
278 extern uint32 ShardId;
279 extern TSessionId CharacterHomeSessionId;
280 extern std::string WebServer;
282 ////////////
283 // GLOBAL //
284 ////////////
285 #ifdef CLIENT_MULTI
286 extern CNetManagerMulti NetMngr;
287 #else
288 extern CNetManager NetMngr;
289 #endif
290 extern CGenericXmlMsgHeaderManager GenericMsgHeaderMngr;
292 extern bool UseFemaleTitles;
295 #endif // CL_NET_MANAGER_H
297 /* End of net_manager.h */