summaryrefslogtreecommitdiff
path: root/server.cpp
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-06-13 13:19:01 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2011-06-13 13:19:01 +0200
commit7add4dd07e17c5a6ba0a2a1d9700d72055b812ae (patch)
tree89039bf48199321f6c2f75958626b2e978322a6f /server.cpp
parent7ff743b857f867180f5c766f0370bde9237932ff (diff)
Send players and updated positions to other players.
Diffstat (limited to 'server.cpp')
-rw-r--r--server.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/server.cpp b/server.cpp
index 77956fa..891708c 100644
--- a/server.cpp
+++ b/server.cpp
@@ -36,11 +36,14 @@ void Server::handle_connect(Connection::p connection) {
% connection->socket.remote_endpoint().address().to_string()).str());
m.send(connection->socket);
- message::Player p(0, Vector3(0, 52, 0), "foooooooooooooooooooooo");
- p.send(connection->socket);
+ message::Player player(connection->get_id(), connection->pos, connection->socket.local_endpoint().address().to_string());
- message::Player p2(1, Vector3(5, 50, 5), "b");
- p2.send(connection->socket);
+ for(std::list<Connection::p>::iterator it = clients.begin(); it != clients.end(); it++) {
+ player.send((*it)->socket);
+ Connection::p c = *it;
+ message::Player other(c->get_id(), c->pos, c->socket.local_endpoint().address().to_string());
+ other.send(connection->socket);
+ }
clients.push_back(connection);
@@ -111,6 +114,13 @@ void Server::handle_pos(Connection::p c) {
chunk.set_data(obj->heights);
chunk.send(c->socket);
}
+ for(std::list<Connection::p>::iterator it = clients.begin(); it != clients.end(); it++) {
+ if(*it == c)
+ continue;
+
+ message::Pos p(c->get_id(), c->pos);
+ p.send((*it)->socket);
+ }
}
void Server::handle_chunk(Connection::p c) {