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
|
||||
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
|
||||
{
|
||||
renderHtmlString(content);
|
||||
|
@ -5926,7 +5942,9 @@ namespace NLGUI
|
|||
return;
|
||||
|
||||
// push to redo, pop undo, and set current
|
||||
if (!_AskedUrl.empty())
|
||||
_BrowseRedo.push_front(_AskedUrl);
|
||||
|
||||
_AskedUrl= _BrowseUndo.back();
|
||||
_BrowseUndo.pop_back();
|
||||
|
||||
|
|
|
@ -595,6 +595,8 @@ HelpPages =
|
|||
"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";
|
||||
WebIgTrustedDomains = {
|
||||
"api.ryzom.com", "app.ryzom.com"
|
||||
|
|
|
@ -434,6 +434,7 @@ CClientConfig::CClientConfig()
|
|||
|
||||
WebIgMainDomain = "shard.ryzomcore.org";
|
||||
WebIgTrustedDomains.push_back(WebIgMainDomain);
|
||||
WebIgNotifInterval = 10; // time in minutes
|
||||
|
||||
CurlMaxConnections = 2;
|
||||
CurlCABundle.clear();
|
||||
|
@ -1097,6 +1098,7 @@ void CClientConfig::setValues()
|
|||
// WEBIG //
|
||||
READ_STRING_FV(WebIgMainDomain);
|
||||
READ_STRINGVECTOR_FV(WebIgTrustedDomains);
|
||||
READ_INT_FV(WebIgNotifInterval);
|
||||
READ_INT_FV(CurlMaxConnections);
|
||||
if (ClientCfg.CurlMaxConnections < 0)
|
||||
ClientCfg.CurlMaxConnections = 2;
|
||||
|
|
|
@ -312,6 +312,7 @@ struct CClientConfig
|
|||
|
||||
std::string WebIgMainDomain;
|
||||
std::vector<string> WebIgTrustedDomains;
|
||||
uint WebIgNotifInterval; // value in minutes for notification thread
|
||||
|
||||
sint32 CurlMaxConnections;
|
||||
string CurlCABundle;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include "group_html_webig.h"
|
||||
#include "nel/misc/xml_auto_ptr.h"
|
||||
#include "nel/gui/lua_manager.h"
|
||||
#include "../client_cfg.h"
|
||||
#include "../user_entity.h"
|
||||
#include "../entities.h"
|
||||
|
@ -149,13 +150,21 @@ size_t writeDataFromCurl(void *buffer, size_t size, size_t nmemb, void *pcl)
|
|||
return size*nmemb;
|
||||
}
|
||||
|
||||
|
||||
struct CWebigNotificationThread : public NLMISC::IRunnable
|
||||
class CWebigNotificationThread : public NLMISC::IRunnable
|
||||
{
|
||||
private:
|
||||
CURL *Curl;
|
||||
bool _Running;
|
||||
IThread *_Thread;
|
||||
|
||||
public:
|
||||
|
||||
CWebigNotificationThread()
|
||||
{
|
||||
_Running = false;
|
||||
_Thread = NULL;
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
|
||||
Curl = curl_easy_init();
|
||||
if(!Curl) return;
|
||||
curl_easy_setopt(Curl, CURLOPT_COOKIEFILE, "");
|
||||
|
@ -173,6 +182,12 @@ struct CWebigNotificationThread : public NLMISC::IRunnable
|
|||
curl_easy_cleanup(Curl);
|
||||
Curl = 0;
|
||||
}
|
||||
if (_Thread)
|
||||
{
|
||||
_Thread->terminate();
|
||||
delete _Thread;
|
||||
_Thread = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void get(const std::string &url)
|
||||
|
@ -186,61 +201,24 @@ struct CWebigNotificationThread : public NLMISC::IRunnable
|
|||
curl_easy_getinfo(Curl, CURLINFO_RESPONSE_CODE, &r);
|
||||
//nlwarning("result : '%s'", curlresult.c_str());
|
||||
|
||||
vector<string> notifs;
|
||||
explode(curlresult, string("|"), notifs);
|
||||
char *ch;
|
||||
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
|
||||
|
||||
uint32 nbmail = 0;
|
||||
if(!notifs.empty() && fromString(notifs[0], nbmail))
|
||||
// "text/lua; charset=utf8"
|
||||
if (contentType.find("text/lua") == 0)
|
||||
{
|
||||
//nlinfo("nb mail is a number %d", nbmail);
|
||||
CInterfaceManager *pIM = CInterfaceManager::getInstance();
|
||||
if(pIM)
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
std::string script;
|
||||
script = "\nlocal __WEBIG_NOTIF__= true\n" + curlresult;
|
||||
CInterfaceManager::getInstance()->queueLuaScript(script);
|
||||
}
|
||||
else
|
||||
{
|
||||
nlwarning("this is not a number '%s'", curlresult.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());
|
||||
nlwarning("Invalid content-type '%s', expected 'text/lua'", contentType.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -257,30 +235,93 @@ struct CWebigNotificationThread : public NLMISC::IRunnable
|
|||
|
||||
void run()
|
||||
{
|
||||
// first time, we wait a small amount of time to be sure everything is initialized
|
||||
nlSleep(1*60*1000);
|
||||
while (true)
|
||||
if (ClientCfg.WebIgNotifInterval == 0)
|
||||
{
|
||||
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);
|
||||
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(!startedWebigNotificationThread)
|
||||
if (!webigThread.isRunning())
|
||||
{
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
//nlinfo("startStatThread");
|
||||
CWebigNotificationThread *webigThread = new CWebigNotificationThread();
|
||||
IThread *thread = IThread::create (webigThread);
|
||||
nlassert (thread != NULL);
|
||||
thread->start ();
|
||||
startedWebigNotificationThread = true;
|
||||
webigThread.startThread();
|
||||
}
|
||||
}
|
||||
|
||||
void stopWebIgNotificationThread()
|
||||
{
|
||||
if (webigThread.isRunning())
|
||||
{
|
||||
webigThread.stopThread();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -351,7 +392,6 @@ NLMISC_REGISTER_OBJECT(CViewBase, CGroupHTMLWebIG, std::string, "webig_html");
|
|||
CGroupHTMLWebIG::CGroupHTMLWebIG(const TCtorParam ¶m)
|
||||
: CGroupHTMLAuth(param)
|
||||
{
|
||||
startWebigNotificationThread();
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
|
|
|
@ -20,6 +20,9 @@
|
|||
#include "nel/misc/types_nl.h"
|
||||
#include "nel/gui/group_html.h"
|
||||
|
||||
void startWebIgNotificationThread();
|
||||
void stopWebIgNotificationThread();
|
||||
|
||||
/**
|
||||
* Auth HTML group
|
||||
*/
|
||||
|
|
|
@ -134,6 +134,8 @@ using namespace NLGUI;
|
|||
#include "user_agent.h"
|
||||
#include "../item_group_manager.h"
|
||||
|
||||
#include "group_html_webig.h"
|
||||
|
||||
using namespace NLMISC;
|
||||
|
||||
namespace NLGUI
|
||||
|
@ -1050,6 +1052,8 @@ void CInterfaceManager::initInGame()
|
|||
{
|
||||
displaySystemInfo(CI18N::get("uiLogTurnedOff"));
|
||||
}
|
||||
|
||||
startWebIgNotificationThread();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
@ -1303,6 +1307,7 @@ void CInterfaceManager::uninitInGame0 ()
|
|||
// ------------------------------------------------------------------------------------------------
|
||||
void CInterfaceManager::uninitInGame1 ()
|
||||
{
|
||||
stopWebIgNotificationThread();
|
||||
|
||||
// release Bar Manager (HP, SAP etc... Bars)
|
||||
CBarManager::getInstance()->releaseInGame();
|
||||
|
@ -1464,6 +1469,9 @@ void CInterfaceManager::updateFrameEvents()
|
|||
|
||||
H_AUTO_USE ( RZ_Client_Update_Frame_Events )
|
||||
|
||||
// lua scripts from different thread
|
||||
flushScriptQueue();
|
||||
|
||||
flushDebugWindow();
|
||||
|
||||
// Handle anims done in 2 times because some AH can add or remove anims
|
||||
|
@ -3483,6 +3491,24 @@ void CInterfaceManager::notifyForumUpdated()
|
|||
_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()
|
||||
|
|
|
@ -19,8 +19,11 @@
|
|||
#ifndef NL_INTERFACE_MANAGER_H
|
||||
#define NL_INTERFACE_MANAGER_H
|
||||
|
||||
#include <queue>
|
||||
|
||||
#include "nel/misc/types_nl.h"
|
||||
#include "nel/misc/cdb_manager.h"
|
||||
#include "nel/misc/mutex.h"
|
||||
#include "nel/3d/u_texture.h"
|
||||
#include "nel/3d/u_text_context.h"
|
||||
#include "nel/gui/interface_group.h"
|
||||
|
@ -427,6 +430,10 @@ public:
|
|||
void notifyMailAvailable();
|
||||
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
|
||||
*/
|
||||
static bool use12hClock();
|
||||
|
@ -570,6 +577,12 @@ private:
|
|||
NLMISC::CCDBNodeLeaf *_CheckForumNode;
|
||||
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.
|
||||
|
|
Loading…
Reference in a new issue