void CSelectMemberDlg::OnBnClickedBtnOk()
{
	int nAddCount = 0;
	int nDelCount = 0;
	PMEMBERINFO ppMemberAdd[ELC_MAX_MEMBER_COUNT] = {0};
	PMEMBERINFO ppMemberDel[ELC_MAX_MEMBER_COUNT] = {0};

	for (int i=0; i<m_wndMemberList.GetItemCount(); i++) {
		PMEMBERINFO pMemberInfo = (PMEMBERINFO)m_wndMemberList.GetItemData(i);

		if (m_wndMemberList.GetCheck(i)) {
			if (!HasMember(pMemberInfo))
				ppMemberAdd[nAddCount ++] = pMemberInfo;
		} else
		{
			if (HasMember(pMemberInfo))
				ppMemberDel[nDelCount ++] = pMemberInfo;
		}
	}

	if (m_pCallback) {
		m_pCallback->OnStudentCheckChanged(m_dwFuncMask, TRUE, nAddCount, ppMemberAdd);
		m_pCallback->OnStudentCheckChanged(m_dwFuncMask, FALSE, nDelCount, ppMemberDel);
	}

	CElcSkinDialog::OnOK();
}
AnimationMaster AnimationMaster::Unserialize(Renderer* renderer,
		rapidjson::Value* value) {

	PASSERT( value->IsObject(), "AnimationMaster cannot unserialize because passed is not an object (Note: This may indicate parsing failure)");
	PASSERT(value->FindMember("animations")->value.IsArray(), "AnimationMaster cannot unserialize because animations field is not an array");
	PASSERT(value->FindMember("default")->value.IsString(), "AnimationMaster default should be string");

	std::map<PBase::String, AnimationSetEntry> anims;

	rapidjson::Value* animations = &value->FindMember("animations")->value;

	for (auto it = animations->Begin(); it != animations->End(); it++) {
		PASSERT(it->IsObject(), "AnimationMaster animation entry should be an object");
		PASSERT(it->FindMember("name")->value.IsString(), "AnimationMaster animation entry name should be string");
		PASSERT(it->FindMember("animation_file")->value.IsString(), "AnimationMaster animation file path should be string");

		String after;

		if (it->HasMember("after")) {
			PASSERT(it->FindMember("after")->value.IsString(), "after should be a string animation identifier");
			after = it->FindMember("after")->value.GetString();
		}

		anims[it->FindMember("name")->value.GetString()] = AnimationSetEntry(
			renderer->LoadAnimationSet(it->FindMember("animation_file")->value.GetString()),
			after);
	}

	return AnimationMaster(value->FindMember("default")->value.GetString(), anims);
}
Beispiel #3
0
std::shared_ptr<rapidjson::Document> ListingFetch::fetch(std::string singleUrl)
{
    std::unique_ptr<FetchJob_Curl> pFetcher(new FetchJob_Curl(singleUrl));

    bool res = pFetcher->run();

    if (res == false)
    {
        DEBUG_PRINT("Fetch failed from URL: " << singleUrl << std::endl);
        return nullptr;
    }
    else
    {
        DEBUG_PRINT("Read " << pFetcher->getSize() << " bytes from URL: " << singleUrl << std::endl);
    }

    auto spJsonDoc = std::make_shared<rapidjson::Document>();
    spJsonDoc->Parse(pFetcher->getData());

    if (spJsonDoc->IsObject() && spJsonDoc->HasMember("jsontv"))
    {
        DEBUG_PRINT("Parsed a valid JSONTV document." << std::endl);
        return spJsonDoc;
    }
    else
    {
        DEBUG_PRINT("JSON parse failed!" << std::endl);
        return nullptr;
    }
}
Beispiel #4
0
bool Alliance::HasMember(string username)
{
	Client * client = m_main->GetClientByName(username);
	if (!client)
		return false;
	return HasMember(client->m_accountid);
}
Beispiel #5
0
void ActiveParty :: AddMember(CreatureInstance* member)
{
	if(HasMember(member->CreatureDefID) == true)
		return;

	PartyMember newMember;
	newMember.mCreatureDefID = member->CreatureDefID;
	newMember.mCreatureID = member->CreatureID;
	newMember.mDisplayName = member->css.display_name;
	newMember.mCreaturePtr = member;
	newMember.mSocket = member->simulatorPtr->sc.ClientSocket;
	mMemberList.push_back(newMember);

	member->PartyID = mPartyID;

	// If the party member is in an instance that has an active PVP game, update the teams
	if(member->actInst->pvpGame != NULL && mPVPTeam != PVP::PVPTeams::NONE) {

		char buf[64];
		int wpos = PrepExt_PVPTeamAdd(buf, member->actInst->pvpGame, member->css.display_name, member->CreatureID, mPVPTeam);
		member->actInst->LSendToAllSimulator(buf, wpos, -1);

//
	}
}
Beispiel #6
0
// player is object class becouse its called from unit class
void Group::SendPartyKillLog(Object * player, Object * Unit)
{
	if (!player || !Unit || !HasMember(((Player*)player)))
		return;

	WorldPacket data(SMSG_PARTYKILLLOG, 16);
	data << player->GetGUID();
	data << Unit->GetGUID();
	SendPacketToAll(&data);
}
void CSelectMemberDlg::InitList()
{
	PMEMBERINFO ppMemberInfo[ELC_MAX_MEMBER_COUNT] = {0};
	int nCount = m_pTeacherFrame->GetAllMemberInfoPtrs(ppMemberInfo);

	for (int i=0; i<nCount; i++) 
	{
		if (!ppMemberInfo[i]) 
			continue;

		if (m_pExcludeMember && m_pExcludeMember == ppMemberInfo[i])
			continue;
		
		int nImage = GetStateIconIndex(ppMemberInfo[i]);
		int nItem = m_wndMemberList.InsertItem(m_wndMemberList.GetItemCount(), 
			ppMemberInfo[i]->szDefaultName, nImage);
		m_wndMemberList.SetItemData(nItem, (DWORD)ppMemberInfo[i]);

		if (HasMember(ppMemberInfo[i])) {
			m_wndMemberList.SetCheck(nItem, TRUE);
		}
	}
}
Status ATCConfigParserPlugin::update(const std::string& source,
                                     const ParserConfig& config) {
  auto cv = config.find(kParserKey);
  if (cv == config.end()) {
    return Status(1, "No configuration for ATC (Auto Table Construction)");
  }
  auto obj = data_.getObject();

  data_.copyFrom(cv->second.doc(), obj);
  data_.add(kParserKey, obj);

  const auto& ac_tables = data_.doc()[kParserKey];
  auto tables = RegistryFactory::get().registry("table");
  auto registered = registeredATCTables();

  for (const auto& ac_table : ac_tables.GetObject()) {
    std::string table_name{ac_table.name.GetString()};
    auto params = ac_table.value.GetObject();

    std::string query{params.HasMember("query") && params["query"].IsString()
                          ? params["query"].GetString()
                          : ""};
    std::string path{params.HasMember("path") && params["path"].IsString()
                         ? params["path"].GetString()
                         : ""};
    std::string platform{params.HasMember("platform") &&
                                 params["platform"].IsString()
                             ? params["platform"].GetString()
                             : ""};

    if (query.empty() || path.empty()) {
      LOG(WARNING) << "ATC Table: " << table_name << " is misconfigured";
      continue;
    }

    if (!checkPlatform(platform)) {
      VLOG(1) << "Skipping ATC table: " << table_name
              << " because platform doesn't match";
      continue;
    }

    TableColumns columns;
    std::string columns_value;
    columns_value.reserve(256);

    for (const auto& column : params["columns"].GetArray()) {
      columns.push_back(make_tuple(
          std::string(column.GetString()), TEXT_TYPE, ColumnOptions::DEFAULT));
      columns_value += std::string(column.GetString()) + ",";
    }

    registered.erase(table_name);
    std::string table_settings{table_name + query + columns_value + path};
    std::string old_setting;
    auto s = getDatabaseValue(
        kPersistentSettings, kDatabaseKeyPrefix + table_name, old_setting);

    // The ATC table hasn't changed so we skip ahead
    if (table_settings == old_setting) {
      continue;
    }

    // Remove the old table to replace with the new one
    s = removeATCTables({table_name});
    if (!s.ok()) {
      LOG(WARNING) << "ATC table overrides core table; Refusing registration";
      continue;
    }

    s = setDatabaseValue(
        kPersistentSettings, kDatabaseKeyPrefix + table_name, table_settings);

    if (!s.ok()) {
      LOG(WARNING) << "Could not write to database";
      continue;
    }

    s = tables->add(
        table_name, std::make_shared<ATCPlugin>(path, columns, query), true);

    if (!s.ok()) {
      LOG(WARNING) << s.getMessage();
      deleteDatabaseValue(kPersistentSettings, kDatabaseKeyPrefix + table_name);
      continue;
    }

    PluginResponse resp;
    Registry::call(
        "sql", "sql", {{"action", "attach"}, {"table", table_name}}, resp);
    LOG(INFO) << "Registered ATC table: " << table_name;
  }

  if (registered.size() > 0) {
    VLOG(1)
        << "Removing any ATC tables that were removed in this configuration "
           "change";
    removeATCTables(registered);
  }
  return Status();
}
Beispiel #9
0
bool DownloadManager::Process()
{
    switch (m_downloadState)
    {
    case DS_IDLE:
    {
        m_downloadState = DS_FETCHING_CONFIG;

        m_httpClient = new HttpClient();

        std::wstring hostname = m_gameServer.GetWAddress();

        std::map<std::string, std::string> postMap;
        postMap["method"] = "getConfiguration";

        bool isUpdate = false;

        if (!m_updateQueue.empty())
        {
            std::string resourceString;

            while (!m_updateQueue.empty())
            {
                resourceString += m_updateQueue.front();

                m_updateQueue.pop();

                if (!m_updateQueue.empty())
                {
                    resourceString += ";";
                }
            }

            postMap["resources"] = resourceString;

            isUpdate = true;
        }

        m_httpClient->DoPostRequest(hostname, m_gameServer.GetPort(), L"/client", postMap, [=] (bool result, std::string connData)
        {
            if (!result)
            {
                // TODO: make this a non-fatal error leading back to UI
                GlobalError("Obtaining configuration from server failed.");

                return;
            }

            if (!isUpdate)
            {
                m_requiredResources.clear();
            }

            std::string serverHost = m_gameServer.GetAddress();
            serverHost += va(":%d", m_gameServer.GetPort());

            // parse the received YAML file
            //try
            //{
            //auto node = YAML::Load(connData);
            rapidjson::Document node;
            node.Parse(connData.c_str());

            if (node.HasParseError())
            {
                auto err = node.GetParseError();

                GlobalError("parse error %d", err);
            }

            if (node.HasMember("loadScreen"))
            {
                m_serverLoadScreen = node["loadScreen"].GetString();
            }

            auto& resources = node["resources"];

            std::string origBaseUrl = node["fileServer"].GetString();

            for (auto it = resources.Begin(); it != resources.End(); it++)
            {
                auto& resource = *it;

                std::string baseUrl = origBaseUrl;

                if (it->HasMember("fileServer"))
                {
                    baseUrl = (*it)["fileServer"].GetString();
                }

                ResourceData resData(resource["name"].GetString(), va(baseUrl.c_str(), serverHost.c_str()));

                //for (auto& file : resource["files"])
                auto& files = resource["files"];
                for (auto i = files.MemberBegin(); i != files.MemberEnd(); i++)
                {
                    std::string filename = i->name.GetString();
                    std::string hash = i->value.GetString();

                    resData.AddFile(filename, hash);
                }

                if (resource.HasMember("streamFiles"))
                {
                    auto& streamFiles = resource["streamFiles"];

                    //for (auto& file : resource["streamFiles"])
                    for (auto i = streamFiles.MemberBegin(); i != streamFiles.MemberEnd(); i++)
                    {
                        std::string filename = i->name.GetString();
                        std::string hash = i->value["hash"].GetString();
                        uint32_t rscFlags = i->value["rscFlags"].GetUint();
                        uint32_t rscVersion = i->value["rscVersion"].GetUint();
                        uint32_t size = i->value["size"].GetUint();

                        AddStreamingFile(resData, filename, hash, rscFlags, rscVersion, size);
                    }
                }

                if (isUpdate)
                {
                    for (auto ite = m_requiredResources.begin(); ite != m_requiredResources.end(); ite++)
                    {
                        if (ite->GetName() == resData.GetName())
                        {
                            m_requiredResources.erase(ite);
                            break;
                        }
                    }
                }

                trace("%s\n", resData.GetName().c_str());

                m_isUpdate = isUpdate;

                m_requiredResources.push_back(resData);
            }
            /*}
            catch (std::exception& e)
            {
            	GlobalError("YAML parsing error in server configuration (%s)", e.msg);

            	return;
            }*/

            if (isUpdate)
            {
                assert(m_isUpdate);
            }

            m_downloadState = DS_CONFIG_FETCHED;
        });

        break;
    }

    case DS_CONFIG_FETCHED:
    {
        // check cache existence (TODO: and integrity?)
        auto resourceCache = TheResources.GetCache();

        auto downloadList = resourceCache->GetDownloadsFromList(m_requiredResources);

        resourceCache->ClearMark();
        resourceCache->MarkList(m_requiredResources);
        resourceCache->MarkStreamingList(m_streamingFiles);

        m_downloadList = std::queue<ResourceDownload>();

        for (auto& download : downloadList)
        {
            m_downloadList.push(download);
        }

        if (m_downloadList.empty())
        {
            m_downloadState = DS_DOWNLOADED_SINGLE;
        }
        else
        {
            m_downloadState = DS_DOWNLOADING;
        }

        break;
    }

    case DS_DOWNLOADING:
    {
        if (!m_currentDownload.get())
        {
            m_currentDownload = std::make_shared<ResourceDownload>(m_downloadList.front());
            m_downloadList.pop();

            std::wstring hostname, path;
            uint16_t port;

            m_httpClient->CrackUrl(m_currentDownload->sourceUrl, hostname, path, port);

            m_httpClient->DoFileGetRequest(hostname, port, path, TheResources.GetCache()->GetCacheDevice(), m_currentDownload->targetFilename, [=] (bool result, std::string connData)
            {
                m_downloadState = DS_DOWNLOADED_SINGLE;
            });
        }

        break;
    }

    case DS_DOWNLOADED_SINGLE:
    {
        if (m_currentDownload.get())
        {
            TheResources.GetCache()->AddFile(m_currentDownload->targetFilename, m_currentDownload->filename, m_currentDownload->resname);

            m_currentDownload = nullptr;
        }

        if (!m_downloadList.empty())
        {
            m_downloadState = DS_DOWNLOADING;
        }
        else
        {
            if (!m_isUpdate)
            {
                TheResources.Reset();
            }
            else
            {
                // unload any resources we already know that are currently unprocessed
                for (auto& resource : m_requiredResources)
                {
                    // this is one we just got from the configuration redownload
                    if (!resource.IsProcessed())
                    {
                        auto resourceData = TheResources.GetResource(resource.GetName());

                        if (!resourceData.get())
                        {
                            continue;
                        }

                        // sanity check: is the resource not running?
                        if (resourceData->GetState() == ResourceStateRunning)
                        {
                            FatalError("Tried to unload a running resource in DownloadMgr. (%s)", resource.GetName().c_str());
                        }

                        // remove all packfiles related to this old resource
                        auto packfiles = resourceData->GetPackFiles();

                        for (auto& packfile : packfiles)
                        {
                            // FIXME: implementation detail from same class
                            fiDevice::Unmount(va("resources:/%s/", resourceData->GetName().c_str()));

                            packfile->closeArchive();

                            // remove from the to-close list (!)
                            for (auto it = m_packFiles.begin(); it != m_packFiles.end(); it++)
                            {
                                if (it->second == packfile)
                                {
                                    m_packFiles.erase(it);
                                    break;
                                }
                            }
                        }

                        // and delete the resource (hope nobody kept a reference to that sucker, ha!)
                        TheResources.DeleteResource(resourceData);
                    }
                }
            }

            //std::string resourcePath = "citizen:/resources/";
            //TheResources.ScanResources(fiDevice::GetDevice("citizen:/setup2.xml", true), resourcePath);

            std::list<std::shared_ptr<Resource>> loadedResources;

            // mount any RPF files that we include
            for (auto& resource : m_requiredResources)
            {
                if (m_isUpdate && resource.IsProcessed())
                {
                    continue;
                }

                std::vector<rage::fiPackfile*> packFiles;

                for (auto& file : resource.GetFiles())
                {
                    if (file.filename.find(".rpf") != std::string::npos)
                    {
                        // get the path of the RPF
                        std::string markedFile = TheResources.GetCache()->GetMarkedFilenameFor(resource.GetName(), file.filename);

                        rage::fiPackfile* packFile = new rage::fiPackfile();
                        packFile->openArchive(markedFile.c_str(), true, false, 0);
                        packFile->mount(va("resources:/%s/", resource.GetName().c_str()));

                        packFiles.push_back(packFile);
                        m_packFiles.push_back(std::make_pair(va("resources:/%s/", resource.GetName().c_str()), packFile));
                    }
                }

                // load the resource
                auto resourceLoad = TheResources.AddResource(resource.GetName(), va("resources:/%s/", resource.GetName().c_str()));

                if (resourceLoad.get())
                {
                    resourceLoad->AddPackFiles(packFiles);

                    loadedResources.push_back(resourceLoad);
                }

                resource.SetProcessed();
            }

            if (m_isUpdate)
            {
                for (auto& resource : loadedResources)
                {
                    resource->Start();
                }
            }

            m_loadedResources = loadedResources;

            m_downloadState = DS_DONE;
        }

        break;
    }

    case DS_DONE:
        m_downloadState = DS_IDLE;

        if (m_isUpdate && !m_updateQueue.empty())
        {
            ProcessQueuedUpdates();
        }

        if (!m_serverLoadScreen.empty() && !m_isUpdate)
        {
            CustomLoadScreens::PrepareSwitchTo(m_serverLoadScreen);
        }

        m_isUpdate = false;

        g_netLibrary->DownloadsComplete();

        while (!g_netLibrary->ProcessPreGameTick())
        {
            HANDLE hThread = GetCurrentThread();

            MsgWaitForMultipleObjects(1, &hThread, TRUE, 15, 0);
        }

        return true;
    }

    return false;
}