summaryrefslogtreecommitdiff
path: root/irc_mod/irc.h
blob: 9b790ed732068832247bbf5610197d2d12b24279 (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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
/*
IRC plugin for Miranda IM

Copyright (C) 2003 Jörgen Persson

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


#ifndef _IRCWIN_H_
#define _IRCWIN_H_

// disable a lot of warnings. It should comppile on VS 6 also
#pragma warning( disable : 4076 ) 
#pragma warning( disable : 4786 ) 
#pragma warning( disable : 4996 ) 

#define WIN32_LEAN_AND_MEAN	

//#if defined(_UNICODE)
//#endif

//#include "AggressiveOptimize.h"

/*
#include <windows.h>
#include <shlwapi.h>
#include <shlobj.h>
#include <objbase.h>
#include <shellapi.h>
#include <stdio.h>
#include <process.h>
#include <math.h>
#include <winsock.h>
#include <time.h>
#include "newpluginapi.h"
#include "m_system.h"
#include "m_protocols.h"
#include "m_protomod.h"
#include "m_protosvc.h"
#include "m_clist.h"
#include "m_options.h"
#include "m_database.h"
#include "m_utils.h"
#include "m_skin.h"
#include "m_netlib.h"
#include "m_clui.h"
#include "m_langpack.h"
#include "m_message.h"
#include "m_userinfo.h"
#include "m_addcontact.h"
#include "m_button.h"
#include "m_file.h"
#include "m_ignore.h"
#include "m_chat.h"
#include "m_ircscript.h"
#include "resource.h"
#include "irclib.h"
#include "commandmonitor.h"
#include "IcoLib.h"
*/

#include <tchar.h>

// Windows includes
#include <windows.h>
#include <commctrl.h>	// ADDED
#include <commdlg.h>	// ADDED

// Standard includes
#include <shlwapi.h>
#include <shlobj.h>
#include <objbase.h>
#include <shellapi.h>
#include <stdio.h>
#include <process.h>
#include <math.h>
#include <winsock.h>
#include <time.h>

// ADDED
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#include <direct.h>
#include <fcntl.h>
#include <crtdbg.h>
#include <malloc.h>

// Miranda IM SDK includes
#include "newpluginapi.h"
#include "m_system.h"
#include "m_protocols.h"
#include "m_protomod.h"
#include "m_protosvc.h"
#include "m_clist.h"
#include "m_options.h"
#include "m_database.h"
#include "m_utils.h"
#include "m_skin.h"
#include "m_netlib.h"
#include "m_clui.h"
#include "m_langpack.h"
#include "m_message.h"
#include "m_userinfo.h"
#include "m_addcontact.h"
#include "m_button.h"
#include "m_file.h"
#include "m_ignore.h"
#include "m_chat.h"
#include "m_popup.h"
#include "m_popupw.h"
#include "m_icolib.h"

#include "m_updater.h"
#include "m_nudge.h"
#include "m_xstatus.h"
#include "m_cluiframes.h"

// Need FIX
#include "i18n.h"
#include "md5.h"

#include "utils.h"
#include "popups.h"

#include "iconlib.h"
#include "avatar.h"
#include "xstatus.h"

#include "m_ircscript.h"
#include "resource.h"
#include "irclib.h"
#include "commandmonitor.h"


#ifndef NDEBUG
#include <crtdbg.h>
#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
#endif

#ifdef _DEBUG
#define DBGprintf printf
#endif

#define	IRC_UPDATELIST				(WM_USER+1)
#define	IRC_QUESTIONAPPLY			(WM_USER+2)
#define	IRC_QUESTIONCLOSE			(WM_USER+3)
#define	IRC_ACTIVATE				(WM_USER+4)
#define	IRC_INITMANAGER				(WM_USER+5)
#define	IRC_REBUILDIGNORELIST		(WM_USER+6)
#define	IRC_UPDATEIGNORELIST		(WM_USER+7)
#define IRC_FIXIGNOREBUTTONS		(WM_USER+8)

#define STR_QUITMESSAGE				"\002Miranda IM!\002"
#define STR_USERINFO				"© 2000-2006 Miranda-IM project"
#define STR_AWAYMESSAGE				"I'm away from the computer." // Default away
#define DCCSTRING					" (DCC)"

#define DCC_CHAT		1
#define DCC_SEND		2

#define FILERESUME_CANCEL	11

// Defaults
#define	DEFAULT_VERSION_AUTO		0
#define DEFAULT_TYPING				0
#define DEFAULT_XSTATUS_ENABLED     0
#define DEFAULT_XSTATUS_AUTO        0
#define DEFAULT_XSTATUS_RESET       0
#define DEFAULT_XSTATUS_ADV			1

#define ADV_CNT		6

// Database setting names                           
// #define DBSETTING_CAPABILITIES      "caps"
#define DBSETTING_XSTATUSID         "XStatusId"
#define DBSETTING_XSTATUSNAME       "XStatusName"
#define DBSETTING_XSTATUSMSG        "XStatusMsg"

// capabilities
// typedef unsigned char capstr[0x10];

// Nudge
#define PS_SEND_NUDGE     "/SendNudge"

// Typing notification statuses
#define MTN_FINISHED                0x0000
#define MTN_TYPED                   0x0001
#define MTN_BEGUN                   0x0002

// Avatars
#define DEFAULT_AVATARS_ENABLED     1

//set owner avatar
//wParam=0
//lParam=(const char *)Avatar file name
//return=0 for sucess
#define PS_IRC_SETMYAVATAR "/SetMyAvatar"

//get current owner avatar
//wParam=(char *)Buffer to file name
//lParam=(int)Buffer size
//return=0 for sucess
#define PS_IRC_GETMYAVATAR "/GetMyAvatar"

//get size limit for avatar image
//wParam=(int *)max width of avatar - will be set
//lParam=(int *)max height of avatar - will be set
//return=0 for sucess
#define PS_IRC_GETMYAVATARMAXSIZE "/GetMyAvatarMaxSize"

//check if image format supported for avatars
//wParam = 0
//lParam = PA_FORMAT_*   // avatar format
//return = 1 (supported) or 0 (not supported)
#define PS_IRC_ISAVATARFORMATSUPPORTED "/IsAvatarFormatSupported"

//PopUp
#define DEFAULT_POPUPS_ENABLED      1

#define LOG_NOTE       0   //trivial problems or problems that will already have been reported elsewhere
#define LOG_WARNING    1   //problems that may have caused data loss
#define LOG_ERROR      2   //problems that cause a disconnection from the network
#define LOG_FATAL      3   //problems requiring user intervention: password wrong, rate exceeded, etc.

#define DEFAULT_LOG0_TEXT_COLORS    RGB(0,0,0)  // LOG_NOTE
#define DEFAULT_LOG0_BACK_COLORS    RGB(255,255,128)
#define DEFAULT_LOG0_TIMEOUT        5
#define DEFAULT_LOG1_TEXT_COLORS    RGB(0,0,0)  // LOG_WARNING
#define DEFAULT_LOG1_BACK_COLORS    RGB(128,128,128)
#define DEFAULT_LOG1_TIMEOUT        5
#define DEFAULT_LOG2_TEXT_COLORS    RGB(0,0,0)  // LOG_ERROR
#define DEFAULT_LOG2_BACK_COLORS    RGB(255,128,64)
#define DEFAULT_LOG2_TIMEOUT        5
#define DEFAULT_LOG3_TEXT_COLORS    RGB(0,0,0)  // LOG_FATAL
#define DEFAULT_LOG3_BACK_COLORS    RGB(255,0,0)
#define DEFAULT_LOG3_TIMEOUT        5

using namespace std;
using namespace irc;

// special service for tweaking performance, implemented in chat.dll
#define MS_GC_GETEVENTPTR  "GChat/GetNewEventPtr"
typedef int (*GETEVENTFUNC)(WPARAM wParam, LPARAM lParam);
typedef struct  {
	GETEVENTFUNC pfnAddEvent;
}GCPTRS;

#define IP_AUTO			1
#define IP_MANUAL		2

typedef struct IPRESOLVE_INFO_TYPE			// Contains info about the channels
{
	int iType;
	char * pszAdr;
} IPRESOLVE;

typedef struct WINDOW_INFO_TYPE			// Contains info about the channels
{
	char * pszTopic;
	char * pszMode;
	char * pszPassword;
	char * pszLimit;
} CHANNELINFO;

typedef struct SERVER_INFO_TYPE			// Contains info about different servers
{
	char * Group;
	char * Address;
	char * Name;
	char * PortStart;
	char * PortEnd;	
	int iSSL;
} SERVER_INFO;

typedef struct PERFORM_INFO_TYPE		// Contains 'Perform buffer' for different networks
{
	char * Perform;

} PERFORM_INFO;

typedef struct CONTACT_TYPE			// Contains info about users
{
	char * name;
	char * user;
	char * host;
	bool ExactOnly;
	bool ExactWCOnly;
	bool ExactNick;
} CONTACT;

typedef struct PREFERENCES_TYPE			// Preferences structure
{
	char ServerName[100];
	char Password [500];
	char IdentSystem[10];
	char Network[30];
	char PortStart[10];
	char PortEnd[10];
	int IdentTimer;
	int iSSL;
	char IdentPort[10];
	char RetryWait[10];
	char RetryCount[10];

	char Nick[30];
	char AlternativeNick[30];
	char Name[200];
	char UserID[200];
	char QuitMessage[400];
	char UserInfo[500];
	char MyHost[50];
	char MySpecifiedHost[500];
	char MySpecifiedHostIP[50];
	char MyLocalHost[50];
	char * Alias;
	int ServerComboSelection;
	int QuickComboSelection;
	int OnlineNotificationTime;
	int OnlineNotificationLimit;
	BYTE ScriptingEnabled;

	BYTE VersionAuto;
	BYTE NudgeEnabled;
	BYTE TypingEnabled;
	BYTE XStatusEnabled;
	BYTE XStatusReset;
	BYTE XStatusAuto;
	BYTE XStatusAdv;

	BYTE AvatarsEnabled;
	BYTE AvatarsAutoLoad;
	BYTE AvatarsAutoLink;

	BYTE UseMemoServ;
	char MemoServName[30];
	BYTE MemoServAuto;

	BYTE PopupsEnabled;
	BYTE PopupsErrors;
	BYTE PopupWhois;
	BYTE PopupsWhoisNoUser;

	BYTE IPFromServer;
	BYTE ShowAddresses;
	BYTE DisconnectDCCChats;
	BYTE DisableErrorPopups;
	BYTE RejoinChannels;
	BYTE RejoinIfKicked;
	BYTE HideServerWindow;
	BYTE Ident;
	BYTE Retry;
	BYTE DisableDefaultServer;
	BYTE AutoOnlineNotification;
	BYTE SendKeepAlive;
	BYTE JoinOnInvite;
	BYTE Perform;
	BYTE ForceVisible;
	BYTE Ignore;
	BYTE IgnoreChannelDefault;
	BYTE UseServer;
	BYTE DCCFileEnabled;
	BYTE DCCChatEnabled;
	BYTE DCCChatAccept;
	BYTE DCCChatIgnore;
	BYTE DCCPassive;
	BYTE ManualHost;
	BYTE OldStyleModes;
	BYTE ChannelAwayNotification;
	BYTE SendNotice;
	POINT ListSize;
	COLORREF colors[16];
	HICON hIcon[13];

} PREFERENCES;

typedef struct WHOIS_TYPE			// Whois structure
{
	char _Name[100];
	char _ID[100];
	char _Server[100];
	char _Address[100];
	char _Auth[100];
	char _Channels[100];
	char _Other[100];
	char _Idle[100];
	char _Away[100];
} WHOIS;

//main.cpp
void						UpgradeCheck(void);

//services.cpp
void						HookEvents(void);
void						UnhookEvents(void);
void						CreateServiceFunctions(void);
void						ConnectToServer(void);
void						DisconnectFromServer(void);
int							Service_GCEventHook(WPARAM wParam,LPARAM lParam);
void						sendTypingNotification(HANDLE hContact, WORD wMTNCode);
void						handleNudgeNotification(const char* NickName);
void						handleTypingNotification(const char* NickName, WORD wMTNCode);
void						handleXStatus(const char* NickName);
void						handleAvatarHash(const char* NickName);

//options.cpp
void						InitPrefs(void);
void						UnInitOptions(void);
int							InitOptionsPages(WPARAM wParam,LPARAM lParam);
void						InitIcons(void);
HICON						LoadIconEx(int iIndex, char * pszIcoLibName, int iX, int iY);

//tools.cpp
int							WCCmp(char* wild, char *string);
char *						IrcLoadFile(char * szPath);
void						AddToJTemp(String sCommand);
void __cdecl				forkthread_r(void *param);
unsigned long				forkthread (	void (__cdecl *threadcode)(void*),unsigned long stacksize,void *arg);
String						GetWord(const char * text, int index);
String						ReplaceString (String text, char * replaceme, char * newword);
bool						IsChannel(String sName); 
char *						GetWordAddress(const char * text, int index);
String						RemoveLinebreaks(String Message);
char*						my_strstri(char *s1, char *s2) ;
char *						DoColorCodes (const char * text, bool bStrip, bool bReplacePercent);
int							DoEvent(int iEvent, const char* pszWindow, const char * pszNick, const char* pszText, const char* pszStatus, const char* pszUserInfo, DWORD dwItemData, bool bAddToLog, bool bIsMe,time_t timestamp = 1);
int							CallChatEvent(WPARAM wParam, LPARAM lParam);
String						ModeToStatus(char sMode) ;
String						PrefixToStatus(char cPrefix) ;
void						SetChatTimer(UINT_PTR &nIDEvent,UINT uElapse,TIMERPROC lpTimerFunc);
void						KillChatTimer(UINT_PTR &nIDEvent);
int							SetChannelSBText(String sWindow, CHANNELINFO * wi);
String						MakeWndID(String sWindow);
bool						FreeWindowItemData(String window, CHANNELINFO* wis);
bool						AddWindowItemData(String window, const char * pszLimit, const char * pszMode, const char * pszPassword, const char * pszTopic);
void						FindLocalIP(HANDLE con);
void						DoUserhostWithReason(int type, String reason, bool bSendCommand, String userhostparams, ...);
String						GetNextUserhostReason(int type);
void						ClearUserhostReasons(int type);
String						PeekAtReasons(int type);
//clist.cpp
HANDLE						CList_AddContact(struct CONTACT_TYPE * user, bool InList, bool SetOnline);
bool						CList_SetAllOffline(BYTE ChatsToo);
HANDLE						CList_SetOffline(struct CONTACT_TYPE * user);

bool						CList_AddEvent(struct CONTACT_TYPE * user, HICON Icon, HANDLE event, const char * tooltip, int type ) ;
HANDLE						CList_FindContact (struct CONTACT_TYPE * user);
int							WCCmp(char* wild, char *string);
BOOL						CList_AddDCCChat(String name, String hostmask, unsigned long adr, int port) ;

//input.cpp
bool						PostIrcMessageWnd(char * pszWindow, HANDLE hContact,const char * szBuf);
bool						PostIrcMessage( const char * fmt, ...);

//output
BOOL						ShowMessage (const CIrcMessage* pmsg);

//windows.cpp
BOOL CALLBACK				MessageboxWndProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam);
BOOL CALLBACK				InfoWndProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam);
BOOL CALLBACK				NickWndProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam);
BOOL CALLBACK				JoinWndProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam);
BOOL CALLBACK				InitWndProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam);
BOOL CALLBACK				ListWndProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam);
BOOL CALLBACK				QuickWndProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam);
BOOL CALLBACK				UserDetailsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK				ManagerWndProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam);
BOOL CALLBACK				QuestionWndProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam);
int CALLBACK				ListViewSort(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
LRESULT CALLBACK			MgrEditSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) ;

//commandmonitor.cpp
VOID CALLBACK				KeepAliveTimerProc(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime);
VOID CALLBACK				OnlineNotifTimerProc(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime);
VOID CALLBACK				OnlineNotifTimerProc3(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime);

//scripting.cpp
int Scripting_InsertRawIn(WPARAM wParam,LPARAM lParam);
int Scripting_InsertRawOut(WPARAM wParam,LPARAM lParam);
int Scripting_InsertGuiIn(WPARAM wParam,LPARAM lParam);
int Scripting_InsertGuiOut(WPARAM wParam,LPARAM lParam);
int Scripting_GetIrcData(WPARAM wparam, LPARAM lparam);
BOOL Scripting_TriggerMSPRawIn(char ** pszRaw);
BOOL Scripting_TriggerMSPRawOut(char ** pszRaw);
BOOL Scripting_TriggerMSPGuiIn(WPARAM * wparam, GCEVENT * gce);
BOOL Scripting_TriggerMSPGuiOut(GCHOOK * gch);

#ifndef NDEBUG
#include <crtdbg.h>
#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
#endif

#pragma comment(lib,"comctl32.lib")

#endif