Skip to content

Commit

Permalink
Remove dependency of wesnothd on SDL_net updating scons accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
loonycyborg committed Oct 28, 2015
1 parent 9ef2d1a commit e961b08
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 772 deletions.
12 changes: 6 additions & 6 deletions SConstruct
Expand Up @@ -347,28 +347,28 @@ if env["prereqs"]:
if env['sdl2']:
def have_sdl_net():
return \
conf.CheckSDL(require_version = '2.0.0') & \
conf.CheckSDL("SDL2_net", header_file = "SDL_net")
conf.CheckSDL(require_version = '2.0.0')

def have_sdl_other():
return \
conf.CheckSDL(require_version = '2.0.0') & \
conf.CheckSDL("SDL2_ttf", header_file = "SDL_ttf") & \
conf.CheckSDL("SDL2_mixer", header_file = "SDL_mixer") & \
conf.CheckSDL("SDL2_image", header_file = "SDL_image")
conf.CheckSDL("SDL2_image", header_file = "SDL_image") & \
conf.CheckSDL("SDL2_net", header_file = "SDL_net")

else:
def have_sdl_net():
return \
conf.CheckSDL(require_version = '1.2.10') & \
conf.CheckSDL('SDL_net')
conf.CheckSDL(require_version = '1.2.10')

def have_sdl_other():
return \
conf.CheckSDL(require_version = '1.2.10') & \
conf.CheckSDL("SDL_ttf", require_version = "2.0.8") & \
conf.CheckSDL("SDL_mixer", require_version = '1.2.12') & \
conf.CheckSDL("SDL_image", require_version = '1.2.0')
conf.CheckSDL("SDL_image", require_version = '1.2.0') & \
conf.CheckSDL('SDL_net')

if env["libintl"]:
def have_i18n_prereqs():
Expand Down
2 changes: 0 additions & 2 deletions src/SConscript
Expand Up @@ -687,9 +687,7 @@ wesnothd_sources = Split("""
server/metrics.cpp
server/player.cpp
server/player_network.cpp
server/proxy.cpp
server/room.cpp
server/room_manager.cpp
server/rooms.cpp
server/sample_user_handler.cpp
server/simple_wml.cpp
Expand Down
1 change: 0 additions & 1 deletion src/server/game.hpp
Expand Up @@ -15,7 +15,6 @@
#ifndef GAME_HPP_INCLUDED
#define GAME_HPP_INCLUDED

#include "../network.hpp"
#include "player_connection.hpp"
#include "player.hpp"

Expand Down
31 changes: 0 additions & 31 deletions src/server/player_network.cpp
Expand Up @@ -41,35 +41,4 @@ void truncate_message(const simple_wml::string_span& str, simple_wml::node& mess

} // end chat_message namespace

bool send_to_one(simple_wml::document& data, const network::connection sock, std::string packet_type)
{
if (packet_type.empty())
packet_type = data.root().first_child().to_string();
try {
simple_wml::string_span s = data.output_compressed();
network::send_raw_data(s.begin(), s.size(), sock, packet_type);
} catch (simple_wml::error& e) {
WRN_CONFIG << __func__ << ": simple_wml error: " << e.message << std::endl;
return false;
}
return true;
}

void send_to_many(simple_wml::document& data, const connection_vector& vec,
const network::connection exclude, std::string packet_type)
{
if (packet_type.empty())
packet_type = data.root().first_child().to_string();
try {
simple_wml::string_span s = data.output_compressed();
for(connection_vector::const_iterator i = vec.begin(); i != vec.end(); ++i) {
if (*i != exclude) {
network::send_raw_data(s.begin(), s.size(), *i, packet_type);
}
}
} catch (simple_wml::error& e) {
WRN_CONFIG << __func__ << ": simple_wml error: " << e.message << std::endl;
}
}

} //end namespace wesnothd
66 changes: 0 additions & 66 deletions src/server/player_network.hpp
Expand Up @@ -16,7 +16,6 @@
#ifndef SERVER_PLAYER_NETWORK_HPP_INCLUDED
#define SERVER_PLAYER_NETWORK_HPP_INCLUDED

#include "../network.hpp"
#include "player.hpp"
#include "simple_wml.hpp"

Expand All @@ -34,71 +33,6 @@ namespace chat_message {
simple_wml::node& message);
} // end chat_message namespace

typedef std::map<network::connection,player> player_map;
typedef std::vector<network::connection> connection_vector;

/**
* Send a wml document to a single player
* @param data the document to send
* @param sock the socket id to send to
* @param packet_type the packet type, if empty the root node name is used
*/
bool send_to_one(simple_wml::document& data,
const network::connection sock,
std::string packet_type = "");

/**
* Send a wml document to a vector of players. More efficient than calling
* send_to_one many times.
* @param data the document to send
* @param vec the vector of player socket ids to send to
* @param exclude if nonzero, do not send to this player
* @param packet_type the packet type, if empty the root node name is used
*/
void send_to_many(simple_wml::document& data,
const connection_vector& vec,
const network::connection exclude = 0,
std::string packet_type = "");
/**
* A more powerful version of send_to_many, allowing the use of a predicate
* connection->bool. The document will be sent only to those sockets for which
* the predicate evaluates to false.
* @param data the document to send
* @param vec the vector of player socket ids to send to
* @param pred the predicate
* @param exclude if nonzero, do not send to this player
* @param packet_type the packet type, if empty the root node name is used
*/
/*
void send_to_many(simple_wml::document& data,
const connection_vector& vec,
boost::function<bool (network::connection)> pred,
const network::connection exclude = 0,
std::string packet_type = "");
*/

template<typename TFilter>
void send_to_many(simple_wml::document& data,
const connection_vector& vec,
const TFilter& pred,
const network::connection exclude = 0,
std::string packet_type = "")
{
if (packet_type.empty()) {
packet_type = data.root().first_child().to_string();
}
try {
simple_wml::string_span s = data.output_compressed();
for(connection_vector::const_iterator i = vec.begin(); i != vec.end(); ++i) {
if ((*i != exclude) && pred(*i)) {
network::send_raw_data(s.begin(), s.size(), *i, packet_type);
}
}
} catch (simple_wml::error& e) {
LOG_STREAM(warn, log_config_pn) << __func__ << ": simple_wml error: " << e.message << std::endl;
}
}

} //end namespace wesnothd

#endif
17 changes: 8 additions & 9 deletions src/server/room.cpp
Expand Up @@ -29,7 +29,6 @@ namespace wesnothd {

room::room(const std::string& name)
: name_(name)
, members_()
, persistent_(false)
, topic_()
, logged_(false)
Expand All @@ -38,7 +37,6 @@ room::room(const std::string& name)

room::room(const config& wml)
: name_(wml["name"])
, members_()
, persistent_(wml["persistent"].to_bool())
, topic_(wml["topic"])
, logged_(wml["logged"].to_bool())
Expand Down Expand Up @@ -88,7 +86,7 @@ void room::set_logged(bool v)
logged_ = v;
}

bool room::add_player(network::connection player)
/*bool room::add_player(network::connection player)
{
if (is_member(player)) {
ERR_ROOM << "ERROR: Player is already in this room. (socket: "
Expand All @@ -97,7 +95,7 @@ bool room::add_player(network::connection player)
}
members_.push_back(player);
return true;
}
}*/

/*
void room::remove_player(network::connection player)
Expand All @@ -113,7 +111,7 @@ void room::remove_player(network::connection player)
}
*/

void room::send_data(simple_wml::document& data,
/*void room::send_data(simple_wml::document& data,
const network::connection exclude,
std::string packet_type) const
{
Expand Down Expand Up @@ -144,11 +142,12 @@ void room::send_server_message(const char* message, network::connection sock,
send_to_one(doc, sock, "message");
}
}
*/

void room::process_message(simple_wml::document& /*data*/,
const player_map::iterator /*user*/)
{
}
//void room::process_message(simple_wml::document& /*data*/,
// const player_map::iterator /*user*/)
//{
//}



Expand Down
59 changes: 28 additions & 31 deletions src/server/room.hpp
Expand Up @@ -15,14 +15,11 @@
#ifndef SERVER_ROOM_HPP_INCLUDED
#define SERVER_ROOM_HPP_INCLUDED

#include "../network.hpp"
#include "player.hpp"
#include "simple_wml.hpp"

namespace wesnothd {

typedef std::vector<network::connection> connection_vector;
typedef std::map<network::connection,player> player_map;
class game;

/**
Expand Down Expand Up @@ -84,37 +81,37 @@ class room {
/**
* Return the number of players in this room
*/
size_t size() const {
return members_.size();
}
//size_t size() const {
// return members_.size();
//}

/**
* Return true iif the room is empty
*/
bool empty() const {
return members_.empty();
}
//bool empty() const {
// return members_.empty();
//}

/**
* Return the members of this room
*/
const std::vector<network::connection>& members() const {
return members_;
}
//const std::vector<network::connection>& members() const {
// return members_;
//}

/**
* Membership checker.
* @return true iif player is a member of this room
*/
bool is_member(network::connection player) const {
return std::find(members_.begin(), members_.end(), player) != members_.end();
}
//bool is_member(network::connection player) const {
// return std::find(members_.begin(), members_.end(), player) != members_.end();
//}

/**
* Joining the room
* @return true if the player was successfully added
*/
bool add_player(network::connection player);
//bool add_player(network::connection player);

/**
* Leaving the room
Expand All @@ -124,7 +121,7 @@ class room {
/**
* Chat message processing
*/
void process_message(simple_wml::document& data, const player_map::iterator user);
//void process_message(simple_wml::document& data, const player_map::iterator user);

/**
* Convenience function for sending a wml document to all (or all except
Expand All @@ -134,18 +131,18 @@ class room {
* @param exclude if nonzero, do not send to this player
* @param packet_type the packet type, if empty the root node name is used
*/
void send_data(simple_wml::document& data, const network::connection exclude=0, std::string packet_type = "") const;
//void send_data(simple_wml::document& data, const network::connection exclude=0, std::string packet_type = "") const;

/**
* Send a text message to all members
* @param message the message text
* @param exclude if nonzero, do not send to this player
*/
void send_server_message_to_all(const char* message, network::connection exclude=0) const;
void send_server_message_to_all(const std::string& message, network::connection exclude=0) const
{
send_server_message_to_all(message.c_str(), exclude);
}
//void send_server_message_to_all(const char* message, network::connection exclude=0) const;
//void send_server_message_to_all(const std::string& message, network::connection exclude=0) const
//{
// send_server_message_to_all(message.c_str(), exclude);
//}

/**
* Prepare a text message and/or send it to a player. If a nonzero sock
Expand All @@ -156,19 +153,19 @@ class room {
* @param sock the socket to send the message to, if nonzero
* @param docptr the wml document to store the message in, if nonnull
*/
void send_server_message(const char* message, network::connection sock,
simple_wml::document* docptr = NULL) const;
//void send_server_message(const char* message, network::connection sock,
// simple_wml::document* docptr = NULL) const;

void send_server_message(const std::string& message, network::connection sock,
simple_wml::document* docptr = NULL) const
{
send_server_message(message.c_str(), sock, docptr);
}
//void send_server_message(const std::string& message, network::connection sock,
// simple_wml::document* docptr = NULL) const
//{
// send_server_message(message.c_str(), sock, docptr);
//}


private:
std::string name_;
connection_vector members_;
//connection_vector members_;
bool persistent_;
std::string topic_;
bool logged_;
Expand Down

0 comments on commit e961b08

Please sign in to comment.