mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-19 01:22:14 +11:00
commit
af6fff0793
4 changed files with 13 additions and 11 deletions
|
|
@ -33,7 +33,7 @@ make -j<threads>
|
||||||
sudo ./bank <admin password> <saving frequency in minutes> <threads>
|
sudo ./bank <admin password> <saving frequency in minutes> <threads>
|
||||||
```
|
```
|
||||||
|
|
||||||
you also have to edit the config file to add your cert locations, I personally use cert bot
|
**you also have to edit the config file to add your cert locations**, I personally use cert bot
|
||||||
|
|
||||||
### Connected Services
|
### Connected Services
|
||||||
|
|
||||||
|
|
@ -64,7 +64,7 @@ Ideas:
|
||||||
- written in **C++**, arguably the fastest language
|
- written in **C++**, arguably the fastest language
|
||||||
- **multi-threaded**
|
- **multi-threaded**
|
||||||
- **parallel hashmaps** a far superior HashMap implementation to the STD, that also benefit from multi-threaded
|
- **parallel hashmaps** a far superior HashMap implementation to the STD, that also benefit from multi-threaded
|
||||||
- **Passwords are Hashed**, allowing each user to be 12 bytes, which is allows hashmap to be flat
|
- **Passwords are Hashed**, allowing each user to be 12 bytes, which is allows hashmap to be flat. This hashing is also very fast at 31.5 GB/s on a i7-9700K
|
||||||
|
|
||||||
### Safety
|
### Safety
|
||||||
|
|
||||||
|
|
@ -77,8 +77,10 @@ Ideas:
|
||||||
- **Web front-end**
|
- **Web front-end**
|
||||||
- **RESTful** API for connected services like a market, gambling, or anything else you can think of
|
- **RESTful** API for connected services like a market, gambling, or anything else you can think of
|
||||||
- able to be used millions of blocks away, across dimensions, servers, **vanilla or modded**. In contrast to an in-game modded implementation that would be range limited.
|
- able to be used millions of blocks away, across dimensions, servers, **vanilla or modded**. In contrast to an in-game modded implementation that would be range limited.
|
||||||
|
- **Logging**
|
||||||
|
|
||||||
#### Dependencies
|
#### Dependencies
|
||||||
|
|
||||||
- [Parallel HashMap](https://github.com/greg7mdp/parallel-hashmap/tree/master)
|
- [Parallel HashMap](https://github.com/greg7mdp/parallel-hashmap/tree/master)
|
||||||
- [drogon web framework (and all its dependencies)](https://github.com/an-tao/drogon/tree/master)
|
- [Drogon](https://github.com/an-tao/drogon/tree/master)
|
||||||
|
- [XXHASH](https://github.com/Cyan4973/xxHash)
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ public:
|
||||||
bool DelUser(const std::string &name, const std::string &attempt)
|
bool DelUser(const std::string &name, const std::string &attempt)
|
||||||
{
|
{
|
||||||
std::shared_lock<std::shared_mutex> lock{size_lock};
|
std::shared_lock<std::shared_mutex> lock{size_lock};
|
||||||
return users.erase_if(name, [&attempt](const User &u) { return (XXH64(attempt.data(), attempt.size(), 1) == u.password); });
|
return users.erase_if(name, [&attempt](const User &u) { return (XXH3_64bits(attempt.data(), attempt.size()) == u.password); });
|
||||||
}
|
}
|
||||||
bool AdminDelUser(const std::string &name, const std::string &attempt)
|
bool AdminDelUser(const std::string &name, const std::string &attempt)
|
||||||
{
|
{
|
||||||
|
|
@ -75,7 +75,7 @@ public:
|
||||||
bool state = false;
|
bool state = false;
|
||||||
std::shared_lock<std::shared_mutex> lock{send_funds_l}; //because SendFunds requires 3 locking operations
|
std::shared_lock<std::shared_mutex> lock{send_funds_l}; //because SendFunds requires 3 locking operations
|
||||||
users.modify_if(a_name, [&state, amount, &attempt](User &a) {
|
users.modify_if(a_name, [&state, amount, &attempt](User &a) {
|
||||||
if (state = (a.balance >= amount) && (a.password == XXH64(attempt.data(), attempt.size(), 1)))
|
if (state = (a.balance >= amount) && (a.password == XXH3_64bits(attempt.data(), attempt.size())))
|
||||||
{
|
{
|
||||||
a.balance -= amount;
|
a.balance -= amount;
|
||||||
}
|
}
|
||||||
|
|
@ -130,7 +130,7 @@ public:
|
||||||
{
|
{
|
||||||
int_fast8_t res = -1;
|
int_fast8_t res = -1;
|
||||||
users.if_contains(name, [&res, &attempt](const User &u) {
|
users.if_contains(name, [&res, &attempt](const User &u) {
|
||||||
res = u.password == XXH64(attempt.data(), attempt.size(), 1);
|
res = u.password == XXH3_64bits(attempt.data(), attempt.size());
|
||||||
});
|
});
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
@ -138,10 +138,10 @@ public:
|
||||||
{
|
{
|
||||||
int_fast8_t res = -1;
|
int_fast8_t res = -1;
|
||||||
users.modify_if(name, [&res, &attempt, &new_pass](User &u) {
|
users.modify_if(name, [&res, &attempt, &new_pass](User &u) {
|
||||||
res = (u.password == XXH64(attempt.data(), attempt.size(), 1));
|
res = (u.password == XXH3_64bits(attempt.data(), attempt.size()));
|
||||||
if (res)
|
if (res)
|
||||||
{
|
{
|
||||||
u.password = XXH64(new_pass.data(), new_pass.size(), 1);
|
u.password = XXH3_64bits(new_pass.data(), new_pass.size());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return res;
|
return res;
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ struct User
|
||||||
*
|
*
|
||||||
* @param init_pass initial password
|
* @param init_pass initial password
|
||||||
*/
|
*/
|
||||||
User(std::string &&init_pass) : password(XXH64(init_pass.data(), init_pass.size(), 1)) {}
|
User(std::string &&init_pass) : password(XXH3_64bits(init_pass.data(), init_pass.size())) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief User Constructor for admins
|
* @brief User Constructor for admins
|
||||||
|
|
@ -21,7 +21,7 @@ struct User
|
||||||
* @param init_bal initial balance
|
* @param init_bal initial balance
|
||||||
* @param init_pass initial password
|
* @param init_pass initial password
|
||||||
*/
|
*/
|
||||||
User(uint_fast32_t init_bal, std::string &&init_pass, bool state = false) : balance(init_bal), password(XXH64(init_pass.data(), init_pass.size(), 1)), is_admin(state) {}
|
User(uint_fast32_t init_bal, std::string &&init_pass, bool state = false) : balance(init_bal), password(XXH3_64bits(init_pass.data(), init_pass.size())), is_admin(state) {}
|
||||||
User(uint_fast32_t init_bal, uint64_t init_pass, bool state = false) : balance(init_bal), password(init_pass), is_admin(state) {}
|
User(uint_fast32_t init_bal, uint64_t init_pass, bool state = false) : balance(init_bal), password(init_pass), is_admin(state) {}
|
||||||
|
|
||||||
Json::Value Serialize() const
|
Json::Value Serialize() const
|
||||||
|
|
|
||||||
2
main.cpp
2
main.cpp
|
|
@ -44,7 +44,7 @@ int main(int argc, char **argv)
|
||||||
[](const drogon::HttpRequestPtr &req, const drogon::HttpResponsePtr &resp) {
|
[](const drogon::HttpRequestPtr &req, const drogon::HttpResponsePtr &resp) {
|
||||||
resp->addHeader("Access-Control-Allow-Origin", "*");
|
resp->addHeader("Access-Control-Allow-Origin", "*");
|
||||||
});
|
});
|
||||||
app().loadConfigFile("../config.json").addListener("0.0.0.0", 80).registerController(API).setThreadNum(std::stoul(argv[3])).enableRunAsDaemon().run();
|
app().loadConfigFile("../config.json").registerController(API).setThreadNum(std::stoul(argv[3])).enableRunAsDaemon().run();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue