int m_servlist(aClient *cptr, aClient *sptr, int parc, char *parv[]) { aClient *acptr; char *mask; mask = IsParam(1) ? parv[1] : NULL; for (acptr = client; acptr; acptr = acptr->next) { if (!IsPerson(acptr) || !IsServices(acptr)) continue; if (mask && _match(mask, acptr->name)) continue; sendto_one(sptr, TEXT_SERVLIST, me.name, sptr->name, acptr->name, acptr->user->username, GetHost(acptr), acptr->srvptr->name, acptr->srvptr->hopcount, acptr->info); } sendto_one(sptr, TEXT_SERVLISTEND, me.name, sptr->name, mask ? mask : "*"); return 0; }
void CvVSModule::TransferParamsToChild(CvVSModule* pM, char* prefix) { char tmp[1024]; int i; for(i=0;;++i) { const char* N = pM->GetParamName(i); if(N == NULL) break; if(prefix) { strcpy(tmp,prefix); strcat(tmp,"_"); strcat(tmp,N); } else { strcpy(tmp,N); } if(IsParam(tmp)) { if(GetParamStr(tmp)) pM->SetParamStr(N,GetParamStr(tmp)); else pM->SetParam(N,GetParam(tmp)); } }/* Transfer next parameter */ pM->ParamUpdate(); }/* Transfer params */
/* Get type of symbole */ char TypeOf(char symbol) { if (IsParam(symbol)) { return 'f'; } else { return ST[symbol - 'A']; } }
/* Add a new parameter to table */ void AddParam(char name) { if (IsParam(name)) { Duplicate(name); } NumParams++; Params[name - 'A'] = NumParams; }
// // FindNextParamArg // // Returns the next argument number for a command line parameter starting // from argument number i. // static size_t FindNextParamArg(const char* param, const std::vector<std::string>& args, size_t i) { while (i < args.size()) { if (!IsParam(args, i)) return i; // matches param, return first argument for this param if (stricmp(param, args[i].c_str()) == 0) { i++; continue; } // skip over any params that don't match and their arguments for (i++; i < args.size() && !IsParam(args, i); i++) ; } return args.size(); }
void CvVSModule::TransferParamsFromChild(CvVSModule* pM, const char* prefix) { char tmp[1024]; const char* FN = NULL; int i; for(i=0;;++i) { const char* N = pM->GetParamName(i); if(N == NULL) break; FN = N; if(prefix) { strcpy(tmp,prefix); strcat(tmp,"_"); FN = strcat(tmp,N); } if(!IsParam(FN)) { if(pM->GetParamStr(N)) { AddParam(FN,(const char**)NULL); } else { AddParam(FN); } } if(pM->GetParamStr(N)) { const char* val = pM->GetParamStr(N); SetParamStr(FN,val); } else { double val = pM->GetParam(N); SetParam(FN,val); } CommentParam(FN, pM->GetParamComment(N)); }/* transfer next param */ }/* Transfer params */
//////////////////////////////////////////////////////////////////////// // 描 述: 启动应用程序 // 作 者: 邵凯田 // 创建时间: 2008-10-10 14:17 // 参数说明: @argc/argv为main输入参数 // @szDate/szTime为编译日期时间 // @bBlock为是否阻塞运行,true为阻塞,false为不阻塞 // 返 回 值: true/false ////////////////////////////////////////////////////////////////////////// bool SApplication::Run(int argc, char* argv[],const char* szDate,const char* szTime,bool bBlock/*=true*/) { m_iArgc = argc; m_ppArgv = (char**)argv; m_sModule = argv[0]; #ifndef _WITHOUT_AGENT_CHANNEL_ m_sAgentIp = "127.0.0.1"; #endif SString err; SString crc = SApi::GenerateCRCByFile(m_sModule,err); m_sModuleCrc = crc; m_sModuleTime.sprintf("%s %s",szDate,szTime); if(m_sModule.findRev('/') >= 0) m_sModule = m_sModule.mid(m_sModule.findRev('/')+1); if(m_sModule.findRev('\\') >= 0) m_sModule = m_sModule.mid(m_sModule.findRev('\\')+1); printf("#########################################################\n"); printf("## SKTBASE Application frame\n"); printf("## Module Name: %s \n",m_sModule.data()); printf("## Description : %s \n",m_sModuleDesc.data()); printf("## Compile Time: %s %s\n",szDate,szTime); printf("## Appbase Ver : V%s \n",m_sAppbaseVer.data()); printf("## Module Ver : V%s \n",m_sModuleVer.data()); printf("## CRC Code : %s \n",crc.data()); printf("#########################################################\n"); SString sTemp=""; if(IsParam("version",sTemp)) { bool bWrite = false; SString sLine; SFile file; if(sTemp.length() > 0) { file.setFileName(sTemp); if(file.open(IO_Truncate)) bWrite = true; } if(bWrite) { sLine.sprintf("#########################################################\n"); file.writeString(sLine); sLine.sprintf("## SKTBASE Application frame\n"); file.writeString(sLine); sLine.sprintf("## Module Name: %s \n",m_sModule.data()); file.writeString(sLine); sLine.sprintf("## Description : %s \n",m_sModuleDesc.data()); file.writeString(sLine); sLine.sprintf("## Compile Time: %s %s\n",szDate,szTime); file.writeString(sLine); sLine.sprintf("## Appbase Ver : V%s \n",m_sAppbaseVer.data()); file.writeString(sLine); sLine.sprintf("## Module Ver : V%s \n",m_sModuleVer.data()); file.writeString(sLine); sLine.sprintf("## CRC Code : %s \n",crc.data()); file.writeString(sLine); sLine.sprintf("#########################################################\n"); file.writeString(sLine); file.close(); } exit(0); abort(); } if(m_sModuleDesc.length() == 0) { printf("ERROR!!! 缺少模块描述信息!请调用基类CSRecApplication::SetModuleDesc方法!\n\n\n"); } if(m_sModuleVer.length() == 0) { printf("ERROR!!! 缺少模块版本信息!请调用基类CSRecApplication::SetVersion方法!\n\n\n"); } #ifndef WIN32 signal(SIGPIPE,SIG_IGN);//忽略管道断开信号 signal(SIGCHLD,SIG_IGN); signal(SIGCLD, SIG_IGN); #endif #ifndef WIN32 if(m_bFork) { //LINUX下将进程设置为守护进程 //printf("@@@@@@@@@@@@begin fork()\n"); if(fork()) { //printf("@@@@@@@@@@@@fork()\n"); exit(0); } } SApi::UsSleep(100000); signal(SIGCHLD,SIG_IGN); #endif SLog::setLogLevel(SLog::LOG_DEBUG); SLog::setModuleName(m_sModule.data()); //预处理命令 SXmlConfig xml; SString sFileName; m_sExePath = SDir::currentDirPath(); if(m_sExePath.right(1) != "/" && m_sExePath.right(1) != "\\") m_sExePath += "/"; sFileName=m_sExePath + "logconfig.xml"; if(!xml.ReadConfig(sFileName)) { LOGWARN("打开<logconfig.xml>文件失败!将无法使用日志记录功能! file=%s",sFileName.data()); } else { sFileName = m_sModule; SBaseConfig *pPrecommand = xml.SearchChild("log<module='"+sFileName+"'>"); if(pPrecommand == NULL) { if(sFileName.right(4).toLower() == ".exe") sFileName = sFileName.left(sFileName.length()-4); pPrecommand = xml.SearchChild("log<module='"+sFileName+"'>"); } if(pPrecommand == NULL) { //没有专用的,找缺省的 pPrecommand = xml.SearchChild("log<module=''>"); } if(pPrecommand != NULL) { //预处理命令 int i,cnt = pPrecommand==NULL?0:pPrecommand->GetChildCount("command"); for(i=0;i<cnt;i++) { SBaseConfig *pCommand = pPrecommand->GetChildNode(i,"command"); if(pCommand == NULL ) continue; SString cmd = pCommand->GetNodeValue(); if(cmd.find("[@modulename]") >= 0) { SString sModule = SLog::getModuleName(); cmd = cmd.replace("[@modulename]",sModule); } ParseCommandLine(cmd); } } } //是否处于调试模式 if(IsParam("debug")) m_bDebugMode = true; if(IsParam("console",sTemp)) { sTemp = sTemp.toLower(); if(sTemp == "off") { //强制关闭控制台的日志输出 m_bLogToConsole = false; ParseCommandLine("log to console off"); } } #ifndef _WITHOUT_AGENT_CHANNEL_ if(IsParam("agentport",sTemp)) { m_iAgentPort = sTemp.toInt(); if(m_iAgentPort == 0) m_iAgentPort = 6666; } #endif if(IsParam("stop")) { if(!_Stop()) { LOGFAULT("停止应用失败!"); //SLog::WaitForLogEmpty(); return false; } return true; } else if(IsParam("restart")) { _Stop(); if(!_Start()) { LOGFAULT("启动应用失败!"); //SLog::WaitForLogEmpty(); return false; } } else { if(!_Start()) { LOGFAULT("启动应用失败!"); //SLog::WaitForLogEmpty(); return false; } } LOGDEBUG("应用服务启动完成!"); if(bBlock) { //阻塞方式运行 #ifndef _WITHOUT_AGENT_CHANNEL_ StartAgent(bBlock); #else while(!m_bHalt) { //等待有人发出退出信号 if(IsClosedExist()) { LOGWARN("收到退出信号! 准备关闭当前进程!"); Stop(); //准备关闭当前进程 this->RemoveClose(); break; } SApi::UsSleep(2000000); } #endif } else { //非阻塞方式运行 #ifndef _WITHOUT_AGENT_CHANNEL_ StartAgent(bBlock); #endif } LOGDEBUG("应用服务已退出!"); //SLog::WaitForLogEmpty(); return true; }
DLLFUNC int m_rmtkl(aClient *cptr, aClient *sptr, int parc, char *parv[]) { aTKline *tk, *next = NULL; TKLType *tkltype; char *types, *uhmask, *cmask, *p; char gmt[256], flag; int tklindex; if (!IsULine(sptr) && !(IsPerson(sptr) && IsAnOper(sptr))) { sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]); return -1; } if (IsNotParam(1)) return dumpit(sptr, rmtkl_help); if (IsNotParam(2)) { sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS), me.name, parv[0], "RMTKL"); sendnotice(sptr, "Type '/RMTKL' for help"); return 0; } types = parv[1]; uhmask = parv[2]; cmask = IsParam(3) ? parv[3] : NULL; /* I don't add 'q' and 'Q' here. They are different. */ if (strchr(types, '*')) types = "KzGZs"; /* check access */ if (!IsULine(sptr)) for (p = types; *p; p++) { tkltype = find_TKLType_by_flag(*p); if (!tkltype->type) continue; if (((tkltype->type & TKL_GLOBAL) && !IsOper(sptr)) || !(sptr->oflag & tkltype->oflag)) { sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]); return -1; } } for (tkltype = tkl_types; tkltype->type; tkltype++) { flag = tkltype->flag; tklindex = tkl_hash(flag); if (!strchr(types, flag)) continue; for (tk = tklines[tklindex]; tk; tk = next) { next = tk->next; if (tk->type != tkltype->type) continue; if (tk->type & TKL_NICK) { /* * If it's a services hold (ie. NickServ is holding * a nick), it's better not to touch it */ if (*tk->usermask == 'H') continue; if (match(uhmask, tk->hostmask)) continue; } else if (match(uhmask, make_user_host(tk->usermask, tk->hostmask))) continue; if (cmask && _match(cmask, tk->reason)) continue; strncpyzt(gmt, asctime(gmtime((TS *)&tk->set_at)), sizeof gmt); iCstrip(gmt); if (tk->type & TKL_NICK) { sendto_snomask(SNO_TKL, "%s removed %s %s (set at %s " "- reason: %s)", sptr->name, tkltype->txt, tk->hostmask, gmt, tk->reason); ircd_log(LOG_TKL, "%s removed %s %s (set at %s " "- reason: %s)", sptr->name, tkltype->txt, tk->hostmask, gmt, tk->reason); } else { sendto_snomask(SNO_TKL, "%s removed %s %s@%s (set at " "%s - reason: %s)", sptr->name, tkltype->txt, tk->usermask, tk->hostmask, gmt, tk->reason); ircd_log(LOG_TKL, "%s removed %s %s@%s (set at " "%s - reason: %s)", sptr->name, tkltype->txt, tk->usermask, tk->hostmask, gmt, tk->reason); } if ((tk->type & TKL_GLOBAL) && flag) sendto_serv_butone_token(&me, me.name, MSG_TKL, TOK_TKL, "- %c %s %s %s", flag, tk->usermask, tk->hostmask, parv[0]); if (tk->type & TKL_SHUN) tkl_check_local_remove_shun(tk); my_tkl_del_line(tk, tklindex); } } return 0; }