-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ allow replacing simulations and genomes
+ new labels also show up for replaced items
- Loading branch information
Showing
14 changed files
with
325 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
require './helpers.php'; | ||
require './hooks.php'; | ||
|
||
function closeAndExit($db) { | ||
echo json_encode(["result"=>false]); | ||
$db->close(); | ||
exit; | ||
} | ||
|
||
|
||
$db = connectToDB(); | ||
$db->begin_transaction(); | ||
|
||
$userName = $_POST["userName"]; | ||
$pw = $_POST["password"]; | ||
|
||
if (!checkPw($db, $userName, $pw)) { | ||
echo json_encode(["result"=>false]); | ||
$db->close(); | ||
exit; | ||
} | ||
|
||
$obj = $db->query("SELECT u.ID as id FROM user u WHERE u.NAME='".addslashes($userName)."'")->fetch_object(); | ||
if (!$obj) { | ||
echo json_encode(["result"=>false]); | ||
$db->close(); | ||
exit; | ||
} | ||
|
||
$success = false; | ||
$particles = (int)$_POST['particles']; | ||
$version = $_POST['version']; | ||
$content = $_POST['content']; | ||
$settings = $_POST['settings']; | ||
$simId = $_POST['simId']; | ||
$size = strlen($content); | ||
$type = array_key_exists('type', $_POST) ? $_POST['type'] : 0; | ||
$workspace = array_key_exists('workspace', $_POST) ? $_POST['workspace'] : 0; | ||
$statistics = array_key_exists('statistics', $_POST) ? $_POST['statistics'] : ""; | ||
|
||
if ($userName != 'alien-project' && $workspace == 1) { | ||
closeAndExit($db); | ||
} | ||
|
||
$stmt = $db->prepare("UPDATE simulation SET PARTICLES=?, VERSION=?, CONTENT=?, WIDTH=?, HEIGHT=?, SETTINGS=?, SIZE=?, STATISTICS=?, CONTENT2=?, CONTENT3=?, CONTENT4=?, CONTENT5=?, CONTENT6=? WHERE ID=?"); | ||
if (!$stmt) { | ||
closeAndExit($db); | ||
} | ||
|
||
$emptyString = ''; | ||
$stmt->bind_param("issiisissssssi", $particles, $version, $content, $width, $height, $settings, $size, $statistics, $emptyString, $emptyString, $emptyString, $emptyString, $emptyString, $simId); | ||
|
||
if (!$stmt->execute()) { | ||
closeAndExit($db); | ||
} | ||
|
||
// create Discord message | ||
//if ($workspace != PRIVATE_WORKSPACE_TYPE) { | ||
// $discordPayload = createAddResourceMessage($type, $simName, $userName, $simDesc, $width, $height, $particles); | ||
// sendDiscordMessage($discordPayload); | ||
//} | ||
|
||
echo json_encode(["result"=>true]); | ||
|
||
$db->commit(); | ||
$db->close(); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "LastSessionBrowserData.h" | ||
|
||
#include "Base/GlobalSettings.h" | ||
#include "Network/NetworkResourceRawTO.h" | ||
|
||
void LastSessionBrowserData::load(std::unordered_set<NetworkResourceRawTO> const& rawTOs) | ||
{ | ||
auto currentIdentifiers = convertToIdentifiers(rawTOs); | ||
auto lastIdentifiers = GlobalSettings::getInstance().getStringVector( | ||
"windows.browser.last session.simulation ids", std::vector(currentIdentifiers.begin(), currentIdentifiers.end())); | ||
_identifiers = std::unordered_set(lastIdentifiers.begin(), lastIdentifiers.end()); | ||
} | ||
|
||
void LastSessionBrowserData::save(std::unordered_set<NetworkResourceRawTO> const& rawTOs) | ||
{ | ||
auto currentIdentifiers = convertToIdentifiers(rawTOs); | ||
GlobalSettings::getInstance().setStringVector( | ||
"windows.browser.last session.simulation ids", std::vector(currentIdentifiers.begin(), currentIdentifiers.end())); | ||
} | ||
|
||
bool LastSessionBrowserData::isNew(NetworkResourceRawTO const& rawTO) const | ||
{ | ||
return !_identifiers.count(convertToIdentifier(rawTO)); | ||
} | ||
|
||
std::unordered_set<std::string> LastSessionBrowserData::convertToIdentifiers(std::unordered_set<NetworkResourceRawTO> const& rawTOs) const | ||
{ | ||
std::unordered_set<std::string> result; | ||
for (auto const& rawTO : rawTOs) { | ||
result.insert(convertToIdentifier(rawTO)); | ||
} | ||
return result; | ||
} | ||
|
||
std::string LastSessionBrowserData::convertToIdentifier(NetworkResourceRawTO const& rawTO) const | ||
{ | ||
return rawTO->id + "/" + rawTO->timestamp; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <unordered_set> | ||
|
||
#include "Network/Definitions.h" | ||
|
||
class LastSessionBrowserData | ||
{ | ||
public: | ||
void load(std::unordered_set<NetworkResourceRawTO> const& rawTOs); | ||
void save(std::unordered_set<NetworkResourceRawTO> const& rawTOs); | ||
bool isNew(NetworkResourceRawTO const& rawTO) const; | ||
|
||
private: | ||
std::unordered_set<std::string> convertToIdentifiers(std::unordered_set<NetworkResourceRawTO> const& rawTOs) const; | ||
std::string convertToIdentifier(NetworkResourceRawTO const& rawTO) const; | ||
|
||
std::unordered_set<std::string> _identifiers; | ||
}; |
Oops, something went wrong.