Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2009-08-18 09:24:15 +0000
committerStijn Buys <ingar@osirion.org>2009-08-18 09:24:15 +0000
commitf030154fe727e25a2afe1f78b3998c2d2dba95e4 (patch)
treecd92baf9e4fa8a136523b9eb570e9811846c9250 /src/core/netconnection.cc
parent5636fad174f0bcff857c357c394c4cc8d424b302 (diff)
astyle cleanup, corrects not loading of material textures
Diffstat (limited to 'src/core/netconnection.cc')
-rw-r--r--src/core/netconnection.cc158
1 files changed, 78 insertions, 80 deletions
diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc
index 81f5b48..c37fe05 100644
--- a/src/core/netconnection.cc
+++ b/src/core/netconnection.cc
@@ -16,7 +16,7 @@
#include "core/player.h"
#include "core/stats.h"
-namespace core
+namespace core
{
NetConnection::NetConnection()
@@ -37,7 +37,7 @@ NetConnection::~NetConnection()
void NetConnection::abort()
{
- connection_error= true;
+ connection_error = true;
}
void NetConnection::connect(std::string const &to_host, int to_port)
@@ -48,7 +48,7 @@ void NetConnection::connect(std::string const &to_host, int to_port)
if (valid())
return;
-
+
// resolve serverhostname
struct hostent *serverhostent;
serverhostent = gethostbyname(to_host.c_str());
@@ -57,7 +57,7 @@ void NetConnection::connect(std::string const &to_host, int to_port)
abort();
return;
}
-
+
// Get a socket file descriptor
connection_fd = socket(PF_INET, SOCK_DGRAM, 0);
if (connection_fd == -1) {
@@ -65,7 +65,7 @@ void NetConnection::connect(std::string const &to_host, int to_port)
abort();
return;
}
-
+
// make the connection
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(to_port);
@@ -77,7 +77,7 @@ void NetConnection::connect(std::string const &to_host, int to_port)
abort();
return;
}
-
+
connection_host = to_host;
connection_port = to_port;
connection_error = false;
@@ -94,10 +94,10 @@ void NetConnection::connect(std::string const &to_host, int to_port)
connection_state = Pending;
game()->localplayer()->set_dirty();
- std::stringstream str;
- str << "Connecting to " << inet_ntoa(*((struct in_addr *)serverhostent->h_addr)) << ":" << to_port << "...";
- con_print << str.str() << std::endl;
- application()->notify_loader(str.str());
+ std::stringstream str;
+ str << "Connecting to " << inet_ntoa(*((struct in_addr *)serverhostent->h_addr)) << ":" << to_port << "...";
+ con_print << str.str() << std::endl;
+ application()->notify_loader(str.str());
}
void NetConnection::disconnect()
@@ -114,7 +114,7 @@ void NetConnection::disconnect()
close(connection_fd);
#endif
}
-
+
connection_fd = -1;
connection_error = false;
connection_host.clear();
@@ -145,9 +145,9 @@ void NetConnection::receive()
return;
ssize_t bytes_received;
-
+
memset(recvbuf, 0, BLOCKSIZE);
- bytes_received = ::recv(connection_fd, recvbuf, BLOCKSIZE-1, 0);
+ bytes_received = ::recv(connection_fd, recvbuf, BLOCKSIZE - 1, 0);
Stats::network_bytes_received += bytes_received;
connection_timeout = core::application()->time();
@@ -173,7 +173,7 @@ void NetConnection::receive()
// uncompress
char zunbuf[BLOCKSIZE*2];
memset(zunbuf, 0, sizeof(zunbuf));
- uLong zunbuf_size = (uLong) BLOCKSIZE*2 - 1;
+ uLong zunbuf_size = (uLong) BLOCKSIZE * 2 - 1;
int status = uncompress((Bytef *) zunbuf, &zunbuf_size, (Bytef *) zrecvbuf, (uLong) compressed_size);
@@ -182,7 +182,7 @@ void NetConnection::receive()
} else {
const char *zc = zunbuf;
while (*zc) {
- if (( *zc == '\n') || (*zc == '\r')) {
+ if ((*zc == '\n') || (*zc == '\r')) {
if (messageblock.size()) {
recvq.push_back(messageblock);
messageblock.clear();
@@ -204,22 +204,22 @@ void NetConnection::receive()
received_compressed_size = 0;
compressed_size = 0;
}
- } else if (!messageblock.size() && (bytes_received > 3 ) && ( *c == '\xff') && (*(c+1) == '\xff')) {
-
- receive_compressed = true;
- received_compressed_size = 0;
- compressed_size = (uLong) (*(unsigned char *)(c+2) + (*(unsigned char *)(c+3) << 8));
- c += 3;
- bytes_received -= 3;
- memset(zrecvbuf, 0, sizeof(zrecvbuf));
- if (compressed_size > BLOCKSIZE) {
- con_warn << "Incoming compressed datablock exceeds " << BLOCKSIZE << " bytes!\n";
- receive_compressed = false;
- }
+ } else if (!messageblock.size() && (bytes_received > 3) && (*c == '\xff') && (*(c + 1) == '\xff')) {
+
+ receive_compressed = true;
+ received_compressed_size = 0;
+ compressed_size = (uLong)(*(unsigned char *)(c + 2) + (*(unsigned char *)(c + 3) << 8));
+ c += 3;
+ bytes_received -= 3;
+ memset(zrecvbuf, 0, sizeof(zrecvbuf));
+ if (compressed_size > BLOCKSIZE) {
+ con_warn << "Incoming compressed datablock exceeds " << BLOCKSIZE << " bytes!\n";
+ receive_compressed = false;
+ }
- } else if (( *c == '\n') || (*c == '\r')) {
+ } else if ((*c == '\n') || (*c == '\r')) {
if (messageblock.size()) {
- recvq.push_back(messageblock);
+ recvq.push_back(messageblock);
messageblock.clear();
}
} else {
@@ -243,7 +243,7 @@ void NetConnection::frame()
timeout.tv_usec = 0;
fd_set readset = clientset;
- int nb = select(fd()+1, &readset, NULL, NULL, &timeout);
+ int nb = select(fd() + 1, &readset, NULL, NULL, &timeout);
if (nb == 0) {
if (connection_timeout + NETTIMEOUT < core::application()->time()) {
con_error << "Connection timeout!\n";
@@ -266,7 +266,7 @@ void NetConnection::frame()
parse_incoming_message(message);
}
- nb = select(fd()+1, &readset, NULL, NULL, &timeout);
+ nb = select(fd() + 1, &readset, NULL, NULL, &timeout);
if (nb == 0) {
return;
}
@@ -284,9 +284,9 @@ void NetConnection::transmit()
if (error() || invalid())
return;
-
+
if (!sendq.size()) {
- if (connection_keepalive + NETTIMEOUT /2 < application()->time()) {
+ if (connection_keepalive + NETTIMEOUT / 2 < application()->time()) {
sendq.assign("ping\n");
} else {
return;
@@ -296,18 +296,18 @@ void NetConnection::transmit()
sendq.clear();
return;
}
-
+
ssize_t bytes_sent = 0;
-
+
while (sendq.size()) {
- bytes_sent = ::sendto(connection_fd, sendq.c_str(), sendq.size(), 0, (struct sockaddr *)&server_addr, sizeof(server_addr));
+ bytes_sent = ::sendto(connection_fd, sendq.c_str(), sendq.size(), 0, (struct sockaddr *) & server_addr, sizeof(server_addr));
if (bytes_sent <= 0) {
con_error << "Network send() error!" << std::endl;
//perror("send");
abort();
return;
}
-
+
// assert (bytes_sent <= sendbuf.size());
sendq.erase(0, bytes_sent);
Stats::network_bytes_sent += bytes_sent;
@@ -334,7 +334,7 @@ void NetConnection::send_raw(std::string const &msg)
* priv <text>
*/
-// send a "connect" message to the server
+// send a "connect" message to the server
void NetConnection::send_connect()
{
std::ostringstream msg;
@@ -441,18 +441,18 @@ void NetConnection::send_info_request(Info *info)
void NetConnection::parse_incoming_message(const std::string & message)
{
std::istringstream msgstream(message);
-
+
std::string command;
msgstream >> command;
-
+
if (command == "msg") {
std::string level;
if (msgstream >> level) {
- if (level =="info") {
+ if (level == "info") {
if (message.size() > 9) {
application()->notify_message(Message::Info, message.substr(9));
}
- } else if (level =="rcon") {
+ } else if (level == "rcon") {
if (message.size() > 9) {
application()->notify_message(Message::RCon, message.substr(9));
}
@@ -465,7 +465,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
// FIXME - separate sender nickname
if (message.size() > 12) {
application()->notify_message(Message::Private, message.substr(12));
- }
+ }
} else if (level == "snd") {
if (message.size() > 8) {
application()->notify_sound(message.substr(8).c_str());
@@ -503,7 +503,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
if (msgstream >> id) {
//con_debug << "Received die entity id " << id << std::endl;
Entity *e = Entity::find(id);
- if (localcontrol() == e)
+ if (localcontrol() == e)
localplayer()->set_control(0);
if (e)
Entity::erase(id);
@@ -525,26 +525,25 @@ void NetConnection::parse_incoming_message(const std::string & message)
Entity *entity = Entity::find(id);
if (!entity) {
- switch (type)
- {
- case Entity::Default:
- entity = new Entity(msgstream);
- break;
- case Entity::Dynamic:
- entity = new EntityDynamic(msgstream);
- break;
- case Entity::Controlable:
- entity = new EntityControlable(msgstream);
- break;
- case Entity::Globe:
- entity = new EntityGlobe(msgstream);
- break;
- default:
- con_warn << "Received create for unknown entity type " << type << "!" << std::endl;
- return;
- break;
+ switch (type) {
+ case Entity::Default:
+ entity = new Entity(msgstream);
+ break;
+ case Entity::Dynamic:
+ entity = new EntityDynamic(msgstream);
+ break;
+ case Entity::Controlable:
+ entity = new EntityControlable(msgstream);
+ break;
+ case Entity::Globe:
+ entity = new EntityGlobe(msgstream);
+ break;
+ default:
+ con_warn << "Received create for unknown entity type " << type << "!" << std::endl;
+ return;
+ break;
}
-
+
Entity::add(entity, id);
}
@@ -560,7 +559,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
con_warn << "Received menu for NULL entity!" << std::endl;
return;
}
-
+
Entity *entity = Entity::find(id);
if (!entity) {
con_warn << "Received menu for unknown entity " << id << "!" << std::endl;
@@ -591,7 +590,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
if (id) {
//con_debug << "Received zone " << id << std::endl;
Zone * zone = Zone::find(id);
-
+
// create the zone if necessary
if (!zone) {
zone = new Zone(msgstream);
@@ -618,18 +617,18 @@ void NetConnection::parse_incoming_message(const std::string & message)
if (!player_id) {
Zone *oldzone = connection()->localplayer()->zone();
connection()->localplayer()->receive_server_update(msgstream);
-
+
//con_debug << "zone " << ( connection()->localplayer()->zone() ? connection()->localplayer()->zone()->id() : 0) << std::endl;
-
+
if (connection()->localplayer()->zonechange() && oldzone && (oldzone != connection()->localplayer()->zone())) {
-
+
// notify the applciation to clear none-core zone assets (textures etc)
application()->notify_zonechange();
-
+
// delete all entities in the old zone
- for (Entity::Registry::iterator it=Entity::registry().begin(); it != Entity::registry().end(); ) {
+ for (Entity::Registry::iterator it = Entity::registry().begin(); it != Entity::registry().end();) {
Entity *entity = (*it).second;
-
+
if ((entity->zone() == oldzone)) {
delete entity;
Entity::registry().erase(it++);
@@ -640,7 +639,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
oldzone->content().clear();
}
- // short "pif" message about a different player
+ // short "pif" message about a different player
} else if (player_id != localplayer()->id()) {
// find player
@@ -648,7 +647,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
// search other players
for (GameInterface::Players::iterator it = game()->players().begin(); it != game()->players().end() && !player; it++) {
- if( (*it)->id() == player_id) {
+ if ((*it)->id() == player_id) {
player = (*it);
}
}
@@ -664,7 +663,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
} else if (command == "pid") {
con_debug << "Received player disconnect info" << std::endl;
-
+
int player_id;
if (!(msgstream >> player_id)) {
con_warn << "Received illegal player disconnect message!" << std::endl;
@@ -680,7 +679,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
// search other players
Player *player = 0;
for (GameInterface::Players::iterator it = game()->players().begin(); it != game()->players().end() && !player; it++) {
- if( (*it)->id() == player_id) {
+ if ((*it)->id() == player_id) {
game()->players().erase(it);
return;
}
@@ -691,9 +690,9 @@ void NetConnection::parse_incoming_message(const std::string & message)
std::string label;
char c;
- while ( (msgstream.get(c)) && (c != '"'));
- while ( (msgstream.get(c)) && (c != '"'))
- label += c;
+ while ((msgstream.get(c)) && (c != '"'));
+ while ((msgstream.get(c)) && (c != '"'))
+ label += c;
if (label.size()) {
Info *info = Info::find(label);
@@ -708,8 +707,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
con_warn << "Received empty information record!" << std::endl;
}
} else if (command == "sup") {
- if (connection_state == Connected)
- {
+ if (connection_state == Connected) {
unsigned int id;
if (msgstream >> id) {
//con_debug << "Received update entity id " << id << std::endl;