Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ add_subdirectory(qr)
add_subdirectory(natneg)
add_subdirectory(GP)
add_subdirectory(gamestats)
add_subdirectory(gamestats_http)
add_subdirectory(search)
add_subdirectory(FESL)
add_subdirectory(peerchat)
Expand Down
11 changes: 11 additions & 0 deletions code/gamestats/server/commands/handle_auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ namespace GS {
}
m_response = data_parser.GetValue("response");

if (gamename.compare("sniperelpc") == 0) {
m_game = OS::GameData();
m_game.gamename = gamename;
m_game.secretkey = "hP58dm";
if (IsResponseValid(m_response.c_str())) {
std::ostringstream ss;
ss << "\\lc\\2\\sesskey\\" << m_session_key << "\\proof\\0\\id\\" << local_id;
SendPacket(ss.str());
return;
}
}

GPPersistRequestData *persist_request_data = (GPPersistRequestData *)malloc(sizeof(GPPersistRequestData));
persist_request_data->profileid = 0;
Expand Down
74 changes: 74 additions & 0 deletions code/gamestats/server/commands/handle_updgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,80 @@ namespace GS {
}

game_data = OS::KeyStringToMap(gamedata);

// Sniper Elite leaderboard writes (Redis)
if (m_game.gamename == "sniperelpc") {
auto it_mission = game_data.find("mission");
auto it_pid = game_data.find("pid_0");
auto it_total = game_data.find("total_0");

if (it_mission != game_data.end() && it_pid != game_data.end() && it_total != game_data.end()) {
int mission = atoi(it_mission->second.c_str());
int pid = atoi(it_pid->second.c_str());
long long total = _strtoi64(it_total->second.c_str(), nullptr, 10);

redisContext* ctx = TaskShared::getThreadLocalRedisContext();
if (ctx) {
{
std::ostringstream hk;
hk << "gstats:sniperelpc:missionstats:" << mission << ":" << pid;
std::string hkey = hk.str();

auto getv = [&](const char *k) -> const char * {
auto it = game_data.find(k);
if (it == game_data.end()) return "0";
if (it->second.empty()) return "0";
return it->second.c_str();
};

redisReply* r = (redisReply*)redisCommand(
ctx,
"HMSET %s "
"twoforone %s "
"threeforone %s "
"fourforone %s "
"silentkill %s "
"covertkill %s "
"2covertkill %s "
"3coverkill %s "
"headshot %s "
"moving %s "
"healthlost %s "
"accuracy %s "
"longestshot %s "
"pinpull %s "
"difficulty %s",
hkey.c_str(),
getv("twoforone_0"),
getv("threeforone_0"),
getv("fourforone_0"),
getv("silentkill_0"),
getv("covertkill_0"),
getv("2covertkill_0"),
getv("3coverkill_0"),
getv("headshot_0"),
getv("moving_0"),
getv("healthlost_0"),
getv("accuracy_0"),
getv("longestshot_0"),
getv("pinpull_0"),
getv("difficulty_0"));
if (r) freeReplyObject(r);
}
{
redisReply* r = (redisReply*)redisCommand(ctx, "ZADD %s %lld %d", "gstats:sniperelpc:total", total, pid);
if (r) freeReplyObject(r);
}
{
std::ostringstream k;
k << "gstats:sniperelpc:mission:" << mission;
redisReply* r = (redisReply*)redisCommand(ctx, "ZADD %s %lld %d", k.str().c_str(), total, pid);
if (r) freeReplyObject(r);
}
}
}
}

PersistBackendRequest req;
req.profileid = m_profile.id;
req.mp_peer = this;
Expand Down
24 changes: 24 additions & 0 deletions code/gamestats_http/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
cmake_minimum_required (VERSION 3.22)

project(gstats_http)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

file (GLOB MAIN_SRCS "*.cpp")
file (GLOB MAIN_HDRS "*.h")
file (GLOB SERVER_SRCS "server/*.cpp")
file (GLOB SERVER_HDRS "server/*.h")

set (ALL_SRCS ${MAIN_SRCS} ${MAIN_HDRS} ${SERVER_SRCS} ${SERVER_HDRS})

include_directories (${CMAKE_CURRENT_SOURCE_DIR})

source_group("Sources" FILES ${MAIN_SRCS})
source_group("Sources\\Server" FILES ${SERVER_SRCS})

source_group("Headers" FILES ${MAIN_HDRS})
source_group("Headers\\Server" FILES ${SERVER_HDRS})

add_executable (gstats_http ${ALL_SRCS})

target_link_libraries(gstats_http openspy SharedTasks ZLIB::ZLIB)
52 changes: 52 additions & 0 deletions code/gamestats_http/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <stdio.h>
#include <string>
#include <OS/Net/NetServer.h>
#include <OS/OpenSpy.h>

#include "server/GHTTPServer.h"
#include "server/GHTTPDriver.h"

INetServer *g_httpserver = NULL;

void tick_handler(uv_timer_t *handle) {
g_httpserver->tick();
}

int main() {
uv_loop_t *loop = uv_default_loop();
uv_timer_t tick_timer;

uv_timer_init(uv_default_loop(), &tick_timer);

OS::Init("gstats_http");
g_httpserver = new GHTTP::Server();

char address_buff[256];
char port_buff[16];
size_t temp_env_sz = sizeof(address_buff);

if (uv_os_getenv("OPENSPY_GSTATS_HTTP_BIND_ADDR", (char *)&address_buff, &temp_env_sz) != UV_ENOENT) {
temp_env_sz = sizeof(port_buff);

uint16_t port = 80;
if (uv_os_getenv("OPENSPY_GSTATS_HTTP_BIND_PORT", (char *)&port_buff, &temp_env_sz) != UV_ENOENT) {
port = atoi(port_buff);
}

GHTTP::Driver *driver = new GHTTP::Driver(g_httpserver, address_buff, port);

OS::LogText(OS::ELogLevel_Info, "Adding gstats_http Driver: %s:%d\n", address_buff, port);
g_httpserver->addNetworkDriver(driver);
} else {
OS::LogText(OS::ELogLevel_Warning, "Missing gstats_http bind address environment variable");
}

uv_timer_start(&tick_timer, tick_handler, 0, 250);
uv_run(loop, UV_RUN_DEFAULT);
uv_loop_close(loop);

delete g_httpserver;

OS::Shutdown();
return 0;
}
4 changes: 4 additions & 0 deletions code/gamestats_http/main.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#ifndef _GSTATS_HTTP_MAIN_H
#define _GSTATS_HTTP_MAIN_H

#endif
9 changes: 9 additions & 0 deletions code/gamestats_http/server/GHTTPDriver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "GHTTPDriver.h"

namespace GHTTP {
Driver::Driver(INetServer *server, const char *host, uint16_t port) : TCPDriver(server, host, port) {
}
INetPeer *Driver::CreatePeer(uv_tcp_t *sd) {
return new Peer(this, sd);
}
}
18 changes: 18 additions & 0 deletions code/gamestats_http/server/GHTTPDriver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef _GHTTP_DRIVER_H
#define _GHTTP_DRIVER_H

#include <stdint.h>
#include <OS/Net/drivers/TCPDriver.h>

#include "GHTTPPeer.h"

namespace GHTTP {
class Driver : public OS::TCPDriver {
public:
Driver(INetServer *server, const char *host, uint16_t port);
protected:
virtual INetPeer *CreatePeer(uv_tcp_t *sd);
};
}

#endif
Loading