/* tag: IrcChannel class Copyright (c) 2001 David Roundy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // For compilers that support precompilation, includes . #include // for all others, include the necessary headers (this file is usually all you // need because it includes almost all "standard" wxWindows headers #ifndef WX_PRECOMP #include #include #include #endif #include #include #include "irc.h" #include "debug.h" #include "globals.h" #include "config.h" #include "speech.h" #include "prefmacros.h" const wxString newline = "\x0D\x0A"; // CRLF as in RFC whatever. // Warning!!! IrcChannels should ONLY be created by the Irc Join method! IrcChannel::IrcChannel(Irc *the_irc, wxEvtHandler* parent, wxTextCtrl* output, const wxString& the_room) { m_log = output; m_magic = aBridgeMagic; m_parent_handler = parent; m_irc = the_irc; m_room = the_room; m_room.Replace("\n",""); m_irc->SendBack("JOIN " + m_room + newline); // m_irc->SendBack("WHO " + m_room + newline); } void IrcChannel::SendVersion() { SendMsg("VERSION", wxString("aBridge version ") + VERSION + " running under " + wxGetOsDescription() + " using " + wxVERSION_STRING + newline); } IrcChannel::~IrcChannel() { // We might want to leave the channel here... it would probably be a good // idea, but I'll leave that for later. m_irc->Leave(m_room); } void IrcChannel::GotWhoCmd(const wxString &line) { wxString name = line.AfterLast(' '); wxString nick = line.AfterFirst('#').AfterFirst('~').BeforeFirst(' '); m_log->AppendText(nick + " - " + name + "\n"); } void IrcChannel::GotNames(const wxString &names) { wxString temp = names; temp.Replace(" ",", "); temp = temp.BeforeLast(','); m_log->AppendText("Players present: " + display_name(temp) + "\n"); wxStringTokenizer my_names(names, " "); while ( my_names.HasMoreTokens() ) { wxString name = my_names.GetNextToken(); m_logged_in.Add(name); } SendVersion(); IrcMsgEvent my_event( this ); my_event.SetEventType( wxEVT_COMMAND_IRC_IJOINED ); DebugMsg("I just joined a channel"); wxPostEvent( m_parent_handler, my_event ); } void IrcChannel::GotMessageEvent(IrcMsgEvent my_event) { wxPostEvent( m_parent_handler, my_event ); } void IrcChannel::GotChat(const wxString &from, const wxString &msg) { m_log->AppendText(from + "> " + msg + "\n"); if (wxConfig::Get()->Read("/Speech/Chat", 0l)) { speak_string(msg); } } void IrcChannel::GotLeftCmd(const wxString &from) { m_log->AppendText(display_name(from) + " just left us.\n"); IrcMsgEvent my_event( this, from); my_event.SetEventType( wxEVT_COMMAND_IRC_LEFT ); m_logged_in.Delete(from); wxPostEvent( m_parent_handler, my_event ); } int IrcChannel::NumOthersInRoom() { return m_logged_in.GetCount() - 1; } void IrcChannel::GotJoiner(const wxString &from) { m_log->AppendText(display_name(from) + " just joined us.\n"); IrcMsgEvent my_event( this, from); my_event.SetEventType( wxEVT_COMMAND_IRC_JOINED ); m_logged_in.Add(from); if (GetBeep()) wxBell(); wxPostEvent( m_parent_handler, my_event ); } // This is the routine that gets called with whatever the user types in. void IrcChannel::Send(const wxString &str) { wxString *temp = new wxString; if (str.Matches("/who")) { m_irc->SendBack("WHO " + m_room + newline); /* } else if (str.StartsWith("'", temp)) { SendBack(*temp); } else if (str.StartsWith("/JOIN ", temp)) { Join(*temp); } else if (str.StartsWith("/join ", temp)) { Join(*temp); */ } else { // Send a message!!! :) m_irc->SendBack("PRIVMSG " + m_room + " :" + str); } delete temp; } void IrcChannel::AskTopic(const wxString &channel) { if (channel.IsSameAs("none")) { m_irc->AskTopic(TheRoom()); } else { m_irc->AskTopic(channel, TheRoom()); } } void IrcChannel::SetTopic(const wxString &topic, const wxString &channel) { wxString the_chan = TheRoom(); if (!channel.IsSameAs("none")) { the_chan = channel; } m_irc->SetTopic(topic, the_chan); } void IrcChannel::SendTo(const wxString &who, const wxString &str) { m_irc->SendBack("PRIVMSG " + who + " :" + str); } void IrcChannel::SendMsg(const wxString &type, const wxString &msg, const wxString &who, const wxString &from) { wxString typed_message = type +" "+ msg + newline; wxString header = m_magic + m_room +" "+ from +" "; wxString address = who; if (who.IsSameAs("")) { address = m_room; } if (from.IsSameAs("")) { header = m_magic + m_room +" "+ m_irc->Login() +" "; } NoDebugMsg("Sending message " + address + " " + header + typed_message); SendTo(address,header + typed_message); } // IrcMsgEvent !!!!!!!!!!!!!!!!!!! IMPLEMENT_DYNAMIC_CLASS( IrcMsgEvent, wxEvent ) DEFINE_EVENT_TYPE(wxEVT_COMMAND_IRC_MESSAGE) DEFINE_EVENT_TYPE(wxEVT_COMMAND_IRC_JOINED) DEFINE_EVENT_TYPE(wxEVT_COMMAND_IRC_IJOINED) DEFINE_EVENT_TYPE(wxEVT_COMMAND_IRC_LEFT) IrcMsgEvent::IrcMsgEvent( wxEvtHandler* win, const wxString& from, const wxString& type, const wxString& message) { SetEventType( wxEVT_COMMAND_IRC_MESSAGE ); SetEventObject( win ); m_from = from; m_type = type; m_message = message; } #if wxCHECK_VERSION(2, 3, 0) #else void IrcMsgEvent::CopyObject( wxObject& obj_d ) const { wxCommandEvent::CopyObject( obj_d ); IrcMsgEvent &evt = (IrcMsgEvent &) obj_d; evt.m_from = m_from; evt.m_type = m_type; evt.m_message = m_message; } #endif