53 lines
1.2 KiB
C++
53 lines
1.2 KiB
C++
|
#include "Client.h"
|
||
|
#include <os/File.h>
|
||
|
|
||
|
Client::Client(OwnedPtr<os::IPC::ClientConnection>&& client, i16 _pledges)
|
||
|
: conn(move(client)), windows(), pledges(_pledges)
|
||
|
{
|
||
|
conn->set_message_handler(wind::handle_ipc_message, this);
|
||
|
}
|
||
|
|
||
|
bool Client::update_pledges(i16 _pledges)
|
||
|
{
|
||
|
if (_pledges < 0)
|
||
|
{
|
||
|
os::eprintln("wind: Client trying to set an invalid pledge, disconnecting!");
|
||
|
should_be_disconnected = true;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
if (pledges < 0)
|
||
|
{
|
||
|
pledges = _pledges;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
if (_pledges & ~pledges)
|
||
|
{
|
||
|
os::eprintln("wind: Client trying to add pledges, disconnecting!");
|
||
|
should_be_disconnected = true;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
pledges = _pledges;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool Client::check_pledge(i16 pledge)
|
||
|
{
|
||
|
check(pledge > 0);
|
||
|
|
||
|
if (pledges < 0)
|
||
|
{
|
||
|
os::eprintln("wind: Client trying to use pledge-protected functions before pledging anything, disconnecting!");
|
||
|
should_be_disconnected = true;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
if ((pledges & pledge) == pledge) return true;
|
||
|
|
||
|
os::eprintln("wind: Client trying to use a function they haven't pledged, disconnecting!");
|
||
|
should_be_disconnected = true;
|
||
|
return false;
|
||
|
}
|