Server freezing when using /kick
#1

OK, I don't know whats wrong, but every time I use the /kick command, my server freezes, looses connection, etc for a few seconds..

I'm hopeing someone can find the problem in the code..

pawn Код:
dcmd_kick(playerid,params[])
{
    if(pInfo[playerid][Level] < 1)
    {
        return SendClientMessage(playerid,COLOR_RED,"You must be level 1 to kick someone!");
    }
    new giveplayerid,reason[80];
    if(sscanf(params,"ds",giveplayerid,reason))
    {
        SendClientMessage(playerid,COLOR_WHITE,"Usage: /kick (id) [reason]");
        return 1;
    }
    if(!IsPlayerConnected(giveplayerid))
    {
      SendClientMessage(playerid,COLOR_RED,"ERROR: Invalid ID!");
      return 1;
    }
    if(giveplayerid == playerid)
    {
      SendClientMessage(playerid,COLOR_RED,"ERROR: You cannot kick yourself.");
      return 1;
    }
    new string[128],name[24];
    GetPlayerName(giveplayerid,name,24);
    SendClientMessage(playerid,COLOR_RED,string);
    format(string,128,"%s(%d) has been kicked by %s(%d). Reason: %s.",name,giveplayerid,ReturnPlayerName(playerid),playerid,reason);
    SendClientMessageToAll(COLOR_RED,string);
    SendClientMessage(giveplayerid,COLOR_RED,"SERVER: You have been kicked from the server.");
    SetPlayerPos(giveplayerid,10000,10000,10000);
   
    ResetPlayerWeapons(giveplayerid);
    GivePlayerWeapon(giveplayerid,10,1);
    SetPlayerWeather(giveplayerid,150);
    SetPlayerSkin(giveplayerid,77);
    Kick(giveplayerid);
    return 1;
}
Thanks
Reply
#2

I don't see what's with the useless code before the Kick(). Try using 'z' instead of 's' in the sscanf(), just to see the outcome.
Reply
#3

good luck man, also PM me on msn cuz i missed couple meetings
Reply
#4

Debug your code and you'll know where the problem is.
Reply
#5

Quote:
Originally Posted by Don Correlli
Debug your code and you'll know where the problem is.
How do I "Debug" my code?
Reply
#6

Here's an example:
pawn Код:
MyFunction()
{
  printf("DEBUG: debugMsg0 - MyFunction init.");
  CallMyFunction2(playerid);
  printf("DEBUG: debugMsg1 - passed.");
  // other code.
  if(_WHATEVER_DEFINE_ == 1)
  {
    // other code.
    printf("DEBUG: debugMsg2 - _WHATEVER_DEFINE_ is 1.");
    // other code.
  }
  // other code.
  return 1;
}
Reply
#7

Quote:
Originally Posted by Don Correlli
Here's an example:
pawn Код:
MyFunction()
{
  printf("DEBUG: debugMsg0 - MyFunction init.");
  CallMyFunction2(playerid);
  printf("DEBUG: debugMsg1 - passed.");
  // other code.
  if(_WHATEVER_DEFINE_ == 1)
  {
    // other code.
    printf("DEBUG: debugMsg2 - _WHATEVER_DEFINE_ is 1.");
    // other code.
  }
  // other code.
  return 1;
}
So where would I put the command, then where would I put MyFunction()?
Reply
#8

That was just an example how to use debug-messages (printf).
Reply
#9

Shouldnt you change the sscansf to:
pawn Код:
if(sscanf(params,"is",giveplayerid,reason))
Reply
#10

Quote:
Originally Posted by whooper
Shouldnt you change the sscansf to:
pawn Код:
if(sscanf(params,"is",giveplayerid,reason))
Would that be why the server crashes when i use the command?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)