Add uid param to stats module

This commit is contained in:
Eduardo Bart 2012-08-22 22:50:03 -03:00
parent ecd1ec5c0d
commit bdbce01c97
4 changed files with 34 additions and 10 deletions

View File

@ -1,9 +1,23 @@
HOST = 'otclient.herokuapp.com' HOST = 'otclient.herokuapp.com'
PORT = 80 PORT = 80
UUID = nil
--HOST = 'localhost'
--PORT = 3000
function initUUID()
UUID = g_settings.getString('report-uuid')
if not UUID or #UUID ~= 36 then
UUID = g_crypt.genUUID()
g_settings.set('report-uuid', UUID)
end
end
function init() function init()
connect(g_game, { onGameStart = onGameStart }) connect(g_game, { onGameStart = onGameStart })
initUUID()
protocolHttp = ProtocolHttp.create() protocolHttp = ProtocolHttp.create()
connect(protocolHttp, { onConnect = onConnect, connect(protocolHttp, { onConnect = onConnect,
onRecv = onRecv, onRecv = onRecv,
@ -19,33 +33,31 @@ function terminate()
protocolHttp = nil protocolHttp = nil
end end
function sendInfo() function sendReport()
protocolHttp:connect(HOST, PORT) protocolHttp:connect(HOST, PORT)
end end
-- events -- events
function onGameStart() function onGameStart()
scheduleEvent(sendInfo, 5*1000) scheduleEvent(sendReport, 5*1000)
end end
function onConnect(protocol) function onConnect(protocol)
pinfo('Connected to stats server.')
if not g_game.isOnline() then if not g_game.isOnline() then
perror('Could not send stats. Game not online.')
protocol:disconnect() protocol:disconnect()
return return
end end
local post = '' local post = ''
post = post .. 'os=' .. g_app.getOs() post = post .. 'uid=' .. UUID
post = post .. '&os' .. g_app.getOs()
post = post .. '&graphics_vendor=' .. g_graphics.getVendor() post = post .. '&graphics_vendor=' .. g_graphics.getVendor()
post = post .. '&graphics_renderer=' .. g_graphics.getRenderer() post = post .. '&graphics_renderer=' .. g_graphics.getRenderer()
post = post .. '&graphics_version=' .. g_graphics.getVersion() post = post .. '&graphics_version=' .. g_graphics.getVersion()
post = post .. '&painter_engine=' .. g_graphics.getPainterEngine() post = post .. '&painter_engine=' .. g_graphics.getPainterEngine()
post = post .. '&fps=' .. g_app.getBackgroundPaneFps() post = post .. '&fps=' .. g_app.getBackgroundPaneFps()
post = post .. '&max_fps=' .. g_app.getBackgroundPaneMaxFps() post = post .. '&max_fps=' .. g_app.getBackgroundPaneMaxFps()
post = post .. '&fullscreen=' .. fromboolean(g_window.isFullscreen()) post = post .. '&fullscreen=' .. tostring(g_window.isFullscreen())
post = post .. '&window_width=' .. g_window.getWidth() post = post .. '&window_width=' .. g_window.getWidth()
post = post .. '&window_height=' .. g_window.getHeight() post = post .. '&window_height=' .. g_window.getHeight()
post = post .. '&player_name=' .. g_game.getLocalPlayer():getName() post = post .. '&player_name=' .. g_game.getLocalPlayer():getName()
@ -74,11 +86,11 @@ end
function onRecv(protocol, message) function onRecv(protocol, message)
if string.find(message, 'HTTP/1.1 200 OK') then if string.find(message, 'HTTP/1.1 200 OK') then
pinfo('Stats sent to server successfully!') --pinfo('Stats sent to server successfully!')
end end
protocol:disconnect() protocol:disconnect()
end end
function onError(protocol, message, code) function onError(protocol, message, code)
perror('Could not send statistics. ' .. message .. 'Code: ' .. code) perror('Could not send statistics: ' .. message)
end end

View File

@ -88,6 +88,7 @@ void Application::registerLuaFunctions()
// Crypt // Crypt
g_lua.registerSingletonClass("g_crypt"); g_lua.registerSingletonClass("g_crypt");
g_lua.bindSingletonFunction("g_crypt", "genUUID", &Crypt::genUUID, &g_crypt);
g_lua.bindSingletonFunction("g_crypt", "encrypt", &Crypt::encrypt, &g_crypt); g_lua.bindSingletonFunction("g_crypt", "encrypt", &Crypt::encrypt, &g_crypt);
g_lua.bindSingletonFunction("g_crypt", "decrypt", &Crypt::decrypt, &g_crypt); g_lua.bindSingletonFunction("g_crypt", "decrypt", &Crypt::decrypt, &g_crypt);
g_lua.bindSingletonFunction("g_crypt", "sha1Encode", &Crypt::sha1Encode, &g_crypt); g_lua.bindSingletonFunction("g_crypt", "sha1Encode", &Crypt::sha1Encode, &g_crypt);

View File

@ -25,6 +25,9 @@
#include <framework/core/logger.h> #include <framework/core/logger.h>
#include <boost/uuid/uuid.hpp> #include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/functional/hash.hpp> #include <boost/functional/hash.hpp>
#include <openssl/rsa.h> #include <openssl/rsa.h>
@ -147,6 +150,13 @@ std::string Crypt::xorCrypt(const std::string& buffer, const std::string& key)
return out; return out;
} }
std::string Crypt::genUUID()
{
boost::uuids::random_generator gen;
boost::uuids::uuid u = gen();
return boost::uuids::to_string(u);
}
std::string Crypt::genUUIDKey() std::string Crypt::genUUIDKey()
{ {
boost::hash<boost::uuids::uuid> uuid_hasher; boost::hash<boost::uuids::uuid> uuid_hasher;

View File

@ -37,7 +37,7 @@ public:
std::string base64Encode(const std::string& decoded_string); std::string base64Encode(const std::string& decoded_string);
std::string base64Decode(const std::string& encoded_string); std::string base64Decode(const std::string& encoded_string);
std::string xorCrypt(const std::string& buffer, const std::string& key); std::string xorCrypt(const std::string& buffer, const std::string& key);
std::string genUUIDKey(); std::string genUUID();
std::string encrypt(const std::string& decrypted_string); std::string encrypt(const std::string& decrypted_string);
std::string decrypt(const std::string& encrypted_string); std::string decrypt(const std::string& encrypted_string);
std::string md5Encode(const std::string& decoded_string, bool upperCase); std::string md5Encode(const std::string& decoded_string, bool upperCase);
@ -52,6 +52,7 @@ public:
bool rsaDecrypt(unsigned char *msg, int size); bool rsaDecrypt(unsigned char *msg, int size);
private: private:
std::string genUUIDKey();
RSA *m_rsa; RSA *m_rsa;
}; };