Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/application.cc16
-rw-r--r--src/core/application.h1
-rw-r--r--src/core/gameconnection.cc8
-rw-r--r--src/core/gameconnection.h5
-rw-r--r--src/core/gameserver.cc57
-rw-r--r--src/core/gameserver.h8
-rw-r--r--src/core/message.h9
-rw-r--r--src/core/net.h2
-rw-r--r--src/core/netclient.cc4
-rw-r--r--src/core/netconnection.cc19
-rw-r--r--src/core/netconnection.h5
-rw-r--r--src/core/netserver.cc36
12 files changed, 145 insertions, 25 deletions
diff --git a/src/core/application.cc b/src/core/application.cc
index c731833..ec7e89c 100644
--- a/src/core/application.cc
+++ b/src/core/application.cc
@@ -202,8 +202,11 @@ void Application::init(int count, char **arguments)
func = Func::add("disconnect", Application::func_disconnect);
func->set_info("leave the current game");
+ func = Func::add("shout", Application::func_shout);
+ func->set_info("shout [text] shout something on the global chat");
+
func = Func::add("say", Application::func_say);
- func->set_info("say [text] say something on the public chat");
+ func->set_info("say [text] say something on the local chat");
func = Func::add("msg", Application::func_msg);
func->set_info("msg [player] [text] send a private message to another player");
@@ -518,6 +521,17 @@ void Application::func_disconnect(std::string const &args)
Application::instance()->disconnect();
}
+void Application::func_shout(std::string const &args)
+{
+ if (connection()) {
+ connection()->shout(args);
+ } else if (server()) {
+ server()->shout(localplayer(), args);
+ } else {
+ con_print << "Not connected." << std::endl;
+ }
+}
+
void Application::func_say(std::string const &args)
{
if (connection()) {
diff --git a/src/core/application.h b/src/core/application.h
index fbaba9d..37b70c2 100644
--- a/src/core/application.h
+++ b/src/core/application.h
@@ -127,6 +127,7 @@ private:
static void func_quit(std::string const &args);
static void func_connect(std::string const &args);
static void func_disconnect(std::string const &args);
+ static void func_shout(std::string const &args);
static void func_say(std::string const &args);
static void func_msg(std::string const &args);
static void func_load(std::string const &args);
diff --git a/src/core/gameconnection.cc b/src/core/gameconnection.cc
index dee506a..ebd5a49 100644
--- a/src/core/gameconnection.cc
+++ b/src/core/gameconnection.cc
@@ -162,6 +162,14 @@ void GameConnection::say(std::string const &args)
connection_network->send_say(args);
}
+void GameConnection::shout(std::string const &args)
+{
+ if (!connection_network->connected())
+ return;
+
+ connection_network->send_shout(args);
+}
+
void GameConnection::private_message(std::string const &args)
{
if (!connection_network->connected())
diff --git a/src/core/gameconnection.h b/src/core/gameconnection.h
index fdd5daf..1cc6deb 100644
--- a/src/core/gameconnection.h
+++ b/src/core/gameconnection.h
@@ -31,7 +31,10 @@ public:
/// forward a remote console command
void rcon(std::string const &cmdline);
- /// localplayer sends a chat message to the public channel
+ /// localplayer sends a chat message to the global chat channel
+ void shout(std::string const &args);
+
+ /// localplayer sends a chat message to the local chat channel
void say(std::string const &args);
/// localplayer sends a private message to another player
diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc
index 1bd0dbe..d6f9029 100644
--- a/src/core/gameserver.cc
+++ b/src/core/gameserver.cc
@@ -255,7 +255,8 @@ Inventory *GameServer::request_inventory(Entity *entity)
}
-void GameServer::say(Player *player, std::string const &message)
+// global chat message
+void GameServer::shout(Player *player, std::string const &message)
{
if (!message.size())
return;
@@ -265,14 +266,39 @@ void GameServer::say(Player *player, std::string const &message)
return;
}
+ // TODO strip color codes if requested
std::string notification("^B");
notification.append(player->name());
- notification.append("^F:^N ");
+ notification.append("^B: ");
notification.append(message);
broadcast(Message::Public, notification);
}
+// local chat message
+void GameServer::say(Player *player, std::string const &message)
+{
+ if (!message.size())
+ return;
+
+ if(!player->zone())
+ return;
+
+ if (player->mute()) {
+ player->send("^WYou have been muted");
+ return;
+ }
+
+ // TODO strip color codes if requested
+ std::string notification("^B");
+ notification.append(player->name());
+ notification.append("^B:^N ");
+ notification.append(message);
+
+ broadcast(player->zone(), notification);
+}
+
+// player-to-player chat messages
void GameServer::private_message(Player *player, std::string const &args)
{
if (!args.size())
@@ -346,6 +372,29 @@ void GameServer::broadcast(const Message::Channel channel, const std::string tex
}
}
+// broadcast a message to all players in a particular zone
+void GameServer::broadcast(Zone *zone, std::string const text, Player *ignore_player)
+{
+ if (!text.size())
+ return;
+
+ for (Players::iterator it = players().begin(); it != players().end(); it++) {
+ Player *player = (*it);
+ if ((player->zone() == zone) && (player != ignore_player)) {
+ Player *player = (*it);
+ player->message(Message::Local, text);
+ }
+ }
+
+ // console is not in the player list
+ if (Cvar::sv_dedicated->value()) {
+ std::string notification(zone->label());
+ notification += ' ';
+ notification.append(text);
+ localplayer()->message(Message::Local, notification);
+ }
+}
+
// broadcast a sound event to all players
void GameServer::broadcast_sound(const std::string name, Player *ignore_player)
{
@@ -418,11 +467,13 @@ void GameServer::player_connect(Player *player)
player->player_id = server_maxplayerid++;
+ /*
std::string message("^B");
message.append(player->name());
message.append("^B connects.");
broadcast(message, player);
-
+ */
+
// notify the game module
server_module->player_connect(player);
diff --git a/src/core/gameserver.h b/src/core/gameserver.h
index f0cf88b..ab2bf92 100644
--- a/src/core/gameserver.h
+++ b/src/core/gameserver.h
@@ -43,7 +43,10 @@ public:
/// run a game server time frame
void frame(unsigned long timestamp);
- /// a player sends a chat message to the public channel
+ /// a player sends a chat message to the global chat channel
+ void shout(Player *player, std::string const &args);
+
+ /// a player sends a chat message to the local chat channel
void say(Player *player, std::string const &args);
/// a player sends a private message to another player
@@ -54,6 +57,9 @@ public:
/// broadcast an Info message to all players
void broadcast(std::string const message, Player *ignore_player = 0);
+
+ /// broadcast an Info message to all players in a particular zone
+ void broadcast(Zone *zone, std::string const message, Player *ignore_player = 0);
/// broadcast a message to all players on a specified channel
void broadcast(Message::Channel const channel, std::string const message, Player *ignore_player = 0);
diff --git a/src/core/message.h b/src/core/message.h
index 3c53439..bab095d 100644
--- a/src/core/message.h
+++ b/src/core/message.h
@@ -14,7 +14,14 @@ class Message
{
public:
- /// indicates the type of message
+ /**
+ * @brief indicates the type of message
+ * Info info messages from the server to the player
+ * Public public global chat
+ * Local public local (zone) chat
+ * Private player to player private messages
+ * RCon rcon messages
+ */
enum Channel {Info = 0, Public = 1, Local = 2, Private = 3, RCon = 4};
};
diff --git a/src/core/net.h b/src/core/net.h
index f89d0d8..4607797 100644
--- a/src/core/net.h
+++ b/src/core/net.h
@@ -11,7 +11,7 @@ namespace core
{
/// network protocol version
-const unsigned int PROTOCOLVERSION = 21;
+const unsigned int PROTOCOLVERSION = 22;
/// maximum lenght of a (compressed) network message block
const unsigned int FRAMESIZE = 1152;
diff --git a/src/core/netclient.cc b/src/core/netclient.cc
index 46694a6..01de8b8 100644
--- a/src/core/netclient.cc
+++ b/src/core/netclient.cc
@@ -34,7 +34,7 @@ NetClient::NetClient(std::string host, int port, int fd) :
abort();
return;
}
- con_print << host << ":" << port << " connected." << std::endl;
+ con_print << host << ":" << port << " connected" << std::endl;
client_addr.sin_family = AF_INET;
client_addr.sin_port = htons(port);
@@ -58,7 +58,7 @@ NetClient::NetClient(std::string host, int port, int fd) :
NetClient::~NetClient()
{
- con_print << host() << ":" << port() << " disconnected." << std::endl;
+ con_print << host() << ":" << port() << " disconnected" << std::endl;
delete client_player;
}
diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc
index 15e57e2..262c956 100644
--- a/src/core/netconnection.cc
+++ b/src/core/netconnection.cc
@@ -393,10 +393,19 @@ void NetConnection::send_rcon(std::string const &cmdline)
this->send_raw(msg);
}
+// send a "shout" chat message message to the server
+void NetConnection::send_shout(std::string const &text)
+{
+ std::string msg("msg public ");
+ msg.append(text);
+ msg += '\n';
+ this->send_raw(msg);
+}
+
// send a "say" chat message message to the server
void NetConnection::send_say(std::string const &text)
{
- std::string msg("say ");
+ std::string msg("msg local ");
msg.append(text);
msg += '\n';
this->send_raw(msg);
@@ -405,7 +414,7 @@ void NetConnection::send_say(std::string const &text)
// send a "priv" private message to the server
void NetConnection::send_private_message(std::string const &text)
{
- std::string msg("priv ");
+ std::string msg("msg private ");
msg.append(text);
msg += '\n';
this->send_raw(msg);
@@ -604,6 +613,12 @@ void NetConnection::parse_incoming_message(const std::string & message)
if (message.size() > 9) {
application()->notify_message(Message::RCon, message.substr(9));
}
+ } else if (level == "local") {
+ // FIXME - separate zone and sender nickname
+ if (message.size() > 10) {
+ application()->notify_message(Message::Local, message.substr(10));
+ }
+
} else if (level == "public") {
// FIXME - separate sender nickname
if (message.size() > 11) {
diff --git a/src/core/netconnection.h b/src/core/netconnection.h
index ffab093..dc5dc27 100644
--- a/src/core/netconnection.h
+++ b/src/core/netconnection.h
@@ -67,8 +67,11 @@ public:
/// send an entity request
void send_entity_request(Entity *entity);
- /// send a chat message
+ /// send a local chat message
void send_say(std::string const &text);
+
+ /// send a public chat message
+ void send_shout(std::string const &text);
/// send a private message
void send_private_message(std::string const &text);
diff --git a/src/core/netserver.cc b/src/core/netserver.cc
index 937d91b..f58f2d4 100644
--- a/src/core/netserver.cc
+++ b/src/core/netserver.cc
@@ -41,6 +41,8 @@ namespace core
NetServer::NetServer(std::string const host, unsigned int const port)
{
con_print << "^BInitializing network server..." << std::endl;
+
+ con_debug << " protocol version " << PROTOCOLVERSION << std::endl;
// initialize variables
netserver_fd = -1;
@@ -280,7 +282,7 @@ void NetServer::receive()
NetClient * NetServer::client_connect(std::string const host, int const port)
{
- con_print << "Client " << host << ":" << port << " connected\n";
+ //con_print << "Client " << host << ":" << port << " connected\n";
NetClient *client = new NetClient(host, port, fd());
if (client->error()) {
@@ -651,8 +653,7 @@ void NetServer::send_inventory_update(NetClient *client, Entity *entity, const u
* inf
* pif
* ping
- * say <text>
- * priv <player> <text>
+ * msg <channel> <text>
* info <id>
* req <id>
* inv <id>
@@ -863,15 +864,26 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
}
return;
- } else if (command.compare("say") == 0 ) {
- if (message.size() > command.size() + 1) {
- server()->say(client->player(), message.substr(command.size() + 1));
- }
- return;
-
- } else if (command.compare("priv") == 0 ) {
- if (message.size() > command.size() + 1) {
- server()->private_message(client->player(), message.substr(command.size() + 1));
+ } else if (command.compare("msg") == 0 ) {
+ std::string channel;
+ msgstream >> channel;
+
+ if (!channel.size())
+ return;
+
+ const size_t subpos = command.size() + channel.size() + 2;
+ if (message.size() <= subpos)
+ return;
+
+ if (channel.compare("public") == 0) {
+ server()->shout(client->player(), message.substr(subpos));
+
+ } else if (channel.compare("local") == 0) {
+ server()->say(client->player(), message.substr(subpos));
+
+ } else if (channel.compare("private") == 0) {
+
+ server()->say(client->player(), message.substr(subpos));
}
return;
}