2021-10-08 19:08:23 -04:00
|
|
|
#include "util/rsdebug.h"
|
|
|
|
|
|
|
|
#include "friendserver.h"
|
2021-10-24 14:01:19 -04:00
|
|
|
#include "friend_server/fsitem.h"
|
2021-10-08 19:08:23 -04:00
|
|
|
|
|
|
|
void FriendServer::threadTick()
|
|
|
|
{
|
|
|
|
// Listen to the network interface, capture incoming data etc.
|
|
|
|
|
2021-10-09 09:06:06 -04:00
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
|
|
|
|
2021-10-11 17:40:22 -04:00
|
|
|
RsItem *item;
|
|
|
|
|
2021-10-19 17:24:50 -04:00
|
|
|
while(nullptr != (item = mni->GetItem()))
|
2021-10-11 17:40:22 -04:00
|
|
|
{
|
|
|
|
RsFriendServerItem *fsitem = dynamic_cast<RsFriendServerItem*>(item);
|
|
|
|
|
|
|
|
if(!fsitem)
|
|
|
|
{
|
|
|
|
RsErr() << "Received an item of the wrong type!" ;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
2021-10-19 17:24:50 -04:00
|
|
|
std::cerr << "Received item: " << std::endl << *fsitem << std::endl;
|
2021-10-11 17:40:22 -04:00
|
|
|
|
|
|
|
switch(fsitem->PacketSubType())
|
|
|
|
{
|
|
|
|
case RS_PKT_SUBTYPE_FS_CLIENT_REMOVE: handleClientRemove(dynamic_cast<RsFriendServerClientRemoveItem*>(fsitem));
|
|
|
|
break;
|
|
|
|
case RS_PKT_SUBTYPE_FS_CLIENT_PUBLISH: handleClientPublish(dynamic_cast<RsFriendServerClientPublishItem*>(fsitem));
|
|
|
|
break;
|
|
|
|
default: ;
|
|
|
|
}
|
|
|
|
delete item;
|
|
|
|
}
|
2021-10-08 19:08:23 -04:00
|
|
|
}
|
|
|
|
|
2021-10-11 17:40:22 -04:00
|
|
|
void FriendServer::handleClientPublish(const RsFriendServerClientPublishItem *item)
|
|
|
|
{
|
|
|
|
RsDbg() << "Received a client publish item:" << *item ;
|
|
|
|
}
|
|
|
|
void FriendServer::handleClientRemove(const RsFriendServerClientRemoveItem *item)
|
|
|
|
{
|
|
|
|
RsDbg() << "Received a client remove item:" << *item ;
|
|
|
|
}
|
2021-10-08 19:08:23 -04:00
|
|
|
FriendServer::FriendServer(const std::string& base_dir)
|
|
|
|
{
|
2021-10-09 09:06:06 -04:00
|
|
|
RsDbg() << "Creating friend server." ;
|
2021-10-08 19:08:23 -04:00
|
|
|
mBaseDirectory = base_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FriendServer::run()
|
|
|
|
{
|
|
|
|
// 1 - create network interface.
|
|
|
|
|
|
|
|
mni = new FsNetworkInterface;
|
2021-10-09 09:06:06 -04:00
|
|
|
mni->start();
|
2021-10-08 19:08:23 -04:00
|
|
|
|
|
|
|
while(!shouldStop()) { threadTick() ; }
|
|
|
|
}
|
|
|
|
|