From 7add4dd07e17c5a6ba0a2a1d9700d72055b812ae Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Mon, 13 Jun 2011 13:19:01 +0200 Subject: Send players and updated positions to other players. --- server.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'server.cpp') 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::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::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) { -- cgit v1.2.3