Ejemplo n.º 1
0
void execStdFileClose (void) {

	long fileHandle = ABLi_popInteger();

	UserFile* userFile = UserFile::files[fileHandle];
	if (userFile->inUse)
		userFile->close();
}
Ejemplo n.º 2
0
bool MultiServer::setUserFile(const QString &path)
{
	UserFile *userfile = new UserFile(_sessions);
	if(!userfile->setFile(path))
		return false;

	_sessions->setIdentityManager(userfile);
	return true;
}
Ejemplo n.º 3
0
void execStdFileWrite (void) {

	long fileHandle = ABLi_popInteger();
	char* string = ABLi_popCharPtr();

	UserFile* userFile = UserFile::files[fileHandle];
	if (userFile->inUse)
		userFile->write(string);
}
Ejemplo n.º 4
0
void execStdFileOpen (void) {

	char* fileName = ABLi_popCharPtr();

	long fileHandle = -1;
	UserFile* userFile = UserFile::getNewFile();
	if (userFile) {
		long err = userFile->open(fileName);
		if (!err)
			fileHandle = userFile->handle;
	}

	ABLi_pushInteger(fileHandle);
}
Ejemplo n.º 5
0
// set flags in the user_Info structure for this user
void DryonBot::checkUserFlags(user_Info *usr, const string &dest)
{
	if( !usr->flags_set )
	{
		// global flags
		userfile.setUserFlagsFromUserfile(*usr, use_AUTH);
		// flags for channel(s)
		userfile.setChanFlagsFromUserfile(*usr);

		Debug("Flags set for '%s'\n", usr->nick.c_str());
		usr->flags_set= true;
	}

	// if user has no account do nothing
	if( usr->hasAccount() )
	{
		if( isChannelName(dest) )
		{
			// global flag(s)
			bool glb_need_op=		usr->hasFlag(USRLVL_OPERATOR);
			bool glb_need_voice=	usr->hasFlag(USRLVL_VOICE);
			bool glb_need_kickban=	usr->hasFlag(USRLVL_KICK);

			// channel specific flag(s)
			bool need_op=			usr->hasChannelFlag(USRLVL_OPERATOR, dest);
			bool need_voice=		usr->hasChannelFlag(USRLVL_VOICE, dest);
			bool need_kickban=		usr->hasChannelFlag(USRLVL_KICK, dest);

			if( glb_need_kickban || need_kickban )
			{
				if( isOp(usr, dest) )
					setMode(dest, usr->nick, "-o");

				ban(dest, usr->full_host);
				kick(dest, usr->nick, "auto-kick");
			}
			else if( glb_need_op || need_op )
			{
				if( !isOp(usr, dest) )
					setMode(dest, usr->nick, "+o");
			}
			else if( glb_need_voice || need_voice )
			{
				if( !isVoice(usr, dest) )
					setMode(dest, usr->nick, "+v");
			}
		}
	}
}
Ejemplo n.º 6
0
int main(int argc, char **argv)
{
	int ret= 0;
	int ok= parseCommandLine(argc, argv);

#if defined(DEBUG_MEM)
	atexit(_CheckMemLeaks);
#endif

#if defined(__FreeBSD__)

	//set_terminate( term_exception );
	setlocale(LC_TIME, "fr_FR.ISO8859-1");
	//signal(SIGINT, sigINT);
	signal(SIGPIPE, SIG_IGN);

#elif defined(WIN32)
	setlocale(LC_TIME, "French");
	WSAData wsaData;
	main_thread= GetCurrentThread();
	console.run();
	sleep(1);

#	if defined(_DEBUG) && defined(_MSC_VER)
		// add breakpoint when memory block n is allocated
		// _crtBreakAlloc
		//_CrtSetBreakAlloc(n);
		//_CrtSetBreakAlloc(10193);
		//_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF |
		//	_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_CHECK_CRT_DF | _CRTDBG_DELAY_FREE_MEM_DF);
#	endif

if( WSAStartup(MAKEWORD(1,1), &wsaData) != 0)
{
	Error("Unable to initialise network: %d\n", WSAGetLastError());
}
else
{
#endif
	Output("Dryon v" BOT_VERSION " compiled on " __DATE__ "\n");
	Output("Embedded AMX: v" SMALL_VERSION "\n");
	Output("Embedded Ruby: v" RUBY_VERSION "\n");

	if( ok != 0 )
	{
		usleep(10000);
		return 1;
	}

	if( help_mode )
	{
		Output("Usage: %s [option(s)]\n", basename(argv[0]));
		Output("--test		enable test mode\n");
		Output("--help		display help\n");
		Output("--hidden	start hidden (windows)\n");
		Output("--config xxx	set dryon.cfg file\n");
		Output("--servers xxx	set servers.txt file\n");
		Output("--userfile xxx	set userfile.txt file\n");
		usleep(10000);
		return 0;
}

	cfg.setFile( configfile_path.c_str() );

	/* some checks on required folders/files */
	if( makeSanityChecks() == 0 )
	{
		bool err= false;
		cfg.readFile();

		#define CHECK_CFG_VAR(X)	if( !cfg.isDefined(#X) ){ Error("variable '" #X "' undefined\n"); err= true; }

		// check if required config directives are set
		CHECK_CFG_VAR(	botname	 );
		CHECK_CFG_VAR(	alt_nick );
		CHECK_CFG_VAR(	realname );
		CHECK_CFG_VAR(	useauth  );
		CHECK_CFG_VAR(	script_01);


		// if one or more vars are undefined then exit now
		// exit also if the compilation of scripts fails
		if( !err &&  (PMgr.loadScriptsFromCfg(cfg) == 0) )
		{
			//// compile/test the scripts /////
			if( test_mode )
			{
				Output("** TEST MODE **\n");
				PMgr.callEvent("event_onTest");
			}
			///////////
			else
			{
				string last_srv= "", srv= "";

				cfg.readFile();
				userfile.readUserFile( userfile_path.c_str() );
				servers.loadFromFile( serverlist_path.c_str() );

				while(1)
				{
					int ret;

					if( cfg.isDefined("debugmode") )
						bot.setIntOption(OPTION_INT_DEBUGMODE, 	cfg.readIntKey("debugmode"));
					else
						bot.setIntOption(OPTION_INT_DEBUGMODE, 	0);

					bot.setIntOption(OPTION_INT_USEAUTH, 	cfg.readBoolKey("useauth")?1:0);
					bot.setStrOption(OPTION_STR_REALNAME, 	cfg.readStringKey("realname"));
					bot.setStrOption(OPTION_STR_ALTNICK,	cfg.readStringKey("alt_nick"));

					srv= servers.getNextServer();
					// if the server is the same than the last one we tried, wait 2min
					// before trying to reconnect to be nice with the server :)
					if( srv == "" )
					{
						Error("No servers in servers.txt, exiting...\n");
						break;
					}
					else if( srv == last_srv )
					{
						Debug("Waiting 2min before reconnect attempt...\n");
						sleep(120);
					}



					// if exceptions occur then they came from the STL since
					// i don't use them
					try
					{
						ret= bot.mainLoop(srv, cfg.readStringKey("botname"));
					}
					catch( exception &e )
					{
						Error("exception: %s\n", e.what());
					}

					last_srv= srv;

					if( ret!=0 )
					{
						Debug("Exiting...\n");
						break;
					}

					PMgr.callEvent("event_onBotDisconnected");
				}
			}
		}
		else
		{
			Output("Errors during loading/compilation\n");
			ret= 1;
		}
	}
	else
	{
		ret= 1;
	}


#if defined(WIN32)
}
#endif

	// i had problems when the bot exited immediatly from an error
	// the thread didn't had time to initialiase before exiting and this resulted
	// in a seg fault, with a small delay it works fine :)
	usleep(10000);

#if defined(WIN32)

WSACleanup();
Output("%sBot exited successfully, you can now close the window.%s\n", COLOR_GREEN, COLOR_RESET);
//	console.requestEnd();
//	console.waitEnd();

#endif

	return ret;
}
Ejemplo n.º 7
0
void DryonBot::onPrivMsg(const string &sender, const string &dest, const string &msg)
{
	vector<string> msg_parts;
	Tokenize(msg, msg_parts, " ");
	user_Info *usr;
	GET_USR(usr, sender);

	const string &command= msg_parts[0].substr(1);

	// load user flags from userfile.txt
	checkUserFlags(usr, dest);

	if( command=="reload" )
	{
		/* if user has owner flag then reload all config files */
		if( usr->hasFlag(USRLVL_OWNER) )
		{
			// force update of user flags
			for(userDataTypeIter it= userData.begin(); it!= userData.end(); it++)
				(*it).second.flags_set= false;

			servers.loadFromFile("servers.txt");
			userfile.saveFile();
			userfile.readUserFile();
			cfg.readFile();
			PMgr.loadScriptsFromCfg(cfg);
		}
		return;
	}
	// user list
	else if( command=="userlist" )
	{
		if( usr->hasAccount() && usr->hasFlag(USRLVL_OWNER) )
		{
			map<string, UsersData> &ulist= userfile.getAccessList();
			notice(sender, "User list: %d entries", ulist.size());
			notice(sender, "-------- Start (Show accounts and global flags) --------");

			for(map<string, UsersData>::iterator it= ulist.begin(); it!=ulist.end(); it++)
			{
				string what= it->first;
				if( (what[0]=='a') && (what[1]=='/') )
				{
					what= '#' + what.substr(2);
				}

				notice(sender, "%15s %35s %5s", it->second.name.c_str(), what.c_str(), it->second.flags.c_str());
			}

			notice(sender, "--------  End  --------");
		}
		return;
	}
	else if( command == "showflags" )
	{
		if( usr->hasAccount() && usr->hasFlag(USRLVL_MASTER) )
		{
			map<string, UsersData> &ulist= userfile.getAccessList();
			string &chan= msg_parts[1];
			notice(sender, "User list for %s", chan.c_str());

			for(map<string, UsersData>::iterator it= ulist.begin(); it!=ulist.end(); it++)
			{
				string what= it->first;
				UsersData &tmp= it->second;

				for(map<string,string>::iterator it2= tmp.channel_flags.begin(); it2 != tmp.channel_flags.end(); it2++)
				{
					if( it2->first == chan )
						notice(sender, "%15s %5s", it->second.name.c_str(), it2->second.c_str());
				}
			}
			notice(sender, "--------  End  --------");
		}
	}
	// return a list of loaded plugins
	else if( command=="scripts" )
	{
		uint count= PMgr.getPluginCount();
		for(int i= count-1; i>= 0; i--)
		{
			notice(sender, "%2d ) %s\n", i, PMgr.getPlugin(i)->getPath());
		}
	}
	else if( command=="quit" )
	{
		if( usr->hasFlag(USRLVL_OWNER) )
		{
			quit("exit requested");
		}
		return;
	}
	else if( command=="help" )
	{
		if( usr->hasAccount() )
		{
			notice(sender, "Core commands:");
			if( usr->hasFlag(USRLVL_OWNER) )
			{
				notice(sender, ":reload - reload all plugins and config file");
				notice(sender, ":userlist - display user list");
			}

			notice(sender, ":help - display this :<");
			notice(sender, ":scripts - display list of currently loaded scripts");
			notice(sender, "---");
			PMgr.sendCommandsList(sender, dest, usr);
			//return;
		}
	}
	else if( command=="nfo" )
	{
		if( msg_parts.size() == 1 )
		{
			Output("Nick: '%s'\n", bot_data.nick.c_str());
			Output("Host: '%s'\n", bot_data.full_host.c_str());
			Output("Auth: '%s'\n", bot_data.auth.c_str());
		}
		else if( msg_parts.size() >= 2 )
		{
			user_Info *u= getUserData(msg_parts[1]);
			if( u!=NULL )
			{
				Output("Nick: '%s'\n", u->nick.c_str());
				Output("Host: '%s'\n", u->full_host.c_str());
				Output("Auth: '%s'\n", u->auth.c_str());
			}
			else
			{
				notice(sender, "Nick unknown: %s", msg_parts[1].c_str());
			}
		}
	}
	else
	{
		chan_Info *chan;
		if( isChannelName(dest) )
		{
			GET_CHAN(chan, dest);
			PMgr.callEvent("event_onPrivMsg", "ucv", usr, chan, &msg_parts);
			PMgr.callCommand(usr, (dummy_Info*)chan, msg_parts);
		}
		else
		{
			PMgr.callEvent("event_onPrivMsg", "uuv", usr, &bot_data, &msg_parts);
			PMgr.callCommand(usr, (dummy_Info*)&bot_data, msg_parts);
		}
	}
}
Ejemplo n.º 8
0
void execute(SymTableNodePtr routineIdPtr)
{
	SymTableNodePtr thisRoutineIdPtr = CurRoutineIdPtr;
	CurRoutineIdPtr = routineIdPtr;
	routineEntry(routineIdPtr);
	//----------------------------------------------------
	// Now, search this module for the function we want...
	if(CallModuleInit)
	{
		CallModuleInit = false;
		SymTableNodePtr initFunctionIdPtr = searchSymTable("init", ModuleRegistry[CurModule->getHandle()].moduleIdPtr->defn.info.routine.localSymTable);
		if(initFunctionIdPtr)
		{
			execRoutineCall(initFunctionIdPtr, false);
			//-------------------------------------------------------------------------
			// Since we're calling the function directly, we need to compensate for the
			// codeSegmentPtr being incremented by 1 in the normal execRoutineCall...
			codeSegmentPtr--;
		}
	}
	if(routineIdPtr->defn.info.routine.flags & ROUTINE_FLAG_FSM)
	{
		NewStateSet = true;
		static char stateList[60][256];
		strcpy(SetStateDebugStr, "--");
		while(NewStateSet)
		{
			NumStateTransitions++;
			sprintf(stateList[NumStateTransitions], "%s (%s)", CurModule->getState()->name, SetStateDebugStr);
			if(NumStateTransitions == 50)
			{
				UserFile* userFile = UserFile::getNewFile();
				char errStr[512];
				if(userFile)
				{
					int32_t err = userFile->open("endless.log");
					if(!err)
					{
						//char s[1024];
						//sprintf(s, "Current Date: %s\n", GetTime());
						//userFile->write(s);
						userFile->write(ModuleRegistry[CurModule->getHandle()].fileName);
						for(size_t i = 1; i < 51; i++)
							userFile->write(stateList[i]);
						userFile->write(" ");
						if(ABLEndlessStateCallback)
							(*ABLEndlessStateCallback)(userFile);
						userFile->close();
					}
				}
				sprintf(errStr, " ABL endless state loop in %s [%s:%s] ", ModuleRegistry[CurModule->getHandle()].fileName, CurModule->getState()->name, CurModule->getPrevState()->name);
#if 0
				ABL_Fatal(NumStateTransitions, errStr);
#else
				NewStateSet = false;
#endif
			}
			else
			{
				NewStateSet = false;
				SymTableNodePtr curState = CurModule->getState();
				if(!curState)
					ABL_Fatal(0, " ABL.execute: nullptr state in FSM ");
				execRoutineCall(curState, false);
				codeSegmentPtr--;
			}
			//---------------------------------------------
			// In case we exited with a return statement...
			ExitWithReturn = false;
			ExitFromTacOrder = false;
		}
	}
	else
	{
		getCodeToken();
		execStatement();
		//---------------------------------------------
		// In case we exited with a return statement...
		ExitWithReturn = false;
		ExitFromTacOrder = false;
	}
	routineExit(routineIdPtr);
	CurRoutineIdPtr = thisRoutineIdPtr;
}
Ejemplo n.º 9
0
void NameAtlas::GenerateDoc(){
    UserFile f;
    f.Open("doc.txt");
    f.Write(g_s.str());
    f.Close();
}