Page 1 of 1

logic about TokenCollectorBase::insertClient

Posted: 20 Mar 2013, 02:49
by dlqingxi
First , forgive me post this question on this board, in fact this is a manaserv question, but I don't find a 'manaserv development discuss' board.
My question is below:
I read the manaserv's source code and found it in the utils/tokencollector.cpp

Code: Select all

void TokenCollectorBase::insertClient(const std::string &token, intptr_t data)
{
    for (std::list<Item>::reverse_iterator it = mPendingConnects.rbegin(),
         it_end = mPendingConnects.rend(); it != it_end; ++it)
    {
        if (it->token == token)
        {
            foundMatch(data, it->data);
            mPendingConnects.erase(--it.base());
            return;
        }
    }

    time_t current = time(NULL);

    Item item;
    item.token = token;
    item.data = data;
    item.timeStamp = current;
    mPendingClients.push_back(item);

    removeOutdated(current);
}
I think it's function is to insert a new client into the mPendingClients list, but why first search it in the mPendingConnects and delete it ?
In what situations it will be necessary?

Similar logic exists in TokenCollectorBase::insertConnect too.

Code: Select all

void TokenCollectorBase::insertConnect(const std::string &token, intptr_t data)
{
    for (std::list<Item>::reverse_iterator it = mPendingClients.rbegin(),
         it_end = mPendingClients.rend(); it != it_end; ++it)
    {
        if (it->token == token)
        {
            foundMatch(it->data, data);
            mPendingClients.erase(--it.base());
            return;
        }
    }

    time_t current = time(NULL);

    Item item;
    item.token = token;
    item.data = data;
    item.timeStamp = current;
    mPendingConnects.push_back(item);

    removeOutdated(current);
}
Anyone who can help me to understand it ?
Thank you very much.

Re: logic about TokenCollectorBase::insertClient

Posted: 20 Mar 2013, 05:49
by Ablu
Manaserv uses Token to handle the logins. If a client connects to the account-server it has to login using its username and password. If this login was correct the client is getting a token. Using this token he can connect to the game and chat server.

However the basic tokencollector is a shared base between the chat and the game server. It requires to get a Handler class assigned.
So as soon a token is matched (foundMatch is called) it tells the handler this:

Code: Select all

        void foundMatch(intptr_t client, intptr_t data)
        { mHandler->tokenMatched((Client)client, (ServerData)data); }
So the handler only needs to implement this tokenMatched(...) function and can use this to verify the connecting clients.

For questions regarding manaserv better use the IRC (#mana on freenode) or the maillinglist (https://groups.google.com/group/mana-developers).

Regards
Ablu