Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/gameserver.cc6
-rw-r--r--src/core/netclient.cc20
-rw-r--r--src/core/netclient.h9
3 files changed, 33 insertions, 2 deletions
diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc
index 839ed03..985fac4 100644
--- a/src/core/gameserver.cc
+++ b/src/core/gameserver.cc
@@ -258,6 +258,7 @@ void GameServer::frame(float seconds)
entity->entity_dirty = false;
}
+ // update player info
for (std::list<NetClient *>::iterator it = server_network->clients.begin(); it != server_network->clients.end(); it++) {
NetClient *client = *it;
if (client->player()->dirty()) {
@@ -271,6 +272,11 @@ void GameServer::frame(float seconds)
client->player()->player_dirty = false;
}
}
+
+ // transmit buffered sends
+ for (std::list<NetClient *>::iterator it = server_network->clients.begin(); it != server_network->clients.end(); it++) {
+ (*it)->transmit();
+ }
} else {
diff --git a/src/core/netclient.cc b/src/core/netclient.cc
index 7b5d554..937cf21 100644
--- a/src/core/netclient.cc
+++ b/src/core/netclient.cc
@@ -26,6 +26,9 @@ NetClient::NetClient(int clientfd, std::string host, int port) :
client_host = host;
client_port = port;
+
+ sendq.clear();
+ messageblock.clear();
}
NetClient::~NetClient()
@@ -87,4 +90,21 @@ void NetClient::receive()
datablock.clear();
}
+void NetClient::send(std::string const &msg)
+{
+ sendq.append(msg);
+}
+
+void NetClient::transmit()
+{
+ while (sendq.size() && !error()) {
+ TCPClient::send(sendq.substr(0, net::FRAMESIZE-1));
+ if (sendq.size() < net::FRAMESIZE) {
+ sendq.clear();
+ } else {
+ sendq.erase(0, net::FRAMESIZE-1);
+ }
+ }
+}
+
}
diff --git a/src/core/netclient.h b/src/core/netclient.h
index f06f7c5..23a2787 100644
--- a/src/core/netclient.h
+++ b/src/core/netclient.h
@@ -41,16 +41,21 @@ public:
/// receive incoming data and store messages
void receive();
+
+ /// buffer outgoing data
+ void send(std::string const &msg);
+
+ /// send bufered outgoing data
+ void transmit();
private:
std::string client_host;
int client_port;
Player client_player;
- std::string sendq;
-
std::string messageblock;
std::deque<std::string> recvq;
+ std::string sendq;
};
}