parent
c50e186fa7
commit
05fcf740b4
@ -0,0 +1,84 @@
|
||||
HOST = '189.55.105.125'
|
||||
PORT = 3000
|
||||
|
||||
function init()
|
||||
connect(g_game, { onGameStart = onGameStart })
|
||||
|
||||
protocolHttp = ProtocolHttp.create()
|
||||
connect(protocolHttp, { onConnect = onConnect,
|
||||
onRecv = onRecv,
|
||||
onError = onError })
|
||||
end
|
||||
|
||||
function terminate()
|
||||
disconnect(g_game, { onGameStart = onGameStart })
|
||||
|
||||
disconnect(protocolHttp, { onConnect = onConnect,
|
||||
onRecv = onRecv,
|
||||
onError = onError })
|
||||
protocolHttp = nil
|
||||
end
|
||||
|
||||
function sendInfo()
|
||||
protocolHttp:connect(HOST, PORT)
|
||||
end
|
||||
|
||||
-- events
|
||||
function onGameStart()
|
||||
scheduleEvent(sendInfo, 5*1000)
|
||||
end
|
||||
|
||||
function onConnect(protocol)
|
||||
pinfo('Connected to stats server.')
|
||||
|
||||
if not g_game.isOnline() then
|
||||
perror('Could not send stats. Game not online.')
|
||||
protocol:disconnect()
|
||||
return
|
||||
end
|
||||
|
||||
local post = ''
|
||||
post = post .. 'os=' .. g_app.getOs()
|
||||
post = post .. '&graphics_vendor=' .. g_graphics.getVendor()
|
||||
post = post .. '&graphics_renderer=' .. g_graphics.getRenderer()
|
||||
post = post .. '&graphics_version=' .. g_graphics.getVersion()
|
||||
post = post .. '&painter_engine=' .. g_graphics.getPainterEngine()
|
||||
post = post .. '&fps=' .. g_app.getBackgroundPaneFps()
|
||||
post = post .. '&max_fps=' .. g_app.getBackgroundPaneMaxFps()
|
||||
post = post .. '&fullscreen=' .. fromboolean(g_window.isFullscreen())
|
||||
post = post .. '&window_width=' .. g_window.getWidth()
|
||||
post = post .. '&window_height=' .. g_window.getHeight()
|
||||
post = post .. '&player_name=' .. g_game.getLocalPlayer():getName()
|
||||
post = post .. '&otserv_host=' .. G.host
|
||||
post = post .. '&otserv_port=' .. G.port
|
||||
post = post .. '&otserv_protocol=' .. g_game.getClientVersion()
|
||||
post = post .. '&build_version=' .. g_app.getVersion()
|
||||
post = post .. '&build_revision=' .. g_app.getBuildRevision()
|
||||
post = post .. '&build_commit=' .. g_app.getBuildCommit()
|
||||
post = post .. '&build_date=' .. g_app.getBuildDate()
|
||||
post = post .. '&display_width=' .. g_window.getDisplayWidth()
|
||||
post = post .. '&display_height=' .. g_window.getDisplayHeight()
|
||||
|
||||
local message = ''
|
||||
message = message .. "POST /report HTTP/1.0\r\n"
|
||||
message = message .. "Host: " .. HOST .. "\r\n"
|
||||
message = message .. "Accept: */*\r\n"
|
||||
message = message .. "Connection: close\r\n"
|
||||
message = message .. "Content-Type: application/x-www-form-urlencoded\r\n"
|
||||
message = message .. "Content-Length: " .. post:len() .. "\r\n\r\n"
|
||||
message = message .. post
|
||||
|
||||
protocol:send(message)
|
||||
protocol:recv()
|
||||
end
|
||||
|
||||
function onRecv(protocol, message)
|
||||
if string.find(message, 'HTTP/1.1 200 OK') then
|
||||
pinfo('Stats sent to server successfully!')
|
||||
end
|
||||
protocol:disconnect()
|
||||
end
|
||||
|
||||
function onError(protocol, message, code)
|
||||
perror('Could not send statistics. ' .. message .. 'Code: ' .. code)
|
||||
end
|
@ -0,0 +1,9 @@
|
||||
Module
|
||||
name: client_stats
|
||||
description: Sends client statistics to a server
|
||||
author: baxnie
|
||||
website: www.otclient.info
|
||||
sandboxed: true
|
||||
scripts: [ stats.lua ]
|
||||
@onLoad: init()
|
||||
@onUnload: terminate()
|
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "protocolhttp.h"
|
||||
#include "connection.h"
|
||||
#include <framework/core/application.h>
|
||||
|
||||
ProtocolHttp::ProtocolHttp()
|
||||
{
|
||||
}
|
||||
|
||||
ProtocolHttp::~ProtocolHttp()
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
assert(!g_app.isTerminated());
|
||||
#endif
|
||||
disconnect();
|
||||
}
|
||||
|
||||
void ProtocolHttp::connect(const std::string& host, uint16 port)
|
||||
{
|
||||
m_connection = ConnectionPtr(new Connection);
|
||||
m_connection->setErrorCallback(std::bind(&ProtocolHttp::onError, asProtocolHttp(), std::placeholders::_1));
|
||||
m_connection->connect(host, port, std::bind(&ProtocolHttp::onConnect, asProtocolHttp()));
|
||||
}
|
||||
|
||||
void ProtocolHttp::disconnect()
|
||||
{
|
||||
if(m_connection) {
|
||||
m_connection->close();
|
||||
m_connection.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void ProtocolHttp::send(const std::string& message)
|
||||
{
|
||||
if(m_connection)
|
||||
m_connection->write((uint8*)message.c_str(), message.length());
|
||||
}
|
||||
|
||||
void ProtocolHttp::recv()
|
||||
{
|
||||
if(m_connection)
|
||||
m_connection->read_until("\r\n\r\n", std::bind(&ProtocolHttp::onRecv, asProtocolHttp(), std::placeholders::_1, std::placeholders::_2));
|
||||
}
|
||||
|
||||
void ProtocolHttp::onConnect()
|
||||
{
|
||||
callLuaField("onConnect");
|
||||
}
|
||||
|
||||
void ProtocolHttp::onRecv(uint8* buffer, uint16 size)
|
||||
{
|
||||
std::string string = std::string((char*)buffer, (size_t)size);
|
||||
callLuaField("onRecv", string);
|
||||
}
|
||||
|
||||
void ProtocolHttp::onError(const boost::system::error_code& err)
|
||||
{
|
||||
callLuaField("onError", err.message(), err.value());
|
||||
disconnect();
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef PROTOCOLHTTP_H
|
||||
#define PROTOCOLHTTP_H
|
||||
|
||||
#include "declarations.h"
|
||||
#include "connection.h"
|
||||
|
||||
#include <framework/luaengine/luaobject.h>
|
||||
|
||||
// @bindclass
|
||||
class ProtocolHttp : public LuaObject
|
||||
{
|
||||
public:
|
||||
ProtocolHttp();
|
||||
virtual ~ProtocolHttp();
|
||||
|
||||
void connect(const std::string& host, uint16 port);
|
||||
void disconnect();
|
||||
|
||||
void send(const std::string &message);
|
||||
void recv();
|
||||
|
||||
ProtocolHttpPtr asProtocolHttp() { return static_self_cast<ProtocolHttp>(); }
|
||||
|
||||
protected:
|
||||
void onConnect();
|
||||
void onRecv(uint8* buffer, uint16 size);
|
||||
void onError(const boost::system::error_code& err);
|
||||
|
||||
private:
|
||||
ConnectionPtr m_connection;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in new issue