very ugly spare your eyes
This commit is contained in:
parent
7258056e1c
commit
1d0a382eed
7 changed files with 51 additions and 36 deletions
|
@ -275,11 +275,6 @@ Communication between the master server and clients will be done over a WebSocke
|
|||
<td>Password</td>
|
||||
<td>String</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="center">3</td>
|
||||
<td>Server Id</td>
|
||||
<td>Packed Unsigned Short</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table style="margin-right: 8px; margin-bottom: 8px;">
|
||||
|
|
|
@ -17,11 +17,14 @@ namespace sosc {
|
|||
|
||||
class MasterClient {
|
||||
public:
|
||||
MasterClient() = delete;
|
||||
explicit MasterClient(const ScapeConnection& client);
|
||||
bool Process(const db::Queries* queries);
|
||||
|
||||
bool Close();
|
||||
bool Close(const Packet& message);
|
||||
|
||||
~MasterClient();
|
||||
private:
|
||||
enum MasterToClientId {
|
||||
kLoginResponse = 0,
|
||||
|
@ -47,11 +50,11 @@ class MasterClientPool : public Pool<MasterClient, ctx::MasterClientContext> {
|
|||
protected:
|
||||
void SetupQueries(db::Queries* queries) override;
|
||||
bool ProcessClient(
|
||||
MasterClient& client,
|
||||
MasterClient* client,
|
||||
ctx::MasterClientContext* context,
|
||||
const db::Queries* queries) override
|
||||
{
|
||||
return client.Process(queries);
|
||||
return client->Process(queries);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -59,11 +62,14 @@ protected:
|
|||
|
||||
class MasterIntra {
|
||||
public:
|
||||
MasterIntra() = delete;
|
||||
explicit MasterIntra(const IntraClient& client);
|
||||
bool Process(const db::Queries* queries);
|
||||
|
||||
bool Close();
|
||||
bool Close(const Packet& message);
|
||||
|
||||
~MasterIntra();
|
||||
private:
|
||||
bool Authentication(Packet& pck);
|
||||
bool StatusUpdate(Packet& pck);
|
||||
|
@ -99,11 +105,11 @@ class MasterIntraPool : public Pool<MasterIntra, ctx::MasterIntraContext> {
|
|||
protected:
|
||||
void SetupQueries(db::Queries* queries) override;
|
||||
bool ProcessClient
|
||||
(MasterIntra& client,
|
||||
(MasterIntra* client,
|
||||
ctx::MasterIntraContext* context,
|
||||
const db::Queries* queries) override
|
||||
{
|
||||
return client.Process(queries);
|
||||
return client->Process(queries);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ bool master_intra(uint16_t port, const sosc::poolinfo_t& info) {
|
|||
using namespace sosc;
|
||||
|
||||
IntraServer server;
|
||||
IntraClient client;
|
||||
IntraClient* client;
|
||||
if(!server.Listen(port))
|
||||
return false;
|
||||
|
||||
|
@ -49,7 +49,7 @@ bool master_intra(uint16_t port, const sosc::poolinfo_t& info) {
|
|||
pool.Configure(info);
|
||||
pool.Start();
|
||||
|
||||
while(server.Accept(&client))
|
||||
while(server.Accept(client = new IntraClient()))
|
||||
pool.AddClient(MasterIntra(client));
|
||||
|
||||
pool.Stop();
|
||||
|
@ -60,7 +60,7 @@ bool master_client(uint16_t port, const sosc::poolinfo_t& info) {
|
|||
using namespace sosc;
|
||||
|
||||
ScapeServer server;
|
||||
ScapeConnection client;
|
||||
ScapeConnection* client;
|
||||
if(!server.Listen(port, true))
|
||||
return false;
|
||||
|
||||
|
@ -68,7 +68,7 @@ bool master_client(uint16_t port, const sosc::poolinfo_t& info) {
|
|||
pool.Configure(info);
|
||||
pool.Start();
|
||||
|
||||
while(server.Accept(&client))
|
||||
while(server.Accept(client = new ScapeConnection()))
|
||||
pool.AddClient(MasterClient(client));
|
||||
|
||||
pool.Stop();
|
||||
|
@ -79,7 +79,7 @@ bool slave(uint16_t port, const sosc::poolinfo_t& info) {
|
|||
using namespace sosc;
|
||||
|
||||
ScapeServer server;
|
||||
ScapeConnection client;
|
||||
ScapeConnection* client;
|
||||
if(!server.Listen(port))
|
||||
return false;
|
||||
|
||||
|
@ -87,7 +87,7 @@ bool slave(uint16_t port, const sosc::poolinfo_t& info) {
|
|||
pool.Configure(info);
|
||||
pool.Start();
|
||||
|
||||
while(server.Accept(&client))
|
||||
while(server.Accept(client = new ScapeConnection()))
|
||||
pool.AddClient(SlaveClient(client));
|
||||
|
||||
pool.Stop();
|
||||
|
|
|
@ -72,7 +72,7 @@ private:
|
|||
std::string body;
|
||||
|
||||
inline static bool IsValidOpCode(int op) {
|
||||
return !(op == 0x0 || op == 0x1 || op == 0x2
|
||||
return (op == 0x0 || op == 0x1 || op == 0x2
|
||||
|| op == 0x8 || op == 0x9 || op == 0xA);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -36,7 +36,7 @@ public:
|
|||
void Configure(const poolinfo_t& info);
|
||||
|
||||
void Start();
|
||||
bool AddClient(T client);
|
||||
bool AddClient(T* client);
|
||||
int ClientCount();
|
||||
inline bool IsOpen() const {
|
||||
return this->is_open;
|
||||
|
@ -46,7 +46,7 @@ public:
|
|||
protected:
|
||||
virtual void SetupQueries(db::Queries* queries) {};
|
||||
virtual bool ProcessClient
|
||||
(T& client, U* context, const db::Queries* queries) = 0;
|
||||
(T* client, U* context, const db::Queries* queries) = 0;
|
||||
private:
|
||||
bool IsStackFull(int stackCount) const;
|
||||
bool CanAddStack() const;
|
||||
|
@ -58,7 +58,7 @@ private:
|
|||
|
||||
void Start();
|
||||
|
||||
void AddClient(T client);
|
||||
void AddClient(T* client);
|
||||
int ClientCount();
|
||||
inline bool IsOpen() const {
|
||||
return this->is_open;
|
||||
|
@ -74,7 +74,7 @@ private:
|
|||
bool is_open;
|
||||
bool is_running;
|
||||
|
||||
std::list<T> clients;
|
||||
std::list<T*> clients;
|
||||
std::mutex clients_mtx;
|
||||
};
|
||||
|
||||
|
@ -132,7 +132,7 @@ bool Pool<T,U>::CanAddStack() const {
|
|||
}
|
||||
|
||||
template<class T, class U>
|
||||
bool Pool<T,U>::AddClient(T client) {
|
||||
bool Pool<T,U>::AddClient(T* client) {
|
||||
if(!this->is_open)
|
||||
return false;
|
||||
|
||||
|
@ -214,7 +214,7 @@ void Pool<T,U>::Stack::Start() {
|
|||
}
|
||||
|
||||
template<class T, class U>
|
||||
void Pool<T,U>::Stack::AddClient(T client) {
|
||||
void Pool<T,U>::Stack::AddClient(T* client) {
|
||||
if(!this->is_open || !this->is_running)
|
||||
return;
|
||||
|
||||
|
@ -248,9 +248,10 @@ void Pool<T,U>::Stack::StackThread() {
|
|||
|
||||
this->clients_mtx.lock();
|
||||
if(!this->pool->ProcessClient
|
||||
(*client, &this->pool->context, &this->queries))
|
||||
(client, &this->pool->context, &this->queries))
|
||||
{
|
||||
this->clients.erase(client);
|
||||
delete client;
|
||||
}
|
||||
this->clients_mtx.unlock();
|
||||
}
|
||||
|
@ -269,8 +270,11 @@ void Pool<T,U>::Stack::Stop() {
|
|||
|
||||
this->is_running = false;
|
||||
this->thread->join();
|
||||
|
||||
delete this->thread;
|
||||
|
||||
for(auto client : this->clients)
|
||||
delete client;
|
||||
|
||||
this->is_open = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,9 +12,7 @@
|
|||
</div>
|
||||
<div id="login" class="hidden section">
|
||||
<h1>Log In</h1>
|
||||
<div class="error">
|
||||
test error test test error test test error test test error test test error test test error test test error test test error test test error test
|
||||
</div>
|
||||
<div class="hidden error"></div>
|
||||
<label>
|
||||
Username: <br/>
|
||||
<input type="text" id="login-user" />
|
||||
|
@ -23,7 +21,7 @@
|
|||
Password: <br/>
|
||||
<input type="password" id="login-pwd" />
|
||||
</label>
|
||||
<input type="button" value="Log In" />
|
||||
<input type="button" value="Log In" onclick="attempt_login();" />
|
||||
<input type="button" value="Register" onclick="show_section('register');" />
|
||||
</div>
|
||||
<div id="register" class="hidden section">
|
||||
|
|
|
@ -21,19 +21,27 @@ let receive_callbacks = {};
|
|||
function attempt_login() {
|
||||
let section = document.getElementById("login");
|
||||
let error = section.getElementsByClassName("error");
|
||||
let buttons = filter(
|
||||
let lock_fields = filter(
|
||||
to_array(section.getElementsByTagName("input")),
|
||||
x => (x.type === "button" || x.type === "submit")
|
||||
x => ["submit", "button", "text", "password"].indexOf(x.type) !== -1
|
||||
);
|
||||
|
||||
for(let i in buttons)
|
||||
buttons[i].disabled = true;
|
||||
for_each(lock_fields, x => x.disabled = true);
|
||||
ws.send(pack(
|
||||
kClientToMaster.LoginRequest, [
|
||||
document.getElementById("login-user").value,
|
||||
document.getElementById("login-pwd").value
|
||||
]
|
||||
));
|
||||
|
||||
receive_callbacks[kMasterToClient.LoginResponse] = (pck) => {
|
||||
receive_callbacks[kMasterToClient.LoginResponse] = pck => {
|
||||
if(pck.regions[0][0] === 0) {
|
||||
error.innerHTML = "Username or password was incorrect."
|
||||
} else {
|
||||
alert("allo");
|
||||
}
|
||||
|
||||
|
||||
for(let i in buttons)
|
||||
buttons[i].disabled = false;
|
||||
for_each(lock_fields, x => x.disabled = false);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -578,4 +586,8 @@ function filter(x, f) {
|
|||
|
||||
function to_array(x) {
|
||||
return Array.prototype.slice.call(x);
|
||||
}
|
||||
|
||||
function concat(x, y) {
|
||||
return Array.prototype.concat.call(x, y);
|
||||
}
|
Loading…
Reference in a new issue