mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
Turn modtcl into a network module
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include "Modules.h"
|
||||
#include "Server.h"
|
||||
#include "User.h"
|
||||
#include "IRCNetwork.h"
|
||||
#include "znc.h"
|
||||
|
||||
#include <tcl.h>
|
||||
@@ -83,13 +84,11 @@ public:
|
||||
Tcl_CreateCommand(interp, "Binds::ProcessNick", tcl_Bind, this, NULL);
|
||||
Tcl_CreateCommand(interp, "Binds::ProcessKick", tcl_Bind, this, NULL);
|
||||
Tcl_CreateCommand(interp, "PutIRC", tcl_PutIRC, this, NULL);
|
||||
Tcl_CreateCommand(interp, "PutIRCAs", tcl_PutIRCAs, this, NULL);
|
||||
Tcl_CreateCommand(interp, "PutModule", tcl_PutModule, this, NULL);
|
||||
Tcl_CreateCommand(interp, "PutStatus", tcl_PutStatus, this, NULL);
|
||||
Tcl_CreateCommand(interp, "PutStatusNotice", tcl_PutStatusNotice, this, NULL);
|
||||
Tcl_CreateCommand(interp, "PutUser", tcl_PutUser, this, NULL);
|
||||
|
||||
Tcl_CreateCommand(interp, "GetLocalIP", tcl_GetLocalIP, this, NULL);
|
||||
Tcl_CreateCommand(interp, "GetCurNick", tcl_GetCurNick, this, NULL);
|
||||
Tcl_CreateCommand(interp, "GetUsername", tcl_GetUsername, this, NULL);
|
||||
Tcl_CreateCommand(interp, "GetRealName", tcl_GetRealName, this, NULL);
|
||||
@@ -237,15 +236,9 @@ private:
|
||||
// Placeholder for binds incase binds.tcl isn't used
|
||||
static int tcl_Bind STDVAR {return TCL_OK;}
|
||||
|
||||
static int tcl_GetLocalIP STDVAR {
|
||||
CModTcl *mod = static_cast<CModTcl *>(cd);
|
||||
Tcl_SetResult(irp, (char *)mod->m_pUser->GetLocalIP().c_str(), TCL_VOLATILE);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
static int tcl_GetCurNick STDVAR {
|
||||
CModTcl *mod = static_cast<CModTcl *>(cd);
|
||||
Tcl_SetResult(irp, (char *)mod->m_pUser->GetCurNick().c_str(), TCL_VOLATILE);
|
||||
Tcl_SetResult(irp, (char *)mod->m_pNetwork->GetCurNick().c_str(), TCL_VOLATILE);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
@@ -274,7 +267,7 @@ private:
|
||||
|
||||
BADARGS(1, 1, "");
|
||||
|
||||
const vector<CChan*>& Channels = mod->m_pUser->GetChans();
|
||||
const vector<CChan*>& Channels = mod->m_pNetwork->GetChans();
|
||||
for (unsigned int c = 0; c < Channels.size(); c++) {
|
||||
CChan* pChan = Channels[c];
|
||||
l[0] = pChan->GetName().c_str();
|
||||
@@ -294,7 +287,7 @@ private:
|
||||
BADARGS(2, 999, " channel");
|
||||
|
||||
CString sChannel = argvit(argv, argc, 1, " ");
|
||||
CChan *pChannel = mod->m_pUser->FindChan(sChannel);
|
||||
CChan *pChannel = mod->m_pNetwork->FindChan(sChannel);
|
||||
|
||||
if (!pChannel) {
|
||||
CString sMsg = "invalid channel: " + sChannel;
|
||||
@@ -323,7 +316,7 @@ private:
|
||||
BADARGS(2, 999, " channel");
|
||||
|
||||
CString sChannel = argvit(argv, argc, 1, " ");
|
||||
CChan *pChannel = mod->m_pUser->FindChan(sChannel);
|
||||
CChan *pChannel = mod->m_pNetwork->FindChan(sChannel);
|
||||
CString sMsg;
|
||||
|
||||
if (!pChannel) {
|
||||
@@ -339,7 +332,7 @@ private:
|
||||
|
||||
static int tcl_GetServer STDVAR {
|
||||
CModTcl *mod = static_cast<CModTcl *>(cd);
|
||||
CServer* pServer = mod->m_pUser->GetCurrentServer();
|
||||
CServer* pServer = mod->m_pNetwork->GetCurrentServer();
|
||||
CString sMsg;
|
||||
if (pServer)
|
||||
sMsg = pServer->GetName() + ":" + CString(pServer->GetPort());
|
||||
@@ -349,7 +342,7 @@ private:
|
||||
|
||||
static int tcl_GetServerOnline STDVAR {
|
||||
CModTcl *mod = static_cast<CModTcl *>(cd);
|
||||
CIRCSock* pIRCSock = mod->m_pUser->GetIRCSock();
|
||||
CIRCSock* pIRCSock = mod->m_pNetwork->GetIRCSock();
|
||||
CString sMsg = "0";
|
||||
if (pIRCSock)
|
||||
sMsg = CString(pIRCSock->GetStartTime());
|
||||
@@ -393,24 +386,7 @@ private:
|
||||
|
||||
BADARGS(2, 999, " string");
|
||||
sMsg = argvit(argv, argc, 1, " ");
|
||||
mod->m_pUser->PutIRC(sMsg);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
static int tcl_PutIRCAs STDVAR {
|
||||
CString sMsg;
|
||||
|
||||
BADARGS(3, 999, " user string");
|
||||
|
||||
CUser *pUser = CZNC::Get().FindUser(argv[1]);
|
||||
if (!pUser) {
|
||||
sMsg = "invalid user " + CString(argv[1]);
|
||||
Tcl_SetResult(irp, (char*)sMsg.c_str(), TCL_VOLATILE);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
sMsg = argvit(argv, argc, 2, " ");
|
||||
pUser->PutIRC(sMsg);
|
||||
mod->m_pNetwork->PutIRC(sMsg);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
@@ -498,4 +474,4 @@ template<> void TModInfo<CModTcl>(CModInfo& Info) {
|
||||
Info.SetWikiPage("modtcl");
|
||||
}
|
||||
|
||||
MODULEDEFS(CModTcl, "Loads Tcl scripts as ZNC modules")
|
||||
NETWORKMODULEDEFS(CModTcl, "Loads Tcl scripts as ZNC modules")
|
||||
|
||||
Reference in New Issue
Block a user