summaryrefslogtreecommitdiff
path: root/protocols/IRCG/src/output.cpp
blob: 6a97f45baf12739c571db16cf2ef6d33e4ae3954 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
IRC plugin for Miranda IM

Copyright (C) 2003-05 Jurgen Persson
Copyright (C) 2007-09 George Hazan

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.
*/

#include "irc.h"

static CMString FormatOutput (const CIrcMessage* pmsg)
{
	CMString sMessage;

	if ( pmsg->m_bIncoming ) { // Is it an incoming message?
		if ( pmsg->sCommand == _T("WALLOPS") && pmsg->parameters.getCount() > 0 ) {
			TCHAR temp[200]; *temp = '\0';
			mir_sntprintf(temp, SIZEOF(temp), TranslateT("WallOps from %s: "), pmsg->prefix.sNick.c_str());
			sMessage = temp;
			for ( int i=0; i < (int)pmsg->parameters.getCount(); i++ ) {
				sMessage += pmsg->parameters[i];
				if (i != pmsg->parameters.getCount()-1)
					sMessage += _T(" ");
			}
			goto THE_END;
		}
		
		if ( pmsg->sCommand == _T("INVITE") && pmsg->parameters.getCount() > 1 ) {
			TCHAR temp[256]; *temp = '\0';
			mir_sntprintf(temp, SIZEOF(temp), TranslateT("%s invites you to %s"), pmsg->prefix.sNick.c_str(), pmsg->parameters[1].c_str());
			sMessage = temp;
			for ( int i=2; i < (int)pmsg->parameters.getCount(); i++ ) {
				sMessage += _T(": ") + pmsg->parameters[i];
				if ( i != pmsg->parameters.getCount()-1 )
					sMessage += _T(" ");
			}
			goto THE_END;
		}
		
		int index = StrToInt( pmsg->sCommand.c_str());
		if ( index == 301 && pmsg->parameters.getCount() > 0 ) {
			TCHAR temp[500]; *temp = '\0';
			mir_sntprintf(temp, SIZEOF(temp), TranslateT("%s is away"), pmsg->parameters[1].c_str());
			sMessage = temp;
			for ( int i=2; i < (int)pmsg->parameters.getCount(); i++ ) {
				sMessage += _T(": ") + pmsg->parameters[i];
				if ( i != pmsg->parameters.getCount()-1 )
					sMessage += _T(" ");
			}
			goto THE_END;
		}
		
		if (( index == 443 || index == 441 ) && pmsg->parameters.getCount() > 3 )
			return pmsg->parameters[1] + _T(" ") + pmsg->parameters[3] + _T(": ") + pmsg->parameters[2];
		
		if ( index == 303 ) {  // ISON command
			sMessage = TranslateT("These are online: ");
			for ( int i=1; i < (int)pmsg->parameters.getCount(); i++ ) {
				sMessage += pmsg->parameters[i];
				if (i != pmsg->parameters.getCount()-1)
					sMessage += _T(", ");
			}
			goto THE_END;
		}
		
		if (( index > 400 || index < 500) && pmsg->parameters.getCount() > 2 && pmsg->sCommand[0] == '4' ) //all error messages
			return pmsg->parameters[2] + _T(": ") + pmsg->parameters[1];
	}
	else if ( pmsg->sCommand == _T("NOTICE") && pmsg->parameters.getCount() > 1 ) {
		TCHAR temp[500]; *temp = '\0';

		int l = pmsg->parameters[1].GetLength();
		if ( l > 3 && pmsg->parameters[1][0] == 1 && pmsg->parameters[1][ l-1 ] == 1 ) {
			// CTCP reply
			CMString tempstr = pmsg->parameters[1];
			tempstr.Delete(0,1);
			tempstr.Delete(tempstr.GetLength()-1,1);
			CMString type = GetWord(tempstr.c_str(), 0);
			if ( lstrcmpi(type.c_str(), _T("ping")) == 0)
				mir_sntprintf(temp, SIZEOF(temp), TranslateT("CTCP %s reply sent to %s"), type.c_str(), pmsg->parameters[0].c_str());
			else
				mir_sntprintf(temp, SIZEOF(temp), TranslateT("CTCP %s reply sent to %s: %s"), type.c_str(), pmsg->parameters[0].c_str(), GetWordAddress(tempstr.c_str(), 1));
			sMessage = temp;
		}
		else {
			mir_sntprintf(temp, SIZEOF(temp), TranslateT("Notice to %s: "), pmsg->parameters[0].c_str());
			sMessage = temp;
			for ( int i=1; i < (int)pmsg->parameters.getCount(); i++ ) {
				sMessage += pmsg->parameters[i];
				if (i != pmsg->parameters.getCount()-1)
					sMessage += _T(" ");
		}	}
		goto THE_END;
	}

	// Default Message handler.	

	if ( pmsg->m_bIncoming ) {
		if ( pmsg->parameters.getCount() < 2 && pmsg->parameters.getCount() > 0 )
			return pmsg->sCommand + _T(" : ") + pmsg->parameters[0];
	
		if ( pmsg->parameters.getCount() > 1 )
			for ( int i=1; i < (int)pmsg->parameters.getCount(); i++ )
				sMessage += pmsg->parameters[i] + _T(" ");
	}
	else {
		if ( pmsg->prefix.sNick.GetLength())
			sMessage = pmsg->prefix.sNick + _T(" ");
		sMessage += pmsg->sCommand + _T(" ");
		for ( int i=0; i < (int)pmsg->parameters.getCount(); i++ )
			sMessage += pmsg->parameters[i] + _T(" ");
	}

THE_END:
	return sMessage;
}

BOOL CIrcProto::ShowMessage (const CIrcMessage* pmsg)
{
	CMString mess = FormatOutput(pmsg);

	if ( !pmsg->m_bIncoming )
		ReplaceString( mess, _T("%%"), _T("%"));

	int iTemp = StrToInt( pmsg->sCommand.c_str());

	//To active window
	if (( iTemp > 400 || iTemp < 500 ) && pmsg->sCommand[0] == '4' //all error messages	
		|| pmsg->sCommand == _T("303")		//ISON command
		|| pmsg->sCommand == _T("INVITE")
		|| ( (pmsg->sCommand == _T("NOTICE")) && ( (pmsg->parameters.getCount() > 2) ? (_tcsstr(pmsg->parameters[1].c_str(), _T("\001"))==NULL) : false)) // CTCP answers should go to m_network Log window!
		|| pmsg->sCommand == _T("515"))		//chanserv error
	{
		DoEvent(GC_EVENT_INFORMATION, NULL, pmsg->m_bIncoming?pmsg->prefix.sNick.c_str():m_info.sNick.c_str(), mess.c_str(), NULL, NULL, NULL, true, pmsg->m_bIncoming?false:true); 
		return TRUE;
	}

	if ( m_useServer ) {
		DoEvent( GC_EVENT_INFORMATION, SERVERWINDOW, 
			( pmsg->m_bIncoming ) ? pmsg->prefix.sNick.c_str() : m_info.sNick.c_str(),
			mess.c_str(), NULL, NULL, NULL, true, pmsg->m_bIncoming ? false : true ); 
		return true;
	}
	return false;
}