aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
m---------depends/odhtdb0
-rw-r--r--include/Channel.hpp3
-rw-r--r--src/Channel.cpp15
-rw-r--r--src/main.cpp63
4 files changed, 9 insertions, 72 deletions
diff --git a/depends/odhtdb b/depends/odhtdb
-Subproject 22abf1aa83b2668f918556491a55947be798f89
+Subproject 109108c896f1ada76121330ab01602072f32dd8
diff --git a/include/Channel.hpp b/include/Channel.hpp
index 443a722..58bbcc3 100644
--- a/include/Channel.hpp
+++ b/include/Channel.hpp
@@ -28,8 +28,6 @@ namespace dchat
NICKNAME_CHANGE,
CHANGE_AVATAR,
CHANGE_CHANNEL_NAME,
-
- ADD_DISCORD_MESSAGE
};
class Channel
@@ -56,7 +54,6 @@ namespace dchat
void addLocalDiscordMessage(const std::string &discordUserName, u64 discordUserId, const std::string &msg, User *owner, u64 timestampSeconds, const odhtdb::Hash &id);
void addSystemMessage(const std::string &msg, bool plainText = true);
void addMessage(const std::string &msg);
- void addDiscordMessage(const std::string &discordUserName, u64 discordUserId, const std::string &msg);
void deleteLocalMessage(const odhtdb::Hash &id, const odhtdb::Signature::PublicKey &requestedByUser);
void deleteMessage(const odhtdb::Hash &id, const odhtdb::Signature::PublicKey &requestedByUser);
diff --git a/src/Channel.cpp b/src/Channel.cpp
index 6107a22..9164f9d 100644
--- a/src/Channel.cpp
+++ b/src/Channel.cpp
@@ -207,21 +207,6 @@ namespace dchat
else
addLocalMessage(msg, localUser, 0, odhtdb::Hash());
}
-
- void Channel::addDiscordMessage(const string &discordUserName, u64 discordUserId, const string &msg)
- {
- assert(database && localUser->type == User::Type::ONLINE_LOCAL_USER);
- auto onlineLocalUser = static_cast<OnlineLocalUser*>(localUser);
-
- sibs::SafeSerializer serializer;
- serializer.add(ChannelDataType::ADD_DISCORD_MESSAGE);
- serializer.add(discordUserId);
- serializer.add((u8)discordUserName.size());
- serializer.add((const u8*)discordUserName.data(), discordUserName.size());
- serializer.add((const u8*)msg.data(), msg.size());
-
- database->addData(databaseNodeInfo, onlineLocalUser->keyPair, odhtdb::DataView(serializer.getBuffer().data(), serializer.getBuffer().size()));
- }
void Channel::deleteLocalMessage(const odhtdb::Hash &id, const odhtdb::Signature::PublicKey &requestedByUser)
{
diff --git a/src/main.cpp b/src/main.cpp
index e60f77c..77b1d5c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -102,7 +102,7 @@ static void channelChangeChannelName(Channel *channel, const StringView data, co
int userPermissionLevel = channel->getUserLowestPermissionLevel(user);
if(userPermissionLevel != odhtdb::PERMISSION_LEVEL_ADMIN)
{
- fprintf(stderr, "Channel change name: attempted by user %s who is not an admin\n", user->getName().c_str());
+ fprintf(stderr, "Channel change name: attempted by user %s who is not an admin (permission level: %d)\n", user->getName().c_str(), userPermissionLevel);
return;
}
@@ -118,40 +118,6 @@ static void channelChangeChannelName(Channel *channel, const StringView data, co
// We dont care if there is more data to read (malicious packet), we already got all the data we need
}
-static void channelAddDiscordMessage(Channel *channel, const StringView data, const odhtdb::Signature::PublicKey &userPublicKey, u64 timestamp, const odhtdb::Hash &requestHash)
-{
- auto bridgeOwner = channel->getUserByPublicKey(userPublicKey);
- if(!bridgeOwner)
- {
- fprintf(stderr, "Channel add discord message: user with public key %s not found in channel %s\n", userPublicKey.toString().c_str(), channel->getName().c_str());
- return;
- }
-
- int userPermissionLevel = channel->getUserLowestPermissionLevel(bridgeOwner);
- if(userPermissionLevel != odhtdb::PERMISSION_LEVEL_ADMIN)
- {
- fprintf(stderr, "Channel add discord message: attempted by user %s who is not an admin\n", bridgeOwner->getName().c_str());
- return;
- }
-
- sibs::SafeDeserializer deserializer((const u8*)data.data, data.size);
- u64 discordUserId = deserializer.extract<u64>();
- u8 discordNameLength = deserializer.extract<u8>();
- if(discordNameLength == 0) return;
-
- string discordUserName;
- discordUserName.resize(discordNameLength);
- deserializer.extract((u8*)&discordUserName[0], discordNameLength);
-
- usize msgSize = deserializer.getSize();
- if(msgSize == 0) return;
- string msg(deserializer.getBuffer(), deserializer.getBuffer() + deserializer.getSize());
-
- auto timestampSeconds = ntp::NtpTimestamp::fromCombined(timestamp).seconds;
- channel->addLocalDiscordMessage(discordUserName, discordUserId, msg, bridgeOwner, timestampSeconds, requestHash);
- // We dont care if there is more data to read (malicious packet), we already got all the data we need
-}
-
static void channelAddStoredMessage(Channel *channel, const odhtdb::Hash &requestHash, const odhtdb::Signature::PublicKey &creatorPublicKey, const StringView decryptedObject, u64 timestamp, bool loadedFromCache)
{
User *user = channel->getUserByPublicKey(creatorPublicKey);
@@ -232,18 +198,6 @@ static void channelAddStoredMessage(Channel *channel, const odhtdb::Hash &reques
}
break;
}
- case ChannelDataType::ADD_DISCORD_MESSAGE:
- {
- try
- {
- channelAddDiscordMessage(channel, decryptedData, creatorPublicKey, timestamp, requestHash);
- }
- catch(sibs::DeserializeException &e)
- {
- fprintf(stderr, "Failed to deserialize channel add discord message\n");
- }
- break;
- }
default:
fprintf(stderr, "Got unexpected channel data type: %u\n", channelDataType);
break;
@@ -300,7 +254,7 @@ int main(int argc, char **argv)
using LocalUserMessageCallback = function<void(const odhtdb::DatabaseAddNodeRequest &request)>;
LocalUserMessageCallback onMessageByLocalUser = nullptr;
- callbackFuncs.createNodeCallbackFunc = [&waitingToJoinChannels, database, &channels, &channelMessageMutex, &waitingToJoin, &localNodeUsers, &lastFocusedTimer](const odhtdb::DatabaseCreateNodeRequest &request)
+ callbackFuncs.createNodeCallbackFunc = [&waitingToJoinChannels, &database, &channels, &channelMessageMutex, &waitingToJoin, &localNodeUsers, &lastFocusedTimer](const odhtdb::DatabaseCreateNodeRequest &request)
{
lock_guard<recursive_mutex> lock(channelMessageMutex);
printf("Create node callback func %s\n", request.nodeHash->toString().c_str());
@@ -318,6 +272,7 @@ int main(int argc, char **argv)
memcpy(databaseNodeHash->getData(), request.nodeHash->getData(), odhtdb::HASH_BYTE_SIZE);
odhtdb::DatabaseNode databaseNode(nodeUserData->second.nodeEncryptionKey, databaseNodeHash);
Channel *channel = new Channel("NoChannelName", databaseNode, localUser, database);
+ printf("database: %llu\n", database.get());
ChannelSidePanel::addChannel(channel);
channels.push_back(channel);
Channel::setCurrent(channel);
@@ -407,7 +362,7 @@ int main(int argc, char **argv)
};
// Login to account
- Command::add("login", [&localNodeUsers, database, &channels, &loggedIn, &channelMessageMutex, &currentUsername, &currentPassword](const vector<string> &args)
+ Command::add("login", [&localNodeUsers, &database, &channels, &loggedIn, &channelMessageMutex, &currentUsername, &currentPassword](const vector<string> &args)
{
lock_guard<recursive_mutex> lock(channelMessageMutex);
if(args.size() != 2)
@@ -445,7 +400,7 @@ int main(int argc, char **argv)
});
// Register account
- Command::add("register", [&localNodeUsers, database, &channels, &loggedIn, &channelMessageMutex, &currentUsername, &currentPassword](const vector<string> &args)
+ Command::add("register", [&localNodeUsers, &database, &channels, &loggedIn, &channelMessageMutex, &currentUsername, &currentPassword](const vector<string> &args)
{
lock_guard<recursive_mutex> lock(channelMessageMutex);
if(args.size() != 2)
@@ -482,7 +437,7 @@ int main(int argc, char **argv)
// TODO: Use database->addData to change channel name
// Create channel
- Command::add("cc", [database, &channels, &channelMessageMutex, &loggedIn, &localNodeUsers, &currentUsername, &currentPassword, &lastFocusedTimer, addSystemMessage](const vector<string> &args)
+ Command::add("cc", [&database, &channels, &channelMessageMutex, &loggedIn, &localNodeUsers, &currentUsername, &currentPassword, &lastFocusedTimer, addSystemMessage](const vector<string> &args)
{
lock_guard<recursive_mutex> lock(channelMessageMutex);
if(args.size() != 1)
@@ -515,7 +470,7 @@ int main(int argc, char **argv)
});
// Create invite key
- Command::add("invite", [&channelMessageMutex, &offlineChannel, database, addSystemMessage](const vector<string> &args)
+ Command::add("invite", [&channelMessageMutex, &offlineChannel, &database, addSystemMessage](const vector<string> &args)
{
lock_guard<recursive_mutex> lock(channelMessageMutex);
if(args.size() != 0)
@@ -599,7 +554,7 @@ int main(int argc, char **argv)
});
// Join channel using invite key
- Command::add("jc", [&loggedIn, database, &localNodeUsers, &channelMessageMutex, &waitingToJoin, &waitingToJoinChannels, &currentUsername, &currentPassword](const vector<string> &args)
+ Command::add("jc", [&loggedIn, &database, &localNodeUsers, &channelMessageMutex, &waitingToJoin, &waitingToJoinChannels, &currentUsername, &currentPassword](const vector<string> &args)
{
lock_guard<recursive_mutex> lock(channelMessageMutex);
if(args.size() != 1)
@@ -651,7 +606,7 @@ int main(int argc, char **argv)
keySerializer.add((const u8*)encryptionKeyBinRaw.data(), odhtdb::ENCRYPTION_KEY_BYTE_SIZE);
odhtdb::InfoHash key = odhtdb::Database::getInfoHash(keySerializer.getBuffer().data(), keySerializer.getBuffer().size());
database->sendCustomMessage(key, serializer.getBuffer().data(), serializer.getBuffer().size(),
- [database, nodeHash, encryptionKey, &waitingToJoinChannels, &channelMessageMutex, keyPair, &currentUsername, &currentPassword, &localNodeUsers]
+ [&database, nodeHash, encryptionKey, &waitingToJoinChannels, &channelMessageMutex, keyPair, &currentUsername, &currentPassword, &localNodeUsers]
(bool gotResponse, const void *data, usize size)
{
if(!gotResponse)