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
|
/*
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 "stdafx.h"
INT_PTR __cdecl CIrcProto::Scripting_InsertRawIn(WPARAM, LPARAM lParam)
{
char* pszRaw = (char*)lParam;
if (m_scriptingEnabled && pszRaw && IsConnected()) {
wchar_t* p = mir_a2u(pszRaw);
InsertIncomingEvent(p);
mir_free(p);
return 0;
}
return 1;
}
INT_PTR __cdecl CIrcProto::Scripting_InsertRawOut( WPARAM, LPARAM lParam )
{
char* pszRaw = (char*)lParam;
if (m_scriptingEnabled && pszRaw && IsConnected()) {
CMStringA S = pszRaw;
S.Replace("%", "%%%%");
NLSendNoScript((const unsigned char *)S.c_str(), (int)mir_strlen(S.c_str()));
return 0;
}
return 1;
}
INT_PTR __cdecl CIrcProto::Scripting_InsertGuiIn(WPARAM, LPARAM)
{
return 1;
}
//helper functions
static void __stdcall OnHook(void * pi)
{
GCHOOK* gch = (GCHOOK*)pi;
free(gch->ptszUID);
free(gch->ptszText);
free((void*)gch->ptszID);
free((void*)gch->pszModule);
delete gch;
}
static void __cdecl GuiOutThread(GCHOOK *gch)
{
Thread_SetName("IRC: GuiOutThread");
CallFunctionAsync(OnHook, gch);
}
INT_PTR __cdecl CIrcProto::Scripting_InsertGuiOut(WPARAM, LPARAM lParam)
{
GCHOOK* gch = (GCHOOK*)lParam;
if (m_scriptingEnabled && gch) {
GCHOOK* gchook = new GCHOOK;
gchook->dwData = gch->dwData;
gchook->iType = gch->iType;
if (gch->ptszText)
gchook->ptszText = wcsdup(gch->ptszText);
else
gchook->ptszText = nullptr;
if (gch->ptszUID)
gchook->ptszUID = wcsdup(gch->ptszUID);
else
gchook->ptszUID = nullptr;
if (gch->ptszID) {
CMStringW S = MakeWndID(gch->ptszID);
gchook->ptszID = wcsdup(S.c_str());
}
else gchook->ptszID = nullptr;
if (gch->pszModule)
gchook->pszModule = _strdup(gch->pszModule);
else
gchook->pszModule = nullptr;
mir_forkThread<GCHOOK>(GuiOutThread, gchook);
return 0;
}
return 1;
}
INT_PTR __cdecl CIrcProto::Scripting_GetIrcData(WPARAM, LPARAM lparam)
{
if (m_scriptingEnabled && lparam) {
CMStringA sString = (char*)lparam, sRequest;
CMStringW sOutput, sChannel;
int i = sString.Find("|");
if (i != -1) {
sRequest = sString.Mid(0, i);
wchar_t* p = mir_a2u(sString.Mid(i + 1));
sChannel = p;
mir_free(p);
}
else sRequest = sString;
sRequest.MakeLower();
if (sRequest == "ownnick" && IsConnected())
sOutput = m_info.sNick;
else if (sRequest == "network" && IsConnected())
sOutput = m_info.sNetwork;
else if (sRequest == "primarynick")
sOutput = m_nick;
else if (sRequest == "secondarynick")
sOutput = m_alternativeNick;
else if (sRequest == "myip")
return (INT_PTR)mir_strdup(m_manualHost ? m_mySpecifiedHostIP :
(m_IPFromServer) ? m_myHost : m_myLocalHost);
else if (sRequest == "usercount" && !sChannel.IsEmpty()) {
CMStringW S = MakeWndID(sChannel.c_str());
GC_INFO gci = { 0 };
gci.Flags = GCF_BYID | GCF_COUNT;
gci.pszModule = m_szModuleName;
gci.pszID = S.c_str();
if (!Chat_GetInfo(&gci)) {
wchar_t szTemp[40];
mir_snwprintf(szTemp, L"%u", gci.iCount);
sOutput = szTemp;
}
}
else if (sRequest == "userlist" && !sChannel.IsEmpty()) {
CMStringW S = MakeWndID(sChannel.c_str());
GC_INFO gci = { 0 };
gci.Flags = GCF_BYID | GCF_USERS;
gci.pszModule = m_szModuleName;
gci.pszID = S.c_str();
if (!Chat_GetInfo(&gci))
return (INT_PTR)mir_strdup(gci.pszUsers);
}
else if (sRequest == "channellist") {
CMStringW S = L"";
int n = pci->SM_GetCount(m_szModuleName);
if (n >= 0) {
int j = 0;
while (j < n) {
GC_INFO gci = { 0 };
gci.Flags = GCF_BYINDEX | GCF_ID;
gci.pszModule = m_szModuleName;
gci.iItem = j;
if (!Chat_GetInfo(&gci)) {
if (mir_wstrcmpi(gci.pszID, SERVERWINDOW)) {
CMStringW S1 = gci.pszID;
int k = S1.Find(L" ");
if (k != -1)
S1 = S1.Mid(0, k);
S += S1 + L" ";
}
}
j++;
}
}
if (!S.IsEmpty())
sOutput = (wchar_t*)S.c_str();
}
// send it to mbot
if (!sOutput.IsEmpty())
return (INT_PTR)mir_u2a(sOutput.c_str());
}
return 0;
}
|