Exemplo n.º 1
0
void wk_gateKeeper(DS::SocketHandle sockp)
{
    GateKeeper_Private client;
    client.m_crypt = 0;

    s_clientMutex.lock();
    client.m_sock = sockp;
    s_clients.push_back(&client);
    s_clientMutex.unlock();

    try {
        gate_init(client);

        for ( ;; ) {
            uint16_t msgId = DS::CryptRecvValue<uint16_t>(client.m_sock, client.m_crypt);
            switch (msgId) {
            case e_CliToGateKeeper_PingRequest:
                cb_ping(client);
                break;
            case e_CliToGateKeeper_FileServIpAddressRequest:
                cb_fileServIpAddress(client);
                break;
            case e_CliToGateKeeper_AuthServIpAddressRequest:
                cb_authServIpAddress(client);
                break;
            default:
                /* Invalid message */
                fprintf(stderr, "[GateKeeper] Got invalid message ID %d from %s\n",
                        msgId, DS::SockIpAddress(client.m_sock).c_str());
                DS::CloseSock(client.m_sock);
                throw DS::SockHup();
            }
        }
    } catch (const DS::SockHup&) {
        // Socket closed...
    } catch (const std::exception& ex) {
        fprintf(stderr, "[GateKeeper] Error processing client message from %s: %s\n",
                DS::SockIpAddress(sockp).c_str(), ex.what());
    }

    s_clientMutex.lock();
    auto client_iter = s_clients.begin();
    while (client_iter != s_clients.end()) {
        if (*client_iter == &client)
            client_iter = s_clients.erase(client_iter);
        else
            ++client_iter;
    }
    s_clientMutex.unlock();

    DS::CryptStateFree(client.m_crypt);
    DS::FreeSock(client.m_sock);
}
Exemplo n.º 2
0
void cb_sockRead(AuthServer_Private& client)
{
    uint16_t msgId = DS::CryptRecvValue<uint16_t>(client.m_sock, client.m_crypt);
    switch (msgId) {
    case e_CliToAuth_PingRequest:
        cb_ping(client);
        break;
    case e_CliToAuth_ClientRegisterRequest:
        cb_register(client);
        break;
    case e_CliToAuth_AcctLoginRequest:
        cb_login(client);
        break;
    case e_CliToAuth_AcctSetPlayerRequest:
        cb_setPlayer(client);
        break;
    case e_CliToAuth_PlayerCreateRequest:
        cb_playerCreate(client);
        break;
    case e_CliToAuth_PlayerDeleteRequest:
        cb_playerDelete(client);
        break;
    case e_CliToAuth_VaultNodeCreate:
        cb_nodeCreate(client);
        break;
    case e_CliToAuth_VaultNodeFetch:
        cb_nodeFetch(client);
        break;
    case e_CliToAuth_VaultNodeSave:
        cb_nodeUpdate(client);
        break;
    case e_CliToAuth_VaultNodeAdd:
        cb_nodeRef(client);
        break;
    case e_CliToAuth_VaultNodeRemove:
        cb_nodeUnref(client);
        break;
    case e_CliToAuth_VaultFetchNodeRefs:
        cb_nodeTree(client);
        break;
    case e_CliToAuth_VaultInitAgeRequest:
        cb_ageCreate(client);
        break;
    case e_CliToAuth_VaultNodeFind:
        cb_nodeFind(client);
        break;
    case e_CliToAuth_VaultSendNode:
        cb_nodeSend(client);
        break;
    case e_CliToAuth_AgeRequest:
        cb_ageRequest(client, false);
        break;
    case e_CliToAuth_AgeRequestEx:
        cb_ageRequest(client, true);
        break;
    case e_CliToAuth_FileListRequest:
        cb_fileList(client);
        break;
    case e_CliToAuth_FileDownloadRequest:
        cb_downloadStart(client);
        break;
    case e_CliToAuth_FileDownloadChunkAck:
        cb_downloadNext(client);
        break;
    case e_CliToAuth_LogPythonTraceback:
        printf("[Auth] Got client python traceback:\n%s\n",
                DS::CryptRecvString(client.m_sock, client.m_crypt).c_str());
        break;
    case e_CliToAuth_LogStackDump:
        printf("[Auth] Got client stackdump:\n%s\n",
                DS::CryptRecvString(client.m_sock, client.m_crypt).c_str());
        break;
    case e_CliToAuth_LogClientDebuggerConnect:
        // Nobody cares
        break;
    case e_CliToAuth_ScoreCreate:
        cb_scoreCreate(client);
        break;
    case e_CliToAuth_ScoreGetScores:
        cb_scoreGetScores(client);
        break;
    case e_CliToAuth_ScoreAddPoints:
        cb_scoreAddPoints(client);
        break;
    case e_CliToAuth_ScoreTransferPoints:
        cb_scoreTransferPoints(client);
        break;
    case e_CliToAuth_ScoreSetPoints:
        cb_scoreSetPoints(client);
        break;
    case e_CliToAuth_ScoreGetHighScores:
        cb_scoreGetHighScores(client);
        break;
    case e_CliToAuth_GetPublicAgeList:
        cb_getPublicAges(client);
        break;
    case e_CliToAuth_SetAgePublic:
        cb_setAgePublic(client);
        break;
    case e_CliToAuth_ClientSetCCRLevel:
    case e_CliToAuth_AcctSetRolesRequest:
    case e_CliToAuth_AcctSetBillingTypeRequest:
    case e_CliToAuth_AcctActivateRequest:
    case e_CliToAuth_AcctCreateFromKeyRequest:
    case e_CliToAuth_VaultNodeDelete:
    case e_CliToAuth_UpgradeVisitorRequest:
    case e_CliToAuth_SetPlayerBanStatusRequest:
    case e_CliToAuth_KickPlayer:
        fprintf(stderr, "[Auth] Got unsupported client message %d from %s\n",
                msgId, DS::SockIpAddress(client.m_sock).c_str());
        DS::CloseSock(client.m_sock);
        throw DS::SockHup();
    default:
        /* Invalid message */
        fprintf(stderr, "[Auth] Got invalid message ID %d from %s\n",
                msgId, DS::SockIpAddress(client.m_sock).c_str());
        DS::CloseSock(client.m_sock);
        throw DS::SockHup();
    }
}
Exemplo n.º 3
0
void* wk_gameWorker(void* sockp)
{
    GameClient_Private client;
    client.m_sock = reinterpret_cast<DS::SocketHandle>(sockp);
    client.m_host = 0;
    client.m_crypt = 0;
    client.m_isLoaded = false;

    try {
        game_client_init(client);
    } catch (DS::AssertException ex) {
        fprintf(stderr, "[Game] Assertion failed at %s:%ld:  %s\n",
                ex.m_file, ex.m_line, ex.m_cond);
        return 0;
    } catch (DS::SockHup) {
        // Socket closed...
        return 0;
    }

    try {
        for ( ;; ) {
            uint16_t msgId = DS::CryptRecvValue<uint16_t>(client.m_sock, client.m_crypt);
            switch (msgId) {
            case e_CliToGame_PingRequest:
                cb_ping(client);
                break;
            case e_CliToGame_JoinAgeRequest:
                cb_join(client);
                break;
            case e_CliToGame_Propagatebuffer:
                DS_PASSERT(client.m_host != 0);
                cb_netmsg(client);
                break;
            case e_CliToGame_GameMgrMsg:
                DS_PASSERT(client.m_host != 0);
                cb_gameMgrMsg(client);
                break;
            default:
                /* Invalid message */
                fprintf(stderr, "[Game] Got invalid message ID %d from %s\n",
                        msgId, DS::SockIpAddress(client.m_sock).c_str());
                DS::CloseSock(client.m_sock);
                throw DS::SockHup();
            }
        }
    } catch (DS::AssertException ex) {
        fprintf(stderr, "[Game] Assertion failed at %s:%ld:  %s\n",
                ex.m_file, ex.m_line, ex.m_cond);
    } catch (DS::SockHup) {
        // Socket closed...
    }

    if (client.m_host) {
        pthread_mutex_lock(&client.m_host->m_clientMutex);
        client.m_host->m_clients.erase(client.m_clientInfo.m_PlayerId);
        pthread_mutex_unlock(&client.m_host->m_clientMutex);
        Game_ClientMessage msg;
        msg.m_client = &client;
        client.m_host->m_channel.putMessage(e_GameDisconnect, reinterpret_cast<void*>(&msg));
        client.m_channel.getMessage();
    }

    DS::CryptStateFree(client.m_crypt);
    DS::FreeSock(client.m_sock);
    return 0;
}
Exemplo n.º 4
0
void* wk_fileServ(void* sockp)
{
    FileServer_Private client;

    pthread_mutex_lock(&s_clientMutex);
    client.m_sock = reinterpret_cast<DS::SocketHandle>(sockp);
    client.m_readerId = 0;
    s_clients.push_back(&client);
    pthread_mutex_unlock(&s_clientMutex);

    try {
        file_init(client);

        for ( ;; ) {
            DS::RecvValue<uint32_t>(client.m_sock);  // Message size
            uint32_t msgId = DS::RecvValue<uint32_t>(client.m_sock);
            switch (msgId) {
            case e_CliToFile_PingRequest:
                cb_ping(client);
                break;
            case e_CliToFile_BuildIdRequest:
                cb_buildId(client);
                break;
            case e_CliToFile_ManifestRequest:
                cb_manifest(client);
                break;
            case e_CliToFile_ManifestEntryAck:
                cb_manifestAck(client);
                break;
            case e_CliToFile_DownloadRequest:
                cb_downloadStart(client);
                break;
            case e_CliToFile_DownloadChunkAck:
                cb_downloadNext(client);
                break;
            default:
                /* Invalid message */
                fprintf(stderr, "[File] Got invalid message ID %d from %s\n",
                        msgId, DS::SockIpAddress(client.m_sock).c_str());
                DS::CloseSock(client.m_sock);
                throw DS::SockHup();
            }
        }
    } catch (DS::AssertException ex) {
        fprintf(stderr, "[File] Assertion failed at %s:%ld:  %s\n",
                ex.m_file, ex.m_line, ex.m_cond);
    } catch (DS::SockHup) {
        // Socket closed...
    }

    pthread_mutex_lock(&s_clientMutex);
    auto client_iter = s_clients.begin();
    while (client_iter != s_clients.end()) {
        if (*client_iter == &client)
            client_iter = s_clients.erase(client_iter);
        else
            ++client_iter;
    }
    pthread_mutex_unlock(&s_clientMutex);

    DS::FreeSock(client.m_sock);
    return 0;
}
Exemplo n.º 5
0
void wk_fileServ(DS::SocketHandle sockp)
{
    FileServer_Private client;

    s_clientMutex.lock();
    client.m_sock = sockp;
    client.m_readerId = 0;
    s_clients.push_back(&client);
    s_clientMutex.unlock();

    try {
        file_init(client);

        for ( ;; ) {
            DS::RecvValue<uint32_t>(client.m_sock);  // Message size
            uint32_t msgId = DS::RecvValue<uint32_t>(client.m_sock);
            switch (msgId) {
            case e_CliToFile_PingRequest:
                cb_ping(client);
                break;
            case e_CliToFile_BuildIdRequest:
                cb_buildId(client);
                break;
            case e_CliToFile_ManifestRequest:
                cb_manifest(client);
                break;
            case e_CliToFile_ManifestEntryAck:
                cb_manifestAck(client);
                break;
            case e_CliToFile_DownloadRequest:
                cb_downloadStart(client);
                break;
            case e_CliToFile_DownloadChunkAck:
                cb_downloadNext(client);
                break;
            default:
                /* Invalid message */
                fprintf(stderr, "[File] Got invalid message ID %d from %s\n",
                        msgId, DS::SockIpAddress(client.m_sock).c_str());
                DS::CloseSock(client.m_sock);
                throw DS::SockHup();
            }
        }
    } catch (const DS::AssertException& ex) {
        fprintf(stderr, "[File] Assertion failed at %s:%ld:  %s\n",
                ex.m_file, ex.m_line, ex.m_cond);
    } catch (const DS::PacketSizeOutOfBounds& ex) {
        fprintf(stderr, "[File] Client packet size too large: Requested %u bytes\n",
                ex.requestedSize());
    } catch (const DS::SockHup&) {
        // Socket closed...
    }

    s_clientMutex.lock();
    auto client_iter = s_clients.begin();
    while (client_iter != s_clients.end()) {
        if (*client_iter == &client)
            client_iter = s_clients.erase(client_iter);
        else
            ++client_iter;
    }
    s_clientMutex.unlock();

    DS::FreeSock(client.m_sock);
}