<commit_before>/* bzflag
 * Copyright (c) 1993 - 2004 <NAME>
 *
 * This package is free software;  you can redistribute it and/or
 * modify it under the terms of the license found in the file
 * named LICENSE that should have accompanied this file.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#ifdef _MSC_VER
#pragma warning( 4:4786)
#endif

// interface header
#include "commands.h"

// system implementation headers
#include <vector>
#include <string>
#ifdef HAVE_CSTDIO
#include <cstdio>
#else
#include <stdio.h>
#endif
#ifdef HAVE_CSTRING
#include <cstring>
#else
#include <string.h>
#endif

// common implementation headers
#include "Address.h"
#include "CommandManager.h"
#include "LagInfo.h"
#include "NetHandler.h"
#include "PlayerInfo.h"
#include "VotingArbiter.h"
#include "global.h"
#include "version.h"

// local implementation headers
#include "CmdLineOptions.h"
#include "FlagHistory.h"
#include "FlagInfo.h"
#include "PackVars.h"
#include "Permissions.h"
#include "RecordReplay.h"


#if defined(_WIN32)
#define popen _popen
#define pclose _pclose
#endif


// FIXME -- need to pull communication out of bzfs.cxx...

// externs that poll, veto, vote, and clientquery require
extern void sendMessage(int playerIndex, PlayerId targetPlayer, const char *message);
extern CmdLineOptions *clOptions;
extern uint16_t curMaxPlayers;
extern int NotConnected;

// externs that ghost needs
extern void removePlayer(int playerIndex, const char *reason, bool notify=true);

// externs that shutdownserver requires
extern bool done;

// externs that superkill and gameover requires
extern bool gameOver;
extern char *getDirectMessageBuffer();
extern void broadcastMessage(uint16_t code, int len, const void *msg);

// externs needed by the countdown command
#include "TimeKeeper.h"
extern TimeKeeper gameStartTime;
#include "PlayerInfo.h"
extern TeamInfo team[NumTeams];
extern void sendTeamUpdate(int playerIndex = -1, int teamIndex1 = -1, int teamIndex2 = -1);
extern int numFlags;
extern void zapFlag(int flagIndex);
extern void sendFlagUpdate(int flagIndex = -1, int playerIndex = -1);
extern void resetFlag(int flagIndex);

// externs that countdown requires
extern bool countdownActive;

// externs that identify and password requires
extern void sendIPUpdate(int targetPlayer = -1, int playerIndex = -1);


int getTarget(const char *victimname) {
  GameKeeper::Player *targetData;
  int i;
  for (i = 0; i < curMaxPlayers; i++) {
    targetData = GameKeeper::Player::getPlayerByIndex(i);
    if (targetData && strncasecmp(targetData->player.getCallSign(),
				  victimname, 256) == 0) {
      break;
    }
  }
  return i;
}


void handleMeCmd(GameKeeper::Player *playerData, const char *message)
{
  int t = playerData->getIndex();
  std::string message2;

  if (!playerData->accessInfo.hasPerm(PlayerAccessInfo::actionMessage)) {
    char reply[MessageLen] = {0};
    sprintf(reply,"%s, you are not presently authorized to perform /me actions", playerData->player.getCallSign());
    sendMessage(ServerPlayer, t, reply);
    return;
  }

  /* wrap the action using *\t(.*)\t* for effect. the \t is converted
   * to a space, but allows new clients to display differently.
   */
  message2 = string_util::format("*\t%s %s\t*", playerData->player.getCallSign(), message + 4);
  sendMessage(t, AllPlayers, message2.c_str());
}


void handleMsgCmd(GameKeeper::Player *playerData, const char *message)
{
  int from = playerData->getIndex();
  int to;

  std::string message2;
  size_t callsignStart=0, callsignEnd=0, messageStart=0;

  if (!playerData->accessInfo.hasPerm(PlayerAccessInfo::privateMessage)) {
    char reply[MessageLen] = {0};
    sprintf(reply,"%s, you are not presently authorized to /msg people privately", playerData->player.getCallSign());
    sendMessage(ServerPlayer, from, reply);
    return;
  }

  // start from after "/msg"
  std::string arguments = &message[4];
  std::string recipient = std::string("");

  // skip any leading whitespace
  callsignStart = 0;
  while ((callsignStart < arguments.size()) &&
	 (isspace(arguments[callsignStart]))) {
    callsignStart++;
  }

  // find the player name, optionally quoted
  if ( arguments[callsignStart] == '"' ) {
    callsignStart++;

    // find the trailing quote
    bool foundQuote = false;
    callsignEnd = callsignStart;<commit_msg>make sure /msg is followed by whitespace<commit_after>/* bzflag
 * Copyright (c) 1993 - 2004 <NAME>
 *
 * This package is free software;  you can redistribute it and/or
 * modify it under the terms of the license found in the file
 * named LICENSE that should have accompanied this file.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#ifdef _MSC_VER
#pragma warning( 4:4786)
#endif

// interface header
#include "commands.h"

// system implementation headers
#include <vector>
#include <string>
#ifdef HAVE_CSTDIO
#include <cstdio>
#else
#include <stdio.h>
#endif
#ifdef HAVE_CSTRING
#include <cstring>
#else
#include <string.h>
#endif

// common implementation headers
#include "Address.h"
#include "CommandManager.h"
#include "LagInfo.h"
#include "NetHandler.h"
#include "PlayerInfo.h"
#include "VotingArbiter.h"
#include "global.h"
#include "version.h"

// local implementation headers
#include "CmdLineOptions.h"
#include "FlagHistory.h"
#include "FlagInfo.h"
#include "PackVars.h"
#include "Permissions.h"
#include "RecordReplay.h"


#if defined(_WIN32)
#define popen _popen
#define pclose _pclose
#endif


// FIXME -- need to pull communication out of bzfs.cxx...

// externs that poll, veto, vote, and clientquery require
extern void sendMessage(int playerIndex, PlayerId targetPlayer, const char *message);
extern CmdLineOptions *clOptions;
extern uint16_t curMaxPlayers;
extern int NotConnected;

// externs that ghost needs
extern void removePlayer(int playerIndex, const char *reason, bool notify=true);

// externs that shutdownserver requires
extern bool done;

// externs that superkill and gameover requires
extern bool gameOver;
extern char *getDirectMessageBuffer();
extern void broadcastMessage(uint16_t code, int len, const void *msg);

// externs needed by the countdown command
#include "TimeKeeper.h"
extern TimeKeeper gameStartTime;
#include "PlayerInfo.h"
extern TeamInfo team[NumTeams];
extern void sendTeamUpdate(int playerIndex = -1, int teamIndex1 = -1, int teamIndex2 = -1);
extern int numFlags;
extern void zapFlag(int flagIndex);
extern void sendFlagUpdate(int flagIndex = -1, int playerIndex = -1);
extern void resetFlag(int flagIndex);

// externs that countdown requires
extern bool countdownActive;

// externs that identify and password requires
extern void sendIPUpdate(int targetPlayer = -1, int playerIndex = -1);


int getTarget(const char *victimname) {
  GameKeeper::Player *targetData;
  int i;
  for (i = 0; i < curMaxPlayers; i++) {
    targetData = GameKeeper::Player::getPlayerByIndex(i);
    if (targetData && strncasecmp(targetData->player.getCallSign(),
				  victimname, 256) == 0) {
      break;
    }
  }
  return i;
}


void handleMeCmd(GameKeeper::Player *playerData, const char *message)
{
  int t = playerData->getIndex();
  std::string message2;

  if (!playerData->accessInfo.hasPerm(PlayerAccessInfo::actionMessage)) {
    char reply[MessageLen] = {0};
    sprintf(reply,"%s, you are not presently authorized to perform /me actions", playerData->player.getCallSign());
    sendMessage(ServerPlayer, t, reply);
    return;
  }

  /* wrap the action using *\t(.*)\t* for effect. the \t is converted
   * to a space, but allows new clients to display differently.
   */
  message2 = string_util::format("*\t%s %s\t*", playerData->player.getCallSign(), message + 4);
  sendMessage(t, AllPlayers, message2.c_str());
}


void handleMsgCmd(GameKeeper::Player *playerData, const char *message)
{
  int from = playerData->getIndex();
  int to;

  std::string message2;
  size_t callsignStart=0, callsignEnd=0, messageStart=0;

  if (!playerData->accessInfo.hasPerm(PlayerAccessInfo::privateMessage)) {
    char reply[MessageLen] = {0};
    sprintf(reply,"%s, you are not presently authorized to /msg people privately", playerData->player.getCallSign());
    sendMessage(ServerPlayer, from, reply);
    return;
  }

  // start from after "/msg"
  std::string arguments = &message[4];
  std::string recipient = std::string("");

  // skip any leading whitespace
  callsignStart = 0;
  while ((callsignStart < arguments.size()) &&
	 (isspace(arguments[callsignStart]))) {
    callsignStart++;
  }

  // make sure there was _some_ whitespace after /msg
  if (callsignStart == 0) {
    sendMessage(ServerPlayer, from, "Usage: /msg \"some callsign\" some message");
    return;
  }

  // find the player name, optionally quoted
  if ( arguments[callsignStart] == '"' ) {
    callsignStart++;

    // find the trailing quote
    bool foundQuote = false;
    callsignEnd = callsignStart;
{'fraction_non_alphanumeric': 0.1163525438500926, 'fraction_numerical': 0.009913933979736354, 'mean_word_length': 4.573770491803279, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7620967', 'n_tokens_mistral': 2939, 'n_tokens_neox': 2789, 'n_words': 913}