Modifications to Game Launcher to fixup the display of names / status.

Added Date check to DHT Server File, so we don't download each restart.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@378 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2008-03-05 19:03:51 +00:00
parent d05ef8d797
commit 7eeb4420fe
10 changed files with 139 additions and 20 deletions

View File

@ -35,6 +35,7 @@ class DHTClient
public:
/* initialise from file */
virtual bool checkServerFile(std::string filename) = 0;
virtual bool loadServers(std::string filename) = 0;
virtual bool loadServersFromWeb(std::string storename) = 0;
virtual bool loadServers(std::istream&) = 0;
@ -54,6 +55,7 @@ class DHTClientDummy: public DHTClient
public:
/* initialise from file */
virtual bool checkServerFile(std::string filename) { return false; }
virtual bool loadServers(std::string filename) { return true; }
virtual bool loadServersFromWeb(std::string storename) { return true; }
virtual bool loadServers(std::istream&) { return true; }

View File

@ -44,6 +44,97 @@ const std::string openDHT_Agent = "RS-HTTP-V0.4";
#define OPENDHT_DEBUG 1
bool OpenDHTClient::checkServerFile(std::string filename)
{
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::checkServerFile(" << filename << ")" << std::endl;
#endif
/* open the file */
std::ifstream file(filename.c_str());
if (file.fail())
{
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::checkServerFile() Open Failed" << std::endl;
#endif
return false;
}
/* get the first line */
std::string line;
getline(file, line);
char day[16], month[16];
int date;
char day2[16], month2[16];
int date2;
if (3 != sscanf(line.c_str(), "%15s %15s %d", day, month, &date))
{
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::checkServerFile() failed file TS parse";
std::cerr << std::endl;
#endif
return false;
}
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::checkServerFile() file TS month: ";
std::cerr << month << " date: " << date << std::endl;
#endif
/* store current timestamp */
struct tm result;
time_t now = time(NULL);
char nowstr[1023];
asctime_r(gmtime_r(&now, &result), nowstr);
if (3 != sscanf(nowstr, "%15s %15s %d", day2, month2, &date2))
{
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::checkServerFile() failed now TS parse";
std::cerr << std::endl;
#endif
return false;
}
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::checkServerFile() current TS month: ";
std::cerr << month2 << " date: " << date2 << std::endl;
#endif
/* if month is different */
if (0 != strcmp(month, month2))
{
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::checkServerFile() different MONTHS fail";
std::cerr << std::endl;
#endif
return false;
}
/* if month is different */
int delta = abs(date-date2);
if (delta > 2)
{
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::checkServerFile() fail - large DATE diff: " << delta;
std::cerr << std::endl;
#endif
return false;
}
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::checkServerFile() file is up-to-date!";
std::cerr << std::endl;
#endif
return true;
}
bool OpenDHTClient::loadServers(std::string filename)
{
/* open the file */

View File

@ -55,6 +55,7 @@ virtual bool publishKey(std::string key, std::string value, uint32_t ttl);
virtual bool searchKey(std::string key, std::list<std::string> &values);
/* Fns accessing data */
virtual bool checkServerFile(std::string filename);
virtual bool loadServers(std::string filename);
virtual bool loadServersFromWeb(std::string storefname);
virtual bool loadServers(std::istream&);

View File

@ -122,7 +122,12 @@ bool OpenDHTMgr::init()
}
filename += "ODHTservers.txt";
if (!mClient -> loadServersFromWeb(filename))
/* check file date first */
if (mClient -> checkServerFile(filename))
{
return mClient -> loadServers(filename);
}
else if (!mClient -> loadServersFromWeb(filename))
{
return mClient -> loadServers(filename);
}

View File

@ -58,7 +58,7 @@ class RsGameInfo
class RsGamePeer
{
public:
std::string name;
std::string id;
bool invite;
bool interested;
bool play;

View File

@ -511,7 +511,7 @@ int RsServer::StartupRetroShare(RsInit *config)
ad = new p3disc(mAuthMgr, mConnMgr);
msgSrv = new p3MsgService(mConnMgr);
chatSrv = new p3ChatService(mConnMgr);
p3GameLauncher *gameLauncher = new p3GameLauncher();
p3GameLauncher *gameLauncher = new p3GameLauncher(mConnMgr);
pqih -> addService(ad);
pqih -> addService(msgSrv);

View File

@ -26,6 +26,7 @@
#include "services/p3gamelauncher.h"
#include "services/p3gameservice.h"
#include "pqi/pqidebug.h"
#include "pqi/p3connmgr.h"
#include <sstream>
#include <iomanip>
@ -103,11 +104,12 @@ const uint32_t RS_GAME_MSG_REJECT = 6; /* ANY -> ANY */
const int p3gamezone = 1745;
p3GameLauncher::p3GameLauncher()
:p3Service(RS_SERVICE_TYPE_GAME_LAUNCHER)
p3GameLauncher::p3GameLauncher(p3ConnectMgr *connMgr)
:p3Service(RS_SERVICE_TYPE_GAME_LAUNCHER),
mConnMgr(connMgr)
{
//addSerialType(new RsGameSerialiser());
mOwnId = "mOwnId";
mOwnId = mConnMgr->getOwnId();
}
int p3GameLauncher::tick()
@ -196,16 +198,16 @@ std::string p3GameLauncher::newGame(uint16_t srvId, std::string name)
newGame.numPlayers = 0;
newGame.gameName = name;
newGame.interestedPeers.clear();
newGame.peerIds.clear();
newGame.state = RS_GAME_INIT_SETUP; /* Server Only */
newGame.areServer = true;
newGame.serverId = mOwnId;
newGame.allowedPeers.push_back(mOwnId);
newGame.interestedPeers.push_back(mOwnId);
newGame.peerIds.push_back(mOwnId);
newGame.interestedPeers.clear();
newGame.peerIds.clear();
newGame.state = RS_GAME_INIT_SETUP; /* Server Only */
/* send messages to peers inviting to game */
std::list<std::string>::const_iterator it;
@ -268,6 +270,7 @@ bool p3GameLauncher::inviteGame(std::string gameId)
RsGameItem *rgi = new RsGameItem();
rgi->serviceId = git->second.serviceId;
rgi->gameId = git->second.gameId;
rgi->gameComment= git->second.gameName;
rgi->numPlayers = git->second.numPlayers;
rgi->players = git->second.allowedPeers;
@ -310,6 +313,7 @@ bool p3GameLauncher::confirmGame(std::string game)
RsGameItem *rgi = new RsGameItem();
rgi->serviceId = git->second.serviceId;
rgi->gameId = git->second.gameId;
rgi->gameComment= git->second.gameName;
rgi->numPlayers = git->second.numPlayers;
rgi->players = git->second.peerIds;
@ -354,6 +358,7 @@ bool p3GameLauncher::playGame(std::string gameId)
RsGameItem *rgi = new RsGameItem();
rgi->serviceId = git->second.serviceId;
rgi->gameId = git->second.gameId;
rgi->gameComment= git->second.gameName;
rgi->numPlayers = git->second.numPlayers;
rgi->players = git->second.peerIds;
@ -378,6 +383,7 @@ bool p3GameLauncher::playGame(std::string gameId)
RsGameItem *rgi = new RsGameItem();
rgi->serviceId = git->second.serviceId;
rgi->gameId = git->second.gameId;
rgi->gameComment= git->second.gameName;
rgi->numPlayers = 0;
rgi->players.clear();
@ -575,6 +581,7 @@ bool p3GameLauncher::inviteResponse(std::string gameId, bool interested)
RsGameItem *rgi = new RsGameItem();
rgi->serviceId = git->second.serviceId;
rgi->gameId = git->second.gameId;
rgi->gameComment= git->second.gameName;
rgi->numPlayers = 0;
rgi->players.clear();
@ -671,7 +678,7 @@ bool p3GameLauncher::getGameDetail(std::string gameId, RsGameDetail &detail)
it != git->second.allowedPeers.end(); it++)
{
RsGamePeer rgp;
rgp.name = "PEER???";
rgp.id = *it;
rgp.invite = true;
rgp.interested = false;
rgp.play = false;
@ -689,13 +696,13 @@ bool p3GameLauncher::getGameDetail(std::string gameId, RsGameDetail &detail)
it != git->second.allowedPeers.end(); it++)
{
RsGamePeer rgp;
rgp.name = "PEER???";
rgp.id = *it;
rgp.invite = true;
if (git->second.interestedPeers.end() !=
std::find(git->second.interestedPeers.begin(),
git->second.interestedPeers.end(),
git->first))
*it))
{
rgp.interested = true;
}
@ -707,7 +714,7 @@ bool p3GameLauncher::getGameDetail(std::string gameId, RsGameDetail &detail)
if (git->second.peerIds.end() !=
std::find(git->second.peerIds.begin(),
git->second.peerIds.end(),
git->first))
*it))
{
rgp.play = true;
}
@ -729,7 +736,7 @@ bool p3GameLauncher::getGameDetail(std::string gameId, RsGameDetail &detail)
it != git->second.peerIds.end(); it++)
{
RsGamePeer rgp;
rgp.name = "PEER???";
rgp.id = *it;
rgp.invite = true;
rgp.interested = true;
rgp.play = true;
@ -933,6 +940,7 @@ int p3GameLauncher::handleClientStart(RsGameItem *gi)
gameStatus gs;
gs.serviceId = gi->serviceId;
gs.gameId = gi->gameId;
gs.gameName = gi->gameComment;
gs.areServer = false;
gs.serverId = gi->PeerId();
gs.state = RS_GAME_INIT_INVITED; /* Client */

View File

@ -39,6 +39,9 @@
#include "serialiser/rsgameitems.h"
#include "rsiface/rsgame.h"
class p3ConnectMgr;
class gameAvail
{
uint32_t serviceId;
@ -73,7 +76,7 @@ class p3GameService;
class p3GameLauncher: public p3Service, public RsGameLauncher
{
public:
p3GameLauncher();
p3GameLauncher(p3ConnectMgr *connMgr);
/***** EXTERNAL RsGameLauncher Interface *******/
/* server commands */
@ -141,6 +144,7 @@ bool checkGameProperties(uint16_t serviceId, uint16_t players);
std::map<uint16_t, p3GameService *> gameList;
std::map<std::string, gameStatus> gamesCurrent;
p3ConnectMgr *mConnMgr;
std::string mOwnId;
};

View File

@ -139,8 +139,9 @@ void GamesDialog::updateGameList()
{
/* make a widget per game */
QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0);
std::string serverName = rsPeers->getPeerName(it->serverId);
item -> setText(GAME_LIST_TYPE, QString::fromStdString(it->gameType));
item -> setText(GAME_LIST_SERVER, QString::fromStdString(it->serverName));
item -> setText(GAME_LIST_SERVER, QString::fromStdString(serverName));
item -> setText(GAME_LIST_NAME, QString::fromStdString(it->gameName));
item -> setText(GAME_LIST_STATUS, QString::fromStdString(it->status));
item -> setText(GAME_LIST_ID, QString::fromStdString(it->gameId));
@ -236,7 +237,14 @@ void GamesDialog::updateGameDetails()
if (showPeer)
{
QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0);
item -> setText(GAME_PEER_PLAYER, QString::fromStdString(it->second.name));
std::string name = rsPeers->getPeerName(it->second.id);
if (it->second.id == rsPeers->getOwnId())
{
name = "Yourself";
}
item -> setText(GAME_PEER_PLAYER, QString::fromStdString(name));
if (it->second.invite)
item -> setText(GAME_PEER_INVITE, "Yes");
else
@ -254,7 +262,7 @@ void GamesDialog::updateGameDetails()
/* add a checkItem here */
//item -> setText(GAME_PEER_PLAY, "Maybe");
item -> setText(GAME_PEER_ID, QString::fromStdString(it->first));
item -> setText(GAME_PEER_ID, QString::fromStdString(it->second.id));
if ((oldSelect) && (oldId == it->first))
{

View File

@ -58,7 +58,7 @@ class RsGameInfo
class RsGamePeer
{
public:
std::string name;
std::string id;
bool invite;
bool interested;
bool play;