Changed: add text/lua content type for CGroupHTML and Webig notif thread
--HG-- branch : develop
This commit is contained in:
parent
f997e73961
commit
86db1f29ac
8 changed files with 175 additions and 70 deletions
|
@ -5682,6 +5682,22 @@ namespace NLGUI
|
||||||
// create html code with image url inside and do the request again
|
// create html code with image url inside and do the request again
|
||||||
renderHtmlString("<html><head><title>"+_URL+"</title></head><body><img src=\"" + _URL + "\"></body></html>");
|
renderHtmlString("<html><head><title>"+_URL+"</title></head><body><img src=\"" + _URL + "\"></body></html>");
|
||||||
}
|
}
|
||||||
|
else if (_TrustedDomain && type.find("text/lua") == 0)
|
||||||
|
{
|
||||||
|
setTitle(_TitleString);
|
||||||
|
|
||||||
|
_LuaScript = "\nlocal __CURRENT_WINDOW__=\""+this->_Id+"\" \n"+content;
|
||||||
|
CLuaManager::getInstance().executeLuaScript(_LuaScript, true);
|
||||||
|
_LuaScript.clear();
|
||||||
|
|
||||||
|
_Browsing = false;
|
||||||
|
_Connecting = false;
|
||||||
|
|
||||||
|
// disable refresh button
|
||||||
|
clearRefresh();
|
||||||
|
// disable redo into this url
|
||||||
|
_AskedUrl.clear();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
renderHtmlString(content);
|
renderHtmlString(content);
|
||||||
|
@ -5926,7 +5942,9 @@ namespace NLGUI
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// push to redo, pop undo, and set current
|
// push to redo, pop undo, and set current
|
||||||
|
if (!_AskedUrl.empty())
|
||||||
_BrowseRedo.push_front(_AskedUrl);
|
_BrowseRedo.push_front(_AskedUrl);
|
||||||
|
|
||||||
_AskedUrl= _BrowseUndo.back();
|
_AskedUrl= _BrowseUndo.back();
|
||||||
_BrowseUndo.pop_back();
|
_BrowseUndo.pop_back();
|
||||||
|
|
||||||
|
|
|
@ -595,6 +595,8 @@ HelpPages =
|
||||||
"ru=http://forums.ryzom.com/forum/showthread.php?t=29129"
|
"ru=http://forums.ryzom.com/forum/showthread.php?t=29129"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// interval in minutes for webig notify thread to run
|
||||||
|
WebIgNotifInterval = 10;
|
||||||
WebIgMainDomain = "app.ryzom.com";
|
WebIgMainDomain = "app.ryzom.com";
|
||||||
WebIgTrustedDomains = {
|
WebIgTrustedDomains = {
|
||||||
"api.ryzom.com", "app.ryzom.com"
|
"api.ryzom.com", "app.ryzom.com"
|
||||||
|
|
|
@ -434,6 +434,7 @@ CClientConfig::CClientConfig()
|
||||||
|
|
||||||
WebIgMainDomain = "shard.ryzomcore.org";
|
WebIgMainDomain = "shard.ryzomcore.org";
|
||||||
WebIgTrustedDomains.push_back(WebIgMainDomain);
|
WebIgTrustedDomains.push_back(WebIgMainDomain);
|
||||||
|
WebIgNotifInterval = 10; // time in minutes
|
||||||
|
|
||||||
CurlMaxConnections = 2;
|
CurlMaxConnections = 2;
|
||||||
CurlCABundle.clear();
|
CurlCABundle.clear();
|
||||||
|
@ -1097,6 +1098,7 @@ void CClientConfig::setValues()
|
||||||
// WEBIG //
|
// WEBIG //
|
||||||
READ_STRING_FV(WebIgMainDomain);
|
READ_STRING_FV(WebIgMainDomain);
|
||||||
READ_STRINGVECTOR_FV(WebIgTrustedDomains);
|
READ_STRINGVECTOR_FV(WebIgTrustedDomains);
|
||||||
|
READ_INT_FV(WebIgNotifInterval);
|
||||||
READ_INT_FV(CurlMaxConnections);
|
READ_INT_FV(CurlMaxConnections);
|
||||||
if (ClientCfg.CurlMaxConnections < 0)
|
if (ClientCfg.CurlMaxConnections < 0)
|
||||||
ClientCfg.CurlMaxConnections = 2;
|
ClientCfg.CurlMaxConnections = 2;
|
||||||
|
|
|
@ -312,6 +312,7 @@ struct CClientConfig
|
||||||
|
|
||||||
std::string WebIgMainDomain;
|
std::string WebIgMainDomain;
|
||||||
std::vector<string> WebIgTrustedDomains;
|
std::vector<string> WebIgTrustedDomains;
|
||||||
|
uint WebIgNotifInterval; // value in minutes for notification thread
|
||||||
|
|
||||||
sint32 CurlMaxConnections;
|
sint32 CurlMaxConnections;
|
||||||
string CurlCABundle;
|
string CurlCABundle;
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#include "group_html_webig.h"
|
#include "group_html_webig.h"
|
||||||
#include "nel/misc/xml_auto_ptr.h"
|
#include "nel/misc/xml_auto_ptr.h"
|
||||||
|
#include "nel/gui/lua_manager.h"
|
||||||
#include "../client_cfg.h"
|
#include "../client_cfg.h"
|
||||||
#include "../user_entity.h"
|
#include "../user_entity.h"
|
||||||
#include "../entities.h"
|
#include "../entities.h"
|
||||||
|
@ -149,13 +150,21 @@ size_t writeDataFromCurl(void *buffer, size_t size, size_t nmemb, void *pcl)
|
||||||
return size*nmemb;
|
return size*nmemb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CWebigNotificationThread : public NLMISC::IRunnable
|
||||||
struct CWebigNotificationThread : public NLMISC::IRunnable
|
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
CURL *Curl;
|
CURL *Curl;
|
||||||
|
bool _Running;
|
||||||
|
IThread *_Thread;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
CWebigNotificationThread()
|
CWebigNotificationThread()
|
||||||
{
|
{
|
||||||
|
_Running = false;
|
||||||
|
_Thread = NULL;
|
||||||
|
curl_global_init(CURL_GLOBAL_ALL);
|
||||||
|
|
||||||
Curl = curl_easy_init();
|
Curl = curl_easy_init();
|
||||||
if(!Curl) return;
|
if(!Curl) return;
|
||||||
curl_easy_setopt(Curl, CURLOPT_COOKIEFILE, "");
|
curl_easy_setopt(Curl, CURLOPT_COOKIEFILE, "");
|
||||||
|
@ -173,6 +182,12 @@ struct CWebigNotificationThread : public NLMISC::IRunnable
|
||||||
curl_easy_cleanup(Curl);
|
curl_easy_cleanup(Curl);
|
||||||
Curl = 0;
|
Curl = 0;
|
||||||
}
|
}
|
||||||
|
if (_Thread)
|
||||||
|
{
|
||||||
|
_Thread->terminate();
|
||||||
|
delete _Thread;
|
||||||
|
_Thread = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void get(const std::string &url)
|
void get(const std::string &url)
|
||||||
|
@ -186,61 +201,24 @@ struct CWebigNotificationThread : public NLMISC::IRunnable
|
||||||
curl_easy_getinfo(Curl, CURLINFO_RESPONSE_CODE, &r);
|
curl_easy_getinfo(Curl, CURLINFO_RESPONSE_CODE, &r);
|
||||||
//nlwarning("result : '%s'", curlresult.c_str());
|
//nlwarning("result : '%s'", curlresult.c_str());
|
||||||
|
|
||||||
vector<string> notifs;
|
char *ch;
|
||||||
explode(curlresult, string("|"), notifs);
|
std::string contentType;
|
||||||
|
res = curl_easy_getinfo(Curl, CURLINFO_CONTENT_TYPE, &ch);
|
||||||
|
if (res == CURLE_OK && ch != NULL)
|
||||||
|
{
|
||||||
|
contentType = ch;
|
||||||
|
}
|
||||||
|
|
||||||
// Update the mail notification icon
|
// "text/lua; charset=utf8"
|
||||||
|
if (contentType.find("text/lua") == 0)
|
||||||
uint32 nbmail = 0;
|
|
||||||
if(!notifs.empty() && fromString(notifs[0], nbmail))
|
|
||||||
{
|
{
|
||||||
//nlinfo("nb mail is a number %d", nbmail);
|
std::string script;
|
||||||
CInterfaceManager *pIM = CInterfaceManager::getInstance();
|
script = "\nlocal __WEBIG_NOTIF__= true\n" + curlresult;
|
||||||
if(pIM)
|
CInterfaceManager::getInstance()->queueLuaScript(script);
|
||||||
{
|
|
||||||
CCDBNodeLeaf *_CheckMailNode = NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:MAIL_WAITING");
|
|
||||||
if(_CheckMailNode)
|
|
||||||
{
|
|
||||||
_CheckMailNode->setValue32(nbmail==0?0:1);
|
|
||||||
CInterfaceElement *elm = CWidgetManager::getInstance()->getElementFromId("ui:interface:compass:mail:mail_nb");
|
|
||||||
if (elm)
|
|
||||||
{
|
|
||||||
CViewText *vt = dynamic_cast<CViewText*>(elm);
|
|
||||||
vt->setText(toString("%d", nbmail));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
nlwarning("this is not a number '%s'", curlresult.c_str());
|
nlwarning("Invalid content-type '%s', expected 'text/lua'", contentType.c_str());
|
||||||
}
|
|
||||||
|
|
||||||
// Update the forum notification icon
|
|
||||||
|
|
||||||
uint32 nbforum = 0;
|
|
||||||
if(notifs.size() > 1 && fromString(notifs[1], nbforum))
|
|
||||||
{
|
|
||||||
//nlinfo("nb forum this is a number %d", nbforum);
|
|
||||||
CInterfaceManager *pIM = CInterfaceManager::getInstance();
|
|
||||||
if(pIM)
|
|
||||||
{
|
|
||||||
CCDBNodeLeaf *_CheckForumNode = NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:FORUM_UPDATED");
|
|
||||||
if(_CheckForumNode)
|
|
||||||
{
|
|
||||||
_CheckForumNode->setValue32(nbforum==0?0:1);
|
|
||||||
CInterfaceElement *elm = CWidgetManager::getInstance()->getElementFromId("ui:interface:compass:forum:forum_nb");
|
|
||||||
if (elm)
|
|
||||||
{
|
|
||||||
CViewText *vt = dynamic_cast<CViewText*>(elm);
|
|
||||||
vt->setText(toString("%d", nbforum));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
nlwarning("this is not a number '%s'", curlresult.c_str());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,30 +235,93 @@ struct CWebigNotificationThread : public NLMISC::IRunnable
|
||||||
|
|
||||||
void run()
|
void run()
|
||||||
{
|
{
|
||||||
// first time, we wait a small amount of time to be sure everything is initialized
|
if (ClientCfg.WebIgNotifInterval == 0)
|
||||||
nlSleep(1*60*1000);
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
string url = "http://"+ClientCfg.WebIgMainDomain+"/index.php?app=notif&rnd="+randomString();
|
_Running = false;
|
||||||
|
nlwarning("ClientCfg.WebIgNotifInterval == 0, notification thread not running");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string domain = ClientCfg.WebIgMainDomain;
|
||||||
|
uint32 ms = ClientCfg.WebIgNotifInterval*60*1000;
|
||||||
|
|
||||||
|
_Running = true;
|
||||||
|
// first time, we wait a small amount of time to be sure everything is initialized
|
||||||
|
nlSleep(30*1000);
|
||||||
|
uint c = 0;
|
||||||
|
while (_Running)
|
||||||
|
{
|
||||||
|
string url = "https://"+domain+"/index.php?app=notif&format=lua&rnd="+randomString();
|
||||||
addWebIGParams(url, true);
|
addWebIGParams(url, true);
|
||||||
get(url);
|
get(url);
|
||||||
nlSleep(10*60*1000);
|
|
||||||
|
sleepLoop(ms);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sleepLoop(uint ms)
|
||||||
|
{
|
||||||
|
// use smaller sleep time so stopThread() will not block too long
|
||||||
|
// tick == 100ms
|
||||||
|
uint32 ticks = ms / 100;
|
||||||
|
while (_Running && ticks > 0) {
|
||||||
|
nlSleep(100);
|
||||||
|
ticks--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void startThread()
|
||||||
|
{
|
||||||
|
if (!_Thread)
|
||||||
|
{
|
||||||
|
_Thread = IThread::create(this);
|
||||||
|
nlassert(_Thread != NULL);
|
||||||
|
_Thread->start();
|
||||||
|
nlwarning("WebIgNotification thread started");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nlwarning("WebIgNotification thread already started");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void stopThread()
|
||||||
|
{
|
||||||
|
_Running = false;
|
||||||
|
if (_Thread)
|
||||||
|
{
|
||||||
|
_Thread->wait();
|
||||||
|
delete _Thread;
|
||||||
|
_Thread = NULL;
|
||||||
|
nlwarning("WebIgNotification thread stopped");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nlwarning("WebIgNotification thread already stopped");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isRunning() const
|
||||||
|
{
|
||||||
|
return _Running;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void startWebigNotificationThread()
|
static CWebigNotificationThread webigThread;
|
||||||
|
void startWebIgNotificationThread()
|
||||||
{
|
{
|
||||||
static bool startedWebigNotificationThread = false;
|
if (!webigThread.isRunning())
|
||||||
if(!startedWebigNotificationThread)
|
|
||||||
{
|
{
|
||||||
curl_global_init(CURL_GLOBAL_ALL);
|
webigThread.startThread();
|
||||||
//nlinfo("startStatThread");
|
}
|
||||||
CWebigNotificationThread *webigThread = new CWebigNotificationThread();
|
}
|
||||||
IThread *thread = IThread::create (webigThread);
|
|
||||||
nlassert (thread != NULL);
|
void stopWebIgNotificationThread()
|
||||||
thread->start ();
|
{
|
||||||
startedWebigNotificationThread = true;
|
if (webigThread.isRunning())
|
||||||
|
{
|
||||||
|
webigThread.stopThread();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,7 +392,6 @@ NLMISC_REGISTER_OBJECT(CViewBase, CGroupHTMLWebIG, std::string, "webig_html");
|
||||||
CGroupHTMLWebIG::CGroupHTMLWebIG(const TCtorParam ¶m)
|
CGroupHTMLWebIG::CGroupHTMLWebIG(const TCtorParam ¶m)
|
||||||
: CGroupHTMLAuth(param)
|
: CGroupHTMLAuth(param)
|
||||||
{
|
{
|
||||||
startWebigNotificationThread();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
|
|
|
@ -20,6 +20,9 @@
|
||||||
#include "nel/misc/types_nl.h"
|
#include "nel/misc/types_nl.h"
|
||||||
#include "nel/gui/group_html.h"
|
#include "nel/gui/group_html.h"
|
||||||
|
|
||||||
|
void startWebIgNotificationThread();
|
||||||
|
void stopWebIgNotificationThread();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Auth HTML group
|
* Auth HTML group
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -134,6 +134,8 @@ using namespace NLGUI;
|
||||||
#include "user_agent.h"
|
#include "user_agent.h"
|
||||||
#include "../item_group_manager.h"
|
#include "../item_group_manager.h"
|
||||||
|
|
||||||
|
#include "group_html_webig.h"
|
||||||
|
|
||||||
using namespace NLMISC;
|
using namespace NLMISC;
|
||||||
|
|
||||||
namespace NLGUI
|
namespace NLGUI
|
||||||
|
@ -1050,6 +1052,8 @@ void CInterfaceManager::initInGame()
|
||||||
{
|
{
|
||||||
displaySystemInfo(CI18N::get("uiLogTurnedOff"));
|
displaySystemInfo(CI18N::get("uiLogTurnedOff"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startWebIgNotificationThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
@ -1303,6 +1307,7 @@ void CInterfaceManager::uninitInGame0 ()
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void CInterfaceManager::uninitInGame1 ()
|
void CInterfaceManager::uninitInGame1 ()
|
||||||
{
|
{
|
||||||
|
stopWebIgNotificationThread();
|
||||||
|
|
||||||
// release Bar Manager (HP, SAP etc... Bars)
|
// release Bar Manager (HP, SAP etc... Bars)
|
||||||
CBarManager::getInstance()->releaseInGame();
|
CBarManager::getInstance()->releaseInGame();
|
||||||
|
@ -1464,6 +1469,9 @@ void CInterfaceManager::updateFrameEvents()
|
||||||
|
|
||||||
H_AUTO_USE ( RZ_Client_Update_Frame_Events )
|
H_AUTO_USE ( RZ_Client_Update_Frame_Events )
|
||||||
|
|
||||||
|
// lua scripts from different thread
|
||||||
|
flushScriptQueue();
|
||||||
|
|
||||||
flushDebugWindow();
|
flushDebugWindow();
|
||||||
|
|
||||||
// Handle anims done in 2 times because some AH can add or remove anims
|
// Handle anims done in 2 times because some AH can add or remove anims
|
||||||
|
@ -3483,6 +3491,24 @@ void CInterfaceManager::notifyForumUpdated()
|
||||||
_CheckForumNode->setValue32(1);
|
_CheckForumNode->setValue32(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CInterfaceManager::queueLuaScript(const std::string &script)
|
||||||
|
{
|
||||||
|
CAutoMutex<CMutex> autoMutex(_ScriptQueueMutex);
|
||||||
|
|
||||||
|
_ScriptQueue.push(script);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CInterfaceManager::flushScriptQueue()
|
||||||
|
{
|
||||||
|
CAutoMutex<CMutex> autoMutex(_ScriptQueueMutex);
|
||||||
|
|
||||||
|
while(!_ScriptQueue.empty())
|
||||||
|
{
|
||||||
|
CLuaManager::getInstance().executeLuaScript(_ScriptQueue.front());
|
||||||
|
_ScriptQueue.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
void CInterfaceManager::resetTextIndex()
|
void CInterfaceManager::resetTextIndex()
|
||||||
|
|
|
@ -19,8 +19,11 @@
|
||||||
#ifndef NL_INTERFACE_MANAGER_H
|
#ifndef NL_INTERFACE_MANAGER_H
|
||||||
#define NL_INTERFACE_MANAGER_H
|
#define NL_INTERFACE_MANAGER_H
|
||||||
|
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
#include "nel/misc/types_nl.h"
|
#include "nel/misc/types_nl.h"
|
||||||
#include "nel/misc/cdb_manager.h"
|
#include "nel/misc/cdb_manager.h"
|
||||||
|
#include "nel/misc/mutex.h"
|
||||||
#include "nel/3d/u_texture.h"
|
#include "nel/3d/u_texture.h"
|
||||||
#include "nel/3d/u_text_context.h"
|
#include "nel/3d/u_text_context.h"
|
||||||
#include "nel/gui/interface_group.h"
|
#include "nel/gui/interface_group.h"
|
||||||
|
@ -427,6 +430,10 @@ public:
|
||||||
void notifyMailAvailable();
|
void notifyMailAvailable();
|
||||||
void notifyForumUpdated();
|
void notifyForumUpdated();
|
||||||
|
|
||||||
|
/** Queue up lua script to be run on next frame update
|
||||||
|
*/
|
||||||
|
void queueLuaScript(const std::string &script);
|
||||||
|
|
||||||
/** Return true if 12-hour clock should be used
|
/** Return true if 12-hour clock should be used
|
||||||
*/
|
*/
|
||||||
static bool use12hClock();
|
static bool use12hClock();
|
||||||
|
@ -570,6 +577,12 @@ private:
|
||||||
NLMISC::CCDBNodeLeaf *_CheckForumNode;
|
NLMISC::CCDBNodeLeaf *_CheckForumNode;
|
||||||
sint64 _UpdateWeatherTime;
|
sint64 _UpdateWeatherTime;
|
||||||
|
|
||||||
|
// WebIG notify thread is pushing lua code here
|
||||||
|
std::queue<std::string> _ScriptQueue;
|
||||||
|
NLMISC::CMutex _ScriptQueueMutex;
|
||||||
|
|
||||||
|
void flushScriptQueue();
|
||||||
|
|
||||||
// @}
|
// @}
|
||||||
|
|
||||||
/** This is the GLOBAL Action counter used to synchronize some systems (including INVENTORY) with the server.
|
/** This is the GLOBAL Action counter used to synchronize some systems (including INVENTORY) with the server.
|
||||||
|
|
Loading…
Reference in a new issue