2019-09-06 23:43:07 -04:00
|
|
|
#include "channels.h"
|
|
|
|
|
|
|
|
// This file is part of MRCI.
|
|
|
|
|
|
|
|
// MRCI is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// MRCI is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with MRCI under the LICENSE.md file. If not, see
|
|
|
|
// <http://www.gnu.org/licenses/>.
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
CreateChannel::CreateChannel(QObject *parent) : CmdObject(parent) {}
|
|
|
|
RemoveChannel::RemoveChannel(QObject *parent) : CmdObject(parent) {}
|
|
|
|
RenameChannel::RenameChannel(QObject *parent) : CmdObject(parent) {}
|
|
|
|
SetActiveState::SetActiveState(QObject *parent) : CmdObject(parent) {}
|
|
|
|
CreateSubCh::CreateSubCh(QObject *parent) : CmdObject(parent) {}
|
|
|
|
RemoveSubCh::RemoveSubCh(QObject *parent) : CmdObject(parent) {}
|
|
|
|
RenameSubCh::RenameSubCh(QObject *parent) : CmdObject(parent) {}
|
|
|
|
InviteToCh::InviteToCh(QObject *parent) : CmdObject(parent) {}
|
|
|
|
DeclineChInvite::DeclineChInvite(QObject *parent) : CmdObject(parent) {}
|
|
|
|
AcceptChInvite::AcceptChInvite(QObject *parent) : CmdObject(parent) {}
|
|
|
|
RemoveChMember::RemoveChMember(QObject *parent) : CmdObject(parent) {}
|
|
|
|
SetMemberLevel::SetMemberLevel(QObject *parent) : CmdObject(parent) {}
|
|
|
|
SetSubAcessLevel::SetSubAcessLevel(QObject *parent) : CmdObject(parent) {}
|
|
|
|
OwnerOverride::OwnerOverride(QObject *parent) : CmdObject(parent) {}
|
2019-09-06 23:43:07 -04:00
|
|
|
|
|
|
|
ListChannels::ListChannels(QObject *parent) : TableViewer(parent)
|
|
|
|
{
|
2019-11-08 22:06:09 -05:00
|
|
|
setParams(TABLE_CH_MEMBERS, false);
|
|
|
|
addTableColumn(TABLE_CH_MEMBERS, COLUMN_CHANNEL_ID);
|
|
|
|
addTableColumn(TABLE_CHANNELS, COLUMN_CHANNEL_NAME);
|
|
|
|
addTableColumn(TABLE_CH_MEMBERS, COLUMN_PENDING_INVITE);
|
|
|
|
addTableColumn(TABLE_CH_MEMBERS, COLUMN_ACCESS_LEVEL);
|
|
|
|
addJointColumn(TABLE_CHANNELS, COLUMN_CHANNEL_ID);
|
|
|
|
addJointColumn(TABLE_USERS, COLUMN_USER_ID);
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ListSubCh::ListSubCh(QObject *parent) : TableViewer(parent)
|
|
|
|
{
|
2019-11-08 22:06:09 -05:00
|
|
|
setParams(TABLE_SUB_CHANNELS, false);
|
|
|
|
addTableColumn(TABLE_SUB_CHANNELS, COLUMN_SUB_CH_ID);
|
|
|
|
addTableColumn(TABLE_SUB_CHANNELS, COLUMN_SUB_CH_NAME);
|
|
|
|
addTableColumn(TABLE_SUB_CHANNELS, COLUMN_LOWEST_LEVEL);
|
|
|
|
addTableColumn(TABLE_SUB_CHANNELS, COLUMN_ACTIVE_UPDATE);
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
SearchChannels::SearchChannels(QObject *parent) : TableViewer(parent)
|
|
|
|
{
|
2019-11-08 22:06:09 -05:00
|
|
|
setParams(TABLE_CHANNELS, false);
|
|
|
|
addTableColumn(TABLE_CHANNELS, COLUMN_CHANNEL_ID);
|
|
|
|
addTableColumn(TABLE_CHANNELS, COLUMN_CHANNEL_NAME);
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ListMembers::ListMembers(QObject *parent) : TableViewer(parent)
|
|
|
|
{
|
2019-11-08 22:06:09 -05:00
|
|
|
setParams(TABLE_CH_MEMBERS, false);
|
|
|
|
addTableColumn(TABLE_CH_MEMBERS, COLUMN_CHANNEL_ID);
|
|
|
|
addTableColumn(TABLE_USERS, COLUMN_USERNAME);
|
|
|
|
addTableColumn(TABLE_USERS, COLUMN_DISPLAY_NAME);
|
|
|
|
addTableColumn(TABLE_CH_MEMBERS, COLUMN_PENDING_INVITE);
|
|
|
|
addTableColumn(TABLE_CH_MEMBERS, COLUMN_ACCESS_LEVEL);
|
|
|
|
addJointColumn(TABLE_USERS, COLUMN_USER_ID);
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
QString CreateChannel::cmdName() {return "add_ch";}
|
|
|
|
QString RemoveChannel::cmdName() {return "rm_ch";}
|
|
|
|
QString RenameChannel::cmdName() {return "rename_ch";}
|
|
|
|
QString SetActiveState::cmdName() {return "set_active_flag";}
|
|
|
|
QString CreateSubCh::cmdName() {return "add_sub_ch";}
|
|
|
|
QString RemoveSubCh::cmdName() {return "rm_sub_ch";}
|
|
|
|
QString RenameSubCh::cmdName() {return "rename_sub_ch";}
|
|
|
|
QString ListChannels::cmdName() {return "ls_chs";}
|
|
|
|
QString ListSubCh::cmdName() {return "ls_sub_chs";}
|
|
|
|
QString SearchChannels::cmdName() {return "find_ch";}
|
|
|
|
QString InviteToCh::cmdName() {return "invite_to_ch";}
|
|
|
|
QString DeclineChInvite::cmdName() {return "decline_ch";}
|
|
|
|
QString AcceptChInvite::cmdName() {return "accept_ch";}
|
|
|
|
QString RemoveChMember::cmdName() {return "remove_ch_member";}
|
|
|
|
QString SetMemberLevel::cmdName() {return "set_member_level";}
|
|
|
|
QString SetSubAcessLevel::cmdName() {return "set_sub_ch_level";}
|
|
|
|
QString ListMembers::cmdName() {return "ls_ch_members";}
|
|
|
|
QString OwnerOverride::cmdName() {return "ch_owner_override";}
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
QByteArray createChMemberAsyncFrame(quint64 chId, const QByteArray &userId, bool invite, quint8 level, const QString &userName, const QString &dispName, const QString &chName)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
2019-11-08 22:06:09 -05:00
|
|
|
QByteArray ret;
|
2019-09-06 23:43:07 -04:00
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
ret.append(wrInt(chId, 64));
|
|
|
|
ret.append(userId);
|
|
|
|
|
|
|
|
if (invite)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
2019-11-08 22:06:09 -05:00
|
|
|
ret.append(wrInt(1, 8));
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-08 22:06:09 -05:00
|
|
|
ret.append(wrInt(0, 8));
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
|
|
|
|
ret.append(wrInt(level, 8));
|
|
|
|
ret.append(nullTermTEXT(userName));
|
|
|
|
ret.append(nullTermTEXT(dispName));
|
|
|
|
ret.append(nullTermTEXT(chName));
|
|
|
|
|
|
|
|
return ret;
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
void ListChannels::procIn(const QByteArray &binIn, quint8 dType)
|
|
|
|
{
|
|
|
|
Q_UNUSED(binIn)
|
|
|
|
|
|
|
|
if (flags & MORE_INPUT)
|
|
|
|
{
|
|
|
|
TableViewer::procIn(binIn, dType);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TableViewer::procIn(toTEXT("-" + QString(COLUMN_USERNAME) + " " + rdStringFromBlock(userName, BLKSIZE_USER_NAME)), dType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ListSubCh::procIn(const QByteArray &binIn, quint8 dType)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
if (dType == TEXT)
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
auto args = parseArgs(binIn, 2);
|
|
|
|
auto chName = getParam("-ch_name", args);
|
|
|
|
|
|
|
|
quint64 chId;
|
|
|
|
|
|
|
|
retCode = INVALID_PARAMS;
|
2019-09-06 23:43:07 -04:00
|
|
|
|
|
|
|
if (chName.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The channel name (-ch_name) argument was not found or is empty.\n");
|
|
|
|
}
|
|
|
|
else if (!validChName(chName))
|
|
|
|
{
|
|
|
|
errTxt("err: Invalid channel name.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!channelExists(chName, &chId))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: Channel name '" + chName + "' does not exists.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
retCode = NO_ERRORS;
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
if (channelAccessLevel(rdFromBlock(userId, BLKSIZE_USER_ID), chOwnerOverride, chId) > REGULAR)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
2019-11-08 22:06:09 -05:00
|
|
|
TableViewer::procIn(toTEXT("-" + QString(COLUMN_CHANNEL_NAME) + " " + chName + " -" + QString(COLUMN_LOWEST_LEVEL) + " " + QString::number(PUBLIC)), dType);
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-08 22:06:09 -05:00
|
|
|
TableViewer::procIn(toTEXT("-" + QString(COLUMN_CHANNEL_NAME) + " " + chName), dType);
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
void SearchChannels::procIn(const QByteArray &binIn, quint8 dType)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
if (dType == TEXT)
|
|
|
|
{
|
2019-11-08 22:06:09 -05:00
|
|
|
if (flags & MORE_INPUT)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
2019-11-08 22:06:09 -05:00
|
|
|
TableViewer::procIn(binIn, dType);
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
auto args = parseArgs(binIn, 4);
|
|
|
|
auto name = getParam("-name", args);
|
|
|
|
auto chId = getParam("-id", args);
|
|
|
|
|
|
|
|
retCode = INVALID_PARAMS;
|
2019-09-06 23:43:07 -04:00
|
|
|
|
|
|
|
if (!name.isEmpty() && !validChName(name))
|
|
|
|
{
|
|
|
|
errTxt("err: '" + name + "' is not a valid channel name.\n");
|
|
|
|
}
|
|
|
|
else if (!chId.isEmpty() && !isInt(chId))
|
|
|
|
{
|
|
|
|
errTxt("err: '" + chId + "' is not a valid channel id.\n");
|
|
|
|
}
|
|
|
|
else if (!name.isEmpty())
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
retCode = NO_ERRORS;
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
TableViewer::procIn(toTEXT("-" + QString(COLUMN_CHANNEL_NAME) + " " + name), dType);
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
else if (!chId.isEmpty())
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
retCode = NO_ERRORS;
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
TableViewer::procIn(toTEXT("-" + QString(COLUMN_CHANNEL_ID) + " " + chId), dType);
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
retCode = NO_ERRORS;
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
TableViewer::procIn(QByteArray(), dType);
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
void ListMembers::procIn(const QByteArray &binIn, quint8 dType)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
if (dType == TEXT)
|
|
|
|
{
|
2019-11-08 22:06:09 -05:00
|
|
|
if (flags & MORE_INPUT)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
2019-11-08 22:06:09 -05:00
|
|
|
TableViewer::procIn(binIn, dType);
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
auto args = parseArgs(binIn, 6);
|
|
|
|
auto chName = getParam("-ch_name", args);
|
|
|
|
auto userFind = getParam("-user_name", args);
|
|
|
|
auto dispFind = getParam("-disp_name", args);
|
|
|
|
|
|
|
|
quint64 chId;
|
|
|
|
|
|
|
|
retCode = INVALID_PARAMS;
|
2019-09-06 23:43:07 -04:00
|
|
|
|
|
|
|
if (chName.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The channel name (-ch_name) argument was not found or is empty.\n");
|
|
|
|
}
|
|
|
|
else if (!validChName(chName))
|
|
|
|
{
|
|
|
|
errTxt("err: Invalid channel name.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!channelExists(chName, &chId))
|
|
|
|
{
|
|
|
|
errTxt("err: Channel name '" + chName + "' does not exists.\n");
|
|
|
|
}
|
|
|
|
else if (channelAccessLevel(rdFromBlock(userId, BLKSIZE_USER_ID), chOwnerOverride, chId) > REGULAR)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: You are not currently a member of the channel: '" + chName + "'\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
retCode = NO_ERRORS;
|
|
|
|
|
|
|
|
auto argsBa = toTEXT("-" + QString(COLUMN_CHANNEL_NAME) + " " + chName);
|
2019-09-06 23:43:07 -04:00
|
|
|
|
|
|
|
if (!userFind.isEmpty())
|
|
|
|
{
|
2019-11-08 22:06:09 -05:00
|
|
|
argsBa.append(toTEXT(" -" + QString(COLUMN_USERNAME) + " " + userFind));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dispFind.isEmpty())
|
|
|
|
{
|
|
|
|
argsBa.append(toTEXT(" -" + QString(COLUMN_DISPLAY_NAME) + " " + dispFind));
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
TableViewer::procIn(argsBa, dType);
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
void CreateChannel::procIn(const QByteArray &binIn, uchar dType)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
if (dType == TEXT)
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
auto args = parseArgs(binIn, 2);
|
|
|
|
auto chName = getParam("-ch_name", args);
|
|
|
|
|
|
|
|
quint64 chId;
|
|
|
|
|
|
|
|
retCode = INVALID_PARAMS;
|
2019-09-06 23:43:07 -04:00
|
|
|
|
|
|
|
if (chName.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The channel name (-ch_name) argument was not found or is empty.\n");
|
|
|
|
}
|
|
|
|
else if (!validChName(chName))
|
|
|
|
{
|
|
|
|
errTxt("err: Invalid channel name. it must be between 4-32 chars long and contain no spaces.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (channelExists(chName, &chId))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: Channel name '" + chName + "' already exists.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
retCode = NO_ERRORS;
|
|
|
|
|
2019-09-06 23:43:07 -04:00
|
|
|
Query db(this);
|
|
|
|
|
|
|
|
db.setType(Query::PUSH, TABLE_CHANNELS);
|
|
|
|
db.addColumn(COLUMN_CHANNEL_NAME, chName);
|
|
|
|
db.exec();
|
|
|
|
|
2020-01-29 12:29:01 -05:00
|
|
|
auto uId = rdFromBlock(userId, BLKSIZE_USER_ID);
|
|
|
|
auto uName = rdStringFromBlock(userName, BLKSIZE_USER_NAME);
|
|
|
|
auto dName = rdStringFromBlock(displayName, BLKSIZE_DISP_NAME);
|
2019-09-06 23:43:07 -04:00
|
|
|
|
|
|
|
db.setType(Query::PUSH, TABLE_CH_MEMBERS);
|
|
|
|
db.addColumn(COLUMN_CHANNEL_ID, chId);
|
2019-11-08 22:06:09 -05:00
|
|
|
db.addColumn(COLUMN_USER_ID, uId);
|
2019-09-06 23:43:07 -04:00
|
|
|
db.addColumn(COLUMN_ACCESS_LEVEL, OWNER);
|
|
|
|
db.addColumn(COLUMN_PENDING_INVITE, false);
|
|
|
|
db.exec();
|
|
|
|
|
2020-01-29 12:29:01 -05:00
|
|
|
auto frame = createChMemberAsyncFrame(chId, uId, false, OWNER, uName, dName, chName);
|
2019-09-06 23:43:07 -04:00
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
async(ASYNC_NEW_CH_MEMBER, PUB_IPC_WITH_FEEDBACK, frame);
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
void RemoveChannel::procIn(const QByteArray &binIn, quint8 dType)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
if (dType == TEXT)
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
auto args = parseArgs(binIn, 2);
|
|
|
|
auto chName = getParam("-ch_name", args);
|
|
|
|
|
|
|
|
quint64 chId;
|
|
|
|
|
|
|
|
retCode = INVALID_PARAMS;
|
2019-09-06 23:43:07 -04:00
|
|
|
|
|
|
|
if (chName.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The channel name (-ch_name) argument was not found or is empty.\n");
|
|
|
|
}
|
|
|
|
else if (!validChName(chName))
|
|
|
|
{
|
|
|
|
errTxt("err: Invalid channel name.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!channelExists(chName, &chId))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: Channel name '" + chName + "' does not exists.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (channelAccessLevel(rdFromBlock(userId, BLKSIZE_USER_ID), chOwnerOverride, chId) != OWNER)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: Only the channel owner can delete it.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
retCode = NO_ERRORS;
|
|
|
|
|
2019-09-06 23:43:07 -04:00
|
|
|
Query db(this);
|
|
|
|
|
|
|
|
db.setType(Query::DEL, TABLE_CHANNELS);
|
2019-11-08 22:06:09 -05:00
|
|
|
db.addCondition(COLUMN_CHANNEL_ID, chId);
|
2019-09-06 23:43:07 -04:00
|
|
|
db.exec();
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
async(ASYNC_DEL_CH, PUB_IPC_WITH_FEEDBACK, wrInt(chId, 64));
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
void RenameChannel::procIn(const QByteArray &binIn, quint8 dType)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
if (dType == TEXT)
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
auto args = parseArgs(binIn, 4);
|
|
|
|
auto chName = getParam("-ch_name", args);
|
|
|
|
auto newName = getParam("-new_name", args);
|
|
|
|
|
|
|
|
quint64 chId;
|
|
|
|
|
|
|
|
retCode = INVALID_PARAMS;
|
2019-09-06 23:43:07 -04:00
|
|
|
|
|
|
|
if (chName.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The channel name (-ch_name) argument was not found or is empty.\n");
|
|
|
|
}
|
|
|
|
else if (newName.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The new channel name (-new_name) was not found or is empty.\n");
|
|
|
|
}
|
|
|
|
else if (!validChName(chName))
|
|
|
|
{
|
|
|
|
errTxt("err: Invalid channel name.\n");
|
|
|
|
}
|
|
|
|
else if (!validChName(newName))
|
|
|
|
{
|
|
|
|
errTxt("err: Invalid new channel name. it must be between 4-32 chars long and contain no spaces.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!channelExists(chName, &chId))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: Channel name '" + chName + "' does not exists.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (channelAccessLevel(rdFromBlock(userId, BLKSIZE_USER_ID), chOwnerOverride, chId) != OWNER)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: Only the channel owner can rename it.\n");
|
|
|
|
}
|
|
|
|
else if (channelExists(newName))
|
|
|
|
{
|
|
|
|
errTxt("err: Channel name '" + newName + "' already exists.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
retCode = NO_ERRORS;
|
|
|
|
|
2019-09-06 23:43:07 -04:00
|
|
|
Query db(this);
|
|
|
|
|
|
|
|
db.setType(Query::UPDATE, TABLE_CHANNELS);
|
|
|
|
db.addColumn(COLUMN_CHANNEL_NAME, newName);
|
2019-11-08 22:06:09 -05:00
|
|
|
db.addCondition(COLUMN_CHANNEL_ID, chId);
|
2019-09-06 23:43:07 -04:00
|
|
|
db.exec();
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
QByteArray frame = wrInt(chId, 64) + nullTermTEXT(newName);
|
|
|
|
|
|
|
|
async(ASYNC_RENAME_CH, PUB_IPC_WITH_FEEDBACK, frame);
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
void SetActiveState::procIn(const QByteArray &binIn, quint8 dType)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
if (dType == TEXT)
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
auto args = parseArgs(binIn, 6);
|
|
|
|
auto chName = getParam("-ch_name", args);
|
|
|
|
auto subName = getParam("-sub_name", args);
|
|
|
|
auto state = getParam("-state", args);
|
|
|
|
|
|
|
|
quint64 chId;
|
|
|
|
quint8 subId;
|
|
|
|
|
|
|
|
retCode = INVALID_PARAMS;
|
2019-09-06 23:43:07 -04:00
|
|
|
|
|
|
|
if (chName.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The channel name (-ch_name) argument was not found or is empty.\n");
|
|
|
|
}
|
|
|
|
else if (subName.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The sub-channel name (-sub_name) was not found or is empty.\n");
|
|
|
|
}
|
|
|
|
else if (state.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The active flag state (-state) argument was not found or is empty.\n");
|
|
|
|
}
|
|
|
|
else if (!validChName(chName))
|
|
|
|
{
|
|
|
|
errTxt("err: Invalid channel name.\n");
|
|
|
|
}
|
|
|
|
else if (!validChName(subName))
|
|
|
|
{
|
|
|
|
errTxt("err: Invalid sub-channel name.\n");
|
|
|
|
}
|
|
|
|
else if (!isBool(state))
|
|
|
|
{
|
|
|
|
errTxt("err: '" + state + "' is not a valid boolean value. it must be 0 or 1.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!channelExists(chName, &chId))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: Channel name '" + chName + "' does not exists.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (channelAccessLevel(rdFromBlock(userId, BLKSIZE_USER_ID), chOwnerOverride, chId) > ADMIN)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: Access denied.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!channelSubExists(chId, subName, &subId))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: Sub-channel name '" + chName + "' does not exists.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
retCode = NO_ERRORS;
|
|
|
|
|
2019-09-06 23:43:07 -04:00
|
|
|
Query db(this);
|
|
|
|
|
|
|
|
db.setType(Query::UPDATE, TABLE_SUB_CHANNELS);
|
|
|
|
db.addColumn(COLUMN_ACTIVE_UPDATE, static_cast<bool>(state.toInt()));
|
2019-11-08 22:06:09 -05:00
|
|
|
db.addCondition(COLUMN_CHANNEL_ID, chId);
|
|
|
|
db.addCondition(COLUMN_SUB_CH_ID, subId);
|
2019-09-06 23:43:07 -04:00
|
|
|
db.exec();
|
|
|
|
|
|
|
|
if (globalActiveFlag())
|
|
|
|
{
|
|
|
|
mainTxt("warning: The host currently have the global active update flag set so setting this flag at the sub-channel level does nothing.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-08 22:06:09 -05:00
|
|
|
async(ASYNC_CH_ACT_FLAG, PUB_IPC_WITH_FEEDBACK, wrInt(chId, 64) + wrInt(subId, 8));
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
void CreateSubCh::procIn(const QByteArray &binIn, quint8 dType)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
if (dType == TEXT)
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
auto args = parseArgs(binIn, 4);
|
|
|
|
auto chName = getParam("-ch_name", args);
|
|
|
|
auto subName = getParam("-sub_name", args);
|
|
|
|
|
|
|
|
quint64 chId;
|
|
|
|
quint8 subId;
|
|
|
|
|
|
|
|
retCode = INVALID_PARAMS;
|
2019-09-06 23:43:07 -04:00
|
|
|
|
|
|
|
if (chName.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The channel name (-ch_name) argument was not found or is empty.\n");
|
|
|
|
}
|
|
|
|
else if (subName.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The sub-channel name (-sub_name) was not found or is empty.\n");
|
|
|
|
}
|
|
|
|
else if (!validChName(chName))
|
|
|
|
{
|
|
|
|
errTxt("err: Invalid channel name.\n");
|
|
|
|
}
|
|
|
|
else if (!validChName(subName))
|
|
|
|
{
|
|
|
|
errTxt("err: Invalid sub-channel name. it must be between 4-32 chars long and contain no spaces.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!channelExists(chName, &chId))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: Channel name '" + chName + "' does not exists.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (channelAccessLevel(rdFromBlock(userId, BLKSIZE_USER_ID), chOwnerOverride, chId) > ADMIN)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: Access denied.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (channelSubExists(chId, subName))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: Sub-channel name '" + subName + "' already exists.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!genSubId(chId, &subId))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: This channel has reached the maximum amount sub-channels it can have (" + QString::number(maxSubChannels()) + ").\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
retCode = NO_ERRORS;
|
|
|
|
|
2019-09-06 23:43:07 -04:00
|
|
|
Query db(this);
|
|
|
|
|
|
|
|
db.setType(Query::PUSH, TABLE_SUB_CHANNELS);
|
|
|
|
db.addColumn(COLUMN_SUB_CH_NAME, subName);
|
|
|
|
db.addColumn(COLUMN_SUB_CH_ID, subId);
|
|
|
|
db.addColumn(COLUMN_LOWEST_LEVEL, REGULAR);
|
|
|
|
db.addColumn(COLUMN_CHANNEL_ID, chId);
|
|
|
|
db.addColumn(COLUMN_ACTIVE_UPDATE, false);
|
|
|
|
db.exec();
|
|
|
|
|
2020-01-29 12:29:01 -05:00
|
|
|
auto frame = wrInt(chId, 64) + wrInt(subId, 8) + wrInt(REGULAR, 8) + wrInt(0, 8) + nullTermTEXT(subName);
|
2019-09-06 23:43:07 -04:00
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
async(ASYNC_NEW_SUB_CH, PUB_IPC_WITH_FEEDBACK, frame);
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
void RemoveSubCh::procIn(const QByteArray &binIn, quint8 dType)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
if (dType == TEXT)
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
auto args = parseArgs(binIn, 4);
|
|
|
|
auto chName = getParam("-ch_name", args);
|
|
|
|
auto subName = getParam("-sub_name", args);
|
|
|
|
|
|
|
|
quint64 chId;
|
|
|
|
quint8 subId;
|
|
|
|
|
|
|
|
retCode = INVALID_PARAMS;
|
2019-09-06 23:43:07 -04:00
|
|
|
|
|
|
|
if (chName.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The channel name (-ch_name) argument was not found or is empty.\n");
|
|
|
|
}
|
|
|
|
else if (subName.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The sub-channel name (-sub_name) was not found or is empty.\n");
|
|
|
|
}
|
|
|
|
else if (!validChName(chName))
|
|
|
|
{
|
|
|
|
errTxt("err: Invalid channel name.\n");
|
|
|
|
}
|
|
|
|
else if (!validChName(subName))
|
|
|
|
{
|
|
|
|
errTxt("err: Invalid sub-channel name.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!channelExists(chName, &chId))
|
|
|
|
{
|
|
|
|
errTxt("err: Channel name '" + chName + "' does not exists.\n");
|
|
|
|
}
|
|
|
|
else if (channelAccessLevel(rdFromBlock(userId, BLKSIZE_USER_ID), chOwnerOverride, chId) > ADMIN)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: Access denied.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!channelSubExists(chId, subName, &subId))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: Sub-channel name '" + subName + "' does not exists.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
retCode = NO_ERRORS;
|
|
|
|
|
2019-09-06 23:43:07 -04:00
|
|
|
Query db(this);
|
|
|
|
|
|
|
|
db.setType(Query::DEL, TABLE_SUB_CHANNELS);
|
2019-11-08 22:06:09 -05:00
|
|
|
db.addCondition(COLUMN_CHANNEL_ID, chId);
|
|
|
|
db.addCondition(COLUMN_SUB_CH_ID, subId);
|
2019-09-06 23:43:07 -04:00
|
|
|
db.exec();
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
async(ASYNC_RM_SUB_CH, PUB_IPC_WITH_FEEDBACK, wrInt(chId, 64) + wrInt(subId, 8));
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
void RenameSubCh::procIn(const QByteArray &binIn, quint8 dType)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
if (dType == TEXT)
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
auto args = parseArgs(binIn, 6);
|
|
|
|
auto chName = getParam("-ch_name", args);
|
|
|
|
auto subName = getParam("-sub_name", args);
|
|
|
|
auto newName = getParam("-new_name", args);
|
|
|
|
|
|
|
|
quint64 chId;
|
|
|
|
quint8 subId;
|
|
|
|
|
|
|
|
retCode = INVALID_PARAMS;
|
2019-09-06 23:43:07 -04:00
|
|
|
|
|
|
|
if (chName.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The channel name (-ch_name) argument was not found or is empty.\n");
|
|
|
|
}
|
|
|
|
else if (subName.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The sub-channel name (-sub_name) argument was not found or is empty.\n");
|
|
|
|
}
|
|
|
|
else if (newName.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The new sub-channel name (-new_name) argument was not found or is empty.\n");
|
|
|
|
}
|
|
|
|
else if (!validChName(chName))
|
|
|
|
{
|
|
|
|
errTxt("err: Invalid channel name.\n");
|
|
|
|
}
|
|
|
|
else if (!validChName(subName))
|
|
|
|
{
|
|
|
|
errTxt("err: Invalid sub-channel name.\n");
|
|
|
|
}
|
|
|
|
else if (!validChName(newName))
|
|
|
|
{
|
|
|
|
errTxt("err: Invalid new sub-channel name. it must be between 4-32 chars long and contain no spaces.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!channelExists(chName, &chId))
|
|
|
|
{
|
|
|
|
errTxt("err: Channel name '" + chName + "' does not exists.\n");
|
|
|
|
}
|
|
|
|
else if (channelAccessLevel(rdFromBlock(userId, BLKSIZE_USER_ID), chOwnerOverride, chId) > ADMIN)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: Access denied.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!channelSubExists(chId, subName, &subId))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: Sub-channel name '" + subName + "' does not exists.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
retCode = NO_ERRORS;
|
|
|
|
|
2019-09-06 23:43:07 -04:00
|
|
|
Query db(this);
|
|
|
|
|
|
|
|
db.setType(Query::UPDATE, TABLE_SUB_CHANNELS);
|
|
|
|
db.addColumn(COLUMN_SUB_CH_NAME, newName);
|
2019-11-08 22:06:09 -05:00
|
|
|
db.addCondition(COLUMN_CHANNEL_ID, chId);
|
|
|
|
db.addCondition(COLUMN_SUB_CH_ID, subId);
|
2019-09-06 23:43:07 -04:00
|
|
|
db.exec();
|
|
|
|
|
2020-01-29 12:29:01 -05:00
|
|
|
auto frame = wrInt(chId, 64) + wrInt(subId, 8) + nullTermTEXT(newName);
|
2019-11-08 22:06:09 -05:00
|
|
|
|
|
|
|
async(ASYNC_RENAME_SUB_CH, PUB_IPC_WITH_FEEDBACK, frame);
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
void InviteToCh::procIn(const QByteArray &binIn, quint8 dType)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
if (dType == TEXT)
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
auto args = parseArgs(binIn, 4);
|
|
|
|
auto chName = getParam("-ch_name", args);
|
|
|
|
auto uName = getParam("-user", args);
|
|
|
|
|
|
|
|
QByteArray uId;
|
|
|
|
quint64 chId;
|
|
|
|
|
|
|
|
retCode = INVALID_PARAMS;
|
2019-09-06 23:43:07 -04:00
|
|
|
|
|
|
|
if (chName.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The channel name (-ch_name) argument was not found or is empty.\n");
|
|
|
|
}
|
|
|
|
else if (uName.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The user name (-user) argument was not found or is empty.\n");
|
|
|
|
}
|
|
|
|
else if (!validChName(chName))
|
|
|
|
{
|
|
|
|
errTxt("err: Invalid channel name.\n");
|
|
|
|
}
|
|
|
|
else if (!validUserName(uName))
|
|
|
|
{
|
|
|
|
errTxt("err: Invalid user name.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!channelExists(chName, &chId))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: Channel name '" + chName + "' does not exists.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!userExists(uName, &uId))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: User name '" + uName + "' does not exists.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (channelAccessLevel(rdFromBlock(userId, BLKSIZE_USER_ID), chOwnerOverride, chId) > OFFICER)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: Access denied.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (inviteExists(uId, chId))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: User name '" + uName + "' already has an invitation to channel '" + chName + ".'\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (channelAccessLevel(uId, chId) < PUBLIC)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: User name '" + uName + "' is already a member of the requested channel '" + chName + ".'\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
retCode = NO_ERRORS;
|
|
|
|
|
2019-09-06 23:43:07 -04:00
|
|
|
Query db(this);
|
|
|
|
|
|
|
|
db.setType(Query::PUSH, TABLE_CH_MEMBERS);
|
2019-11-08 22:06:09 -05:00
|
|
|
db.addColumn(COLUMN_USER_ID, uId);
|
|
|
|
db.addColumn(COLUMN_CHANNEL_ID, chId);
|
2019-09-06 23:43:07 -04:00
|
|
|
db.addColumn(COLUMN_PENDING_INVITE, true);
|
|
|
|
db.addColumn(COLUMN_ACCESS_LEVEL, REGULAR);
|
|
|
|
db.exec();
|
|
|
|
|
2020-01-29 12:29:01 -05:00
|
|
|
auto frame = createChMemberAsyncFrame(chId, uId, true, REGULAR, uName, getDispName(uId), chName);
|
2019-11-08 22:06:09 -05:00
|
|
|
|
|
|
|
async(ASYNC_INVITED_TO_CH, PUB_IPC_WITH_FEEDBACK, frame);
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
void DeclineChInvite::procIn(const QByteArray &binIn, quint8 dType)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
if (dType == TEXT)
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
auto args = parseArgs(binIn, 2);
|
|
|
|
auto chName = getParam("-ch_name", args);
|
|
|
|
|
|
|
|
quint64 chId;
|
|
|
|
|
|
|
|
retCode = INVALID_PARAMS;
|
2019-09-06 23:43:07 -04:00
|
|
|
|
|
|
|
if (chName.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The channel name (-ch_name) argument was not found or is empty.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!channelExists(chName, &chId))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: Channel name '" + chName + "' does not exists.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!inviteExists(rdFromBlock(userId, BLKSIZE_USER_ID), chId))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: You don't currently have an invitation to channel '" + chName + ".'\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
retCode = NO_ERRORS;
|
|
|
|
|
2019-09-06 23:43:07 -04:00
|
|
|
Query db(this);
|
|
|
|
|
|
|
|
db.setType(Query::DEL, TABLE_CH_MEMBERS);
|
2019-11-08 22:06:09 -05:00
|
|
|
db.addCondition(COLUMN_CHANNEL_ID, chId);
|
|
|
|
db.addCondition(COLUMN_USER_ID, rdFromBlock(userId, BLKSIZE_USER_ID));
|
2019-09-06 23:43:07 -04:00
|
|
|
db.exec();
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
async(ASYNC_RM_CH_MEMBER, PUB_IPC_WITH_FEEDBACK, wrInt(chId, 64) + rdFromBlock(userId, BLKSIZE_USER_ID));
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
void AcceptChInvite::procIn(const QByteArray &binIn, quint8 dType)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
if (dType == TEXT)
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
auto args = parseArgs(binIn, 2);
|
|
|
|
auto chName = getParam("-ch_name", args);
|
|
|
|
|
|
|
|
quint64 chId;
|
|
|
|
|
|
|
|
retCode = INVALID_PARAMS;
|
2019-09-06 23:43:07 -04:00
|
|
|
|
|
|
|
if (chName.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The channel name (-ch_name) argument was not found or is empty.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!channelExists(chName, &chId))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: Channel name '" + chName + "' does not exists.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!inviteExists(rdFromBlock(userId, BLKSIZE_USER_ID), chId))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: You don't currently have an invitation to channel '" + chName + ".'\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
retCode = NO_ERRORS;
|
|
|
|
|
2019-09-06 23:43:07 -04:00
|
|
|
Query db(this);
|
|
|
|
|
|
|
|
db.setType(Query::UPDATE, TABLE_CH_MEMBERS);
|
|
|
|
db.addColumn(COLUMN_PENDING_INVITE, false);
|
2019-11-08 22:06:09 -05:00
|
|
|
db.addCondition(COLUMN_CHANNEL_ID, chId);
|
|
|
|
db.addCondition(COLUMN_USER_ID, rdFromBlock(userId, BLKSIZE_USER_ID));
|
2019-09-06 23:43:07 -04:00
|
|
|
db.exec();
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
async(ASYNC_INVITE_ACCEPTED, PUB_IPC_WITH_FEEDBACK, wrInt(chId, 64) + rdFromBlock(userId, BLKSIZE_USER_ID));
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
bool RemoveChMember::allowMemberDel(const QByteArray &uId, quint64 chId)
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
auto myId = rdFromBlock(userId, BLKSIZE_USER_ID);
|
|
|
|
auto ret = false;
|
|
|
|
auto leaving = (uId == myId);
|
|
|
|
auto targetLevel = channelAccessLevel(uId, chId);
|
|
|
|
auto myLevel = channelAccessLevel(myId, chOwnerOverride, BLKSIZE_USER_ID);
|
2019-11-08 22:06:09 -05:00
|
|
|
|
|
|
|
if (leaving && (myLevel == OWNER))
|
|
|
|
{
|
|
|
|
errTxt("err: The channel owner cannot leave the channel. please assign a new owner before doing so.\n");
|
|
|
|
}
|
|
|
|
else if (targetLevel == PUBLIC)
|
|
|
|
{
|
|
|
|
errTxt("err: The target user is not a member of the channel.\n");
|
|
|
|
}
|
|
|
|
else if (leaving)
|
|
|
|
{
|
|
|
|
ret = myLevel != PUBLIC;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = myLevel < targetLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveChMember::procIn(const QByteArray &binIn, quint8 dType)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
if (dType == TEXT)
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
auto args = parseArgs(binIn, 4);
|
|
|
|
auto chName = getParam("-ch_name", args);
|
|
|
|
auto uName = getParam("-user", args);
|
|
|
|
|
|
|
|
QByteArray uId;
|
|
|
|
quint64 chId;
|
|
|
|
|
|
|
|
retCode = INVALID_PARAMS;
|
2019-09-06 23:43:07 -04:00
|
|
|
|
|
|
|
if (chName.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The channel name (-ch_name) argument was not found or is empty.\n");
|
|
|
|
}
|
|
|
|
else if (uName.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The user name (-user) argument was not found or is empty.\n");
|
|
|
|
}
|
|
|
|
else if (!validChName(chName))
|
|
|
|
{
|
|
|
|
errTxt("err: Invalid channel name.\n");
|
|
|
|
}
|
|
|
|
else if (!validUserName(uName))
|
|
|
|
{
|
|
|
|
errTxt("err: Invalid user name.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!channelExists(chName, &chId))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: Channel name '" + chName + "' does not exists.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!userExists(uName, &uId))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: User name '" + uName + "' does not exists.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!allowMemberDel(uId, chId))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: Access denied.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
retCode = NO_ERRORS;
|
|
|
|
|
2019-09-06 23:43:07 -04:00
|
|
|
Query db(this);
|
|
|
|
|
|
|
|
db.setType(Query::DEL, TABLE_CH_MEMBERS);
|
2019-11-08 22:06:09 -05:00
|
|
|
db.addCondition(COLUMN_CHANNEL_ID, chId);
|
|
|
|
db.addCondition(COLUMN_USER_ID, uId);
|
2019-09-06 23:43:07 -04:00
|
|
|
db.exec();
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
async(ASYNC_RM_CH_MEMBER, PUB_IPC_WITH_FEEDBACK, wrInt(chId, 64) + uId);
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
bool SetMemberLevel::allowLevelChange(const QByteArray &uId, int newLevel, quint64 chId)
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
auto targetLevel = channelAccessLevel(uId, chId);
|
|
|
|
auto myLevel = channelAccessLevel(rdFromBlock(userId, BLKSIZE_USER_ID), chOwnerOverride, BLKSIZE_USER_ID);
|
2019-11-08 22:06:09 -05:00
|
|
|
|
|
|
|
return (newLevel >= myLevel) && (targetLevel > myLevel);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetMemberLevel::procIn(const QByteArray &binIn, uchar dType)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
if (dType == TEXT)
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
auto args = parseArgs(binIn, 6);
|
|
|
|
auto chName = getParam("-ch_name", args);
|
|
|
|
auto uName = getParam("-user", args);
|
|
|
|
auto level = getParam("-level", args);
|
|
|
|
|
|
|
|
quint64 chId;
|
|
|
|
QByteArray uId;
|
|
|
|
|
|
|
|
retCode = INVALID_PARAMS;
|
2019-09-06 23:43:07 -04:00
|
|
|
|
|
|
|
if (chName.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The channel name (-ch_name) argument was not found or is empty.\n");
|
|
|
|
}
|
|
|
|
else if (uName.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The user name (-user) argument was not found or is empty.\n");
|
|
|
|
}
|
|
|
|
else if (level.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The privilege level (-level) argument was not found or is empty.\n");
|
|
|
|
}
|
|
|
|
else if (!validChName(chName))
|
|
|
|
{
|
|
|
|
errTxt("err: Invalid channel name.\n");
|
|
|
|
}
|
|
|
|
else if (!validUserName(uName))
|
|
|
|
{
|
|
|
|
errTxt("err: Invalid user name.\n");
|
|
|
|
}
|
|
|
|
else if (!validLevel(level, false))
|
|
|
|
{
|
|
|
|
errTxt("err: Invalid privilege level. it must be an integer between 1-4.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!channelExists(chName, &chId))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: Channel name '" + chName + "' does not exists.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!userExists(uName, &uId))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: User name '" + uName + "' does not exists.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!allowLevelChange(uId, level.toInt(), chId))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: Access denied.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
retCode = NO_ERRORS;
|
|
|
|
|
2019-09-06 23:43:07 -04:00
|
|
|
Query db(this);
|
|
|
|
|
|
|
|
db.setType(Query::PULL, TABLE_CH_MEMBERS);
|
2019-11-08 22:06:09 -05:00
|
|
|
db.addColumn(COLUMN_USER_ID);
|
2019-09-06 23:43:07 -04:00
|
|
|
db.addCondition(COLUMN_ACCESS_LEVEL, OWNER);
|
2019-11-08 22:06:09 -05:00
|
|
|
db.addCondition(COLUMN_CHANNEL_ID, chId);
|
2019-09-06 23:43:07 -04:00
|
|
|
db.exec();
|
|
|
|
|
2020-01-29 12:29:01 -05:00
|
|
|
auto newLevel = level.toInt();
|
|
|
|
auto owner = db.getData(COLUMN_USER_ID).toByteArray();
|
2019-09-06 23:43:07 -04:00
|
|
|
|
|
|
|
db.setType(Query::UPDATE, TABLE_CH_MEMBERS);
|
2019-11-08 22:06:09 -05:00
|
|
|
db.addColumn(COLUMN_ACCESS_LEVEL, newLevel);
|
|
|
|
db.addCondition(COLUMN_CHANNEL_ID, chId);
|
|
|
|
db.addCondition(COLUMN_USER_ID, uId);
|
2019-09-06 23:43:07 -04:00
|
|
|
db.exec();
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
async(ASYNC_MEM_LEVEL_CHANGED, PUB_IPC_WITH_FEEDBACK, wrInt(chId, 64) + uId + wrInt(newLevel, 8));
|
2019-09-06 23:43:07 -04:00
|
|
|
|
|
|
|
if (level.toInt() == OWNER)
|
|
|
|
{
|
|
|
|
db.setType(Query::UPDATE, TABLE_CH_MEMBERS);
|
|
|
|
db.addColumn(COLUMN_ACCESS_LEVEL, ADMIN);
|
2019-11-08 22:06:09 -05:00
|
|
|
db.addCondition(COLUMN_CHANNEL_ID, chId);
|
|
|
|
db.addCondition(COLUMN_USER_ID, owner);
|
2019-09-06 23:43:07 -04:00
|
|
|
db.exec();
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
async(ASYNC_MEM_LEVEL_CHANGED, PUB_IPC_WITH_FEEDBACK, wrInt(chId, 64) + owner + wrInt(ADMIN, 8));
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
void SetSubAcessLevel::procIn(const QByteArray &binIn, quint8 dType)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
if (dType == TEXT)
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
auto args = parseArgs(binIn, 6);
|
|
|
|
auto chName = getParam("-ch_name", args);
|
|
|
|
auto subName = getParam("-sub_name", args);
|
|
|
|
auto level = getParam("-level", args);
|
|
|
|
|
|
|
|
quint64 chId;
|
|
|
|
quint8 subId;
|
|
|
|
|
|
|
|
retCode = INVALID_PARAMS;
|
2019-09-06 23:43:07 -04:00
|
|
|
|
|
|
|
if (chName.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The channel name (-ch_name) argument was not found or is empty.\n");
|
|
|
|
}
|
|
|
|
else if (subName.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The sub-channel name (-sub_name) argument was not found or is empty.\n");
|
|
|
|
}
|
|
|
|
else if (level.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The privilege level (-level) argument was not found or is empty.\n");
|
|
|
|
}
|
|
|
|
else if (!validChName(chName))
|
|
|
|
{
|
|
|
|
errTxt("err: Invalid channel name.\n");
|
|
|
|
}
|
|
|
|
else if (!validChName(subName))
|
|
|
|
{
|
|
|
|
errTxt("err: Invalid sub-channel name.\n");
|
|
|
|
}
|
|
|
|
else if (!validLevel(level, true))
|
|
|
|
{
|
|
|
|
errTxt("err: Invalid privilege level. it must be an integer between 1-5.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!channelExists(chName, &chId))
|
|
|
|
{
|
|
|
|
errTxt("err: Channel name '" + chName + "' does not exists.\n");
|
|
|
|
}
|
|
|
|
else if (channelAccessLevel(rdFromBlock(userId, BLKSIZE_USER_ID), chOwnerOverride, chId) > ADMIN)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: Access denied.\n");
|
|
|
|
}
|
2019-11-08 22:06:09 -05:00
|
|
|
else if (!channelSubExists(chId, subName, &subId))
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
errTxt("err: Sub-channel name '" + subName + "' does not exists.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
retCode = NO_ERRORS;
|
|
|
|
|
2019-09-06 23:43:07 -04:00
|
|
|
Query db(this);
|
|
|
|
|
|
|
|
db.setType(Query::UPDATE, TABLE_SUB_CHANNELS);
|
|
|
|
db.addColumn(COLUMN_LOWEST_LEVEL, level.toInt());
|
2019-11-08 22:06:09 -05:00
|
|
|
db.addCondition(COLUMN_SUB_CH_ID, subId);
|
|
|
|
db.addCondition(COLUMN_CHANNEL_ID, chId);
|
2019-09-06 23:43:07 -04:00
|
|
|
db.exec();
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
async(ASYNC_SUB_CH_LEVEL_CHG, PUB_IPC_WITH_FEEDBACK, wrInt(chId, 64) + wrInt(subId, 8) + wrInt(level.toInt(), 8));
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
void OwnerOverride::procIn(const QByteArray &binIn, quint8 dType)
|
2019-09-06 23:43:07 -04:00
|
|
|
{
|
|
|
|
if (dType == TEXT)
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
auto args = parseArgs(binIn, 2);
|
|
|
|
auto state = getParam("-state", args);
|
|
|
|
|
|
|
|
retCode = INVALID_PARAMS;
|
2019-09-06 23:43:07 -04:00
|
|
|
|
|
|
|
if (state.isEmpty())
|
|
|
|
{
|
|
|
|
errTxt("err: The flag state (-state) argument was not found or is empty.\n");
|
|
|
|
}
|
|
|
|
else if (!isBool(state))
|
|
|
|
{
|
|
|
|
errTxt("err: Invalid bool value for -state, it must be 1 or 0.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-29 12:29:01 -05:00
|
|
|
retCode = NO_ERRORS;
|
|
|
|
|
2019-11-08 22:06:09 -05:00
|
|
|
wr8BitToBlock(static_cast<quint8>(state.toUInt()), chOwnerOverride);
|
2019-09-06 23:43:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|