Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added [GetClientCount].

  • Loading branch information...
commit f377197a47349342b3faaf46ae77d7868b30b5f9 1 parent f65cc27
@blackwind blackwind authored
Showing with 47 additions and 18 deletions.
  1. +47 −18 modules/modtcl.cpp
View
65 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 <znc/Chan.h>
-#include <znc/IRCSock.h>
-#include <znc/Modules.h>
-#include <znc/Server.h>
-#include <znc/User.h>
-#include <znc/IRCNetwork.h>
-#include <znc/znc.h>
+#include "Chan.h"
+#include "IRCSock.h"
+#include "Modules.h"
+#include "Server.h"
+#include "User.h"
+#include "znc.h"
#include <tcl.h>
@@ -85,11 +84,13 @@ class CModTcl : public CModule {
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 @@ class CModTcl : public CModule {
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 @@ class CModTcl : public CModule {
// 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_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 @@ class CModTcl : public CModule {
BADARGS(1, 1, "");
- const vector<CChan*>& Channels = mod->m_pNetwork->GetChans();
+ const vector<CChan*>& 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 @@ class CModTcl : public CModule {
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 @@ class CModTcl : public CModule {
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 @@ class CModTcl : public CModule {
static int tcl_GetServer STDVAR {
CModTcl *mod = static_cast<CModTcl *>(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 @@ class CModTcl : public CModule {
static int tcl_GetServerOnline STDVAR {
CModTcl *mod = static_cast<CModTcl *>(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 @@ class CModTcl : public CModule {
return TCL_OK;
}
+ static int tcl_GetClientCount STDVAR {
+ CModTcl *mod = static_cast<CModTcl *>(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<CModTcl *>(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<CModTcl>(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")
Please sign in to comment.
Something went wrong with that request. Please try again.