123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635 |
- /*
- * The contents of this file are subject to the Mozilla Public
- * License Version 1.1 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS
- * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
- * implied. See the License for the specific language governing
- * rights and limitations under the License.
- *
- * The Original Code is Vision.
- *
- * The Initial Developer of the Original Code is The Vision Team.
- * Portions created by The Vision Team are
- * Copyright (C) 1999, 2000, 2001 The Vision Team. All Rights
- * Reserved.
- *
- * Contributor(s): Wade Majors <wade@ezri.org>
- * Rene Gollent
- * Todd Lair
- * Andrew Bazan
- * Jamie Wilkinson
- * Bjorn Oksholen
- * Alan Ellis <alan@cgsoftware.org>
- */
-
- #include "Vision.h"
- #include "Utilities.h"
- #include "StatusView.h"
- #include "ServerAgent.h"
- #include "ChannelAgent.h"
- #include "MessageAgent.h"
- #include "ClientWindow.h"
- #include "WindowList.h"
- #include <stdio.h>
- /* #6502 was here --
- <kurros> regurg, amiyumi?
- <regurg> Let's discuss further why your pizza NOW.
- <kurros> uh
- <slaad> ?
- <kurros> yeah
- */
- bool
- ServerAgent::ParseEvents (const char *data)
- {
- BString firstWord = GetWord(data, 1).ToUpper();
- BString secondWord = GetWord(data, 2).ToUpper();
- if (secondWord == "PRIVMSG")
- {
- BString theNick (GetNick (data)),
- ident (GetIdent (data)),
- address (GetAddress (data)),
- addy;
-
- addy += ident;
- addy += "@";
- addy += address;
- BString theTarget (GetWord (data, 3).ToUpper()),
- theTargetOrig (GetWord (data, 3)),
- theMsg (RestOfString (data, 4));
-
- ClientAgent *client (0);
- theMsg.RemoveFirst(":");
-
- if (theMsg.Length() == 0)
- return true;
- if (theMsg[0] == '\1' && GetWord (theMsg.String(), 1) != "\1ACTION")
- {
- // CTCP Request
- ParseCTCP (theNick, theTargetOrig, theMsg);
- return true;
- }
- if (theTarget[0] == '#'
- || theTarget[0] == '!'
- || theTarget[0] == '&'
- || theTarget[0] == '+')
- client = Client (theTarget.String());
- else if (!(client = Client (theNick.String())))
- {
- BString msgident (GetIdent (data)),
- msgaddress (GetAddress (data));
-
- client = new MessageAgent (
- *vision_app->pClientWin()->AgentRect(),
- theNick.String(),
- fId.String(),
- fSMsgr,
- fMyNick.String(),
- addy.String()),
- vision_app->pClientWin()->pWindowList()->AddAgent (client,
- theNick.String(),
- WIN_MESSAGE_TYPE,
- false);
- fClients.AddItem (client);
- }
- if (client)
- {
- BString msgident (GetIdent (data)),
- msgaddress (GetAddress (data));
- client->ChannelMessage (
- theMsg.String(),
- theNick.String(),
- msgident.String(),
- msgaddress.String());
- }
- return true;
- }
- if (firstWord == "NOTICE")
- {
- BString theNotice (RestOfString(data, 3));
- theNotice.RemoveFirst(":");
- BString tempString;
-
- const char *expansions[2];
- expansions[0] = fServerHostName.String();
- expansions[1] = theNotice.String();
- tempString = ExpandKeyed (fEvents[E_SNOTICE].String(), "NR", expansions);
- Display (tempString.String(), C_NOTICE);
-
- return true;
- }
- if (secondWord == "NOTICE")
- {
- BString theNotice (RestOfString(data, 4));
- theNotice.RemoveFirst(":");
- BString tempString;
- firstWord.RemoveFirst (":");
- if (firstWord.ICompare (fServerHostName) == 0)
- {
- const char *expansions[2];
- expansions[0] = fServerHostName.String();
- expansions[1] = theNotice.String();
- tempString = ExpandKeyed (fEvents[E_SNOTICE].String(), "NR", expansions);
- Display (tempString.String(), C_NOTICE);
- return true;
- }
- else
- {
- BString theNick (GetNick (data)),
- ident (GetIdent (data)),
- address (GetAddress (data));
-
- if ((theNotice.Length() > 0) && theNotice[0] == '\1')
- {
- // CTCP reply
- ParseCTCPResponse (theNick, theNotice);
- return true;
- }
- const char *expansions[4];
- expansions[0] = theNick.String();
- expansions[1] = theNotice.String();
- expansions[2] = ident.String();
- expansions[3] = address.String();
- tempString = ExpandKeyed (fEvents[E_UNOTICE].String(), "NRIA", expansions);
- BMessage display (M_DISPLAY);
- PackDisplay (&display, tempString.String(), C_NOTICE);
- PostActive (&display);
- return true;
- }
- }
- if (secondWord == "JOIN")
- {
- BString nick (GetNick (data)),
- channel (GetWord (data, 3));
- channel.RemoveFirst (":");
- ClientAgent *client (Client (channel.String()));
- if (nick == fMyNick)
- {
- bool activateChan (true);
- int32 chanCount (0);
- if ((chanCount = fStartupChannels.CountItems()) > 0)
- {
- for (int32 i = 0; i < chanCount; i++)
- if ((fStartupChannels.ItemAt (i)->ICompare (channel)) == 0)
- {
- delete fStartupChannels.RemoveItemAt (i);
- activateChan = false;
- break;
- }
- }
- if (!client)
- {
- ChannelAgent *newAgent (new ChannelAgent (
- channel.String(),
- fId.String(),
- fIrcdtype,
- fMyNick.String(),
- fSMsgr,
- *vision_app->pClientWin()->AgentRect()));
-
- vision_app->pClientWin()->pWindowList()->AddAgent (newAgent,
- channel.String(),
- WIN_CHANNEL_TYPE,
- activateChan);
- fClients.AddItem (newAgent);
- }
- BString tempString ("MODE ");
- tempString += channel;
- SendData (tempString.String());
- }
- else if (client)
- {
- // someone else
- BString ident (GetIdent (data)),
- address (GetAddress (data)),
- tempString;
-
- const char *expansions[3];
- expansions[0] = nick.String();
- expansions[1] = ident.String();
- expansions[2] = address.String();
- tempString = ExpandKeyed (fEvents[E_JOIN].String(), "NIA", expansions);
-
- BMessage display (M_DISPLAY);
-
- PackDisplay (
- &display,
- tempString.String(),
- C_JOIN);
-
- // add ignore code here
- bool ignored (false);
- BMessage msg (M_USER_ADD);
- msg.AddString ("nick", nick.String());
- msg.AddBool ("ignore", ignored);
- // don't bother displaying if the user puts an empty string
- if (tempString.Length() > 1)
- {
- msg.AddMessage ("display", &display);
- }
- client->fMsgr.SendMessage (&msg);
- }
- return true;
- }
- if (secondWord == "PART")
- {
- BString nick (GetNick (data)),
- channel (GetWord (data, 3)),
- reason (RestOfString(data, 4));
-
- // some servers seem to add this, shouldn't be there though
- channel.RemoveFirst(":");
- reason.RemoveFirst(":");
-
- if (reason == "-9z99")
- {
- reason = "";
- }
- ClientAgent *client;
- if ((client = Client (channel.String())) != 0)
- {
- BString ident (GetIdent (data)),
- address (GetAddress (data)),
- buffer;
-
- const char *expansions[4];
- expansions[0] = nick.String();
- expansions[1] = ident.String();
- expansions[2] = address.String();
- expansions[3] = reason.String();
- buffer = ExpandKeyed (fEvents[E_PART].String(), "NIAR", expansions);
- BMessage display (M_DISPLAY);
- PackDisplay (&display, buffer.String(), C_JOIN);
- BMessage msg (M_USER_QUIT);
- msg.AddString ("nick", nick.String());
- if (buffer.Length() > 1)
- {
- msg.AddMessage ("display", &display);
- }
- client->fMsgr.SendMessage (&msg);
- }
- return true;
- }
- if (secondWord == "NICK")
- {
- BString oldNick (GetNick (data)),
- ident (GetIdent (data)),
- address (GetAddress (data)),
- newNick (GetWord (data, 3)),
- buffer;
-
- newNick.RemoveFirst (":");
-
- const char *expansions[4];
- expansions[0] = oldNick.String();
- expansions[1] = newNick.String();
- expansions[2] = ident.String();
- expansions[3] = address.String();
- buffer = ExpandKeyed (fEvents[E_NICK].String(), "NnIA", expansions);
- BMessage display (M_DISPLAY);
- PackDisplay (&display, buffer.String(), C_NICK);
- BMessage msg (M_CHANGE_NICK);
- msg.AddString ("oldnick", oldNick.String());
- msg.AddString ("newnick", newNick.String());
- msg.AddString ("ident", ident.String());
- msg.AddString ("address", address.String());
- msg.AddMessage ("display", &display);
- Broadcast (&msg);
- // Gotta change the server as well!
- if (fMyNick.ICompare (oldNick) == 0)
- {
- fMyNick = newNick;
- if (!fReacquiredNick && (fMyNick == fReconNick))
- fReacquiredNick = true;
- if (!IsHidden())
- vision_app->pClientWin()->pStatusView()->SetItemValue (STATUS_NICK,
- newNick.String());
- }
- return true;
- }
- if (secondWord == "QUIT")
- {
- BString theNick (GetNick (data).String()),
- theRest (RestOfString (data, 3)),
- ident (GetIdent (data)),
- address (GetAddress (data)),
- theMsg,
- firstNick;
-
- theRest.RemoveFirst (":");
-
- const char *expansions[4];
- expansions[0] = theNick.String();
- expansions[1] = theRest.String();
- expansions[2] = ident.String();
- expansions[3] = address.String();
- theMsg = ExpandKeyed (fEvents[E_QUIT].String(), "NRIA", expansions);
-
- BMessage display (M_DISPLAY);
- PackDisplay (&display, theMsg.String(), C_QUIT);
- BMessage msg (M_USER_QUIT);
- if (theMsg.Length() > 1)
- {
- msg.AddMessage ("display", &display);
- }
- msg.AddString ("nick", theNick.String());
- Broadcast (&msg);
- // see if we had this nickname previously.
- // (we might have been disconnected and this could be a
- // connection waiting to time out)
- if (theNick == fReconNick)
- {
- BString tempCmd ("/nick ");
- tempCmd += fReconNick;
- ParseCmd (tempCmd.String());
- }
- return true;
- }
- if (firstWord == "PING")
- {
- BString tempString,
- theServer (GetWord(data, 2));
-
- theServer.RemoveFirst(":");
- tempString += "PONG ";
- tempString += fMyNick;
- tempString += " ";
- tempString += theServer;
- SendData (tempString.String());
- // some noncompliant servers dont like the above (correct) reply,
- // so we send this one, too.
- // this can't be contained in an ircdtype if because the first reply
- // is sent before we receive the server version.
- tempString = "";
- tempString += "PONG ";
- tempString += theServer;
- SendData (tempString.String());
-
- return true;
- }
- if (secondWord == "KICK")
- {
- BString kicker (GetNick (data)),
- kickee (GetWord (data, 4)),
- rest (RestOfString (data, 5)),
- channel (GetWord (data, 3));
- ClientAgent *client (Client (channel.String()));
- rest.RemoveFirst (":");
- if ((client = Client (channel.String())) != 0
- && kickee == fMyNick)
- {
- BMessage msg (M_CHANNEL_GOT_KICKED);
- msg.AddString ("channel", channel.String());
- msg.AddString ("kicker", kicker.String());
- msg.AddString ("rest", rest.String());
- client->fMsgr.SendMessage (&msg);
- }
- if (client && kickee != fMyNick)
- {
- BMessage display (M_DISPLAY);
- const char *expansions[4];
- BString buffer;
- expansions[0] = kickee.String();
- expansions[1] = channel.String();
- expansions[2] = kicker.String();
- expansions[3] = rest.String();
- buffer = ExpandKeyed (fEvents[E_KICK].String(), "NCnR", expansions);
- PackDisplay (&display, buffer.String(), C_QUIT);
- BMessage msg (M_USER_QUIT);
- msg.AddString ("nick", kickee.String());
- msg.AddMessage ("display", &display);
- client->fMsgr.SendMessage (&msg);
- }
- return true;
- }
-
- if (secondWord == "TOPIC")
- {
- BString theNick (GetNick (data)),
- theChannel (GetWord (data, 3)),
- theTopic (RestOfString (data, 4));
- ClientAgent *client (Client (theChannel.String()));
- theTopic.RemoveFirst (":");
- if (client)
- {
- BString ident (GetIdent (data)),
- address (GetAddress (data)),
- buffer;
- const char *expansions[5];
- expansions[0] = theNick.String();
- expansions[1] = theTopic.String();
- expansions[2] = client->Id().String();
- expansions[3] = ident.String();
- expansions[4] = address.String();
- BMessage topic (M_CHANNEL_TOPIC);
- topic.AddString("topic", theTopic.String());
- BMessage display (M_DISPLAY);
- buffer = ExpandKeyed (fEvents[E_TOPIC].String(), "NTCIA", expansions);
- PackDisplay (&display, buffer.String(), C_WHOIS);
- topic.AddMessage("display", &display);
- client->fMsgr.SendMessage (&topic);
- }
- return true;
- }
- if (secondWord == "MODE")
- {
- BString theNick (GetNick (data)),
- theChannel (GetWord (data, 3)),
- theMode (GetWord (data, 4)),
- theTarget (RestOfString (data, 5));
- ClientAgent *client (Client (theChannel.String()));
- if (client)
- {
- BMessage msg (M_CHANNEL_MODE);
- msg.AddString("nick", theNick.String());
- msg.AddString("mode", theMode.String());
- msg.AddString("target", theTarget.String());
- client->fMsgr.SendMessage (&msg);
- }
- else
- {
- BMessage msg (M_DISPLAY);
- BString buffer;
- theMode.RemoveFirst(":");
- buffer += S_PEVENTS_UMODE_CHANGE;
- buffer += theMode;
- buffer += "\n";
-
- PackDisplay (&msg, buffer.String());
- PostActive (&msg);
- }
- return true;
- }
- if (firstWord == "ERROR") // server error (on connect?)
- {
- BString theError (RestOfString (data, 2));
- theError.RemoveFirst (":");
- theError.Append ("\n");
- Display (theError.String(), C_QUIT);
-
- return true;
- }
- if (secondWord == "WALLOPS")
- {
- BString theNick (GetNick (data)),
- theWall (RestOfString (data, 3)),
- tempString;
- theWall.RemoveFirst (":");
- theWall.Append ("\n");
- tempString += "!";
- tempString += theNick;
- tempString += "! ";
- tempString += theWall;
-
- if (IsHidden())
- {
- BMessage statusMsg (M_CW_UPDATE_STATUS);
- statusMsg.AddPointer ("item", fAgentWinItem);
- statusMsg.AddInt32 ("status", WIN_NEWS_BIT);
- Window()->PostMessage (&statusMsg);
- }
-
- Display (tempString.String(), C_WALLOPS);
- return true;
- }
- if (secondWord == "INVITE")
- {
- BString tempString,
- theChannel (GetWord(data, 4));
- theChannel.RemoveFirst(":");
- tempString += S_PEVENTS_INVITE1;
- tempString += theChannel;
- tempString += S_PEVENTS_INVITE2;
- tempString += GetNick(data);
- tempString += ".\n";
- BMessage msg (M_DISPLAY);
- PackDisplay (&msg, tempString.String(), C_WHOIS);
- PostActive (&msg);
- return true;
- }
- if (secondWord == "SILENCE")
- {
- BString tempString,
- theHostmask (GetWord(data, 3)); // Could be a hostmask, a nick, whatever
- const char *hostmask = theHostmask.String();
-
- if (hostmask[0] == '+') {
- tempString += S_PEVENTS_SILENCE_ADDED;
- theHostmask.RemoveFirst("+");
- } else {
- tempString += S_PEVENTS_SILENCE_REMOVED;
- theHostmask.RemoveFirst("-");
- }
- tempString += theHostmask;
- tempString += ".\n";
- BMessage msg (M_DISPLAY);
- PackDisplay (&msg, tempString.String(), C_WHOIS);
- PostActive (&msg);
- return true;
- }
- // ship off to parse numerics
- return ParseENums (data, secondWord.String());
-
- }
|