Forum > Serverside Modding

[SOLVED] [C++] Command crashes on usage

(1/3) > >>

bizzlesnaff:
Hey guys ;)

Atm I'm trying to create my own command (trinitycore btw). I just try to say ingame .showaccount (while target any player) and the result should be a text which is in a custom database and linked with the id of the player..
Well, here is my code:

--- Code: ---RBAC.h
RBAC_PERM_COMMAND_CUSTOMINFO = 799,

cs_misc.cpp
{ "showaccount",  rbac::RBAC_PERM_COMMAND_CUSTOMINFO, false, &HandleNewCommand,   "", NULL },


static bool HandleNewCommand(ChatHandler * handler, char const* args)
{

Player* target;
ObjectGuid targetGuid;
std::string targetName;

QueryResult resulta = CharacterDatabase.PQuery("SELECT Info FROM characterinfo WHERE acc='%s'", targetGuid);


handler->PSendSysMessage("Info: %s", resulta);
return true;
}

--- End code ---

I copied this code from some tutorials, and other scripts together, so i dont wonder that it doesn't work. But it compile fine, just if I type ingame ".showaccount" the server crashed up, but with no error log...just...shutting down or something

someone an idea what I've made wrong?

sorry for my english...thats such a dump language :)

Kaev:
Did you add the command to the rbac_permissions and rbac_linked_permissions table?

bizzlesnaff:
Ah yeah of course, forgot to write it. I did every step of this tutorial..

bizzlesnaff:
little push ;)?

Kaev:
QueryResult resulta = CharacterDatabase.PQuery("SELECT Info FROM characterinfo WHERE acc='%s'", targetGuid);

%s means null terminated string, but a guid is a integer value. Try %u instead of %s. %u means unsigned integer.

EDIT:
Lol, didn't saw that.
You can't just print a query as a string, like you did here:

handler->PSendSysMessage("Info: %s", resulta);

Here's a short snippet of a script, which i wrote:

--- Code: --- QueryResult result = WorldDatabase.Query("SELECT * FROM hm_waves");
if (result)
{
do
{
Field *fields = result->Fetch();
int waveid = fields[0].GetInt32();
creature.id = fields[1].GetInt32();
} while (result->NextRow());
}

--- End code ---
If the field info is a string, you have to use .GetString(); instead of GetInt32();. The array index is the number of the field in the query. You only request one field with your query, so it should be std::string infotext = fields[0].GetString();
And you don't have to use the do-while-loop, because you probably only expect one result.

Navigation

[0] Message Index

[#] Next page

Go to full version