added code to handle a single connection

This commit is contained in:
fourtf
2018-07-16 17:23:41 +02:00
parent e51c5c692a
commit 3b3c5d8d75
18 changed files with 114 additions and 84 deletions
+17 -21
View File
@@ -35,26 +35,18 @@ AbstractIrcServer::AbstractIrcServer()
// this->writeConnection->reconnectRequested.connect([this] { this->connect(); });
}
IrcConnection *AbstractIrcServer::getReadConnection() const
{
return this->readConnection_.get();
}
IrcConnection *AbstractIrcServer::getWriteConnection() const
{
return this->writeConnection_.get();
}
void AbstractIrcServer::connect()
{
this->disconnect();
// if (this->hasSeparateWriteConnection()) {
this->initializeConnection(this->writeConnection_.get(), false, true);
this->initializeConnection(this->readConnection_.get(), true, false);
// } else {
// this->initializeConnection(this->readConnection.get(), true, true);
// }
bool separateWriteConnection = this->hasSeparateWriteConnection();
if (separateWriteConnection) {
this->initializeConnection(this->writeConnection_.get(), false, true);
this->initializeConnection(this->readConnection_.get(), true, false);
} else {
this->initializeConnection(this->readConnection_.get(), true, true);
}
// fourtf: this should be asynchronous
{
@@ -67,7 +59,6 @@ void AbstractIrcServer::connect()
continue;
}
this->writeConnection_->sendRaw("JOIN #" + chan->name);
this->readConnection_->sendRaw("JOIN #" + chan->name);
}
@@ -88,13 +79,18 @@ void AbstractIrcServer::disconnect()
}
void AbstractIrcServer::sendMessage(const QString &channelName, const QString &message)
{
this->sendRawMessage("PRIVMSG #" + channelName + " :" + message);
}
void AbstractIrcServer::sendRawMessage(const QString &rawMessage)
{
std::lock_guard<std::mutex> locker(this->connectionMutex_);
// fourtf: trim the message if it's sent from twitch chat
if (this->writeConnection_) {
this->writeConnection_->sendRaw("PRIVMSG #" + channelName + " :" + message);
if (this->hasSeparateWriteConnection()) {
this->writeConnection_->sendRaw(rawMessage);
} else {
this->readConnection_->sendRaw(rawMessage);
}
}