Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-07-13 16:37:18 +0000
committerStijn Buys <ingar@osirion.org>2008-07-13 16:37:18 +0000
commit3a3ba622dbf9c035b0f26979601b2d4d192b4167 (patch)
tree1439700a9df9ba1dd32ae1f7ca86c5caa0fd4d1c /src/core/netserver.cc
parent2e789cb9894ac5a9565013b134f1c1e51174f430 (diff)
connection sequence updates, breaks network protocol
Diffstat (limited to 'src/core/netserver.cc')
-rw-r--r--src/core/netserver.cc39
1 files changed, 35 insertions, 4 deletions
diff --git a/src/core/netserver.cc b/src/core/netserver.cc
index 2859006..fe6e45b 100644
--- a/src/core/netserver.cc
+++ b/src/core/netserver.cc
@@ -300,10 +300,14 @@ void NetServer::client_initialize(NetClient *client) {
netmsg << "\n";
client->send(netmsg.str());
}
+
+ // send connect completed
netmsg.str("connect\n");
client->send(netmsg.str());
-
client->transmit(fd());
+
+ // set client state to pending
+ client->client_state = NetClient::Pending;
}
void NetServer::send(NetClient * client, std::string const & message)
@@ -361,15 +365,42 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
return;
}
+ // connection request
+ // connect is the first command expected from the client
+ if (command == "connect") {
+ if (client->state() != NetClient::Connecting)
+ return;
+
+ unsigned int protover;
+ if (msgstream >> protover) {
+ if (protover != PROTOCOLVERSION) {
+ std::stringstream netmsgstream("");
+ netmsgstream << "Protocol version mismatch: ";
+ netmsgstream << "client " << protover << " server " << PROTOCOLVERSION << "!\n";
+
+ con_print << client->host() << ":" << client->port() << " " << netmsgstream.str() << std::endl;
+ server()->send(client->player(), netmsgstream.str());
+ } else {
+ client_initialize(client);
+ }
+ } else {
+ std::string message("Unknown client protocol version!");
+ con_print << client->host() << ":" << client->port() << " " << message << std::endl;
+ server()->send(client->player(), message);
+ client->abort();
+ }
+ return;
+ }
+
// pif - update player information
- // pif is the first command expected from the client
+ // client connection is completed on the first pif
if (command == "pif") {
std::string oldname(client->player()->name());
client->player()->recieve_client_update(msgstream);
- if (client->state() == NetClient::Connecting) {
+ if (client->state() == NetClient::Pending) {
+
client->client_state = NetClient::Connected;
- client_initialize(client);
server()->player_connect(client->player());
} else if ((client->state() == NetClient::Connected) && (client->player()->name() != oldname)) {