Ejemplo n.º 1
0
bool ProxyClient::ProcessStringCmd(char *string)
{
	if (BaseClient::ProcessStringCmd(string)) {
		return true;
	}

	TokenLine cmdLine;
	if (!cmdLine.SetLine(string)) {
		m_System->Printf("WARNING! ProxyClient::ProcessStringCmd: string command too long.\n");
		return true;
	}

	char *cmd = cmdLine.GetToken(0);
	for (auto& local_cmd : m_LocalCmdReg)
	{
		if (!_stricmp(local_cmd.name, cmd)) {
			(this->*local_cmd.pfnCmd)(&cmdLine);
			return true;
		}
	}

	if (m_ClientType < TYPE_COMMENTATOR) {
		m_System->DPrintf("Unkown client command: \"%s\"\n", cmd);
	}

	m_System->DPrintf("Unkown director command: \"%s\"\n", cmd);
	return false;
}
Ejemplo n.º 2
0
void GDLNode::createOrNode(const TokenLine &tokenLine, GDLNode **nodeOut) {
	std::vector<TokenLine> tokenLines;
	
	breakDownTokenLine(tokenLine, tokenLines);
	try {
		std::vector<PropositionNode*> propositions;
		for (size_t i = 1; i < tokenLines.size(); ++i) {
			try {
				if (tokenLines[i].getType() != TOKEN_LINE_RELATION && tokenLines[i].getType() != TOKEN_LINE_DISTINCT) {
					throw Exception("Syntax error: Or must have proposition as arguments. In line: " + tokenLine.toString());
				}
				
				PropositionNode *proposition;
				createPropositionNode(tokenLines[i], (GDLNode**)&proposition);
				propositions.push_back(proposition);
			} catch (Exception &e) {
				for (size_t i = 0; i < propositions.size(); ++i) {
					delete propositions[i];
				}
				throw e;
			}
		}
		*nodeOut = new OrNode(propositions);
	} catch (std::out_of_range) {
		throw Exception("Syntax error while creating Or node. In line: " + tokenLine.toString());
	}
}
Ejemplo n.º 3
0
void GDLNode::createDistinctNode(const TokenLine &tokenLine, GDLNode **nodeOut) {
	std::vector<TokenLine> tokenLines;
	std::vector<Token> arguments;
	
	breakDownTokenLine(tokenLine, tokenLines);
	for (size_t i = 1; i < tokenLines.size(); ++i) {
		int type = tokenLines[i].getTokens()[0].getType();
		if (type != TOKENIZER_TOKEN_TYPE_TERM && type != TOKENIZER_TOKEN_TYPE_VAR) {
			throw Exception("Syntax error: Invalid arguments in Distinct. In line: " + tokenLine.toString());
		}
		arguments.push_back(tokenLines[i].getTokens()[0]);
	}
	*nodeOut = new DistinctNode(arguments);
}
Ejemplo n.º 4
0
void GDLNode::createInitNode(const TokenLine &tokenLine, GDLNode **nodeOut) {
	std::vector<TokenLine> tokenLines;
	PropositionNode *proposition;
	
	breakDownTokenLine(tokenLine, tokenLines);
	try {
		if (tokenLines.at(1).getType() != TOKEN_LINE_RELATION) {
			throw Exception("Syntax error: Init must have proposition as argument. In line: " + tokenLine.toString());
		}
		
		createPropositionNode(tokenLines.at(1), (GDLNode**)&proposition);
		*nodeOut = new InitNode(proposition);
	} catch (std::out_of_range) {
		throw Exception("Syntax error while creating init node. In line: " + tokenLine.toString());
	}
}
Ejemplo n.º 5
0
void GDLNode::createIfNode(const TokenLine &tokenLine, GDLNode **nodeOut) {
	std::vector<TokenLine> tokenLines;
	
	breakDownTokenLine(tokenLine, tokenLines);
	try {
		GDLNode *head = createGDLNodes(tokenLines.at(1));
		std::vector<GDLNode*> body;
		for (size_t i = 2; i < tokenLines.size(); ++i) {
			GDLNode *b = createGDLNodes(tokenLines[i]);
			body.push_back(b);
		}
		*nodeOut = new IfNode(head, body);
	} catch (std::out_of_range) {
		throw Exception("Syntax error while creating If node. In line: " + tokenLine.toString());
	}
}
Ejemplo n.º 6
0
void GDLNode::createGoalNode(const TokenLine &tokenLine, GDLNode **nodeOut) {
	std::vector<TokenLine> tokenLines;
	
	breakDownTokenLine(tokenLine, tokenLines);
	try {
		int type = tokenLines.at(1).getTokens().at(0).getType();
		if (type != TOKENIZER_TOKEN_TYPE_TERM && type != TOKENIZER_TOKEN_TYPE_VAR) {
			throw Exception("Syntax error: Goal must have role as first argument. In line: " + tokenLine.toString());
		}
		if (tokenLines.at(2).getTokens().at(0).getType() != TOKENIZER_TOKEN_TYPE_TERM) {
			throw Exception("Syntax error: Goal must have value as second argument. In line: " + tokenLine.toString());
		}
		
		Token role = tokenLines[1].getTokens()[0];
		int value = stoi(tokenLines[2].getTokens()[0].getTokenStr());
		*nodeOut = new GoalNode(role, value);
	} catch (std::out_of_range) {
		throw Exception("Syntax error while creating Goal node. In line: " + tokenLine.toString());
	}
}
Ejemplo n.º 7
0
void GDLNode::createDoesNode(const TokenLine &tokenLine, GDLNode **nodeOut) {
	std::vector<TokenLine> tokenLines;
	
	breakDownTokenLine(tokenLine, tokenLines);
	try {
		int type = tokenLines.at(1).getTokens().at(0).getType();
		if (type != TOKENIZER_TOKEN_TYPE_TERM && type != TOKENIZER_TOKEN_TYPE_VAR) {
			throw Exception("Syntax error: Does must have role as first argument. In line: " + tokenLine.toString());
		}
		if (tokenLines.at(2).getType() != TOKEN_LINE_RELATION) {
			throw Exception("Syntax error: Does must have action as second argument. In line: " + tokenLine.toString());
		}
		
		Token role = tokenLines[1].getTokens()[0];
		PropositionNode *proposition;
		createPropositionNode(tokenLines[2], (GDLNode**)&proposition);
		*nodeOut = new DoesNode(role, proposition);
	} catch (std::out_of_range) {
		throw Exception("Syntax error while creating Does node. In line: " + tokenLine.toString());
	}
}
Ejemplo n.º 8
0
void GDLNode::createPropositionNode(const TokenLine &tokenLine, GDLNode **nodeOut) {
	std::vector<TokenLine> tokenLines;
	
	breakDownTokenLine(tokenLine, tokenLines);
	try {
		std::string name;
		std::vector<Token> arguments;
		
		name = tokenLines.at(0).getTokens().at(0).getTokenStr();
		for (size_t i = 1; i < tokenLines.size(); ++i) {
			int type = tokenLines.at(i).getTokens().at(0).getType();
			if (type != TOKENIZER_TOKEN_TYPE_TERM && type != TOKENIZER_TOKEN_TYPE_VAR) {
				throw Exception("Syntax error: Proposition '" + name + "' has incorrect arguments. In line: " + tokenLine.toString());
			}
			arguments.push_back(tokenLines.at(i).getTokens().at(0));
		}
		*nodeOut = new PropositionNode(name, arguments);
	} catch (std::out_of_range) {
		throw Exception("Syntax error while creating Proposition node. In line: " + tokenLine.toString());
	}
}
Ejemplo n.º 9
0
void GDLNode::breakDownTokenLine(const TokenLine &tokenLine, std::vector<TokenLine> &tokenLinesOut) {
	TokenLiner tokenLiner;
	tokenLiner.createLines(tokenLine.getTokens(), tokenLinesOut);
}
Ejemplo n.º 10
0
void CBanList::ServerResponded()
{

	if(m_bGotIPs == false) 
	{
		m_BanList.RemoveAll();

		const char *rconResp = m_pRcon->RconResponse();
		const char *cur = strstr(rconResp,"UserID filter list:")
								+ strlen("UserID filter list:");

		if( (unsigned int)cur == strlen("UserID filter list:")) 
			// if strstr returned NULL and we added a strlen to it...
		{
			cur=NULL;
		}
	// listid format:
	//	UserID filter list:
	// 1 23434 : 20.000 min

	// and on empty it produces:
	//	IP filter list: empty

		while(cur!=NULL) 
		{

			TokenLine banLine;
			cur++; // dodge the newline
			banLine.SetLine(cur); // need to add one here, to remove the "\n"
			if(banLine.CountToken() >= 4 ) 
			{
				Bans_t ban;

				memset(&ban,0x0,sizeof(Bans_t));
	
				v_strncpy(ban.name,banLine.GetToken(1),20);
				sscanf(banLine.GetToken(3),"%f",&ban.time);
				ban.type= ID;
				m_BanList.AddToTail(ban);
	
			}
			cur=strchr(cur,'\n');
		
		}
		
		m_bGotIPs=true;

		// now find out the list of banned ips
		m_pRcon->SendRcon("listip");
	} 
	else 
	{

	// listip format:
	//	IP filter list:
	//192.168.  1. 66 : 20.000 min

			const char *rconResp = m_pRcon->RconResponse();
		const char *cur = strstr(rconResp,"IP filter list:")
								+ strlen("IP filter list:");

		if( (unsigned int)cur == strlen("IP filter list:")) 
			// if strstr returned NULL and we added a strlen to it...
		{
			cur=NULL;
		}


		while(cur!=NULL) 
		{

			char tmpStr[512]; 
			Bans_t ban;
	
			cur++; // dodge past the newline
			v_strncpy(tmpStr,cur,512);

			memset(&ban,0x0,sizeof(Bans_t));
	
			if( strchr(tmpStr,':') != NULL )
			{
				char *time; 
				time = strchr(tmpStr,':')+1;
				tmpStr[strchr(tmpStr,':')-tmpStr]=0;
				
				v_strncpy(ban.name,tmpStr,20);
				unsigned int i=0;
				while(i<strlen(ban.name)) // strip all the white space out...
				{
					if( ban.name[i]==' ') 
					{
						strcpy(&ban.name[i],&ban.name[i+1]);
					} 
					else 
					{
						i++;
					}
				}

				sscanf(time,"%f",&ban.time);
				ban.type= IP;
				m_BanList.AddToTail(ban);
	
			}
			cur=strchr(cur,'\n');
		
		}
		
		m_bNewBanList=true;
		m_bIsRefreshing=false;




		// notify the UI of the new server info
		m_pResponseTarget->ServerResponded();
	}

}