Example #1
0
bool playerList::addPlayer(const Player& newPlayer) {
    playerNode *currentNode = _head;
    bool foundPlayer = false;
    bool memoryFailure = false;

    if(!(findPlayer(newPlayer.getName()))) { // findPlayer returns NULL if
        // not found
        playerNode *newNode = new playerNode;
        if(newNode) {
            newNode->setPlayer(newPlayer);
            newNode->setNext(_head);
            _head = newNode;
        }

        else {
            memoryFailure = true;
        }
    }

    else {
        foundPlayer = true;
    }

    return !(foundPlayer) || memoryFailure;
}
Example #2
0
bool playerHash::addPlayer(const Player& newPlayer) {
    bool foundPlayer = false;
    unsigned int index = getHash(newPlayer.getName());
    if(_hashTable[index].addPlayer(newPlayer)) {
        foundPlayer = true;
        _entries++;
    }

    return foundPlayer;
}
Example #3
0
// set_inventory_formspec(self, formspec)
int ObjectRef::l_set_inventory_formspec(lua_State *L)
{
    ObjectRef *ref = checkobject(L, 1);
    Player *player = getplayer(ref);
    if(player == NULL) return 0;
    std::string formspec = luaL_checkstring(L, 2);

    player->inventory_formspec = formspec;
    get_server(L)->reportInventoryFormspecModified(player->getName());
    lua_pushboolean(L, true);
    return 1;
}
Example #4
0
// get_player_name(self)
int ObjectRef::l_get_player_name(lua_State *L)
{
    ObjectRef *ref = checkobject(L, 1);
    Player *player = getplayer(ref);
    if(player == NULL) {
        lua_pushlstring(L, "", 0);
        return 1;
    }
    // Do it
    lua_pushstring(L, player->getName());
    return 1;
}