BOOMER TIME

This commit is contained in:
malloc 2018-10-04 16:27:26 -05:00
parent 8635b98a14
commit 9661b5367a
4 changed files with 62 additions and 24 deletions

View file

@ -188,20 +188,9 @@ Communication between the master server and clients will be done over a WebSocke
<tr>
<td class="center">2</td>
<td>Secret</td>
<td>Bytes (16)</td>
<td>Bytes (128)</td>
<td>R<sub>1</sub></td>
</tr>
<tr>
<td class="center">3</td>
<td>Server Address</td>
<td>IPv4 String</td>
<td>R<sub>1</sub></td>
</tr>
<tr>
<td class="center">4</td>
<td>Server Port</td>
<td>Packed Unsigned Short</td>
<td>R<sub>1</sub></td>
</tr>
</table>

View file

@ -14,15 +14,11 @@ const char* _mem_db_sql =
"`MAX_USERS` INTEGER NOT NULL DEFAULT 0"
");\n"
"CREATE UNIQUE INDEX `UIX_SERVER_LICENSES` ON `SERVER_LICENSES` ("
"`KEY_ID`, `SECRET`"
");\n"
"CREATE TABLE `USER_KEYS` ("
"`ID` INTEGER,"
"`SECRET` BLOB NOT NULL UNIQUE,"
"PRIMARY KEY(`ID`)"
");";
");\n";
const char* _hard_db_init_migration_sql =
"CREATE TABLE `MIGRATIONS` ("
@ -35,11 +31,15 @@ const char* _hard_db_init_migration_sql =
const std::vector<const char*> _hard_db_sql = {
/** START MIGRATION 0 **/
"CREATE TABLE `SERVER_LICENSES` ("
"`KEY_ID` TEXT NOT NULL UNIQUE,"
"`SECRET` BLOB NOT NULL UNIQUE,"
"`KEY_ID` TEXT NOT NULL PRIMARY KEY AUTOINCREMENT,"
"`SECRET` BLOB NOT NULL,"
"`ALLOWANCE` INTEGER NOT NULL DEFAULT 0"
");\n"
"CREATE UNIQUE INDEX `UIX_SERVER_LICENSES` ON `SERVER_LICENSES` ("
"`KEY_ID`, `SECRET`"
");\n"
"CREATE TABLE `USERS` ("
"`ID` INTEGER PRIMARY KEY AUTOINCREMENT,"
"`USERNAME` TEXT NOT NULL,"

View file

@ -17,9 +17,25 @@ namespace sosc {
class MasterClient {
public:
explicit MasterClient(const ScapeConnection& client);
bool Process(const Queries* queries);
bool Close();
bool Close(const Packet& message);
private:
enum MasterToClientId {
};
enum ClientToMasterId {
};
ScapeConnection sock;
bool authed;
int auth_attempts;
const int MAX_AUTH_ATTEMPTS = 5;
};
class MasterClientPool : public Pool<MasterClient, ctx::MasterClientContext> {
@ -30,8 +46,7 @@ protected:
ctx::MasterClientContext* context,
const Queries* queries) override
{
// TODO implement
return true;
return client.Process(queries);
}
};

View file

@ -7,8 +7,42 @@ static struct {
/** MASTERCLIENTPOOL CODE **/
void sosc::MasterClientPool::SetupQueries(Queries *queries) {
#define QRY_USER_REGISTER 0
#define QRY_USER_REG_CHECK 0
queries->push_back(new db::Query(
"SELECT COUNT(*) FROM `USERS` "
"WHERE `USERNAME` = ? OR `EMAIL` = ?"
));
#define QRY_USER_REGISTER 1
queries->push_back(new db::Query(
"INSERT INTO `USERS` "
"(`USERNAME`, `PASS_HASH`, `EMAIL`, `ACTIVATED`, `JOINED`) "
"VALUES (?, ?, ?, 0, CURRENT_TIMESTAMP)"
));
#define QRY_USER_GET_PWD_HASH 2
queries->push_back(new db::Query(
"SELECT `ID`, `PASS_HASH` FROM `USERS` "
"WHERE `USERNAME` = ?"
));
#define QRY_USER_GENERATE_KEY 3
queries->push_back(new db::Query(
"INSERT OR IGNORE INTO `USER_KEYS` "
"(`ID`, `SECRET`) VALUES (?, RANDOMBLOB(128))"
));
#define QRY_USER_GET_KEY 4
queries->push_back(new db::Query(
"SELECT `SECRET` FROM `USER_KEYS` "
"WHERE `ID` = ?"
));
#define QRY_USER_CHECK_KEY 5
queries->push_back(new db::Query(
"SELECT COUNT(*) FROM `USER_KEYS` "
"WHERE `ID` = ? AND `SECRET` = ?"
));
}
/** MASTERCLIENT CODE **/