Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/netserver.cc')
-rw-r--r--src/core/netserver.cc56
1 files changed, 39 insertions, 17 deletions
diff --git a/src/core/netserver.cc b/src/core/netserver.cc
index c37b71d..072e790 100644
--- a/src/core/netserver.cc
+++ b/src/core/netserver.cc
@@ -35,7 +35,7 @@ NetServer::~NetServer()
std::list<NetClient *>:: iterator it;
for (it = clients.begin(); it != clients.end(); it++) {
// notify the game
- if (core::connected()) {
+ if (game() && game()->connected) {
core::game()->player_disconnect((*it)->player());
con_print << (*it)->player().name << " disconnected."<< std::endl;
}
@@ -59,11 +59,14 @@ void NetServer::client_connect(int const clientfd, std::string const host, int c
// TODO send infos
- con_print << client->player().name << " connected."<< std::endl;
+ con_print << client->host() << ":" << client->port() << " connected."<< std::endl;
// notify the game
- if (core::game())
+ if (game() && game()->connected) {
core::game()->player_connect(client->player());
+ } else {
+ // TODO send disconnect message and remove client
+ }
// BROADCAST connect message
std::ostringstream osstream;
@@ -169,6 +172,28 @@ void NetServer::broadcast(std::ostringstream &osstream, int ignorefd)
osstream.str("");
}
+// find the client corresponding to a player id
+NetClient *NetServer::find_client(Player const &player)
+{
+ for (std::list<NetClient *>::iterator it = clients.begin(); it != clients.end(); it++) {
+ if ((*it)->fd() == (int) player.id) {
+ return (*it);
+ }
+ }
+ return 0;
+}
+
+// parse server messages
+/**
+ * The following incoming messages are parsed;
+ *
+ * disconnect
+ * help
+ * list_players
+ * name
+ * say <text>
+ *
+ */
void NetServer::parse_incoming_message(NetClient *client, const std::string & message)
{
std::stringstream msgstream(message);
@@ -186,7 +211,7 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
if (command == "say") {
if (message.size() > command.size()+1) {
std::ostringstream osstream;
- osstream << "msg public " << client->player().name << " " << message.substr(command.size()+1) << std::endl;
+ osstream << "msg public " << client->player().name << " " << message.substr(command.size()+1) << "\n";
broadcast(osstream);
con_print << client->player().name << " " << message.substr(command.size()+1) << std::endl;
}
@@ -201,10 +226,10 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
name = name.substr(0,16);
if (name != client->player().name) {
std::ostringstream osstream;
- osstream << "msg info " << client->player().name << " renamed to " << name << std::endl;
- broadcast(osstream);
+ osstream << "msg info " << client->player().name << " renamed to " << name << "\n";
+ broadcast(osstream);
+ con_print << "name " << name << std::endl;
client->player().name = name;
- con_print << client->player().name << " renamed to " << name << std::endl;
}
}
return;
@@ -213,9 +238,9 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
if (command == "list_players") {
std::ostringstream osstream;
for (std::list<NetClient *>::iterator it = clients.begin(); it != clients.end(); it++) {
- osstream << "msg info client " << (*it)->player().name << " " << (*it)->host() << ":" << (*it)->port() << std::endl;
+ osstream << "msg info " << (*it)->player().name << " " << (*it)->host() << ":" << (*it)->port() << "\n";
}
- osstream << "msg info client " << clients.size() << " players" << std::endl;
+ osstream << "msg info " << clients.size() << " connected players\n" << std::endl;
send(client, osstream);
}
@@ -232,19 +257,16 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
if (game() && game()->connected) {
Func f = func::find(command);
if (f) {
- if (f->flags && func::Game) {
+ if (f->flags() && func::Game) {
GameFuncPtr function = (GameFuncPtr) f->ptr;
function(client->player(), msgstream);
} else {
- // FIXME rcon
- // FuncPtr function = (FuncPtr) f->ptr;
- // function(msgstream);
+ // instant rcon
+ //FuncPtr function = (FuncPtr) f->ptr;
+ //function(msgstream);
}
- return;
}
}
-
- // TODO rcon
}
void NetServer::parse_client_variable(NetClient * client, const std::string varname, std::istringstream &istringstream)
@@ -256,7 +278,7 @@ void NetServer::parse_client_variable(NetClient * client, const std::string varn
if (name.size() > 16)
name = name.substr(0,16);
if (name != client->player().name) {
- osstream << "msg info " << client->player().name << " renamed to " << name << std::endl;
+ osstream << "msg info " << client->player().name << " renamed to " << name << "\n";
broadcast(osstream);
client->player().name = name;
}