From 6243cc7ff0fdea65144d30f998c184a189238848 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 26 Jun 2021 16:44:39 +0300 Subject: for #2928 - atavism removed from IRC: scripting support --- protocols/IRCG/src/irclib.cpp | 43 +++------- protocols/IRCG/src/ircproto.cpp | 5 -- protocols/IRCG/src/ircproto.h | 9 -- protocols/IRCG/src/options.cpp | 6 +- protocols/IRCG/src/resource.h | 1 - protocols/IRCG/src/scripting.cpp | 176 --------------------------------------- protocols/IRCG/src/version.h | 2 +- 7 files changed, 13 insertions(+), 229 deletions(-) delete mode 100644 protocols/IRCG/src/scripting.cpp (limited to 'protocols/IRCG/src') diff --git a/protocols/IRCG/src/irclib.cpp b/protocols/IRCG/src/irclib.cpp index 0fe6ed79ef..73629ae988 100644 --- a/protocols/IRCG/src/irclib.cpp +++ b/protocols/IRCG/src/irclib.cpp @@ -280,8 +280,10 @@ int CIrcProto::NLSend(const unsigned char* buf, int cbBuf) { if (!con || !buf) return 0; - if (m_scriptingEnabled && cbBuf == 0) + + if (cbBuf == 0) cbBuf = (int)mir_strlen((const char *)buf); + return Netlib_Send(con, (const char*)buf, cbBuf, MSG_DUMPASTEXT); } @@ -340,19 +342,6 @@ void CIrcProto::InsertIncomingEvent(wchar_t* pszRaw) Notify(&msg); } -void CIrcProto::createMessageFromPchar(const char* p) -{ - wchar_t *ptszMsg; - if (codepage != CP_UTF8 && m_utfAutodetect) { - if (mir_utf8decodecp(NEWSTR_ALLOCA(p), codepage, &ptszMsg) == nullptr) - ptszMsg = mir_a2u_cp(p, codepage); - } - else ptszMsg = mir_a2u_cp(p, codepage); - CIrcMessage msg(this, ptszMsg, codepage, true); - Notify(&msg); - mir_free(ptszMsg); -} - void CIrcProto::DoReceive() { char chBuf[1024 * 4 + 1]; @@ -399,24 +388,14 @@ void CIrcProto::DoReceive() // process single message by monitor objects if (*pStart) { - if (m_scriptingEnabled) { - char* pszTemp = mir_strdup(pStart); - - if (pszTemp) { - char* p1 = pszTemp; - // replace end-of-line with NULLs - while (*p1 != 0) { - if (*p1 == '\r' || *p1 == '\n') - *p1 = 0; - p1++; - } - - createMessageFromPchar(pszTemp); - } - - mir_free(pszTemp); - } - else createMessageFromPchar(pStart); + ptrW ptszMsg; + if (codepage != CP_UTF8 && m_utfAutodetect && Utf8CheckString(pStart)) + ptszMsg = mir_utf8decodeW(pStart); + else + ptszMsg = mir_a2u_cp(pStart, codepage); + + CIrcMessage msg(this, ptszMsg, codepage, true); + Notify(&msg); } cbInBuf -= pEnd - pStart; diff --git a/protocols/IRCG/src/ircproto.cpp b/protocols/IRCG/src/ircproto.cpp index 6607277681..c6a4e86737 100644 --- a/protocols/IRCG/src/ircproto.cpp +++ b/protocols/IRCG/src/ircproto.cpp @@ -55,11 +55,6 @@ CIrcProto::CIrcProto(const char* szModuleName, const wchar_t* tszUserName) : CreateProtoService(IRC_UM_IGNORE, &CIrcProto::OnMenuIgnore); CreateProtoService("/DblClickEvent", &CIrcProto::OnDoubleclicked); - CreateProtoService("/InsertRawIn", &CIrcProto::Scripting_InsertRawIn); - CreateProtoService("/InsertRawOut", &CIrcProto::Scripting_InsertRawOut); - CreateProtoService("/InsertGuiIn", &CIrcProto::Scripting_InsertGuiIn); - CreateProtoService("/InsertGuiOut", &CIrcProto::Scripting_InsertGuiOut); - CreateProtoService("/GetIrcData", &CIrcProto::Scripting_GetIrcData); HookProtoEvent(ME_DB_CONTACT_SETTINGCHANGED, &CIrcProto::OnDbSettingChanged); HookProtoEvent(ME_OPT_INITIALISE, &CIrcProto::OnInitOptionsPages); diff --git a/protocols/IRCG/src/ircproto.h b/protocols/IRCG/src/ircproto.h index 6f1a5d1ff1..1cd646d368 100644 --- a/protocols/IRCG/src/ircproto.h +++ b/protocols/IRCG/src/ircproto.h @@ -123,7 +123,6 @@ struct CIrcProto : public PROTO int m_quickComboSelection; int m_onlineNotificationTime; int m_onlineNotificationLimit; - BYTE m_scriptingEnabled; BYTE m_IPFromServer; BYTE m_showAddresses; BYTE m_disconnectDCCChats; @@ -255,13 +254,6 @@ struct CIrcProto : public PROTO // output BOOL ShowMessage(const CIrcMessage *pmsg); - // scripting.cpp - INT_PTR __cdecl Scripting_InsertRawIn(WPARAM wParam, LPARAM lParam); - INT_PTR __cdecl Scripting_InsertRawOut(WPARAM wParam, LPARAM lParam); - INT_PTR __cdecl Scripting_InsertGuiIn(WPARAM wParam, LPARAM lParam); - INT_PTR __cdecl Scripting_InsertGuiOut(WPARAM wParam, LPARAM lParam); - INT_PTR __cdecl Scripting_GetIrcData(WPARAM wparam, LPARAM lparam); - // services.cpp void ConnectToServer(void); void DisconnectFromServer(void); @@ -336,7 +328,6 @@ protected: private: mir_cs m_dcc; // protect the dcc objects - void createMessageFromPchar(const char* p); void Notify(const CIrcMessage *pmsg); void __cdecl ThreadProc(void *pparam); diff --git a/protocols/IRCG/src/options.cpp b/protocols/IRCG/src/options.cpp index f8bb7c8dab..aa5dc2c6cd 100644 --- a/protocols/IRCG/src/options.cpp +++ b/protocols/IRCG/src/options.cpp @@ -583,7 +583,6 @@ static TDbSetting OtherSettings[] = { FIELD_OFFSET(CIrcProto, m_codepage), "Codepage", DBVT_DWORD, 0, CP_ACP }, { FIELD_OFFSET(CIrcProto, m_utfAutodetect), "UtfAutodetect", DBVT_BYTE }, { FIELD_OFFSET(CIrcProto, m_perform), "Perform", DBVT_BYTE }, - { FIELD_OFFSET(CIrcProto, m_scriptingEnabled), "ScriptingEnabled", DBVT_BYTE } }; static char* sttPerformEvents[] = { @@ -628,7 +627,7 @@ class COtherPrefsDlg : public CIrcBaseDlg CCtrlMButton m_add, m_delete; CCtrlCombo m_performCombo, m_codepage; CCtrlEdit m_pertormEdit, m_quitMessage, m_alias; - CCtrlCheck m_perform, m_scripting, m_autodetect; + CCtrlCheck m_perform, m_autodetect; public: COtherPrefsDlg(CIrcProto *_pro) : @@ -638,7 +637,6 @@ public: m_codepage(this, IDC_CODEPAGE), m_pertormEdit(this, IDC_PERFORMEDIT), m_perform(this, IDC_PERFORM), - m_scripting(this, IDC_SCRIPT), m_autodetect(this, IDC_UTF_AUTODETECT), m_quitMessage(this, IDC_QUITMESSAGE), m_alias(this, IDC_ALIASEDIT), @@ -663,7 +661,6 @@ public: m_alias.SetText(m_proto->m_alias); m_quitMessage.SetText(m_proto->m_quitMessage); m_perform.SetState(m_proto->m_perform); - m_scripting.SetState(m_proto->m_scriptingEnabled); m_performCombo.Enable(m_proto->m_perform); m_pertormEdit.Enable(m_proto->m_perform); m_add.Enable(m_proto->m_perform); @@ -710,7 +707,6 @@ public: m_proto->m_utfAutodetect = m_autodetect.GetState(); m_proto->m_perform = m_perform.GetState(); - m_proto->m_scriptingEnabled = m_scripting.GetState(); if (m_add.Enabled()) OnAdd(nullptr); diff --git a/protocols/IRCG/src/resource.h b/protocols/IRCG/src/resource.h index a57abd37e5..cc7a8a0371 100644 --- a/protocols/IRCG/src/resource.h +++ b/protocols/IRCG/src/resource.h @@ -135,7 +135,6 @@ #define IDC_COMBO 1196 #define IDC_DISC 1197 #define IDC_FROMSERVER 1201 -#define IDC_SCRIPT 1202 #define IDC_MASK 1204 #define IDC_Q 1205 #define IDC_M 1206 diff --git a/protocols/IRCG/src/scripting.cpp b/protocols/IRCG/src/scripting.cpp deleted file mode 100644 index 8d15cc6da4..0000000000 --- a/protocols/IRCG/src/scripting.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/* -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); - 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; - - mir_forkThread(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 == "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()) { - GC_INFO gci = { 0 }; - gci.Flags = GCF_BYID | GCF_COUNT; - gci.pszModule = m_szModuleName; - gci.pszID = sChannel.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()) { - GC_INFO gci = { 0 }; - gci.Flags = GCF_BYID | GCF_USERS; - gci.pszModule = m_szModuleName; - gci.pszID = sChannel.c_str(); - if (!Chat_GetInfo(&gci)) - return (INT_PTR)mir_strdup(gci.pszUsers); - } - else if (sRequest == "channellist") { - CMStringW S = L""; - int n = g_chatApi.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; -} diff --git a/protocols/IRCG/src/version.h b/protocols/IRCG/src/version.h index 0e67ee5bb7..9d4eeed3ac 100644 --- a/protocols/IRCG/src/version.h +++ b/protocols/IRCG/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 96 #define __RELEASE_NUM 1 -#define __BUILD_NUM 1 +#define __BUILD_NUM 2 #include -- cgit v1.2.3