Skip to content

Commit

Permalink
Implemented /track & /trackoff
Browse files Browse the repository at this point in the history
Two new commands
/track <username> & /trackoff

This will /whois username every 4 seconds, and once they are in-game, it will automatically search for that users game via /game gamename.

This will also play track_done.wav once the player is in-game. This is to notify the user is in-game, and GProxy is searching for their game name.

Code was provided by a previous suggestion made in 2011.
(w3gh#5)
• Sound notification works/tested on Windows/Mac.
• track_done.wav provided with compiled GProxy on ENT Gaming Wiki.
  • Loading branch information
Unitil committed Sep 25, 2018
1 parent 5b394f8 commit f197610
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 0 deletions.
Binary file modified gproxy.exe
Binary file not shown.
55 changes: 55 additions & 0 deletions gproxy/bnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include "bnet.h"
#include "gameprotocol.h"


#include "gettimeofday.h"

//
// CBNET
//
Expand Down Expand Up @@ -93,6 +96,11 @@ CBNET :: CBNET( CGProxy *nGProxy, string nServer, string nBNLSServer, uint16_t n
m_LoggedIn = false;
m_InChat = false;
m_InGame = false;


trackData.active = false;
trackData.username = "";
gettimeofday(&(trackData.lastWhoisTime), NULL);
}

CBNET :: ~CBNET( )
Expand Down Expand Up @@ -729,7 +737,54 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent )
else if( Event == CBNETProtocol :: EID_CHANNELRESTRICTED )
CONSOLE_Print( "[BNET] channel restricted" );
else if( Event == CBNETProtocol :: EID_INFO )
{
CONSOLE_Print( "[INFO] " + Message );


// are we tracking a user by issuing /whois commands ever few seconds?
if (trackData.active) {
// yes - ok, copy the message then lowercase it so that we
// can search it effectively.
string MsgCopy = string(Message);
transform(MsgCopy.begin(), MsgCopy.end(), MsgCopy.begin(), tolower);

if (MsgCopy.find(trackData.username) == 0) {
// message starts with the username we're looking for, so it might be interesting...
int index;
string IN_GAME = " in game ";
if ( (index = MsgCopy.find(IN_GAME)) != MsgCopy.npos ) {
// the user we're tracking is (now) in a game! hooray!

// the game name is at the end of the message, but be sure to clip the "." char off the end...
int startPos = index + IN_GAME.length();
int nChars = MsgCopy.length() - startPos - 1;

if (nChars >= 1) {
string gameName = MsgCopy.substr(startPos, nChars);
SetSearchGameName(gameName); // Start looking for the game

// same log message as if the user typed /game ...
CONSOLE_Print( "[BNET] looking for a game named \"" + gameName + "\" for up to two minutes" );

trackData.active = false; // stop tracking

#ifdef WIN32
// notify user that we've found a game
PlaySound(L"track_done.wav", NULL, SND_FILENAME | SND_ASYNC);
#endif
#ifdef __APPLE__
// notify user that we've found a game
string file = "track_done.wav";
string command = "afplay " + file;
system(command.c_str());
#endif
} else {
CONSOLE_Print("Unable to find game name in message: " + MsgCopy);
}
}
}
}
}
else if( Event == CBNETProtocol :: EID_ERROR )
CONSOLE_Print( "[ERROR] " + Message );
else if( Event == CBNETProtocol :: EID_EMOTE )
Expand Down
7 changes: 7 additions & 0 deletions gproxy/bnet.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ class CBNET
void QueueGetGameList( uint32_t numGames );
void QueueGetGameList( string gameName );
void QueueJoinGame( string gameName );


struct _trackData {
bool active;
string username;
struct timeval lastWhoisTime;
} trackData;
};

#endif
40 changes: 40 additions & 0 deletions gproxy/gettimeofday.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "gettimeofday.h"

#ifdef WIN32

int gettimeofday(struct timeval *tv, struct timezone *tz)
{
FILETIME ft;
unsigned __int64 tmpres = 0;
static int tzflag;

if (NULL != tv)
{
GetSystemTimeAsFileTime(&ft);

tmpres |= ft.dwHighDateTime;
tmpres <<= 32;
tmpres |= ft.dwLowDateTime;

/*converting file time to unix epoch*/
tmpres -= DELTA_EPOCH_IN_MICROSECS;
tmpres /= 10; /*convert into microseconds*/
tv->tv_sec = (long)(tmpres / 1000000UL);
tv->tv_usec = (long)(tmpres % 1000000UL);
}

if (NULL != tz)
{
if (!tzflag)
{
_tzset();
tzflag;
}
tz->tz_minuteswest = _timezone / 60;
tz->tz_dsttime = _daylight;
}

return 0;
}

#endif
26 changes: 26 additions & 0 deletions gproxy/gettimeofday.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef GETTIMEOFDAY_H
#define GETTIMEOFDAY_H

#ifdef WIN32
#include < time.h >
#include <windows.h>
#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
#else
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
#endif

struct timezone
{
int tz_minuteswest; /* minutes W of Greenwich */
int tz_dsttime; /* type of dst correction */
};

int gettimeofday(struct timeval *, struct timezone *);

#else

#include <sys/time.h>

#endif
#endif
40 changes: 40 additions & 0 deletions gproxy/gproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include "gameprotocol.h"
#include "gpsprotocol.h"


#include "gettimeofday.h"

#include <signal.h>
#include <stdlib.h>

Expand Down Expand Up @@ -632,11 +635,31 @@ int main( int argc, char **argv )

gGProxy = new CGProxy( !CDKeyTFT.empty( ), War3Path, CDKeyROC, CDKeyTFT, Server, Username, Password, Channel, War3Version, Port, EXEVersion, EXEVersionHash, PasswordHashType );


struct timeval currTime;
int timeDiff;

while( 1 )
{
if( gGProxy->Update( 40000 ) )
break;


if (gGProxy->m_BNET->trackData.active) {
gettimeofday(&currTime, NULL);

// find difference, in milliseconds.
timeDiff = (currTime.tv_sec - gGProxy->m_BNET->trackData.lastWhoisTime.tv_sec) * 1000;
timeDiff += (currTime.tv_usec - gGProxy->m_BNET->trackData.lastWhoisTime.tv_usec) / 1000;

if (timeDiff >= 4000) {
//CONSOLE_Print("DO WHOIS NOW");
gGProxy->m_BNET->QueueChatCommand( "/whois " + gGProxy->m_BNET->trackData.username );
// reset last whois time
memcpy(&(gGProxy->m_BNET->trackData.lastWhoisTime), &currTime, sizeof(currTime));
}
}

bool Quit = false;
int c = wgetch( gInputWindow );

Expand Down Expand Up @@ -675,6 +698,8 @@ int main( int argc, char **argv )
CONSOLE_Print( " /filter <f> : start filtering public game names for <f>", false );
CONSOLE_Print( " /filteroff : stop filtering public game names", false );
CONSOLE_Print( " /game <gamename> : look for a specific game named <gamename>", false );
CONSOLE_Print( " /track <username> : starts tracking specific username", false );
CONSOLE_Print( " /trackoff : stops tracking", false );
CONSOLE_Print( " /help : show help text", false );
CONSOLE_Print( " /public : enable listing of public games", false );
CONSOLE_Print( " /publicoff : disable listing of public games", false );
Expand Down Expand Up @@ -812,6 +837,21 @@ int main( int argc, char **argv )
#endif
else if( Command == "/version" )
CONSOLE_Print( "[GPROXY] GProxy++ Version " + gGProxy->m_Version );


else if( Command.size( ) >= 8 && Command.substr( 0, 7 ) == "/track " )
{
gGProxy->m_BNET->trackData.active = true;
gGProxy->m_BNET->trackData.username = Command.substr(7);
}
else if( Command == "/trackoff" ) {
if (gGProxy->m_BNET->trackData.active) {
CONSOLE_Print("[BNET] Stopped tracking " + gGProxy->m_BNET->trackData.username);
gGProxy->m_BNET->trackData.active = false;
} else {
CONSOLE_Print("[BNET] Tracking is not active.");
}
}
else
gGProxy->m_BNET->QueueChatCommand( gInputBuffer );

Expand Down
8 changes: 8 additions & 0 deletions gproxy/gproxy.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@
RelativePath=".\gameprotocol.cpp"
>
</File>
<File
RelativePath=".\gettimeofday.cpp"
>
</File>
<File
RelativePath=".\gproxy.cpp"
>
Expand Down Expand Up @@ -246,6 +250,10 @@
RelativePath=".\gameprotocol.h"
>
</File>
<File
RelativePath=".\gettimeofday.h"
>
</File>
<File
RelativePath=".\gproxy.h"
>
Expand Down

0 comments on commit f197610

Please sign in to comment.