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-25 18:30:10 +0000
committerStijn Buys <ingar@osirion.org>2008-07-25 18:30:10 +0000
commit812bb37b7e73104d97da35eb3e66046495aaa305 (patch)
tree63ee32e2c53d35aeb3dc219c8caa211de5fbf0cd
parentabe6c3dc6e6f9df40345d6aaf19f12fdfa3f3024 (diff)
minor cleanups
-rw-r--r--src/client/targets.cc19
-rw-r--r--src/core/entity.cc2
-rw-r--r--src/core/entity.h5
-rw-r--r--src/core/gameserver.cc11
-rw-r--r--src/core/netclient.cc2
-rw-r--r--src/core/netclient.h6
-rw-r--r--src/core/netconnection.cc12
-rw-r--r--src/core/netconnection.h6
-rw-r--r--src/core/netserver.cc48
-rw-r--r--src/core/netserver.h3
-rw-r--r--src/game/game.cc5
11 files changed, 54 insertions, 65 deletions
diff --git a/src/client/targets.cc b/src/client/targets.cc
index 9dd508b..d1bed10 100644
--- a/src/client/targets.cc
+++ b/src/client/targets.cc
@@ -281,7 +281,7 @@ void draw()
cursor -= render::Camera::axis().up() * y;
math::Vector3f center = render::Camera::eye() + (render::Camera::axis().forward() * (render::Camera::frustum_front() +0.01f));
- for (std::map<unsigned int, core::Entity *>::iterator it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) {
+ for (core::Entity::Registry::iterator it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) {
core::Entity *entity = (*it).second;
// render entity sound
@@ -350,23 +350,6 @@ void draw()
render::gl::end();
}
}
-
-/*
- math::Color color(1, 1, 1, 1);
- core::Cvar *cl_crosshaircolor = core::Cvar::get("cl_crosshaircolor", "1 1 1");
- if (cl_crosshaircolor) {
- std::stringstream colorstr(cl_crosshaircolor->str());
- colorstr >> color;
- }
- const float r = 0.05;
- render::gl::color(color);
- render::gl::begin(render::gl::LineLoop);
- render::gl::vertex(cursorposition + render::Camera::axis().up() * r);
- render::gl::vertex(cursorposition + render::Camera::axis().left() * r);
- render::gl::vertex(cursorposition - render::Camera::axis().up() * r);
- render::gl::vertex(cursorposition - render::Camera::axis().left() * r);
- render::gl::end();
-*/
}
}
diff --git a/src/core/entity.cc b/src/core/entity.cc
index bc1c698..c45825b 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -23,7 +23,7 @@ std::map<unsigned int, Entity *> Entity::registry;
void Entity::add(Entity *ent)
{
- std::map<unsigned int, Entity*>::iterator it;
+ Registry::iterator it;
unsigned int id = 1;
for (it = registry.begin(); it != registry.end() && id == (*it).second->id(); it++) {
id++;
diff --git a/src/core/entity.h b/src/core/entity.h
index 0b25dad..d6000b9 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -133,8 +133,11 @@ public:
/*----- static ---------------------------------------------------- */
+ /// type definition for the entity registry
+ typedef std::map<unsigned int, Entity*> Registry;
+
/// the entity registry
- static std::map<unsigned int, Entity*> registry;
+ static Registry registry;
/// find an entity in the registry
static Entity *find(unsigned int id);
diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc
index 1866ad3..afdc269 100644
--- a/src/core/gameserver.cc
+++ b/src/core/gameserver.cc
@@ -119,6 +119,9 @@ GameServer::GameServer() : GameInterface()
return;
}
+ // set the name of the game
+ core::Cvar::set("g_name", server_module->name().c_str(), core::Cvar::Game | core::Cvar::ReadOnly);
+
server_module->init();
if (!server_module->running()) {
con_error << "Could not initialize module '" << server_module->name() << "'\n";
@@ -308,12 +311,8 @@ void GameServer::kick(Player *player, std::string const &reason)
NetClient *client = server_network->find_client(player);
if (client) {
broadcast("^B" + player->name() + "^B has been kicked: " + reason, player);
- send(player, "^WYou have been kicked: " + reason);
-
- client->send("disconnect\n");
- client->transmit(server_network->fd());
-
- client->abort();
+ server_network->send_message(client, "info", "^WYou have been kicked: " + reason);
+ server_network->send_disconnect(client);
} else {
con_print << "Network client not found." << std::endl;
}
diff --git a/src/core/netclient.cc b/src/core/netclient.cc
index 6113f32..fa89e47 100644
--- a/src/core/netclient.cc
+++ b/src/core/netclient.cc
@@ -111,7 +111,7 @@ void NetClient::receive(char *data)
client_timeout = application()->time();
}
-void NetClient::send(std::string const &msg)
+void NetClient::send_raw(std::string const &msg)
{
if (error())
return;
diff --git a/src/core/netclient.h b/src/core/netclient.h
index 39c425f..3671b4e 100644
--- a/src/core/netclient.h
+++ b/src/core/netclient.h
@@ -49,8 +49,8 @@ public:
/// bufer incoming data
void receive(char *data);
- /// buffer outgoing data
- void send(std::string const &msg);
+ /// add a raw network message to the send queue
+ void send_raw(std::string const &msg);
/// return true if there is buffered incoming data
bool has_messages() const;
@@ -58,7 +58,7 @@ public:
/// retreive buffered incoming data
void retreive(std::string & message);
- /// transmit buffered outgoing data
+ /// transmit messages in the send queue to the remote client
void transmit(int serverfd);
inline bool error() const { return client_error; }
diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc
index e415518..1bda423 100644
--- a/src/core/netconnection.cc
+++ b/src/core/netconnection.cc
@@ -313,7 +313,7 @@ void NetConnection::transmit()
}
// queue a mmessage to the server
-void NetConnection::send(std::string const &msg)
+void NetConnection::send_raw(std::string const &msg)
{
sendq.append(msg);
}
@@ -334,7 +334,7 @@ void NetConnection::send_connect()
{
std::ostringstream msg;
msg << "connect " << PROTOCOLVERSION << "\n";
- this->send(msg.str());
+ this->send_raw(msg.str());
}
// send a "pif" player info message to the server
@@ -346,7 +346,7 @@ void NetConnection::send_playerinfo()
msg << "pif ";
localplayer()->serialize_client_update(msg);
msg << '\n';
- this->send(msg.str());
+ this->send_raw(msg.str());
localplayer()->player_dirty = false;
}
@@ -358,7 +358,7 @@ void NetConnection::send_clientupdate(Entity *entity)
msg << "cup " << entity->id() << " ";
entity->serialize_client_update(msg);
msg << '\n';
- this->send(msg.str());
+ this->send_raw(msg.str());
}
// send a "cmd" command line message to the server
@@ -367,7 +367,7 @@ void NetConnection::send_command(std::string const &cmdline)
std::string msg("cmd ");
msg.append(cmdline);
msg += '\n';
- this->send(msg);
+ this->send_raw(msg);
}
// send a "say" chat message message to the server
@@ -376,7 +376,7 @@ void NetConnection::send_say(std::string const &text)
std::string msg("say ");
msg.append(text);
msg += '\n';
- this->send(msg);
+ this->send_raw(msg);
}
// parse incoming client messages
diff --git a/src/core/netconnection.h b/src/core/netconnection.h
index 4e8d9f9..da683f5 100644
--- a/src/core/netconnection.h
+++ b/src/core/netconnection.h
@@ -65,7 +65,7 @@ public:
/// send a command line to the remote server
void send_command(std::string const &cmdline);
- /// transmit messages in the outgoing queue to the remote server
+ /// transmit messages in the send queue to the remote server
void transmit();
void abort();
@@ -91,8 +91,8 @@ public:
State connection_state;
protected:
- /// add a message to the queue
- void send(std::string const &msg);
+ /// add a raw network message to the send queue
+ void send_raw(std::string const &msg);
/// receive incoming data and store messages
void receive();
diff --git a/src/core/netserver.cc b/src/core/netserver.cc
index f004f83..2e50efd 100644
--- a/src/core/netserver.cc
+++ b/src/core/netserver.cc
@@ -110,7 +110,7 @@ NetServer::~NetServer()
if ((*it)->state() == NetClient::Connected)
server()->player_disconnect((*it)->player());
- (*it)->send(netmsg);
+ (*it)->send_raw(netmsg);
(*it)->transmit(fd());
delete (*it);
@@ -138,10 +138,7 @@ void NetServer::reap()
if (client->client_timeout + NETTIMEOUT < application()->time()) {
// client timed out, send a disconnect
- std::string netmsg("disconnect\n");
- (*it)->send(netmsg);
- (*it)->transmit(fd());
- (*it)->abort();
+ send_disconnect((*it));
// print a message
std::string message("^B");
@@ -288,7 +285,7 @@ void NetServer::client_initialize(NetClient *client) {
std::ostringstream netmsg;
netmsg.str("");
netmsg << "msg info ^B" << Cvar::sv_name->str() << "\n";
- client->send(netmsg.str());
+ client->send_raw(netmsg.str());
client->transmit(fd());
// send entities
@@ -298,12 +295,12 @@ void NetServer::client_initialize(NetClient *client) {
netmsg << "ent ";
(*it).second->serialize(netmsg);
netmsg << "\n";
- client->send(netmsg.str());
+ client->send_raw(netmsg.str());
}
// send connect completed
netmsg.str("connect\n");
- client->send(netmsg.str());
+ client->send_raw(netmsg.str());
client->transmit(fd());
// set client state to pending
@@ -350,7 +347,7 @@ void NetServer::broadcast_message(const char *channel, std::string const & messa
for (std::list<NetClient *>::iterator it = clients.begin(); it != clients.end(); it++) {
if (((*it)->player() && (*it)->player() != ignore_player) && ((*it)->state() == NetClient::Connected)) {
- (*it)->send(msg);
+ (*it)->send_raw(msg);
}
}
}
@@ -367,7 +364,16 @@ void NetServer::send_message(NetClient *client, const char *channel, std::string
msg.append(message);
msg += '\n';
- client->send(msg);
+ client->send_raw(msg);
+}
+
+
+// disconnect a client
+void NetServer::send_disconnect(NetClient *client)
+{
+ client->send_raw("disconnect\n");
+ client->transmit(netserver_fd);
+ client->abort();
}
// broadcast a "frame" message to all clients
@@ -378,7 +384,7 @@ void NetServer::broadcast_frame(float timestamp, float previoustimestamp)
for (std::list<NetClient *>::iterator it = clients.begin(); it != clients.end(); it++) {
if ((*it)->state() == NetClient::Connected) {
- (*it)->send(msg.str());
+ (*it)->send_raw(msg.str());
}
}
}
@@ -391,7 +397,7 @@ void NetServer::broadcast_entity_delete(Entity *entity)
for (std::list<NetClient *>::iterator it = clients.begin(); it != clients.end(); it++) {
if ((*it)->state() == NetClient::Connected) {
- (*it)->send(msg.str());
+ (*it)->send_raw(msg.str());
}
}
}
@@ -406,7 +412,7 @@ void NetServer::broadcast_entity_create(Entity *entity)
for (std::list<NetClient *>::iterator it = clients.begin(); it != clients.end(); it++) {
if ((*it)->state() == NetClient::Connected) {
- (*it)->send(msg.str());
+ (*it)->send_raw(msg.str());
}
}
}
@@ -421,7 +427,7 @@ void NetServer::broadcast_entity_update(Entity *entity)
for (std::list<NetClient *>::iterator it = clients.begin(); it != clients.end(); it++) {
if ((*it)->state() == NetClient::Connected) {
- (*it)->send(msg.str());
+ (*it)->send_raw(msg.str());
}
}
}
@@ -438,7 +444,7 @@ void NetServer::broadcast_player_update()
msg << "pif ";
client->player()->serialize_server_update(msg);
msg << '\n';
- client->send(msg.str());
+ client->send_raw(msg.str());
client->player()->player_dirty = false;
}
@@ -452,7 +458,7 @@ void NetServer::send_player_update(NetClient *client)
msg << "pif ";
client->player()->serialize_server_update(msg);
msg << '\n';
- client->send(msg.str());
+ client->send_raw(msg.str());
}
// parse incoming client messages
@@ -501,20 +507,16 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
con_print << client->host() << ":" << client->port() << " " << netmsgstream.str() << std::endl;
send_message(client, "info", netmsgstream.str());
- netmsgstream.str("disconnect\n");
- netmsgstream.clear();
-
- client->send(netmsgstream.str());
- client->transmit(fd());
- client->abort();
+ send_disconnect(client);
} 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);
+ send_message(client, "info", message);
+ send_disconnect(client);
}
return;
}
diff --git a/src/core/netserver.h b/src/core/netserver.h
index 25bca5f..d76676f 100644
--- a/src/core/netserver.h
+++ b/src/core/netserver.h
@@ -58,6 +58,9 @@ public:
/// send a message to a single client
void send_message(NetClient *client, const char *channel, std::string const & message);
+ /// disconnect a single client
+ void send_disconnect(NetClient *client);
+
/// broadcast a server frame message
void broadcast_frame(float timestamp, float previoustimestamp);
diff --git a/src/game/game.cc b/src/game/game.cc
index 8fe2ad4..2d21be8 100644
--- a/src/game/game.cc
+++ b/src/game/game.cc
@@ -328,9 +328,8 @@ void Game::init()
func = core::Func::add("list_ship", (core::FuncPtr) func_list_ship);
func->set_info("list ship statistics");
- // add engine game variables
- core::Cvar::set("g_testgamevariable", "1", core::Cvar::Game);
- core::Cvar::set("g_name", name().c_str(), core::Cvar::Game | core::Cvar::ReadOnly);
+ // set game variables
+ core::Cvar::set("g_impulsespeed", "10.0f", core::Cvar::Game);
// indicate the module is ready to run frames
module_running = true;