Skip to content

Commit

Permalink
v0.0.2 update
Browse files Browse the repository at this point in the history
  • Loading branch information
martin committed Sep 16, 2019
1 parent ccf6228 commit b7eb89d
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 20 deletions.
29 changes: 23 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# steamcountsnotifyd
SteamCountsNotifyD is a multithreaded Linux daemon written in C++17 that notifies you when your selected games gets some player activity

Current release: v0.0.2 - Alpha

## License
SteamCountsNotifyD is released under a free software license (MIT)

Expand Down Expand Up @@ -40,33 +42,48 @@ Optional:

## Configuration
* Uses xdg directory: `$HOME/.config/steamcountsnotifyd/config`
* You can just copy over the `config/conf_example` over to that configuration place
### Parameters
CLI | Name | Description
---|---|---
`-i` | `interval` | How long in minutes to delay between each player count fetch.
`-t` | `thresholdinterval` | When the threshold's achieved, what interval gets extended to.
`-c` | `connectiontimeout` | How long in seconds the connection stay puts.
`-n` | `notifytimeout` | How long in seconds the notification stays shown.
`-a` | `actiontype` | Which type of clickable notification should use: 0 - default, 1 - button
`-d` | `daemonize` | Defaults to daemonize, 0 to disable daemonization
### Example
```
interval 1
thresholdinterval 2
connectiontimeout 10
notifytimeout 10
actiontype 1
newappid 244630 "NEOTOKYO" 0
newappid 282440 "Quake Live" 100
```
### systemd
* Use the systemd daemon as under user control, more information: [systemd/User - ArchWiki](https://wiki.archlinux.org/index.php/systemd/User)

## TODO (Possible future features)
* Per server notification
* Click to load up game
* Windows port
* Better documentation and comments
* Making it work with systemd properly
* Support reload function
* Support runit and openrc also, sysvinit won't be however

## Releases
### 0.0.2 Alpha release (Not final)
### 0.0.2 Alpha
* counts to count (grammar fix)
* systemd service file available
* fixed paramters not passing through command line and used
* non-daemonize mode added
### 0.0.1 Alpha release
* systemd service file available, but buggy at the moment (need `restart` after a `start`)
* fixed parameters not passing through command line and used
* non-daemonize mode added - paramter: `-n=0`; configuration: `daemonize 0`
* Added the ability to launch the game (`default` or `clicked` options available)
* Added `actiontype` to configuration and command-line paramter
* 0 = default, 1 = clicked
### 0.0.1 Alpha
* First release
* Basic daemon implementation implemented

1 change: 1 addition & 0 deletions config/conf_example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ interval 1
thresholdinterval 2
connectiontimeout 10
notifytimeout 10
actiontype 1

newappid 244630 "NEOTOKYO" 0
newappid 282440 "Quake Live" 100
3 changes: 1 addition & 2 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project('steamcountsnotifyd'
, 'cpp'
, default_options : ['warning_level=3', 'cpp_std=c++17', 'optimization=3', 'werror=false', 'debug=true']
, version : '0.0.1'
, version : '0.0.2'
)

cc = meson.get_compiler('cpp')
Expand All @@ -24,7 +24,6 @@ thread_dep = dependency('threads', required : true) # C++11 threads
libcurl_dep = dependency('libcurl', required : true) # libcurl
libnotify_dep = dependency('libnotify', required : true) # libnotify
systemd_dep = dependency('systemd', required : false) # systemd
#glib_dep = dependency('glib', required : true) # glib

src = [
'./src/main.cpp'
Expand Down
10 changes: 5 additions & 5 deletions src/core/counterThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
#include "wrapper/notify.h"

// Called once clicked
void gameCallback(NotifyNotification *notify, char *action, gpointer data)
// Requires GMainLoop
void gameCallback(NotifyNotification * /*notify*/, char * /*action*/, gpointer data)
{
//unsigned int appid = 282440;
unsigned int appid = static_cast<unsigned int>(reinterpret_cast<std::uintptr_t>(data));
std::string command = R"steamRun(steam steam://rungameid/)steamRun"+std::to_string(appid);
//system(command.c_str());
std::cout << command << '\n';
system(command.c_str());
}

void cthread::appidRunning(unsigned int appid, param::appidName_s game, const param::config &config)
void cthread::run(unsigned int appid, param::appidName_s game, const param::config &config)
{
unsigned int currentCount = 0;
bool notify = false;
Expand All @@ -33,6 +32,7 @@ void cthread::appidRunning(unsigned int appid, param::appidName_s game, const pa

wrapper::notify notifyJob;
notifyJob.setTimeout(config.getNotificationTimeout());
notifyJob.addAction(config.getActionType(), "Launch game", gameCallback, reinterpret_cast<void *>(appid));

while (running)
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/counterThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace cthread
{
void appidRunning(unsigned int appid, param::appidName_s game, const param::config &config);
void run(unsigned int appid, param::appidName_s game, const param::config &config);
}

#endif
6 changes: 4 additions & 2 deletions src/core/help.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"-i Interval: How long in minutes to delay between each player count fetch.\n"\
"-t Threshold interval: When the threshold's achieved, what interval gets extended to.\n"\
"-c Connection Timeout: How long in seconds the connection stay puts.\n"\
"-n Notification Timeout: How long in seconds the notification stays shown.\n"\
"-n Notification Timeout: How long in seconds the notification stays shown.\n"\
"-a Action type: Which type of clickable notification should use: 0 - default, 1 - button\n"\
"-d Daemon: Defaults to daemonize, 0 to disable daemonization\n"\
"\n"\
"-v Prints version information.\n"\
"-h Prints this help information.\n"
Expand All @@ -16,6 +18,6 @@
"steamcountsnotifyd\n"\
"The Steam player count notification daemon\n"\
"\n"\
"0.0.1 - Alpha Release\n"
"0.0.2 - Alpha Release\n"

#endif
22 changes: 21 additions & 1 deletion src/core/params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ void param::config::readConfigurationFile(const std::string &confFilePath)
strMapToVal["thresholdinterval"] = 2; // Minutes
strMapToVal["connectiontimeout"] = 10; // Seconds
strMapToVal["notificationtimeout"] = 10; // Seconds
strMapToVal["actiontype"] = 0; // 0 = default (default), 1 = clicked
strMapToVal["daemonize"] = 1; // 0 = non-daemonize, 1 = daemonize (default)
this->daemonize = true;

wrapper::daemon::log(confFilePath);
Expand Down Expand Up @@ -73,11 +75,13 @@ void param::config::readConfigurationFile(const std::string &confFilePath)
wrapper::daemon::log("Cannot find configuration file.");
}

// Set the configuration file's settings to the program
this->intervalMins = strMapToVal["interval"];
this->thresholdIntervalMins = strMapToVal["thresholdinterval"];
this->connectionTimeout = strMapToVal["connectiontimeout"];
this->notificationTimeout = strMapToVal["notificationtimeout"];
this->daemonize = true;
this->actionType = strMapToVal["actiontype"];
this->daemonize = strMapToVal["daemonize"];
}

param::config::config()
Expand Down Expand Up @@ -115,6 +119,19 @@ unsigned int param::config::getNotificationTimeout() const
return this->notificationTimeout;
}

std::string_view param::config::getActionType() const
{
switch (this->actionType)
{
case 0:
return "default";
case 1:
return "clicked";
default:
return "default";
}
}

param::appidNameMap param::config::getAppidMap() const
{
return this->appidMap;
Expand Down Expand Up @@ -160,6 +177,9 @@ bool param::config::setArg(std::string &arg)
case 'n':
this->notificationTimeout = val;
break;
case 'a':
this->actionType = val;
break;
default:
std::cerr << "ERROR: '" << arg[1] << "' not found.\n";
return false;
Expand Down
2 changes: 2 additions & 0 deletions src/core/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace param
unsigned int thresholdIntervalMins;
unsigned int connectionTimeout;
unsigned int notificationTimeout;
unsigned int actionType;
appidNameMap appidMap;
bool setArg(std::string &arg);
void readConfigurationFile(const std::string &confFilePath);
Expand All @@ -36,6 +37,7 @@ namespace param
unsigned int getThresholdIntervalMins() const;
unsigned int getConnectionTimeout() const;
unsigned int getNotificationTimeout() const;
std::string_view getActionType() const;
appidNameMap getAppidMap() const;
bool setFromArgs(std::deque<std::string> &args);
};
Expand Down
11 changes: 8 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
* steamcountsnotifyd
*
* Steam counter notiifcation daemon
* version Pre-Alpha 2019-09-11
* version Alpha v0.0.2 - 2019-09-16
*
* TODO:
* Per-server notification
* Click to load game
*/

#include <iostream>
Expand All @@ -23,13 +22,17 @@
#include "wrapper/daemon.h"
#include "wrapper/notify.h"

static GMainLoop *loop;

int main(int argc, char **argv)
{
std::deque<std::string> args = tool::toArgs(argc, argv);
args.pop_front(); // Program execution name not needed
param::config config;
bool running = config.setFromArgs(args);

loop = g_main_loop_new(nullptr, FALSE);

// If help or version message not used (normal execution)
if (running)
{
Expand All @@ -45,9 +48,11 @@ int main(int argc, char **argv)

for (const auto &[appid, game] : config.getAppidMap())
{
appidThreadVector.emplace_back(std::thread(std::function(cthread::appidRunning), appid, game, config));
appidThreadVector.emplace_back(std::thread(std::function(cthread::run), appid, game, config));
}

g_main_loop_run(loop);

// Join thread if joinable
for (std::thread &thread : appidThreadVector)
{
Expand Down

0 comments on commit b7eb89d

Please sign in to comment.