This commit is contained in:
malloc 2018-05-11 16:05:21 -05:00
parent 867d8a3fcc
commit 4d1894066c
4 changed files with 35 additions and 7 deletions

View file

@ -102,8 +102,8 @@ Communication between the master server and clients will be done over a WebSocke
</thead>
<tr>
<td>1</td>
<td>Error Message</td>
<td>String</td>
<td>Error Code</td>
<td>Packed Unsigned Short</td>
</tr>
</table>
@ -145,8 +145,8 @@ Communication between the master server and clients will be done over a WebSocke
</tr>
<tr>
<td>2</td>
<td>Error Message</td>
<td>String</td>
<td>Error Code</td>
<td>Packed Unsigned Short</td>
</tr>
</table>
@ -466,11 +466,16 @@ TODO: MAKE THIS SECTION NOT LOOK LIKE SHIT
### Master / Slave
#### S -> M (ID 1)
#### M -> S (ID 2)
0x01: KEY SIZE WAS INCORRECT
0x02: COULD NOT PARSE KEY
#### M -> S (ID 4)
0x01: LICENSE DATA INCORRECT
0x02: LICENSE LIMIT REACHED
### Master / Client
### Slave / Client

View file

@ -24,8 +24,8 @@ const std::vector<const char*> _hard_db_sql = {
/** START MIGRATION 0 **/
"CREATE TABLE `SERVER_LICENSES` ("
"`KEY_ID` TEXT NOT NULL UNIQUE,"
"`SECRET` TEXT NOT NULL UNIQUE,"
"`ALLOWANCE` INTEGER NOT NULL"
"`SECRET` BLOB NOT NULL UNIQUE,"
"`ALLOWANCE` INTEGER NOT NULL DEFAULT 0"
");\n"
"CREATE TABLE `USERS` ("

View file

@ -8,6 +8,8 @@
#include "../crypto/keyex.hpp"
#include "../crypto/cipher.hpp"
#include "../db/database.hpp"
namespace sosc {
/** MASTER -> CLIENT **/
@ -59,6 +61,11 @@ private:
IntraClient sock;
cgc::KeyExchange key;
cgc::Cipher cipher;
bool authed;
int auth_attempts;
const int MAX_AUTH_ATTEMPTS = 3;
std::string license;
};
class MasterIntraPool : public Pool<MasterIntra> {

View file

@ -1,7 +1,10 @@
#include "master.hpp"
#include "../db/database.hpp"
sosc::MasterIntra::MasterIntra(const IntraClient& client) {
this->sock = client;
this->authed = false;
this->auth_attempts = 0;
}
bool sosc::MasterIntra::Process() {
@ -36,7 +39,20 @@ bool sosc::MasterIntra::InitAttempt(sosc::Packet &pck) {
}
bool sosc::MasterIntra::Authentication(sosc::Packet &pck) {
if(this->authed)
return true;
if(!pck.Check(2, PCK_ANY, 512))
return this->Close(Packet(kNegativeAck, { "\x01" }));
db::Query = db::Query::ScalarInt32(
"SELECT COUNT(*) FROM SERVER_LICENSES "
"WHERE KEY_ID = ? AND SECRET = ?"
);
if(isValid > 0) {
}
}
bool sosc::MasterIntra::StatusUpdate(sosc::Packet &pck) {