Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/netclient.cc')
-rw-r--r--src/core/netclient.cc44
1 files changed, 23 insertions, 21 deletions
diff --git a/src/core/netclient.cc b/src/core/netclient.cc
index 253cf4f..46694a6 100644
--- a/src/core/netclient.cc
+++ b/src/core/netclient.cc
@@ -46,10 +46,10 @@ NetClient::NetClient(std::string host, int port, int fd) :
abort();
return;
}
-
+
sendq.clear();
messageblock.clear();
-
+
client_keepalive = application()->time();
client_timeout = application()->time();
@@ -69,25 +69,27 @@ void NetClient::abort()
std::string NetClient::host() const
{
- return client_host;
+ return client_host;
}
int NetClient::port() const
{
- return client_port;
+ return client_port;
}
-Player *NetClient::player()
+Player *NetClient::player()
{
return client_player;
}
-bool NetClient::has_messages() const {
- return (recvq.size() > 0 );
+bool NetClient::has_messages() const
+{
+ return (recvq.size() > 0);
}
-void NetClient::retreive(std::string & message) {
- if (recvq.size() > 0 ) {
+void NetClient::retreive(std::string & message)
+{
+ if (recvq.size() > 0) {
message.assign(recvq.front());
recvq.pop_front();
} else {
@@ -101,9 +103,9 @@ void NetClient::receive(char *data)
const char *c = data;
while (*c) {
- if (( *c == '\n') || (*c == '\r')) {
- if (messageblock.size() > 0 ) {
- recvq.push_back(messageblock);
+ if ((*c == '\n') || (*c == '\r')) {
+ if (messageblock.size() > 0) {
+ recvq.push_back(messageblock);
messageblock.clear();
}
} else {
@@ -117,7 +119,7 @@ void NetClient::receive(char *data)
c++;
}
- client_timeout = application()->time();
+ client_timeout = application()->time();
}
void NetClient::send_raw(std::string const &msg)
@@ -125,7 +127,7 @@ void NetClient::send_raw(std::string const &msg)
if (error())
return;
- if ((sendq.size()) && (sendq.size() + msg.size() >= BLOCKSIZE - 16 )) {
+ if ((sendq.size()) && (sendq.size() + msg.size() >= BLOCKSIZE - 16)) {
transmit();
}
@@ -135,12 +137,12 @@ void NetClient::send_raw(std::string const &msg)
void NetClient::transmit()
{
if (!sendq.size()) {
- if (client_keepalive + NETTIMEOUT/2 < application()->time()) {
+ if (client_keepalive + NETTIMEOUT / 2 < application()->time()) {
sendq.assign("ping\n");
} else {
return;
}
- } else if (sendq.size() >= BLOCKSIZE - 16 ) {
+ } else if (sendq.size() >= BLOCKSIZE - 16) {
con_warn << host() << ":" << port() << " outgoing data exceeds " << BLOCKSIZE - 16 << " bytes!\n";
sendq.clear();
return;
@@ -152,17 +154,17 @@ void NetClient::transmit()
uLong uncompressed_size = (uLong) sendq.size();
size_t total_size = 0;
- memset(zbuf,0, sizeof(zbuf));
+ memset(zbuf, 0, sizeof(zbuf));
Stats::network_uncompressed_bytes_sent += sendq.size();
// zlib compress
- int status = compress((Bytef*)(zbuf+4), &compressed_size, (Bytef*)sendq.c_str(), uncompressed_size);
+ int status = compress((Bytef*)(zbuf + 4), &compressed_size, (Bytef*)sendq.c_str(), uncompressed_size);
if ((status == Z_OK) && (compressed_size + 4 < sendq.size())) {
// add a header to the compress packet
data = (char *) zbuf;
- total_size = (size_t) (compressed_size + 4);
+ total_size = (size_t)(compressed_size + 4);
zbuf[0] = '\xff';
zbuf[1] = '\xff';
zbuf[2] = compressed_size % 256;
@@ -171,12 +173,12 @@ void NetClient::transmit()
data = sendq.c_str();
total_size = sendq.size();
}
-
+
size_t total_sent = 0;
while (total_sent < total_size && !error()) {
ssize_t bytes_sent = ::sendto(fd(), data, total_size - total_sent, 0,
- (struct sockaddr *)&client_addr, sizeof(client_addr));
+ (struct sockaddr *) & client_addr, sizeof(client_addr));
if (bytes_sent < 0) {
abort();