Files
psopeeps-newserv/Client.cc
T
Martin Michelsen 5b8c26ccd7 initial commit
2018-10-31 23:55:32 -07:00

48 lines
1.3 KiB
C++

#include "Client.hh"
#include <event2/buffer.h>
#include <event2/bufferevent.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <phosg/Network.hh>
#include <phosg/Time.hh>
#include "Version.hh"
using namespace std;
Client::Client(struct bufferevent* bev, GameVersion version,
ServerBehavior server_behavior) : version(version),
flags(flags_for_version(version, 0)), bev(bev),
server_behavior(server_behavior), should_disconnect(false),
play_time_begin(now()), last_recv_time(this->play_time_begin),
last_send_time(0), in_information_menu(false), area(0), lobby_id(0),
lobby_client_id(0), lobby_arrow_color(0), next_exp_value(0),
infinite_hp(false), infinite_tp(false), can_chat(true) {
int fd = bufferevent_getfd(this->bev);
get_socket_addresses(fd, &this->local_addr, &this->remote_addr);
memset(this->name, 0, sizeof(this->name));
memset(&this->next_connection_addr, 0, sizeof(this->next_connection_addr));
}
bool Client::send(string&& data) {
rw_guard g(this->lock, false);
if (!this->bev) {
return false;
}
if (this->crypt_out.get()) {
this->crypt_out->encrypt(const_cast<char*>(data.data()), data.size());
}
struct evbuffer* buf = bufferevent_get_output(this->bev);
evbuffer_add(buf, data.data(), data.size());
return true;
}