• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[HELP] Report C++

president vankk

Web Developer & AuraOT Owner
Joined
Jul 10, 2009
Messages
5,719
Solutions
9
Reaction score
339
Hello, I want edit the TFS's report. Instead add a .txt file in reports folder it will goes to SQL.

This is the original code
Code:
void Game::playerReportBug(uint32_t playerId, const std::string& message, const Position& position, uint8_t category)
{
   Player* player = getPlayerByID(playerId);
   if (!player) {
     return;
   }

   if (player->getAccountType() == ACCOUNT_TYPE_NORMAL) {
     return;
   }

   std::string fileName = "data/reports/" + player->getName() + " report.txt";
   FILE* file = fopen(fileName.c_str(), "a");
   if (!file) {
     player->sendTextMessage(MESSAGE_EVENT_DEFAULT, "There was an error when processing your report, please contact a gamemaster.");
     return;
   }

   const Position& playerPosition = player->getPosition();
   if (category == BUG_CATEGORY_MAP) {
     fprintf(file, "------------------------------\nName: %s [Map Position: %u, %u, %u] [Player Position: %u, %u, %u]\nComment: %s\n", player->getName().c_str(), position.x, position.y, position.z, playerPosition.x, playerPosition.y, playerPosition.z, message.c_str());
   } else {
     fprintf(file, "------------------------------\nName: %s [Player Position: %u, %u, %u]\nComment: %s\n", player->getName().c_str(), playerPosition.x, playerPosition.y, playerPosition.z, message.c_str());
   }
   fclose(file);

   player->sendTextMessage(MESSAGE_EVENT_DEFAULT, "Your report has been sent to " + g_config.getString(ConfigManager::SERVER_NAME) + ".");
}

I don't have any knowledge about C++, so sorry..

I'm trying using this, and it didn't work.
Code:
query << "INSERT INTO `player_reports` (`id` ,`name` ,`posx` ,`posy` ,`posz` ,`report_description` ,`date`) VALUES (" << NULL << ',' << player->getName().c_str() << ',' << position.x << ',' << playerPosition.y << ', ' << playerPosition.z << ', '<< message.c_str() <<', ' << date? <<'");

Thanks.
 
could be something like this
Code:
  Database* db = Database::getInstance();
   DBQuery query;
   query << "INSERT INTO `player_reports` (`id` ,`name` ,`posx` ,`posy` ,`posz` ,`report_description` ,`date`) VALUES ("
     << NULL << ',' << player->getName().c_str() << ',' << position.x << ',' << playerPosition.y << ', ' << playerPosition.z << ', '<< message.c_str() <<', ' << time(NULL) <<'");";
   db->query(query.str());
 
Last edited:
@SpiderOT

Code:
const Position& playerPosition = player->getPosition();
   Database* db = Database::getInstance();
   DBQuery query;
   if (category == BUG_CATEGORY_MAP) {
     query << "INSERT INTO `player_reports` (`id` ,`name` ,`posx` ,`posy` ,`posz` ,`report_description` ,`date`) VALUES ("<< NULL << ',' << player->getName().c_str() << ',' << position.x << ',' << position.y << ', ' << position.z << ', '<< message.c_str() <<', ' << time(NULL) <<'");";
     db->query(query.str());
   } else {
     query << "INSERT INTO `player_reports` (`id` ,`name` ,`posx` ,`posy` ,`posz` ,`report_description` ,`date`) VALUES ("<< NULL << ',' << player->getName().c_str() << ',' << playerPosition.x << ',' << playerPosition.y << ', ' << playerPosition.z << ', '<< message.c_str() <<', ' << time(NULL) <<'");";
     db->query(query.str());
   }

How I set the time at "time(NULL")? Can it?
 
@SpiderOT
Then will be it, right?
Code:
query << "INSERT INTO `player_reports` (`id` , `name` , `account_id` ,`posx` ,`posy` ,`posz` ,`report_description` ,`date`) VALUES ("
<< NULL << ',' << player->getName().c_str() << ', '<< player->getAccount().c_str() <<',' << position.x << ',' << position.y << ', ' << position.z << ', '<< message.c_str() <<', ' << time(NULL) <<'");";
 
forget the last one, this is how it should be
Code:
void Game::playerReportBug(uint32_t playerId, const std::string& message, const Position& position, uint8_t category)
{
  Player* player = getPlayerByID(playerId);
  if (!player) {
  return;
  }

  if (player->getAccountType() == ACCOUNT_TYPE_NORMAL) {
  return;
  }

  const Position& playerPosition = player->getPosition();
  Database* db = Database::getInstance();
  DBQuery query;
  if (category == BUG_CATEGORY_MAP) {
  query << "INSERT INTO `player_reports` (`id` , `name` , `account_id` ,`posx` ,`posy` ,`posz` ,`report_description` ,`date`) VALUES ("<< NULL << ',' << db->escapeString(player->getName()) << ', ' << player->getAccount() <<',' << position.x << ',' << position.y << ', ' << position.z << ', '<< db->escapeString(message) <<', ' << time(NULL) <<'");";
  } else {
  query << "INSERT INTO `player_reports` (`id` , `name` , `account_id` ,`posx` ,`posy` ,`posz` ,`report_description` ,`date`) VALUES ("<< NULL << ',' << db->escapeString(player->getName()) << ', ' << player->getAccount() <<',' << playerPosition.x << ',' << playerPosition.y << ', ' << playerPosition.z << ', '<< db->escapeString(message) <<', ' << time(NULL) <<'");";
  }
  
  if(!db->query(query.str())){
  player->sendTextMessage(MESSAGE_EVENT_DEFAULT, "There was an error when processing your report, please contact a gamemaster.");
  return false;
  }
  player->sendTextMessage(MESSAGE_EVENT_DEFAULT, "Your report has been sent to " + g_config.getString(ConfigManager::SERVER_NAME) + ".");
}
 
Last edited:
Error at compiling:
m8QwKp2UD.png


Lines:
553JBcHIr.png
 
didn't know you're using tfs 1.1 :)
hope it works this time
Code:
void Game::playerReportBug(uint32_t playerId, const std::string& message, const Position& position, uint8_t category)
{
  Player* player = getPlayerByID(playerId);
  if (!player) {
  return;
  }

  if (player->getAccountType() == ACCOUNT_TYPE_NORMAL) {
  return;
  }

  const Position& playerPosition = player->getPosition();
   Database* db = Database::getInstance();
   std::ostringstream query;
  
  if (category == BUG_CATEGORY_MAP) {
  query << "INSERT INTO `player_reports` (`id` , `name` , `account_id` ,`posx` ,`posy` ,`posz` ,`report_description` ,`date`) VALUES ("<< NULL << ',' << db->escapeString(player->getName()) << ', ' << player->getAccount() <<',' << position.x << ',' << position.y << ', ' << position.z << ', '<< db->escapeString(message) <<', ' << time(nullptr) << ')';
  } else {
  query << "INSERT INTO `player_reports` (`id` , `name` , `account_id` ,`posx` ,`posy` ,`posz` ,`report_description` ,`date`) VALUES ("<< NULL << ',' << db->escapeString(player->getName()) << ', ' << player->getAccount() <<',' << playerPosition.x << ',' << playerPosition.y << ', ' << playerPosition.z << ', '<< db->escapeString(message) <<', ' << time(nullptr) << ')';
  }
  
  if(!db->executeQuery(query.str())){
  player->sendTextMessage(MESSAGE_EVENT_DEFAULT, "There was an error when processing your report, please contact a gamemaster.");
  return false;
  }
  player->sendTextMessage(MESSAGE_EVENT_DEFAULT, "Your report has been sent to " + g_config.getString(ConfigManager::SERVER_NAME) + ".");
}
 
Code:
void Game::playerReportBug(uint32_t playerId, const std::string& message, const Position& position, uint8_t category)
{
  Player* player = getPlayerByID(playerId);
  if (!player) {
  return;
  }

  if (player->getAccountType() == ACCOUNT_TYPE_NORMAL) {
  return;
  }

  const Position& playerPosition = player->getPosition();
  Database* db = Database::getInstance();
  std::ostringstream query;
 
  if (category == BUG_CATEGORY_MAP) {
  query << "INSERT INTO `player_reports` (`id` , `name` , `account_id` ,`posx` ,`posy` ,`posz` ,`report_description` ,`date`) VALUES ("<< NULL << "," << db->escapeString(player->getName()) << ", " << player->getAccount() <<"," << position.x << "," << position.y << ", " << position.z << ", "<< db->escapeString(message) <<", " << time(nullptr) << ")";
  } else {
  query << "INSERT INTO `player_reports` (`id` , `name` , `account_id` ,`posx` ,`posy` ,`posz` ,`report_description` ,`date`) VALUES ("<< NULL << "," << db->escapeString(player->getName()) << ", " << player->getAccount() <<"," << playerPosition.x << "," << playerPosition.y << ", " << playerPosition.z << ", "<< db->escapeString(message) <<", " << time(nullptr) << ")";
  }
 
  if(!db->executeQuery(query.str())){
  player->sendTextMessage(MESSAGE_EVENT_DEFAULT, "There was an error when processing your report, please contact a gamemaster.");
  return;
  }
  player->sendTextMessage(MESSAGE_EVENT_DEFAULT, "Your report has been sent to " + g_config.getString(ConfigManager::SERVER_NAME) + ".");
}
 
Back
Top