I am working on programming an IRC server, and am having issues with the overload of operator<<
.
I have IrcServer
and IrcClient
classes, and I want to be able to output a server and a client.
What I want is to get this kind of output :
nick | user | host | server | name
With my own client that I use to connect to the server, it works fine, and I get this output :
NICKNAME->mynick | USERNAME->myuser | HOSTNAME->myhost | SERVERNAME->127.0.0.1 | REALNAME->my name
But with irssi, it doesn't work, and I only get this output (NICKNAME is missing):
| USERNAME->myuser | HOSTNAME->myhost | SERVERNAME->127.0.0.1 | REALNAME->my name
This is the code that I use :
ostream_irc_client.hpp :
#ifndef OSTREAM_IRC_CLIENT_HPP
# define OSTREAM_IRC_CLIENT_HPP
# include <iostream>
# include "irc_client.hpp"
# include "../utils/colors.h"
std::ostream &operator << (std::ostream &output, const IrcClient &cl);
#endif
ostream_irc_client.cpp :
#include "ostream_irc_client.hpp"
#include <sstream>
std::ostream &operator << (std::ostream &output , const IrcClient &cl)
{
output << "NICKNAME->" << cl.getNickName() << " | ";
output << "USERNAME->" << cl.getUserName() << " | ";
output << "HOSTNAME->" << cl.getHostName() << " | ";
output << "SERVERNAME->"<< cl.getServerName() << " | ";
output << "REALNAME->"<< cl.getRealName() << " | ";
return (output);
}
ostream_irc_server.hpp :
#ifndef OSTREAM_IRC_SERVER_HPP
# define OSTREAM_IRC_SERVER_HPP
# include <iostream>
# include "irc_server.hpp"
# include "../utils/colors.h"
std::ostream &operator << (std::ostream &output, const IrcServer &s);
#endif
ostream_irc_server.cpp :
#include "ostream_irc_server.hpp"
#include "../irc_client/ostream_irc_client.hpp"
#include <sstream>
#include <map>
std::ostream &operator << (std::ostream &output , const IrcServer &s)
{
output << BOLD_BLUE << "server:>" << RESET << "\n";
output << "| NICKNAME | USERNAME | HOSTNAME | SERVERNAME | STATUS |\n";
std::map<std::string, IrcClient*>::iterator usr;
for (usr = s.getUsers()->begin(); usr != s.getUsers()->end(); usr++)
{
IrcClient *cl = usr->second;
output << *cl;
}
if (s.getServer().getMessages()->size() > 0)
{
output << "\nMessages:\n";
std::vector<Message*>::iterator it;
for (it = s.getServer().getMessages()->begin(); it != s.getServer().getMessages()->end(); it++)
{
Message *msg = *it;
output << msg->getData() << "\n";
}
}
return (output);
}