mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-22 22:21:09 -04:00
Removing old services, serialisers and other references for:
- forums - channels - tunnel - blog - gamelauncher. - distrib. Note this majorly breaks the GUI, for the moment. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.6-initdev@6683 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
212b4c44c9
commit
a6cf738371
47 changed files with 15 additions and 14890 deletions
|
@ -1,406 +0,0 @@
|
|||
/*
|
||||
* libretroshare/src/services: p3Blogs.cc
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 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 "services/p3blogs.h"
|
||||
#include "util/rsdir.h"
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const BlogInfo &info)
|
||||
{
|
||||
std::string name(info.blogName.begin(), info.blogName.end());
|
||||
std::string desc(info.blogDesc.begin(), info.blogDesc.end());
|
||||
|
||||
out << "BlogInfo:";
|
||||
out << std::endl;
|
||||
out << "BlogId: " << info.blogId << std::endl;
|
||||
out << "BlogName: " << name << std::endl;
|
||||
out << "BlogDesc: " << desc << std::endl;
|
||||
out << "BlogFlags: " << info.blogFlags << std::endl;
|
||||
out << "Pop: " << info.pop << std::endl;
|
||||
out << "LastPost: " << info.lastPost << std::endl;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const BlogMsgSummary &info)
|
||||
{
|
||||
out << "BlogMsgSummary:";
|
||||
out << std::endl;
|
||||
out << "BlogId: " << info.blogId << std::endl;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const BlogMsgInfo &info)
|
||||
{
|
||||
out << "BlogMsgInfo:";
|
||||
out << std::endl;
|
||||
out << "BlogId: " << info.blogId << std::endl;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
RsBlogs *rsBlogs = NULL;
|
||||
|
||||
|
||||
/* Blogs will be initially stored for 1 year
|
||||
* remember 2^16 = 64K max units in store period.
|
||||
* PUBPERIOD * 2^16 = max STORE PERIOD */
|
||||
#define BLOG_STOREPERIOD (90*24*3600) /* 30 * 24 * 3600 - secs in a year */
|
||||
#define BLOG_PUBPERIOD 600 /* 10 minutes ... (max = 455 days) */
|
||||
|
||||
p3Blogs::p3Blogs(uint16_t type, CacheStrapper *cs,
|
||||
CacheTransfer *cft,
|
||||
std::string srcdir, std::string storedir)
|
||||
:p3GroupDistrib(type, cs, cft, srcdir, storedir, "",
|
||||
CONFIG_TYPE_QBLOG, BLOG_STOREPERIOD, BLOG_PUBPERIOD)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
p3Blogs::~p3Blogs()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/****************************************/
|
||||
|
||||
bool p3Blogs::blogsChanged(std::list<std::string> &blogIds)
|
||||
{
|
||||
return groupsChanged(blogIds);
|
||||
}
|
||||
|
||||
|
||||
bool p3Blogs::getBlogInfo(std::string cId, BlogInfo &ci)
|
||||
{
|
||||
RsStackMutex stack(distribMtx); /***** STACK LOCKED MUTEX *****/
|
||||
|
||||
/* extract details */
|
||||
GroupInfo *gi = locked_getGroupInfo(cId);
|
||||
|
||||
if (!gi)
|
||||
return false;
|
||||
|
||||
ci.blogId = gi->grpId;
|
||||
ci.blogName = gi->grpName;
|
||||
ci.blogDesc = gi->grpDesc;
|
||||
|
||||
ci.blogFlags = gi->flags;
|
||||
|
||||
ci.pop = gi->sources.size();
|
||||
ci.lastPost = gi->lastPost;
|
||||
|
||||
ci.pngChanImage = gi->grpIcon.pngImageData;
|
||||
|
||||
if(ci.pngChanImage != NULL)
|
||||
ci.pngImageLen = gi->grpIcon.imageSize;
|
||||
else
|
||||
ci.pngImageLen = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool p3Blogs::getBlogList(std::list<BlogInfo> &blogList)
|
||||
{
|
||||
std::list<std::string> grpIds;
|
||||
std::list<std::string>::iterator it;
|
||||
|
||||
getAllGroupList(grpIds);
|
||||
|
||||
for(it = grpIds.begin(); it != grpIds.end(); it++)
|
||||
{
|
||||
BlogInfo ci;
|
||||
if (getBlogInfo(*it, ci))
|
||||
{
|
||||
blogList.push_back(ci);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool p3Blogs::getBlogMsgList(std::string cId, std::list<BlogMsgSummary> &msgs)
|
||||
{
|
||||
std::list<std::string> msgIds;
|
||||
std::list<std::string>::iterator it;
|
||||
|
||||
getAllMsgList(cId, msgIds);
|
||||
|
||||
RsStackMutex stack(distribMtx); /***** STACK LOCKED MUTEX *****/
|
||||
for(it = msgIds.begin(); it != msgIds.end(); it++)
|
||||
{
|
||||
/* get details */
|
||||
RsDistribMsg *msg = locked_getGroupMsg(cId, *it);
|
||||
RsBlogMsg *cmsg = dynamic_cast<RsBlogMsg *>(msg);
|
||||
if (!cmsg)
|
||||
continue;
|
||||
|
||||
BlogMsgSummary tis;
|
||||
|
||||
tis.blogId = msg->grpId;
|
||||
tis.msgId = msg->msgId;
|
||||
tis.ts = msg->timestamp;
|
||||
|
||||
/* the rest must be gotten from the derived Msg */
|
||||
|
||||
tis.subject = cmsg->subject;
|
||||
tis.msg = cmsg->message;
|
||||
|
||||
msgs.push_back(tis);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3Blogs::getBlogMessage(std::string fId, std::string mId, BlogMsgInfo &info)
|
||||
{
|
||||
std::list<std::string> msgIds;
|
||||
std::list<std::string>::iterator it;
|
||||
|
||||
RsStackMutex stack(distribMtx); /***** STACK LOCKED MUTEX *****/
|
||||
|
||||
RsDistribMsg *msg = locked_getGroupMsg(fId, mId);
|
||||
RsBlogMsg *cmsg = dynamic_cast<RsBlogMsg *>(msg);
|
||||
if (!cmsg)
|
||||
return false;
|
||||
|
||||
|
||||
info.blogId = msg->grpId;
|
||||
info.msgId = msg->msgId;
|
||||
info.ts = msg->timestamp;
|
||||
|
||||
/* the rest must be gotten from the derived Msg */
|
||||
|
||||
info.subject = cmsg->subject;
|
||||
info.msg = cmsg->message;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3Blogs::BlogMessageSend(BlogMsgInfo &info)
|
||||
{
|
||||
|
||||
RsBlogMsg *cmsg = new RsBlogMsg();
|
||||
cmsg->grpId = info.blogId;
|
||||
|
||||
cmsg->subject = info.subject;
|
||||
cmsg->message = info.msg;
|
||||
cmsg->timestamp = time(NULL);
|
||||
|
||||
std::string msgId = publishMsg(cmsg, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3Blogs::BlogMessageReply(BlogMsgInfo& reply){
|
||||
|
||||
// ensure it has a value
|
||||
if(isReply(reply)){
|
||||
std::cerr << "p3Blogs::BlogMessageReply()" << " This is not a reply " << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// also check that msgId exists for group
|
||||
|
||||
return BlogMessageSend(reply);
|
||||
}
|
||||
|
||||
bool p3Blogs::isReply(BlogMsgInfo& info){
|
||||
|
||||
// if replies list is empty then this is not a reply to a blog
|
||||
return !info.msgIdReply.empty();
|
||||
}
|
||||
|
||||
std::string p3Blogs::createBlog(std::wstring blogName, std::wstring blogDesc, uint32_t blogFlags,
|
||||
unsigned char* pngImageData, uint32_t imageSize)
|
||||
{
|
||||
|
||||
std::string id = createGroup(blogName, blogDesc, blogFlags, pngImageData, imageSize);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
RsSerialType *p3Blogs::createSerialiser()
|
||||
{
|
||||
return new RsBlogSerialiser();
|
||||
}
|
||||
|
||||
bool p3Blogs::locked_checkDistribMsg(RsDistribMsg *msg)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
RsDistribGrp *p3Blogs::locked_createPublicDistribGrp(GroupInfo &info)
|
||||
{
|
||||
RsDistribGrp *grp = NULL; //new RsChannelGrp();
|
||||
|
||||
return grp;
|
||||
}
|
||||
|
||||
RsDistribGrp *p3Blogs::locked_createPrivateDistribGrp(GroupInfo &info)
|
||||
{
|
||||
RsDistribGrp *grp = NULL; //new RsChannelGrp();
|
||||
|
||||
return grp;
|
||||
}
|
||||
|
||||
|
||||
bool p3Blogs::blogSubscribe(std::string cId, bool subscribe)
|
||||
{
|
||||
std::cerr << "p3Blogs::channelSubscribe() ";
|
||||
std::cerr << cId;
|
||||
std::cerr << std::endl;
|
||||
|
||||
return subscribeToGroup(cId, subscribe);
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************************/
|
||||
/****************** Event Feedback (Overloaded form p3distrib) *************************/
|
||||
/***************************************************************************************/
|
||||
/* only download in the first week of channel
|
||||
* older stuff can be manually downloaded.
|
||||
*/
|
||||
|
||||
const uint32_t DOWNLOAD_PERIOD = 7 * 24 * 3600;
|
||||
|
||||
/* This is called when we receive a msg, and also recalled
|
||||
*
|
||||
*/
|
||||
|
||||
bool p3Blogs::locked_eventDuplicateMsg(GroupInfo *grp, RsDistribMsg *msg, const std::string& id, bool historical)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
#include "pqi/pqinotify.h"
|
||||
|
||||
bool p3Blogs::locked_eventNewMsg(GroupInfo *grp, RsDistribMsg *msg, const std::string& id, bool historical)
|
||||
{
|
||||
std::string grpId = msg->grpId;
|
||||
std::string msgId = msg->msgId;
|
||||
std::string nullId;
|
||||
|
||||
std::cerr << "p3Blogs::locked_eventNewMsg() ";
|
||||
std::cerr << " grpId: " << grpId;
|
||||
std::cerr << " msgId: " << msgId;
|
||||
std::cerr << " peerId: " << id;
|
||||
std::cerr << std::endl;
|
||||
|
||||
if (!historical)
|
||||
{
|
||||
getPqiNotify()->AddFeedItem(RS_FEED_ITEM_BLOG_MSG, grpId, msgId, nullId);
|
||||
}
|
||||
|
||||
/* request the files
|
||||
* NB: This could result in duplicates.
|
||||
* which must be handled by ft side.
|
||||
*
|
||||
* this is exactly what DuplicateMsg does.
|
||||
* */
|
||||
return locked_eventDuplicateMsg(grp, msg, id, historical);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void p3Blogs::locked_notifyGroupChanged(GroupInfo &grp, uint32_t flags, bool historical)
|
||||
{
|
||||
std::string grpId = grp.grpId;
|
||||
std::string msgId;
|
||||
std::string nullId;
|
||||
|
||||
std::cerr << "p3Blogs::locked_notifyGroupChanged() ";
|
||||
std::cerr << grpId;
|
||||
std::cerr << " flags:" << flags;
|
||||
std::cerr << std::endl;
|
||||
|
||||
switch(flags)
|
||||
{
|
||||
case GRP_NEW_UPDATE:
|
||||
std::cerr << "p3Blogs::locked_notifyGroupChanged() NEW UPDATE";
|
||||
std::cerr << std::endl;
|
||||
if (!historical)
|
||||
{
|
||||
getPqiNotify()->AddFeedItem(RS_FEED_ITEM_BLOG_NEW, grpId, msgId, nullId);
|
||||
}
|
||||
break;
|
||||
case GRP_UPDATE:
|
||||
std::cerr << "p3Blogs::locked_notifyGroupChanged() UPDATE";
|
||||
std::cerr << std::endl;
|
||||
if (!historical)
|
||||
{
|
||||
getPqiNotify()->AddFeedItem(RS_FEED_ITEM_BLOG_UPDATE, grpId, msgId, nullId);
|
||||
}
|
||||
break;
|
||||
case GRP_LOAD_KEY:
|
||||
std::cerr << "p3Blogs::locked_notifyGroupChanged() LOAD_KEY";
|
||||
std::cerr << std::endl;
|
||||
break;
|
||||
case GRP_NEW_MSG:
|
||||
std::cerr << "p3Blogs::locked_notifyGroupChanged() NEW MSG";
|
||||
std::cerr << std::endl;
|
||||
break;
|
||||
case GRP_SUBSCRIBED:
|
||||
std::cerr << "p3Blogs::locked_notifyGroupChanged() SUBSCRIBED";
|
||||
std::cerr << std::endl;
|
||||
break;
|
||||
case GRP_UNSUBSCRIBED:
|
||||
std::cerr << "p3Blogs::locked_notifyGroupChanged() UNSUBSCRIBED";
|
||||
std::cerr << std::endl;
|
||||
|
||||
/* won't stop downloads... */
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
std::cerr << "p3Blogs::locked_notifyGroupChanged() Unknown DEFAULT";
|
||||
std::cerr << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
return p3GroupDistrib::locked_notifyGroupChanged(grp, flags);
|
||||
}
|
||||
|
||||
//TODO: if you want to enable config saving and loading implement this
|
||||
bool p3Blogs::childLoadList(std::list<RsItem* >& configSaves)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//TODO:
|
||||
std::list<RsItem *> p3Blogs::childSaveList()
|
||||
{
|
||||
std::list<RsItem *> saveL;
|
||||
|
||||
return saveL;
|
||||
}
|
||||
|
||||
/****************************************/
|
||||
|
||||
|
||||
|
|
@ -1,137 +0,0 @@
|
|||
#ifndef RS_P3_BLOGS_INTERFACE_H
|
||||
#define RS_P3_BLOGS_INTERFACE_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/services: p3blogs.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 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 "retroshare/rsblogs.h"
|
||||
#include "retroshare/rsfiles.h"
|
||||
#include "distrib/p3distrib.h"
|
||||
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rsblogitems.h"
|
||||
|
||||
/*!
|
||||
* implements the blog interface using the distrib service. it allows users to send blogs using
|
||||
* retroshare's cache service. its use
|
||||
*/
|
||||
class p3Blogs: public p3GroupDistrib, public RsBlogs
|
||||
{
|
||||
public:
|
||||
|
||||
/*!
|
||||
* @param CacheStrapper needed to push blogs onto the cache service
|
||||
* @param CacheTransfer maintains distrib servi
|
||||
* @param srcdir
|
||||
* @param storedir
|
||||
*/
|
||||
p3Blogs(uint16_t type, CacheStrapper *cs, CacheTransfer *cft,
|
||||
std::string srcdir, std::string storedir);
|
||||
virtual ~p3Blogs();
|
||||
|
||||
/****************************************/
|
||||
/********* rsBlogs Interface ***********/
|
||||
|
||||
|
||||
/**
|
||||
* check if any of the blogs has been changed
|
||||
* @param blogIds list blogs by ids to be checked
|
||||
* @return false if changed and vice versa
|
||||
*/
|
||||
virtual bool blogsChanged(std::list<std::string> &blogIds);
|
||||
|
||||
/**
|
||||
* creates a new blog
|
||||
*/
|
||||
virtual std::string createBlog(std::wstring blogName, std::wstring blogDesc, uint32_t blogFlags,
|
||||
unsigned char* pngImageData, uint32_t imageSize);
|
||||
|
||||
/**
|
||||
* @param cId the id for the blog
|
||||
* @param BloogInfo blog information is stored here
|
||||
*/
|
||||
virtual bool getBlogInfo(std::string cId, BlogInfo &ci);
|
||||
|
||||
/**
|
||||
* get list of blogs from the group peer belongs to
|
||||
*/
|
||||
virtual bool getBlogList(std::list<BlogInfo> &blogList);
|
||||
|
||||
/**
|
||||
* Returns a list of all the messages sent
|
||||
* @param cId group id
|
||||
* @param msgs
|
||||
*/
|
||||
virtual bool getBlogMsgList(std::string cId, std::list<BlogMsgSummary> &msgs);
|
||||
virtual bool getBlogMessage(std::string cId, std::string mId, BlogMsgInfo &msg);
|
||||
|
||||
virtual bool BlogMessageSend(BlogMsgInfo &info);
|
||||
|
||||
/**
|
||||
* subscribes or unsubscribes peer to a blog message
|
||||
* @param cId the id of the blog message peer wants to subscribe
|
||||
* @param subscribe set to true to subscribe, false otherwise
|
||||
*/
|
||||
virtual bool blogSubscribe(std::string cId, bool subscribe);
|
||||
|
||||
|
||||
/**
|
||||
* send a reply to a blog msg, ensure msgIdReply has valid id to a message
|
||||
*/
|
||||
virtual bool BlogMessageReply(BlogMsgInfo &info);
|
||||
|
||||
/**
|
||||
* check if a particular blog is a reply
|
||||
* @return false if not a reply, true otherwise
|
||||
*/
|
||||
virtual bool isReply(BlogMsgInfo& info);
|
||||
|
||||
|
||||
/***************************************************************************************/
|
||||
/****************** Event Feedback (Overloaded form p3distrib) *************************/
|
||||
/***************************************************************************************/
|
||||
|
||||
protected:
|
||||
virtual void locked_notifyGroupChanged(GroupInfo &info, uint32_t flags, bool historical);
|
||||
virtual bool locked_eventNewMsg(GroupInfo *, RsDistribMsg *, const std::string&, bool historical);
|
||||
virtual bool locked_eventDuplicateMsg(GroupInfo *, RsDistribMsg *, const std::string&, bool historical);
|
||||
|
||||
|
||||
/****************************************/
|
||||
/********* Overloaded Functions *********/
|
||||
|
||||
virtual RsSerialType *createSerialiser();
|
||||
|
||||
virtual bool locked_checkDistribMsg(RsDistribMsg *msg);
|
||||
virtual RsDistribGrp *locked_createPublicDistribGrp(GroupInfo &info);
|
||||
virtual RsDistribGrp *locked_createPrivateDistribGrp(GroupInfo &info);
|
||||
virtual bool childLoadList(std::list<RsItem* >& configSaves);
|
||||
virtual std::list<RsItem *> childSaveList();
|
||||
/****************************************/
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load diff
|
@ -1,130 +0,0 @@
|
|||
#ifndef RS_P3_CHANNELS_INTERFACE_H
|
||||
#define RS_P3_CHANNELS_INTERFACE_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/services: p3channels.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 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 "retroshare/rschannels.h"
|
||||
#include "retroshare/rsfiles.h"
|
||||
#include "distrib/p3distrib.h"
|
||||
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rschannelitems.h"
|
||||
|
||||
#define RS_CHAN_STATUS_MASK 0x000f
|
||||
#define RS_CHAN_STATUS_AUTO_DL 0x0002
|
||||
|
||||
typedef std::map<std::string, uint32_t> statMap;
|
||||
typedef std::map<std::string, statMap> chanStatMap;
|
||||
|
||||
//! Channels is a distributed 'feed' service
|
||||
/*!
|
||||
* Implementations of rschannels interface
|
||||
* @see RsChannels for definition of implemented interface
|
||||
*/
|
||||
class p3Channels: public p3GroupDistrib, public RsChannels
|
||||
{
|
||||
public:
|
||||
|
||||
p3Channels(uint16_t type, CacheStrapper *cs, CacheTransfer *cft, RsFiles *files,
|
||||
std::string srcdir, std::string storedir, std::string channelsdir);
|
||||
virtual ~p3Channels();
|
||||
|
||||
/*!
|
||||
* cleans up dowloaded files older than one month,
|
||||
* should be called during shutdown of rs
|
||||
*/
|
||||
void cleanUpOldFiles();
|
||||
|
||||
/****************************************/
|
||||
/********* rsChannels Interface ***********/
|
||||
|
||||
virtual bool channelsChanged(std::list<std::string> &chanIds);
|
||||
|
||||
virtual std::string createChannel(std::wstring chanName, std::wstring chanDesc, uint32_t chanFlags,
|
||||
unsigned char* pngImageData, uint32_t size);
|
||||
|
||||
virtual bool getChannelInfo(const std::string &cId, ChannelInfo &ci);
|
||||
virtual bool getChannelList(std::list<ChannelInfo> &chanList);
|
||||
virtual bool getChannelMsgList(const std::string &cId, std::list<ChannelMsgSummary> &msgs);
|
||||
virtual bool getChannelMessage(const std::string &cId, const std::string &mId, ChannelMsgInfo &msg);
|
||||
|
||||
virtual bool ChannelMessageSend(ChannelMsgInfo &info);
|
||||
virtual bool setMessageStatus(const std::string& cId, const std::string& mId, const uint32_t status, const uint32_t statusMask);
|
||||
virtual bool getMessageStatus(const std::string& cId, const std::string& mId, uint32_t& status);
|
||||
|
||||
virtual bool getMessageCount(const std::string &cId, unsigned int &newCount, unsigned int &unreadCount);
|
||||
virtual bool channelSubscribe(const std::string &cId, bool subscribe, bool autoDl);
|
||||
virtual bool channelExtraFileHash(const std::string &path, const std::string &chId, FileInfo& fInfo);
|
||||
virtual bool channelExtraFileRemove(const std::string &hash, const std::string &chId);
|
||||
virtual bool channelRestoreKeys(const std::string &chId);
|
||||
virtual bool channelShareKeys(const std::string &chId, std::list<std::string>& peers);
|
||||
virtual bool channelEditInfo(const std::string &chId, ChannelInfo &ci);
|
||||
virtual void getPubKeysAvailableGrpIds(std::list<std::string>& grpIds);
|
||||
virtual bool channelSetAutoDl(const std::string& chId, bool autoDl);
|
||||
virtual bool channelGetAutoDl(const std::string& chId, bool& autoDl);
|
||||
virtual bool channelSetDestinationDirectory(const std::string& chId,const std::string& dest_dir) ;
|
||||
|
||||
/***************************************************************************************/
|
||||
/****************** Event Feedback (Overloaded form p3distrib) *************************/
|
||||
/***************************************************************************************/
|
||||
|
||||
protected:
|
||||
virtual void locked_notifyGroupChanged(GroupInfo &info, uint32_t flags, bool historical);
|
||||
virtual bool locked_eventNewMsg(GroupInfo *, RsDistribMsg *, const std::string&, bool historical);
|
||||
virtual bool locked_eventDuplicateMsg(GroupInfo *, RsDistribMsg *, const std::string&, bool historical);
|
||||
|
||||
|
||||
/****************************************/
|
||||
/********* Overloaded Functions *********/
|
||||
|
||||
virtual RsSerialType *createSerialiser();
|
||||
|
||||
virtual bool locked_checkDistribMsg(RsDistribMsg *msg);
|
||||
|
||||
virtual bool childLoadList(std::list<RsItem* >& configSaves);
|
||||
virtual std::list<RsItem *> childSaveList();
|
||||
|
||||
|
||||
/****************************************/
|
||||
|
||||
private:
|
||||
|
||||
void processChanReadStatus(RsChannelReadStatus* drs);
|
||||
void addChannelReadStatusEntry(const std::string& cId);
|
||||
void removeChannelReadStatusEntry(const std::string& cId);
|
||||
RsFiles *mRsFiles;
|
||||
std::string mChannelsDir;
|
||||
std::list<RsItem *> saveList;
|
||||
|
||||
std::list<RsChannelReadStatus *> mReadStatus;
|
||||
|
||||
chanStatMap mMsgReadStatus;
|
||||
statMap mChannelStatus;
|
||||
std::map<std::string,std::string> mDestinationDirectories ;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
|
@ -1,818 +0,0 @@
|
|||
/*
|
||||
* libretroshare/src/services: rsforums.cc
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* 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 "services/p3forums.h"
|
||||
#include "pqi/authssl.h"
|
||||
#include "util/rsdir.h"
|
||||
#include "retroshare/rsiface.h"
|
||||
|
||||
uint32_t convertToInternalFlags(uint32_t extFlags);
|
||||
uint32_t convertToExternalFlags(uint32_t intFlags);
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const ForumInfo &info)
|
||||
{
|
||||
std::string name(info.forumName.begin(), info.forumName.end());
|
||||
std::string desc(info.forumDesc.begin(), info.forumDesc.end());
|
||||
|
||||
out << "ForumInfo:";
|
||||
out << std::endl;
|
||||
out << "ForumId: " << info.forumId << std::endl;
|
||||
out << "ForumName: " << name << std::endl;
|
||||
out << "ForumDesc: " << desc << std::endl;
|
||||
out << "ForumFlags: " << info.forumFlags << std::endl;
|
||||
out << "Pop: " << info.pop << std::endl;
|
||||
out << "LastPost: " << info.lastPost << std::endl;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const ThreadInfoSummary &/*info*/)
|
||||
{
|
||||
out << "ThreadInfoSummary:";
|
||||
out << std::endl;
|
||||
//out << "ForumId: " << forumId << std::endl;
|
||||
//out << "ThreadId: " << threadId << std::endl;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const ForumMsgInfo &/*info*/)
|
||||
{
|
||||
out << "ForumMsgInfo:";
|
||||
out << std::endl;
|
||||
//out << "ForumId: " << forumId << std::endl;
|
||||
//out << "ThreadId: " << threadId << std::endl;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
RsForums *rsForums = NULL;
|
||||
|
||||
|
||||
/* Forums will be initially stored for 1 year
|
||||
* remember 2^16 = 64K max units in store period.
|
||||
* PUBPERIOD * 2^16 = max STORE PERIOD */
|
||||
#define FORUM_STOREPERIOD (365*24*3600) /* 365 * 24 * 3600 - secs in a year */
|
||||
#define FORUM_PUBPERIOD 600 /* 10 minutes ... (max = 455 days) */
|
||||
|
||||
p3Forums::p3Forums(uint16_t type, CacheStrapper *cs, CacheTransfer *cft,
|
||||
std::string srcdir, std::string storedir, std::string forumDir)
|
||||
:p3GroupDistrib(type, cs, cft, srcdir, storedir, forumDir,
|
||||
CONFIG_TYPE_FORUMS, FORUM_STOREPERIOD, FORUM_PUBPERIOD),
|
||||
mForumsDir(forumDir)
|
||||
{
|
||||
|
||||
/* create chanDir */
|
||||
if (!RsDirUtil::checkCreateDirectory(mForumsDir)) {
|
||||
std::cerr << "p3Channels() Failed to create forums Directory: " << mForumsDir << std::endl;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
p3Forums::~p3Forums()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/****************************************/
|
||||
|
||||
bool p3Forums::forumsChanged(std::list<std::string> &forumIds)
|
||||
{
|
||||
return groupsChanged(forumIds);
|
||||
}
|
||||
|
||||
bool p3Forums::getForumInfo(const std::string &fId, ForumInfo &fi)
|
||||
{
|
||||
RsStackMutex stack(distribMtx); /***** STACK LOCKED MUTEX *****/
|
||||
|
||||
/* extract details */
|
||||
GroupInfo *gi = locked_getGroupInfo(fId);
|
||||
|
||||
if (!gi)
|
||||
return false;
|
||||
|
||||
fi.forumId = gi->grpId;
|
||||
fi.forumName = gi->grpName;
|
||||
fi.forumDesc = gi->grpDesc;
|
||||
fi.forumFlags = gi->grpFlags;
|
||||
|
||||
fi.subscribeFlags = gi->flags;
|
||||
|
||||
fi.pop = gi->sources.size();
|
||||
fi.lastPost = gi->lastPost;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* allows peers to change information for the forum:
|
||||
* can only change name and descriptions
|
||||
*
|
||||
*/
|
||||
bool p3Forums::setForumInfo(const std::string &fId, ForumInfo &fi)
|
||||
{
|
||||
GroupInfo gi;
|
||||
|
||||
RsStackMutex stack(distribMtx);
|
||||
|
||||
gi.grpName = fi.forumName;
|
||||
gi.grpDesc = fi.forumDesc;
|
||||
|
||||
return locked_editGroup(fId, gi);
|
||||
}
|
||||
|
||||
bool p3Forums::getForumList(std::list<ForumInfo> &forumList)
|
||||
{
|
||||
std::list<std::string> grpIds;
|
||||
std::list<std::string>::iterator it;
|
||||
|
||||
getAllGroupList(grpIds);
|
||||
|
||||
for(it = grpIds.begin(); it != grpIds.end(); it++)
|
||||
{
|
||||
ForumInfo fi;
|
||||
if (getForumInfo(*it, fi))
|
||||
{
|
||||
forumList.push_back(fi);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3Forums::getForumThreadList(const std::string &fId, std::list<ThreadInfoSummary> &msgs)
|
||||
{
|
||||
std::list<std::string> msgIds;
|
||||
std::list<std::string>::iterator it;
|
||||
|
||||
getParentMsgList(fId, "", msgIds);
|
||||
|
||||
std::list<std::string> msgDummyIds;
|
||||
getDummyParentMsgList(fId, "", msgDummyIds);
|
||||
|
||||
RsStackMutex stack(distribMtx); /***** STACK LOCKED MUTEX *****/
|
||||
for(it = msgIds.begin(); it != msgIds.end(); it++)
|
||||
{
|
||||
/* get details */
|
||||
RsDistribMsg *msg = locked_getGroupMsg(fId, *it);
|
||||
RsForumMsg *fmsg = dynamic_cast<RsForumMsg *>(msg);
|
||||
if (!fmsg)
|
||||
continue;
|
||||
|
||||
ThreadInfoSummary tis;
|
||||
|
||||
tis.forumId = msg->grpId;
|
||||
tis.msgId = msg->msgId;
|
||||
tis.parentId = ""; // always NULL (see request)
|
||||
tis.threadId = msg->msgId; // these are the thread heads!
|
||||
|
||||
tis.ts = msg->timestamp;
|
||||
tis.childTS = msg->childTS;
|
||||
|
||||
/* the rest must be gotten from the derived Msg */
|
||||
|
||||
tis.title = fmsg->title;
|
||||
tis.msg = fmsg->msg;
|
||||
|
||||
msgs.push_back(tis);
|
||||
}
|
||||
|
||||
// now add dummy msgs.
|
||||
for(it = msgDummyIds.begin(); it != msgDummyIds.end(); it++)
|
||||
{
|
||||
/* get details */
|
||||
RsDistribDummyMsg *msg = locked_getGroupDummyMsg(fId, *it);
|
||||
ThreadInfoSummary tis;
|
||||
|
||||
tis.forumId = fId;
|
||||
tis.msgId = msg->msgId;
|
||||
tis.parentId = ""; // always NULL (see request)
|
||||
tis.threadId = msg->msgId; // these are the thread heads!
|
||||
|
||||
tis.ts = msg->timestamp;
|
||||
tis.childTS = msg->childTS;
|
||||
|
||||
/* dummy msg */
|
||||
tis.title = L"[ ... Missing Message ... ]";
|
||||
tis.msg = L"Placeholder for missing Message";
|
||||
tis.msgflags |= RS_DISTRIB_MISSING_MSG;
|
||||
|
||||
msgs.push_back(tis);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3Forums::getForumThreadMsgList(const std::string &fId, const std::string &pId, std::list<ThreadInfoSummary> &msgs)
|
||||
{
|
||||
std::list<std::string> msgIds;
|
||||
std::list<std::string>::iterator it;
|
||||
|
||||
getParentMsgList(fId, pId, msgIds);
|
||||
|
||||
std::list<std::string> msgDummyIds;
|
||||
getDummyParentMsgList(fId, pId, msgDummyIds);
|
||||
|
||||
RsStackMutex stack(distribMtx); /***** STACK LOCKED MUTEX *****/
|
||||
for(it = msgIds.begin(); it != msgIds.end(); it++)
|
||||
{
|
||||
/* get details */
|
||||
RsDistribMsg *msg = locked_getGroupMsg(fId, *it);
|
||||
RsForumMsg *fmsg = dynamic_cast<RsForumMsg *>(msg);
|
||||
if (!fmsg)
|
||||
continue;
|
||||
|
||||
ThreadInfoSummary tis;
|
||||
|
||||
tis.forumId = msg->grpId;
|
||||
tis.msgId = msg->msgId;
|
||||
tis.parentId = msg->parentId;
|
||||
tis.threadId = msg->threadId;
|
||||
|
||||
tis.ts = msg->timestamp;
|
||||
tis.childTS = msg->childTS;
|
||||
|
||||
/* the rest must be gotten from the derived Msg */
|
||||
|
||||
tis.title = fmsg->title;
|
||||
tis.msg = fmsg->msg;
|
||||
|
||||
if (fmsg->personalSignature.keyId.empty() == false) {
|
||||
tis.msgflags |= RS_DISTRIB_AUTHEN_REQ;
|
||||
}
|
||||
|
||||
msgs.push_back(tis);
|
||||
}
|
||||
|
||||
// now add dummy msgs.
|
||||
for(it = msgDummyIds.begin(); it != msgDummyIds.end(); it++)
|
||||
{
|
||||
/* get details */
|
||||
RsDistribDummyMsg *msg = locked_getGroupDummyMsg(fId, *it);
|
||||
ThreadInfoSummary tis;
|
||||
|
||||
tis.forumId = fId;
|
||||
tis.msgId = msg->msgId;
|
||||
tis.parentId = msg->parentId;
|
||||
tis.threadId = msg->threadId;
|
||||
|
||||
tis.ts = msg->timestamp;
|
||||
tis.childTS = msg->childTS;
|
||||
|
||||
/* dummy msg */
|
||||
tis.title = L"[ ... Missing Message ... ]";
|
||||
tis.msg = L"Placeholder for missing Message";
|
||||
tis.msgflags |= RS_DISTRIB_MISSING_MSG;
|
||||
|
||||
msgs.push_back(tis);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3Forums::getForumMessage(const std::string &fId, const std::string &mId, ForumMsgInfo &info)
|
||||
{
|
||||
processCacheOptReq(fId);
|
||||
|
||||
RsStackMutex stack(distribMtx); /***** STACK LOCKED MUTEX *****/
|
||||
|
||||
RsDistribMsg *msg = locked_getGroupMsg(fId, mId);
|
||||
RsForumMsg *fmsg = dynamic_cast<RsForumMsg *>(msg);
|
||||
if (!fmsg)
|
||||
{
|
||||
/* try for a dummy msg */
|
||||
RsDistribDummyMsg *dmsg = locked_getGroupDummyMsg(fId, mId);
|
||||
if (!dmsg)
|
||||
return false;
|
||||
|
||||
/* fill in the dummy msg */
|
||||
info.forumId = fId;
|
||||
info.msgId = dmsg->msgId;
|
||||
info.parentId = dmsg->parentId;
|
||||
info.threadId = dmsg->threadId;
|
||||
|
||||
info.ts = dmsg->timestamp;
|
||||
info.childTS = dmsg->childTS;
|
||||
|
||||
info.title = L"[ ... Missing Message ... ]";
|
||||
info.msg = L"Placeholder for missing Message";
|
||||
info.msgflags |= RS_DISTRIB_MISSING_MSG;
|
||||
|
||||
info.srcId = "";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
info.forumId = msg->grpId;
|
||||
info.msgId = msg->msgId;
|
||||
info.parentId = msg->parentId;
|
||||
info.threadId = msg->threadId;
|
||||
|
||||
info.ts = msg->timestamp;
|
||||
info.childTS = msg->childTS;
|
||||
|
||||
/* the rest must be gotten from the derived Msg */
|
||||
|
||||
info.title = fmsg->title;
|
||||
info.msg = fmsg->msg;
|
||||
// should only use actual signature ....
|
||||
//info.srcId = fmsg->srcId;
|
||||
info.srcId = fmsg->personalSignature.keyId;
|
||||
|
||||
if (fmsg->personalSignature.keyId.empty() == false) {
|
||||
info.msgflags |= RS_DISTRIB_AUTHEN_REQ;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3Forums::ForumMessageSend(ForumMsgInfo &info)
|
||||
{
|
||||
bool signIt = (info.msgflags == RS_DISTRIB_AUTHEN_REQ);
|
||||
|
||||
std::string mId = createForumMsg(info.forumId, info.parentId,
|
||||
info.title, info.msg, signIt);
|
||||
|
||||
if (mId.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// return id
|
||||
info.msgId = mId;
|
||||
|
||||
return setMessageStatus(info.forumId, mId, FORUM_MSG_STATUS_READ, FORUM_MSG_STATUS_MASK);
|
||||
}
|
||||
|
||||
bool p3Forums::setMessageStatus(const std::string& fId,const std::string& mId,const uint32_t status, const uint32_t statusMask)
|
||||
{
|
||||
bool changed = false;
|
||||
uint32_t newStatus = 0;
|
||||
|
||||
{
|
||||
RsStackMutex stack(distribMtx); /***** STACK LOCKED MUTEX *****/
|
||||
|
||||
std::map<std::string, RsForumReadStatus*>::iterator mit = mReadStatus.find(fId);
|
||||
if (mit != mReadStatus.end())
|
||||
{
|
||||
RsForumReadStatus* rsi = mit->second;
|
||||
uint32_t oldStatus = rsi->msgReadStatus[mId];
|
||||
rsi->msgReadStatus[mId] &= ~statusMask;
|
||||
rsi->msgReadStatus[mId] |= (status & statusMask);
|
||||
|
||||
newStatus = rsi->msgReadStatus[mId];
|
||||
if (oldStatus != newStatus) {
|
||||
changed = true;
|
||||
}
|
||||
} else {
|
||||
// if forum id does not exist create one
|
||||
RsForumReadStatus* rsi = new RsForumReadStatus();
|
||||
rsi->forumId = fId;
|
||||
rsi->msgReadStatus[mId] = status & statusMask;
|
||||
mReadStatus[fId] = rsi;
|
||||
mSaveList.push_back(rsi);
|
||||
|
||||
newStatus = rsi->msgReadStatus[mId];
|
||||
changed = true;
|
||||
}
|
||||
|
||||
IndicateConfigChanged();
|
||||
} /******* UNLOCKED ********/
|
||||
|
||||
if (changed) {
|
||||
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_FORUMLIST_LOCKED, NOTIFY_TYPE_MOD);
|
||||
rsicontrol->getNotify().notifyForumMsgReadSatusChanged(fId, mId, newStatus);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3Forums::getMessageStatus(const std::string& fId, const std::string& mId, uint32_t& status)
|
||||
{
|
||||
status = 0;
|
||||
|
||||
RsStackMutex stack(distribMtx);
|
||||
|
||||
std::map<std::string, RsForumReadStatus*>::iterator fit = mReadStatus.find(fId);
|
||||
|
||||
if (fit == mReadStatus.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::map<std::string, uint32_t >::iterator rit = fit->second->msgReadStatus.find(mId);
|
||||
|
||||
if(rit != fit->second->msgReadStatus.end())
|
||||
{
|
||||
status = rit->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool p3Forums::forumRestoreKeys(const std::string& fIds)
|
||||
{
|
||||
return p3GroupDistrib::restoreGrpKeys(fIds);
|
||||
}
|
||||
|
||||
|
||||
std::string p3Forums::createForum(const std::wstring &forumName, const std::wstring &forumDesc, uint32_t forumFlags)
|
||||
{
|
||||
|
||||
std::string id = createGroup(forumName, forumDesc,
|
||||
convertToInternalFlags(forumFlags), NULL, 0);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
std::string p3Forums::createForumMsg(std::string fId, std::string pId,
|
||||
std::wstring title, std::wstring msg, bool signIt)
|
||||
{
|
||||
|
||||
RsForumMsg *fmsg = new RsForumMsg();
|
||||
fmsg->grpId = fId;
|
||||
fmsg->parentId = pId;
|
||||
processCacheOptReq(fId);
|
||||
|
||||
{
|
||||
RsStackMutex stack(distribMtx); /***** STACK LOCKED MUTEX *****/
|
||||
|
||||
RsDistribMsg *msg = locked_getGroupMsg(fId, pId);
|
||||
if (!msg)
|
||||
{
|
||||
fmsg->parentId = "";
|
||||
fmsg->threadId = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (msg->parentId == "")
|
||||
{
|
||||
fmsg->threadId = fmsg->parentId;
|
||||
}
|
||||
else
|
||||
{
|
||||
fmsg->threadId = msg->threadId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmsg->title = title;
|
||||
fmsg->msg = msg;
|
||||
if (signIt)
|
||||
{
|
||||
fmsg->srcId = AuthSSL::getAuthSSL()->OwnId();
|
||||
}
|
||||
fmsg->timestamp = time(NULL);
|
||||
|
||||
std::string msgId = publishMsg(fmsg, signIt);
|
||||
|
||||
if (msgId.empty()) {
|
||||
delete(fmsg);
|
||||
}
|
||||
|
||||
return msgId;
|
||||
}
|
||||
|
||||
RsSerialType *p3Forums::createSerialiser()
|
||||
{
|
||||
return new RsForumSerialiser();
|
||||
}
|
||||
|
||||
bool p3Forums::locked_checkDistribMsg(RsDistribMsg */*msg*/)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
RsDistribGrp *p3Forums::locked_createPublicDistribGrp(GroupInfo &/*info*/)
|
||||
{
|
||||
RsDistribGrp *grp = NULL; //new RsForumGrp();
|
||||
|
||||
return grp;
|
||||
}
|
||||
|
||||
RsDistribGrp *p3Forums::locked_createPrivateDistribGrp(GroupInfo &/*info*/)
|
||||
{
|
||||
RsDistribGrp *grp = NULL; //new RsForumGrp();
|
||||
|
||||
return grp;
|
||||
}
|
||||
|
||||
|
||||
uint32_t convertToInternalFlags(uint32_t extFlags)
|
||||
{
|
||||
return extFlags;
|
||||
}
|
||||
|
||||
uint32_t convertToExternalFlags(uint32_t intFlags)
|
||||
{
|
||||
return intFlags;
|
||||
}
|
||||
|
||||
bool p3Forums::forumSubscribe(const std::string &fId, bool subscribe)
|
||||
{
|
||||
return subscribeToGroup(fId, subscribe);
|
||||
}
|
||||
|
||||
bool p3Forums::getMessageCount(const std::string &fId, unsigned int &newCount, unsigned int &unreadCount)
|
||||
{
|
||||
newCount = 0;
|
||||
unreadCount = 0;
|
||||
|
||||
std::list<std::string> grpIds;
|
||||
|
||||
if (fId.empty()) {
|
||||
// count all messages of all subscribed forums
|
||||
getAllGroupList(grpIds);
|
||||
} else {
|
||||
// count all messages of one forum
|
||||
grpIds.push_back(fId);
|
||||
}
|
||||
|
||||
std::list<std::string>::iterator git;
|
||||
for (git = grpIds.begin(); git != grpIds.end(); git++) {
|
||||
std::string fId = *git;
|
||||
uint32_t grpFlags;
|
||||
|
||||
{
|
||||
// only flag is needed
|
||||
RsStackMutex stack(distribMtx); /***** STACK LOCKED MUTEX *****/
|
||||
GroupInfo *gi = locked_getGroupInfo(fId);
|
||||
if (gi == NULL) {
|
||||
return false;
|
||||
}
|
||||
grpFlags = gi->flags;
|
||||
} /******* UNLOCKED ********/
|
||||
|
||||
if (grpFlags & (RS_DISTRIB_ADMIN | RS_DISTRIB_SUBSCRIBED)) {
|
||||
std::list<std::string> msgIds;
|
||||
if (getAllMsgList(fId, msgIds)) {
|
||||
|
||||
RsStackMutex stack(distribMtx); /***** STACK LOCKED MUTEX *****/
|
||||
|
||||
std::map<std::string, RsForumReadStatus*>::iterator fit = mReadStatus.find(fId);
|
||||
if (fit == mReadStatus.end()) {
|
||||
// no status available -> all messages are new
|
||||
newCount += msgIds.size();
|
||||
unreadCount += msgIds.size();
|
||||
continue;
|
||||
}
|
||||
|
||||
std::list<std::string>::iterator mit;
|
||||
for (mit = msgIds.begin(); mit != msgIds.end(); mit++) {
|
||||
std::map<std::string, uint32_t >::iterator rit = fit->second->msgReadStatus.find(*mit);
|
||||
|
||||
if (rit == fit->second->msgReadStatus.end()) {
|
||||
// no status available -> message is new
|
||||
newCount++;
|
||||
unreadCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (rit->second & FORUM_MSG_STATUS_READ) {
|
||||
// message is not new
|
||||
if (rit->second & FORUM_MSG_STATUS_UNREAD_BY_USER) {
|
||||
// message is unread
|
||||
unreadCount++;
|
||||
}
|
||||
} else {
|
||||
newCount++;
|
||||
unreadCount++;
|
||||
}
|
||||
}
|
||||
} /******* UNLOCKED ********/
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/***************************************************************************************/
|
||||
/****************** Event Feedback (Overloaded form p3distrib) *************************/
|
||||
/***************************************************************************************/
|
||||
|
||||
#include "pqi/pqinotify.h"
|
||||
|
||||
void p3Forums::locked_notifyGroupChanged(GroupInfo &grp, uint32_t flags, bool historical)
|
||||
{
|
||||
const std::string &grpId = grp.grpId;
|
||||
std::string msgId;
|
||||
std::string nullId;
|
||||
|
||||
switch(flags)
|
||||
{
|
||||
case GRP_NEW_UPDATE:
|
||||
if (!historical)
|
||||
{
|
||||
getPqiNotify()->AddFeedItem(RS_FEED_ITEM_FORUM_NEW, grpId, msgId, nullId);
|
||||
}
|
||||
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_FORUMLIST_LOCKED, NOTIFY_TYPE_ADD);
|
||||
break;
|
||||
case GRP_UPDATE:
|
||||
if (!historical)
|
||||
{
|
||||
getPqiNotify()->AddFeedItem(RS_FEED_ITEM_FORUM_UPDATE, grpId, msgId, nullId);
|
||||
}
|
||||
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_FORUMLIST_LOCKED, NOTIFY_TYPE_MOD);
|
||||
break;
|
||||
case GRP_LOAD_KEY:
|
||||
break;
|
||||
case GRP_NEW_MSG:
|
||||
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_FORUMLIST_LOCKED, NOTIFY_TYPE_ADD);
|
||||
break;
|
||||
case GRP_SUBSCRIBED:
|
||||
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_FORUMLIST_LOCKED, NOTIFY_TYPE_ADD);
|
||||
break;
|
||||
case GRP_UNSUBSCRIBED:
|
||||
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_FORUMLIST_LOCKED, NOTIFY_TYPE_DEL);
|
||||
break;
|
||||
}
|
||||
return p3GroupDistrib::locked_notifyGroupChanged(grp, flags, historical);
|
||||
}
|
||||
|
||||
bool p3Forums::locked_eventDuplicateMsg(GroupInfo */*grp*/, RsDistribMsg */*msg*/, const std::string& /*id*/, bool /*historical*/)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3Forums::forumShareKeys(std::string fId, std::list<std::string>& peers)
|
||||
{
|
||||
|
||||
#ifdef FORUM_DEBUG
|
||||
std::cerr << "p3Forums::forumShareKeys() " << fId << std::endl;
|
||||
#endif
|
||||
|
||||
return sharePubKey(fId, peers);
|
||||
}
|
||||
|
||||
bool p3Forums::locked_eventNewMsg(GroupInfo */*grp*/, RsDistribMsg *msg, const std::string& /*id*/, bool historical)
|
||||
{
|
||||
std::string grpId = msg->grpId;
|
||||
std::string msgId = msg->msgId;
|
||||
std::string nullId;
|
||||
|
||||
if (!historical)
|
||||
{
|
||||
getPqiNotify()->AddFeedItem(RS_FEED_ITEM_FORUM_MSG, grpId, msgId, nullId);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/****************************************/
|
||||
|
||||
void p3Forums::loadDummyData()
|
||||
{
|
||||
ForumInfo fi;
|
||||
std::string forumId;
|
||||
std::string msgId;
|
||||
time_t now = time(NULL);
|
||||
|
||||
fi.forumId = "FID1234";
|
||||
fi.forumName = L"Forum 1";
|
||||
fi.forumDesc = L"Forum 1";
|
||||
fi.forumFlags = RS_DISTRIB_ADMIN;
|
||||
fi.pop = 2;
|
||||
fi.lastPost = now - 123;
|
||||
|
||||
forumId = createForum(fi.forumName, fi.forumDesc, fi.forumFlags);
|
||||
|
||||
fi.forumId = "FID2345";
|
||||
fi.forumName = L"Forum 2";
|
||||
fi.forumDesc = L"Forum 2";
|
||||
fi.forumFlags = RS_DISTRIB_SUBSCRIBED;
|
||||
fi.pop = 3;
|
||||
fi.lastPost = now - 1234;
|
||||
|
||||
forumId = createForum(fi.forumName, fi.forumDesc, fi.forumFlags);
|
||||
msgId = createForumMsg(forumId, "", L"WELCOME TO Forum1", L"Hello!", true);
|
||||
msgId = createForumMsg(forumId, msgId, L"Love this forum", L"Hello2!", true);
|
||||
|
||||
return;
|
||||
|
||||
/* ignore this */
|
||||
|
||||
fi.forumId = "FID3456";
|
||||
fi.forumName = L"Forum 3";
|
||||
fi.forumDesc = L"Forum 3";
|
||||
fi.forumFlags = 0;
|
||||
fi.pop = 3;
|
||||
fi.lastPost = now - 1234;
|
||||
|
||||
forumId = createForum(fi.forumName, fi.forumDesc, fi.forumFlags);
|
||||
|
||||
fi.forumId = "FID4567";
|
||||
fi.forumName = L"Forum 4";
|
||||
fi.forumDesc = L"Forum 4";
|
||||
fi.forumFlags = 0;
|
||||
fi.pop = 5;
|
||||
fi.lastPost = now - 1234;
|
||||
|
||||
forumId = createForum(fi.forumName, fi.forumDesc, fi.forumFlags);
|
||||
|
||||
fi.forumId = "FID5678";
|
||||
fi.forumName = L"Forum 5";
|
||||
fi.forumDesc = L"Forum 5";
|
||||
fi.forumFlags = 0;
|
||||
fi.pop = 1;
|
||||
fi.lastPost = now - 1234;
|
||||
|
||||
forumId = createForum(fi.forumName, fi.forumDesc, fi.forumFlags);
|
||||
|
||||
fi.forumId = "FID6789";
|
||||
fi.forumName = L"Forum 6";
|
||||
fi.forumDesc = L"Forum 6";
|
||||
fi.forumFlags = 0;
|
||||
fi.pop = 2;
|
||||
fi.lastPost = now - 1234;
|
||||
|
||||
forumId = createForum(fi.forumName, fi.forumDesc, fi.forumFlags);
|
||||
|
||||
fi.forumId = "FID7890";
|
||||
fi.forumName = L"Forum 7";
|
||||
fi.forumDesc = L"Forum 7";
|
||||
fi.forumFlags = 0;
|
||||
fi.pop = 4;
|
||||
fi.lastPost = now - 1234;
|
||||
|
||||
forumId = createForum(fi.forumName, fi.forumDesc, fi.forumFlags);
|
||||
|
||||
fi.forumId = "FID8901";
|
||||
fi.forumName = L"Forum 8";
|
||||
fi.forumDesc = L"Forum 8";
|
||||
fi.forumFlags = 0;
|
||||
fi.pop = 3;
|
||||
fi.lastPost = now - 1234;
|
||||
|
||||
forumId = createForum(fi.forumName, fi.forumDesc, fi.forumFlags);
|
||||
|
||||
fi.forumId = "FID9012";
|
||||
fi.forumName = L"Forum 9";
|
||||
fi.forumDesc = L"Forum 9";
|
||||
fi.forumFlags = 0;
|
||||
fi.pop = 2;
|
||||
fi.lastPost = now - 1234;
|
||||
|
||||
forumId = createForum(fi.forumName, fi.forumDesc, fi.forumFlags);
|
||||
|
||||
fi.forumId = "FID9123";
|
||||
fi.forumName = L"Forum 10";
|
||||
fi.forumDesc = L"Forum 10";
|
||||
fi.forumFlags = 0;
|
||||
fi.pop = 1;
|
||||
fi.lastPost = now - 1234;
|
||||
|
||||
forumId = createForum(fi.forumName, fi.forumDesc, fi.forumFlags);
|
||||
}
|
||||
|
||||
std::list<RsItem* > p3Forums::childSaveList()
|
||||
{
|
||||
return mSaveList;
|
||||
}
|
||||
|
||||
bool p3Forums::childLoadList(std::list<RsItem* >& configSaves)
|
||||
{
|
||||
RsForumReadStatus* drs = NULL;
|
||||
std::list<RsItem* >::iterator it;
|
||||
|
||||
for(it = configSaves.begin(); it != configSaves.end(); it++)
|
||||
{
|
||||
if(NULL != (drs = dynamic_cast<RsForumReadStatus* >(*it)))
|
||||
{
|
||||
mReadStatus[drs->forumId] = drs;
|
||||
mSaveList.push_back(drs);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "p3Forums::childLoadList(): Configs items loaded were incorrect!"
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
#ifndef RS_P3_FORUMS_INTERFACE_H
|
||||
#define RS_P3_FORUMS_INTERFACE_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/services: p3forums.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 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 "retroshare/rsforums.h"
|
||||
#include "distrib/p3distrib.h"
|
||||
#include "serialiser/rsforumitems.h"
|
||||
|
||||
|
||||
|
||||
class p3Forums: public p3GroupDistrib, public RsForums
|
||||
{
|
||||
public:
|
||||
|
||||
p3Forums(uint16_t type, CacheStrapper *cs, CacheTransfer *cft,
|
||||
std::string srcdir, std::string storedir, std::string forumdir);
|
||||
virtual ~p3Forums();
|
||||
|
||||
void loadDummyData();
|
||||
|
||||
/****************************************/
|
||||
/********* rsForums Interface ***********/
|
||||
|
||||
virtual bool forumsChanged(std::list<std::string> &forumIds);
|
||||
|
||||
virtual std::string createForum(const std::wstring &forumName, const std::wstring &forumDesc, uint32_t forumFlags);
|
||||
|
||||
virtual bool getForumInfo(const std::string &fId, ForumInfo &fi);
|
||||
virtual bool setForumInfo(const std::string &fId, ForumInfo &fi);
|
||||
virtual bool getForumList(std::list<ForumInfo> &forumList);
|
||||
virtual bool getForumThreadList(const std::string &fId, std::list<ThreadInfoSummary> &msgs);
|
||||
virtual bool getForumThreadMsgList(const std::string &fId, const std::string &tId, std::list<ThreadInfoSummary> &msgs);
|
||||
virtual bool getForumMessage(const std::string &fId, const std::string &mId, ForumMsgInfo &msg);
|
||||
virtual bool ForumMessageSend(ForumMsgInfo &info);
|
||||
virtual bool setMessageStatus(const std::string& fId, const std::string& mId, const uint32_t status, const uint32_t statusMask);
|
||||
virtual bool getMessageStatus(const std::string& fId, const std::string& mId, uint32_t& status);
|
||||
virtual bool forumRestoreKeys(const std::string& fId);
|
||||
virtual bool forumShareKeys(std::string fId, std::list<std::string>& peers);
|
||||
virtual bool forumSubscribe(const std::string &fId, bool subscribe);
|
||||
|
||||
virtual bool getMessageCount(const std::string &fId, unsigned int &newCount, unsigned int &unreadCount);
|
||||
|
||||
/***************************************************************************************/
|
||||
/****************** Event Feedback (Overloaded form p3distrib) *************************/
|
||||
/***************************************************************************************/
|
||||
|
||||
virtual void locked_notifyGroupChanged(GroupInfo &grp, uint32_t flags, bool historical);
|
||||
virtual bool locked_eventDuplicateMsg(GroupInfo *, RsDistribMsg *, const std::string&, bool historical);
|
||||
virtual bool locked_eventNewMsg(GroupInfo *, RsDistribMsg *, const std::string&, bool historical);
|
||||
|
||||
|
||||
/****************************************/
|
||||
/********* Overloaded Functions *********/
|
||||
|
||||
//virtual RsSerialiser *setupSerialiser();
|
||||
//virtual pqistreamer *createStreamer(BinInterface *bio, std::string src, uint32_t bioflags);
|
||||
virtual RsSerialType *createSerialiser();
|
||||
|
||||
virtual bool locked_checkDistribMsg(RsDistribMsg *msg);
|
||||
virtual RsDistribGrp *locked_createPublicDistribGrp(GroupInfo &info);
|
||||
virtual RsDistribGrp *locked_createPrivateDistribGrp(GroupInfo &info);
|
||||
virtual bool childLoadList(std::list<RsItem *>& );
|
||||
virtual std::list<RsItem *> childSaveList();
|
||||
|
||||
|
||||
/****************************************/
|
||||
|
||||
std::string createForumMsg(std::string fId, std::string pId,
|
||||
std::wstring title, std::wstring msg, bool signIt);
|
||||
|
||||
private:
|
||||
|
||||
std::string mForumsDir;
|
||||
std::list<RsItem *> mSaveList; // store save data
|
||||
|
||||
std::map<std::string, RsForumReadStatus*> mReadStatus;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load diff
|
@ -1,151 +0,0 @@
|
|||
/*
|
||||
* libretroshare/src/services: p3gamelauncher.h
|
||||
*
|
||||
* Services for RetroShare.
|
||||
*
|
||||
* Copyright 2004-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".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef SERVICE_GAME_LAUNCHER_HEADER
|
||||
#define SERVICE_GAME_LAUNCHER_HEADER
|
||||
|
||||
/*
|
||||
* A central point to setup games between peers.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
#include "services/p3service.h"
|
||||
#include "serialiser/rsgameitems.h"
|
||||
#include "retroshare/rsgame.h"
|
||||
|
||||
class p3LinkMgr;
|
||||
|
||||
|
||||
class gameAvail
|
||||
{
|
||||
uint32_t serviceId;
|
||||
std::string gameName;
|
||||
uint16_t minPlayers;
|
||||
uint16_t maxPlayers;
|
||||
};
|
||||
|
||||
class gameStatus
|
||||
{
|
||||
public:
|
||||
|
||||
uint32_t serviceId;
|
||||
std::string gameId;
|
||||
std::wstring gameName;
|
||||
|
||||
bool areServer; /* are we the server? */
|
||||
std::string serverId; /* if not, who is? */
|
||||
|
||||
uint16_t numPlayers;
|
||||
std::list<std::string> allowedPeers; /* who can play ( controlled by server) */
|
||||
std::list<std::string> interestedPeers; /* who wants to play ( controlled by server) */
|
||||
std::list<std::string> peerIds; /* in order of turns */
|
||||
|
||||
uint32_t state;
|
||||
};
|
||||
|
||||
class p3GameService;
|
||||
|
||||
/* We're going to add the external Interface - directly on here! */
|
||||
|
||||
class p3GameLauncher: public p3Service, public RsGameLauncher
|
||||
{
|
||||
public:
|
||||
p3GameLauncher(p3LinkMgr *lm);
|
||||
|
||||
/***** EXTERNAL RsGameLauncher Interface *******/
|
||||
/* server commands */
|
||||
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);
|
||||
//virtual bool quitGame(std::string gameId);
|
||||
|
||||
virtual bool invitePeer(std::string gameId, std::string peerId);
|
||||
virtual bool uninvitePeer(std::string gameId, std::string peerId);
|
||||
virtual bool confirmPeer(std::string gameId, std::string peerId,
|
||||
int16_t pos = -1);
|
||||
virtual bool unconfirmPeer(std::string gameId, std::string peerId);
|
||||
|
||||
/* client commands */
|
||||
virtual bool interestedPeer(std::string gameId);
|
||||
virtual bool uninterestedPeer(std::string gameId);
|
||||
|
||||
/* get details */
|
||||
virtual bool getGameList(std::list<RsGameInfo> &gameList);
|
||||
virtual bool getGameDetail(std::string gameId, RsGameDetail &detail);
|
||||
/***** EXTERNAL RsGameLauncher Interface *******/
|
||||
|
||||
/* support functions */
|
||||
private:
|
||||
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);
|
||||
|
||||
|
||||
/* p3Service Overloaded */
|
||||
virtual int tick();
|
||||
virtual int status();
|
||||
|
||||
/* add in the Game */
|
||||
int addGameService(p3GameService *game);
|
||||
/* notify gameService/peers */
|
||||
|
||||
//int getGameList(std::list<gameAvail> &games);
|
||||
//int getGamesCurrent(std::list<std::string> &games);
|
||||
//int getGameDetails(std::string gid, gameStatus &status);
|
||||
|
||||
/**** GUI Interface ****/
|
||||
|
||||
bool resumeGame(std::string gameId);
|
||||
|
||||
/**** Network Interface ****/
|
||||
int checkIncoming();
|
||||
int handleIncoming(RsGameItem *gi);
|
||||
|
||||
int handleClientStart(RsGameItem *gi); /* START msg */
|
||||
int handleClientInvited(RsGameItem *gi); /* REJECT msg */
|
||||
int handleClientReady(RsGameItem *gi); /* CONFIRM / REJECT / PLAY msg */
|
||||
int handleClientActive(RsGameItem *gi); /* PAUSE / QUIT msg */
|
||||
|
||||
int handleServerSetup(RsGameItem *gi); /* INTERESTED / REJECT msg */
|
||||
int handleServerActive(RsGameItem *gi); /* PAUSE / QUIT msg */
|
||||
|
||||
int sendRejectMsg(RsGameItem *gi); /* --- error msg */
|
||||
void cleanupGame(std::string gameId); /* remove from list */
|
||||
bool checkGameProperties(uint16_t serviceId, uint16_t players);
|
||||
|
||||
std::map<uint16_t, p3GameService *> gameList;
|
||||
std::map<std::string, gameStatus> gamesCurrent;
|
||||
|
||||
p3LinkMgr *mLinkMgr;
|
||||
std::string mOwnId;
|
||||
};
|
||||
|
||||
#endif // SERVICE_GAME_LAUNCHER_HEADER
|
|
@ -1,90 +0,0 @@
|
|||
/*
|
||||
* libretroshare/src/services: p3gameservice.h
|
||||
*
|
||||
* Services for RetroShare.
|
||||
*
|
||||
* Copyright 2004-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".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef P3_SERVICE_GAME_HEADER
|
||||
#define P3_SERVICE_GAME_HEADER
|
||||
|
||||
/*
|
||||
* A central point to setup games between peers.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
#include "services/p3service.h"
|
||||
|
||||
class StoredGame
|
||||
{
|
||||
public:
|
||||
std::string gameId;
|
||||
time_t startTime;
|
||||
std::list<std::string> peerIds; /* in order of turns */
|
||||
};
|
||||
|
||||
class p3GameLauncher;
|
||||
class p3Service;
|
||||
|
||||
class p3GameService
|
||||
{
|
||||
public:
|
||||
|
||||
p3GameService(uint16_t sId, std::string name, uint16_t min, uint16_t max, p3GameLauncher *l)
|
||||
:serviceId(sId), gameName(name), minPlayers(min), maxPlayers(max),
|
||||
service(NULL), launcher(l)
|
||||
{ return; }
|
||||
|
||||
virtual ~p3GameService()
|
||||
{ return; }
|
||||
|
||||
/*************** Game Interface ******************/
|
||||
/* saved games */
|
||||
virtual void getSavedGames(std::list<StoredGame> &gList);
|
||||
|
||||
/* start a game */
|
||||
virtual void startGame(StoredGame &newGame, bool resume);
|
||||
virtual void quitGame(std::string gameId);
|
||||
virtual void deleteGame(std::string gameId);
|
||||
/*************** Game Interface ******************/
|
||||
|
||||
/* details for the Launcher */
|
||||
uint16_t getServiceId() { return serviceId; }
|
||||
std::string getGameName() { return gameName; }
|
||||
uint16_t getMinPlayers() { return minPlayers; }
|
||||
uint16_t getMaxPlayers() { return maxPlayers; }
|
||||
p3GameLauncher *getLauncher() { return launcher; }
|
||||
|
||||
private:
|
||||
|
||||
uint16_t serviceId;
|
||||
std::string gameName;
|
||||
uint16_t minPlayers, maxPlayers;
|
||||
|
||||
p3Service *service;
|
||||
p3GameLauncher *launcher;
|
||||
};
|
||||
|
||||
#endif // P3_SERVICE_GAME_HEADER
|
Loading…
Add table
Add a link
Reference in a new issue