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-02-16 14:31:02 +0000
committerStijn Buys <ingar@osirion.org>2008-02-16 14:31:02 +0000
commitd198b7b8d9ff713d891f35ab173d1f428f610e7d (patch)
tree6a1f76ee5788ee3dfac858e2c8233207637c01bc /src/core/netserver.cc
parentd6ee7ec642cc6b3097c8d321a1a00630e24027d1 (diff)
code cleanup
Diffstat (limited to 'src/core/netserver.cc')
-rw-r--r--src/core/netserver.cc40
1 files changed, 15 insertions, 25 deletions
diff --git a/src/core/netserver.cc b/src/core/netserver.cc
index 072e790..08863df 100644
--- a/src/core/netserver.cc
+++ b/src/core/netserver.cc
@@ -58,8 +58,12 @@ void NetServer::client_connect(int const clientfd, std::string const host, int c
FD_SET(client->fd(), &serverset);
// TODO send infos
+ con_print << client->host() << ":" << client->port() << " " << client->player().name << " connected."<< std::endl;
- con_print << client->host() << ":" << client->port() << " connected."<< std::endl;
+ // BROADCAST connect message
+ std::ostringstream osstream;
+ osstream << "msg info " << client->player().name << " connected."<< std::endl;
+ broadcast(osstream.str(), clientfd);
// notify the game
if (game() && game()->connected) {
@@ -67,11 +71,6 @@ void NetServer::client_connect(int const clientfd, std::string const host, int c
} else {
// TODO send disconnect message and remove client
}
-
- // BROADCAST connect message
- std::ostringstream osstream;
- osstream << "msg info " << client->player().name << " connected."<< std::endl;
- broadcast(osstream);
}
// remove disconnected clients
@@ -86,7 +85,7 @@ void NetServer::reap()
// BROADCAST disconnect message
std::ostringstream osstream;
osstream << "msg info " << client->player().name << " disconnected."<< std::endl;
- broadcast(osstream);
+ broadcast(osstream.str());
// notify the game
if (core::game())
@@ -147,29 +146,20 @@ void NetServer::frame(float seconds) {
reap();
}
-// send a message to one client
-void NetServer::send(NetClient * client, std::ostringstream &osstream) {
- // FIXME large messages
- //std::cout << "NetServer: " << osstream.str();
- client->send(osstream.str());
- osstream.str("");
-}
-
-void NetServer::send(NetClient * client, std::string message) {
- //std::cout << "NetServer: " << message;
+void NetServer::send(NetClient * client, std::string const & message)
+{
client->send(message);
}
// send a message to all clients
-void NetServer::broadcast(std::ostringstream &osstream, int ignorefd)
+void NetServer::broadcast(std::string const & message, int ignorefd)
{
//std::cout << "NetServer: " << osstream.str();
for (std::list<NetClient *>::iterator it = clients.begin(); it != clients.end(); it++) {
NetClient *client = *it;
if (!client->error() && client->fd() != ignorefd)
- client->send(osstream.str());
+ client->send(message);
}
- osstream.str("");
}
// find the client corresponding to a player id
@@ -212,7 +202,7 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
if (message.size() > command.size()+1) {
std::ostringstream osstream;
osstream << "msg public " << client->player().name << " " << message.substr(command.size()+1) << "\n";
- broadcast(osstream);
+ broadcast(osstream.str());
con_print << client->player().name << " " << message.substr(command.size()+1) << std::endl;
}
return;
@@ -227,8 +217,8 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
if (name != client->player().name) {
std::ostringstream osstream;
osstream << "msg info " << client->player().name << " renamed to " << name << "\n";
- broadcast(osstream);
- con_print << "name " << name << std::endl;
+ broadcast(osstream.str());
+ con_print << client->player().name << " renamed to " << name << std::endl;
client->player().name = name;
}
}
@@ -241,7 +231,7 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
osstream << "msg info " << (*it)->player().name << " " << (*it)->host() << ":" << (*it)->port() << "\n";
}
osstream << "msg info " << clients.size() << " connected players\n" << std::endl;
- send(client, osstream);
+ send(client, osstream.str());
}
if (command == "help") {
@@ -279,7 +269,7 @@ void NetServer::parse_client_variable(NetClient * client, const std::string varn
name = name.substr(0,16);
if (name != client->player().name) {
osstream << "msg info " << client->player().name << " renamed to " << name << "\n";
- broadcast(osstream);
+ broadcast(osstream.str());
client->player().name = name;
}
}