Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/client.cc11
-rw-r--r--src/client/client.h3
-rw-r--r--src/core/Makefile.am2
-rw-r--r--src/core/application.cc22
-rw-r--r--src/core/application.h3
-rw-r--r--src/core/gameinterface.cc2
-rw-r--r--src/core/gameserver.cc60
-rw-r--r--src/core/gameserver.h7
-rw-r--r--src/core/message.h3
-rw-r--r--src/core/net.h18
-rw-r--r--src/core/netclient.cc2
-rw-r--r--src/core/netclient.h24
-rw-r--r--src/core/netconnection.cc4
-rw-r--r--src/core/netplayer.cc77
-rw-r--r--src/core/netplayer.h42
-rw-r--r--src/core/netserver.cc49
-rw-r--r--src/core/netserver.h5
-rw-r--r--src/core/player.cc20
-rw-r--r--src/core/player.h45
19 files changed, 167 insertions, 232 deletions
diff --git a/src/client/client.cc b/src/client/client.cc
index b514e57..7d4b7e6 100644
--- a/src/client/client.cc
+++ b/src/client/client.cc
@@ -341,11 +341,6 @@ void Client::notify_zonechange()
render::unload();
}
-void Client::notify_sound(const char *name)
-{
- audio::play(name);
-}
-
void Client::notify_message(const char *message)
{
std::string text(message);
@@ -379,6 +374,12 @@ void Client::notify_message(const core::Message::Channel channel, const std::str
audio::play("com/priv");
break;
+ case core::Message::Sound: // Sound event
+
+ audio::play(message.c_str());
+ // a sound event prints nothing to the console
+ return;
+
default:
break;
}
diff --git a/src/client/client.h b/src/client/client.h
index 19a760f..42b87e6 100644
--- a/src/client/client.h
+++ b/src/client/client.h
@@ -39,9 +39,6 @@ public:
/// quit the client
virtual void quit(int status);
- /// sound notifications from the core
- virtual void notify_sound(const char * name);
-
/// text notifications from the core
virtual void notify_message(const core::Message::Channel channel, const std::string &message);
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index c1f4632..4f5011c 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -25,7 +25,6 @@ noinst_HEADERS = \
netclient.h \
netconnection.h \
net.h \
- netplayer.h \
netserver.h \
parser.h \
physics.h \
@@ -55,7 +54,6 @@ libcore_la_SOURCES = \
module.cc \
netclient.cc \
netconnection.cc \
- netplayer.cc \
netserver.cc \
parser.cc \
physics.cc \
diff --git a/src/core/application.cc b/src/core/application.cc
index 38c39a1..2455f85 100644
--- a/src/core/application.cc
+++ b/src/core/application.cc
@@ -452,7 +452,21 @@ void Application::load_commandline(int count, char **arguments)
void Application::notify_message(const core::Message::Channel channel, const std::string &message)
{
- con_print << message << std::endl;
+ switch (channel) {
+ case core::Message::Info: // Info message
+ case core::Message::Local: // Chat message in the local zone
+ case core::Message::Public: // Public chat message
+ case core::Message::Private: // Private chat message
+ case core::Message::RCon: // RCon message
+ con_print << message << std::endl;
+ break;
+
+ case core::Message::Sound: // Sound event
+ break;
+
+ default:
+ break;
+ }
}
void Application::notify_loader(const std::string &message)
@@ -461,12 +475,6 @@ void Application::notify_loader(const std::string &message)
// used by the client to udpate the loader screen
}
-void Application::notify_sound(const char *name)
-{
- // the default implementation does nothing.
- // Dedicated servers don't need sounds
-}
-
void Application::notify_zonechange()
{
// the default implementation does nothing.
diff --git a/src/core/application.h b/src/core/application.h
index 3f71b4c..e846b1f 100644
--- a/src/core/application.h
+++ b/src/core/application.h
@@ -77,9 +77,6 @@ public:
/*----- notifications --------------------------------------------- */
- /// sound notifications from the core to the application
- virtual void notify_sound(const char * name);
-
/// text notifications from the core to the application
virtual void notify_message(const core::Message::Channel channel, const std::string &message);
diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc
index 3505e2c..898d97f 100644
--- a/src/core/gameinterface.cc
+++ b/src/core/gameinterface.cc
@@ -41,7 +41,7 @@ void func_list_players(std::string const &args)
const float MIN_DELTA = 10e-10;
-Player GameInterface::game_localplayer;
+Player GameInterface::game_localplayer(0);
EntityControlable *localcontrol()
{
diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc
index b4b3322..a1102bd 100644
--- a/src/core/gameserver.cc
+++ b/src/core/gameserver.cc
@@ -281,7 +281,7 @@ Inventory *GameServer::request_inventory(Entity *entity)
}
-// global chat message
+// a player sends a global chat message
void GameServer::shout(Player *player, std::string const &message)
{
if (!message.size())
@@ -301,7 +301,7 @@ void GameServer::shout(Player *player, std::string const &message)
broadcast(Message::Public, notification);
}
-// local chat message
+// a player sends a local chat message
void GameServer::say(Player *player, std::string const &message)
{
if (!message.size())
@@ -324,7 +324,7 @@ void GameServer::say(Player *player, std::string const &message)
broadcast(player->zone(), notification);
}
-// player-to-player chat messages
+// a player send a prvate mesage to another player
void GameServer::private_message(Player *player, std::string const &args)
{
if (!args.size())
@@ -347,10 +347,9 @@ void GameServer::private_message(Player *player, std::string const &args)
return;
}
-
- std::string message(args.substr(target.size()));
- player->message(Message::Private, "^FTo ^B" + targetplayer->name() + "^F:" + message);
- targetplayer->message(Message::Private, "^FFrom ^B" + player->name() + "^F:" + message);
+ std::string text(args.substr(target.size()));
+ message(player, Message::Private, "^FTo ^B" + targetplayer->name() + "^F:" + text);
+ message(targetplayer, Message::Private, "^FFrom ^B" + player->name() + "^F:" + text);
}
// FIXME kicked by
@@ -361,24 +360,35 @@ void GameServer::kick(Player *player, std::string const &reason)
return;
}
- NetClient *client = server_network->find_client(player);
+ NetClient *client = player->client();
if (client) {
broadcast("^B" + player->name() + "^B has been kicked: " + reason, player);
- player->send("^WYou have been kicked: " + reason);
+ server_network->send_message(client, Message::Info, "^WYou have been kicked: " + reason);
server_network->send_disconnect(client);
} else {
con_print << "Network client not found" << std::endl;
}
}
-// broadcast an "info" message to all players
-void GameServer::broadcast(const std::string text, Player *ignore_player)
+// server sends a message on a specified channel to a single player
+void GameServer::message(Player *player, const Message::Channel channel, const std::string text)
{
- broadcast(Message::Info, text, ignore_player);
-}
+ if (!text.size())
+ return;
+
+ NetClient *client = player->client();
+ if (client) {
+ // this player is a network client, send message over network
+ server_network->send_message(client, channel, text);
+
+ } else if (player == localplayer()) {
+ // local player, send message to the local application
+ application()->notify_message(channel, text);
+ }
+}
-// broadcast a message on a specified channel to all players
+// server broadcasts a message on a specified channel to all players
void GameServer::broadcast(const Message::Channel channel, const std::string text, Player *ignore_player)
{
if (!text.size())
@@ -386,9 +396,16 @@ void GameServer::broadcast(const Message::Channel channel, const std::string tex
for (Players::iterator it = players().begin(); it != players().end(); it++) {
Player *player = (*it);
+ NetClient *client = player->client();
if (player != ignore_player) {
- Player *player = (*it);
- player->message(channel, text);
+ if (client) {
+ // this player is a network client, send message over network
+ server_network->send_message(client, channel, text);
+
+ } else if (player == localplayer()) {
+ // local player, send message to the local application
+ application()->notify_message(channel, text);
+ }
}
}
@@ -398,7 +415,14 @@ void GameServer::broadcast(const Message::Channel channel, const std::string tex
}
}
-// broadcast a message to all players in a particular zone
+// server broadcasts an "info" message to all players
+void GameServer::broadcast(const std::string text, Player *ignore_player)
+{
+ broadcast(Message::Info, text, ignore_player);
+}
+
+
+// server broadcasts a message to all players in a particular zone
void GameServer::broadcast(Zone *zone, std::string const text, Player *ignore_player)
{
if (!text.size())
@@ -421,7 +445,7 @@ void GameServer::broadcast(Zone *zone, std::string const text, Player *ignore_pl
}
}
-// broadcast a sound event to all players
+// server broadcasts a sound event to all players
void GameServer::broadcast_sound(const std::string name, Player *ignore_player)
{
if (!name.size())
diff --git a/src/core/gameserver.h b/src/core/gameserver.h
index 2e1aa2a..56d0361 100644
--- a/src/core/gameserver.h
+++ b/src/core/gameserver.h
@@ -60,6 +60,11 @@ public:
/// kick a player from the server
void kick(Player *player, std::string const &reason);
+
+ /*----- messages -------------------------------------------------- */
+
+ /// send a message to a single player
+ void message(Player *player, core::Message::Channel channel, const std::string text);
/// broadcast an Info message to all players
void broadcast(std::string const message, Player *ignore_player = 0);
@@ -72,6 +77,8 @@ public:
/// broadcast a sound to all players
void broadcast_sound(std::string const sound, Player *ignore_player = 0);
+
+
/// a player sends a command to the game server
void exec(Player *player, std::string const &cmdline);
diff --git a/src/core/message.h b/src/core/message.h
index bab095d..581dd11 100644
--- a/src/core/message.h
+++ b/src/core/message.h
@@ -21,8 +21,9 @@ public:
* Local public local (zone) chat
* Private player to player private messages
* RCon rcon messages
+ * Sound sound event
*/
- enum Channel {Info = 0, Public = 1, Local = 2, Private = 3, RCon = 4};
+ enum Channel {Info = 0, Public = 1, Local = 2, Private = 3, RCon = 4, Sound = 5};
};
}
diff --git a/src/core/net.h b/src/core/net.h
index 4607797..2dbebfd 100644
--- a/src/core/net.h
+++ b/src/core/net.h
@@ -28,16 +28,26 @@ const float NETTIMEOUT = 15;
}
+#include <unistd.h>
+#include <errno.h>
+
#ifndef _WIN32
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/wait.h>
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
#include <sys/select.h>
+
#else
+
#include <winsock2.h>
#include <windows.h>
-#endif
-#include "core/netserver.h"
-#include "core/netclient.h"
-#include "core/netconnection.h"
+#endif
#endif // __INCLUDED_CORE_NET_H__
diff --git a/src/core/netclient.cc b/src/core/netclient.cc
index 01de8b8..76112e1 100644
--- a/src/core/netclient.cc
+++ b/src/core/netclient.cc
@@ -27,7 +27,7 @@ NetClient::NetClient(std::string host, int port, int fd) :
client_host = host;
client_port = port;
- client_player = new NetPlayer(this);
+ client_player = new Player(this);
if (!fd) {
con_warn << "Network invalid client file descriptor!" << std::endl;
diff --git a/src/core/netclient.h b/src/core/netclient.h
index cca9529..f52aae6 100644
--- a/src/core/netclient.h
+++ b/src/core/netclient.h
@@ -7,32 +7,12 @@
#ifndef __INCLUDED_CORE_NETCLIENT_H__
#define __INCLUDED_CORE_NETCLIENT_H__
-#include "core/net.h"
-
-#include <unistd.h>
-#include <errno.h>
-
-#ifndef _WIN32
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/wait.h>
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#endif
-
-#include <string>
-#include <deque>
-#include <map>
-
namespace core
{
class NetClient;
}
-#include "core/netplayer.h"
+#include "core/net.h"
namespace core
{
@@ -96,7 +76,7 @@ private:
int client_fd;
bool client_error;
- NetPlayer *client_player;
+ Player *client_player;
std::string messageblock;
std::deque<std::string> recvq;
diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc
index 262c956..fd844aa 100644
--- a/src/core/netconnection.cc
+++ b/src/core/netconnection.cc
@@ -631,7 +631,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
}
} else if (level == "snd") {
if (message.size() > 8) {
- application()->notify_sound(message.substr(8).c_str());
+ application()->notify_message(Message::Sound, message.substr(8));
}
}
}
@@ -768,7 +768,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
}
if (!player) {
- player = new Player();
+ player = new Player(0);
game()->players().push_back(player);
game()->set_playerlist_timestamp(game()->timestamp());
}
diff --git a/src/core/netplayer.cc b/src/core/netplayer.cc
deleted file mode 100644
index 9d3e677..0000000
--- a/src/core/netplayer.cc
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- net/netplayer.cc
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
-*/
-
-#include <string>
-
-#include "core/net.h"
-#include "core/netplayer.h"
-#include "sys/sys.h"
-
-namespace core
-{
-
-NetPlayer::NetPlayer(NetClient *client) : Player()
-{
-
- player_client = client;
-}
-
-NetPlayer::~NetPlayer()
-{
-}
-
-void NetPlayer::sound(const std::string name)
-{
- std::string msg("msg snd ");
- msg.append(name);
- msg += '\n';
-
- player_client->send_raw(msg);
-}
-
-void NetPlayer::message(const Message::Channel channel, const std::string text)
-{
- if (!text.size())
- return;
-
- std::string msg_channel;
- switch (channel) {
- case core::Message::Info: // Info message
- msg_channel.assign("info");
- break;
-
- case core::Message::Local: // Chat message in the local zone
- msg_channel.assign("local");
- break;
-
- case core::Message::Public: // Public chat message
- msg_channel.assign("public");
- break;
-
- case core::Message::Private: // Private chat message
- msg_channel.assign("private");
- break;
-
- case core::Message::RCon: // RCon message
- msg_channel.assign("rcon");
- break;
-
- default:
- con_warn << "message on unknown channel " << channel << "!" << std::endl;
- return;
- break;
- }
-
- std::string msg("msg ");
- msg.append(msg_channel);
- msg += ' ';
- msg.append(text);
- msg += '\n';
-
- player_client->send_raw(msg);
-}
-
-}
diff --git a/src/core/netplayer.h b/src/core/netplayer.h
deleted file mode 100644
index ada1bd0..0000000
--- a/src/core/netplayer.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- core/netplayer.h
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
-*/
-
-#ifndef __INCLUDED_CORE_NETPLAYER_H__
-#define __INCLUDED_CORE_NETPLAYER_H__
-
-namespace core
-{
-class NetPlayer;
-}
-
-#include "core/player.h"
-#include "core/netclient.h"
-#include "core/message.h"
-
-namespace core
-{
-
-class NetPlayer : public Player
-{
-public:
- NetPlayer(NetClient *client);
- virtual ~NetPlayer();
-
- NetClient *client() {
- return player_client;
- }
-
- virtual void message(const Message::Channel channel, const std::string text);
- virtual void sound(const std::string name);
-
-private:
- NetClient *player_client;
-};
-
-}
-
-#endif // __INCLUDED_CORE_NETCLIENT_H__
-
diff --git a/src/core/netserver.cc b/src/core/netserver.cc
index 37adfc1..12210a5 100644
--- a/src/core/netserver.cc
+++ b/src/core/netserver.cc
@@ -476,14 +476,46 @@ void NetServer::frame(unsigned long timestamp)
* zone <id> <zone create/update data>
*/
-// send a "msg <channel>" message to one client
-void NetServer::send_message(NetClient *client, const char *channel, std::string const & message)
+// send a message on a specified channel to a single client
+void NetServer::send_message(NetClient *client, const Message::Channel channel, const std::string & message)
{
- if (!channel)
+ if (!message.size())
return;
+ std::string msg_channel;
+ switch (channel) {
+ case core::Message::Info: // Info message
+ msg_channel.assign("info");
+ break;
+
+ case core::Message::Local: // Chat message in the local zone
+ msg_channel.assign("local");
+ break;
+
+ case core::Message::Public: // Public chat message
+ msg_channel.assign("public");
+ break;
+
+ case core::Message::Private: // Private chat message
+ msg_channel.assign("private");
+ break;
+
+ case core::Message::RCon: // RCon message
+ msg_channel.assign("rcon");
+ break;
+
+ case core::Message::Sound: // Sound event
+ msg_channel.assign("snd");
+ break;
+
+ default:
+ con_warn << "message on unknown channel " << channel << "!" << std::endl;
+ return;
+ break;
+ }
+
std::string msg("msg ");
- msg.append(channel);
+ msg.append(msg_channel);
msg += ' ';
msg.append(message);
msg += '\n';
@@ -491,6 +523,7 @@ void NetServer::send_message(NetClient *client, const char *channel, std::string
client->send_raw(msg);
}
+
// disconnect a client
void NetServer::send_disconnect(NetClient *client)
{
@@ -700,7 +733,7 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
netmsgstream << "client " << protover << " server " << PROTOCOLVERSION << "!\n";
con_print << client->host() << ":" << client->port() << " " << netmsgstream.str() << std::endl;
- send_message(client, "info", netmsgstream.str());
+ send_message(client, Message::Info, netmsgstream.str());
send_disconnect(client);
} else {
@@ -710,7 +743,7 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
std::string message("Unknown client protocol version!");
con_print << client->host() << ":" << client->port() << " " << message << std::endl;
- send_message(client, "info", message);
+ send_message(client, Message::Info, message);
send_disconnect(client);
}
@@ -865,7 +898,7 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
core::CommandBuffer::exec();
while (console()->rconbuf().size()) {
- send_message(client, "rcon", (*console()->rconbuf().begin()));
+ send_message(client, Message::RCon, (*console()->rconbuf().begin()));
core::console()->rconbuf().pop_front();
}
@@ -873,7 +906,7 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
console()->set_rcon(false);
} else {
- send_message(client, "info", "rcon access denied");
+ send_message(client, Message::Info, "rcon access denied");
con_warn << "^B" << client->player()->name() << "^W rcon access denied" << std::endl;
}
}
diff --git a/src/core/netserver.h b/src/core/netserver.h
index d8635e4..a739e28 100644
--- a/src/core/netserver.h
+++ b/src/core/netserver.h
@@ -70,9 +70,10 @@ public:
/// find the client corresponding to a player
NetClient *find_client(Player const *player);
+ /// send a message on a specified channel
+ void send_message(NetClient *client, const Message::Channel channel, const std::string & message);
+
protected:
- /// send a message
- void send_message(NetClient *client, const char *channel, std::string const & message);
/// send a server frame marker
void send_frame_marker(NetClient *client, unsigned long timestamp);
diff --git a/src/core/player.cc b/src/core/player.cc
index f183a4c..d07b258 100644
--- a/src/core/player.cc
+++ b/src/core/player.cc
@@ -11,12 +11,15 @@
#include "core/player.h"
#include "core/cvar.h"
#include "core/application.h"
+#include "core/gameserver.h"
namespace core
{
-Player::Player()
+Player::Player(NetClient *client)
{
+ player_client = client;
+
clear();
}
@@ -61,26 +64,21 @@ void Player::print() const
}
-void Player::send(const std::string text)
+void Player::message(Message::Channel channel, const std::string text)
{
- message(core::Message::Info, text);
+ server()->message(this, channel, text);
}
-void Player::send_warning(const std::string text)
+void Player::send(const std::string text)
{
- message(core::Message::Info, text);
- player_warningtime = application()->time();
+ server()->message(this, core::Message::Info, text);
}
void Player::sound(const std::string name)
{
- application()->notify_sound(name.c_str());
+ server()->message(this, core::Message::Sound, name);
}
-void Player::message(Message::Channel channel, const std::string text)
-{
- application()->notify_message(channel, text);
-}
void Player::set_control(EntityControlable *entitycontrolable)
{
diff --git a/src/core/player.h b/src/core/player.h
index dbcc161..afd1bc9 100644
--- a/src/core/player.h
+++ b/src/core/player.h
@@ -15,6 +15,7 @@ class Player;
#include "core/entity.h"
#include "core/message.h"
#include "core/zone.h"
+#include "core/netclient.h"
#include "math/mathlib.h"
#include <string>
@@ -28,9 +29,10 @@ class Player
{
public:
/// default constructor
- Player();
+ Player(NetClient *client);
+
/// default destructor
- virtual ~Player();
+ ~Player();
/*----- inspectors ------------------------------------------------ */
@@ -111,7 +113,7 @@ public:
}
/// print player info to console
- virtual void print() const;
+ void print() const;
/// player level
const int level() const {
@@ -128,27 +130,21 @@ public:
return player_guid;
}
- /*----- messages -------------------------------------------------- */
+ /// network client associated with this player
+ NetClient *client() {
+ return player_client;
+ }
+
+ /*----- server-side mesage functions ------------------------------ */
+ /// send a message to the player on one of the message channels
+ void message(core::Message::Channel channel, const std::string text);
+
/// send a text message
void send(const std::string text);
- /**
- * @brief send a warning message
- * Send the player a warning message abd set the warning
- * message timestamp to the current application time
- * @see last_warning()
- */
- void send_warning(const std::string text);
-
- virtual void sound(const std::string name);
-
- virtual void message(core::Message::Channel channel, const std::string text);
-
- /// time of the last warning message
- float last_warning() const {
- return player_warningtime;
- }
+ /// send a sound for the client to play
+ void sound(const std::string name);
/*----- mutators -------------------------------------------------- */
@@ -253,14 +249,17 @@ public:
std::list<EntityControlable *> assets;
private:
+ // associated network client
+ NetClient *player_client;
+
// entity the Player is currently controling
- EntityControlable *player_control;
+ EntityControlable *player_control;
// entity the Player is currently looking at
- Entity *player_view;
+ Entity *player_view;
// current mission target
- Entity *player_mission_target;
+ Entity *player_mission_target;
// the zone the player is currently in
Zone *player_zone;