10#include "Exceptions.h"
13#include <sigc++/slot.h>
15#include <Atlas/Objects/Operation.h>
16#include <Atlas/Objects/Anonymous.h>
20using namespace Atlas::Objects::Operation;
21using Atlas::Objects::Root;
22using Atlas::Objects::Entity::RootEntity;
23using Atlas::Objects::Entity::Anonymous;
24using Atlas::Objects::smart_dynamic_cast;
41 if (!m_roomId.empty()) {
52 error() <<
"talking in room " << m_roomId <<
", but connection is down";
57 speech->setAttr(
"say", tk);
58 speech->setAttr(
"loc", m_roomId);
73 error() <<
"emoting in room " << m_roomId <<
", but connection is down";
80 emote->setId(
"emote");
81 emote->setAttr(
"loc", m_roomId);
82 emote->setAttr(
"description", em);
96 error() <<
"leaving room " << m_roomId <<
", but connection is down";
105 args->setAttr(
"loc", m_roomId);
106 args->setAttr(
"mode",
"part");
107 part->setArgs1(args);
116 error() <<
"creating room in room " << m_roomId <<
", but connection is down";
128 room->setParent(
"room");
136Person* Room::getPersonByUID(
const std::string& uid)
143 std::vector<Person*> people;
145 for (
const auto & member : m_members)
148 people.push_back(member.second);
155Router::RouterResult Room::handleOperation(
const RootOperation& op)
158 error() <<
"Room received op TO account " << op->getTo() <<
", not the account ID";
162 const std::vector<Root>& args = op->getArgs();
164 if (op->instanceOf(APPEARANCE_NO)) {
165 for (
const auto & arg : args) {
166 appearance(arg->getId());
172 if (op->instanceOf(DISAPPEARANCE_NO)) {
173 for (
const auto & arg : args) {
174 disappearance(arg->getId());
180 if (op->instanceOf(SIGHT_NO)) {
181 assert(!args.empty());
182 RootEntity ent = smart_dynamic_cast<RootEntity>(args.front());
184 if (ent.isValid() && (ent->getId() == m_roomId)) {
193void Room::sight(
const RootEntity &room)
196 warning() <<
"got SIGHT of entered room " << m_roomId;
198 m_name = room->getName();
199 if (room->hasAttr(
"topic"))
200 m_topic = room->getAttr(
"topic").asString();
202 m_lobby->
SightPerson.connect(sigc::mem_fun(
this, &Room::notifyPersonSight));
204 if (room->hasAttr(
"people"))
206 const Atlas::Message::ListType& people = room->getAttr(
"people").asList();
207 for (
const auto & person : people) {
208 appearance(person.asString());
214 if (room->hasAttr(
"rooms"))
216 const Atlas::Message::ListType& rooms = room->getAttr(
"rooms").asList();
217 for (
const auto & item : rooms)
219 m_subrooms.push_back(
new Room(m_lobby, item.asString()));
224void Room::handleSoundTalk(Person* p,
const std::string& speech)
228 if (m_members.count(p->getAccount()) == 0) {
229 error() <<
"room " << m_roomId <<
" got sound(talk) from non-member account";
233 Speech.emit(
this, p, speech);
236void Room::handleEmote(Person* p,
const std::string& description)
240 if (m_members.count(p->getAccount()) == 0) {
241 error() <<
"room " << m_roomId <<
" got sight(imaginary) from non-member account";
245 Emote.emit(
this, p, description);
250void Room::appearance(
const std::string& personId)
252 auto P = m_members.find(personId);
253 if (P != m_members.end()) {
254 error() <<
"duplicate appearance of person " << personId <<
" in room " << m_roomId;
258 Person* person = m_lobby->
getPerson(personId);
261 m_members[personId] = person;
265 m_members[personId] =
nullptr;
270void Room::disappearance(
const std::string& personId)
272 auto P = m_members.find(personId);
273 if (P == m_members.end())
275 error() <<
"during disappearance, person " << personId <<
" not found in room " << m_roomId;
285void Room::notifyPersonSight(Person *p)
288 auto P = m_members.find(p->getAccount());
291 if (P == m_members.end()) {
295 if (P->second ==
nullptr) {
296 m_members[p->getAccount()] = p;
306 assert (P->second == p);
310void Room::checkEntry()
314 bool anyPending =
false;
315 for (
auto& entry : m_members) {
316 if (entry.second ==
nullptr) {
const std::string & getId() const
returns the account ID if logged in
bool isConnected() const
Ascertain whether or not the connection is usable for transport.
virtual void send(const Atlas::Objects::Root &obj)
Transmit an Atlas::Objects instance to the server.
Person * getPerson(const std::string &acc)
obtain a person's info, given their account ID; may return nullptr
Connection & getConnection() const
Helper method to access the underlying Connection from the Account.
Account & getAccount() const
Retrive the Account which this lobbby is bound to.
sigc::signal< void, Person * > SightPerson
Emitted when sight of a person is received.
Room * createRoom(const std::string &name)
sigc::signal< void, Room *, Person *, const std::string & > Emote
Room(Lobby *l, const std::string &id)
sigc::signal< void, Room * > Entered
void say(const std::string &tk)
Send a piece of text to this room.
sigc::signal< void, Room *, Person *, const std::string & > Speech
void emote(const std::string &em)
std::vector< Person * > getPeople() const
obtain an array of pointers to everyone in this room
sigc::signal< void, Room *, Person * > Disappearance
Similarly, emitted when the specifed person leaves the room.
sigc::signal< void, Room *, Person * > Appearance
std::int64_t getNewSerialno()
operation serial number sequencing