Example #1
0
int replaceModule(HWND hwnd, HANDLE hContact, const char *module, const char *find, const char *replace, int mode)
{

	ModuleSettingLL msll;
	struct ModSetLinkLinkItem *setting;
	char *myreplace = NULL;
	char *newModule;
	int count = 0;

	if (mode & RW_FULL)
		newModule = (char*)replace;
	else
	{
		myreplace = multiReplace(module, find, replace, mode & RW_CASE);
		newModule = myreplace;
	}

	if (newModule[0]==0)
	{
		ItemFound(hwnd,hContact,module,NULL,NULL,FW_MODULE|FW_DELETED);
		deleteModule((char*)module, hContact, 1);
		replaceTreeItem(GetDlgItem(hwnd2mainWindow,IDC_MODULES), hContact, module, NULL);
		mir_free(myreplace);
		return 1;
	}

	if (!IsModuleEmpty(hContact, newModule))
		return 0;

	if (EnumSettings(hContact,(char*)module,&msll))
	{
		setting = msll.first;

		while(setting)
		{
			DBVARIANT dbv;

			if (!GetSetting(hContact, module, setting->name, &dbv))
			{
				switch (dbv.type)
				{
					case DBVT_BYTE:
						DBWriteContactSettingByte(hContact, newModule, setting->name, dbv.bVal);
					break;
					case DBVT_WORD:
						DBWriteContactSettingWord(hContact, newModule, setting->name, dbv.wVal);
					break;
					case DBVT_DWORD:
						DBWriteContactSettingDword(hContact, newModule, setting->name, dbv.dVal);
					break;
					case DBVT_ASCIIZ:
						DBWriteContactSettingString(hContact, newModule, setting->name, dbv.pszVal);
					break;
					case DBVT_UTF8:
						DBWriteContactSettingStringUtf(hContact, newModule, setting->name, dbv.pszVal);
					break;
					case DBVT_BLOB:
						DBWriteContactSettingBlob(hContact, newModule, setting->name, dbv.pbVal, dbv.cpbVal);
					break;
				}

				DBFreeVariant(&dbv);
				DBDeleteContactSetting(hContact, module, setting->name);
			}

			setting = (struct ModSetLinkLinkItem *)setting->next;
		}
		FreeModuleSettingLL(&msll);

		replaceTreeItem(GetDlgItem(hwnd2mainWindow,IDC_MODULES), hContact, module, newModule);

		ItemFound(hwnd,hContact,newModule,NULL,NULL,FW_MODULE|FW_REPLACED);
		count++;
	}

	mir_free(myreplace);

	return count;
}
Example #2
0
void __cdecl FindSettings(LPVOID di)
{
	char* text = ((FindInfo*)di)->text;
	char* replace = ((FindInfo*)di)->replace;
	int mode = ((FindInfo*)di)->mode;
	HWND hwnd = ((FindInfo*)di)->hwnd;
	HWND prnthwnd = GetParent(hwnd);
	int options = ((FindInfo*)di)->options;
	ModuleSettingLL ModuleList, SettingList;
	struct ModSetLinkLinkItem *module, *setting;
	HANDLE hContact;
	DBVARIANT dbv = {0};
	int caseSensitive = options&FW_CASE;
	int exactMatch = options&FW_EXACT;
	int inModuleName = options&FW_MODNAME;
	int inSettingName = options&FW_SETNAME;
	int inSettingValue = options&FW_SETVAL;
	int foundCount = 0;
	int replaceCount = 0;
	char szTmp[128];
	int settingValue, isNumber, NULLContactDone = 0;

	freeItems(hwnd);
	if (!text) return;

	if (!EnumModules(&ModuleList)) { msg(Translate("Error Loading Module List"),modFullname); mir_free(di); return;}

	SendMessage(GetDlgItem(GetParent(hwnd),IDC_SBAR),SB_SETTEXT,0,(LPARAM)Translate("Searching..."));

	hContact = 0;

	isNumber = sscanf(text,"%d",&settingValue);

	while (GetWindowLongPtr(GetDlgItem(prnthwnd,IDC_SEARCH),GWLP_USERDATA))
	{
		if (!hContact)
		{
			if (NULLContactDone) break;
			else
			{
				NULLContactDone = 1;
				hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0);
			}
		}
		else hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0);

		module = ModuleList.first;
		while (module)
		{
			if (IsModuleEmpty(hContact, module->name))
			{
				module = (struct ModSetLinkLinkItem *)module->next;
				continue;
			}

			if (!EnumSettings(hContact,module->name,&SettingList))
			{
				msg(Translate("Error Loading Setting List"),modFullname);
				mir_free(text);
				mir_free(di);
				FreeModuleSettingLL(&ModuleList);
				return;
			}
			setting = SettingList.first;

			// check in settings value
			while (setting)
			{
				if (inSettingValue)
				{
					dbv.type = 0;
					// check the setting value
					if (!GetSetting(hContact,module->name,setting->name,&dbv))
					{
						switch (dbv.type)
						{
							case DBVT_UTF8: // no conversion atm
							case DBVT_ASCIIZ:
								if ((exactMatch && !(caseSensitive?strcmp(dbv.pszVal,text):strcmpi(dbv.pszVal,text))) || (!exactMatch && (caseSensitive?strstr(dbv.pszVal,text):StrStrI(dbv.pszVal,text))))
								{
									if ((mode & RW_FOUND) || (mode & RW_SETVAL))
										replaceCount += replaceValue(hwnd, hContact, module->name, setting->name, &dbv, text, replace, mode);
									else
										ItemFound(hwnd,hContact,module->name,setting->name,dbv.pszVal,FW_SETTINGVALUE);

									foundCount++;
								}
							break;

							case DBVT_BYTE:
								if (isNumber && settingValue == dbv.bVal)
								{
									if ((mode & RW_FOUND) || (mode & RW_SETVAL))
										replaceCount += replaceValue(hwnd, hContact, module->name, setting->name, &dbv, NULL, replace, mode);
									else
										ItemFound(hwnd,hContact,module->name,setting->name,text,FW_SETTINGVALUE);
									foundCount++;
								}
							break;

							case DBVT_WORD:
								if (isNumber && settingValue == dbv.wVal)
								{
									if ((mode & RW_FOUND) || (mode & RW_SETVAL))
										replaceCount += replaceValue(hwnd, hContact, module->name, setting->name, &dbv, NULL, replace, mode);
									else
										ItemFound(hwnd,hContact,module->name,setting->name,text,FW_SETTINGVALUE);
									foundCount++;
								}
							break;

							case DBVT_DWORD:
								if (isNumber && settingValue == (int)dbv.dVal)
								{
									if ((mode & RW_FOUND) || (mode & RW_SETVAL))
										replaceCount += replaceValue(hwnd, hContact, module->name, setting->name, &dbv, NULL, replace, mode);
									else
										ItemFound(hwnd,hContact,module->name,setting->name,text,FW_SETTINGVALUE);
									foundCount++;
								}
							break;

						}
						DBFreeVariant(&dbv);
					}
				}

				// check in setting name
				if (inSettingName)
				{
					if ((exactMatch && !(caseSensitive?strcmp(setting->name,text):strcmpi(setting->name,text))) || (!exactMatch && (caseSensitive?StrStrI(setting->name,text):StrStrI(setting->name,text))))
					{
						if ((mode & RW_FOUND) || (mode & RW_SETNAME))
						{
							if (!GetSetting(hContact,module->name,setting->name,&dbv))
							{
								replaceCount += replaceSetting(hwnd, hContact, module->name, setting->name, &dbv, text, replace, mode);
								DBFreeVariant(&dbv);
							}
						}
						else
							ItemFound(hwnd,hContact,module->name,setting->name, NULL, FW_SETTINGNAME);
						foundCount++;
					}
				}

				setting = (struct ModSetLinkLinkItem *)setting->next;
			}

			// check in module name
			if (inModuleName)
			{
				if ((exactMatch && !(caseSensitive?strcmp(module->name,text):strcmpi(module->name,text))) || (!exactMatch && (caseSensitive?strstr(module->name,text):StrStrI(module->name,text))))
				{
					if ((mode & RW_FOUND) || (mode & RW_MODULE))
						replaceCount += replaceModule(hwnd, hContact, module->name, text, replace, mode);
					else
						ItemFound(hwnd,hContact,module->name,0, 0, FW_MODULE);
					foundCount++;
				}
			}

			FreeModuleSettingLL(&SettingList);
			module = (struct ModSetLinkLinkItem *)module->next;
		}
	}

	if (mode)
	{
		if (!replace[0])
			mir_snprintf(szTmp, SIZEOF(szTmp), Translate("Finished. %d items were found, %d items were deleted."), foundCount, replaceCount);
		else
			mir_snprintf(szTmp, SIZEOF(szTmp), Translate("Finished. %d items were found, %d items were replaced."), foundCount, replaceCount);
	}
	else
		mir_snprintf(szTmp, SIZEOF(szTmp), Translate("Finished. %d items were found."), foundCount);

	SendMessage(GetDlgItem(prnthwnd,IDC_SBAR),SB_SETTEXT,0,(LPARAM)szTmp);

	SetWindowLongPtr(GetDlgItem(prnthwnd,IDC_SEARCH),GWLP_USERDATA,0);

	if (GetWindowLongPtr(GetDlgItem(prnthwnd,IDC_REPLACE),GWLP_USERDATA))
	{
		SetWindowLongPtr(GetDlgItem(prnthwnd,IDC_REPLACE),GWLP_USERDATA, 0);
		EnableWindow(GetDlgItem(prnthwnd,IDC_SEARCH),1);
		SetWindowText(GetDlgItem(prnthwnd,IDOK),Translate("&Replace"));
	}
	else
	{
		SetWindowText(GetDlgItem(prnthwnd,IDC_SEARCH),Translate("&Search"));
		EnableWindow(GetDlgItem(prnthwnd,IDOK),1);
	}

	mir_free(replace);
	mir_free(text);
	mir_free(di);
	FreeModuleSettingLL(&ModuleList);

	EnableWindow(GetDlgItem(prnthwnd,IDCANCEL),1);

}
Example #3
0
//Ok, so here goes nothing...
void iohtmlFunc_ajax( ReplyDataPtr cnt ) {
	#if IRCBOT_SUPPORT
	ConfigArrayPtr settings[2];
	#endif
	int a, c, id, numbuild;
	int64_t b;
	int64_t bsums[CMD_BLDG_NUMUSED+1];
	int64_t usums[CMD_UNIT_NUMUSED];
	const char *typestring, *idstring, *refer;
	char CHECKER[256];
	char timebuf[512];
	dbMainEmpireDef empired;
	dbBuildPtr build;
	dbUserMainDef maind;
	proginfoDef pinfod;
	urlinfoPtr urlp;
	cpuInfo cpuinfo;
	time_t tint;
	struct sysinfo sysinfod;

refer = idstring = typestring = NULL;
cpuGetInfo( &cpuinfo );
getsys_infos( &pinfod );
if( sysinfo(&sysinfod) != 0 ) {
	critical( "Failure getting system infomation... Critical failure." );
	sysconfig.shutdown = true; return;
}

idstring = iohtmlVarsFind( cnt, "id" );
typestring = iohtmlVarsFind( cnt, "typ" );

refer = iohtmlHeaderFind(cnt, "Referer");

if( ( id = iohtmlIdentify( cnt, 2 ) ) >= 0 ) {
	if( dbUserMainRetrieve( id, &maind ) < 0 )
		goto BAILAJAX;
	else if( dbEmpireGetInfo( maind.empire, &empired ) < 0 )
		goto BAILAJAX;

}

if( ( typestring ) && ( refer ) ) {
	urlp = parse_url(refer);
	refer = urlp->path;
	httpString( cnt, "<?xml version=\"1.0\"?>" );
	httpPrintf( cnt, "<xml>" );
	//Begin XML generation, we only make one request now... so we have to structure carefully!
	if( !strcmp(typestring,"ticker") ) {
		//Send basic tick info, and check if user is loged in.
		httpPrintf( cnt, "<pass>%d</pass>", ( id != -1 ) ? ( ( bitflag( ((cnt->session)->dbuser)->flags, CMD_USER_FLAGS_ACTIVATED ) ) ? true : false ) : false );
		if( refer )
			httpPrintf( cnt, "<page>%s</page>", refer );
		httpPrintf( cnt, "<u_online>%d</u_online><u_activated>%d</u_activated>", dbRegisteredInfo[DB_TOTALS_USERS_ONLINE], dbRegisteredInfo[DB_TOTALS_USERS_ACTIVATED] );
		httpPrintf( cnt, "<time><next>%d</next><week>%d</week><year>%d</year></time>", (int)fmax( 0.0, ( ticks.next - time(0) ) ), ticks.number % 52, ticks.number / 52 );
		if( !strcmp(refer,"status") ) {
			snprintf( CHECKER, sizeof(CHECKER), "%lu bytes ( %5.1f mb )", pinfod.stvsize, pinfod.stvsize  / megabyte );
			httpString( cnt, "<general>" );
			httpPrintf( cnt, "<servpriority>%ld</servpriority>", pinfod.stpriority );
			httpPrintf( cnt, "<servthreads>%ld</servthreads>", pinfod.threads );
			httpString( cnt, "</general>" );
			httpString( cnt, "<memory>" );
			httpPrintf( cnt, "<memused>%s</memused>", CHECKER );
			httpPrintf( cnt, "<memavbytes>%ld bytes</memavbytes>", sysinfod.freeram );
			httpPrintf( cnt, "<memavmeg>( %4.1f mb )</memavmeg>", (sysinfod.freeram  / megabyte ) );


			httpPrintf( cnt, "<totalswapbytes>%ld bytes</totalswapbytes>", sysinfod.totalswap );
			httpPrintf( cnt, "<totalswapmeg>( %5.1f mb )</totalswapmeg>", (sysinfod.totalswap / megabyte ) );

			httpPrintf( cnt, "<freeswapbytes>%ld bytes</freeswapbytes>", sysinfod.freeswap );
			httpPrintf( cnt, "<freeswapmeg>( %5.1f mb )</freeswapmeg>", (sysinfod.freeswap  / megabyte ) );

			httpPrintf( cnt, "<bufferbytes>%ld bytes</bufferbytes>", sysinfod.bufferram );
			httpPrintf( cnt, "<bufermeg>( %5.1f mb )</bufermeg>", (sysinfod.bufferram  / megabyte ) );

			httpPrintf( cnt, "<sharedbytes>%ld bytes</sharedbytes>", sysinfod.sharedram );
			httpPrintf( cnt, "<sharedmeg>( %5.1f mb )</sharedmeg>", (sysinfod.sharedram  / megabyte ) );

			time( &tint );
			strftime(timebuf,512,"%a, %d %b %G %T %Z", localtime( &tint ) );
			httpPrintf( cnt, "<timeserver>%s</timeserver>", timebuf );
			strftime(timebuf,512,"%a, %d %b %G %T %Z", gmtime( &tint ) );
			httpPrintf( cnt, "<timegmt>%s</timegmt>", timebuf );
			
			httpPrintf( cnt, "<strss>%lu pages</strss>", pinfod.strss );
			httpPrintf( cnt, "</memory>" );
			httpString( cnt, "<cpu>" );
			httpPrintf( cnt, "<cpuprocs>%d</cpuprocs>", sysinfod.procs );
			httpPrintf( cnt, "<cpuloads>%f (1 min) - %f (5 mins) - %f (15 mins)</cpuloads>",pinfod.loadavg[0],pinfod.loadavg[1],pinfod.loadavg[2]);
			httpPrintf( cnt, "<cputotal>%.3f %%</cputotal>", pinfod.userload + pinfod.kernelload );
			httpPrintf( cnt, "<cpukernel>%.3f %%</cpukernel>", pinfod.kernelload );
			httpPrintf( cnt, "<cpuuser>%.3f %%</cpuuser>", pinfod.userload );
			httpString( cnt, "</cpu>" );
			
			#if IRCBOT_SUPPORT
			if( sysconfig.irc_enabled ) {
				if( irc_is_connected(sysconfig.irc_session) ) {
					settings[0] = GetSetting( "IRC Host" );
					settings[1] = GetSetting( "IRC Channel" );
					snprintf( CHECKER, sizeof(CHECKER), "Enabled (Host:%s, Channel:%s)", settings[0]->string_value, settings[1]->string_value );
				} else {
					snprintf( CHECKER, sizeof(CHECKER), "%s", "Enabled but not connected" );
				}
			} else {
				snprintf( CHECKER, sizeof(CHECKER), "%s", "Disabled");
			}
			httpPrintf( cnt, "<botstatus>%s</botstatus>", CHECKER );
			#endif

		//End Status block -- Start user block
		}
		if( id < 0 )
			goto ENDXML;
		a = dbUserNewsGetFlags( id );
		//OK, so they are loged in... time to send some info. Lets start with the header. =)
		httpString( cnt, "<header>" );
		httpPrintf( cnt, "<networth>%lld</networth>", (long long)maind.networth );
		httpString( cnt, "<notification>" );
		httpPrintf( cnt, "<mail>%d</mail>",  ( a & CMD_NEWS_FLAGS_MAIL ) ? true : false );
		httpPrintf( cnt, "<build>%d</build>",  ( a & CMD_NEWS_FLAGS_BUILD ) ? true : false );
		httpPrintf( cnt, "<aid>%d</aid>", ( a & CMD_NEWS_FLAGS_AID ) ? true : false );
		httpPrintf( cnt, "<fleet>%d</fleet>", ( a & CMD_NEWS_FLAGS_ATTACK ) ? 1 : ( ( a & CMD_NEWS_FLAGS_FLEET ) ? 2 : false ) );
		httpString( cnt, "</notification>" );
		httpString( cnt, "<ressources>" );
		for( a = 0 ; a < CMD_RESSOURCE_NUMUSED ; a++ ) {
			snprintf( CHECKER, sizeof(CHECKER),"%s",cmdRessourceName[a]);
			for(b = 0; CHECKER[b]; b++){
				CHECKER[b] = tolower(CHECKER[b]);
			}
			httpPrintf( cnt, "<%s>%lld</%s>", CHECKER, (long long)maind.ressource[a], CHECKER );
		}
		httpPrintf( cnt, "<population>%lld</population>", (long long)maind.ressource[CMD_RESSOURCE_POPULATION] );
		httpString( cnt, "</ressources>" );
		httpString( cnt, "</header>" );
		httpPrintf( cnt, "<%s>", refer );
		//End Header block -- Start HQ block
		if( !strcmp(refer,"hq") ) {
			httpString( cnt, "<readiness>" );
			for( a = 0 ; a < CMD_READY_NUMUSED ; a++ ) {
				httpPrintf( cnt, "<%sready>%d</%sready>", cmdReadyName[a], maind.readiness[a] >> 16, cmdReadyName[a] );
			}
			httpString( cnt, "</readiness>" );
		httpPrintf( cnt, "<planets>%d</planets>", maind.planets );
		//End HQ block -- Start Council block
		} else if( !strcmp(refer,"council") ) {
Example #4
0
/*! \fn GetValue

	Returns a Setting based on the name passed to the function.
	Returns -1 if the setting is not in the list

	\param Name The name of the setting to search for
*/
long _EngineSettings::GetValue(string Name) {
	return GetSetting(Name).Value;
}
Example #5
0
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
void EffectImplemented::Reset()
{
	UnloadResources();

	Setting* loader = GetSetting();

	TextureLoader* textureLoader = loader->GetTextureLoader();

	for( int i = 0; i < m_ImageCount; i++ )
	{
		if( m_ImagePaths[i] != NULL ) delete [] m_ImagePaths[i];
	}

	m_ImageCount = 0;

	ES_SAFE_DELETE_ARRAY( m_ImagePaths );
	ES_SAFE_DELETE_ARRAY(m_pImages);

	{
		for (int i = 0; i < m_normalImageCount; i++)
		{
			if (m_normalImagePaths[i] != NULL) delete [] m_normalImagePaths[i];
		}

		m_normalImageCount = 0;

		ES_SAFE_DELETE_ARRAY(m_normalImagePaths);
		ES_SAFE_DELETE_ARRAY(m_normalImages);
	}

	{
		for (int i = 0; i < m_distortionImageCount; i++)
		{
			if (m_distortionImagePaths[i] != NULL) delete [] m_distortionImagePaths[i];
		}

		m_distortionImageCount = 0;

		ES_SAFE_DELETE_ARRAY(m_distortionImagePaths);
		ES_SAFE_DELETE_ARRAY(m_distortionImages);
	}

	for( int i = 0; i < m_WaveCount; i++ )
	{
		if( m_WavePaths[i] != NULL ) delete [] m_WavePaths[i];
	}
	m_WaveCount = 0;

	ES_SAFE_DELETE_ARRAY( m_WavePaths );
	ES_SAFE_DELETE_ARRAY( m_pWaves );

	for( int i = 0; i < m_modelCount; i++ )
	{
		if( m_modelPaths[i] != NULL ) delete [] m_modelPaths[i];
	}
	m_modelCount = 0;

	ES_SAFE_DELETE_ARRAY( m_modelPaths );
	ES_SAFE_DELETE_ARRAY( m_pModels );

	ES_SAFE_DELETE( m_pRoot );
}
Example #6
0
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
void EffectImplemented::ReloadResources( const EFK_CHAR* materialPath )
{
	UnloadResources();

	const EFK_CHAR* matPath = materialPath != NULL ? materialPath : m_materialPath.c_str();
	
	Setting* loader = GetSetting();

	{
		TextureLoader* textureLoader = loader->GetTextureLoader();
		if( textureLoader != NULL )
		{
			for( int32_t ind = 0; ind < m_ImageCount; ind++ )
			{
				EFK_CHAR fullPath[512];
				PathCombine( fullPath, matPath, m_ImagePaths[ ind ] );
				m_pImages[ind] = textureLoader->Load( fullPath, TextureType::Color );
			}
		}
	}

	{
		TextureLoader* textureLoader = loader->GetTextureLoader();
		if (textureLoader != NULL)
		{
			for (int32_t ind = 0; ind < m_normalImageCount; ind++)
			{
				EFK_CHAR fullPath[512];
				PathCombine(fullPath, matPath, m_normalImagePaths[ind]);
				m_normalImages[ind] = textureLoader->Load(fullPath, TextureType::Normal);
			}
		}

	}
		{
			TextureLoader* textureLoader = loader->GetTextureLoader();
			if (textureLoader != NULL)
			{
				for (int32_t ind = 0; ind < m_distortionImageCount; ind++)
				{
					EFK_CHAR fullPath[512];
					PathCombine(fullPath, matPath, m_distortionImagePaths[ind]);
					m_distortionImages[ind] = textureLoader->Load(fullPath, TextureType::Distortion);
				}
			}
		}

	

	{
		SoundLoader* soundLoader = loader->GetSoundLoader();
		if( soundLoader != NULL )
		{
			for( int32_t ind = 0; ind < m_WaveCount; ind++ )
			{
				EFK_CHAR fullPath[512];
				PathCombine( fullPath, matPath, m_WavePaths[ ind ] );
				m_pWaves[ind] = soundLoader->Load( fullPath );
			}
		}
	}

	{
		ModelLoader* modelLoader = loader->GetModelLoader();
		
		if( modelLoader != NULL )
		{
			for( int32_t ind = 0; ind < m_modelCount; ind++ )
			{
				EFK_CHAR fullPath[512];
				PathCombine( fullPath, matPath, m_modelPaths[ ind ] );
				m_pModels[ind] = modelLoader->Load( fullPath );
			}
		}
	}
}
Example #7
0
void CMainDlg::InitGen()
{
	float pit;
	AmpValue amp;
	FrqValue frq;
	FrqValue atk;
	FrqValue dec;
	AmpValue sus;
	FrqValue rel;
	AmpValue end;
	FrqValue mul1, mul2;
	AmpValue pk;
	FrqValue nyq = synthParams.sampleRate / 2;
	
	durTotal = GetSetting(durValEd);
	volMaster = GetSetting(volValEd);
	
	pit = GetSetting(gen1FrqEd);
	frq = synthParams.GetFrequency(pit);
	if (frq >= nyq)
		frq = nyq;

	amp = GetSetting(gen1VolEd);
	atk = GetSetting(gen1AtkEd);
	dec = GetSetting(gen1DecEd);
	sus = GetSetting(gen1SusEd);
	rel = GetSetting(gen1RelEd);
	gen1EG.InitADSR(0, atk, amp, dec, sus, rel, 0, linSeg);
	gen1Osc.InitWT(frq, WT_SIN);
	if (durTotal < (rel+atk))
	{
		durTotal = atk + rel;
		durAtkSus = atk;
	}
	else
		durAtkSus = durTotal - rel;

	mul1 = GetSetting(gen2MulEd) * frq;
	amp = GetSetting(gen2NdxEd);
	atk = GetSetting(gen2AtkEd);
	pk  = GetSetting(gen2PckEd);
	dec = GetSetting(gen2DecEd);
	sus = GetSetting(gen2SusEd);
	rel = GetSetting(gen2RelEd);
	end = GetSetting(gen2EndEd);

	if (mul1 > nyq)
		mul1 = nyq;
	gen2Osc.InitWT(mul1, WT_SIN);
	if (algorithm != ALG_DELTA)
	{
		amp = CalcPhaseMod(amp, mul1);
		pk  = CalcPhaseMod(pk, mul1);
		sus = CalcPhaseMod(sus, mul1);
		end = CalcPhaseMod(end, mul1);
	}
	gen2EG.InitADSR(amp, atk, pk, dec, sus, rel, end, linSeg); 

	mul2 = GetSetting(gen3MulEd) * frq;
	amp = GetSetting(gen3NdxEd);
	atk = GetSetting(gen3AtkEd);
	pk  = GetSetting(gen3PckEd);
	dec = GetSetting(gen3DecEd);
	sus = GetSetting(gen3SusEd);
	rel = GetSetting(gen3RelEd);
	end = GetSetting(gen3EndEd);

	if (mul2 > nyq)
		mul2 = nyq;
	gen3Osc.InitWT(mul2, WT_SIN);
	amp = CalcPhaseMod(amp, mul2);
	pk  = CalcPhaseMod(pk, mul2);
	sus = CalcPhaseMod(sus, mul2);
	end = CalcPhaseMod(end, mul2);
	gen3EG.InitADSR(amp, atk, pk, dec, sus, rel, end, linSeg);
}
Example #8
0
void MythSystemWindows::Fork(time_t timeout)
{
    QString LOC_ERR = QString("myth_system('%1'): Error: ").arg(GetLogCmd());

    // For use in the child
    char locerr[MAX_BUFLEN];
    strncpy(locerr, (const char *)LOC_ERR.toUtf8().constData(), MAX_BUFLEN);
    locerr[MAX_BUFLEN-1] = '\0';

    LOG(VB_SYSTEM, LOG_DEBUG, QString("Launching: %1").arg(GetLogCmd()));

    GetBuffer(0)->setBuffer(0);
    GetBuffer(1)->setBuffer(0);
    GetBuffer(2)->setBuffer(0);

    HANDLE p_stdin[2] = { NULL, NULL };
    HANDLE p_stdout[2] = { NULL, NULL };
    HANDLE p_stderr[2] = { NULL, NULL };

    SECURITY_ATTRIBUTES saAttr; 
    STARTUPINFO si;

    ZeroMemory(&si, sizeof(STARTUPINFO));
    si.cb = sizeof(STARTUPINFO);
        
    // Set the bInheritHandle flag so pipe handles are inherited. 
    saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); 
    saAttr.bInheritHandle = true; 
    saAttr.lpSecurityDescriptor = NULL; 

    /* set up pipes */
    if( GetSetting("UseStdin") )
    {
        if (!CreatePipe(&p_stdin[0], &p_stdin[1], &saAttr, 0)) 
        {
            LOG(VB_GENERAL, LOG_ERR, LOC_ERR + "stdin pipe() failed");
            SetStatus( GENERIC_EXIT_NOT_OK );
        }
        else
        {
            // Ensure the write handle to the pipe for STDIN is not inherited. 
            if (!SetHandleInformation(p_stdin[1], HANDLE_FLAG_INHERIT, 0))
            {
                LOG(VB_SYSTEM, LOG_ERR, LOC_ERR + "stdin inheritance error");
                SetStatus( GENERIC_EXIT_NOT_OK );
            }
            else
            {
                si.hStdInput = p_stdin[0];
                si.dwFlags |= STARTF_USESTDHANDLES;
            }
        }
    }

    if( GetSetting("UseStdout") )
    {
        if (!CreatePipe(&p_stdout[0], &p_stdout[1], &saAttr, 0)) 
        {
            LOG(VB_SYSTEM, LOG_ERR, LOC_ERR + "stdout pipe() failed");
            SetStatus( GENERIC_EXIT_NOT_OK );
        }
        else
        {
            // Ensure the read handle to the pipe for STDOUT is not inherited.
            if (!SetHandleInformation(p_stdout[0], HANDLE_FLAG_INHERIT, 0))
            {
                LOG(VB_SYSTEM, LOG_ERR, LOC_ERR + "stdout inheritance error");
                SetStatus( GENERIC_EXIT_NOT_OK );
            }
            else
            {
                si.hStdOutput = p_stdout[1];
                si.dwFlags |= STARTF_USESTDHANDLES;
            }
        }
    }

    if( GetSetting("UseStderr") )
    {
        if (!CreatePipe(&p_stderr[0], &p_stderr[1], &saAttr, 0)) 
        {
            LOG(VB_SYSTEM, LOG_ERR, LOC_ERR + "stderr pipe() failed");
            SetStatus( GENERIC_EXIT_NOT_OK );
        }
        else
        {
            // Ensure the read handle to the pipe for STDERR is not inherited.
            if (!SetHandleInformation(p_stderr[0], HANDLE_FLAG_INHERIT, 0))
            {
                LOG(VB_SYSTEM, LOG_ERR, LOC_ERR + "stderr inheritance error");
                SetStatus( GENERIC_EXIT_NOT_OK );
            }
            else
            {
                si.hStdError = p_stderr[1];
                si.dwFlags |= STARTF_USESTDHANDLES;
            }
        }
    }

    // set up command args
    QString cmd = GetCommand().replace('/','\\') + " " + GetArgs().join(" ");
    if (GetSetting("UseShell"))
        cmd.prepend("cmd.exe /c ");

    SetCommand( cmd );

    QByteArray cmdUTF8 = GetCommand().toUtf8();
    TCHAR *command = TEXT((char *)cmdUTF8.constData());

    const char *directory = NULL;
    QString dir = GetDirectory();
    if (GetSetting("SetDirectory") && !dir.isEmpty())
        directory = strdup(dir.toUtf8().constData());

    PROCESS_INFORMATION pi;
    ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));

    m_timeout = timeout;
    if( timeout )
        m_timeout += time(NULL);

    bool success = CreateProcess(NULL, 
                    command,       // command line 
                    NULL,          // process security attributes 
                    NULL,          // primary thread security attributes 
                    TRUE,          // handles are inherited 
                    0,             // creation flags 
                    NULL,          // use parent's environment 
                    directory,     // use parent's current directory 
                   &si,            // STARTUPINFO pointer 
                   &pi);           // receives PROCESS_INFORMATION 

    if (!success)
    {
        LOG(VB_SYSTEM, LOG_ERR, LOC_ERR + "CreateProcess() failed");
        SetStatus( GENERIC_EXIT_NOT_OK );
    }
    else
    {
        /* parent */
        m_child = pi.hProcess;
        SetStatus( GENERIC_EXIT_RUNNING );

        LOG(VB_SYSTEM, LOG_INFO,
                QString("Managed child (Handle: %1) has started! "
                        "%2%3 command=%4, timeout=%5")
                    .arg((long long)m_child) 
                    .arg(GetSetting("UseShell") ? "*" : "")
                    .arg(GetSetting("RunInBackground") ? "&" : "")
                    .arg(GetLogCmd()) .arg(timeout));

        /* close unused pipe ends */
        CLOSE(p_stdin[0]);
        CLOSE(p_stdout[1]);
        CLOSE(p_stderr[1]);

        // store the rest
        m_stdpipe[0] = p_stdin[1];
        m_stdpipe[1] = p_stdout[0];
        m_stdpipe[2] = p_stderr[0];

        // clean up the memory use
        if( directory )
            free((void *)directory);
    }

    /* Parent */
    if( GetStatus() != GENERIC_EXIT_RUNNING )
    {
        CLOSE(p_stdin[0]);
        CLOSE(p_stdin[1]);
        CLOSE(p_stdout[0]);
        CLOSE(p_stdout[1]);
        CLOSE(p_stderr[0]);
        CLOSE(p_stderr[1]);
    }
}
Example #9
0
CGUIControl* CGUIDialogSettingsBase::AddSetting(CSetting *pSetting, float width, int &iControlID)
{
  if (pSetting == NULL)
    return NULL;

  BaseSettingControlPtr pSettingControl;
  CGUIControl *pControl = NULL;

  // determine the label and any possible indentation in case of sub settings
  std::string label = GetSettingsLabel(pSetting);
  int parentLevels = 0;
  CSetting *parentSetting = GetSetting(pSetting->GetParent());
  while (parentSetting != NULL)
  {
    parentLevels++;
    parentSetting = GetSetting(parentSetting->GetParent());
  }

  if (parentLevels > 0)
  {
    // add additional 2 spaces indentation for anything past one level
    std::string indentation;
    for (int index = 1; index < parentLevels; index++)
      indentation.append("  ");
    label = StringUtils::Format(g_localizeStrings.Get(168).c_str(), indentation.c_str(), label.c_str());
  }

  // create the proper controls
  if (!pSetting->GetControl())
    return NULL;

  std::string controlType = pSetting->GetControl()->GetType();
  if (controlType == "toggle")
  {
    if (m_pOriginalRadioButton != NULL)
      pControl = new CGUIRadioButtonControl(*m_pOriginalRadioButton);
    if (pControl == NULL)
      return NULL;

    ((CGUIRadioButtonControl *)pControl)->SetLabel(label);
    pSettingControl.reset(new CGUIControlRadioButtonSetting((CGUIRadioButtonControl *)pControl, iControlID, pSetting));
  }
  else if (controlType == "spinner")
  {
    if (m_pOriginalSpin != NULL)
      pControl = new CGUISpinControlEx(*m_pOriginalSpin);
    if (pControl == NULL)
      return NULL;

    ((CGUISpinControlEx *)pControl)->SetText(label);
    pSettingControl.reset(new CGUIControlSpinExSetting((CGUISpinControlEx *)pControl, iControlID, pSetting));
  }
  else if (controlType == "edit")
  {
    if (m_pOriginalEdit != NULL)
      pControl = new CGUIEditControl(*m_pOriginalEdit);
    if (pControl == NULL)
      return NULL;
      
    ((CGUIEditControl *)pControl)->SetLabel(label);
    pSettingControl.reset(new CGUIControlEditSetting((CGUIEditControl *)pControl, iControlID, pSetting));
  }
  else if (controlType == "list")
  {
    if (m_pOriginalButton != NULL)
      pControl = new CGUIButtonControl(*m_pOriginalButton);
    if (pControl == NULL)
      return NULL;

    ((CGUIButtonControl *)pControl)->SetLabel(label);
    pSettingControl.reset(new CGUIControlListSetting((CGUIButtonControl *)pControl, iControlID, pSetting));
  }
  else if (controlType == "button" || controlType == "slider")
  {
    if (controlType == "button" ||
        static_cast<const CSettingControlSlider*>(pSetting->GetControl())->UsePopup())
    {
      if (m_pOriginalButton != NULL)
        pControl = new CGUIButtonControl(*m_pOriginalButton);
      if (pControl == NULL)
        return NULL;
      
      ((CGUIButtonControl *)pControl)->SetLabel(label);
      pSettingControl.reset(new CGUIControlButtonSetting((CGUIButtonControl *)pControl, iControlID, pSetting));
    }
    else
    {
      if (m_pOriginalSlider != NULL)
        pControl = new CGUISettingsSliderControl(*m_pOriginalSlider);
      if (pControl == NULL)
        return NULL;
      
      ((CGUISettingsSliderControl *)pControl)->SetText(label);
      pSettingControl.reset(new CGUIControlSliderSetting((CGUISettingsSliderControl *)pControl, iControlID, pSetting));
    }
  }
  else if (controlType == "range")
  {
    if (m_pOriginalSlider != NULL)
      pControl = new CGUISettingsSliderControl(*m_pOriginalSlider);
    if (pControl == NULL)
      return NULL;

    ((CGUISettingsSliderControl *)pControl)->SetText(label);
    pSettingControl.reset(new CGUIControlRangeSetting((CGUISettingsSliderControl *)pControl, iControlID, pSetting));
  }
  else
    return NULL;

  if (pSetting->GetControl()->GetDelayed())
    pSettingControl->SetDelayed();

  return AddSettingControl(pControl, pSettingControl, width, iControlID);
}
Example #10
0
LRESULT CMainDlg::OnCopyClip(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	OpenClipboard();
	EmptyClipboard();

	FrqValue atk = GetSetting(gen1AtkEd);
	AmpValue pk  = GetSetting(gen1VolEd);
	FrqValue dec = GetSetting(gen1DecEd);
	AmpValue sus = GetSetting(gen1SusEd);
	FrqValue rel = GetSetting(gen1RelEd);

	FrqValue mul1 = GetSetting(gen2MulEd);
	AmpValue amp1 = GetSetting(gen2NdxEd);
	FrqValue atk1 = GetSetting(gen2AtkEd);
	AmpValue pk1  = GetSetting(gen2PckEd);
	FrqValue dec1 = GetSetting(gen2DecEd);
	AmpValue sus1 = GetSetting(gen2SusEd);
	FrqValue rel1 = GetSetting(gen2RelEd);
	AmpValue end1 = GetSetting(gen2EndEd);

	FrqValue mul2 = GetSetting(gen3MulEd);
	AmpValue amp2 = GetSetting(gen3NdxEd);
	FrqValue atk2 = GetSetting(gen3AtkEd);
	AmpValue pk2  = GetSetting(gen3PckEd);
	FrqValue dec2 = GetSetting(gen3DecEd);
	AmpValue sus2 = GetSetting(gen3SusEd);
	FrqValue rel2 = GetSetting(gen3RelEd);
	AmpValue end2 = GetSetting(gen3EndEd);

	char txt[1024];
	sprintf(txt, "{ %4d, %6.3f, %6.3f, %6.3f, %6.3f, %6.3f, %6.3f, %6.3f,\r\n%6.3f, %6.3f, %6.3f, %6.3f, %6.3f, %6.3f, %6.3f, %6.3f,\r\n%6.3f, %6.3f, %6.3f, %6.3f, %6.3f, %6.3f, %6.3f, %6.3f },\r\n",
		algorithm, 0.0, atk, pk, dec, sus, rel, 0.0,
		mul1, amp1, atk1, pk1, dec1, sus1, rel1, end1,
		mul2, amp2, atk2, pk2, dec2, sus2, rel2, end2);

	HANDLE mem = GlobalAlloc(0, strlen(txt)+1);
	char *ptxt = (char*)GlobalLock(mem);
	strcpy(ptxt, txt);
	GlobalUnlock(mem);

	SetClipboardData(CF_TEXT, mem);
	CloseClipboard();
	return 0;
}
Example #11
0
HRESULT CSWDomeCameraTimer::SaveSetting(const DWORD& dwID)
{
	CHECK_ID(dwID, MAX_TIMER);
	
	char szSection[256];
    swpa_sprintf(szSection, "\\DomeCamera\\Timer\\Timer%d", dwID);

	//SW_TRACE_DEBUG("tobemarked: save timer %d : MotionType=%d, MotionID=%d\n", dwID, GetSetting().Get().sTimerParam[dwID].iMotionType,
	//	GetSetting().Get().sTimerParam[dwID].iMotionID);

	GetSetting().UpdateString(szSection, "Name", GetSetting().Get().sTimerParam[dwID].szName);
	GetSetting().UpdateInt(szSection, "BeginTime", GetSetting().Get().sTimerParam[dwID].iBeginTime);
	GetSetting().UpdateInt(szSection, "EndTime", GetSetting().Get().sTimerParam[dwID].iEndTime);
	GetSetting().UpdateInt(szSection, "Weekday", GetSetting().Get().sTimerParam[dwID].iWeekday);
	GetSetting().UpdateInt(szSection, "MotionType", GetSetting().Get().sTimerParam[dwID].iMotionType);
	GetSetting().UpdateInt(szSection, "MotionID", GetSetting().Get().sTimerParam[dwID].iMotionID);
	GetSetting().UpdateInt(szSection, "Enable", GetSetting().Get().sTimerParam[dwID].fEnable);
	GetSetting().UpdateInt(szSection, "Valid", GetSetting().Get().sTimerParam[dwID].fValid);
	
	return GetSetting().Commit();
}
Example #12
0
bool CSettings::Exists(CString strSetting)
{
	return (GetSetting(strSetting) != NULL);
}
Example #13
0
void MythSystemUnix::Fork(time_t timeout)
{
    QString LOC_ERR = QString("myth_system('%1'): Error: ").arg(GetLogCmd());

    // For use in the child
    char locerr[MAX_BUFLEN];
    strncpy(locerr, (const char *)LOC_ERR.toUtf8().constData(), MAX_BUFLEN);
    locerr[MAX_BUFLEN-1] = '\0';

    LOG(VB_SYSTEM, LOG_DEBUG, QString("Launching: %1").arg(GetLogCmd()));

    GetBuffer(0)->setBuffer(0);
    GetBuffer(1)->setBuffer(0);
    GetBuffer(2)->setBuffer(0);

    int p_stdin[]  = {-1,-1};
    int p_stdout[] = {-1,-1};
    int p_stderr[] = {-1,-1};

    /* set up pipes */
    if( GetSetting("UseStdin") )
    {
        if( pipe(p_stdin) == -1 )
        {
            LOG(VB_SYSTEM, LOG_ERR, LOC_ERR + "stdin pipe() failed");
            SetStatus( GENERIC_EXIT_NOT_OK );
        }
        else
            fcntl(p_stdin[1], F_SETFL, O_NONBLOCK);
    }
    if( GetSetting("UseStdout") )
    {
        if( pipe(p_stdout) == -1 )
        {
            LOG(VB_SYSTEM, LOG_ERR, LOC_ERR + "stdout pipe() failed");
            SetStatus( GENERIC_EXIT_NOT_OK );
        }
        else
            fcntl(p_stdout[0], F_SETFL, O_NONBLOCK);
    }
    if( GetSetting("UseStderr") )
    {
        if( pipe(p_stderr) == -1 )
        {
            LOG(VB_SYSTEM, LOG_ERR, LOC_ERR + "stderr pipe() failed");
            SetStatus( GENERIC_EXIT_NOT_OK );
        }
        else
            fcntl(p_stderr[0], F_SETFL, O_NONBLOCK);
    }

    // set up command args
    if (GetSetting("UseShell"))
    {
        QStringList args = QStringList("-c");
        args << GetCommand() + " " + GetArgs().join(" ");
        SetArgs( args );
        QString cmd = "/bin/sh";
        SetCommand( cmd );
    }
    QStringList args = GetArgs();
    args.prepend(GetCommand().split('/').last());
    SetArgs( args );

    QByteArray cmdUTF8 = GetCommand().toUtf8();
    const char *command = strdup(cmdUTF8.constData());

    char **cmdargs = (char **)malloc((args.size() + 1) * sizeof(char *));
    int i;
    QStringList::const_iterator it;

    for (i = 0, it = args.constBegin(); it != args.constEnd(); ++it)
    {
        cmdargs[i++] = strdup(it->toUtf8().constData());
    }
    cmdargs[i] = NULL;

    const char *directory = NULL;
    QString dir = GetDirectory();
    if (GetSetting("SetDirectory") && !dir.isEmpty())
        directory = strdup(dir.toUtf8().constData());

    // check before fork to avoid QString use in child
    bool setpgidsetting = GetSetting("SetPGID");

    int niceval = m_parent->GetNice();
    int ioprioval = m_parent->GetIOPrio();

    /* Do this before forking in case the child miserably fails */
    m_timeout = timeout;
    if( timeout )
        m_timeout += time(NULL);

    pid_t child = fork();

    if (child < 0)
    {
        /* Fork failed, still in parent */
        LOG(VB_SYSTEM, LOG_ERR, "fork() failed: " + ENO);
        SetStatus( GENERIC_EXIT_NOT_OK );
    }
    else if( child > 0 )
    {
        /* parent */
        m_pid = child;
        SetStatus( GENERIC_EXIT_RUNNING );

        LOG(VB_SYSTEM, LOG_INFO,
                    QString("Managed child (PID: %1) has started! "
                            "%2%3 command=%4, timeout=%5")
                        .arg(m_pid) .arg(GetSetting("UseShell") ? "*" : "")
                        .arg(GetSetting("RunInBackground") ? "&" : "")
                        .arg(GetLogCmd()) .arg(timeout));

        /* close unused pipe ends */
        CLOSE(p_stdin[0]);
        CLOSE(p_stdout[1]);
        CLOSE(p_stderr[1]);

        // store the rest
        m_stdpipe[0] = p_stdin[1];
        m_stdpipe[1] = p_stdout[0];
        m_stdpipe[2] = p_stderr[0];
    }
    else if (child == 0)
    {
        /* Child - NOTE: it is not safe to use LOG or QString between the 
         * fork and execv calls in the child.  It causes occasional locking 
         * issues that cause deadlocked child processes. */

        /* handle standard input */
        if( p_stdin[0] >= 0 )
        {
            /* try to attach stdin to input pipe - failure is fatal */
            if( dup2(p_stdin[0], 0) < 0 )
            {
                cerr << locerr
                     << "Cannot redirect input pipe to standard input: "
                     << strerror(errno) << endl;
                _exit(GENERIC_EXIT_PIPE_FAILURE);
            }
        }
        else
        {
            /* try to attach stdin to /dev/null */
            int fd = open("/dev/null", O_RDONLY);
            if( fd >= 0 )
            {
                if( dup2(fd, 0) < 0)
                {
                    cerr << locerr
                         << "Cannot redirect /dev/null to standard input,"
                            "\n\t\t\tfailed to duplicate file descriptor: " 
                         << strerror(errno) << endl;
                }
            }
            else
            {
                cerr << locerr
                     << "Cannot redirect /dev/null to standard input, "
                        "failed to open: "
                     << strerror(errno) << endl;
            }
        }

        /* handle standard output */
        if( p_stdout[1] >= 0 )
        {
            /* try to attach stdout to output pipe - failure is fatal */
            if( dup2(p_stdout[1], 1) < 0)
            {
                cerr << locerr
                     << "Cannot redirect output pipe to standard output: "
                     << strerror(errno) << endl;
                _exit(GENERIC_EXIT_PIPE_FAILURE);
            }
        }

        /* handle standard err */
        if( p_stderr[1] >= 0 )
        {
            /* try to attach stderr to error pipe - failure is fatal */
            if( dup2(p_stderr[1], 2) < 0)
            {
                cerr << locerr
                     << "Cannot redirect error pipe to standard error: " 
                     << strerror(errno) << endl;
                _exit(GENERIC_EXIT_PIPE_FAILURE);
            }
        }

        /* Close all open file descriptors except stdin/stdout/stderr */
        for( int i = sysconf(_SC_OPEN_MAX) - 1; i > 2; i-- )
            close(i);

        /* set directory */
        if( directory && chdir(directory) < 0 )
        {
            cerr << locerr
                 << "chdir() failed: "
                 << strerror(errno) << endl;
        }

        /* Set the process group id to be the same as the pid of this child
         * process.  This ensures that any subprocesses launched by this
         * process can be killed along with the process itself. */ 
        if (setpgidsetting && setpgid(0,0) < 0 ) 
        {
            cerr << locerr
                 << "setpgid() failed: "
                 << strerror(errno) << endl;
        }

        /* Set nice and ioprio values if non-default */
        if (niceval)
            myth_nice(niceval);
        if (ioprioval)
            myth_ioprio(ioprioval);

        /* run command */
        if( execv(command, cmdargs) < 0 )
        {
            // Can't use LOG due to locking fun.
            cerr << locerr
                 << "execv() failed: "
                 << strerror(errno) << endl;
        }

        /* Failed to exec */
        _exit(GENERIC_EXIT_DAEMONIZING_ERROR); // this exit is ok
    }

    /* Parent */

    // clean up the memory use
    if( command )
        free((void *)command);

    if( directory )
        free((void *)directory);

    if( cmdargs )
    {
        for (i = 0; cmdargs[i]; i++)
            free( cmdargs[i] );
        free( cmdargs );
    }

    if( GetStatus() != GENERIC_EXIT_RUNNING )
    {
        CLOSE(p_stdin[0]);
        CLOSE(p_stdin[1]);
        CLOSE(p_stdout[0]);
        CLOSE(p_stdout[1]);
        CLOSE(p_stderr[0]);
        CLOSE(p_stderr[1]);
    }
}
Example #14
0
// get current TV Standard settings
status_t
GetTVStandard(BScreen *screen, uint32 *standard)
{
	return GetSetting(screen, ms_tv_standard, standard);
}
Example #15
0
void event_channel (irc_session_t * irc_session, const char * event, const char * origin, const char ** params, unsigned int count) {
	char buffer[512];
	char nickbuf[128];
	char md5sum[MD5_HASHSUM_SIZE];
	ConfigArrayPtr setting;
	SessionPtr session;

if ( count != 2 )
	return;

params[1] = irc_color_strip_from_mirc( params[1] );
addlog ("'%s' said in channel %s: %s", origin ? origin : "someone", params[0], params[1] );

if ( !origin )
	return;

irc_target_get_nick( origin, nickbuf, sizeof(nickbuf) );

md5_string( origin, md5sum );
session = get_session( SESSION_IRC, md5sum );


if ( !strcmp (params[1], "help") ) {
	if( ( session->dbuser ) && ( session->dbuser->level >= LEVEL_MODERATOR ) )
		snprintf(buffer, sizeof(buffer), "%s", irc_color_convert_to_mirc( "[B]Usage[/B] - quit, help, dcc send, topic, mode, whois, nick" ) );
	else
		snprintf(buffer, sizeof(buffer), "%s", irc_color_convert_to_mirc( "[B]Usage[/B] - help, dcc send, login" ) );
	irc_cmd_notice( irc_session, params[0], buffer );
}

if ( !strcmp (params[1], "ctcp") ) {
	irc_cmd_ctcp_request (irc_session, nickbuf, "PING 223");
	irc_cmd_ctcp_request (irc_session, nickbuf, "FINGER");
	irc_cmd_ctcp_request (irc_session, nickbuf, "VERSION");
	irc_cmd_ctcp_request (irc_session, nickbuf, "TIME");
}

if ( !strcmp (params[1], "dcc chat") ) {
		irc_dcc_t dccid;
	
	irc_dcc_chat (irc_session, 0, nickbuf, dcc_recv_callback, &dccid);
	addlog ("DCC chat ID: %d", dccid);
}

if ( !strcmp (params[1], "dcc send") ) {
		irc_dcc_t dccid;
	setting = GetSetting( "HTTP Images" );
	snprintf(buffer, sizeof(buffer), "%s/cookie.gif", setting->string_value );
	irc_dcc_sendfile (irc_session, 0, nickbuf, buffer, dcc_file_send_callback, &dccid);
	addlog ("DCC send ID: %d", dccid);
}


if( ( session->dbuser ) && ( session->dbuser->level >= LEVEL_MODERATOR ) ) {

if ( !strcmp (params[1], "quit") ) {
		irc_cmd_quit (irc_session, "of course, Master!");
}

if ( !strcmp (params[1], "topic") ) {
	irc_cmd_topic (irc_session, params[0], 0);
} else if ( strstr (params[1], "topic ") == params[1] ) {
	irc_cmd_topic (irc_session, params[0], params[1] + 6);
}

if ( strstr (params[1], "mode ") == params[1] )
	irc_cmd_channel_mode (irc_session, params[0], params[1] + 5);

if ( strstr (params[1], "nick ") == params[1] )
	irc_cmd_nick (irc_session, params[1] + 5);

if ( strstr (params[1], "whois ") == params[1] )
	irc_cmd_whois (irc_session, params[1] + 5);

}

return;
}