Beispiel #1
0
/*
 * GUI callbacks.
 */
void KBBGame::callBack( int witch )
{
  switch (witch) {
  case ID_HELP:
    help();
    break;
  case ID_ABOUT:
    about();
    break;
  case ID_ABOUT_QT:
    aboutQt();
    break;
  case ID_QUIT:
    kapp->quit();
    break;
  case ID_NEW:
    newGame();
    break;
  case ID_GIVEUP:
    giveUp();
    break;
  case ID_DONE:
    gameFinished();
    break;
  case ID_RESIZE:
    setMinSize();
    gameResize();
    break;
  }
}
CreateGameScreen::CreateGameScreen(QWidget *parent) : QWidget(parent)
{
    setWindowModality(Qt::ApplicationModal);

    _labelName.setText("Game name :");
    _labelMap.setText("Map id :");
    _labelPlayer.setText("Player number :");
    _validButton.setText("Create");
    _cancelButton.setText("Cancel");
    _spinBoxMap.setMaximum(9);
    _spinBoxPlayer.setMaximum(4);

    _gridLayout.addWidget(&_labelName, 0, 0);
    _gridLayout.addWidget(&_lineEditName, 0, 1);

    _gridLayout.addWidget(&_labelMap, 1, 0);
    _gridLayout.addWidget(&_spinBoxMap, 1, 1);

    _gridLayout.addWidget(&_labelPlayer, 2, 0);
    _gridLayout.addWidget(&_spinBoxPlayer, 2, 1);

    _gridLayout.addWidget(&_validButton, 3, 0);
    _gridLayout.addWidget(&_cancelButton, 3, 1);

    setLayout(&_gridLayout);

    connect(&_validButton, SIGNAL(clicked()), this, SLOT(createGame()));
    connect(&_cancelButton, SIGNAL(clicked()), this, SLOT(giveUp()));
    connect(ListenServerSingleton::getInstance(), SIGNAL(gameCreation(bool)), this, SLOT(validGameCreation(bool)));
}
    /**
     * Steps when uncontended:
     * 1. Publish request to dequeue in dequeuers[tid];
     * 2. CAS node->deqTid from IDX_START to tid;
     * 3. Set dequeuers[tid] to the newly owned node;
     * 4. Advance the head with casHead();
     *
     * We must protect either head or tail with HP before doing the check for
     * empty queue, otherwise we may get into retired-deleted-newed-reenqueued.
     *
     * @param tid: The tid must be a UNIQUE index for each thread, in the range 0 to maxThreads-1
     */
    T* dequeue(const int tid) {
        Node* prReq = deqself[tid].load();     // Previous request
        Node* myReq = deqhelp[tid].load();
        deqself[tid].store(myReq);             // Step 1
        for (int i=0; i < maxThreads; i++) {
            if (deqhelp[tid].load() != myReq) break; // No need for HP
            Node* lhead = hp.protectPtr(kHpHead, head.load(), tid);
            if (lhead != head.load()) continue;
            if (lhead == tail.load()) {        // Give up
                deqself[tid].store(prReq);     // Rollback request to dequeue
                giveUp(myReq, tid);
                if (deqhelp[tid].load() != myReq) {
                    deqself[tid].store(myReq, std::memory_order_relaxed);
                    break;
                }
                hp.clear(tid);
                return nullptr;
            }
            Node* lnext = hp.protectPtr(kHpNext, lhead->next.load(), tid);
            if (lhead != head.load()) continue;
 		    if (searchNext(lhead, lnext) != IDX_NONE) casDeqAndHead(lhead, lnext, tid);
        }
        Node* myNode = deqhelp[tid].load();
        Node* lhead = hp.protectPtr(kHpHead, head.load(), tid);     // Do step 4 if needed
        if (lhead == head.load() && myNode == lhead->next.load()) head.compare_exchange_strong(lhead, myNode);
        hp.clear(tid);
        hp.retire(prReq, tid);
        return myNode->item;
    }
Beispiel #4
0
int FixUsersCommand::Execute() {
    std::cout << "Runnning FixUsersCommand::Execute" << std::endl;
    	File userFile(syscfg.datadir, USER_LST);
	if(!userFile.Exists()) {
		Print(NOK, true, "%s does not exist.", userFile.full_pathname().c_str());
		giveUp();
	}

	WUserManager userMgr;
	userMgr.InitializeUserManager(syscfg.datadir, sizeof(userrec), syscfg.maxusers);
	Print(OK, true, "Checking USER.LST... found %d user records.", userMgr.GetNumberOfUserRecords());

	Print(OK, true, "TBD: Check for trashed user recs.");
	if(userMgr.GetNumberOfUserRecords() > syscfg.maxusers) {
		Print(OK, true, "Might be too many.");
			maybeGiveUp();
	} else {
		Print(OK, true, "Reasonable number.");
	}

	std::vector<smalrec> smallrecords;
	std::set<std::string> names;

  const int num_user_records = userMgr.GetNumberOfUserRecords();
	for(int i = 1; i <= num_user_records; i++) {
		WUser user;
		userMgr.ReadUser(&user, i);
		user.FixUp();
		userMgr.WriteUser(&user, i);
		if (!user.IsUserDeleted() && !user.IsUserInactive()) {
			smalrec sr = { 0 };
			strcpy((char*) sr.name, user.GetName());
			sr.number = static_cast<unsigned short>(i);
			std::string namestring((char*) sr.name);
			if (names.find(namestring) == names.end()) {
				smallrecords.push_back(sr);
				names.insert(namestring);
        const std::string msg = StringPrintf("Keeping user: %s #%d", sr.name, sr.number);
        Print(OK, true, msg.c_str());
			}
			else {
				std::cout << "[skipping duplicate user: "******" #" << sr.number << "]";
			}
		}
	};

	std::sort(smallrecords.begin(), smallrecords.end(), [](const smalrec& a, const smalrec& b) -> bool {
		int equal = strcmp((char*)a.name, (char*)b.name);

		// Sort by user number if names match.
		if (equal == 0) {
			return a.number < b.number;
		}

		// Otherwise sort by name comparison.
		return equal < 0;
	});

	printf("size=%lu %lu\n", smallrecords.size(), sizeof(smalrec) * smallrecords.size());

	Print(OK, true, "Checking NAMES.LST");
	File nameFile(syscfg.datadir, NAMES_LST);
	if(!nameFile.Exists()) {
		Print(NOK, true, "%s does not exist, regenerating with %d names", nameFile.full_pathname().c_str(),
			smallrecords.size());
		nameFile.Close();
		nameFile.Open(File::modeCreateFile | File::modeBinary | File::modeWriteOnly);
		nameFile.Write(&smallrecords[0], sizeof(smalrec) * smallrecords.size());
		nameFile.Close();

	} else {
		if(nameFile.Open(File::modeReadOnly | File::modeBinary)) {
			unsigned long size = nameFile.GetLength();
			unsigned short recs = static_cast<unsigned short>(size / sizeof(smalrec));
			if (recs != status.users) {
				status.users = recs;
				Print(NOK, true, "STATUS.DAT contained an incorrect user count.");
			} else {
				Print(OK, true, "STATUS.DAT matches expected user count of %d users.", status.users);
			}
		}
		nameFile.Close();
	}
    return 0;
}