• 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!

Could someone fix this code for me?

Delirium

OTLand veteran
Staff member
Global Moderator
Joined
May 28, 2007
Messages
3,365
Solutions
1
Reaction score
289
Location
Athens, Greece
In game.cpp at the bottom:

Code:
void Game::reportRuleViolation(std::string message)
{
     Player* reporter = getPlayerByName(reporter->getName());
     if(!reporter || reporter->isRemoved())
     return;
     
     std::string fileNameReport = "data/reports/violations/" + reporter->getName() + "'s violation report";
     FILE* f = fopen(fileNameReport.c_str(),"a");
     fprintf(f,"----------------------------\n Name: %s \nMessage: %s",reporter->getName().c_str(),message.c_str());
     fclose(f);
     
     reporter->sendTextMessage(MSG_EVENT_DEFAULT, "Your request has been opened.Please wait patiently for a gamemaster to reply.");

     AutoList<Player>::listiterator it = Player::listPlayer.list.begin();
     while (it != Player::listPlayer.list.end()){
           if((*it).second->getAccountType() >= ACCOUNT_TYPE_GAMEMASTER)
           {
                char buffer [100];
                sprintf(buffer,"Player %s has opened a new violation report request.Please check his report.",reporter->getName().c_str());
                }
           ++it;
         }

}

Commands.cpp at the bottom:

Code:
bool Commands::reportViolations(Creature* creature, const std::string& cmd, const std::string& param)
{
     Player* player = creature->getPlayer();
     if(player)
     {
               g_game.reportRuleViolation(param);
               }
     return false;
}

The other declarations in the header files are written.The code compiles without errors but it gives a crash when i type that command,could someone please fix it? thanks
 
It's crashing because of this:
Player* reporter = getPlayerByName(reporter->getName());

You're trying to access a pointer that you've not properly declared first, you might want to create another parameter to the function where you set the player.
 
It's crashing because of this:
Player* reporter = getPlayerByName(reporter->getName());

You're trying to access a pointer that you've not properly declared first, you might want to create another parameter to the function where you set the player.

so with what can i replace it?

Player* reporter = creature->getPlayer(); would be ok?
 
I told you to send the reporter as parameter, if you use:
Player* reporter = creature->getPlayer();
then creature is not declared.
 
g_game.reportRuleViolation(player, param);

void Game::reportRuleViolation(Player* player, std::string message)
 
You don't need it, now you already have the player declared in the parameter, use 'player' instead of reporter, or replace Player* player with Player* reporter, variable name is not really a big deal.
 
You don't need it, now you already have the player declared in the parameter, use 'player' instead of reporter, or replace Player* player with Player* reporter, variable name is not really a big deal.

Still Crashes

Code:
void Game::reportRuleViolation(Player* player ,std::string message)
{

     if(!player || player->isRemoved())
     return;
     
     std::string fileNameReport = "data/reports/violations/" + player->getName() + "'s violation report";
     FILE* f = fopen(fileNameReport.c_str(),"a");
     fprintf(f,"----------------------------\n Name: %s \nMessage: %s",player->getName().c_str(),message.c_str());
     fclose(f);
     
     player->sendTextMessage(MSG_EVENT_DEFAULT, "Your request has been opened.Please wait patiently for a gamemaster to reply.");

     AutoList<Player>::listiterator it = Player::listPlayer.list.begin();
     while (it != Player::listPlayer.list.end()){
           if((*it).second->getAccountType() >= ACCOUNT_TYPE_GAMEMASTER)
           {
                char buffer [100];
                sprintf(buffer,"Player %s has opened a new violation report request.Please check his report.",player->getName().c_str());
                (*it).second->sendTextMessage(MSG_STATUS_WARNING,buffer);
                }
           ++it;
         }

}

Code:
bool Commands::reportViolations(Creature* creature, const std::string& cmd, const std::string& param)
{
     Player* player = creature->getPlayer();
     if(player)
     {
               g_game.reportRuleViolation(player,param);
               }
     return false;
}
 
I can't see what's causing it, perhaps try to increase buffer size to 150.
 
Back
Top