diff options
-rw-r--r-- | Sluift/client.cpp | 11 | ||||
-rw-r--r-- | Swiften/Client/CoreClient.cpp | 4 |
2 files changed, 13 insertions, 2 deletions
diff --git a/Sluift/client.cpp b/Sluift/client.cpp index 0dc7014..75f675d 100644 --- a/Sluift/client.cpp +++ b/Sluift/client.cpp @@ -360,2 +360,5 @@ SLUIFT_LUA_FUNCTION_WITH_HELP( message->setType(type); + if (!getClient(L)->getClient()->isAvailable()) { + throw Lua::Exception("Trying to send message while client is offline."); + } getClient(L)->getClient()->sendMessage(message); @@ -405,3 +408,5 @@ SLUIFT_LUA_FUNCTION_WITH_HELP( } - + if (!getClient(L)->getClient()->getPresenceSender()->isAvailable()) { + throw Lua::Exception("Trying to send presence while client is offline."); + } getClient(L)->getClient()->getPresenceSender()->sendPresence(presence); @@ -491,3 +496,5 @@ SLUIFT_LUA_FUNCTION_WITH_HELP( Sluift::globals.eventLoop.runOnce(); - + if (!getClient(L)->getClient()->isAvailable()) { + throw Lua::Exception("Trying to send data while client is offline."); + } getClient(L)->getClient()->sendData(std::string(Lua::checkString(L, 2))); diff --git a/Swiften/Client/CoreClient.cpp b/Swiften/Client/CoreClient.cpp index 3c7902e..1de1d61 100644 --- a/Swiften/Client/CoreClient.cpp +++ b/Swiften/Client/CoreClient.cpp @@ -392,2 +392,6 @@ void CoreClient::sendPresence(std::shared_ptr<Presence> presence) { void CoreClient::sendData(const std::string& data) { + if (!sessionStream_) { + SWIFT_LOG(warning) << "Client: Trying to send data while disconnected." << std::endl; + return; + } sessionStream_->writeData(data); |