Restyled RCONSession method names and paren style

Wed, 20 Jul 2016 22:56:16 +0300

author
Teemu Piippo <teemu@compsta2.com>
date
Wed, 20 Jul 2016 22:56:16 +0300
changeset 156
ce66d7e374bf
parent 154
9cdd6b71f0d1
child 157
42bb29924218

Restyled RCONSession method names and paren style

sources/interface.cpp file | annotate | diff | comparison | revisions
sources/main.cpp file | annotate | diff | comparison | revisions
sources/network/rconsession.cpp file | annotate | diff | comparison | revisions
sources/network/rconsession.h file | annotate | diff | comparison | revisions
--- a/sources/interface.cpp	Wed Jul 20 18:29:13 2016 +0300
+++ b/sources/interface.cpp	Wed Jul 20 22:56:16 2016 +0300
@@ -168,7 +168,7 @@
 	m_inputHistory << "";
 	m_outputLines.clear();
 	m_outputLines << ColoredLine();
-	m_session.set_interface(this);
+	m_session.setInterface(this);
 	resetTitle();
 
 	if (::has_colors())
@@ -230,7 +230,7 @@
 //
 void Interface::safeDisconnect(std::function<void(bool)> afterwards)
 {
-	if (m_session.is_active())
+	if (m_session.isActive())
 	{
 		m_disconnectCallback = afterwards;
 		setInputState(INPUTSTATE_CONFIRM_DISCONNECTION);
@@ -480,7 +480,7 @@
 {
 	String text;
 
-	switch (m_session.state())
+	switch (m_session.getState())
 	{
 	case RCON_DISCONNECTED:
 		text = "Disconnected.";
@@ -495,19 +495,19 @@
 		{
 			String adminText;
 
-			if (m_session.num_admins() == 0)
+			if (m_session.getAdminCount() == 0)
 			{
 				adminText = "No other admins";
 			}
 			else
 			{
-				adminText.sprintf("%d other admin%s", m_session.num_admins(),
-					m_session.num_admins() != 1 ? "s" : "");
+				adminText.sprintf("%d other admin%s", m_session.getAdminCount(),
+					m_session.getAdminCount() != 1 ? "s" : "");
 			}
 
 			text.sprintf("%s | %s | %s",
 				m_session.address().to_string(IPAddress::WITH_PORT).chars(),
-				m_session.level().chars(),
+				m_session.getLevel().chars(),
 				adminText.chars());
 		}
 		break;
@@ -517,7 +517,7 @@
 		text += " | ";
 
 	text += "Ctrl+N to connect, Ctrl+Q to ";
-	text +=(m_session.state() == RCON_DISCONNECTED) ? "quit" : "disconnect";
+	text +=(m_session.getState() == RCON_DISCONNECTED) ? "quit" : "disconnect";
 
 	if (text != m_statusBarText)
 	{
@@ -775,7 +775,7 @@
 				and(space == -1 or space >= m_cursorPosition))
 			{
 				String start = getCurrentInput().mid(0, m_cursorPosition);
-				m_session.request_tab_complete(start);
+				m_session.requestTabCompletion(start);
 			}
 		}
 		break;
@@ -809,7 +809,7 @@
 			if (m_inputState == INPUTSTATE_PASSWORD and not getCurrentInput().isEmpty())
 			{
 				m_session.disconnect();
-				m_session.set_password(getCurrentInput());
+				m_session.setPassword(getCurrentInput());
 				m_session.connect(m_remoteAddress);
 				setInputState(INPUTSTATE_NORMAL);
 			}
@@ -821,7 +821,7 @@
 				handleCommand(getCurrentInput());
 				flushInput();
 			}
-			else if (m_session.send_command(getCurrentInput()))
+			else if (m_session.sendCommand(getCurrentInput()))
 			{
 				flushInput();
 			}
@@ -1007,7 +1007,7 @@
 		m_remoteAddress.port = 10666;
 
 	m_session.disconnect();
-	m_session.set_password(password);
+	m_session.setPassword(password);
 	m_session.connect(m_remoteAddress);
 }
 
@@ -1079,7 +1079,7 @@
 			if (address.port == 0)
 				address.port = 10666;
 
-			m_session.set_password(args[1]);
+			m_session.setPassword(args[1]);
 			m_session.disconnect();
 			m_session.connect(m_remoteAddress = address);
 		}
--- a/sources/main.cpp	Wed Jul 20 18:29:13 2016 +0300
+++ b/sources/main.cpp	Wed Jul 20 22:56:16 2016 +0300
@@ -84,7 +84,7 @@
 			FD_ZERO (&fdset);
 			FD_SET (0, &fdset);
 
-			int fd = iface.getSession()->socket()->file_descriptor();
+			int fd = iface.getSession()->getSocket()->file_descriptor();
 			highest = zfc::max (highest, fd);
 			FD_SET (fd, &fdset);
 
--- a/sources/network/rconsession.cpp	Wed Jul 20 18:29:13 2016 +0300
+++ b/sources/network/rconsession.cpp	Wed Jul 20 22:56:16 2016 +0300
@@ -36,16 +36,16 @@
 // -------------------------------------------------------------------------------------------------
 //
 RCONSession::RCONSession() :
-	m_state (RCON_DISCONNECTED),
-	m_lastPing (0),
-	m_numAdmins (0),
-	m_interface (nullptr)
+	m_state(RCON_DISCONNECTED),
+	m_lastPing(0),
+	m_adminCount(0),
+	m_interface(nullptr)
 {
-	if (not m_socket.set_blocking (false))
+	if (not m_socket.set_blocking(false))
 	{
-		fprintf (stderr, "unable to set socket as non-blocking: %s\n",
+		fprintf(stderr, "unable to set socket as non-blocking: %s\n",
 			m_socket.error_string().chars());
-		exit (EXIT_FAILURE);
+		exit(EXIT_FAILURE);
 	}
 }
 
@@ -55,12 +55,12 @@
 
 // -------------------------------------------------------------------------------------------------
 //
-void RCONSession::connect (IPAddress address)
+void RCONSession::connect(IPAddress address)
 {
 	m_address = address;
 	m_state = RCON_CONNECTING;
 	m_interface->updateStatusBar();
-	send_hello();
+	sendHello();
 }
 
 // -------------------------------------------------------------------------------------------------
@@ -71,8 +71,8 @@
 	{
 		// Say goodbye to remote
 		Bytestream packet;
-		packet.write_byte (CLRC_DISCONNECT);
-		this->send (packet);
+		packet.write_byte(CLRC_DISCONNECT);
+		this->send(packet);
 		m_interface->disconnected();
 	}
 
@@ -81,9 +81,9 @@
 
 // -------------------------------------------------------------------------------------------------
 //
-void RCONSession::send (const Bytestream& packet)
+void RCONSession::send(const Bytestream& packet)
 {
-	m_socket.send (m_address, packet);
+	m_socket.send(m_address, packet);
 }
 
 // -------------------------------------------------------------------------------------------------
@@ -94,34 +94,34 @@
 		return;
 
 	time_t now;
-	time (&now);
+	time(&now);
 
 	if (m_lastPing < now)
 	{
 		if (m_state == RCON_CONNECTING)
 		{
-			send_hello();
+			sendHello();
 		}
 		else if (m_state == RCON_AUTHENTICATING)
 		{
-			send_password();
+			sendPassword();
 		}
 		else if (m_state == RCON_CONNECTED and m_lastPing + 5 < now)
 		{
 			Bytestream packet;
-			packet.write_byte (CLRC_PONG);
-			send (packet);
-			bump_last_ping();
+			packet.write_byte(CLRC_PONG);
+			send(packet);
+			bumpLastPing();
 		}
 	}
 
-	for (Datagram datagram; m_socket.read (datagram);)
-		handle_packet (datagram);
+	for (Datagram datagram; m_socket.read(datagram);)
+		handlePacket(datagram);
 }
 
 // -------------------------------------------------------------------------------------------------
 //
-void RCONSession::handle_packet (Datagram& datagram)
+void RCONSession::handlePacket(Datagram& datagram)
 {
 	if (datagram.address != m_address)
 		return;
@@ -132,26 +132,26 @@
 		{
 			int header = datagram.message.read_byte();
 
-			switch (ServerResponse (header))
+			switch (ServerResponse(header))
 			{
 			case SVRC_OLDPROTOCOL:
-				m_interface->printError ("Your RCON client is using outdated protocol.\n");
+				m_interface->printError("Your RCON client is using outdated protocol.\n");
 				m_state = RCON_DISCONNECTED;
 				break;
 
 			case SVRC_BANNED:
-				m_interface->printError ("You have been banned from the server.\n");
+				m_interface->printError("You have been banned from the server.\n");
 				m_state = RCON_DISCONNECTED;
 				break;
 
 			case SVRC_SALT:
 				m_salt = datagram.message.read_string();
 				m_state = RCON_AUTHENTICATING;
-				send_password();
+				sendPassword();
 				break;
 
 			case SVRC_INVALIDPASSWORD:
-				m_interface->printError ("Login failed.\n");
+				m_interface->printError("Login failed.\n");
 				m_state = RCON_DISCONNECTED;
 				break;
 
@@ -159,41 +159,41 @@
 				{
 					String message = datagram.message.read_string();
 					message.normalize();
-					m_interface->printText ("%s\n", message.chars());
+					m_interface->printText("%s\n", message.chars());
 				}
 				break;
 
 			case SVRC_LOGGEDIN:
-				m_interface->print ("Login successful!\n");
+				m_interface->print("Login successful!\n");
 				m_serverProtocol = datagram.message.read_byte();
 				m_hostname = datagram.message.read_string();
-				m_interface->setTitle (m_hostname);
+				m_interface->setTitle(m_hostname);
 				m_state = RCON_CONNECTED;
 
 				for (int i = datagram.message.read_byte(); i > 0; --i)
-					process_server_updates (datagram.message);
+					processServerUpdates(datagram.message);
 
-				m_interface->print ("Previous messages:\n");
+				m_interface->print("Previous messages:\n");
 
 				for (int i = datagram.message.read_byte(); i > 0; --i)
 				{
 					String message = datagram.message.read_string();
 					message.normalize();
-					m_interface->printText ("--- %s\n", message.chars());
+					m_interface->printText("--- %s\n", message.chars());
 				}
 
-				m_interface->print ("End of previous messages.\n");
+				m_interface->print("End of previous messages.\n");
 				break;
 
 			case SVRC_UPDATE:
-				process_server_updates (datagram.message);
+				processServerUpdates(datagram.message);
 				break;
 
 			case SVRC_TOOMANYTABCOMPLETES:
 				{
 					unsigned int numCompletions = datagram.message.read_short();
-					m_interface->print ("%d completions for '%s'.\n",
-						int (numCompletions), m_lastTabComplete.chars());
+					m_interface->print("%d completions for '%s'.\n",
+						int(numCompletions), m_lastTabComplete.chars());
 				}
 				break;
 
@@ -207,17 +207,17 @@
 
 					if (completes.size() == 1)
 					{
-						m_interface->tabComplete (m_lastTabComplete, completes[0]);
+						m_interface->tabComplete(m_lastTabComplete, completes[0]);
 					}
 					else if (not completes.is_empty())
 					{
-						m_interface->print ("Completions for '%s':\n", m_lastTabComplete.chars());
+						m_interface->print("Completions for '%s':\n", m_lastTabComplete.chars());
 
 						for (int i : range(0, completes.size(), 8))
 						{
-							Range<int> spliceRange (i, min (i + 8, completes.size()));
-							StringList splice (completes.splice (spliceRange));
-							m_interface->print ("- %s\n", splice.join (", ").chars());
+							Range<int> spliceRange(i, min(i + 8, completes.size()));
+							StringList splice(completes.splice(spliceRange));
+							m_interface->print("- %s\n", splice.join(", ").chars());
 						}
 					}
 				}
@@ -227,29 +227,29 @@
 	}
 	catch (std::exception& e)
 	{
-		m_interface->printWarning ("Couldn't process packet: %s\n", e.what());
+		m_interface->printWarning("Couldn't process packet: %s\n", e.what());
 	}
 }
 
-void RCONSession::process_server_updates (Bytestream& packet)
+void RCONSession::processServerUpdates(Bytestream& packet)
 {
 	int header = packet.read_byte();
 
-	switch (RCONUpdateType (header))
+	switch (RCONUpdateType(header))
 	{
 	case SVRCU_PLAYERDATA:
 		{
 			StringList players;
 
 			for (int i = packet.read_byte(); i > 0; --i)
-				players.append (packet.read_string());
+				players.append(packet.read_string());
 
-			m_interface->setPlayerNames (players);
+			m_interface->setPlayerNames(players);
 		}
 		break;
 
 	case SVRCU_ADMINCOUNT:
-		m_numAdmins = packet.read_byte();
+		m_adminCount = packet.read_byte();
 		m_interface->updateStatusBar();
 		break;
 
@@ -259,85 +259,84 @@
 		break;
 
 	default:
-		m_interface->printWarning ("Unknown server update type: %d\n", header);
+		m_interface->printWarning("Unknown server update type: %d\n", header);
 		break;
 	}
 }
 
 // -------------------------------------------------------------------------------------------------
 //
-UDPSocket* RCONSession::socket()
+UDPSocket* RCONSession::getSocket()
 {
 	return &m_socket;
 }
 
 // -------------------------------------------------------------------------------------------------
 //
-void RCONSession::send_hello()
+void RCONSession::sendHello()
 {
-	m_interface->print ("Connecting to %s...\n",
-		m_address.to_string (IPAddress::WITH_PORT).chars());
+	m_interface->print("Connecting to %s...\n", m_address.to_string(IPAddress::WITH_PORT).chars());
 	Bytestream packet;
-	packet.write_byte (CLRC_BEGINCONNECTION);
-	packet.write_byte (RCON_PROTOCOL_VERSION);
-	send (packet);
-	bump_last_ping();
+	packet.write_byte(CLRC_BEGINCONNECTION);
+	packet.write_byte(RCON_PROTOCOL_VERSION);
+	send(packet);
+	bumpLastPing();
 }
 
 // -------------------------------------------------------------------------------------------------
 //
-void RCONSession::send_password()
+void RCONSession::sendPassword()
 {
-	m_interface->print ("Authenticating...\n");
+	m_interface->print("Authenticating...\n");
 	Bytestream packet;
-	packet.write_byte (CLRC_PASSWORD);
-	packet.write_string ((m_salt + m_password).md5());
-	send (packet);
-	bump_last_ping();
+	packet.write_byte(CLRC_PASSWORD);
+	packet.write_string((m_salt + m_password).md5());
+	send(packet);
+	bumpLastPing();
 }
 
 // -------------------------------------------------------------------------------------------------
 //
-void RCONSession::set_password (const String& password)
+void RCONSession::setPassword(const String& password)
 {
 	m_password = password;
 }
 
 // -------------------------------------------------------------------------------------------------
 //
-void RCONSession::bump_last_ping()
+void RCONSession::bumpLastPing()
 {
 	time_t now;
-	time (&now);
+	time(&now);
 	m_lastPing = now;
 }
 
 // -------------------------------------------------------------------------------------------------
 //
-bool RCONSession::is_active() const
+bool RCONSession::isActive() const
 {
-	return state() != RCON_DISCONNECTED;
+	return getState() != RCON_DISCONNECTED;
 }
 
 // -------------------------------------------------------------------------------------------------
 // Returns true if the message was successfully sent.
 //
-bool RCONSession::send_command (const String& message)
+bool RCONSession::sendCommand(const String& message)
 {
 	if (m_state != RCON_CONNECTED or message.isEmpty())
 		return false;
 
 	Bytestream packet;
-	packet.write_byte (CLRC_COMMAND);
-	packet.write_string (message);
-	send (packet);
-	bump_last_ping();
+	packet.write_byte(CLRC_COMMAND);
+	packet.write_string(message);
+	send(packet);
+	bumpLastPing();
 	return true;
 }
 
 // -------------------------------------------------------------------------------------------------
 //
-RCONSessionState RCONSession::state() const
+RCONSessionState RCONSession::getState() const
 {
 	return m_state;
 }
@@ -351,42 +350,42 @@
 
 // -------------------------------------------------------------------------------------------------
 //
-int RCONSession::num_admins() const
+int RCONSession::getAdminCount() const
 {
-	return m_numAdmins;
+	return m_adminCount;
 }
 
 // -------------------------------------------------------------------------------------------------
 //
-const String& RCONSession::level() const
+const String& RCONSession::getLevel() const
 {
 	return m_level;
 }
 
 // -------------------------------------------------------------------------------------------------
 //
-void RCONSession::request_tab_complete (const String& part)
+void RCONSession::requestTabCompletion(const String& part)
 {
 	if (m_serverProtocol >= 4)
 	{
 		Bytestream packet;
-		packet.write_byte (CLRC_TABCOMPLETE);
-		packet.write_string (part);
-		send (packet);
-		bump_last_ping();
+		packet.write_byte(CLRC_TABCOMPLETE);
+		packet.write_string(part);
+		send(packet);
+		bumpLastPing();
 		m_lastTabComplete = part;
 	}
 	else
 	{
-		m_interface->print ("This server does not support tab-completion\n", m_serverProtocol);
+		m_interface->print("This server does not support tab-completion\n", m_serverProtocol);
 	}
 }
 
 // -------------------------------------------------------------------------------------------------
 //
-void RCONSession::set_interface (Interface* iface)
+void RCONSession::setInterface(Interface* interface)
 {
-	m_interface = iface;
+	m_interface = interface;
 }
 
 END_ZFC_NAMESPACE
--- a/sources/network/rconsession.h	Wed Jul 20 18:29:13 2016 +0300
+++ b/sources/network/rconsession.h	Wed Jul 20 22:56:16 2016 +0300
@@ -20,10 +20,10 @@
 	TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 	PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
 	OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-	EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+	EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
 	PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 	PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-	LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+	LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING
 	NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 	SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
@@ -95,25 +95,25 @@
 	RCONSession();
 	~RCONSession();
 
-	const IPAddress& address() const;
-	void connect (IPAddress address);
-	void disconnect();
-	void handle_packet (Datagram& datagram);
-	void process_server_updates (Bytestream& packet);
-	int num_admins() const;
-	void send (const Bytestream& packet);
-	void send_hello();
-	void send_password();
-	void set_password (const String& password);
-	UDPSocket* socket();
-	void tick();
-	void bump_last_ping();
-	bool send_command (const String& message);
-	RCONSessionState state() const;
-	const String& level() const;
-	bool is_active() const;
-	void request_tab_complete (const String& part);
-	void set_interface (class Interface* iface);
+	const IPAddress&            address() const;
+	void                        bumpLastPing();
+	void                        connect(IPAddress address);
+	void                        disconnect();
+	int                         getAdminCount() const;
+	const String&               getLevel() const;
+	UDPSocket*                  getSocket();
+	RCONSessionState            getState() const;
+	void                        handlePacket(Datagram& datagram);
+	bool                        isActive() const;
+	void                        processServerUpdates(Bytestream& packet);
+	void                        requestTabCompletion(const String& part);
+	void                        send(const Bytestream& packet);
+	bool                        sendCommand(const String& message);
+	void                        sendHello();
+	void                        sendPassword();
+	void                        setInterface(class Interface* interface);
+	void                        setPassword(const String& password);
+	void                        tick();
 
 private:
 	RCONSessionState m_state;
@@ -124,7 +124,7 @@
 	String m_salt;
 	int m_serverProtocol;
 	String m_hostname;
-	int m_numAdmins;
+	int m_adminCount;
 	String m_level;
 	String m_lastTabComplete;
 	class Interface* m_interface;

mercurial