mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Improvements to the Games Launcher.
Addition of new Bootstrap Peers. Completion of rsgameitems serialiser. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@383 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
5410a20756
commit
79023e7c7c
@ -2781,6 +2781,19 @@ bool p3ConnectMgr::addBootstrapStunPeers()
|
||||
id = "8ad7c08e7778e0289de04843bf57a6ae";
|
||||
stunCollect(RsUtil::HashId(id, false), dummyaddr, flags);
|
||||
|
||||
// Donated by public.
|
||||
id = "8523688347027884059506005618ae74"; /* tm */
|
||||
stunCollect(RsUtil::HashId(id, false), dummyaddr, flags);
|
||||
|
||||
id = "1bd15b320269fa1561ceb1162fd042f0"; /* cp */
|
||||
stunCollect(RsUtil::HashId(id, false), dummyaddr, flags);
|
||||
|
||||
id = "2cf2361f2afcd6d871159714bbbfc502"; /* cc */
|
||||
stunCollect(RsUtil::HashId(id, false), dummyaddr, flags);
|
||||
|
||||
id = "128646cdf761970376a62c52c372c931"; /* rf */
|
||||
stunCollect(RsUtil::HashId(id, false), dummyaddr, flags);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ class RsGameInfo
|
||||
std::string serverId;
|
||||
|
||||
std::string gameType;
|
||||
std::string gameName;
|
||||
std::wstring gameName;
|
||||
std::string serverName;
|
||||
std::string status;
|
||||
uint16_t numPlayers;
|
||||
@ -69,7 +69,7 @@ class RsGameDetail
|
||||
public:
|
||||
std::string gameId;
|
||||
std::string gameType;
|
||||
std::string gameName;
|
||||
std::wstring gameName;
|
||||
|
||||
bool areServer; /* are we the server? */
|
||||
std::string serverId; /* if not, who is? */
|
||||
@ -87,7 +87,7 @@ class RsGameLauncher
|
||||
public:
|
||||
|
||||
/* server commands */
|
||||
virtual std::string createGame(uint32_t gameType, std::string name) = 0;
|
||||
virtual std::string createGame(uint32_t gameType, std::wstring name) = 0;
|
||||
virtual bool deleteGame(std::string gameId) = 0;
|
||||
virtual bool inviteGame(std::string gameId) = 0;
|
||||
virtual bool playGame(std::string gameId) = 0;
|
||||
|
@ -12,6 +12,7 @@ RSOBJ += rstlvfileitem.o rstlvutil.o # TLV Objs
|
||||
RSOBJ += rsbaseitems.o rsconfigitems.o rsdiscitems.o # RsItems
|
||||
RSOBJ += rsmsgitems.o rsrankitems.o # RsItems
|
||||
RSOBJ += rsphotoitems.o # RsItems
|
||||
RSOBJ += rsgameitems.o # RsItems
|
||||
|
||||
TESTOBJ = tlvbase_test.o tlvbase_test2.o tlvfileitem_test.o
|
||||
TESTOBJ += tlvitems_test.o tlvstack_test.o tlvconfig_test.o
|
||||
|
211
libretroshare/src/serialiser/rsgameitems.cc
Normal file
211
libretroshare/src/serialiser/rsgameitems.cc
Normal file
@ -0,0 +1,211 @@
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsgameitems.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rsgameitems.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
|
||||
#define RSSERIAL_DEBUG 1
|
||||
#include <iostream>
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
RsGameItem::~RsGameItem()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void RsGameItem::clear()
|
||||
{
|
||||
serviceId = 0;
|
||||
numPlayers = 0;
|
||||
msg = 0;
|
||||
|
||||
gameId.clear();
|
||||
gameComment.clear();
|
||||
players.TlvClear();
|
||||
}
|
||||
|
||||
std::ostream &RsGameItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGameItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
printIndent(out, int_Indent);
|
||||
out << "serviceId: " << serviceId << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
out << "numPlayers: " << numPlayers << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
out << "msg: " << msg << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "gameId: " << gameId << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
std::string cnv_comment(gameComment.begin(), gameComment.end());
|
||||
out << "msg: " << cnv_comment << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Players Ids: " << std::endl;
|
||||
players.print(out, int_Indent);
|
||||
|
||||
printRsItemEnd(out, "RsGameItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGameSerialiser::sizeItem(RsGameItem *item)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += 4; /* serviceId */
|
||||
s += 4; /* numPlayers */
|
||||
s += 4; /* msg */
|
||||
s += GetTlvStringSize(item->gameId);
|
||||
s += GetTlvWideStringSize(item->gameComment);
|
||||
s += item->players.TlvSize();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/* serialise the data to the buffer */
|
||||
bool RsGameSerialiser::serialiseItem(RsGameItem *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
uint32_t tlvsize = sizeItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (*pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
*pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
std::cerr << "RsGameSerialiser::serialiseItem() Header: " << ok << std::endl;
|
||||
std::cerr << "RsGameSerialiser::serialiseItem() Size: " << tlvsize << std::endl;
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->serviceId);
|
||||
std::cerr << "RsGameSerialiser::serialiseItem() serviceId: " << ok << std::endl;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->numPlayers);
|
||||
std::cerr << "RsGameSerialiser::serialiseItem() numPlayers: " << ok << std::endl;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->msg);
|
||||
std::cerr << "RsGameSerialiser::serialiseItem() msg: " << ok << std::endl;
|
||||
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GENID, item->gameId);
|
||||
std::cerr << "RsGameSerialiser::serialiseItem() gameId: " << ok << std::endl;
|
||||
ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_COMMENT, item->gameComment);
|
||||
std::cerr << "RsGameSerialiser::serialiseItem() gameComment: " << ok << std::endl;
|
||||
ok &= item->players.SetTlv(data, tlvsize, &offset);
|
||||
std::cerr << "RsMsgSerialiser::serialiseItem() players: " << ok << std::endl;
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsGameSerialiser::serialiseItem() Size Error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGameItem *RsGameSerialiser::deserialiseItem(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t tlvsize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_GAME_LAUNCHER != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_DEFAULT != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*pktsize < tlvsize) /* check size */
|
||||
return NULL; /* not enough data */
|
||||
|
||||
/* set the packet length */
|
||||
*pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsGameItem *item = new RsGameItem();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &(item->serviceId));
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &(item->numPlayers));
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &(item->msg));
|
||||
|
||||
ok &= GetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GENID, item->gameId);
|
||||
ok &= GetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_COMMENT, item->gameComment);
|
||||
ok &= item->players.GetTlv(data, tlvsize, &offset);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGameSerialiser::size(RsItem *item)
|
||||
{
|
||||
return sizeItem((RsGameItem *) item);
|
||||
}
|
||||
|
||||
bool RsGameSerialiser::serialise(RsItem *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
return serialiseItem((RsGameItem *) item, data, pktsize);
|
||||
}
|
||||
|
||||
RsItem *RsGameSerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||
{
|
||||
return deserialiseItem(data, pktsize);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
|
||||
|
@ -41,19 +41,18 @@ class RsGameItem: public RsItem
|
||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GAME_LAUNCHER,
|
||||
RS_PKT_SUBTYPE_DEFAULT)
|
||||
{ return; }
|
||||
virtual ~RsGameItem() { return; }
|
||||
virtual void clear() { return; }
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0)
|
||||
{ return out; }
|
||||
virtual ~RsGameItem();
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
uint32_t serviceId;
|
||||
std::string gameId;
|
||||
std::string gameComment;
|
||||
|
||||
uint16_t numPlayers;
|
||||
std::list<std::string> players;
|
||||
uint32_t numPlayers;
|
||||
uint32_t msg; /* RS_GAME_MSG_XXX */
|
||||
|
||||
std::string gameId;
|
||||
std::wstring gameComment;
|
||||
|
||||
RsTlvPeerIdSet players;
|
||||
};
|
||||
|
||||
class RsGameSerialiser: public RsSerialType
|
||||
|
@ -33,6 +33,8 @@
|
||||
/* global variable for GUI */
|
||||
RsGameLauncher *rsGameLauncher = NULL;
|
||||
|
||||
#define GAME_DEBUG 1
|
||||
#define TEST_NO_GAMES 1
|
||||
|
||||
/* So STATEs is always the best way to do things....
|
||||
*
|
||||
@ -108,7 +110,12 @@ p3GameLauncher::p3GameLauncher(p3ConnectMgr *connMgr)
|
||||
:p3Service(RS_SERVICE_TYPE_GAME_LAUNCHER),
|
||||
mConnMgr(connMgr)
|
||||
{
|
||||
//addSerialType(new RsGameSerialiser());
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::p3GameLauncher()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
addSerialType(new RsGameSerialiser());
|
||||
mOwnId = mConnMgr->getOwnId();
|
||||
}
|
||||
|
||||
@ -116,6 +123,7 @@ int p3GameLauncher::tick()
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, p3gamezone,
|
||||
"p3GameLauncher::tick()");
|
||||
checkIncoming();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -163,6 +171,11 @@ std::string generateRandomGameId()
|
||||
|
||||
bool p3GameLauncher::resumeGame(std::string)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::resumeGame()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
/* get game details from p3gameService */
|
||||
/* add to status reports */
|
||||
/* send resume invites to peers in list */
|
||||
@ -179,16 +192,28 @@ bool p3GameLauncher::resumeGame(std::string)
|
||||
|
||||
/* Server commands */
|
||||
|
||||
std::string p3GameLauncher::createGame(uint32_t gameType, std::string name)
|
||||
std::string p3GameLauncher::createGame(uint32_t gameType, std::wstring name)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::createGame()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
/* translate Id */
|
||||
uint16_t srvId = gameType;
|
||||
|
||||
return newGame(srvId, name);
|
||||
}
|
||||
|
||||
std::string p3GameLauncher::newGame(uint16_t srvId, std::string name)
|
||||
std::string p3GameLauncher::newGame(uint16_t srvId, std::wstring name)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::newGame()";
|
||||
std::string tmpname(name.begin(), name.end());
|
||||
std::cerr << "srvId: " << srvId << " name: " << tmpname;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
/* generate GameId (random string) */
|
||||
std::string gameId = generateRandomGameId();
|
||||
|
||||
@ -220,11 +245,23 @@ std::string p3GameLauncher::newGame(uint16_t srvId, std::string name)
|
||||
|
||||
void p3GameLauncher::cleanupGame(std::string gameId)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::cleanupGame()";
|
||||
std::cerr << " gameId: " << gameId;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
deleteGame(gameId);
|
||||
}
|
||||
|
||||
bool p3GameLauncher::deleteGame(std::string gameId)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::deleteGame()";
|
||||
std::cerr << " gameId: " << gameId;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string, gameStatus>::iterator git;
|
||||
git = gamesCurrent.find(gameId);
|
||||
if (git == gamesCurrent.end())
|
||||
@ -245,6 +282,12 @@ bool p3GameLauncher::deleteGame(std::string gameId)
|
||||
|
||||
bool p3GameLauncher::inviteGame(std::string gameId)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::inviteGame()";
|
||||
std::cerr << " gameId: " << gameId;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string, gameStatus>::iterator git;
|
||||
git = gamesCurrent.find(gameId);
|
||||
if (git == gamesCurrent.end())
|
||||
@ -266,13 +309,17 @@ bool p3GameLauncher::inviteGame(std::string gameId)
|
||||
/* for an invite we need:
|
||||
* serviceId, gameId, numPlayers....
|
||||
*/
|
||||
if (*it == mOwnId)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
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;
|
||||
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.ids = git->second.allowedPeers;
|
||||
|
||||
rgi->msg = RS_GAME_MSG_START;
|
||||
/* destination */
|
||||
@ -289,12 +336,18 @@ bool p3GameLauncher::inviteGame(std::string gameId)
|
||||
|
||||
|
||||
/* support Game */
|
||||
bool p3GameLauncher::confirmGame(std::string game)
|
||||
bool p3GameLauncher::confirmGame(std::string gameId)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::confirmGame()";
|
||||
std::cerr << " gameId: " << gameId;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
std::map<std::string, gameStatus>::iterator git;
|
||||
|
||||
git = gamesCurrent.find(game);
|
||||
git = gamesCurrent.find(gameId);
|
||||
if (git == gamesCurrent.end())
|
||||
{
|
||||
return false;
|
||||
@ -310,12 +363,17 @@ bool p3GameLauncher::confirmGame(std::string game)
|
||||
* serviceId, gameId, numPlayers....
|
||||
*/
|
||||
|
||||
if (*it == mOwnId)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
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;
|
||||
rgi->serviceId = git->second.serviceId;
|
||||
rgi->gameId = git->second.gameId;
|
||||
rgi->gameComment = git->second.gameName;
|
||||
rgi->numPlayers = git->second.numPlayers;
|
||||
rgi->players.ids = git->second.peerIds;
|
||||
|
||||
rgi->msg = RS_GAME_MSG_CONFIRM;
|
||||
|
||||
@ -332,6 +390,12 @@ bool p3GameLauncher::confirmGame(std::string game)
|
||||
|
||||
bool p3GameLauncher::playGame(std::string gameId)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::playGame()";
|
||||
std::cerr << " gameId: " << gameId;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string, gameStatus>::iterator git;
|
||||
|
||||
git = gamesCurrent.find(gameId);
|
||||
@ -355,12 +419,17 @@ bool p3GameLauncher::playGame(std::string gameId)
|
||||
* serviceId, gameId, numPlayers....
|
||||
*/
|
||||
|
||||
if (*it == mOwnId)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
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;
|
||||
rgi->serviceId = git->second.serviceId;
|
||||
rgi->gameId = git->second.gameId;
|
||||
rgi->gameComment = git->second.gameName;
|
||||
rgi->numPlayers = git->second.numPlayers;
|
||||
rgi->players.ids = git->second.peerIds;
|
||||
|
||||
rgi->msg = RS_GAME_MSG_PLAY;
|
||||
|
||||
@ -385,7 +454,7 @@ bool p3GameLauncher::playGame(std::string gameId)
|
||||
rgi->gameId = git->second.gameId;
|
||||
rgi->gameComment= git->second.gameName;
|
||||
rgi->numPlayers = 0;
|
||||
rgi->players.clear();
|
||||
rgi->players.ids.clear();
|
||||
|
||||
rgi->msg = RS_GAME_MSG_REJECT;
|
||||
|
||||
@ -408,6 +477,12 @@ bool p3GameLauncher::playGame(std::string gameId)
|
||||
|
||||
bool p3GameLauncher::quitGame(std::string gameId)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::checkGameProperties()";
|
||||
std::cerr << " gameId: " << gameId;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
/* TODO */
|
||||
|
||||
return false;
|
||||
@ -417,6 +492,12 @@ bool p3GameLauncher::quitGame(std::string gameId)
|
||||
|
||||
bool p3GameLauncher::invitePeer(std::string gameId, std::string peerId)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::invitePeer()";
|
||||
std::cerr << " gameId: " << gameId << " peerId: " << peerId;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string, gameStatus>::iterator git;
|
||||
git = gamesCurrent.find(gameId);
|
||||
if (git == gamesCurrent.end())
|
||||
@ -451,6 +532,12 @@ bool p3GameLauncher::invitePeer(std::string gameId, std::string peerId)
|
||||
/* Server GUI commands */
|
||||
bool p3GameLauncher::uninvitePeer(std::string gameId, std::string peerId)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::uninvitePeer()";
|
||||
std::cerr << " gameId: " << gameId << " peerId: " << peerId;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string, gameStatus>::iterator git;
|
||||
git = gamesCurrent.find(gameId);
|
||||
if (git == gamesCurrent.end())
|
||||
@ -482,12 +569,18 @@ bool p3GameLauncher::uninvitePeer(std::string gameId, std::string peerId)
|
||||
}
|
||||
|
||||
|
||||
bool p3GameLauncher::confirmPeer(std::string game, std::string peerId,
|
||||
bool p3GameLauncher::confirmPeer(std::string gameId, std::string peerId,
|
||||
int16_t pos)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::confirmPeer()";
|
||||
std::cerr << " gameId: " << gameId << " peerId: " << peerId;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string, gameStatus>::iterator git;
|
||||
|
||||
git = gamesCurrent.find(game);
|
||||
git = gamesCurrent.find(gameId);
|
||||
if (git == gamesCurrent.end())
|
||||
{
|
||||
return false;
|
||||
@ -524,15 +617,21 @@ bool p3GameLauncher::confirmPeer(std::string game, std::string peerId,
|
||||
}
|
||||
|
||||
git->second.peerIds.insert(it, peerId);
|
||||
return confirmGame(game);
|
||||
return confirmGame(gameId);
|
||||
}
|
||||
|
||||
|
||||
bool p3GameLauncher::unconfirmPeer(std::string game, std::string peerId)
|
||||
bool p3GameLauncher::unconfirmPeer(std::string gameId, std::string peerId)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::unconfirmPeer()";
|
||||
std::cerr << " gameId: " << gameId << " peerId: " << peerId;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string, gameStatus>::iterator git;
|
||||
|
||||
git = gamesCurrent.find(game);
|
||||
git = gamesCurrent.find(gameId);
|
||||
if (git == gamesCurrent.end())
|
||||
{
|
||||
return false;
|
||||
@ -551,23 +650,41 @@ bool p3GameLauncher::unconfirmPeer(std::string game, std::string peerId)
|
||||
{
|
||||
git->second.peerIds.erase(it);
|
||||
}
|
||||
return confirmGame(game);
|
||||
return confirmGame(gameId);
|
||||
}
|
||||
|
||||
|
||||
/* Client GUI Commands */
|
||||
bool p3GameLauncher::interestedPeer(std::string gameId)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::interestedPeer()";
|
||||
std::cerr << " gameId: " << gameId;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
return inviteResponse(gameId, true);
|
||||
}
|
||||
|
||||
bool p3GameLauncher::uninterestedPeer(std::string gameId)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::uninterestedPeer()";
|
||||
std::cerr << " gameId: " << gameId;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
return inviteResponse(gameId, false);
|
||||
}
|
||||
|
||||
bool p3GameLauncher::inviteResponse(std::string gameId, bool interested)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::inviteResponse()";
|
||||
std::cerr << " gameId: " << gameId << "interested: " << interested;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string, gameStatus>::iterator git;
|
||||
|
||||
git = gamesCurrent.find(gameId);
|
||||
@ -583,15 +700,17 @@ bool p3GameLauncher::inviteResponse(std::string gameId, bool interested)
|
||||
rgi->gameId = git->second.gameId;
|
||||
rgi->gameComment= git->second.gameName;
|
||||
rgi->numPlayers = 0;
|
||||
rgi->players.clear();
|
||||
rgi->players.ids.clear();
|
||||
|
||||
if (interested)
|
||||
{
|
||||
rgi->msg = RS_GAME_MSG_INTERESTED;
|
||||
git->second.state = RS_GAME_INIT_READY;
|
||||
}
|
||||
else
|
||||
{
|
||||
rgi->msg = RS_GAME_MSG_REJECT;
|
||||
git->second.state = RS_GAME_INIT_INVITED;
|
||||
}
|
||||
|
||||
/* destination */
|
||||
@ -609,6 +728,11 @@ bool p3GameLauncher::inviteResponse(std::string gameId, bool interested)
|
||||
/* get details */
|
||||
bool p3GameLauncher::getGameList(std::list<RsGameInfo> &gameList)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::getGameList()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string, gameStatus>::iterator git;
|
||||
for(git = gamesCurrent.begin(); git != gamesCurrent.end(); git++)
|
||||
{
|
||||
@ -625,16 +749,22 @@ bool p3GameLauncher::getGameList(std::list<RsGameInfo> &gameList)
|
||||
info.numPlayers = git->second.numPlayers;
|
||||
info.gameName = git->second.gameName;
|
||||
|
||||
if ((git->second.state == RS_GAME_INIT_SETUP) ||
|
||||
(git->second.state == RS_GAME_INIT_INVITED))
|
||||
if (git->second.state == RS_GAME_INIT_SETUP)
|
||||
{
|
||||
info.status = "Setup";
|
||||
}
|
||||
else if (git->second.state == RS_GAME_INIT_INVITED)
|
||||
{
|
||||
info.status = "Invite";
|
||||
}
|
||||
else if ((git->second.state == RS_GAME_INIT_CONFIRM) ||
|
||||
(git->second.state == RS_GAME_INIT_READY))
|
||||
else if (git->second.state == RS_GAME_INIT_CONFIRM)
|
||||
{
|
||||
info.status = "Confirm";
|
||||
}
|
||||
else if (git->second.state == RS_GAME_INIT_READY)
|
||||
{
|
||||
info.status = "Ready";
|
||||
}
|
||||
else if (git->second.state == RS_GAME_INIT_ACTIVE)
|
||||
{
|
||||
info.status = "Playing";
|
||||
@ -651,6 +781,12 @@ bool p3GameLauncher::getGameList(std::list<RsGameInfo> &gameList)
|
||||
|
||||
bool p3GameLauncher::getGameDetail(std::string gameId, RsGameDetail &detail)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::getGameDetail()";
|
||||
std::cerr << " gameId: " << gameId;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string, gameStatus>::iterator git;
|
||||
std::list<std::string>::iterator it;
|
||||
git = gamesCurrent.find(gameId);
|
||||
@ -660,18 +796,21 @@ bool p3GameLauncher::getGameDetail(std::string gameId, RsGameDetail &detail)
|
||||
}
|
||||
|
||||
/* fill in the details */
|
||||
detail.gameId = gameId;
|
||||
detail.gameType = git->second.serviceId;
|
||||
detail.gameName = git->second.gameName;
|
||||
detail.areServer = git->second.areServer;
|
||||
detail.serverId = git->second.serverId;
|
||||
detail.gameId = gameId;
|
||||
detail.gameType = git->second.serviceId;
|
||||
detail.gameName = git->second.gameName;
|
||||
detail.areServer = git->second.areServer;
|
||||
detail.serverId = git->second.serverId;
|
||||
detail.serverName = "Server???";
|
||||
detail.numPlayers = git->second.numPlayers;
|
||||
|
||||
if ((git->second.state == RS_GAME_INIT_SETUP) ||
|
||||
(git->second.state == RS_GAME_INIT_INVITED))
|
||||
{
|
||||
detail.status = "Invite";
|
||||
if (git->second.state == RS_GAME_INIT_SETUP)
|
||||
detail.status = "Setup";
|
||||
else
|
||||
detail.status = "Invite";
|
||||
|
||||
/* copy from invited List */
|
||||
for(it = git->second.allowedPeers.begin();
|
||||
@ -689,7 +828,10 @@ bool p3GameLauncher::getGameDetail(std::string gameId, RsGameDetail &detail)
|
||||
else if ((git->second.state == RS_GAME_INIT_CONFIRM) ||
|
||||
(git->second.state == RS_GAME_INIT_READY))
|
||||
{
|
||||
detail.status = "Confirm";
|
||||
if (git->second.state == RS_GAME_INIT_CONFIRM)
|
||||
detail.status = "Confirm";
|
||||
else
|
||||
detail.status = "Ready";
|
||||
|
||||
/* copy from invited List */
|
||||
for(it = git->second.allowedPeers.begin();
|
||||
@ -756,6 +898,11 @@ bool p3GameLauncher::getGameDetail(std::string gameId, RsGameDetail &detail)
|
||||
|
||||
int p3GameLauncher::checkIncoming()
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::checkIncoming()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
/* check for incoming items */
|
||||
|
||||
RsGameItem *gi = NULL;
|
||||
@ -771,6 +918,11 @@ int p3GameLauncher::checkIncoming()
|
||||
|
||||
int p3GameLauncher::handleIncoming(RsGameItem *gi)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::handleIncoming()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
/* check that its a valid packet...
|
||||
* and that there is a gameStatus.
|
||||
*/
|
||||
@ -778,6 +930,10 @@ int p3GameLauncher::handleIncoming(RsGameItem *gi)
|
||||
/* Always check the Properties */
|
||||
if (!checkGameProperties(gi->serviceId, gi->numPlayers))
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::handleIncoming()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
sendRejectMsg(gi);
|
||||
return 0;
|
||||
}
|
||||
@ -796,6 +952,10 @@ int p3GameLauncher::handleIncoming(RsGameItem *gi)
|
||||
/* we are the client -> start it up! */
|
||||
return handleClientStart(gi);
|
||||
}
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::handleIncoming()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
sendRejectMsg(gi);
|
||||
return 0;
|
||||
}
|
||||
@ -809,10 +969,14 @@ int p3GameLauncher::handleIncoming(RsGameItem *gi)
|
||||
|
||||
if (it->second.areServer)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::handleIncoming() AreServer for Game";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
/***** SERVER HANDLING ****/
|
||||
switch(it->second.state)
|
||||
{
|
||||
case RS_GAME_INIT_SETUP:
|
||||
case RS_GAME_INIT_CONFIRM:
|
||||
/* only accept INTERESTED | REJECT */
|
||||
if ((gi->msg == RS_GAME_MSG_INTERESTED) ||
|
||||
(gi->msg == RS_GAME_MSG_REJECT))
|
||||
@ -822,6 +986,11 @@ int p3GameLauncher::handleIncoming(RsGameItem *gi)
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::handleIncoming()";
|
||||
std::cerr << " INIT_CONFIRM & msg != INT | REJ - reject";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
sendRejectMsg(gi);
|
||||
return 0;
|
||||
}
|
||||
@ -836,14 +1005,25 @@ int p3GameLauncher::handleIncoming(RsGameItem *gi)
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::handleIncoming()";
|
||||
std::cerr << " INIT_ACTIVE & msg != PAU | QUIT - reject ";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
sendRejectMsg(gi);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case RS_GAME_INIT_SETUP: /* invalid state */
|
||||
case RS_GAME_INIT_INVITED: /* invalid state */
|
||||
case RS_GAME_INIT_READY: /* invalid state */
|
||||
default:
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::handleIncoming()";
|
||||
std::cerr << " INIT_SETUP | INIT_INVITED | INIT_READY | default - reject ";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
sendRejectMsg(gi);
|
||||
return 0;
|
||||
break;
|
||||
@ -851,6 +1031,10 @@ int p3GameLauncher::handleIncoming(RsGameItem *gi)
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::handleIncoming() AreClient for Game";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
/***** CLIENT HANDLING ****/
|
||||
switch(it->second.state)
|
||||
{
|
||||
@ -863,6 +1047,11 @@ int p3GameLauncher::handleIncoming(RsGameItem *gi)
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::handleIncoming()";
|
||||
std::cerr << " INIT_INVITED & msg != REJ - reject ";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
sendRejectMsg(gi);
|
||||
return 0;
|
||||
}
|
||||
@ -879,6 +1068,11 @@ int p3GameLauncher::handleIncoming(RsGameItem *gi)
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::handleIncoming()";
|
||||
std::cerr << " INIT_READY & msg != CFM, REJ, PLY - reject ";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
sendRejectMsg(gi);
|
||||
return 0;
|
||||
}
|
||||
@ -893,6 +1087,11 @@ int p3GameLauncher::handleIncoming(RsGameItem *gi)
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::handleIncoming()";
|
||||
std::cerr << " INIT_ACTIVE & msg != PAU, QUIT - reject ";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
sendRejectMsg(gi);
|
||||
return 0;
|
||||
}
|
||||
@ -901,12 +1100,22 @@ int p3GameLauncher::handleIncoming(RsGameItem *gi)
|
||||
|
||||
case RS_GAME_INIT_SETUP: /* invalid state */
|
||||
default:
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::handleIncoming()";
|
||||
std::cerr << " INIT_SETUP - invalid state - reject ";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
sendRejectMsg(gi);
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::handleIncoming() Never Get Here - reject";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
/* should never get here */
|
||||
sendRejectMsg(gi);
|
||||
return 0;
|
||||
@ -934,6 +1143,11 @@ int p3GameLauncher::handleIncoming(RsGameItem *gi)
|
||||
/* START msg */
|
||||
int p3GameLauncher::handleClientStart(RsGameItem *gi)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::handleClientStart()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
/* Already checked existance / Properties */
|
||||
|
||||
/* else -> add into the list of games */
|
||||
@ -945,7 +1159,9 @@ int p3GameLauncher::handleClientStart(RsGameItem *gi)
|
||||
gs.serverId = gi->PeerId();
|
||||
gs.state = RS_GAME_INIT_INVITED; /* Client */
|
||||
gs.numPlayers = gi->numPlayers;
|
||||
gs.peerIds = gi->players;
|
||||
gs.allowedPeers = gi->players.ids;
|
||||
//gs.interestedPeers = gi->players.ids;
|
||||
//gs.peerIds = gi->players.ids;
|
||||
|
||||
gamesCurrent[gi->gameId] = gs;
|
||||
|
||||
@ -955,6 +1171,11 @@ int p3GameLauncher::handleClientStart(RsGameItem *gi)
|
||||
/* REJECT msg */
|
||||
int p3GameLauncher::handleClientInvited(RsGameItem *gi)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::handleClientInvited()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
/* cleanup game */
|
||||
cleanupGame(gi->gameId);
|
||||
return 1;
|
||||
@ -963,6 +1184,11 @@ int p3GameLauncher::handleClientInvited(RsGameItem *gi)
|
||||
/* CONFIRM / REJECT / PLAY msg */
|
||||
int p3GameLauncher::handleClientReady(RsGameItem *gi)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::handleClientReady()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
/* get game */
|
||||
std::map<std::string, gameStatus>::iterator it;
|
||||
if (gamesCurrent.end() == (it = gamesCurrent.find(gi->gameId)))
|
||||
@ -979,7 +1205,9 @@ int p3GameLauncher::handleClientReady(RsGameItem *gi)
|
||||
* (other info should be the same)
|
||||
*/
|
||||
it->second.numPlayers = gi->numPlayers;
|
||||
it->second.peerIds = gi->players;
|
||||
// Which one?
|
||||
it->second.interestedPeers = gi->players.ids;
|
||||
//it->second.peerIds = gi->players.ids;
|
||||
|
||||
return 1;
|
||||
break;
|
||||
@ -1002,6 +1230,11 @@ int p3GameLauncher::handleClientReady(RsGameItem *gi)
|
||||
/* PAUSE / QUIT msg */
|
||||
int p3GameLauncher::handleClientActive(RsGameItem *gi)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::handleClientActive()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
return 1;
|
||||
@ -1011,6 +1244,11 @@ int p3GameLauncher::handleClientActive(RsGameItem *gi)
|
||||
/* INTERESTED / REJECT msg */
|
||||
int p3GameLauncher::handleServerSetup(RsGameItem *gi)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::handleServerSetup()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
/* check if there is an existing game? */
|
||||
std::map<std::string, gameStatus>::iterator it;
|
||||
if (gamesCurrent.end() == (it = gamesCurrent.find(gi->gameId)))
|
||||
@ -1043,20 +1281,47 @@ int p3GameLauncher::handleServerSetup(RsGameItem *gi)
|
||||
*/
|
||||
int p3GameLauncher::handleServerActive(RsGameItem *gi)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::handleServerActive()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int p3GameLauncher::sendRejectMsg(RsGameItem *gi)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::sendRejectMsg()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
/* all should be okay ... except msg */
|
||||
gi->msg = RS_GAME_MSG_REJECT;
|
||||
sendItem(gi);
|
||||
|
||||
RsGameItem *response = new RsGameItem();
|
||||
response->serviceId = gi->serviceId;
|
||||
response->numPlayers = gi->numPlayers;
|
||||
response->msg = RS_GAME_MSG_REJECT;
|
||||
response->gameId = gi->gameId;
|
||||
response->gameComment = gi->gameComment;
|
||||
response->players.ids = gi->players.ids;
|
||||
|
||||
sendItem(response);
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool p3GameLauncher::checkGameProperties(uint16_t serviceId, uint16_t players)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::checkGameProperties()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
#ifdef TEST_NO_GAMES
|
||||
return true;
|
||||
#endif
|
||||
|
||||
std::map<uint16_t, p3GameService *>::iterator it;
|
||||
if (gameList.end() == (it = gameList.find(serviceId)))
|
||||
{
|
||||
|
@ -56,7 +56,7 @@ class gameStatus
|
||||
|
||||
uint32_t serviceId;
|
||||
std::string gameId;
|
||||
std::string gameName;
|
||||
std::wstring gameName;
|
||||
|
||||
bool areServer; /* are we the server? */
|
||||
std::string serverId; /* if not, who is? */
|
||||
@ -80,7 +80,7 @@ class p3GameLauncher: public p3Service, public RsGameLauncher
|
||||
|
||||
/***** EXTERNAL RsGameLauncher Interface *******/
|
||||
/* server commands */
|
||||
virtual std::string createGame(uint32_t gameType, std::string name);
|
||||
virtual std::string createGame(uint32_t gameType, std::wstring name);
|
||||
virtual bool deleteGame(std::string gameId);
|
||||
virtual bool inviteGame(std::string gameId);
|
||||
virtual bool playGame(std::string gameId);
|
||||
@ -103,7 +103,7 @@ virtual bool getGameDetail(std::string gameId, RsGameDetail &detail);
|
||||
|
||||
/* support functions */
|
||||
private:
|
||||
std::string newGame(uint16_t srvId, std::string name);
|
||||
std::string newGame(uint16_t srvId, std::wstring name);
|
||||
bool confirmGame(std::string gameId);
|
||||
bool quitGame(std::string gameId);
|
||||
bool inviteResponse(std::string gameId, bool interested);
|
||||
|
@ -142,7 +142,7 @@ void GamesDialog::updateGameList()
|
||||
std::string serverName = rsPeers->getPeerName(it->serverId);
|
||||
item -> setText(GAME_LIST_TYPE, QString::fromStdString(it->gameType));
|
||||
item -> setText(GAME_LIST_SERVER, QString::fromStdString(serverName));
|
||||
item -> setText(GAME_LIST_NAME, QString::fromStdString(it->gameName));
|
||||
item -> setText(GAME_LIST_NAME, QString::fromStdWString(it->gameName));
|
||||
item -> setText(GAME_LIST_STATUS, QString::fromStdString(it->status));
|
||||
item -> setText(GAME_LIST_ID, QString::fromStdString(it->gameId));
|
||||
|
||||
@ -218,11 +218,13 @@ void GamesDialog::updateGameDetails()
|
||||
for(it = detail.gamers.begin(); it != detail.gamers.end(); it++)
|
||||
{
|
||||
bool showPeer = false;
|
||||
if (detail.status == "Invite")
|
||||
if ((detail.status == "Setup") ||
|
||||
(detail.status == "Invite"))
|
||||
{
|
||||
showPeer = true;
|
||||
}
|
||||
else if (detail.status == "Confirm")
|
||||
else if ((detail.status == "Confirm") ||
|
||||
(detail.status == "Ready"))
|
||||
{
|
||||
if ((it->second).invite == true)
|
||||
showPeer = true;
|
||||
@ -273,7 +275,7 @@ void GamesDialog::updateGameDetails()
|
||||
items.append(item);
|
||||
}
|
||||
}
|
||||
if (detail.status == "Invite")
|
||||
if (detail.status == "Setup")
|
||||
{
|
||||
std::list<std::string> friends;
|
||||
std::list<std::string>::iterator fit;
|
||||
@ -354,7 +356,7 @@ void GamesDialog::gamePeersPopupMenu( QPoint point )
|
||||
return;
|
||||
}
|
||||
|
||||
if (mCurrentGameStatus == "Invite")
|
||||
if (mCurrentGameStatus == "Setup")
|
||||
{
|
||||
/* invite */
|
||||
/* uninvite */
|
||||
@ -369,31 +371,73 @@ void GamesDialog::gamePeersPopupMenu( QPoint point )
|
||||
contextMnu.addAction(uninviteAct);
|
||||
contextMnu.exec( mevent->globalPos() );
|
||||
}
|
||||
else if (mCurrentGameStatus == "Invite")
|
||||
{
|
||||
/* invite */
|
||||
/* uninvite */
|
||||
|
||||
QAction *inviteAct = new QAction(QIcon(IMAGE_EXPIORTFRIEND), tr( "Interested in Playing" ), this );
|
||||
connect( inviteAct , SIGNAL( triggered() ), this, SLOT( interested() ) );
|
||||
QAction *uninviteAct = new QAction(QIcon(IMAGE_EXPIORTFRIEND), tr( "Not Interested in Game" ), this );
|
||||
connect( uninviteAct , SIGNAL( triggered() ), this, SLOT( uninterested() ) );
|
||||
|
||||
contextMnu.clear();
|
||||
contextMnu.addAction(inviteAct);
|
||||
contextMnu.addAction(uninviteAct);
|
||||
contextMnu.exec( mevent->globalPos() );
|
||||
}
|
||||
else if (mCurrentGameStatus == "Invite")
|
||||
{
|
||||
/* invite */
|
||||
/* uninvite */
|
||||
|
||||
QAction *interestedAct = new QAction(QIcon(IMAGE_EXPIORTFRIEND), tr( "Interested in Playing" ), this );
|
||||
connect( interestedAct , SIGNAL( triggered() ), this, SLOT( interested() ) );
|
||||
QAction *uninterestedAct = new QAction(QIcon(IMAGE_EXPIORTFRIEND), tr( "Not Interested" ), this );
|
||||
connect( uninterestedAct , SIGNAL( triggered() ), this, SLOT( uninterested() ) );
|
||||
|
||||
contextMnu.clear();
|
||||
contextMnu.addAction(interestedAct);
|
||||
contextMnu.addAction(uninterestedAct);
|
||||
contextMnu.exec( mevent->globalPos() );
|
||||
}
|
||||
else if (mCurrentGameStatus == "Confirm")
|
||||
{
|
||||
/* invite */
|
||||
/* uninvite */
|
||||
|
||||
QAction *inviteAct = new QAction(QIcon(IMAGE_EXPIORTFRIEND), tr( "Add to Play List" ), this );
|
||||
QAction *inviteAct = new QAction(QIcon(IMAGE_EXPIORTFRIEND), tr( "Confirm Peer in Game" ), this );
|
||||
connect( inviteAct , SIGNAL( triggered() ), this, SLOT( confirmPeer() ) );
|
||||
QAction *uninviteAct = new QAction(QIcon(IMAGE_EXPIORTFRIEND), tr( "Remove from Play List" ), this );
|
||||
QAction *uninviteAct = new QAction(QIcon(IMAGE_EXPIORTFRIEND), tr( "Remove Peer from Game" ), this );
|
||||
connect( uninviteAct , SIGNAL( triggered() ), this, SLOT( unconfirmPeer() ) );
|
||||
|
||||
contextMnu.clear();
|
||||
contextMnu.addAction(inviteAct);
|
||||
contextMnu.addAction(uninviteAct);
|
||||
contextMnu.exec( mevent->globalPos() );
|
||||
}
|
||||
else if (mCurrentGameStatus == "Ready")
|
||||
{
|
||||
/* invite */
|
||||
/* uninvite */
|
||||
|
||||
QAction *interestedAct = new QAction(QIcon(IMAGE_EXPIORTFRIEND), tr( "Interested in Game" ), this );
|
||||
connect( interestedAct , SIGNAL( triggered() ), this, SLOT( interested() ) );
|
||||
QAction *uninterestedAct = new QAction(QIcon(IMAGE_EXPIORTFRIEND), tr( "Not Interested" ), this );
|
||||
connect( uninterestedAct , SIGNAL( triggered() ), this, SLOT( uninterested() ) );
|
||||
|
||||
contextMnu.clear();
|
||||
contextMnu.addAction(inviteAct);
|
||||
contextMnu.addAction(uninviteAct);
|
||||
contextMnu.addSeparator();
|
||||
contextMnu.addAction(interestedAct);
|
||||
contextMnu.addAction(uninterestedAct);
|
||||
contextMnu.exec( mevent->globalPos() );
|
||||
}
|
||||
else
|
||||
else /* PLAYING */
|
||||
{
|
||||
/* no menu for playing */
|
||||
QAction *quitAct = new QAction(QIcon(IMAGE_EXPIORTFRIEND), tr( "Quit Game" ), this );
|
||||
contextMnu.clear();
|
||||
contextMnu.addAction(quitAct);
|
||||
contextMnu.exec( mevent->globalPos() );
|
||||
}
|
||||
|
||||
return;
|
||||
@ -404,7 +448,7 @@ void GamesDialog::gamePeersPopupMenu( QPoint point )
|
||||
void GamesDialog::createGame()
|
||||
{
|
||||
/* extract the Game Type and number of players from GUI */
|
||||
std::string gameName = ui.gameNameEdit->text().toStdString();
|
||||
std::wstring gameName = ui.gameNameEdit->text().toStdWString();
|
||||
uint32_t gameType = ui.gameComboBox->currentIndex();
|
||||
bool addAll = ui.checkInviteAll->isChecked();
|
||||
std::list<std::string> playerList;
|
||||
@ -424,7 +468,8 @@ void GamesDialog::createGame()
|
||||
}
|
||||
|
||||
/* call to the GameControl */
|
||||
std::cerr << "GamesDialog::createGame() Game: " << gameType << " name: " << gameName;
|
||||
std::string tmpName(gameName.begin(), gameName.end());
|
||||
std::cerr << "GamesDialog::createGame() Game: " << gameType << " name: " << tmpName;
|
||||
std::cerr << std::endl;
|
||||
|
||||
updateGameList();
|
||||
|
@ -48,7 +48,7 @@ class RsGameInfo
|
||||
std::string serverId;
|
||||
|
||||
std::string gameType;
|
||||
std::string gameName;
|
||||
std::wstring gameName;
|
||||
std::string serverName;
|
||||
std::string status;
|
||||
uint16_t numPlayers;
|
||||
@ -69,7 +69,7 @@ class RsGameDetail
|
||||
public:
|
||||
std::string gameId;
|
||||
std::string gameType;
|
||||
std::string gameName;
|
||||
std::wstring gameName;
|
||||
|
||||
bool areServer; /* are we the server? */
|
||||
std::string serverId; /* if not, who is? */
|
||||
@ -87,7 +87,7 @@ class RsGameLauncher
|
||||
public:
|
||||
|
||||
/* server commands */
|
||||
virtual std::string createGame(uint32_t gameType, std::string name) = 0;
|
||||
virtual std::string createGame(uint32_t gameType, std::wstring name) = 0;
|
||||
virtual bool deleteGame(std::string gameId) = 0;
|
||||
virtual bool inviteGame(std::string gameId) = 0;
|
||||
virtual bool playGame(std::string gameId) = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user