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.cc130
1 files changed, 72 insertions, 58 deletions
diff --git a/src/core/netserver.cc b/src/core/netserver.cc
index 65388e8..6ba9dc7 100644
--- a/src/core/netserver.cc
+++ b/src/core/netserver.cc
@@ -506,12 +506,12 @@ void NetServer::send_entity_delete(NetClient *client, Entity *entity)
}
}
-// broadcast a "sup" server update entity message to all clients
+// send a "sup" server update entity message to a client
void NetServer::send_entity_update(NetClient *client, Entity *entity)
{
if ((client->state() == NetClient::Connected) && !entity->serverside()) {
std::ostringstream msg;
- msg << "sup " << entity->id() << " ";
+ msg << "sup " << entity->id() << " " << entity->type() << " ";
entity->serialize_server_update(msg);
msg << '\n';
@@ -584,6 +584,8 @@ void NetServer::send_info_update(NetClient *client, Info *info)
* ping
* say <text>
* priv <player> <text>
+ * info <id> <typelabel> <label>
+ * req <id>
*
*/
void NetServer::parse_incoming_message(NetClient *client, const std::string & message)
@@ -596,15 +598,15 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
std::string command;
msgstream >> command;
- // disconnect
- if (command == "disconnect") {
+ if (command.compare("disconnect") == 0 ) {
+ // disconnect
client->abort();
return;
- }
-
- // connection request
- // connect is the first command expected from the client
- if (command == "connect") {
+
+ } else if (command.compare("connect") == 0) {
+ // connection request
+ // connect is the first command expected from the client
+
if (client->state() != NetClient::Connecting)
return;
@@ -631,11 +633,11 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
send_disconnect(client);
}
return;
- }
-
- // pif - update player information
- // client connection is completed on the first pif
- if (command == "pif") {
+
+ } else if (command.compare("pif") == 0) {
+ // pif - update player information
+ // client connection is completed on the first pif
+
std::string oldname(client->player()->name());
client->player()->receive_client_update(msgstream);
@@ -652,9 +654,8 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
netmsg.append(client->player()->name());
server()->broadcast(netmsg);
}
- }
-
- if (command == "ping") {
+
+ } else if (command.compare("ping") == 0) {
unsigned long timestamp;
if (msgstream >> timestamp) {
client->player()->set_ping(application()->timestamp() - server()->startup() - timestamp);
@@ -665,16 +666,63 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
if (client->state() != NetClient::Connected)
return;
- // cmd
- if (command == "cmd") {
+ if (command.compare("cmd") == 0) {
if (message.size() > command.size() + 1) {
std::string cmdline(message.substr(command.size() + 1));
server()->exec(client->player(), cmdline);
}
return;
- }
- if (command == "inf") {
+ } else if (command.compare("cup") == 0) {
+ // cup - client update entity
+
+ //con_debug << message << "\n";
+ unsigned int id;
+ if (msgstream >> id) {
+ Entity *entity = Entity::find(id);
+ if (!entity) {
+ con_warn << client->host() << ":" << client->port() << " update for unknown entity " << id << "\n";
+ return;
+ }
+
+ if (entity->type() != Entity::Controlable) {
+ con_warn << client->host() << ":" << client->port() << " update for non-controlable entity " << id << "\n";
+ return;
+ }
+
+ EntityControlable *entitycontrolable = (EntityControlable *)entity;
+
+ if (entitycontrolable->owner() != client->player()) {
+ con_warn << client->host() << ":" << client->port() << " update for non-owned entity " << id << "\n";
+ return;
+ }
+
+ entitycontrolable->set_dirty(true);
+ entitycontrolable->receive_client_update(msgstream);
+ }
+ return;
+
+ } else if (command.compare("req") == 0) {
+
+ // request entity
+ unsigned int id;
+
+ if (!(msgstream >> id)) {
+ con_warn << "^B" << client->player()->name() << "^W invalid entity request" << std::endl;
+ return;
+ }
+
+ Entity *entity = Entity::find(id);
+ if (entity) {
+ send_entity_create(client, entity);
+ } else {
+ con_warn << "^B" << client->player()->name() << "^W entity request for unkown entity " << id << std::endl;
+ }
+ return;
+
+ } else if (command.compare("inf") == 0) {
+
+ // request information record
unsigned int id;
if (!(msgstream >> id)) {
@@ -726,9 +774,8 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
send_info_update(client, info);
client->transmit();
}
- }
- if (command == "rcon") {
+ } else if (command.compare("rcon") == 0) {
if ((message.size() > command.size() + 1) && Cvar::sv_password->str().size()) {
if ((Cvar::sv_password->str().compare(client->player()->rconpassword()) == 0)) {
con_print << "^B" << client->player()->name() << "^F rcon: " << message.substr(command.size() + 1) << std::endl;
@@ -754,46 +801,13 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
}
return;
- }
- // cup - client update entity
- if (command == "cup") {
- //con_debug << message << "\n";
- unsigned int id;
- if (msgstream >> id) {
- Entity *entity = Entity::find(id);
- if (!entity) {
- con_warn << client->host() << ":" << client->port() << " update for unknown entity " << id << "\n";
- return;
- }
-
- if (entity->type() != Entity::Controlable) {
- con_warn << client->host() << ":" << client->port() << " update for non-controlable entity " << id << "\n";
- return;
- }
-
- EntityControlable *entitycontrolable = (EntityControlable *)entity;
-
- if (entitycontrolable->owner() != client->player()) {
- con_warn << client->host() << ":" << client->port() << " update for non-owned entity " << id << "\n";
- return;
- }
-
- entitycontrolable->set_dirty(true);
- entitycontrolable->receive_client_update(msgstream);
- }
- return;
- }
-
- // say
- if (command == "say") {
+ } else if (command.compare("say") == 0 ) {
if (message.size() > command.size() + 1) {
server()->say(client->player(), message.substr(command.size() + 1));
}
return;
- }
- // priv
- if (command == "priv") {
+ } else if (command.compare("priv") == 0 ) {
if (message.size() > command.size() + 1) {
server()->private_message(client->player(), message.substr(command.size() + 1));
}