summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
m---------common0
-rw-r--r--connection.cpp7
-rw-r--r--connection.h3
-rw-r--r--server.cpp18
4 files changed, 24 insertions, 4 deletions
diff --git a/common b/common
-Subproject e483f468085379a986cbc48bb13a7983315475c
+Subproject ff7f9de199213ea6d4832c0b91f2a96f5edc6bb
diff --git a/connection.cpp b/connection.cpp
index 3b5076c..613eed0 100644
--- a/connection.cpp
+++ b/connection.cpp
@@ -4,7 +4,10 @@
using std::min;
using std::max;
+uint32_t Connection::next_id = 0;
+
Connection::Connection(boost::asio::io_service& io_service_) : io_service(io_service_), socket(io_service_) {
+ id = ++next_id;
}
float Connection::distance(float px, float pz) {
@@ -57,3 +60,7 @@ std::set<std::pair<int64_t, int64_t> > Connection::check_chunks() {
return new_chunks;
}
+
+uint32_t Connection::get_id() {
+ return id;
+}
diff --git a/connection.h b/connection.h
index 78603e4..cba5031 100644
--- a/connection.h
+++ b/connection.h
@@ -10,6 +10,8 @@
class Connection {
private:
+ static uint32_t next_id;
+ uint32_t id;
boost::asio::io_service& io_service;
public:
@@ -25,6 +27,7 @@ class Connection {
/* data */
Vector3 pos;
std::set<std::pair<int64_t, int64_t> > chunk_indices;
+ uint32_t get_id();
};
#endif
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) {