Skip to content

Commit

Permalink
Made status a member of MessageHandler
Browse files Browse the repository at this point in the history
Obtaining user list no longer library function
  • Loading branch information
Arc676 committed Aug 5, 2018
1 parent 41ad726 commit eca6f62
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 18 deletions.
1 change: 1 addition & 0 deletions lib/messagehandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class MessageHandler {
protected:
bool useSSL = true;
SSL_CTX* sslctx = nullpointer;
int status = SUCCESS;

/**
* Initializes the SSL context
Expand Down
2 changes: 0 additions & 2 deletions lib/socktalkclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@ class SockTalkClient : public MessageHandler {
std::string username;
MsgThread* msgThread;

int status = SUCCESS;

/**
* Utility method for sending messages
* @param msg Message to send
Expand Down
8 changes: 0 additions & 8 deletions lib/socktalkserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,6 @@ void SockTalkServer::sendTo(const std::string &msg, const std::string &recipient
}
}

std::string SockTalkServer::userList() {
std::string str = "\tConnected users:";
for (int i = 0; i < handlers.size(); i++) {
str += "\n\t\t" + handlers[i]->getUsername();
}
return str;
}

void SockTalkServer::addHandler(SockTalkClientHandler* ch) {
handlers.push_back(ch);
handleMessage("Incoming connection...", INFO, "Notice");
Expand Down
8 changes: 0 additions & 8 deletions lib/socktalkserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ class SockTalkServer : public MessageHandler {
AcceptThread* acceptThread;
std::vector<SockTalkClientHandler*> handlers;

int status = SUCCESS;

/**
* Check the handlers to see if any connections are dead, dropping
* any handlers for clients that have disconnected
Expand All @@ -201,12 +199,6 @@ class SockTalkServer : public MessageHandler {
*/
virtual void closeServer();

/**
* Obtain a list of the connected users
* @return String representation of the user list
*/
std::string userList();

/**
* Adds a new client handler
* @param ch Client handler to add
Expand Down
8 changes: 8 additions & 0 deletions stclient/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ void Server::run() {
std::cout << "Server closed" << std::endl;
}

std::string Server::userList() {
std::string str = "\tConnected users:";
for (int i = 0; i < handlers.size(); i++) {
str += "\n\t\t" + handlers[i]->getUsername();
}
return str;
}

int main(int argc, char * argv[]) {
int port;
if (argc == 2) {
Expand Down
5 changes: 5 additions & 0 deletions stclient/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@
#include "socktalkserver.h"

class Server : public SockTalkServer {
/**
* Obtain a list of the connected users
* @return String representation of the user list
*/
std::string userList();
public:
using SockTalkServer::SockTalkServer;
virtual void handleMessage(const std::string&, int, const std::string&);
Expand Down

0 comments on commit eca6f62

Please sign in to comment.