diff --git a/modules/modtcl.cpp b/modules/modtcl.cpp index 6d5179fc..6ce8cf13 100644 --- a/modules/modtcl.cpp +++ b/modules/modtcl.cpp @@ -1,18 +1,17 @@ /* - * Copyright (C) 2004-2012 See the AUTHORS file for details. + * Copyright (C) 2004-2011 See the AUTHORS file for details. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation. */ -#include -#include -#include -#include -#include -#include -#include +#include "Chan.h" +#include "IRCSock.h" +#include "Modules.h" +#include "Server.h" +#include "User.h" +#include "znc.h" #include @@ -85,11 +84,13 @@ 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); @@ -101,6 +102,7 @@ public: Tcl_CreateCommand(interp, "GetServer", tcl_GetServer, this, NULL); Tcl_CreateCommand(interp, "GetServerOnline", tcl_GetServerOnline, this, NULL); Tcl_CreateCommand(interp, "GetModules", tcl_GetModules, this, NULL); + Tcl_CreateCommand(interp, "GetClientCount", tcl_GetClientCount, this, NULL); Tcl_CreateCommand(interp, "exit", tcl_exit, this, NULL); @@ -250,9 +252,15 @@ 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(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(cd); - Tcl_SetResult(irp, (char *)mod->m_pNetwork->GetCurNick().c_str(), TCL_VOLATILE); + Tcl_SetResult(irp, (char *)mod->m_pUser->GetCurNick().c_str(), TCL_VOLATILE); return TCL_OK; } @@ -281,7 +289,7 @@ private: BADARGS(1, 1, ""); - const vector& Channels = mod->m_pNetwork->GetChans(); + const vector& Channels = mod->m_pUser->GetChans(); for (unsigned int c = 0; c < Channels.size(); c++) { CChan* pChan = Channels[c]; l[0] = pChan->GetName().c_str(); @@ -301,7 +309,7 @@ private: BADARGS(2, 999, " channel"); CString sChannel = argvit(argv, argc, 1, " "); - CChan *pChannel = mod->m_pNetwork->FindChan(sChannel); + CChan *pChannel = mod->m_pUser->FindChan(sChannel); if (!pChannel) { CString sMsg = "invalid channel: " + sChannel; @@ -330,7 +338,7 @@ private: BADARGS(2, 999, " channel"); CString sChannel = argvit(argv, argc, 1, " "); - CChan *pChannel = mod->m_pNetwork->FindChan(sChannel); + CChan *pChannel = mod->m_pUser->FindChan(sChannel); CString sMsg; if (!pChannel) { @@ -346,7 +354,7 @@ private: static int tcl_GetServer STDVAR { CModTcl *mod = static_cast(cd); - CServer* pServer = mod->m_pNetwork->GetCurrentServer(); + CServer* pServer = mod->m_pUser->GetCurrentServer(); CString sMsg; if (pServer) sMsg = pServer->GetName() + ":" + CString(pServer->GetPort()); @@ -356,7 +364,7 @@ private: static int tcl_GetServerOnline STDVAR { CModTcl *mod = static_cast(cd); - CIRCSock* pIRCSock = mod->m_pNetwork->GetIRCSock(); + CIRCSock* pIRCSock = mod->m_pUser->GetIRCSock(); CString sMsg = "0"; if (pIRCSock) sMsg = CString(pIRCSock->GetStartTime()); @@ -394,13 +402,36 @@ private: return TCL_OK; } + static int tcl_GetClientCount STDVAR { + CModTcl *mod = static_cast(cd); + Tcl_SetResult(irp, (char *)CString(mod->m_pUser->GetClients().size()).c_str(), TCL_VOLATILE); + return TCL_OK; + } + static int tcl_PutIRC STDVAR { CString sMsg; CModTcl *mod = static_cast(cd); BADARGS(2, 999, " string"); sMsg = argvit(argv, argc, 1, " "); - mod->m_pNetwork->PutIRC(sMsg); + 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); return TCL_OK; } @@ -486,8 +517,6 @@ void CModTclStartTimer::RunJob() { template<> void TModInfo(CModInfo& Info) { Info.SetWikiPage("modtcl"); - Info.SetHasArgs(true); - Info.SetArgsHelpText("The argument is the number of seconds to wait before rejoining."); } -NETWORKMODULEDEFS(CModTcl, "Loads Tcl scripts as ZNC modules") +MODULEDEFS(CModTcl, "Loads Tcl scripts as ZNC modules")