From 95c304daf9414edbc918d24de2e1c9715d4fae22 Mon Sep 17 00:00:00 2001 From: Aleksandr Zenkov Date: Sun, 14 Mar 2021 15:45:19 +0100 Subject: [PATCH] Change KickUser Lua API to allow hiding kick messages --- CMakeLists.txt | 10 +- TODO | 16 +-- plugins/lua/callbacks.cpp | 9 +- plugins/perl/README | 2 +- src/casyncconn.cpp | 91 +++++++++++-- src/casyncconn.h | 13 ++ src/casyncsocketserver.cpp | 55 +++++++- src/casyncsocketserver.h | 15 ++- src/cconndc.cpp | 2 +- src/cconndc.h | 9 +- src/cdcconsole.cpp | 4 +- src/cdcproto.cpp | 38 +++--- src/cserverdc.cpp | 26 ++-- src/cserverdc.h | 7 +- src/ctime.cpp | 270 ++++++++++++++++++------------------- src/ctime.h | 242 ++++++++++++++++----------------- src/script_api.cpp | 8 +- src/script_api.h | 2 +- 18 files changed, 499 insertions(+), 320 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 383e3ae1..bb45d05e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,8 @@ message(STATUS) message(STATUS "You can change build options with: -D{OPTION}=ON|OFF") message(STATUS "You can turn on debug build with: -DDEFINE_DEBUG=ON") message(STATUS "You can disable all plugins with: -DWITH_PLUGINS=OFF") +message(STATUS "You can turn on buffer reservation with: -DUSE_BUFFER_RESERVE=ON") +#message(STATUS "You can disable SSL secured connects with: -DUSE_SSL_CONNECTS=OFF") message(STATUS "You can also disable specific plugins with: -DWITH_{NAME}=OFF") message(STATUS "Plugin names: LUA PYTHON PERL FORBID CHATROOM IPLOG ISP MESSENGER STATS REPLACER FLOODPROT") message(STATUS "If you get errors related to autosprintf, please try with: -DUSE_CUSTOM_AUTOSPRINTF=ON") @@ -31,7 +33,7 @@ message(STATUS) SET(VERLIHUB_VERSION_MAJOR 1) SET(VERLIHUB_VERSION_MINOR 3) SET(VERLIHUB_VERSION_PATCH 0) -SET(VERLIHUB_VERSION_TWEAK 1) +SET(VERLIHUB_VERSION_TWEAK 2) SET(VERLIHUB_VERSION "${VERLIHUB_VERSION_MAJOR}.${VERLIHUB_VERSION_MINOR}.${VERLIHUB_VERSION_PATCH}.${VERLIHUB_VERSION_TWEAK}") #SET(VERLIHUB_SOVERSION "${VERLIHUB_VERSION_MAJOR}.${VERLIHUB_VERSION_MINOR}.${VERLIHUB_VERSION_PATCH}") SET(PROJECT_NAME "verlihub") @@ -187,7 +189,7 @@ IF(NOT HAVE_GETOPT_H) ENDIF(NOT HAVE_GETOPT_H) ADD_DEFINITIONS(-DUSE_BUFFER_RESERVE) -OPTION(USE_BUFFER_RESERVE "Use buffer string reservation?" OFF) # use cmake -DUSE_BUFFER_RESERVE=ON to use buffer string reservation +OPTION(USE_BUFFER_RESERVE "Use buffer string reservation" OFF) # use cmake -DUSE_BUFFER_RESERVE=ON to use buffer string reservation OPTION(DEFINE_DEBUG "Build the project using debugging code" OFF) # use cmake -DDEFINE_DEBUG=ON to enable debug @@ -198,6 +200,10 @@ ELSE(DEFINE_DEBUG) SET(CMAKE_BUILD_TYPE Release) ENDIF(DEFINE_DEBUG) + +#ADD_DEFINITIONS(-DUSE_SSL_CONNECTS) +#OPTION(USE_SSL_CONNECTS "Use SSL secured connects" ON) # use cmake -DUSE_SSL_CONNECTS=OFF to disable ssl + MESSAGE(STATUS "[ OK ] Build type: ${CMAKE_BUILD_TYPE}") ADD_DEFINITIONS(-DHAVE_CONFIG_H) diff --git a/TODO b/TODO index f1ce9332..e46673dc 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,8 @@ -[*] Confirmed: - - On start resolve hublist.te-home.net domain and update auth_ip field for registered user TEPinger - -[*] Unconfirmed: - - Fix creguserinfo.cpp for HAVE_LIBSSL and crypto stuff - ? +[*] Confirmed: + + On start resolve hublist.te-home.net domain and update auth_ip field for registered user TEPinger + +[*] Unconfirmed: + + Fix creguserinfo.cpp for HAVE_LIBSSL and crypto stuff + ? diff --git a/plugins/lua/callbacks.cpp b/plugins/lua/callbacks.cpp index a7716d61..81e1b128 100644 --- a/plugins/lua/callbacks.cpp +++ b/plugins/lua/callbacks.cpp @@ -1891,7 +1891,7 @@ int _KickUser(lua_State *L) return 2; } - if (!lua_isstring(L, 2) || !lua_isstring(L, 3) || !lua_isstring(L, 4) || ((args >= 4) && !lua_isstring(L, 5)) || ((args >= 5) && !lua_isstring(L, 6))) { + if (!lua_isstring(L, 2) || !lua_isstring(L, 3) || !lua_isstring(L, 4) || ((args >= 4) && !lua_isstring(L, 5)) || ((args >= 5) && !lua_isstring(L, 6)) || ((args >= 6) && !lua_isnumber(L, 7))) { luaerror(L, ERR_PARAM); return 2; } @@ -1909,7 +1909,12 @@ int _KickUser(lua_State *L) if (args >= 5) note_usr = lua_tostring(L, 6); - if (!KickUser(oper.c_str(), nick.c_str(), why.c_str(), (note_op.size() ? note_op.c_str() : NULL), (note_usr.size() ? note_usr.c_str() : NULL))) { + int hide = 0; + + if (args >= 6) + hide = lua_tonumber(L, 7); + + if (!KickUser(oper.c_str(), nick.c_str(), why.c_str(), (note_op.size() ? note_op.c_str() : NULL), (note_usr.size() ? note_usr.c_str() : NULL), (hide == 1))) { luaerror(L, ERR_CALL); return 2; } diff --git a/plugins/perl/README b/plugins/perl/README index c6fbfb0b..552ef3d6 100644 --- a/plugins/perl/README +++ b/plugins/perl/README @@ -1 +1 @@ -Verlihub PerlScript plugin +Verlihub PerlScript plugin diff --git a/src/casyncconn.cpp b/src/casyncconn.cpp index 75ddda52..c9de9f0c 100644 --- a/src/casyncconn.cpp +++ b/src/casyncconn.cpp @@ -103,6 +103,11 @@ cAsyncConn::cAsyncConn(int desc, cAsyncSocketServer *s, tConnType ct): // incomi mLineSizeMax(0), mType(ct), mxLine(NULL), +/* +#ifdef USE_SSL_CONNECTS + mSSLConn(NULL), +#endif +*/ meLineStatus(AC_LS_NO_LINE), mBufEnd(0), mBufReadPos(0), @@ -219,6 +224,16 @@ void cAsyncConn::Close() mWritable = false; ok = false; +/* +#ifdef USE_SSL_CONNECTS + if (mSSLConn) { + SSL_shutdown(mSSLConn); + SSL_free(mSSLConn); + mSSLConn = NULL; + } +#endif +*/ + if (mxServer) mxServer->OnConnClose(this); @@ -348,11 +363,25 @@ int cAsyncConn::ReadAll(const unsigned int tries, const unsigned int sleep) //bool udp = (this->GetType() == eCT_CLIENTUDP); //if (!udp) { - while (((buf_len = recv(mSockDesc, msBuffer.data(), MAX_MESS_SIZE, 0)) == -1) && ((errno == EAGAIN) || (errno == EINTR)) && (i++ <= tries)) { - //#if !defined _WIN32 - ::usleep(sleep); - //#endif +/* +#ifdef USE_SSL_CONNECTS + if (mSSLConn) { + while (((buf_len = SSL_read(mSSLConn, msBuffer.data(), MAX_MESS_SIZE)) == -1) && ((errno == EAGAIN) || (errno == EINTR)) && (i++ <= tries)) // todo: errno + ::usleep(sleep); + + } else { +#endif +*/ + while (((buf_len = recv(mSockDesc, msBuffer.data(), MAX_MESS_SIZE, 0)) == -1) && ((errno == EAGAIN) || (errno == EINTR)) && (i++ <= tries)) { + //#if !defined _WIN32 + ::usleep(sleep); + //#endif + } +/* +#ifdef USE_SSL_CONNECTS } +#endif +*/ /* } else { while (((buf_len = recvfrom(mSockDesc, msBuffer.data(), MAX_MESS_SIZE, 0, (struct sockaddr*)&mAddrIN, (socklen_t*)&addr_len)) == -1) && (i++ <= tries)) { @@ -369,9 +398,6 @@ int cAsyncConn::ReadAll(const unsigned int tries, const unsigned int sleep) if (Log(2)) // connection hung up LogStream() << "User hung up" << endl; - CloseNow(); - return -1; - } else { if (Log(2)) LogStream() << "Read IO error: " << errno << " = " << strerror(errno) << endl; @@ -395,6 +421,14 @@ int cAsyncConn::ReadAll(const unsigned int tries, const unsigned int sleep) //} } else { // received data + if ((buf_len > 2) && (msBuffer[0] == 0x16) && (msBuffer[1] == 0x03)) { // detect tls connection + if (Log(1)) + LogStream() << "Closing TLS connection" << endl; + + CloseNow(); // todo: eCR_TLS_SESS + return -1; + } + mBufEnd = buf_len; msBuffer[mBufEnd] = '\0'; // end string @@ -420,7 +454,14 @@ int cAsyncConn::SendAll(const char *buf, size_t &len) //try { //if (!udp) { //#if !defined _WIN32 - n = send(mSockDesc, buf + total, bytesleft, MSG_NOSIGNAL | MSG_DONTWAIT); + /* + #ifdef USE_SSL_CONNECTS + if (mSSLConn) + n = SSL_write(mSSLConn, buf + total, bytesleft); + else + #endif + */ + n = send(mSockDesc, buf + total, bytesleft, MSG_NOSIGNAL | MSG_DONTWAIT); /* #else int RetryCount = 0; @@ -462,7 +503,14 @@ int cAsyncConn::SendAll(const char *buf, size_t &len) } #else //if (!udp) - n = send(mSockDesc, buf + total, bytesleft, 0); + /* + #ifdef USE_SSL_CONNECTS + if (mSSLConn) + n = SSL_write(mSSLConn, buf + total, bytesleft); + else + #endif + */ + n = send(mSockDesc, buf + total, bytesleft, 0); /* else n = sendto(mSockDesc, buf + total, bytesleft, 0, (struct sockaddr*)&mAddrIN, sizeof(struct sockaddr)); @@ -739,6 +787,31 @@ tSocket cAsyncConn::AcceptSock(const unsigned int sleep, const unsigned int trie if (Log(3)) LogStream() << "Accepted socket: " << socknum << endl; +/* +#ifdef USE_SSL_CONNECTS + if (mxServer && mxServer->mSSLCont) { + mSSLConn = SSL_new(mxServer->mSSLCont); + + if (mSSLConn) { + SSL_set_fd(mSSLConn, socknum); + + if (SSL_accept(mSSLConn) <= 0) { + if (Log(0)) + LogStream() << "Failed to accept client SSL socket: " << socknum << endl; + + ERR_print_errors_fp(stderr); + SSL_free(mSSLConn); + mSSLConn = NULL; + } + + } else { + if (Log(0)) + LogStream() << "Failed to create client SSL socket: " << socknum << endl; + } + } +#endif +*/ + sSocketCounter++; sockoptval_t yes = 1; diff --git a/src/casyncconn.h b/src/casyncconn.h index a1925050..82ec3010 100644 --- a/src/casyncconn.h +++ b/src/casyncconn.h @@ -36,6 +36,12 @@ #include //#endif +/* +#ifdef USE_SSL_CONNECTS + #include +#endif +*/ + #include #include #include @@ -483,6 +489,13 @@ namespace nVerliHub { return mSockDesc; } + /* + #ifdef USE_SSL_CONNECTS + // ssl connection + SSL *mSSLConn; + #endif + */ + /** * Write the given data into the output buffer. * The content of the buffer may be flushed manually or when the buffer diff --git a/src/casyncsocketserver.cpp b/src/casyncsocketserver.cpp index 2121aad9..cff37177 100644 --- a/src/casyncsocketserver.cpp +++ b/src/casyncsocketserver.cpp @@ -61,6 +61,11 @@ cAsyncSocketServer::cAsyncSocketServer(int port): mbRun(false), mFactory(NULL), mRunResult(0), +/* +#ifdef USE_SSL_CONNECTS + mSSLCont(NULL), +#endif +*/ mNowTreating(NULL) { /* @@ -116,6 +121,45 @@ int cAsyncSocketServer::run() mbRun = true; vhLog(1) << "Main loop start" << endl; +/* +#ifdef USE_SSL_CONNECTS + // https://wiki.openssl.org/index.php/Simple_TLS_Server + SSL_load_error_strings(); + OpenSSL_add_ssl_algorithms(); + const SSL_METHOD *meth = TLS_server_method(); // todo: detect version from ssl.h + mSSLCont = SSL_CTX_new(meth); + + if (mSSLCont) { + SSL_CTX_set_options(mSSLCont, SSL_OP_NO_COMPRESSION); // no compression + SSL_CTX_set_min_proto_version(mSSLCont, TLS1_3_VERSION); // min version 1.3 + SSL_CTX_set_max_proto_version(mSSLCont, TLS1_3_VERSION); // max version 1.3 + SSL_CTX_set_ecdh_auto(mSSLCont, 1); + + if (SSL_CTX_use_certificate_file(mSSLCont, "/home/rolex/.certs/FearDC.crt", SSL_FILETYPE_PEM) <= 0) { // todo: add config + vhLog(0) << ("Failed to apply SSL certificate to server SSL context") << endl; + ERR_print_errors_fp(stderr); + SSL_CTX_free(mSSLCont); + mSSLCont = NULL; + EVP_cleanup(); + + } else { + if (SSL_CTX_use_PrivateKey_file(mSSLCont, "/home/rolex/.certs/FearDC.key", SSL_FILETYPE_PEM) <= 0 ) { // todo: add config + vhLog(0) << ("Failed to apply SSL key to server SSL context") << endl; + ERR_print_errors_fp(stderr); + SSL_CTX_free(mSSLCont); + mSSLCont = NULL; + EVP_cleanup(); + } + } + + } else { + vhLog(0) << ("Failed to create server SSL context") << endl; + ERR_print_errors_fp(stderr); + EVP_cleanup(); + } +#endif +*/ + while (mbRun) { mTime.Get(); // note: always current time, dont modify this container anywhere TimeStep(); @@ -140,7 +184,6 @@ int cAsyncSocketServer::run() } vhLog(1) << "Main loop stop with code " << mRunResult << endl; - return mRunResult; } @@ -170,6 +213,16 @@ void cAsyncSocketServer::close() } } } + +/* +#ifdef USE_SSL_CONNECTS + if (mSSLCont) { + SSL_CTX_free(mSSLCont); + mSSLCont = NULL; + EVP_cleanup(); + } +#endif +*/ } /* diff --git a/src/casyncsocketserver.h b/src/casyncsocketserver.h index 8f0f30cb..c423eb55 100644 --- a/src/casyncsocketserver.h +++ b/src/casyncsocketserver.h @@ -32,10 +32,16 @@ #include "ctimeout.h" #include #include "cobj.h" -//#include "cconndc.h" // added #include "casyncconn.h" #include "cmeanfrequency.h" +/* +#ifdef USE_SSL_CONNECTS + #include + #include +#endif +*/ + using namespace std; namespace nVerliHub { @@ -126,6 +132,13 @@ namespace nVerliHub { */ int OnTimerBase(const cTime &now); + /* + #ifdef USE_SSL_CONNECTS + // ssl context + SSL_CTX* mSSLCont; + #endif + */ + /** * Start the main loop. * This ìs the method that calls OnTimerBase() and TimeStep() diff --git a/src/cconndc.cpp b/src/cconndc.cpp index 52c33075..89630b60 100644 --- a/src/cconndc.cpp +++ b/src/cconndc.cpp @@ -44,7 +44,7 @@ cConnDC::cConnDC(int sd, cAsyncSocketServer *server): //mNickListInProgress = false; //mSkipNickList = false; mConnType = NULL; - mCloseReason = 0; + mCloseReason = eCR_DEFAULT; SetTimeOut(eTO_LOGIN, Server()->mC.timeout_length[eTO_LOGIN], server->mTime); // default login timeout mGeoZone = -1; mRegInfo = NULL; diff --git a/src/cconndc.h b/src/cconndc.h index 436fbbc7..9cc0ed51 100644 --- a/src/cconndc.h +++ b/src/cconndc.h @@ -28,15 +28,19 @@ namespace nVerliHub { using namespace nSocket; using namespace nUtils; using namespace nTables; + namespace nTables { class cConnType; }; + namespace nProtocol { class cDCProto; } + using nProtocol::cDCProto; class cUser; + namespace nSocket { class cServerDC; }; @@ -216,6 +220,7 @@ namespace nVerliHub { class cConnDC : public cAsyncConn { friend class nProtocol::cDCProto; + public: /** * Class constructor. @@ -249,13 +254,13 @@ namespace nVerliHub { * @param msed Time in milliseconds before closing the connection. * @param reason The reason. */ - virtual void CloseNice(int msec, int reason = 0); + virtual void CloseNice(int msec, int reason = 0); // eCR_DEFAULT /** * Close the connection with the given reason. * @param reason The reason. */ - virtual void CloseNow(int reason = 0); + virtual void CloseNow(int reason = 0); // eCR_DEFAULT /** * Return if the given login status flag is set or not. diff --git a/src/cdcconsole.cpp b/src/cdcconsole.cpp index 042a1ab8..3ea23985 100644 --- a/src/cdcconsole.cpp +++ b/src/cdcconsole.cpp @@ -1904,7 +1904,7 @@ bool cDCConsole::cfBan::operator()() mS->DCPublicToAll(mS->mC.hub_security, toall.str(), mS->mC.notify_kicks_to_all, int(eUC_MASTER), mS->mC.delayed_chat); } - conn->CloseNow(); // todo: user dont get any message, only if notify_kicks_to_all is in his range + conn->CloseNow(eCR_KICKED); // todo: user dont get any message, only if notify_kicks_to_all is in his range } } } @@ -1930,7 +1930,7 @@ bool cDCConsole::cfBan::operator()() mS->DCPublicToAll(mS->mC.hub_security, toall.str(), mS->mC.notify_kicks_to_all, int(eUC_MASTER), mS->mC.delayed_chat); } - user->mxConn->CloseNow(); // todo: user dont get any message, only if notify_kicks_to_all is in his range + user->mxConn->CloseNow(eCR_KICKED); // todo: user dont get any message, only if notify_kicks_to_all is in his range } } diff --git a/src/cdcproto.cpp b/src/cdcproto.cpp index 7684f0e9..3ccd1e89 100644 --- a/src/cdcproto.cpp +++ b/src/cdcproto.cpp @@ -113,7 +113,7 @@ int cDCProto::TreatMsg(cMessageParser *pMsg, cAsyncConn *pConn) mS->ReportUserToOpchat(conn, os.str()); } - conn->CloseNow(); + conn->CloseNow(eCR_SYNTAX); return -1; } @@ -131,7 +131,7 @@ int cDCProto::TreatMsg(cMessageParser *pMsg, cAsyncConn *pConn) return 1; } else { if (!mS->mCallBacks.mOnParsedMsgAnyEx.CallAll(conn, msg)) { - conn->CloseNow(); + conn->CloseNow(eCR_PLUGIN); return -1; } } @@ -727,13 +727,13 @@ int cDCProto::DC_ValidateNick(cMessageDC *msg, cConnDC *conn) cUser *NewUser = new cUser(nick); if (!conn->SetUser(NewUser)) { - conn->CloseNow(); + conn->CloseNow(eCR_INVALID_USER); return -1; } #ifndef WITHOUT_PLUGINS if (!mS->mCallBacks.mOnParsedMsgValidateNick.CallAll(conn, msg)) { - conn->CloseNow(); + conn->CloseNow(eCR_PLUGIN); return -2; } #endif @@ -787,7 +787,7 @@ int cDCProto::DC_MyPass(cMessageDC *msg, cConnDC *conn) #ifndef WITHOUT_PLUGINS if (!mS->mCallBacks.mOnParsedMsgMyPass.CallAll(conn, msg)) { - conn->CloseNow(); + conn->CloseNow(eCR_PLUGIN); return -1; } #endif @@ -936,7 +936,7 @@ int cDCProto::DC_MyHubURL(cMessageDC *msg, cConnDC *conn) #ifndef WITHOUT_PLUGINS if (!mS->mCallBacks.mOnParsedMsgMyHubURL.CallAll(conn, msg)) { - conn->CloseNow(); + conn->CloseNow(eCR_PLUGIN); return -1; } #endif @@ -970,7 +970,7 @@ int cDCProto::DC_Version(cMessageDC *msg, cConnDC *conn) #ifndef WITHOUT_PLUGINS if (!mS->mCallBacks.mOnParsedMsgVersion.CallAll(conn, msg)) { - conn->CloseNow(); + conn->CloseNow(eCR_PLUGIN); return -1; } #endif @@ -3088,7 +3088,7 @@ int cDCProto::DCB_BotINFO(cMessageDC *msg, cConnDC *conn) #ifndef WITHOUT_PLUGINS if (!mS->mCallBacks.mOnParsedMsgBotINFO.CallAll(conn, msg)) { - conn->CloseNow(); + conn->CloseNow(eCR_PLUGIN); return -1; } #endif @@ -3475,12 +3475,12 @@ int cDCProto::DCC_MyIP(cMessageDC *msg, cConnDC *conn) return this->DCU_Unknown(msg, conn); if ((msg->mLen < 17) || (msg->mLen > 25)) { - conn->CloseNow(); + conn->CloseNow(eCR_SYNTAX); return -1; } if (msg->SplitChunks()) { - conn->CloseNow(); + conn->CloseNow(eCR_SYNTAX); return -1; } @@ -3488,7 +3488,7 @@ int cDCProto::DCC_MyIP(cMessageDC *msg, cConnDC *conn) string &vers = msg->ChunkString(eCH_MYIP_VERS); if (!conn->SetSecConn(addr, vers)) { - conn->CloseNow(); + conn->CloseNow(eCR_SYNTAX); return -1; } @@ -3506,24 +3506,24 @@ int cDCProto::DCC_MyNick(cMessageDC *msg, cConnDC *conn) return this->DCU_Unknown(msg, conn); if (conn->mMyNick.size()) { - conn->CloseNow(); + conn->CloseNow(eCR_LOGIN_ERR); return -1; } if (msg->mLen > mS->mC.max_len_mynick) { - conn->CloseNow(); + conn->CloseNow(eCR_SYNTAX); return -1; } if (msg->SplitChunks()) { - conn->CloseNow(); + conn->CloseNow(eCR_SYNTAX); return -1; } const string &nick = msg->ChunkString(eCH_1_PARAM); if (nick.empty()) { - conn->CloseNow(); + conn->CloseNow(eCR_SYNTAX); return -1; } @@ -3537,24 +3537,24 @@ int cDCProto::DCC_Lock(cMessageDC *msg, cConnDC *conn) return this->DCU_Unknown(msg, conn); if (conn->mMyNick.empty()) { - conn->CloseNow(); + conn->CloseNow(eCR_LOGIN_ERR); return -1; } if (msg->mLen > mS->mC.max_len_lock) { - conn->CloseNow(); + conn->CloseNow(eCR_SYNTAX); return -1; } if (msg->SplitChunks()) { - conn->CloseNow(); + conn->CloseNow(eCR_SYNTAX); return -1; } const string &lock = msg->ChunkString(eCH_1_PARAM); if (lock.empty()) { - conn->CloseNow(); + conn->CloseNow(eCR_SYNTAX); return -1; } diff --git a/src/cserverdc.cpp b/src/cserverdc.cpp index 8ed11b29..b2ce1800 100644 --- a/src/cserverdc.cpp +++ b/src/cserverdc.cpp @@ -1200,7 +1200,7 @@ bool cServerDC::VerifyUniqueNick(cConnDC *conn) RemoveNick(olduser); } else { - conn->CloseNow(); + conn->CloseNow(eCR_SELF); return false; } @@ -1350,7 +1350,7 @@ void cServerDC::AfterUserLogin(cConnDC *conn) #ifndef WITHOUT_PLUGINS if (!mCallBacks.mOnUserLogin.CallAll(conn->mpUser)) { - conn->CloseNow(); + conn->CloseNow(eCR_PLUGIN); return; } #endif @@ -1362,7 +1362,7 @@ void cServerDC::DoUserLogin(cConnDC *conn) if (conn->ErrLog(2)) conn->LogStream() << "User login when not all done" << endl; - conn->CloseNow(); + conn->CloseNow(eCR_LOGIN_ERR); return; } @@ -1375,13 +1375,13 @@ void cServerDC::DoUserLogin(cConnDC *conn) conn->mpUser->ApplyRights(pen); if (!AddToList(conn->mpUser)) { // insert user to userlist - conn->CloseNow(); + conn->CloseNow(eCR_INVALID_USER); return; } #ifndef WITHOUT_PLUGINS if (!mCallBacks.mOnUserInList.CallAll(conn->mpUser)) { - conn->CloseNow(); + conn->CloseNow(eCR_PLUGIN); return; } #endif @@ -1413,7 +1413,7 @@ void cServerDC::DoUserLogin(cConnDC *conn) bool cServerDC::BeginUserLogin(cConnDC *conn) { if (conn->GetLSFlag(eLS_LOGIN_DONE) != eLS_LOGIN_DONE) { - conn->CloseNow(); + conn->CloseNow(eCR_LOGIN_ERR); return false; } @@ -2777,7 +2777,7 @@ void cServerDC::SendHeaders(cConnDC *conn, unsigned int where) } } -void cServerDC::DCKickNick(ostream *use_os, cUser *op, const string &nick, const string &why, int flags, const string ¬e_op, const string ¬e_usr) +void cServerDC::DCKickNick(ostream *use_os, cUser *op, const string &nick, const string &why, int flags, const string ¬e_op, const string ¬e_usr, bool hide) { if (!op || nick.empty() || (op->mNick == nick)) // todo: possible to use user pointer instead of nick string here? then we can use mNickHash return; @@ -2787,10 +2787,13 @@ void cServerDC::DCKickNick(ostream *use_os, cUser *op, const string &nick, const if (!user || !user->mxConn) { ostr << autosprintf(_("User not found: %s"), nick.c_str()); + } else if (((user->mClass + int(mC.classdif_kick)) > op->mClass) || !op->Can(eUR_KICK, mTime.Sec())) { ostr << autosprintf(_("You have no rights to kick user: %s"), nick.c_str()); + } else if (user->mProtectFrom >= op->mClass) { ostr << autosprintf(_("User is protected from your kicks: %s"), nick.c_str()); + } else { string new_why(why); bool keep = true; @@ -2799,6 +2802,7 @@ void cServerDC::DCKickNick(ostream *use_os, cUser *op, const string &nick, const #ifndef WITHOUT_PLUGINS keep = mCallBacks.mOnOperatorKicks.CallAll(op, user, &new_why); #endif + } else if (flags & eKI_DROP) { #ifndef WITHOUT_PLUGINS keep = mCallBacks.mOnOperatorDrops.CallAll(op, user, &new_why); @@ -2873,15 +2877,18 @@ void cServerDC::DCKickNick(ostream *use_os, cUser *op, const string &nick, const if (mC.notify_kicks_to_all == -1) { ostr << autosprintf(_("User was kicked and banned for %s: %s"), age.AsPeriod().AsString().c_str(), nick.c_str()); + } else { // message to all if (new_why.size()) toall << autosprintf(_("%s was kicked and banned for %s by %s with reason: %s"), nick.c_str(), age.AsPeriod().AsString().c_str(), op->mNick.c_str(), new_why.c_str()); else toall << autosprintf(_("%s was kicked and banned for %s by %s without reason."), nick.c_str(), age.AsPeriod().AsString().c_str(), op->mNick.c_str()); } + } else { if (mC.notify_kicks_to_all == -1) { ostr << autosprintf(_("User was kicked and banned permanently: %s"), nick.c_str()); + } else { // message to all if (new_why.size()) toall << autosprintf(_("%s was kicked and banned permanently by %s with reason: %s"), nick.c_str(), op->mNick.c_str(), new_why.c_str()); @@ -2891,6 +2898,7 @@ void cServerDC::DCKickNick(ostream *use_os, cUser *op, const string &nick, const } mBanList->AddBan(ban); + } else if (flags & eKI_DROP) { if (user->mxConn->Log(2)) user->mxConn->LogStream() << "Dropped by " << op->mNick << " because: " << new_why << endl; @@ -2902,6 +2910,7 @@ void cServerDC::DCKickNick(ostream *use_os, cUser *op, const string &nick, const os << autosprintf(_("%s dropped user without reason"), op->mNick.c_str()); ReportUserToOpchat(user->mxConn, os.str(), mC.dest_drop_chat); + } else { // message to all if (new_why.size()) toall << autosprintf(_("%s was dropped by %s with reason: %s"), nick.c_str(), op->mNick.c_str(), new_why.c_str()); @@ -2920,6 +2929,7 @@ void cServerDC::DCKickNick(ostream *use_os, cUser *op, const string &nick, const if (flags & eKI_CLOSE) user->mxConn->CloseNice(1000, eCR_KICKED); + } else { ostr << _("Your action was blocked by a plugin."); } @@ -2932,7 +2942,7 @@ void cServerDC::DCKickNick(ostream *use_os, cUser *op, const string &nick, const DCPublicHS(ostr.str(), op->mxConn); } - if ((mC.notify_kicks_to_all > -1) && toall.str().size()) // message to all + if (!hide && (mC.notify_kicks_to_all > -1) && toall.str().size()) // message to all DCPublicToAll(mC.hub_security, toall.str(), mC.notify_kicks_to_all, int(eUC_MASTER), mC.delayed_chat); } diff --git a/src/cserverdc.h b/src/cserverdc.h index b6395005..079b5db0 100644 --- a/src/cserverdc.h +++ b/src/cserverdc.h @@ -122,7 +122,7 @@ namespace nVerliHub { enum { - eCR_DEFAULT = 0, // default value, means not closed or unknown reason + eCR_DEFAULT = 0, // default value, means not closed or unknown reason eCR_INVALID_USER, // bad nick, banned nick, ip or whatever eCR_KICKED, // user was kicked eCR_FORCEMOVE, // operator redirect command @@ -142,7 +142,8 @@ namespace nVerliHub { eCR_CLONE, // clone detected eCR_SELF, // same user connects twice eCR_BADNICK, // bad nick, already used, too short, etc - eCR_NOREDIR // do not redirect, special reason + eCR_NOREDIR, // do not redirect, special reason + eCR_PLUGIN // connection closed by plugin }; enum @@ -345,7 +346,7 @@ class cServerDC : public cAsyncSocketServer /* kick user and perform different actions based of flags */ - void DCKickNick(ostream *use_os, cUser *op, const string &nick, const string &why, int flags, const string ¬e_op = "", const string ¬e_usr = ""); + void DCKickNick(ostream *use_os, cUser *op, const string &nick, const string &why, int flags, const string ¬e_op = "", const string ¬e_usr = "", bool hide = false); /* Send a private message to user from other user or hub security. diff --git a/src/ctime.cpp b/src/ctime.cpp index d9328a83..919e7942 100644 --- a/src/ctime.cpp +++ b/src/ctime.cpp @@ -1,135 +1,135 @@ -/* - Copyright (C) 2003-2005 Daniel Muller, dan at verliba dot cz - Copyright (C) 2006-2021 Verlihub Team, info at verlihub dot net - - Verlihub is free software; You can redistribute it - and modify it under the terms of the GNU General - Public License as published by the Free Software - Foundation, either version 3 of the license, or at - your option any later version. - - Verlihub 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. - - Please see http://www.gnu.org/licenses/ for a copy - of the GNU General Public License. -*/ - -#include "ctime.h" - -#ifdef HAVE_CONFIG_H - #include -#endif - -#include -#include - -/* -#if defined _WIN32 - #include -#endif -*/ - -#include "i18n.h" - -using namespace std; - -namespace nVerliHub { - namespace nUtils { - -cTime::~cTime() -{} - -string cTimePrint::AsString() const -{ - ostringstream os; - os << (*this); - return os.str(); -} - -std::ostream& operator<<(std::ostream &os, const cTimePrint &t) -{ - #define CTIME_BUFFSIZE 26 - static char buf[CTIME_BUFFSIZE + 1]; - long n, rest, i; - ostringstream ostr; - - switch (t.mPrintType) { - case 1: - strftime(buf, CTIME_BUFFSIZE + 1, "%Y-%m-%d %H:%M:%S", localtime((const time_t*) & (t.tv_sec))); - os << buf; - break; - - case 2: - rest = t.tv_sec; - i = 0; - n = rest / (24 * 3600 * 7); - rest %= (24 * 3600 * 7); - - if (n > 0) { - ++i; - ostr << ' ' << autosprintf(ngettext("%ld week", "%ld weeks", n), n); - } - - n = rest / (24 * 3600); - rest %= (24 * 3600); - - if (n > 0) { - ++i; - ostr << ' ' << autosprintf(ngettext("%ld day", "%ld days", n), n); - } - - n = rest / 3600; - rest %= 3600; - - if ((n > 0) && (++i <= 2)) - ostr << ' ' << autosprintf(ngettext("%ld hour", "%ld hours", n), n); - - n = rest / 60; - rest %= 60; - - if ((n > 0) && (++i <= 2)) - ostr << ' ' << autosprintf(ngettext("%ld min", "%ld mins", n), n); - - n = rest; - rest = 0; - - if ((n > 0) && (++i <= 2)) - ostr << ' ' << autosprintf(ngettext("%ld sec", "%ld secs", n), n); - - n = (int)t.tv_usec / 1000; - - if ((n > 0) && (++i <= 2)) - ostr << ' ' << autosprintf(ngettext("%ld msec", "%ld msecs", n), n); - - //n = (int)t.tv_usec % 1000; - - //if ((n > 0) && (++i <= 2)) - //ostr << ' ' << autosprintf(ngettext("%ld usec", "%ld usecs", n), n); - - if (ostr.str().empty()) - os << autosprintf(_("%d msecs"), 0); // _("%d usecs") - else - os << ostr.str().substr(1); // strip space - - break; - - default: - #ifdef HAVE_OPENBSD - os << ' ' << autosprintf(ngettext("%lld sec", "%lld secs", t.tv_sec), t.tv_sec); - #else - os << ' ' << autosprintf(ngettext("%ld sec", "%ld secs", t.tv_sec), t.tv_sec); - #endif - - os << ' ' << autosprintf(ngettext("%ld usec", "%ld usecs", t.tv_usec), t.tv_usec); - break; - } - - return os; -}; - - }; // namespace nUtils -}; // namespace nVerliHub +/* + Copyright (C) 2003-2005 Daniel Muller, dan at verliba dot cz + Copyright (C) 2006-2021 Verlihub Team, info at verlihub dot net + + Verlihub is free software; You can redistribute it + and modify it under the terms of the GNU General + Public License as published by the Free Software + Foundation, either version 3 of the license, or at + your option any later version. + + Verlihub 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. + + Please see http://www.gnu.org/licenses/ for a copy + of the GNU General Public License. +*/ + +#include "ctime.h" + +#ifdef HAVE_CONFIG_H + #include +#endif + +#include +#include + +/* +#if defined _WIN32 + #include +#endif +*/ + +#include "i18n.h" + +using namespace std; + +namespace nVerliHub { + namespace nUtils { + +cTime::~cTime() +{} + +string cTimePrint::AsString() const +{ + ostringstream os; + os << (*this); + return os.str(); +} + +std::ostream& operator<<(std::ostream &os, const cTimePrint &t) +{ + #define CTIME_BUFFSIZE 26 + static char buf[CTIME_BUFFSIZE + 1]; + long n, rest, i; + ostringstream ostr; + + switch (t.mPrintType) { + case 1: + strftime(buf, CTIME_BUFFSIZE + 1, "%Y-%m-%d %H:%M:%S", localtime((const time_t*) & (t.tv_sec))); + os << buf; + break; + + case 2: + rest = t.tv_sec; + i = 0; + n = rest / (24 * 3600 * 7); + rest %= (24 * 3600 * 7); + + if (n > 0) { + ++i; + ostr << ' ' << autosprintf(ngettext("%ld week", "%ld weeks", n), n); + } + + n = rest / (24 * 3600); + rest %= (24 * 3600); + + if (n > 0) { + ++i; + ostr << ' ' << autosprintf(ngettext("%ld day", "%ld days", n), n); + } + + n = rest / 3600; + rest %= 3600; + + if ((n > 0) && (++i <= 2)) + ostr << ' ' << autosprintf(ngettext("%ld hour", "%ld hours", n), n); + + n = rest / 60; + rest %= 60; + + if ((n > 0) && (++i <= 2)) + ostr << ' ' << autosprintf(ngettext("%ld min", "%ld mins", n), n); + + n = rest; + rest = 0; + + if ((n > 0) && (++i <= 2)) + ostr << ' ' << autosprintf(ngettext("%ld sec", "%ld secs", n), n); + + n = (int)t.tv_usec / 1000; + + if ((n > 0) && (++i <= 2)) + ostr << ' ' << autosprintf(ngettext("%ld msec", "%ld msecs", n), n); + + //n = (int)t.tv_usec % 1000; + + //if ((n > 0) && (++i <= 2)) + //ostr << ' ' << autosprintf(ngettext("%ld usec", "%ld usecs", n), n); + + if (ostr.str().empty()) + os << autosprintf(_("%d msecs"), 0); // _("%d usecs") + else + os << ostr.str().substr(1); // strip space + + break; + + default: + #ifdef HAVE_OPENBSD + os << ' ' << autosprintf(ngettext("%lld sec", "%lld secs", t.tv_sec), t.tv_sec); + #else + os << ' ' << autosprintf(ngettext("%ld sec", "%ld secs", t.tv_sec), t.tv_sec); + #endif + + os << ' ' << autosprintf(ngettext("%ld usec", "%ld usecs", t.tv_usec), t.tv_usec); + break; + } + + return os; +}; + + }; // namespace nUtils +}; // namespace nVerliHub diff --git a/src/ctime.h b/src/ctime.h index a74c4861..84e6bf30 100644 --- a/src/ctime.h +++ b/src/ctime.h @@ -1,125 +1,125 @@ -/* - Copyright (C) 2003-2005 Daniel Muller, dan at verliba dot cz - Copyright (C) 2006-2021 Verlihub Team, info at verlihub dot net - - Verlihub is free software; You can redistribute it - and modify it under the terms of the GNU General - Public License as published by the Free Software - Foundation, either version 3 of the license, or at - your option any later version. - - Verlihub 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. - - Please see http://www.gnu.org/licenses/ for a copy - of the GNU General Public License. -*/ - -#ifndef NUTILS_CTIME_H -#define NUTILS_CTIME_H - -#ifdef HAVE_CONFIG_H - #include -#endif - -#include -#include - -/* -#if defined _WIN32 -#include -#endif -*/ - -#include -#include - -//#ifndef _WIN32 -#define __int64 long long -//#endif - -namespace nVerliHub { - namespace nUtils { - -class cTime : public timeval -{ - public: - ~cTime(); - cTime(){Get();} - cTime(double sec){tv_sec=(long)sec; tv_usec=long((sec-tv_sec)*1000000);} - cTime(long sec, long usec=0){tv_sec=sec; tv_usec=usec;} - int operator> (const cTime &t) const { if(tv_sec > t.tv_sec) return 1; if(tv_sec < t.tv_sec) return 0; return (tv_usec > t.tv_usec);} - int operator>= (const cTime &t) const { if(tv_sec > t.tv_sec) return 1; if(tv_sec < t.tv_sec) return 0; return (tv_usec >= t.tv_usec);} - int operator< (const cTime &t) const { if(tv_sec < t.tv_sec) return 1; if(tv_sec > t.tv_sec) return 0; return (tv_usec < t.tv_usec);} - int operator<= (const cTime &t) const { if(tv_sec < t.tv_sec) return 1; if(tv_sec > t.tv_sec) return 0; return (tv_usec <= t.tv_usec);} - int operator== (const cTime &t) const { return ((tv_usec == t.tv_usec) && (tv_sec == t.tv_sec));} - cTime & Get(){gettimeofday(this,NULL);return *this;} - cTime operator- (const cTime &t) const {long sec = tv_sec-t.tv_sec; long usec=tv_usec-t.tv_usec; return cTime(sec,usec).Normalize();} - cTime operator+ (const cTime &t) const {long sec = tv_sec+t.tv_sec; long usec=tv_usec+t.tv_usec; return cTime(sec,usec).Normalize();} - cTime operator+ (int _sec) const {long sec = tv_sec+_sec; return cTime(sec,tv_usec).Normalize();} - cTime operator- (int _sec) const {long sec = tv_sec-_sec; return cTime(sec,tv_usec).Normalize();} - cTime & operator-= (const cTime &t){tv_sec-=t.tv_sec;tv_usec-=t.tv_usec; Normalize(); return *this;} - - cTime & operator+= (const cTime &t){tv_sec+=t.tv_sec;tv_usec+=t.tv_usec; Normalize(); return *this;} - cTime & operator+= (int msec){tv_usec+=1000*msec; Normalize(); return *this;} - cTime & operator+= (long usec){tv_usec+=usec; Normalize(); return *this;} - - cTime & operator/= (int i){long sec=tv_sec/i; tv_usec+=1000000*(tv_sec % i); tv_usec/=i; tv_sec=sec; Normalize(); return *this;} - cTime & operator*= (int i){tv_sec*=i;tv_usec*=i;Normalize(); return *this;} - cTime operator/ (int i) const {long sec=tv_sec/i; long usec=tv_usec+1000000*(tv_sec % i); usec/=i; return cTime(sec,usec).Normalize();} - cTime operator* (int i) const {long sec=tv_sec*i; long usec=tv_usec*i; return cTime(sec,usec).Normalize();} - operator double(){ return double(tv_sec)+double(tv_usec)/1000000.;} - operator long() const { return long(tv_sec)*1000000+long(tv_usec);} - operator bool() const { return !(!tv_sec && !tv_usec);} - int operator! () const { return !tv_sec && !tv_usec;} - long Sec() const { return tv_sec; } - __int64 MiliSec() { return (__int64)(tv_sec)*1000+(__int64)(tv_usec)/1000; } - - cTime & Normalize() - { - if(tv_usec >= 1000000 || tv_usec <= -1000000) - { - tv_sec += tv_usec/1000000; - tv_usec %= 1000000; - } - if( tv_sec < 0 && tv_usec > 0) - { - tv_sec ++; - tv_usec-= 1000000; - } - if( tv_sec > 0 && tv_usec < 0) - { - tv_sec --; - tv_usec+= 1000000; - } - return *this; - }; - -}; - -class cTimePrint: public cTime -{ +/* + Copyright (C) 2003-2005 Daniel Muller, dan at verliba dot cz + Copyright (C) 2006-2021 Verlihub Team, info at verlihub dot net + + Verlihub is free software; You can redistribute it + and modify it under the terms of the GNU General + Public License as published by the Free Software + Foundation, either version 3 of the license, or at + your option any later version. + + Verlihub 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. + + Please see http://www.gnu.org/licenses/ for a copy + of the GNU General Public License. +*/ + +#ifndef NUTILS_CTIME_H +#define NUTILS_CTIME_H + +#ifdef HAVE_CONFIG_H + #include +#endif + +#include +#include + +/* +#if defined _WIN32 +#include +#endif +*/ + +#include +#include + +//#ifndef _WIN32 +#define __int64 long long +//#endif + +namespace nVerliHub { + namespace nUtils { + +class cTime : public timeval +{ + public: + ~cTime(); + cTime(){Get();} + cTime(double sec){tv_sec=(long)sec; tv_usec=long((sec-tv_sec)*1000000);} + cTime(long sec, long usec=0){tv_sec=sec; tv_usec=usec;} + int operator> (const cTime &t) const { if(tv_sec > t.tv_sec) return 1; if(tv_sec < t.tv_sec) return 0; return (tv_usec > t.tv_usec);} + int operator>= (const cTime &t) const { if(tv_sec > t.tv_sec) return 1; if(tv_sec < t.tv_sec) return 0; return (tv_usec >= t.tv_usec);} + int operator< (const cTime &t) const { if(tv_sec < t.tv_sec) return 1; if(tv_sec > t.tv_sec) return 0; return (tv_usec < t.tv_usec);} + int operator<= (const cTime &t) const { if(tv_sec < t.tv_sec) return 1; if(tv_sec > t.tv_sec) return 0; return (tv_usec <= t.tv_usec);} + int operator== (const cTime &t) const { return ((tv_usec == t.tv_usec) && (tv_sec == t.tv_sec));} + cTime & Get(){gettimeofday(this,NULL);return *this;} + cTime operator- (const cTime &t) const {long sec = tv_sec-t.tv_sec; long usec=tv_usec-t.tv_usec; return cTime(sec,usec).Normalize();} + cTime operator+ (const cTime &t) const {long sec = tv_sec+t.tv_sec; long usec=tv_usec+t.tv_usec; return cTime(sec,usec).Normalize();} + cTime operator+ (int _sec) const {long sec = tv_sec+_sec; return cTime(sec,tv_usec).Normalize();} + cTime operator- (int _sec) const {long sec = tv_sec-_sec; return cTime(sec,tv_usec).Normalize();} + cTime & operator-= (const cTime &t){tv_sec-=t.tv_sec;tv_usec-=t.tv_usec; Normalize(); return *this;} + + cTime & operator+= (const cTime &t){tv_sec+=t.tv_sec;tv_usec+=t.tv_usec; Normalize(); return *this;} + cTime & operator+= (int msec){tv_usec+=1000*msec; Normalize(); return *this;} + cTime & operator+= (long usec){tv_usec+=usec; Normalize(); return *this;} + + cTime & operator/= (int i){long sec=tv_sec/i; tv_usec+=1000000*(tv_sec % i); tv_usec/=i; tv_sec=sec; Normalize(); return *this;} + cTime & operator*= (int i){tv_sec*=i;tv_usec*=i;Normalize(); return *this;} + cTime operator/ (int i) const {long sec=tv_sec/i; long usec=tv_usec+1000000*(tv_sec % i); usec/=i; return cTime(sec,usec).Normalize();} + cTime operator* (int i) const {long sec=tv_sec*i; long usec=tv_usec*i; return cTime(sec,usec).Normalize();} + operator double(){ return double(tv_sec)+double(tv_usec)/1000000.;} + operator long() const { return long(tv_sec)*1000000+long(tv_usec);} + operator bool() const { return !(!tv_sec && !tv_usec);} + int operator! () const { return !tv_sec && !tv_usec;} + long Sec() const { return tv_sec; } + __int64 MiliSec() { return (__int64)(tv_sec)*1000+(__int64)(tv_usec)/1000; } + + cTime & Normalize() + { + if(tv_usec >= 1000000 || tv_usec <= -1000000) + { + tv_sec += tv_usec/1000000; + tv_usec %= 1000000; + } + if( tv_sec < 0 && tv_usec > 0) + { + tv_sec ++; + tv_usec-= 1000000; + } + if( tv_sec > 0 && tv_usec < 0) + { + tv_sec --; + tv_usec+= 1000000; + } + return *this; + }; + +}; + +class cTimePrint: public cTime +{ public: - cTimePrint():mPrintType(0){} - cTimePrint(double sec){tv_sec=(long)sec; tv_usec=long((sec-tv_sec)*1000000);mPrintType=0;} - cTimePrint(long sec, long usec=0){tv_sec=sec; tv_usec=usec;mPrintType=0;} + cTimePrint():mPrintType(0){} + cTimePrint(double sec){tv_sec=(long)sec; tv_usec=long((sec-tv_sec)*1000000);mPrintType=0;} + cTimePrint(long sec, long usec=0){tv_sec=sec; tv_usec=usec;mPrintType=0;} cTimePrint(const cTime& t) {timeval& t_val = *this;t_val = t; mPrintType=0;} -private: - mutable int mPrintType; - -public: - cTimePrint operator/ (int i) const {long sec=tv_sec/i; long usec=tv_usec+1000000*(tv_sec % i); usec/=i; return cTimePrint(cTime(sec,usec).Normalize());} - const cTimePrint & AsDate() const { mPrintType=1; return *this;} - const cTimePrint & AsPeriod() const { mPrintType=2; return *this;} +private: + mutable int mPrintType; + +public: + cTimePrint operator/ (int i) const {long sec=tv_sec/i; long usec=tv_usec+1000000*(tv_sec % i); usec/=i; return cTimePrint(cTime(sec,usec).Normalize());} + const cTimePrint & AsDate() const { mPrintType=1; return *this;} + const cTimePrint & AsPeriod() const { mPrintType=2; return *this;} //operator cTime() {return *this;} - std::string AsString() const; - friend std::ostream & operator<< (std::ostream &os, const cTimePrint &t); -}; - - }; // namespace nUtils -}; // namespace nVerliHub -#endif + std::string AsString() const; + friend std::ostream & operator<< (std::ostream &os, const cTimePrint &t); +}; + + }; // namespace nUtils +}; // namespace nVerliHub +#endif diff --git a/src/script_api.cpp b/src/script_api.cpp index 61e7e01c..ed2a2cd6 100644 --- a/src/script_api.cpp +++ b/src/script_api.cpp @@ -237,7 +237,7 @@ bool SendToOpChat(const char *data, const char *nick) return true; } -bool KickUser(const char *oper, const char *nick, const char *why, const char *note_op, const char *note_usr) +bool KickUser(const char *oper, const char *nick, const char *why, const char *note_op, const char *note_usr, bool hide) { if (!oper || !nick) return false; @@ -259,7 +259,7 @@ bool KickUser(const char *oper, const char *nick, const char *why, const char *n if (!user || !user->mxConn) return false; - serv->DCKickNick(NULL, opuser, nick, why, (eKI_CLOSE | eKI_WHY | eKI_PM | eKI_BAN), (note_op ? note_op : ""), (note_usr ? note_usr : "")); + serv->DCKickNick(NULL, opuser, nick, why, (eKI_CLOSE | eKI_WHY | eKI_PM | eKI_BAN), (note_op ? note_op : ""), (note_usr ? note_usr : ""), hide); return true; } @@ -274,9 +274,9 @@ bool CloseConnection(const char *nick, long delay) return false; if (delay) - user->mxConn->CloseNice(delay, eCR_KICKED); + user->mxConn->CloseNice(delay, eCR_PLUGIN); else - user->mxConn->CloseNow(); + user->mxConn->CloseNow(eCR_PLUGIN); return true; } diff --git a/src/script_api.h b/src/script_api.h index c5d1119b..15191bab 100644 --- a/src/script_api.h +++ b/src/script_api.h @@ -53,7 +53,7 @@ namespace nVerliHub { const char* GetUserIP(const char *nick); bool SetUserIP(const char *nick, const char *ip); bool Ban(const char *, const string &, const string &, unsigned, unsigned); - bool KickUser(const char *oper, const char *nick, const char *why, const char *note_op = NULL, const char *note_usr = NULL); + bool KickUser(const char *oper, const char *nick, const char *why, const char *note_op = NULL, const char *note_usr = NULL, bool hide = false); bool DeleteNickTempBan(const char *nick); bool DeleteIPTempBan(const char *ip); bool ParseCommand(const char *nick, const char *cmd, int pm);