1. David Stone
  2. Technical Machine

Commits

David Stone  committed 08f1fd3

Moved time stamp creation / formatting out of the networking code.

  • Participants
  • Parent commits 2c26861
  • Branches default

Comments (0)

Files changed (4)

File source/clients/client.cpp

View file
  • Ignore whitespace
 
 #include "client.hpp"
 
+#include "../settings_file.hpp"
+
 namespace technicalmachine {
 
+void Client::print_with_time_stamp (std::ostream & stream, std::string const & message) const {
+	stream << time_stamp() + " " + message + "\n";
+}
+
+std::string Client::time_stamp() const {
+	// There does not appear to be an easy way to format the current time with
+	// a format string. This seems like a major limitation of boost::date_time
+	// and / or boost::posix_time, as well as the std header chrono.
+	std::string result;
+	if (!time_format.empty ()) {
+		// probably_big_enough is a guess at how big the time stamp will be.
+		// It is OK if it is wrong.
+		constexpr unsigned probably_big_enough = 30;
+		result.resize (probably_big_enough);
+		time_t current_time = time (nullptr);
+		tm * timeptr = localtime (&current_time);
+		while (strftime (&result [0], result.size (), time_format.c_str(), timeptr) == 0)
+			result.resize (result.size () * 2);
+	}
+	return result;
+}
+
+Settings Client::load_settings() {
+	Settings settings;
+	time_format = settings.time_format;
+	return settings;
+}
+
 void Client::reload_settings() {
 	m_evaluation_constants.load();
 }

File source/clients/client.hpp

View file
  • Ignore whitespace
 #include "../team_predictor/detailed_stats.hpp"
 
 namespace technicalmachine {
+class Settings;
 
 class Client {
 	public:
+		void print_with_time_stamp(std::ostream & stream, std::string const & message) const;
 		DetailedStats const & detailed() const;
 		Evaluate const & evaluation_constants() const;
 		virtual ~Client() { }
 	protected:
+		Settings load_settings();
 		void reload_settings();
 	private:
+		std::string time_stamp() const;
 		DetailedStats detailed_stats;
 		Evaluate m_evaluation_constants;
+		std::string time_format;
 };
 
 }	// namespace technicalmachine

File source/clients/network/client.cpp

View file
  • Ignore whitespace
 }
 
 void Client::load_settings (bool const reloading) {
-	Settings settings;
+	auto settings = ::technicalmachine::Client::load_settings();
 	team_file_name = settings.team_file;
 	chattiness = settings.chattiness;
-	time_format = settings.time_format;
 	
 	if (!reloading) {
 		Server & server = settings.servers.front();
 	connect ();
 }
 
-void Client::print_with_time_stamp (std::ostream & stream, std::string const & message) const {
-	stream << time_stamp() + " " + message + "\n";
-}
-
-std::string Client::time_stamp () const {
-	// There does not appear to be an easy way to format the current time with
-	// a format string. This seems like a major limitation of boost::date_time
-	// and / or boost::posix_time, as well as the std header chrono.
-	std::string result;
-	if (!time_format.empty ()) {
-		// probably_big_enough is a guess at how big the time stamp will be.
-		// It is OK if it is wrong.
-		constexpr unsigned probably_big_enough = 30;
-		result.resize (probably_big_enough);
-		time_t current_time = time (nullptr);
-		tm * timeptr = localtime (&current_time);
-		while (strftime (&result [0], result.size (), time_format.c_str(), timeptr) == 0)
-			result.resize (result.size () * 2);
-	}
-	return result;
-}
-
 void Client::handle_channel_message (uint32_t channel_id, std::string const & user, std::string const & message) const {
 	std::string msg = message;
 	boost::to_lower (msg);

File source/clients/network/client.hpp

View file
  • Ignore whitespace
 
 class Client : public ::technicalmachine::Client {
 	public:
-		void print_with_time_stamp(std::ostream & stream, std::string const & message) const;
 		void handle_channel_message (uint32_t channel_id, std::string const & user, std::string const & message) const;
 		void send_message(OutMessage & msg);
 	protected:
 		void connect ();
 		virtual void join_channel (std::string const & channel) = 0;
 		virtual void part_channel (std::string const & channel) = 0;
-		std::string time_stamp () const;
 		bool is_highlighted (std::string const & message) const;
 		void do_request (std::string const & user, std::string const & request);
 		void handle_challenge_command (std::string const & request, size_t start);
 		std::string current_username;
 		std::string current_password;
 		std::string team_file_name;
-		std::string time_format;
 		std::vector <std::string> highlights;
 		std::vector <std::string> trusted_users;
 		unsigned chattiness;