Skip to content

Commit

Permalink
Made it a buggy mess because of encryption
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePinkUnicorn6 committed Nov 10, 2023
1 parent e5df9ba commit 8491f49
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Classes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Message
public string UserName {get; set;}
public Double Time {get; set;}
public string Text {get; set;}
public byte[] IV {get; set;}
public string IV {get; set;}
}
class Guild
{
Expand Down
18 changes: 7 additions & 11 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ PRIMARY KEY('ChannelID')
'MessageID' CHAR(36),
'UserID' CHAR(36),
'MessageText' TEXT,
'IV' BLOB,
'IV' CHAR(32),
FOREIGN KEY('UserID') REFERENCES 'tblUsers'('UserID'),
FOREIGN KEY('ChannelID') REFERENCES 'tblChannels'('ChannelID'),
PRIMARY KEY('MessageID')
Expand Down Expand Up @@ -157,7 +157,7 @@ FOREIGN KEY('UserID') REFERENCES 'tblUsers'('UserID')
'GuildName' VARCHAR(36),
'OwnerID' CHAR(36),
'GuildDesc' VARCHAR(100),
'GuildKey' BLOB,
'GuildKey' CHAR(32),
PRIMARY KEY('GuildID'),
FOREIGN KEY('OwnerID') REFERENCES 'tblUsers'('UserID')
);";
Expand Down Expand Up @@ -270,7 +270,6 @@ ELSE false
{
while (reader.Read()) // Loops through each message and adds it to the message list
{
byte[]? iv = reader[5] == null ? null : (byte[])reader[5];
Message responseRow = new Message
{
UserID = reader.GetString(0),
Expand All @@ -279,7 +278,7 @@ ELSE false
ChannelID = channelID,
Time = reader.GetDouble(3),
Text = reader.GetString(4),
IV = iv
IV = reader.GetString(5),
};
messages.Add(responseRow);
}
Expand Down Expand Up @@ -318,6 +317,7 @@ static void apiSendMessage(HttpListenerContext context)
ID = Guid.NewGuid().ToString(),
ChannelID = context.Request.QueryString["channelID"],
Text = context.Request.QueryString["messageText"],
IV = context.Request.QueryString["IV"],
};
string? token = context.Request.QueryString["token"];
int code;
Expand All @@ -343,12 +343,13 @@ static void apiSendMessage(HttpListenerContext context)
using (var cmd = new SQLiteCommand(con))
{
con.Open();
cmd.CommandText = @"INSERT INTO tblMessages (ChannelID, TimeSent, MessageID, UserID, MessageText)
VALUES (@ChannelID, unixepoch('subsec'), @MessageID, @UserID, @MessageText);";
cmd.CommandText = @"INSERT INTO tblMessages (ChannelID, TimeSent, MessageID, UserID, MessageText, IV)
VALUES (@ChannelID, unixepoch('subsec'), @MessageID, @UserID, @MessageText, @IV);";
cmd.Parameters.AddWithValue("ChannelID", message.ChannelID);
cmd.Parameters.AddWithValue("MessageID", message.ID);
cmd.Parameters.AddWithValue("UserID", message.UserID);
cmd.Parameters.AddWithValue("MessageText", message.Text);
cmd.Parameters.AddWithValue("IV", message.IV);
cmd.ExecuteNonQuery();
cmd.CommandText = @"SELECT Username
FROM tblUsers
Expand Down Expand Up @@ -856,17 +857,12 @@ static void apiListGuilds(HttpListenerContext context) // Returns all guilds the
string guildsJson = "[{";
for (int i = 0; i < dbResponse.Count; i++) // Build the json response string
{
string guildKeyHex;
if (dbResponse[i].GuildKey == null){ guildKeyHex = null; }
else { guildKeyHex = Convert.ToBase64String(dbResponse[i].GuildKey); };

if (i == 0 || dbResponse[i].GuildID != dbResponse[i - 1].GuildID) // If the guildID is different from the previous iteration, start a new guild item in the JSON array.
{
guildsJson += "\"guildName\": \"" + dbResponse[i].GuildName + "\", ";
guildsJson += "\"guildID\": \"" + dbResponse[i].GuildID + "\", ";
guildsJson += "\"guildOwnerID\": \"" + dbResponse[i].GuildOwnerID + "\", ";
guildsJson += "\"guildDesc\": \"" + dbResponse[i].GuildDesc + "\", ";
guildsJson += "\"guildKey\": \"" + guildKeyHex + "\", ";
guildsJson += "\"channels\": [";
}
guildsJson += "{"; // Build channel array in guilds json array.
Expand Down

0 comments on commit 8491f49

Please sign in to comment.