• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

[SOLVED] Vote Point System Errors!

Status
Not open for further replies.

Synth

Exalted Member
Sup everyone as title said today i try to add the Vote Point System maded by @Tommy,so i think its outdated i get custom errors after compile:
3>trinitycore\src\server\scripts\custom\VotePoints.h(27): error C2059: syntax error : '<' (TrinityCore\src\server\scripts\Custom\votepoints.cpp)
3>trinitycore\src\server\scripts\custom\VotePoints.h(27): error C2238: unexpected token(s) preceding ';' (TrinityCore\src\server\scripts\Custom\votepoints.cpp)
3>trinitycore\src\server\scripts\custom\VotePoints.h(27): error C2059: syntax error : '<' (TrinityCore\src\server\scripts\Custom\cmd_vote_points.cpp)
3>trinitycore\src\server\scripts\custom\VotePoints.h(27): error C2238: unexpected token(s) preceding ';' (TrinityCore\src\server\scripts\Custom\cmd_vote_points.cpp)
3>TrinityCore\src\server\scripts\Custom\votepoints.cpp(34): error C2065: 'LOGIN_SEL_POINTS' : undeclared identifier
3>TrinityCore\src\server\scripts\Custom\votepoints.cpp(35): error C2065: 'LOGIN_UPD_POINTS' : undeclared identifier
3>TrinityCore\src\server\scripts\Custom\cmd_vote_points.cpp(38): error C2555: 'cmd_vote_points::GetCommands': overriding virtual function return type differs and is not covariant from 'CommandScript::GetCommands'
3> TrinityCore\src\server\game\Scripting\ScriptMgr.h(537) : see declaration of 'CommandScript::GetCommands'
3>TrinityCore\src\server\scripts\Custom\cmd_vote_points.cpp(21): error C2440: 'initializing' : cannot convert from 'initializer-list' to 'ChatCommand'
3> No constructor could take the source type, or constructor overload resolution was ambiguous
3>TrinityCore\src\server\scripts\Custom\votepoints.cpp(65): error C2065: 'LOGIN_LOAD_POINTS' : undeclared identifier
3>TrinityCore\src\server\scripts\Custom\votepoints.cpp(69): error C2039: 'outInfo' : is not a member of 'Log'
3> TrinityCore\src\common\Logging/Log.h(38) : see declaration of 'Log'
3>TrinityCore\src\server\scripts\Custom\votepoints.cpp(69): error C2065: 'LOG_FILTER_SERVER_LOADING' : undeclared identifier
3>TrinityCore\src\server\scripts\Custom\votepoints.cpp(86): error C2039: 'outInfo' : is not a member of 'Log'
3> TrinityCore\src\common\Logging/Log.h(38) : see declaration of 'Log'
3>TrinityCore\src\server\scripts\Custom\votepoints.cpp(86): error C2065: 'LOG_FILTER_SERVER_LOADING' : undeclared identifier
3>TrinityCore\src\server\scripts\Custom\cmd_vote_points.cpp(27): error C2440: 'initializing' : cannot convert from 'initializer-list' to 'ChatCommand'
3> No constructor could take the source type, or constructor overload resolution was ambiguous
3>TrinityCore\src\server\scripts\Custom\cmd_vote_points.cpp(34): error C2275: 'ACE_Singleton' : illegal use of this type as an expression
3> trinitycore\src\server\scripts\custom\VotePoints.h(27) : see declaration of 'ACE_Singleton'
3>TrinityCore\src\server\scripts\Custom\cmd_vote_points.cpp(34): error C2143: syntax error : missing ';' before '>'
3>TrinityCore\src\server\scripts\Custom\cmd_vote_points.cpp(34): error C2039: 'instance' : is not a member of '`global namespace''
4>------ Build started: Project: worldserver, Configuration: Release Win32 ------
4>game.lib(ScriptLoader.obj) : error LNK2019: unresolved external symbol "void __cdecl AddSC_vote_points(void)" (?AddSC_vote_points@@YAXXZ) referenced in function "void __cdecl AddCustomScripts(void)" (?AddCustomScripts@@YAXXZ)
4>Build\bin\Release\worldserver.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 2 succeeded, 2 failed, 18 up-to-date, 0 skipped ==========
I try to understand this great code but i didn't know how to fix this errors so wiried!

Thank you!
Synth!
 

Tommy

Founder
I'm assuming I made that years ago since ACE is still involved within the script. It is a very old script which means it is very outdated. Pasting errors with no script kinda gets annoying. Paste the script.
 

Synth

Exalted Member

Tommy

Founder
Been busy with holiday and I forgot all about this thread. :p

The errors are really simple to fix, especially if you compare code to TrinityCore's source today.

Code:
3>TrinityCore\src\server\scripts\Custom\votepoints .cpp(34): error C2065: 'LOGIN_SEL_POINTS' : undeclared identifier
3>TrinityCore\src\server\scripts\Custom\votepoints .cpp(35): error C2065: 'LOGIN_UPD_POINTS' : undeclared identifier

The two errors above are supposed to be in LoginDatabase.h above "MAX_LOGINDATABASE_STATEMENTS" and in LoginDatabase.cpp:

Code:
PrepareStatement(LOGIN_SEL_POINTS, "SELECT votepoints FROM account WHERE id=?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_UPD_POINTS, "UPDATE account SET votepoints=? WHERE id=?", CONNECTION_ASYNC);

For starters, the code below:

Code:
sLog->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded 0 Account Vote Points Data");
sLog->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded %u Player Vote Data in %u ms", count, GetMSTimeDiffToNow(oldMSTime));

Should be:

Code:
TC_LOG_ERROR("server.loading", ">> Loaded 0 Account Vote Points Data");
TC_LOG_INFO("server.loading", ">> Loaded %u Player Vote Data in %u ms", count, GetMSTimeDiffToNow(oldMSTime));

As for the CommandScript, it was refactored over a month ago (at least only the command tables in GetCommands()): https://github.com/TrinityCore/TrinityCore/commit/2d942ddcc528cc9fe718ebbd5903318fcbdab817

This:

Code:
    ChatCommand* GetCommands() const
    {
        static ChatCommand pointCommandTable[] =
        {
            { "getpoints",      SEC_PLAYER,         false, &HandleGetPointsCommand,           "", NULL },
            { NULL,             0,                  false, NULL,                              "", NULL }
        };
 
        static ChatCommand commandTable[]  =
        {
            { "vote",           SEC_PLAYER,         true,  NULL,                              "", pointCommandTable },
            { NULL,             0,                  false, NULL,                              "", NULL }
        };
        return commandTable;
    }

Should be:

Code:
    std::vector<ChatCommand> GetCommands() const override
    {
        static std::vector<ChatCommand> pointCommandTable =
        {
            { "getpoints",      SEC_PLAYER,         false, &HandleGetPointsCommand,           "", NULL },
            { NULL,             0,                  false, NULL,                              "", NULL }
        };
 
        static std::vector<ChatCommand> commandTable  =
        {
            { "vote",           SEC_PLAYER,         true,  NULL,                              "", pointCommandTable },
            { NULL,             0,                  false, NULL,                              "", NULL }
        };
        return commandTable;
    }

Lastly, you need to get rid of ACE code in VotePointSystemMgr.h. Delete:

Code:
friend class ACE_Singleton<VotePointSystemMgr, ACE_Null_Mutex>;

And add the code below under "public:" in VotePointSystemMgr class:

Code:
    static VotePointSystemMgr* GetInstance()
    {
        static VotePointSystemMgr instance;
        return &instance;
    }

After that, replace:

Code:
#define sVoteSystemMgr ACE_Singleton<VotePointSystemMgr, ACE_Null_Mutex>::instance()

with:

Code:
#define sVoteSystemMgr VotePointSystemMgr::GetInstance()

That should be everything. If I missed anything just say so or try and fix it yourself.
 
  • Like
Reactions: noc

Synth

Exalted Member
I replace everything correctly i get 1 compile error LOGIN_LOAD_POINTS no define for it,so i just follow the steps you said i go to loginDB.h i add LOGIN_LOAD_POINTS,then i go to loginDB.cpp i add this:
PrepareStatement(LOGIN_LOAD_POINTS, "SELECT vp FROM fusion.account_data WHERE id=?", CONNECTION_SYNCH);
,after that no compile error i just go to test it in-game i write .vote showpoints then directly my server crashed and nothing happen so seems there is DB errors actually i'm using fusion website so i just changed query to make sql works with fusion site,problay this what i change with query's:
PrepareStatement(LOGIN_SEL_POINTS, "SELECT vp FROM fusion.account_data WHERE id=?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_UPD_POINTS, "UPDATE fusion.account_data SET vp = ? WHERE id = ?", CONNECTION_ASYNC);
So i have no idea why its not working what i should do for i make it work with fusion website?

i have test my script but instead of command i just do an npc to show you vote and donate points same time i use same query but it works look:
QueryResult select = LoginDatabase.PQuery("SELECT dp, vp FROM fusion.account_data WHERE id = '%u'", player->GetSession()->GetAccountId());
 
Last edited:

Kaev

Super Moderator
The query doesn't crash your server, it's something else you messed up.
Can you post your current code, so i can see which changes you made?
 

Synth

Exalted Member
The query doesn't crash your server, it's something else you messed up.
Can you post your current code, so i can see which changes you made?

Well ye i don't know what is the problem for it cause this,maybe i miss to define and write for whole scripts "#include",i really don't know if yes what includes should i write?
Anyway you can check the changes i just followed Tommy what did he said:
So the first change i did i put the following in LoginDatabase.h:
LOGIN_SEL_POINTS,
LOGIN_UPD_POINTS,
LOGIN_LOAD_POINTS,
i add all of these above MAX_LOGINDATABASE_STATEMENTS

Then i open up LoginDatabase.cpp and i add the following statement:
PrepareStatement(LOGIN_SEL_POINTS, "SELECT vp FROM fusion.account_data WHERE id= ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_UPD_POINTS, "UPDATE fusion.account_data SET vp = ? WHERE id = ?", CONNECTION_ASYNC);
PrepareStatement(LOGIN_LOAD_POINTS, "SELECT vp FROM fusion.account_data WHERE id = ?", CONNECTION_SYNCH);

and then i followed what Tommy said for i fix the compile errors but maybe this is making the server crash?
He told me to add this code below under "public:" in VotePointSystemMgr class,Do you think its right?
class VotePointSystemMgr
{

private:
VotePointSystemMgr();
~VotePointSystemMgr();

public:
static VotePointSystemMgr* GetInstance()
{
static VotePointSystemMgr instance;
return &instance;
}
void LoadVoteSystem();

typedef std::map<uint32, VotePointSystem*> VotePointList;

VotePointSystem* GetPointsByAccountId(uint32 id)
{
for (VotePointList::const_iterator itr = _voteList.begin(); itr != _voteList.end(); ++itr)
if (itr->second && itr->second->GetPlayerAccount(id))
return itr->second;
return NULL;
}
Also you can check the whole scripts of votesystem here:
VotePoints.h
VotePoints.cpp
Votecommand.cpp

I get 0 failed after compile but in error list there is custom errors check it out here:
Image
 
Last edited:

Tommy

Founder
He told me to add this code below under "public:" in VotePointSystemMgr class,Do you think its right?

...

Of COURSE it is correct.. If it was private or protected you wouldn't be able to access it which wouldn't make much sense, since it needs to be public so you can return the instance to access its methods, etc. That isn't the cause of the crash, matter of fact, all that you mentioned isn't the cause of a crash.

I get 0 failed after compile but in error list there is custom errors check it out here:
Image

Those are false positive errors. They mostly occur when files aren't done parsing yet.

As I said before: this project is pretty old. It is best to make your own system or fix this one up to make it work, work better or make it more clean.

You did say you wrote ".vote showpoints" and it crashes. After looking myself the crash is probably because "voteSystem" variable is null when running the command.

Simple if statement check will lift that issue:

Code:
    static bool HandleGetPointsCommand(ChatHandler* handler, char const* args)
    {
        Player* player = handler->GetSession()->GetPlayer();
        VotePointSystem* voteSystem = sVoteSystemMgr->GetPointsByAccountId(player->GetSession()->GetAccountId());
        [COLOR="#FF8C00"]if (voteSystem)[/COLOR]
            ChatHandler(player->GetSession()).PSendSysMessage("You have %u vote points", voteSystem->Points());

        return true;
    }
 

Kaev

Super Moderator
Code:
    static bool HandleGetPointsCommand(ChatHandler* handler, char const* args)
    {
        Player* player = handler->GetSession()->GetPlayer();
        [COLOR="#FF0000"]if (player)[/COLOR]
        {
            VotePointSystem* voteSystem = sVoteSystemMgr->GetPointsByAccountId(player->GetSession()->GetAccountId());
            [COLOR="#FF8C00"]if (voteSystem)[/COLOR]
            {
                ChatHandler(player->GetSession()).PSendSysMessage("You have %u vote points", voteSystem->Points());
                return true;
            }
        }
        return false;
    }
Just to be sure, you never know! :p
Please try that and give us the results of your tests.
 

Synth

Exalted Member
Just to be sure, you never know! :p
Please try that and give us the results of your tests.

Well before i try you're edit i try Tommy edit i add if (voteSystem) under VotePointSystem* voteSystem=... i get no compile error i go to test in-game it didn't crash but its not working,so if i write .vote showpoints nothing happen without crashing...
Then i try you're way i get different error with "{" i just remove this and try it without it so it look like this:
static bool HandleGetPointsCommand(ChatHandler* handler, char const* args)
{
Player* player = handler->GetSession()->GetPlayer();
if (player)
VotePointSystem* voteSystem = sVoteSystemMgr->GetPointsByAccountId(player->GetSession()->GetAccountId());
if (voteSystem)
ChatHandler(player->GetSession()).PSendSysMessage("You have %u vote points", voteSystem->Points());
return true;
}
}
return false;
}
I get different errors so acutally we fix a problem we get other one :p
2>TrinityCore\src\server\scripts\Custom\cmd_vote_points.cpp(35): error C2065: 'voteSystem' : undeclared identifier
2>TrinityCore\src\server\scripts\Custom\cmd_vote_points.cpp(36): error C2065: 'voteSystem' : undeclared identifier
2>TrinityCore\src\server\scripts\Custom\cmd_vote_points.cpp(36): error C2227: left of '->Points' must point to class/struct/union/generic type
2> type is 'unknown-type'
Thank you for helping hope it can be solved...
 

Tommy

Founder
Just to be sure, you never know! :p
Please try that and give us the results of your tests.

Player won't be null unless the command was entered through the console.

Well before i try you're edit i try Tommy edit i add if (voteSystem) under VotePointSystem* voteSystem=... i get no compile error i go to test in-game it didn't crash but its not working,so if i write .vote showpoints nothing happen without crashing...
Then i try you're way i get different error with "{" i just remove this and try it without it so it look like this:

I get different errors so acutally we fix a problem we get other one :p

Thank you for helping hope it can be solved...

Well, you're getting those errors because you removed those BRACKETS and failed to remove the closing brackets. However, don't remove the brackets. They have nothing to do with how everything works. The only condition why you shouldn't use brackets is if there's one line of code being used in said statement(s) - though, it confuses a lot of people how it works and I don't get why it is so confusing. There's different opinions on what to use, take a look at: http://programmers.stackexchange.com/questions/16528/single-statement-if-block-braces-or-no

In this case, the brackets should stay since it will error and it is illogical because of what is inside those said brackets.

If it didn't show when you ran the command, make sure you have vote points before the account data is loaded. Restart your authserver too, to make sure (if you haven't).
 

Synth

Exalted Member
Well, you're getting those errors because you removed those BRACKETS and failed to remove the closing brackets. However, don't remove the brackets. They have nothing to do with how everything works. The only condition why you shouldn't use brackets is if there's one line of code being used in said statement(s) - though, it confuses a lot of people how it works and I don't get why it is so confusing. There's different opinions on what to use, take a look at: http://programmers.stackexchange.com/questions/16528/single-statement-if-block-braces-or-no

In this case, the brackets should stay since it will error and it is illogical because of what is inside those said brackets.

If it didn't show when you ran the command, make sure you have vote points before the account data is loaded. Restart your authserver too, to make sure (if you haven't).

So could you please paste the script with brackets correctly,actually i already have vote points in my account but the problem nothing happen when you write the command,i also restarted authserver,and ofc i add the command to rbac tables in auth but its something from the script i can't understand why.
Anyway look that is my account in DB with votepoints:
Screenshot_3.png
 

Tommy

Founder
So could you please paste the script with brackets correctly,actually i already have vote points in my account but the problem nothing happen when you write the command,i also restarted authserver,and ofc i add the command to rbac tables in auth but its something from the script i can't understand why.
Anyway look that is my account in DB with votepoints:
View attachment 525

You copied the command code that Kaev pasted. Do it again.
 

Synth

Exalted Member
You copied the command code that Kaev pasted. Do it again.

Well ye now i get 0 compile error,and i go in-game to test it once i write .voteshowpoints it said incorrect syntax i don't why,anw this is the command script.
/*
*╔═╦═╦═╦╦╦══╦═╦╗─╔╦══╗
*║╦╣║║║║║╠╗╗║╦╣╚╦╝║══╣
*║╩╣║║║║║╠╩╝║╩╬╗║╔╬══║
*╚═╩╩═╩╩═╩══╩═╝╚═╝╚══╝
* http://emudevs.com
*/
#include "VotePoints.h"
#include "Chat.h"

class cmd_vote_points : public CommandScript
{
public:
cmd_vote_points() : CommandScript("cmd_vote_points") { }

std::vector<ChatCommand> GetCommands() const override
{

static std::vector<ChatCommand> pointCommandTable =
{
{ "voteshowpoints", rbac::RBAC_PERM_COMMAND_VOTE_SHOWPOINTS, true, &HandleGetPointsCommand, "" },
};
return pointCommandTable;
}

static bool HandleGetPointsCommand(ChatHandler* handler, char const* args)
{
Player* player = handler->GetSession()->GetPlayer();
if (player)
{
VotePointSystem* voteSystem = sVoteSystemMgr->GetPointsByAccountId(player->GetSession()->GetAccountId());
if (voteSystem)
{
ChatHandler(player->GetSession()).PSendSysMessage("You have %u vote points", voteSystem->Points());
return true;
}
}
return false;
}
};

void AddSC_vote_points()
{
new cmd_vote_points;
}
 

Synth

Exalted Member
You posted this file: http://paste2.org/CjZaX1bw
Can you set a breakpoint to line 44, debug and tell us where it does crash? (if it does crash there)

What you mean by breakpoint?
That is line 44 what i should change or add and how it will look like?
for (VotePointList::const_iterator itr = _voteList.begin(); itr != _voteList.end(); ++itr)
and also debug you mean after change compile with debug and then what to do?
 

Synth

Exalted Member
Any help please i really need to done from this,i know its OLD but its GOLD because Tommy made it :D :typing:
 
Status
Not open for further replies.
Top