[Help] Server closed the connection on connecting
#1

Hi,
I've made an kick script
When i kick myself (for testing) it works correctly but when i try to connect again, server says "Server closed the connection.".
PHP код:
CMD:kick(playeridparams[])
{
    new
        
targetid,
        
Reason[50],
        
AdminName[MAX_PLAYERS],
        
TargetName[MAX_PLAYER_NAME],
        
kickmsg[128];
    if(
PlayerInfo[pAdmin][playerid]>=1)
    {
         if(
sscanf(params"us[50]"targetidReason)) return SendClientMessage(playerid0xE90A0AFF"[CMD] /kick [playerid] [reason]");
        if(!
IsPlayerConnected(targetid)) return SendClientMessage(playerid0xE90A0AFF"[ERROR] Invalid player ID.");
        
GetPlayerName(playeridAdminNamesizeof(AdminName));
        
GetPlayerName(targetidTargetNamesizeof(TargetName));
        
format(kickmsgsizeof(kickmsg), "[ADMIN] Admin %s has kicked %s [Reason: %s]"AdminNameTargetNameReason);
        
SendClientMessageToAll(0xE90A0AFFkickmsg);
        
SetTimerEx("KickPlayer"5001"i"playerid);
    }
    else
    {
        
SendClientMessage(playerid0xE90A0AFF"[ERROR] You are not authorized.");
    }
    return 
1;

PHP код:
forward KickPlayer(playerid);
public 
KickPlayer(playerid)
{
    
Kick(playerid);
    return 
1;

In
Код:
Kick(playerid);
what should i write? (playerid or targetid?)
[/PHP]
Reply
#2

Write it like this:
PHP код:
CMD:kick(playerid,params[])
{
    new 
targetid,Reason[50],AdminName[MAX_PLAYER_NAME],TargetName[MAX_PLAYER_NAME],kickmsg[145];
    if(
PlayerInfo[pAdmin][playerid] >= 1)
    {
        if(
sscanf(params,"us[50]",targetid,Reason))return SendClientMessage(playerid,0xE90A0AFF,"[CMD] /kick [playerid] [reason]");
        if(!
IsPlayerConnected(targetid))return SendClientMessage(playerid,0xE90A0AFF,"[ERROR] Invalid player ID.");
        
GetPlayerName(playerid,AdminName,MAX_PLAYER_NAME);
        
GetPlayerName(targetid,TargetName,MAX_PLAYER_NAME);
        
format(kickmsg,sizeof kickmsg,"[ADMIN] Admin %s has kicked %s [Reason: %s]",AdminName,TargetName,Reason);
        
SendClientMessageToAll(0xE90A0AFF,kickmsg);
        
SetTimerEx("KickPlayer",500,0,"i",targetid);
        return 
1;
    }
    
SendClientMessage(playerid,0xE90A0AFF,"[ERROR] You are not authorized.");
    return 
1;
}
forward KickPlayer(playerid);
public 
KickPlayer(playerid)
{
    
Kick(playerid);
    return 
1;

You have to start the timer with targetid and the repeat as 0.
Reply
#3

Kick(playerid) that is in side the timer stays exactly the same, because targetid is not defined globally and gets passed throw into the playerid parem anyway. AdminName[MAX_PLAYERS] should be AdminName[MAX_PLAYER_NAME]. However, it is just the size of the array ^ hes probably right about the timers. I don't use timers very often :P.
Reply
#4

@CNMike:
It doesn't crash. He start a timer with the repeat 1 and "playerid". So if he disconnected the timer is going on and when he connects again he will kick because the timer is already going on with the "playerd".
Reply
#5

Quote:
Originally Posted by MarvinPWN
Посмотреть сообщение
Write it like this:
PHP код:
CMD:kick(playerid,params[])
{
    new 
targetid,Reason[50],AdminName[MAX_PLAYER_NAME],TargetName[MAX_PLAYER_NAME],kickmsg[145];
    if(
PlayerInfo[pAdmin][playerid] >= 1)
    {
        if(
sscanf(params,"us[50]",targetid,Reason))return SendClientMessage(playerid,0xE90A0AFF,"[CMD] /kick [playerid] [reason]");
        if(!
IsPlayerConnected(targetid))return SendClientMessage(playerid,0xE90A0AFF,"[ERROR] Invalid player ID.");
        
GetPlayerName(playerid,AdminName,MAX_PLAYER_NAME);
        
GetPlayerName(targetid,TargetName,MAX_PLAYER_NAME);
        
format(kickmsg,sizeof kickmsg,"[ADMIN] Admin %s has kicked %s [Reason: %s]",AdminName,TargetName,Reason);
        
SendClientMessageToAll(0xE90A0AFF,kickmsg);
        
SetTimerEx("KickPlayer",500,0,"i",targetid);
        return 
1;
    }
    
SendClientMessage(playerid,0xE90A0AFF,"[ERROR] You are not authorized.");
    return 
1;
}
forward KickPlayer(playerid);
public 
KickPlayer(playerid)
{
    
Kick(playerid);
    return 
1;

You have to start the timer with targetid and the repeat as 0.
Fixed.
Thanks, +REP
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)