void ScriptRunner::bootstrap() { if (QThread::currentThread() != m_thread) { bool success; success = QMetaObject::invokeMethod(this, "bootstrap", Qt::QueuedConnection); Q_ASSERT(success); return; } // initialize the MF object before we run any user code QScriptValue mf_obj = m_engine->newObject(); m_engine->globalObject().setProperty("mf", mf_obj); // add utility functions mf_obj.setProperty("include", m_engine->newFunction(include)); mf_obj.setProperty("exit", m_engine->newFunction(exit)); mf_obj.setProperty("print", m_engine->newFunction(print)); mf_obj.setProperty("debug", m_engine->newFunction(debug)); mf_obj.setProperty("setTimeout", m_engine->newFunction(setTimeout)); mf_obj.setProperty("clearTimeout", m_engine->newFunction(clearTimeout)); mf_obj.setProperty("setInterval", m_engine->newFunction(setInterval)); mf_obj.setProperty("clearInterval", m_engine->newFunction(clearTimeout)); mf_obj.setProperty("currentTimestamp", m_engine->newFunction(currentTimestamp)); mf_obj.setProperty("readFile", m_engine->newFunction(readFile)); mf_obj.setProperty("writeFile", m_engine->newFunction(writeFile)); mf_obj.setProperty("args", m_engine->newFunction(args)); // init event handler framework { QString file_name = ":/js/create_handlers.js"; m_handler_map = evalJsonContents(internalReadFile(file_name), file_name); checkEngine("creating event handlers"); } // init builtin types { QString file_name = ":/js/builtin_types.js"; m_engine->evaluate(internalReadFile(file_name), file_name); checkEngine("evaluating builtin type"); m_point_class = mf_obj.property("Point"); m_entity_class = mf_obj.property("Entity"); m_item_class = mf_obj.property("Item"); m_block_class = mf_obj.property("Block"); m_health_status_class = mf_obj.property("HealthStatus"); m_status_effect_class = mf_obj.property("StatusEffect"); } // create the mf.ItemType enum { QScriptValue item_type_obj = m_engine->newObject(); mf_obj.setProperty("ItemType", item_type_obj); const QHash<Item::ItemType, Item::ItemData*> * item_data_hash = Item::itemDataHash(); for (QHash<Item::ItemType, Item::ItemData*>::const_iterator it = item_data_hash->constBegin(); it != item_data_hash->constEnd(); ++it) { const Item::ItemData * item_data = it.value(); item_type_obj.setProperty(item_data->name, item_data->id); } } // hook up mf functions mf_obj.setProperty("chat", m_engine->newFunction(chat)); mf_obj.setProperty("timeOfDay", m_engine->newFunction(timeOfDay)); mf_obj.setProperty("itemStackHeight", m_engine->newFunction(itemStackHeight)); mf_obj.setProperty("isPhysical", m_engine->newFunction(isPhysical)); mf_obj.setProperty("isSafe", m_engine->newFunction(isSafe)); mf_obj.setProperty("isDiggable", m_engine->newFunction(isDiggable)); mf_obj.setProperty("healthStatus", m_engine->newFunction(healthStatus)); mf_obj.setProperty("blockAt", m_engine->newFunction(blockAt)); mf_obj.setProperty("isBlockLoaded", m_engine->newFunction(isBlockLoaded)); mf_obj.setProperty("signTextAt", m_engine->newFunction(signTextAt)); mf_obj.setProperty("self", m_engine->newFunction(self)); mf_obj.setProperty("setControlState", m_engine->newFunction(setControlState)); mf_obj.setProperty("clearControlStates", m_engine->newFunction(clearControlStates)); mf_obj.setProperty("lookAt", m_engine->newFunction(lookAt)); mf_obj.setProperty("respawn", m_engine->newFunction(respawn)); mf_obj.setProperty("entity", m_engine->newFunction(entity)); mf_obj.setProperty("startDigging", m_engine->newFunction(startDigging)); mf_obj.setProperty("stopDigging", m_engine->newFunction(stopDigging)); mf_obj.setProperty("attackEntity", m_engine->newFunction(attackEntity)); mf_obj.setProperty("selectEquipSlot", m_engine->newFunction(selectEquipSlot)); mf_obj.setProperty("selectedEquipSlot", m_engine->newFunction(selectedEquipSlot)); mf_obj.setProperty("openInventoryWindow", m_engine->newFunction(openInventoryWindow)); mf_obj.setProperty("clickInventorySlot", m_engine->newFunction(clickInventorySlot)); mf_obj.setProperty("clickUniqueSlot", m_engine->newFunction(clickUniqueSlot)); mf_obj.setProperty("clickOutsideWindow", m_engine->newFunction(clickOutsideWindow)); mf_obj.setProperty("closeWindow", m_engine->newFunction(closeWindow)); mf_obj.setProperty("inventoryItem", m_engine->newFunction(inventoryItem)); mf_obj.setProperty("uniqueWindowItem", m_engine->newFunction(uniqueWindowItem)); mf_obj.setProperty("canPlaceBlock", m_engine->newFunction(canPlaceBlock)); mf_obj.setProperty("activateItem", m_engine->newFunction(activateItem)); mf_obj.setProperty("dimension", m_engine->newFunction(dimension)); mf_obj.setProperty("onlinePlayers", m_engine->newFunction(onlinePlayers)); // hook up hax functions QScriptValue hax_obj = m_engine->newObject(); mf_obj.setProperty("hax", hax_obj); hax_obj.setProperty("setPosition", m_engine->newFunction(setPosition)); hax_obj.setProperty("positionUpdateInterval", m_engine->newFunction(positionUpdateInterval)); hax_obj.setProperty("setGravityEnabled", m_engine->newFunction(setGravityEnabled)); hax_obj.setProperty("setJesusModeEnabled", m_engine->newFunction(setJesusModeEnabled)); hax_obj.setProperty("placeBlock", m_engine->newFunction(placeBlock)); hax_obj.setProperty("activateBlock", m_engine->newFunction(activateBlock)); // run main script QString main_script_contents = internalReadFile(m_main_script_filename); if (main_script_contents.isNull()) { m_stderr << "file not found: " << m_main_script_filename << "\n"; m_stderr.flush(); QCoreApplication::instance()->exit(1); return; } m_engine->evaluate(main_script_contents, m_main_script_filename); checkEngine("evaluating main script"); if (m_exiting) return; // connect to server bool success; success = connect(m_game, SIGNAL(entitySpawned(QSharedPointer<Game::Entity>)), this, SLOT(handleEntitySpawned(QSharedPointer<Game::Entity>))); Q_ASSERT(success); success = connect(m_game, SIGNAL(entityMoved(QSharedPointer<Game::Entity>)), this, SLOT(handleEntityMoved(QSharedPointer<Game::Entity>))); Q_ASSERT(success); success = connect(m_game, SIGNAL(entityDespawned(QSharedPointer<Game::Entity>)), this, SLOT(handleEntityDespawned(QSharedPointer<Game::Entity>))); Q_ASSERT(success); success = connect(m_game, SIGNAL(animation(QSharedPointer<Game::Entity>,Message::AnimationType)), this, SLOT(handleAnimation(QSharedPointer<Game::Entity>,Message::AnimationType))); Q_ASSERT(success); success = connect(m_game, SIGNAL(entityEffect(QSharedPointer<Game::Entity>,QSharedPointer<Game::StatusEffect>)), this, SLOT(handleEntityEffect(QSharedPointer<Game::Entity>,QSharedPointer<Game::StatusEffect>))); Q_ASSERT(success); success = connect(m_game, SIGNAL(removeEntityEffect(QSharedPointer<Game::Entity>,QSharedPointer<Game::StatusEffect>)), this, SLOT(handleRemoveEntityEffect(QSharedPointer<Game::Entity>,QSharedPointer<Game::StatusEffect>))); Q_ASSERT(success); success = connect(m_game, SIGNAL(chunkUpdated(Int3D,Int3D)), this, SLOT(handleChunkUpdated(Int3D,Int3D))); Q_ASSERT(success); success = connect(m_game, SIGNAL(signUpdated(Int3D,QString)), this, SLOT(handleSignUpdated(Int3D,QString))); Q_ASSERT(success); success = connect(m_game, SIGNAL(playerPositionUpdated()), this, SLOT(movePlayerPosition())); Q_ASSERT(success); success = connect(m_game, SIGNAL(loginStatusUpdated(Server::LoginStatus)), this, SLOT(handleLoginStatusUpdated(Server::LoginStatus))); Q_ASSERT(success); success = connect(m_game, SIGNAL(chatReceived(QString,QString)), this, SLOT(handleChatReceived(QString,QString))); Q_ASSERT(success); success = connect(m_game, SIGNAL(nonSpokenChatReceived(QString)), this, SLOT(handleNonSpokenChatReceived(QString))); Q_ASSERT(success); success = connect(m_game, SIGNAL(timeUpdated(double)), this, SLOT(handleTimeUpdated(double))); Q_ASSERT(success); success = connect(m_game, SIGNAL(playerDied()), this, SLOT(handlePlayerDied())); Q_ASSERT(success); success = connect(m_game, SIGNAL(playerSpawned(int)), this, SLOT(handlePlayerSpawned(int))); Q_ASSERT(success); success = connect(m_game, SIGNAL(playerHealthStatusUpdated()), this, SLOT(handlePlayerHealthStatusUpdated())); Q_ASSERT(success); success = connect(m_game, SIGNAL(inventoryUpdated()), this, SLOT(handleInventoryUpdated())); Q_ASSERT(success); success = connect(m_game, SIGNAL(stoppedDigging(Game::StoppedDiggingReason)), this, SLOT(handleStoppedDigging(Game::StoppedDiggingReason))); Q_ASSERT(success); success = connect(m_game, SIGNAL(windowOpened(Message::WindowType)), this, SLOT(handleWindowOpened(Message::WindowType))); Q_ASSERT(success); success = connect(m_game, SIGNAL(equippedItemChanged()), this, SLOT(handleEquippedItemChanged())); Q_ASSERT(success); success = connect(&m_stdin_reader, SIGNAL(readLine(QString)), this, SLOT(handleReadLine(QString))); Q_ASSERT(success); success = connect(&m_stdin_reader, SIGNAL(eof()), QCoreApplication::instance(), SLOT(quit())); Q_ASSERT(success); m_physics_doer = new PhysicsDoer(m_game); m_started_game = true; m_game->start(); m_stdin_reader.start(); }
int ClientNetwork::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: packetReceived(); break; case 1: packetCorrupted(); break; case 2: pingUpdated((*reinterpret_cast< quint32(*)>(_a[1]))); break; case 3: chatReceived((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2])),(*reinterpret_cast< QString(*)>(_a[3])),(*reinterpret_cast< ENUM_TYPE(*)>(_a[4]))); break; case 4: serverInformationsChanged((*reinterpret_cast< ServerInformations(*)>(_a[1]))); break; case 5: clientIDChanged((*reinterpret_cast< CLID(*)>(_a[1]))); break; case 6: nicknameChanged((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 7: error((*reinterpret_cast< ENUM_TYPE(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 8: clientVoted((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< CLID(*)>(_a[2]))); break; case 9: newGameMaster((*reinterpret_cast< CLID(*)>(_a[1]))); break; case 10: serverName((*reinterpret_cast< QString(*)>(_a[1]))); break; case 11: motdChanged((*reinterpret_cast< QString(*)>(_a[1]))); break; case 12: gameLaunched(); break; case 13: narrationChanged((*reinterpret_cast< QString(*)>(_a[1]))); break; case 14: mapChanged((*reinterpret_cast< MapPtr(*)>(_a[1]))); break; case 15: mapFlare((*reinterpret_cast< QPoint(*)>(_a[1])),(*reinterpret_cast< CLID(*)>(_a[2]))); break; case 16: scriptToGMMsg((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 17: scriptToOwnerMsg((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 18: scriptActionMsg((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 19: scriptToPlayerMsg((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 20: scriptMsg((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 21: scriptError((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 22: updateEntities((*reinterpret_cast< const QList<EntityInformations>(*)>(_a[1]))); break; case 23: updateEntity((*reinterpret_cast< const EntityInformations(*)>(_a[1]))); break; case 24: entityDeleted((*reinterpret_cast< const QString(*)>(_a[1]))); break; case 25: scriptReceived((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 26: ressourcesUpdated((*reinterpret_cast< const QMap<QString,RSID>(*)>(_a[1]))); break; case 27: connectionEtablished(); break; case 28: connectionLost(); break; case 29: diceRolled((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< quint16(*)>(_a[2])),(*reinterpret_cast< quint16(*)>(_a[3]))); break; case 30: sanctionned((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< ENUM_TYPE(*)>(_a[2])),(*reinterpret_cast< QString(*)>(_a[3]))); break; case 31: clientJoined((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 32: clientLeft((*reinterpret_cast< CLID(*)>(_a[1]))); break; case 33: playSound((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 34: syncLibs((*reinterpret_cast< QList<SoundLibInformations>(*)>(_a[1]))); break; case 35: syncLanguagesList((*reinterpret_cast< QList<QPair<QString,QString> >(*)>(_a[1]))); break; case 36: syncDictionariesList((*reinterpret_cast< QStringList(*)>(_a[1]))); break; case 37: syncScriptList((*reinterpret_cast< QStringList(*)>(_a[1]))); break; case 38: updateCharacterList((*reinterpret_cast< const QStringList(*)>(_a[1]))); break; case 39: send((*reinterpret_cast< Packet*(*)>(_a[1])),(*reinterpret_cast< bool(*)>(_a[2]))); break; case 40: send((*reinterpret_cast< Packet*(*)>(_a[1]))); break; case 41: send((*reinterpret_cast< Packet(*)>(_a[1]))); break; case 42: send((*reinterpret_cast< qint32(*)>(_a[1])),(*reinterpret_cast< const QByteArray(*)>(_a[2]))); break; case 43: ping(); break; case 44: { qint32 _r = getPing(); if (_a[0]) *reinterpret_cast< qint32*>(_a[0]) = _r; } break; case 45: { QString _r = serverIP(); if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r; } break; case 46: { quint16 _r = serverPort(); if (_a[0]) *reinterpret_cast< quint16*>(_a[0]) = _r; } break; case 47: flush(); break; case 48: connection(); break; case 49: disconnection(); break; case 50: { bool _r = setServer((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< quint16(*)>(_a[2]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 51: connected(); break; case 52: disconnected(); break; case 53: dataReceived(); break; case 54: socketError((*reinterpret_cast< QAbstractSocket::SocketError(*)>(_a[1]))); break; case 55: operatePacket((*reinterpret_cast< Packet*(*)>(_a[1]))); break; default: ; } _id -= 56; } return _id; }