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.cc90
1 files changed, 28 insertions, 62 deletions
diff --git a/src/core/netserver.cc b/src/core/netserver.cc
index 39548dd..ba8510d 100644
--- a/src/core/netserver.cc
+++ b/src/core/netserver.cc
@@ -8,6 +8,7 @@
#include <sstream>
#include "sys/sys.h"
+#include "core/gameserver.h"
#include "core/netclient.h"
#include "core/netserver.h"
#include "core/cvar.h"
@@ -20,6 +21,7 @@ namespace core
NetServer::NetServer(std::string const host, unsigned int const port) :
net::TCPServer(host, port)
{
+ //con_print << "Initializing network server..." << std::endl;
FD_ZERO(&serverset);
// add the listening socket to the file descriptor set
FD_SET(fd(), &serverset);
@@ -29,16 +31,16 @@ NetServer::NetServer(std::string const host, unsigned int const port) :
NetServer::~NetServer()
{
- con_print << "Shutting down network..." << std::endl;
+ con_print << "Shutting down network server..." << std::endl;
// delete all clients
std::list<NetClient *>:: iterator it;
for (it = clients.begin(); it != clients.end(); it++) {
- // notify the game
- if (game() && game()->connected) {
- core::game()->player_disconnect((*it)->player());
- con_print << (*it)->player()->name() << " disconnected."<< std::endl;
- }
+ // notify the game server
+ server()->player_disconnect((*it)->player());
+
+ con_print << " " << (*it)->host() << ":" << (*it)->port() << " disconnected.\n";
+
delete (*it);
}
clients.clear();
@@ -48,8 +50,7 @@ void NetServer::client_connect(int const clientfd, std::string const host, int c
{
NetClient *client = new NetClient(clientfd, host, port);
if (client->error()) {
- con_warn << "Client " << client->fd() << " " <<
- client->host() << ":" << client->port() << " connection failed!" << std::endl;
+ con_warn << client->host() << ":" << client->port() << " connection failed!\n";
delete(client);
return;
}
@@ -57,20 +58,11 @@ void NetServer::client_connect(int const clientfd, std::string const host, int c
clients.push_back(client);
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.\n";
- // BROADCAST connect message
- std::ostringstream osstream;
- osstream << "msg info " << client->player()->name() << " connected."<< std::endl;
- broadcast(osstream.str(), clientfd);
+ // notify the game server
+ server()->player_connect(client->player());
- // notify the game
- if (game() && game()->connected) {
- core::game()->player_connect(client->player());
- } else {
- // TODO send disconnect message and remove client
- }
}
// remove disconnected clients
@@ -82,16 +74,9 @@ void NetServer::reap()
if (client->error()) {
FD_CLR(client->fd(), &serverset);
- // BROADCAST disconnect message
- std::ostringstream osstream;
- osstream << "msg info " << client->player()->name() << " disconnected."<< std::endl;
- broadcast(osstream.str());
-
- // notify the game
- if (core::game())
- core::game()->player_disconnect(client->player());
-
- con_print << client->player()->name() << " disconnected."<< std::endl;
+ // notify the game server
+ server()->player_disconnect((*it)->player());
+ con_print << client->host() << ":" << client->port() << " disconnected.\n";
// remove the client
clients.erase(it);
@@ -118,7 +103,7 @@ void NetServer::frame(float seconds) {
if (nb == -1) {
con_error << "Network error on select()" << std::endl;
- perror("select");
+ //perror("select");
abort();
}
@@ -244,40 +229,21 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
}
// execute game functions
- if (game() && game()->connected) {
- Func *function = Func::find(command);
- if (function ) {
- std::string args;
- char c;
- if (msgstream >> args)
- while (msgstream >> c)
- args += c;
- if (function ->flags() && Func::Game) {
- function->exec(client->player(), args);
- } else {
- // instant rcon
- //function->exec(args);
- }
+ Func *function = Func::find(command);
+ if (function ) {
+ std::string args;
+ char c;
+ if (msgstream >> args)
+ while (msgstream >> c)
+ args += c;
+ if (function ->flags() && Func::Game) {
+ function->exec(client->player(), args);
+ } else {
+ // FIXME instant rcon
+ function->exec(args);
}
}
-}
-void NetServer::parse_client_variable(NetClient * client, const std::string varname, std::istringstream &istringstream)
-{
- if (varname=="name") {
- std::string name;
- if (istringstream >> name) {
- std::ostringstream osstream;
- if (name.size() > 16)
- name = name.substr(0,16);
- if (name != client->player()->name()) {
- osstream << "msg info " << client->player()->name() << " renamed to " << name << "\n";
- broadcast(osstream.str());
- client->player()->player_name = name;
- }
- }
- return;
- }
}
}