void Server::removeUserChannel(const UserChannel &channel) { QString userFullName = channel.getUserFullName(); if(users.contains(userFullName)){ users[userFullName].removeChannel(channel.getIndex()); } }
void Server::updateUserChannel(const UserChannel &serverChannel) { QString userFullName = serverChannel.getUserFullName(); if(users.contains(userFullName)){ users[userFullName].updateChannelName(serverChannel.getIndex(), serverChannel.getName()); } }
void TestServerInfo::removeUserChannel() { ServerInfo server("localhost", 2040, 2); QString userFullName("anon@localhost"); server.addUser(User(userFullName)); QFETCH(quint8, channelsToAdd); QFETCH(quint8, channelsToRemove); //adding some channels for (quint8 channelIndex = 0; channelIndex < channelsToAdd; ++channelIndex) { QString channelName = "channel " + QString::number(channelIndex); server.addUserChannel(userFullName, UserChannel(channelName, channelIndex)); } //removing channels and check for (quint8 channelIndex = 0; channelIndex < channelsToRemove; ++channelIndex) { UserChannel channel = server.getUser(userFullName).getChannel(channelIndex); if(channelsToRemove >= channelsToAdd){ server.removeUserChannel(userFullName, channel); QVERIFY(!server.getUser(userFullName).hasChannel(channel.getIndex())); } else{ QCOMPARE(channel.getName(), QString("invalid")); } } }
UserChannel::UserChannel(const UserChannel &c) : userFullName(c.getUserFullName()), channelName(c.getName()), active(c.isActive()), index(c.getIndex()), volume(c.volume), pan(c.pan), flags(c.flags) { }
void Server::addUserChannel(const UserChannel &newChannel) { QString userFullName = newChannel.getUserFullName(); if(users.contains(userFullName)){ int userChannelsCount = users[userFullName].getChannelsCount(); if(userChannelsCount < maxChannels) users[userFullName].addChannel(newChannel); else qCCritical(jtNinjamCore) << "Can't add more channels for " << userFullName << "(using" << QString::number(userChannelsCount) << " channels). The server maxChannels is " << QString::number(maxChannels); } }
QString NinjamController::getUniqueKeyForChannel(const UserChannel &channel, const QString &userFullName) { return userFullName + QString::number(channel.getIndex()); }