Server crashing on command
#1

Server crashes or restarts when someone uses this command:

Код:
CMD:ban(playerid, params[])
{
    new string[128], str[356], id, reason[1024], ip[50];
	if(PlayerInfo[playerid][pAdmin] >= 4)
	{
	    if(sscanf(params, "us[1024]", id, reason)) return GameTextForPlayer(playerid, "~g~/ban~w~~n~(id)~w~~n~(reason)",4500,3);
		if(PlayerInfo[playerid][pAdmin] < PlayerInfo[id][pAdmin]) return ErrorMessages(playerid, 3);
		if(id == INVALID_PLAYER_ID) return GameTextForPlayer(playerid, "~g~Player is not connected",4500,3);
	    PlayerInfo[id][BanC]++;
		GetPlayerIp(id, ip, sizeof(ip));
	    format(str, sizeof(str), "%s(%d) has been banned by Administrator %s(%d) (Reason: %s) (Ip of Player: %s)", GetName(id), id, GetName(playerid), playerid, reason, ip);
   		SaveIn("banlog", str);
	    format(str, sizeof(str), ""COL_GREEN"Banned Player %s(%d)\n\n- Name: %s\n- Account ID: %d\n- Reason: %s\r\n\n", GetName(id),id,GetName(id),PlayerInfo[id][Accountid],reason);
	    ShowPlayerDialog(playerid, 900, DIALOG_STYLE_MSGBOX, ""COL_GREEN"UGF - Banned",str,"OK","");
	    format(string, sizeof(string), "%s(%d) has been banned by Administrator %s(%d) (Reason: %s)", GetName(id), id, GetName(playerid), playerid, reason);
	    SendClientMessageToAll(BAN, string);
	    format(string, sizeof(string), "You have been banned by Administrator %s(%d) (Reason: %s)", GetName(playerid), playerid, reason);
	    SendClientMessage(id, BAN, string);
		PlayerInfo[id][Banned] = 1;
		SetTimerEx("Kick", 1000, false, "i", playerid);
	}
	else return 0;
	return 1;
}
Reply
#2

Try this. I'm not so sure it will work, but still, try it.

PHP код:
CMD:ban(playeridparams[])
{
    new 
string[128], str[356], idreason[1024], ip[50];
    if(
PlayerInfo[playerid][pAdmin] >= 4)
    {
        if(
sscanf(params"us[1024]"idreason)) return GameTextForPlayer(playerid"~r~/ban~p~(id)~b~(reason)",4500,3);
        if(
PlayerInfo[playerid][pAdmin] < PlayerInfo[id][pAdmin]) return ErrorMessages(playerid3);
        if(!
IsPlayerConnected(id)) return GameTextForPlayer(playerid"~r~Player is not connected",4500,3);
        
PlayerInfo[id][BanC]++;
        
GetPlayerIp(idipsizeof(ip));
        
format(strsizeof(str), "%s(%d) has been banned by Administrator %s(%d) (Reason: %s) (Ip of Player: %s)"GetName(id), idGetName(playerid), playeridreasonip);
           
SaveIn("banlog"str);
        
format(strsizeof(str), ""COL_GREEN"Banned Player %s(%d)\n\n- Name: %s\n- Account ID: %d\n- Reason: %s\r\n\n"GetName(id),id,GetName(id),PlayerInfo[id][Accountid],reason);
        
ShowPlayerDialog(playerid900DIALOG_STYLE_MSGBOX""COL_GREEN"UGF - Banned",str,"OK","");
        
format(stringsizeof(string), "%s(%d) has been banned by Administrator %s(%d) (Reason: %s)"GetName(id), idGetName(playerid), playeridreason);
        
SendClientMessageToAll(BANstring);
        
format(stringsizeof(string), "You have been banned by Administrator %s(%d) (Reason: %s)"GetName(playerid), playeridreason);
        
SendClientMessage(idBANstring);
        
PlayerInfo[id][Banned] = 1;
        
SetTimerEx("Kick"1000false"i"playerid);
    }
    else return 
0;
    return 
1;

Reply
#3

Use crashdetect plugin and give me results. It is probably array index out of bounds or because of these huge unused strings..
Reply
#4

Reduce the size of those arrays.
Array "str" is really interesting, you're including the reason into it but it's only 356 chars long, while the reason is 1024 chars long.

On the other end, your chat is limited to 144 chars, so there is no reason why "reason" should be 1024 chars long.

Use "string[256]" for both the dialog and all messages, it should be enough, and make "reason[128]" instead of 1024.
Also IP is too long. IP[16] should be enough. The longest IP is one with 4 numbers of 3 digits each like 123.123.123.123 and counts 15 chars, but you need 16 chars for the added 0 character to indicate the end of the string.

Also add a check to see if "id" isn't 65535 (invalid player id), otherwise you could operate on index 65535 of your PlayerInfo array and have Array-out-of-bounds issues.
Place this immediately below the sscanf line.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)