Skip to content

Commit

Permalink
complete key transeferal
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePinkUnicorn6 committed Dec 19, 2023
1 parent 74fa355 commit d94b17b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Classes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Message
public string ChannelID {get; set;}
public string UserID {get; set;}
public string UserName {get; set;}
public Double Time {get; set;}
public double Time {get; set;}
public string Text {get; set;}
public string IV {get; set;}
}
Expand Down
27 changes: 22 additions & 5 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1231,29 +1231,45 @@ FROM tblKeyRequests
bool alreadyRequested = (Int64)cmd.ExecuteScalar() > 0;
if (alreadyRequested)
{
cmd.CommandText = @"SELECT EncryptedKey, ResponderID
FROM tblKeyRequests
WHERE RequesterID = @UserID
AND GuildID = @GuildID;";
cmd.CommandText =
@"SELECT EncryptedKey, ResponderID
FROM tblKeyRequests
WHERE RequesterID = @UserID
AND GuildID = @GuildID
AND EncryptedKey IS NOT NULL;";
cmd.Parameters.AddWithValue("UserID", userID);
cmd.Parameters.AddWithValue("GuildID", guildID);
bool keysReturned;
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
if (!reader.Read())
if (reader.Read())
{
var keys = new {
key = reader.GetString(0),
userID = reader.GetString(1),
};
responseMessage = JsonConvert.SerializeObject(keys);
code = 200;
keysReturned = true;
}
else // If no other users have responded the the request will return nothing
{
responseMessage = null;
code = 202;
keysReturned = false;
}
}
if (keysReturned)
{
// After successfully returning the key, delete the request from the db
// so if the user needs to request it again there are no problems.
cmd.CommandText = @"DELETE FROM tblKeyRequests
WHERE RequesterID = @UserID
AND GuildID = @GuildID;";
cmd.Parameters.AddWithValue("UserID", userID);
cmd.Parameters.AddWithValue("GuildID", guildID);
cmd.ExecuteNonQuery();
}
}
else // If the client has not previously requested details for that guild, store the request.
{
Expand Down Expand Up @@ -1372,6 +1388,7 @@ static void apiSubmitKey(HttpListenerContext context)
cmd.Parameters.AddWithValue("Key", keyCypherText);
cmd.Parameters.AddWithValue("RequesterID", requesterID);
cmd.Parameters.AddWithValue("GuildID", guildID);
cmd.ExecuteNonQuery();
}
responseMessage = null;
code = 200;
Expand Down

0 comments on commit d94b17b

Please sign in to comment.