diff options
-rw-r--r-- | src/core/netserver.cc | 20 | ||||
-rw-r--r-- | src/core/netserver.h | 3 |
2 files changed, 14 insertions, 9 deletions
diff --git a/src/core/netserver.cc b/src/core/netserver.cc index c9870c5..3b17a65 100644 --- a/src/core/netserver.cc +++ b/src/core/netserver.cc @@ -256,7 +256,12 @@ NetClient * NetServer::client_connect(std::string const host, int const port) } clients.push_back(client); - + client->player()->player_dirty = false; + return client; +} + +void NetServer::client_initialize(NetClient *client) { + // send welcome message std::ostringstream netmsg; netmsg.str(""); @@ -266,7 +271,7 @@ NetClient * NetServer::client_connect(std::string const host, int const port) // send entities std::map<unsigned int, Entity *>::iterator it; - for (it=Entity::registry.begin(); it != Entity::registry.end(); it++) { + for (it=Entity::registry.begin(); it != Entity::registry.end(); it++) { netmsg.str(""); switch ((*it).second->type()) { case Entity::Default: @@ -283,11 +288,10 @@ NetClient * NetServer::client_connect(std::string const host, int const port) break; } } - client->transmit(fd()); - - client->player()->player_dirty = false; + netmsg.str("connect\n"); + client->send(netmsg.str()); - return client; + client->transmit(fd()); } void NetServer::send(NetClient * client, std::string const & message) @@ -353,11 +357,9 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me if (client->state() == NetClient::Connecting) { client->client_state = NetClient::Connected; + client_initialize(client); server()->player_connect(client->player()); - std::string netmsg("connect\n"); - client->send(netmsg); - } else if ((client->state() == NetClient::Connected) && (client->player()->name() != oldname)) { std::string netmsg(oldname); diff --git a/src/core/netserver.h b/src/core/netserver.h index df098df..de923b9 100644 --- a/src/core/netserver.h +++ b/src/core/netserver.h @@ -63,6 +63,9 @@ protected: /// called when a new client connects NetClient *client_connect(std::string const host, int const port); + /// called when a client has send the intial handshake + void client_initialize(NetClient *client); + /// remove terminated clients void reap(); |