diff --git a/code/ryzom/client/src/main_loop.cpp b/code/ryzom/client/src/main_loop.cpp index c034eaa83..8cccb99f2 100644 --- a/code/ryzom/client/src/main_loop.cpp +++ b/code/ryzom/client/src/main_loop.cpp @@ -150,6 +150,8 @@ #include "nel/gui/lua_manager.h" #include "nel/gui/group_table.h" +#include "ping.h" + /////////// // USING // @@ -218,84 +220,6 @@ uint64 SimulatedServerTick = 0; -/////////// -// CLASS // -/////////// -/** - * Class to manage the ping computed with the database. - * \author Guillaume PUZIN - * \author Nevrax France - * \date 2003 - */ -class CPing : public ICDBNode::IPropertyObserver -{ -private: - uint32 _Ping; - bool _RdyToPing; - -public: - // Constructor. - CPing() {_Ping = 0; _RdyToPing = true;} - // Destructor. - ~CPing() {;} - - // Add an observer on the database for the ping. - void init() - { - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - if(pIM) - { - CCDBNodeLeaf *pNodeLeaf = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:DEBUG_INFO:Ping", false); - if(pNodeLeaf) - { - ICDBNode::CTextId textId; - pNodeLeaf->addObserver(this, textId); - // nlwarning("CPing: cannot add the observer"); - } - else - nlwarning("CPing: 'SERVER:DEBUG_INFO:Ping' does not exist."); - } - } - - // Release the observer on the database for the ping. - void release() - { - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - if(pIM) - { - CCDBNodeLeaf *pNodeLeaf = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:DEBUG_INFO:Ping", false); - if(pNodeLeaf) - { - ICDBNode::CTextId textId; - pNodeLeaf->removeObserver(this, textId); - } - else - nlwarning("CPing: 'SERVER:DEBUG_INFO:Ping' does not exist."); - } - } - - // Method called when the ping message is back. - virtual void update(ICDBNode* node) - { - CCDBNodeLeaf *leaf = safe_cast(node); - uint32 before = (uint32)leaf->getValue32(); - uint32 current = (uint32)(0xFFFFFFFF & ryzomGetLocalTime()); - if(before > current) - { - //nlwarning("DB PING Pb before '%u' after '%u'.", before, current); - if(ClientCfg.Check) - nlstop; - } - _Ping = current - before; - _RdyToPing = true; - } - - // return the ping in ms. - uint32 getValue() {return _Ping;} - - void rdyToPing(bool rdy) {_RdyToPing = rdy;} - bool rdyToPing() const {return _RdyToPing;} -}; ///////////// // GLOBALS // diff --git a/code/ryzom/client/src/ping.cpp b/code/ryzom/client/src/ping.cpp new file mode 100644 index 000000000..a6d5c2e2c --- /dev/null +++ b/code/ryzom/client/src/ping.cpp @@ -0,0 +1,73 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include "ping.h" + +#include "interface_v3/interface_manager.h" +#include "time_client.h" + +using namespace NLMISC; +using namespace NLGUI; + +void CPing::init() +{ + CInterfaceManager *pIM = CInterfaceManager::getInstance(); + if(pIM) + { + CCDBNodeLeaf *pNodeLeaf = CDBManager::getInstance()->getDbProp("SERVER:DEBUG_INFO:Ping", false); + if(pNodeLeaf) + { + ICDBNode::CTextId textId; + pNodeLeaf->addObserver(this, textId); + // nlwarning("CPing: cannot add the observer"); + } + else + nlwarning("CPing: 'SERVER:DEBUG_INFO:Ping' does not exist."); + } +} + +void CPing::release() +{ + CInterfaceManager *pIM = CInterfaceManager::getInstance(); + if(pIM) + { + CCDBNodeLeaf *pNodeLeaf = CDBManager::getInstance()->getDbProp("SERVER:DEBUG_INFO:Ping", false); + if(pNodeLeaf) + { + ICDBNode::CTextId textId; + pNodeLeaf->removeObserver(this, textId); + } + else + nlwarning("CPing: 'SERVER:DEBUG_INFO:Ping' does not exist."); + } +} + +void CPing::update(NLMISC::ICDBNode* node) +{ + CCDBNodeLeaf *leaf = safe_cast(node); + uint32 before = (uint32)leaf->getValue32(); + uint32 current = (uint32)(0xFFFFFFFF & ryzomGetLocalTime()); + if(before > current) + { + //nlwarning("DB PING Pb before '%u' after '%u'.", before, current); + if(ClientCfg.Check) + nlstop; + } + _Ping = current - before; + _RdyToPing = true; +} + +/* end of file */ \ No newline at end of file diff --git a/code/ryzom/client/src/ping.h b/code/ryzom/client/src/ping.h new file mode 100644 index 000000000..46a7e2c13 --- /dev/null +++ b/code/ryzom/client/src/ping.h @@ -0,0 +1,62 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef CL_PING_H +#define CL_PING_H + +#include +#include + +/////////// +// CLASS // +/////////// +/** + * Class to manage the ping computed with the database. + * \author Guillaume PUZIN + * \author Nevrax France + * \date 2003 + */ +class CPing : public NLMISC::ICDBNode::IPropertyObserver +{ +private: + uint32 _Ping; + bool _RdyToPing; + +public: + // Constructor. + CPing() {_Ping = 0; _RdyToPing = true;} + // Destructor. + ~CPing() {;} + + // Add an observer on the database for the ping. + void init(); + + // Release the observer on the database for the ping. + void release(); + + // Method called when the ping message is back. + virtual void update(NLMISC::ICDBNode* node); + + // return the ping in ms. + uint32 getValue() {return _Ping;} + + void rdyToPing(bool rdy) {_RdyToPing = rdy;} + bool rdyToPing() const {return _RdyToPing;} +}; + +#endif // CL_PING_H + +/* end of file */ \ No newline at end of file