logic about TokenCollectorBase::insertClient

Content and general development discussion, including quest scripts and server code. TMW Classic is a project comprising the Legacy tmwAthena server & the designated improved engine server based on evolHercules.


Forum rules

This forum houses many years of development, tracing back to some of the earliest posts that exist on the board.

Its current use is for the continued development of the server and game it has always served: TMW Classic.

Post Reply
dlqingxi
Newly Registered User
Posts: 7
Joined: 04 Jan 2013, 08:44

logic about TokenCollectorBase::insertClient

Post 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.
Ablu
Manasource
Manasource
Posts: 288
Joined: 23 Jul 2011, 08:31
Location: Germany

Re: logic about TokenCollectorBase::insertClient

Post 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
Post Reply