예제 #1
0
bool
NetClientDlg::PingComplete()
{
    if (hnet != 0) {
        DWORD result = 0;
        GetExitCodeThread(hnet, &result);

        if (result != STILL_ACTIVE) {
            CloseHandle(hnet);
            hnet = 0;

            NetClientConfig* config = NetClientConfig::GetInstance();
            if (config) {
                NetServerInfo* info = config->GetServerInfo(ping_index);
                if (info) {
                    // copy result back into server list
                    info->machine_info = ping_info.machine_info;
                    info->gameport     = ping_info.gameport;
                    info->status       = ping_info.status;
                    info->nplayers     = ping_info.nplayers;
                    info->hosted       = ping_info.hosted;
                    info->ping_time    = ping_info.ping_time;
                }
            }

            if (lst_servers && ping_index >= lst_servers->NumItems()-1)
            ping_index = 0;
            else
            ping_index++;
        }
    }

    return !hnet;
}
예제 #2
0
void
NetClientDlg::PingServer(int n)
{
    if (hnet == 0) {
        NetClientConfig* config = NetClientConfig::GetInstance();
        if (!config) return;

        NetServerInfo* info = config->GetServerInfo(n);
        if (!info) return;

        // copy info from server list
        ping_info = *info;

        DWORD thread_id = 0;
        hnet = CreateThread(0, 4096, NetClientPingProc, (LPVOID) &ping_info, 0, &thread_id);

        if (hnet == 0) {
            static int report = 10;
            if (report > 0) {
                ::Print("WARNING: NetClientDlg() failed to create PING thread for server '%s' (err=%08x)\n", info->name.data(), GetLastError());
                report--;

                if (report == 0)
                ::Print("         Further warnings of this type will be supressed.\n");
            }
        }
    }
}