Пример #1
0
//---------------------------------------------------------------------------
void TCustomMsgServer::Incoming(socket_t Sock) 
{
    int idx;
    PWorkerSocket WorkerSocket;
    longword ClientHandle = Msg_GetSockAddr(Sock);

    if (CanAccept(Sock))
    {
        LockList();
        // First position available in the thread buffer
        idx = FirstFree();
        if (idx >= 0)
        {
            // Creates the Worker and assigns it the connected socket
            WorkerSocket = CreateWorkerSocket(Sock);
            // Creates the Worker thread
            Workers[idx] = new TMsgWorkerThread(WorkerSocket, this);
            PMsgWorkerThread(Workers[idx])->Index = idx;
            // Update the number
            ClientsCount++;
            // And Starts the worker
            PMsgWorkerThread(Workers[idx])->Start();
            DoEvent(WorkerSocket->ClientHandle, evcClientAdded, 0, 0, 0, 0, 0);
        }
        else
        {
            DoEvent(ClientHandle, evcClientNoRoom, 0, 0, 0, 0, 0);
            Msg_CloseSocket(Sock);
        }
        UnlockList();
    }
    else
    {
        Msg_CloseSocket(Sock);
        DoEvent(ClientHandle, evcClientRejected, 0, 0, 0, 0, 0);
    };
}
Пример #2
0
void
QuitView::ExecFrame()
{
    sim = Sim::GetSim();

    if (show_menu) {
        Color::SetFade(1, Color::Black, 0);
        int action = 0;

        if (Mouse::LButton()) {
            mouse_latch = true;
        }
        else if (mouse_latch) {
            mouse_latch = false;

            if (Mouse::X() > xcenter - w2 && Mouse::X() < xcenter + w2) {
                int y0 = ycenter - h2;

                for (int i = 0; i < 4; i++)
                if (Mouse::Y() >= y0 + 75 + i * 30 && Mouse::Y() <= y0 + 105 + i * 30)
                action = i+1;
            }
        }

        for (int i = 1; i <= 4; i++) {
            if (Keyboard::KeyDown('0' + i))
            action = i;
        }

        // was mission long enough to accept?
        if (action == 1 && !CanAccept()) {
            Button::PlaySound(Button::SND_REJECT);
            action = 3;
        }

        // exit and accept:
        if (action == 1) {
            CloseMenu();
            Game::SetTimeCompression(1);

            Starshatter* stars = Starshatter::GetInstance();
            stars->SetGameMode(Starshatter::PLAN_MODE);
        }

        // quit and discard results:
        else if (action == 2) {
            CloseMenu();
            Game::SetTimeCompression(1);

            Starshatter*   stars    = Starshatter::GetInstance();
            Campaign*      campaign = Campaign::GetCampaign();

            // discard mission and events:
            if (sim) sim->UnloadMission();
            else ShipStats::Initialize();

            if (campaign && campaign->GetCampaignId() < Campaign::SINGLE_MISSIONS) {
                campaign->RollbackMission();
                stars->SetGameMode(Starshatter::CMPN_MODE);
            }

            else {
                stars->SetGameMode(Starshatter::MENU_MODE);
            }
        }

        // resume:
        else if (action == 3) {
            CloseMenu();
        }

        // controls:
        else if (action == 4) {
            GameScreen* game_screen = GameScreen::GetInstance();

            if (game_screen)
            game_screen->ShowCtlDlg();
            else
            CloseMenu();
        }
    }
}