Example #1
0
void parseCommand(char* pMsg)
{
	if (pMsg == NULL) return;

	char   seps[] = "= \t\n";
	char   * token, * token2;
	class  CStrTok * pStrTok;
	char * cName[11];
	char buff[100];
	BOOL bFlag;
	int i;
	pStrTok = new class CStrTok(pMsg, seps);
	token = pStrTok->pGet();
	token2 = pStrTok->pGet();
	bFlag = false;
	/*	if (memcmp(pMsg,"ascii ",5) == 0) {
	//if (strlen(token) == 1) {
	bFlag = TRUE;
	char znak[1];
	memcpy(znak,token,1);
	wsprintf(buff,"AscII%d/%s.txt",znak[0],token);
	PutLogList(buff);
	}*/

	if (memcmp(pMsg,"check ",6) == 0) {
		if(!g_clientList)
		{
			PutLogList("No client list! Server is probably off.");
			return;
		}

		if (token2 != NULL) {
			ZeroMemory(cName, sizeof(cName));
			memcpy(cName, token2,11);
		} 


		if (cName != NULL) {

			for (i = 1; i < MAXCLIENTS; i++)
				if ((g_clientList[i] != NULL) && (memcmp(g_clientList[i]->m_cCharName, cName, 10) == 0)) {
					ZeroMemory(buff, sizeof(buff));
					if ((g_clientList[i] != NULL) && (memcmp(g_clientList[i]->m_cCharName, cName, 10) == 0)) {
						wsprintf(buff, "%s:    Str:%d  Dex:%d  Vit:%d  Int:%d  Mag:%d  Chr:%d    Map:%s - %i , %i    Admin level:%i", g_clientList[i]->m_cCharName, g_clientList[i]->GetStr(),  g_clientList[i]->GetDex(), g_clientList[i]->GetVit(), g_clientList[i]->GetInt(),g_clientList[i]->GetMag(), g_clientList[i]->m_iCharisma, g_clientList[i]->m_cMapName, g_clientList[i]->m_sX, g_clientList[i]->m_sY, g_clientList[i]->m_iAdminUserLevel);
						PutLogList(buff);
					}else{
						wsprintf(buff,"Player %s is offline.", cName);
						PutLogList(buff);
					}
				}
		}
	}
	/*
	if (memcmp(pMsg,"start apocalypse",16) == 0) {
	if(!g_game)
	{
	PutLogList("Couldn't get the game server pointer! Server is probably off.");
	return;
	}
	g_game->GlobalStartApocalypseMode();
	}

	if (memcmp(pMsg,"end apocalypse",14) == 0) {
	if(!g_game)
	{
	PutLogList("Couldn't get the game server pointer! Server is probably off.");
	return;
	}
	g_game->GlobalEndApocalypseMode();
	}
	*/

	else if (memcmp(pMsg,"start heldenian",15) == 0) {
		if(!g_game)
		{
			PutLogList("Couldn't get the game server pointer! Server is probably off.");
			return;
		}
		g_game->StartHeldenianMode();
	}
	else if (memcmp(pMsg,"end heldenian 1",15) == 0) {
		if(!g_game)
		{
			PutLogList("Couldn't get the game server pointer! Server is probably off.");
			return;
		}
		g_game->HeldenianEndWarNow(g_game->m_iHeldenianType, ARESDEN); 
	}
	else if (memcmp(pMsg,"end heldenian 2",15) == 0) {
		if(!g_game)
		{
			PutLogList("Couldn't get the game server pointer! Server is probably off.");
			return;
		}
		g_game->HeldenianEndWarNow(g_game->m_iHeldenianType, ELVINE); 
	}
	else if (memcmp(pMsg,"start crusade",13) == 0) {
		if(!g_game)
		{
			PutLogList("Couldn't get the game server pointer! Server is probably off.");
			return;
		}
		g_game->GlobalStartCrusadeMode();
	}else if (memcmp(pMsg,"end crusade",11) == 0) {
		if(!g_game)
		{
			PutLogList("Couldn't get the game server pointer! Server is probably off.");
			return;
		}
		g_game->ManualEndCrusadeMode(0);
	}else if (memcmp(pMsg,"benchmark",9) == 0) {
		if(!g_game)
		{
			PutLogList("Couldn't get the game server pointer! Server is probably off.");
			return;
		}

		int ix = 60, iy = 60;
		Point p;
		p.x = p.y = 60;

		CMap * map = g_game->m_pMapList[1];

		DWORD time;
		time = timeGetTime();
		uint32 count = 0;
		for(uint32 i=0; i < 100000000; i++)
		{
			count += map->bGetIsMoveAllowedTile(p);
		}

		char txt[50];
		ZeroMemory(txt, sizeof(txt));

		wsprintf(txt, "time: %u, %u", timeGetTime() - time, count);
		PutLogList(txt);
	}
	else if (memcmp(pMsg,"broadcast ",10) == 0) {
		if(!g_clientList)
		{
			PutLogList("No client list! Server is probably off.");
			return;
		}
		if(!g_game)
		{
			PutLogList("Couldn't get the game server pointer! Server is probably off.");
			return;
		}
		//tLogList(token2);
		char ss[100];
		ZeroMemory(ss,100);
		memcpy(ss,pMsg,strlen(pMsg));
		ss[0]=' ';
		ss[1]=' ';
		ss[2]=' ';
		ss[3]=' ';
		ss[4]=' ';
		ss[5]=' '; 
		ss[6]=' ';
		ss[7]=' ';
		ss[8]=' ';
		ss[9]=' ';
		int i;
		char*p=ss;
		while(isspace(*p) && (*p))p++;
		memmove(ss,p,strlen(p)+1);
		wsprintf(ss,"%s",ss);
		int do_ilu;
		do_ilu=0;
		// Send to clients on current HG
		for (i = 1; i < MAXCLIENTS; i++) {
			if (g_clientList[i] != NULL) {
				g_game->ShowClientMsg(i,ss);
				do_ilu++;
			}
		}

		// Send to all other HGs through Login Server
		if (strlen(ss) < 90) {
			char * cp2;
			WORD * wp;
			char * pkt = new char[strlen(ss) + 20];
			ZeroMemory(pkt, strlen(ss) + 20);
			cp2 = (char *)pkt;
			*cp2 = GSM_CHATMSG;
			cp2++;
			*cp2 = CHAT_GM;
			cp2++;
			//ip = (int *)cp2;
			//*ip = NULL;
			cp2 += 4;
			strcpy(cp2, "Server");
			cp2 += 10;
			wp  = (WORD *)cp2;
			*wp = (WORD)strlen(ss);
			cp2 += 2;
			strcpy(cp2, ss);
			cp2 += strlen(ss);
			g_game->bStockMsgToGateServer(pkt, strlen(ss) + 18);
		}

		char buff[100];
		wsprintf(buff,"(!) The Message '%s' was sent to all players ( %d )",ss,do_ilu);
		PutLogList(buff);
	}else if(memcmp(pMsg, "maplist", 7) == 0){
		if(!g_mapList) return;

		for (i = 0; i < MAXMAPS; i++)
			if (g_mapList[i] != NULL) {
				wsprintf(buff, "[%d] %s", g_mapList[i]->m_iTotalActiveObject, g_mapList[i]->m_cName);
				PutLogList(buff);
			}
	}else if(memcmp(pMsg, "clientlist", 10) == 0){
		if(!g_clientList) return;

		for (i = 0; i < MAXCLIENTS; i++)
			if (g_clientList[i] != NULL) {
				wsprintf(buff, "Char:%s(%d) %s on %s (%s)", g_clientList[i]->m_cCharName, 
					g_clientList[i]->m_iLevel,
					GetFactionName(g_clientList[i]->GetFaction()),
					g_clientList[i]->m_cAccountName,
					g_clientList[i]->m_cIPaddress);
				PutLogList(buff);
			}
	}else{
		wsprintf(buff,"(!!!) %s - unrecognized commad",pMsg);
		PutLogList(buff);
	}

}