Can this crash my server?
#1

Код:
if(strcmp(cmd, "/ban", true) == 0)
{
	new reason[256];
	if (Admin[playerid] < 4 && !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, RED, "You are not an admin with the required level.");

	tmp = strtok(cmdtext, idx);

	if(!strlen(tmp)) return SendClientMessage(playerid, ORANGE, "USAGE: /ban [playerid] [reason]");

	giveplayerid = ReturnUser(tmp);

	if(giveplayerid == INVALID_PLAYER_ID)
	{
		format(string, sizeof(string), "%s is not an active player.", tmp);
		SendClientMessage(playerid, RED, string);
		return 1;
	}

	GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
	GetPlayerName(playerid, sendername, sizeof(sendername));

	new length = strlen(cmdtext);

	while ((idx < length) && (cmdtext[idx] <= ' '))
	{
		idx++;
	}
	new offset = idx;
	while ((idx < length) && ((idx - offset) < (sizeof(reason) - 1)))
	{
		reason[idx - offset] = cmdtext[idx];
		idx++;
	}
	reason[idx - offset] = EOS;

	if(!strlen(reason)) return SendClientMessage(playerid, ORANGE, "USAGE: /ban [playerid] [reason]");
	else
	{
		new sstring[256];
		new ip[128];
		new name[50];
		GetPlayerName(giveplayerid,name,50);
		strins(name,"users/",0);
		dini_IntSet(name,"Banned",1);
		dini_Set(name,"BanReason",reason);
		SendClientMessage(giveplayerid, -1, "Go on our site for unban: {FF0000}http://cls.irc.su");
		Kick(giveplayerid);
		format(string,sizeof(string),"*** BAN: %s has been banned by Admin %s (%s)",giveplayer,sendername,reason);
		printf(string);
		SendClientMessageToAll(COLOR_SYSTEM,string);
		TogglePlayerControllable(giveplayerid,0);
		BanLog(string);
		GetPlayerIp(giveplayerid,ip,128);
		format(sstring, sizeof(sstring),"Player's IP: %s",ip);
		SendClientMessageToAdmins(COLOR_SYSTEM,sstring,1);
	}
	return 1;
}
Take a look at "Kick(giveplayerid);"

although that's the /ban command ,there is Kick(giveplayerid);..
can the server crash due to this?
If I'll add Bangiveplayerid);when I ban someone,the whole IP Class is banned,or something like this
Reply
#2

I don't know if it crashes or not, Use zcmd kick and ban cmds, Also in this way dcmd and strcmp does not show errors sometimes and no warnings though but it not does not work in server, When you type the cmd it says 'Unknown Command' or sometimes crashes but zcmd and ycmds works fine and when zcmd and ycmd does not show errors its 99 percent sure
It will work ingame.

Thanks
Reply
#3

You made serveral mistakes

1. Check if player is connected with INVALID_PLAYER_ID, is not enough
2. you cant even enter reason longer than 128 chars
3. Why you need to get name 3x times
4. Why TogglePlayerControllable(giveplayerid,0); on kick ?
5. You cant get IP of disconnected player ( you kicked him before get ip )
6. Always use braces, else you can lose your self in script
pawn Код:
if(strcmp(cmd, "/ban", true) == 0)
{
    new reason[128],ip[32];
    if (Admin[playerid] < 4 && !IsPlayerAdmin(playerid))
    {
        SendClientMessage(playerid, RED, "You are not an admin with the required level."); return 1;
    }
    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp))
    {
        SendClientMessage(playerid, ORANGE, "USAGE: /ban [playerid] [reason]"); return 1;
    }
    giveplayerid = ReturnUser(tmp);
    if(IsPlayerConnected(giveplayerid))
    {
        GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
        GetPlayerName(playerid, sendername, sizeof(sendername));
        new length = strlen(cmdtext);
        while ((idx < length) && (cmdtext[idx] <= ' ')) { idx++; }
        new offset = idx;
        while ((idx < length) && ((idx - offset) < (sizeof(reason) - 1)))
        {
            reason[idx - offset] = cmdtext[idx];
            idx++;
        }
        reason[idx - offset] = EOS;
        if(!strlen(reason))
        {
            SendClientMessage(playerid, ORANGE, "USAGE: /ban [playerid] [reason]"); return 1;
        }
        strins(name,"users/",0);
        dini_IntSet(name,"Banned",1);
        dini_Set(name,"BanReason",reason);
        SendClientMessage(giveplayerid, -1, "Go on our site for unban: {FF0000}http://cls.irc.su");
        format(string,sizeof(string),"*** BAN: %s has been banned by Admin %s (%s)",giveplayer,sendername,reason);
        printf(string);
        SendClientMessageToAll(COLOR_SYSTEM,string);
        BanLog(string);
        GetPlayerIp(giveplayerid,ip,sizeof(ip));
        format(string, sizeof(string),"Player's IP: %s",ip);
        SendClientMessageToAdmins(COLOR_SYSTEM,string,1);
        Kick(giveplayerid);
    }
    else
    {
        SendClientMessage(playerid, ORANGE, "This player is not connected.");
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)