示例#1
0
文件: compiler.cpp 项目: rzymek/cxxsp
 void compiler::process(const string& cpp_path, const string& out_path, const vector<string>& params) {
     int cmd_stdout[2];//0-read, 1-write;
     int cmd_stderr[2];//0-read, 1-write;
     if(pipe(cmd_stdout) == -1 || pipe(cmd_stderr) == -1)
             throw system_error("pipe",errno);
     pid_t pid = fork();
     switch(pid){
         case -1:
             throw system_error("fork", errno);
         case 0: //child
             setup_descriptors(cmd_stdout, cmd_stderr);
             compiler_main(cpp_path, out_path, params);            
             break;
         default:
             parent(pid, cmd_stdout, cmd_stderr);
     }
 }
示例#2
0
文件: driver.cpp 项目: cjb129/beekar
int
main(int argc, char* argv[])
{
  return compiler_main(argc, argv);
}
示例#3
0
///////////////////////////////////////////////////////////////////
// Function name     : racProcessInput
// Description       : processes input from socket s
// Return type       : void 
// Author            : Xanathar 
// Argument          : int s -> socket to process input
// Changes           : rewritten by Anthalir
void RemoteAdmin::ProcessInput(int s)
{
	char inp2[1024]= {'\0'};
	char *inp= inp2;
	UI32 i;


	if (rac_port==0) return;

	if( !strncmp(&inputbufs[s][0], "!!", 2) )
	{
		strcpy(inp2, oldinp[s]);
	}
	else 
	{
		int j=0;
		for (int i=0; i<inputptrs[s]; i++)
		{
			if (inputbufs[s][i]!='\b')		// \b = bell
				inp2[j++] = inputbufs[s][i];
		}

		strncpy(oldinp[s], inp2, sizeof(oldinp[s])-1);
	}

	// remove spaces and tabulations at string start
	while( isspace(inp[0]) )
		inp++;

	if (status[s]==RACST_STDIN)
	{
		for (i=0; i< strlen(inp); i++)
		{
			if ((inp[i]>='a')&&(inp[i]<='z')) 
				inp[i] -= 'a'-'A';

			if (inp[i]==' ') break;
		}
	}
		
	inputptrs[s] = 0;

	if (status[s]==RACST_CHECK_USR)
	{
		strcpy(loginname[s], inp);
		Printf(s, "password : "******"\r\nAccess Denied.\r\nPress any key to get disconnected...");
			ConOut("Access Denied on Remote Console for user '%s' with pass '%s'\n", loginname[s], inp);
			status[s]=RACST_ACCESS_DENIED;
			return;
		} else {
			status[s]=RACST_STDIN;
			Printf(s,"\r\n\r\n");
			Printf(s,"------------------------------------------------------------------------\r\n");
			Printf(s,"Welcome to the administration console\r\n");
			Printf(s,"\r\nType HELP to receive help on commands.\r\n");
			Printf(s,"If you are not authorized to access this system\r\n");
			Printf(s,"please exit immediately by typing the EXIT command\r\n");
			Printf(s,"or by closing your client. Any other unauthorized\r\n");
			Printf(s,"action can be persecuted by law.\r\n");
			Printf(s,"\r\n");

			// re-enable local echo for client
			Printf(s, "%c%c%c", IAC, DO, ECHO);
			Printf(s, "%c%c%c", IAC, WONT, ECHO);

			ConOut("Authorised acces on Remote Console by user %s\n", loginname[s]);
			return;
		}
	}

	if (status[s]!=RACST_STDIN) return;

	if (!strcmp(inp,"PDUMP")) 
	{
		Printf(s, "Performace Dump:\r\n");

		Printf(s, "Network code: %fmsec [%i]", (float)((float)networkTime/(float)networkTimeCount), networkTimeCount);
		Printf(s,"Timer code: %fmsec [%i]" , (float)((float)timerTime/(float)timerTimeCount) , timerTimeCount);
		Printf(s,"Auto code: %fmsec [%i]" , (float)((float)autoTime/(float)autoTimeCount) , autoTimeCount);
		Printf(s,"Loop Time: %fmsec [%i]" , (float)((float)loopTime/(float)loopTimeCount) , loopTimeCount);
		Printf(s,"Simulation Cycles/Sec: %f" , (1000.0*(1.0/(float)((float)loopTime/(float)loopTimeCount))));
		return;
	}



	if (!strcmp(inp,"WHO")) 
	{
			if(now==0) 
			{
				Printf(s,"There are no users connected.\r\n");
				return;
			}

			int i, j=0;
			Printf(s,"Current Users in the World:\r\n");
			for (i=0;i<now;i++)
			{
				P_CHAR pc_i=MAKE_CHAR_REF(currchar[i]);				
				if( ISVALIDPC(pc_i) && clientInfo[i]->ingame ) //Keeps NPC's from appearing on the list
				{
					j++;
					Printf(s, "    %i) %s [%08x]\r\n", j, pc_i->getCurrentNameC(), pc_i->getSerial32());
				}
			}
			Printf(s, "Total Users Online: %d\r\n", j);
			Printf(s, "End of userlist\r\n");
			return;
	}

	if (!strcmp(inp,"QUIT") || !strcmp(inp, "EXIT")) 
	{ 
		Printf(s, "Bye %s ! :)\r\n\r\n", loginname[s]); 
		Disconnect(s); 
		return; 
	}

	if (!strcmp(inp,"HELP")) {
		Printf(s,"!! : repeats the last command\r\n");
		Printf(s,"WHO : displays logon players\r\n");
		Printf(s,"QUIT : close the connection\r\n");
		Printf(s,"EXIT : close the connection\r\n");
		Printf(s,"PDUMP : displays performance dump\r\n");
		Printf(s,"SAVE : saves the world\r\n");
		Printf(s,"SHUTDOWN : shuts the server\r\n");
		Printf(s,"ABORT : shuts the server WITHOUT saving\r\n");
		Printf(s,"BROADCAST, BC or '!' <msg> : broadcasts a message to everyone\r\n");
		Printf(s,"CFG <section>.<property>=<value> : sets a server.cfg setting dynamically\r\n");
		Printf(s,"ADDACCT <name>,<pwd> : creates a new account\r\n");
		Printf(s,"REMACCT <name> : remove an account\r\n");
		Printf(s,"CHANGEACCTPWD <name>,<pwd> : change an account password\r\n");
		Printf(s,"RELOADCRON : reloads the crontab.scp file\r\n");
		Printf(s,"AMXCALL <function> : executes a function of override.sma\r\n");
		Printf(s,"AMXRUN <program> : executes an external AMX program\r\n");
		Printf(s,"AMXBUILD <sourcefile> <outputprogram> : compiles a Small program\r\n");
		Printf(s,"RELOADBLOCKS : reload hosts_deny.scp\r\n");
		Printf(s,"RELOADSMALL : recompile and reload small scritps\r\n");

		return;
	}

	char tkn[1024];
	char *cmd = NULL, *par2 = NULL;
	

	for (i=0; i< strlen(inp); i++)
	{
		if (inp[i]==' ') 
		{
			tkn[i] = '\0';
			cmd = inp+i+1;
			break;
		} 
		else 
		{
			tkn[i]=inp[i];
		}
	}

	// before the splitting of arguments

	if (!strcmp(tkn,"CFG")) 
	{
		if ((cmd==NULL))
		{
			Printf(s,"Syntax is : CFG <section>.<property>=<value>\r\nExample : CFG SERVER.STATCAP=200\r\nSections and properties are the ones contained in server.scp\r\n");
			return;
		}
		int n=cfg_command(cmd);
		if (n!=0) 
			Printf(s, "Error number : %d\r\n", n);
		else 
			Printf(s, "OK.\r\n");

		return;
	}

	if (!strcmp(tkn,"AMXCALL")) 
	{
		if ((cmd==NULL)) 
		{
			Printf(s,"Syntax is : AMXCALL <function>\r\nExample : AMXCALL foo\r\n");
			return;
		}
		AmxFunction::g_prgOverride->CallFn(cmd);
		return;
	}

	if (!strcmp(tkn,"AMXRUN")) 
	{
		if ((cmd==NULL)) 
		{
			Printf(s,"Syntax is : AMXRUN <program>\r\nExample : AMXRUN myprog.amx\r\n");
			return;
		}
		AmxProgram *prg = new AmxProgram(cmd);
		prg->CallFn(-1);
		safedelete(prg);
		return;
	}

	if (cmd!=NULL) {
		for (i=0; i< strlen(cmd); i++)
		{
			if ((cmd[i]==',')||(cmd[i]==' ')) 
			{
				par2 = cmd+i+1;
				cmd[i] = '\0';
				break;
			}
		}
	}

	if (!strcmp(inp,"SAVE")) 
	{
			if ( !cwmWorldState->Saving() )
			{
				Printf(s, "Saving worldfile...");
				cwmWorldState->saveNewWorld();
				saveserverscript();
				Printf(s, "[DONE]\r\n");
				Printf(s, "OK.\r\n");
			} 
			return;
	}

	if (!strcmp(inp,"SHUTDOWN")) {
			ConOut("NoX-Wizard: Immediate Shutdown initialized from Remote Console!\n");
			Printf(s, "Bye! :)\r\n\r\n");
			keeprun=0;
			return;
	}

#ifdef DEBUG
	if (!strcmp(inp,"---CRASH")) { //this command is usefull to test crash recovery :)
			char *p = NULL;
			p[0] = 'X';
			Printf(s, "OK.\r\n");
			return;
	}
#endif

	if (!strcmp(inp,"ABORT")) 
	{
		exit(3);
		return;
	}

	if (!strcmp(inp,"RELOADCRON")) 
	{
			killCronTab();
			initCronTab();
			return;
	}


	if (!strcmp(inp,"RELOADBLOCKS")) 
	{
			Network->LoadHosts_deny();
			Printf(s,"hosts_deny.scp reloaded.");
			return;
	}									//wad }
	if (!strcmp(inp,"RELOADSMALL")) 
	{
			initAmxEvents();
			LoadOverrides ();
			AMXEXECV(AMXT_SPECIALS,0,AMX_AFTER);
			Printf(s,"Recompiled Small scripts");
			return;
	}									


	if ((!strcmp(tkn,"BROADCAST"))||(!strcmp(tkn,"BC"))||(!strcmp(tkn,"!"))) 
	{
			if ((cmd==NULL)) 
			{
				Printf(s,"Syntax is : BROADCAST <message>\r\nExample : BROADCAST Warning restarting server!\r\n");
				return;
			}

			if (par2!=NULL) 
				sysbroadcast("%s %s", cmd, par2);
			else 
				sysbroadcast("%s", cmd);

			Printf(s, "OK.\r\n");
			return;
	}

	if (!strcmp(tkn,"ADDACCT")) 
	{
		if ((cmd==NULL)||(par2==NULL)) 
		{
			Printf(s,"Syntax is : ADDACCT <name>,<password>\r\nExample : ADDACCT administrator,password\r\n");
			return;
		}
		int acc = Accounts->CreateAccount(cmd, par2);
		if ( acc != INVALID )
		{
			Printf(s, "Account %d created\r\n  Name : %s\r\n  Pass : %s\r\n", acc,cmd,par2);
			Printf(s, "[  OK  ] \r\n");
		}
		else
		{
			Printf(s, "Account %s not created. Username existant.\r\n", cmd);
			Printf(s, "[ERRORS]\r\n");
		}
		return;
	}
	
	if ( !strcmp(tkn,"REMACCT") )
	{
		if ((cmd==NULL))
		{
			Printf(s,"Syntax is : REMACCT <name>\r\nExample : REMACCT administrator\r\n");
			return;
		}
		if ( Accounts->RemoveAccount(cmd) )
		{
			Printf(s, "Account %s deleted\r\n", cmd);
			Printf(s, "[  OK  ]\r\n");
		}
		else
		{
			Printf(s, "Account %s not deleted\r\n", cmd);
			Printf(s, "[ERRORS]\r\n");
		}
		return;
	}
	
	if ( !strcmp(tkn,"CHANGEACCTPWD") )
	{
		if ((cmd==NULL)||(par2==NULL))
		{
			Printf(s,"Syntax is: CHANGEACCTPWD <name>,<password>\r\nExample : CHANGEACCTPWD administrator,newpassword\r\n");
			return;
		}
		ACCOUNT acc = Accounts->GetAccountByName(cmd);
		if ( acc != INVALID )
		{
			Accounts->ChangePassword(acc, par2);
			Printf(s, "Account %d has new password\r\n  Password : %s\r\n", acc, par2);
			Printf(s, "[  OK  ] \r\n");
		}
		else
		{
			Printf(s, "Password of account %s not changed. Username not existant.\r\n", cmd);
			Printf(s, "[ERRORS]\r\n");
		}
		return;
	}

	if (!strcmp(tkn,"AMXBUILD")) 
	{
		if ((cmd==NULL)||(par2==NULL)) 
		{
			Printf(s,"Syntax is : AMXBUILD <source> <output>\r\nExample : AMXBUILD myprog.sma myprog.amx\r\n");
			return;
		}
		Printf(s,"Initializing build : NOTE that output will go to the main console. Sorry for that :(\r\n");
		Printf(s,"Building...");
		char *argv[4];
		
		argv[0] = "noxwizard.internal.compiler";
		argv[1] = new char[50];
		argv[2] = new char[50];
		argv[3] = new char[50];

		strncpy(argv[1], cmd, 49);
		strncpy(argv[2], par2, 49);
		strncpy(argv[3], "", 49);

		int ret = compiler_main(3, (char **)argv);

		if (ret==0) 
			Printf(s,"[ OK ]\r\n");
		else if (ret==1) 
			Printf(s,"[WARNINGS]\r\n");
		else if (ret>1) 
			Printf(s,"[ERRORS]\r\n");

		delete argv[1];
		delete argv[2];
		delete argv[3];
		return;
	}

	Printf(s,"Unknown command entered.\r\n");
}