PCL void OnMessageSent(char *message,int slot, qboolean *show, int type) {
    if(!(*show))
        return;
    if(!message) {
        *show = qfalse;
        return;
    }
    int uid = Plugin_GetPlayerUid(slot);
    time_t t = time(NULL);
    if(data.minAP->integer != 0 && uid >= data.minAP->integer) {
        return;
    }
    //Plugin_ChatPrintf(slot,"Debug: minMD = %d, time = %d, lastMessage = %d, t - lastMessage = %d\n",data.minMD->integer,t,data.players[slot].lastMessage,t - data.players[slot].lastMessage);
    if(data.minMD->integer != 0 && (t - data.players[slot].lastMessage < data.minMD->integer)) {
        *show = qfalse;
        if(data.renMD->boolean)
            data.players[slot].lastMessage = t;
        return;
    }
    // Max messages per minute check
    int i,j=0;
    for(i=0; ( i<ANTISPAM_MAXMESSAGES) && (data.players[slot].messages[i] != 0) && (t - data.players[slot].messages[i] > 60); ++i);
    // the loop above iterates on the messages array until it's end, value of 0 or message older than 1 minute
    // now the i value holds the number of messages in the messages array which are older than 60 seconds + 1
    // we need to remove those
    if(i!=0) {
        for(j=0; j<ANTISPAM_MAXMESSAGES && i<ANTISPAM_MAXMESSAGES && data.players[slot].messages[j] != 0; ++i,++j);
        {
            data.players[slot].messages[j] = data.players[slot].messages[i];
            data.players[slot].messages[i] = 0;
        }
    }
    Plugin_ChatPrintf(slot,"Debug: %d, %d, %d, %d.\n",j,i,data.maxMPM->integer,data.maxMPM->latchedinteger);
    for(i=j; i<ANTISPAM_MAXMESSAGES; ++i) {
        data.players[slot].messages[i] = 0;
    }

    // j now holds the value of how many messages this player has sent in the last 60 seconds. If it is too much - dont show the msg
    // if it is ok - show the message and add time to messages[j]
    if(j<data.maxMPM->integer) {
        data.players[slot].messages[j] = t;
        data.players[slot].lastMessage = t;
        *show = qtrue;
    }
    else {
        *show = qfalse;
        Plugin_ChatPrintf(slot,"^2AntiSpam: you can send next chat message in %d seconds.",60 - t - data.players[slot].messages[0]);
    }
}
Exemple #2
0
void AdminCmds::SM_Chat(const char* line, int clnum)
{
  char chattername[256];
  char cleanname[256];
  int i;

  if(line[0] == 0)
  {
    return;
  }

  if ( clnum >= 0 )
  {
    Q_strncpyz(cleanname, Plugin_GetPlayerName(clnum), sizeof(cleanname));
    Q_CleanStr(cleanname);
    if(Plugin_CanPlayerUseCommand(clnum, "sm_chat"))
    {
        Com_sprintf(chattername, sizeof(chattername), "^3%s", cleanname);
    }else{
        Com_sprintf(chattername, sizeof(chattername), "^2%s", cleanname);
    }
  }else{
    Q_strncpyz(chattername, "^1Console", sizeof(chattername));
  }

  for ( i = 0; i < Plugin_GetSlotCount(); ++i )
  {
    if ( Plugin_CanPlayerUseCommand(i, "sm_chat") || i == clnum)
    {
      Plugin_ChatPrintf(i, "^3[^0AdminChat^3]^7 (%s^7): %s", chattername, line);
    }
  }
}
Exemple #3
0
//For using chat with @@ prefix
void AdminCmds::SM_PSay(const char* msg, int source)
{
  int i;
  char message[1024];
  char cleannames[128];
  char cleannamed[128];

  Cmd_TokenizeString(msg);

  if(Cmd_Argc() < 2)
  {
    Plugin_ChatPrintf(source, "Usage: @@player message");
    return;
  }

  client_t* cl = Plugin_SV_Cmd_GetPlayerClByHandle(Cmd_Argv(0));

  if(cl == NULL)
  {
    Plugin_ChatPrintf(source, "No player for %s found", Cmd_Argv(0));
    return;
  }
  if(cl->state < CS_ACTIVE)
  {
    Plugin_ChatPrintf(source, "Player %s is not in active", cl->name);
    return;
  }

  message[0] = '\0';
  for(i = 1; i < Cmd_Argc(); ++i)
  {
    Q_strcat(message, sizeof(message), Cmd_Argv(i));
    Q_strcat(message, sizeof(message), " ");
  }

  int destination = NUMFORCLIENT(cl);

  if(source == destination)
  {
      Plugin_ChatPrintf(source, "Why would you send a message to yourself?");
      return;
  }

  Q_strncpyz(cleannames, Plugin_GetPlayerName(source), sizeof(cleannames));
  Q_strncpyz(cleannamed, cl->name, sizeof(cleannamed));

  Q_CleanStr(cleannames);
  Q_CleanStr(cleannamed);

  Plugin_ChatPrintf(source, "^7%s ^1>> ^7%s: %s", cleannames, cleannamed, message);
  Plugin_ChatPrintf(destination, "^7%s ^1>> ^7%s: %s", cleannames, cleannamed, message);
}