VERRY BIG COMMAND FLAW THAT CRASHES COMMANDS
#1



Hello, I have this problem with a command (a couple) but they all work the same way and same result.

if you do this /givedrugs id amount or /gc id amount it works fine....

but if the amount is 999999999999999999999999999999999999999999999999
it will say unknown command (which you cant give that much anyway) but after that all commands that are not filterscripts will not work. all server commands turn into Unknown Command.

ofcourse i have saftey's that stop that like if you dont ask for drugs then a drugdealer cant even use /givedrugs id amount because playerwantsdrugs[playerid] == 0 and not 1. you can only use that command if you type /drugs then the playerwantsdrugs[playerid] == 1 until the timer kicks it back to 0

though the playerwantsdrugs[playerid] == 0 if you type /givedrugs anyid 99999999999999999999999
then it will crash all the commands like i said before. this also works with just /gc id amount (givecash)


i dont use dcmd , nor do i want to. here is my code. how can i stop this

Код:
if(strcmp(cmd, "/givedrugs", true) == 0) {
  if(wantsdrugs[giveplayerid] == 0) {
  SendClientMessage(playerid, COLOR_ERROR, "That player does not want drugs. Use /selldrugs ID to offer drugs to a player");
  return 1;
 	}
	if(IsSpawned[playerid] == 0) {
	SendClientMessage(playerid, COLOR_ERROR, "You are dead. You cannot use this command");
  return 1;
  }
  if(Jailed[playerid] == 1) {
	SendClientMessage(playerid, COLOR_ERROR, "You cannot use this command in jail");
  return 1;
  }
  if(InDerby[playerid] == 1) {
  SendClientMessage(playerid,COLOR_ERROR,"You cannot use this command while you are in the stadium");
  return 1;
  }
  if(cuffed[playerid] == 1) {
  SendClientMessage(playerid,COLOR_ERROR,"You are handcuffed. You cannot use this command");
  return 1;
  }
  if(gTeam[playerid] != TEAM_DRGDEL) {
  SendClientMessage(playerid,COLOR_ERROR,"You are not a Drug Dealer");
  return 1;
  }
  if(solddrugsrecent[playerid] == 1) {
  SendClientMessage(playerid,COLOR_ERROR,"Command used recently... Please wait");
  return 1;
  }
  if(PlayerDrugs[playerid] == 0) {
  SendClientMessage(playerid,COLOR_ERROR,"You are not carrying any drugs. Visit the drug house to get your supply");
  return 1;
  }
  tmp = strtok(cmdtext, idx);
  if(!strlen(tmp)) {
  SendClientMessage(playerid, COLOR_ERROR, "USAGE: /givedrugs (id) [Grams]");
  return 1;
  }
  giveplayerid = strval(tmp);
  if(!IsNumeric(tmp)) {
  SendClientMessage(playerid, COLOR_ERROR, "USAGE: /givedrugs (id) [Grams] ID Must be a number");
  return 1;
  }
//	if(IsNumeric(tmp) > 502) {
//	SendClientMessage(playerid, COLOR_ERROR, "Nice try.");
//	return 1;
//	}
	if(strval(tmp) == playerid) {
  SendClientMessage(playerid, COLOR_ERROR, "You cannot sell yourself drugs");
  return 1;
  }
  if(gTeam[giveplayerid] <=2) {
  SendClientMessage(playerid, COLOR_ERROR, "You cannot give drugs to a Law Enforcement agent");
  return 1;
  }
  tmp = strtok(cmdtext, idx);
  if(!strlen(tmp)) {
  SendClientMessage(playerid, COLOR_ERROR, "USAGE: /givedrugs (id) [Grams]");
  return 1;
  }
  new gramtogive = strval(tmp);
  if(!IsNumeric(tmp)) {
  SendClientMessage(playerid, COLOR_ERROR, "USAGE: /givedrugs (id) [Grams] Grams must be a number");
  return 1;
  }
  if(!IsPlayerConnected(giveplayerid)) {
  format(string, sizeof(string), "ID (%d) is not an active player", giveplayerid);
  SendClientMessage(playerid, COLOR_ERROR, string);
  return 1;
  }
  if(gramtogive <=0) {
  SendClientMessage(playerid, COLOR_ERROR, "Minimum amount of grams you can give in one transaction is 1 Gram");
  return 1;
  }
  if(gramtogive >=501) {
  SendClientMessage(playerid, COLOR_ERROR, "Maximum amount of grams you can give in one transaction is 500 Grams");
  return 1;
  }
  if(PlayerDrugs[playerid] < gramtogive) {
  SendClientMessage(playerid,COLOR_ERROR,"You are not carrying that much drugs. Visit the drug house to replenish your supply");
  return 1;
  }
  new dealername[24];
  new buyername[24];
  GetPlayerName(playerid,dealername, 24);
	GetPlayerName(giveplayerid,buyername, 24);
	if(GetDistanceBetweenPlayers(playerid,giveplayerid) > 7) {
  format(string, sizeof(string), "%s(%d) Is not close enough. You cannot deal drugs to that player",buyername,giveplayerid);
  SendClientMessage(playerid, COLOR_ERROR, string);
  return 1;
  }
  SendClientMessage(giveplayerid, 0xA9A9A9AA, "|_Drugs Purchased_|");
	format(string, sizeof(string), "Drug Dealer %s(%d) has given you %d grams of drugs. Make sure you pay/have paid the dealer",dealername,playerid,gramtogive);
  SendClientMessage(giveplayerid, COLOR_DODGERBLUE, string);
  SendClientMessage(giveplayerid, COLOR_DODGERBLUE, "Use /takedrugs (grams) to use drugs. Remember, cops can search you for drugs...try /throwaway in emergency");
  SendClientMessage(playerid, 0xA9A9A9AA, "|_Drugs Sold_|");
  format(string, sizeof(string), "You have given %s(%d) %d grams of drugs. Make sure you get paid",buyername,giveplayerid,gramtogive);
  SendClientMessage(playerid, 0x00C7FFAA, string);
  PlayerDrugs[playerid] -= gramtogive;
  PlayerDrugs[giveplayerid] += gramtogive;
  oscore = GetPlayerScore(playerid);
	SetPlayerScore(playerid, oscore +1);
  new current_zone;
  current_zone = player_zone[playerid];
  commitedcrimerecently[playerid] +=180;
  for(new i=0;i<MAX_PLAYERS;i++)
	{
  if(LawEnforcementRadio[i] == 1) {
  format(string, sizeof(string), "DISPATCH: (DRUG DEALING) Suspected drug deal has taken place - Suspect: %s(%d) Location: %s",dealername,playerid,zones[current_zone][zone_name]);
  SendClientMessage(i,COLOR_ROYALBLUE,string);
  
  }
  }
  new plwl = GetPlayerWantedLevel(playerid);
  SetPlayerWantedLevel(playerid, plwl +2 );
  new pcol = GetPlayerColor(playerid);
	plwl = GetPlayerWantedLevel(playerid);
	SendClientMessage(playerid, 0xA9A9A9AA, "|_Crime Commited_|");
	format(string, sizeof(string), "(DRUG DEALING) Wanted Level %d",plwl);
	SendClientMessage(playerid,pcol,string);
  return 1;
 	}
Reply
#2


Sorry for the double post but i dont think that code matters at all. But is the problem there? you see i added the isnumeric > 502 then "nice try" but it does not stop the 999999999999999999999's

Reply
#3

I'm not sure if it's a symptom of having uploaded to the forums but your indentation is terrible =o

Replace:

pawn Код:
if(IsNumeric(tmp) > 502)
with..

pawn Код:
if(giveplayerid > MAX_PLAYERS)
EDIT: It might not help that the code in question is commented out >.>

EDIT 2: You use this, having already saved strval(tmp) as giveplayerid:

pawn Код:
if(strval(tmp) == playerid)
Having already converted from string to value, you may aswell use the value instead:

pawn Код:
if(giveplayerid == playerid)
Reply
#4


Its commented out, i just added it in and it did nothing. So its not that, right? Anyone know how to fix this?
Reply
#5

Quote:
Originally Posted by Jason_Borne
Its commented out, i just added it in and it did nothing. So its not that, right? Anyone know how to fix this?
Did you try any of the other fixes in my post? There were at least 3...
Reply
#6


no because i dont know to put it in the command or on the top of onplayercommandtext
Reply
#7

Quote:
Originally Posted by Weirdosport
Replace:

pawn Код:
if(IsNumeric(tmp) > 502)
with..

pawn Код:
if(giveplayerid > MAX_PLAYERS)
Try that one. Simply replace that one line, nothing needs changing/defining.
Reply
#8

ok i added it, not tested, but how will that stop you from trying /givedrugs 1 999999999999999999999999999999999999

and crash the server
Reply
#9

add

pawn Код:
stock strint(input[])
{
    if(strlen(input) < 25) return strval(input);
    return -1;
}
to your script, and replace any calling of "strval" with "strint" (except the strval in the above function, ofc)
Reply
#10

You need to add another line, near your second "strtok" that checks if the amount of money is > The Mx Money you specify. The check you have in there at the moment only checks that the playerID is a plausible number.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)