diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/coremods/core_channel/invite.cpp | 31 | ||||
-rw-r--r-- | src/coremods/core_channel/invite.h | 18 |
2 files changed, 48 insertions, 1 deletions
diff --git a/src/coremods/core_channel/invite.cpp b/src/coremods/core_channel/invite.cpp index 253c571ca..7ac662edc 100644 --- a/src/coremods/core_channel/invite.cpp +++ b/src/coremods/core_channel/invite.cpp @@ -38,6 +38,11 @@ void RemoveInvite(Invite::Invite* inv, bool remove_user, bool remove_chan) apiimpl->Destruct(inv, remove_user, remove_chan); } +void UnserializeInvite(LocalUser* user, const std::string& str) +{ + apiimpl->Unserialize(user, str); +} + Invite::APIBase::APIBase(Module* parent) : DataProvider(parent, "core_channel_invite") { @@ -150,6 +155,17 @@ const Invite::List* Invite::APIImpl::GetList(LocalUser* user) return NULL; } +void Invite::APIImpl::Unserialize(LocalUser* user, const std::string& value) +{ + irc::spacesepstream ss(value); + for (std::string channame, exptime; (ss.GetToken(channame) && ss.GetToken(exptime)); ) + { + Channel* chan = ServerInstance->FindChan(channame); + if (chan) + Create(user, chan, ConvToInt(exptime)); + } +} + Invite::Invite::Invite(LocalUser* u, Channel* c) : user(u) , chan(c) @@ -163,6 +179,21 @@ Invite::Invite::~Invite() ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Invite::~ %p", (void*) this); } +void Invite::Invite::Serialize(SerializeFormat format, bool show_chans, std::string& out) +{ + if (show_chans) + out.append(this->chan->name); + else + out.append((format == FORMAT_USER) ? user->nick : user->uuid); + out.push_back(' '); + + if (expiretimer) + out.append(ConvToStr(expiretimer->GetTrigger())); + else + out.push_back('0'); + out.push_back(' '); +} + InviteExpireTimer::InviteExpireTimer(Invite::Invite* invite, time_t timeout) : Timer(timeout) , inv(invite) diff --git a/src/coremods/core_channel/invite.h b/src/coremods/core_channel/invite.h index f11ff9043..2a99ec2df 100644 --- a/src/coremods/core_channel/invite.h +++ b/src/coremods/core_channel/invite.h @@ -40,6 +40,7 @@ namespace Invite } extern void RemoveInvite(Invite::Invite* inv, bool remove_user, bool remove_chan); +extern void UnserializeInvite(LocalUser* user, const std::string& value); template<typename T, ExtensionItem::ExtensibleType ExtType> class Invite::ExtItem : public ExtensionItem @@ -84,11 +85,25 @@ class Invite::ExtItem : public ExtensionItem std::string serialize(SerializeFormat format, const Extensible* container, void* item) const CXX11_OVERRIDE { - return std::string(); + if (format == FORMAT_NETWORK) + return std::string(); + + std::string ret; + Store<T>* store = static_cast<Store<T>*>(item); + for (typename insp::intrusive_list<Invite, T>::iterator i = store->invites.begin(); i != store->invites.end(); ++i) + { + Invite* inv = *i; + inv->Serialize(format, (ExtType == ExtensionItem::EXT_USER), ret); + } + if (!ret.empty()) + ret.erase(ret.length()-1); + return ret; } void unserialize(SerializeFormat format, Extensible* container, const std::string& value) CXX11_OVERRIDE { + if ((ExtType != ExtensionItem::EXT_CHANNEL) && (format != FORMAT_NETWORK)) + UnserializeInvite(static_cast<LocalUser*>(container), value); } }; @@ -108,4 +123,5 @@ class Invite::APIImpl : public APIBase void RemoveAll(LocalUser* user) { userext.unset(user); } void RemoveAll(Channel* chan) { chanext.unset(chan); } void Destruct(Invite* inv, bool remove_chan = true, bool remove_user = true); + void Unserialize(LocalUser* user, const std::string& value); }; |