Skip to content

Commit

Permalink
Merge remote-tracking branch 'blattersturm/fix/jump-list-icon-path' i…
Browse files Browse the repository at this point in the history
…nto master-pub
  • Loading branch information
blattersturm committed Aug 14, 2021
2 parents cc3c7a6 + 3587858 commit 50662fa
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 9 deletions.
65 changes: 61 additions & 4 deletions code/components/glue/src/ConnectToNative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#endif

std::string g_lastConn;
static std::string g_connectNonce;

extern bool XBR_InterceptCardResponse(const nlohmann::json& j);
extern bool XBR_InterceptCancelDefer();
Expand Down Expand Up @@ -362,7 +363,7 @@ static WRL::ComPtr<IShellLink> MakeShellLink(const ServerLink& link)

if (!link.rawIcon.empty())
{
auto iconPath = MakeRelativeCitPath(fmt::sprintf(L"data/cache/browser/%08x.ico", HashString(link.rawIcon.c_str())));
auto iconPath = MakeRelativeCitPath(fmt::sprintf(L"data/cache/servers/%08x.ico", HashString(link.rawIcon.c_str())));

FILE* f = _wfopen(iconPath.c_str(), L"wb");

Expand Down Expand Up @@ -455,6 +456,7 @@ static void UpdatePendingAuthPayload()
static InitFunction initFunction([] ()
{
static std::function<void()> g_onYesCallback;
static std::function<void()> backfillDoneEvent;

static ipc::Endpoint ep("launcherTalk", false);

Expand All @@ -477,6 +479,39 @@ static InitFunction initFunction([] ()
{
netLibrary = lib;

netLibrary->OnInfoBlobReceived.Connect([](std::string_view sv, const std::function<void()>& cb)
{
try
{
auto info = nlohmann::json::parse(sv);
std::string iconUri = "";
std::string svLicenseKeyToken = "";

if (auto it = info.find("icon"); it != info.end())
{
iconUri = "data:image/png;base64," + it.value().get<std::string>();
}

if (auto it = info.find("vars"); it != info.end())
{
if (auto it2 = it.value().find("sv_licenseKeyToken"); it2 != it.value().end())
{
svLicenseKeyToken = it2.value().get<std::string>();
}
}

auto outInfo = nlohmann::json::object({ { "icon", iconUri }, { "token", svLicenseKeyToken }, { "vars", info["vars"] } });
auto outData = nlohmann::json::object({ { "nonce", g_connectNonce }, { "server", outInfo } }).dump();

nui::PostFrameMessage("mpMenu", fmt::sprintf(R"({ "type": "backfillServerInfo", "data": %s })", outData));
backfillDoneEvent = cb;
}
catch (...)
{
cb();
}
});

netLibrary->OnConnectOKReceived.Connect([](NetAddress)
{
auto peerAddress = netLibrary->GetCurrentPeer().ToString();
Expand Down Expand Up @@ -882,6 +917,15 @@ static InitFunction initFunction([] ()
{
UpdatePendingAuthPayload();
}
else if (!_wcsicmp(type, L"backfillDone"))
{
auto ev = std::move(backfillDoneEvent);

if (ev)
{
ev();
}
}
else if (!_wcsicmp(type, L"getMinModeInfo"))
{
#ifdef GTA_FIVE
Expand Down Expand Up @@ -914,10 +958,23 @@ static InitFunction initFunction([] ()
}
else if (!_wcsicmp(type, L"connectTo"))
{
std::wstring hostnameStrW = arg;
std::string hostnameStr(hostnameStrW.begin(), hostnameStrW.end());
std::string hostName = ToNarrow(arg);

try
{
auto j = nlohmann::json::parse(hostName);
hostName = j[0].get<std::string>();

if (j.size() >= 2)
{
g_connectNonce = j[1].get<std::string>();
}
}
catch (...)
{
}

ConnectTo(hostnameStr, true);
ConnectTo(hostName, true);
}
else if (!_wcsicmp(type, L"cancelDefer"))
{
Expand Down
5 changes: 5 additions & 0 deletions code/components/net/include/NetLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,11 @@ class
// a2: previous connection state
fwEvent<ConnectionState, ConnectionState> OnStateChanged;

// a1: the info.json data, raw
// a2: callback when completed
// #TODO: fxSingleEvent maybe?
fwEvent<std::string_view, const std::function<void()>&> OnInfoBlobReceived;

// for use from high-level code calling down to lower-level code
fwEvent<const NetLibraryClientInfo&> OnClientInfoReceived;

Expand Down
16 changes: 14 additions & 2 deletions code/components/net/src/NetLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1296,9 +1296,8 @@ concurrency::task<void> NetLibrary::ConnectToServer(const std::string& rootUrl)

auto continueAfterAllowance = [=]()
{
m_httpClient->DoGetRequest(fmt::sprintf("%sinfo.json", url), [=](bool success, const char* data, size_t size)
auto doneCB = [=](const char* data, size_t size)
{
if (success)
{
try
{
Expand Down Expand Up @@ -1495,6 +1494,19 @@ concurrency::task<void> NetLibrary::ConnectToServer(const std::string& rootUrl)
m_connectionState = CS_IDLE;
}
}
};

m_httpClient->DoGetRequest(fmt::sprintf("%sinfo.json", url), [=](bool success, const char* data, size_t size)
{
if (success)
{
std::string blobStr(data, size);

OnInfoBlobReceived(blobStr, [blobStr, doneCB]()
{
doneCB(blobStr.data(), blobStr.size());
});
}
else
{
OnConnectionError("Failed to fetch /info.json to obtain policy metadata.", json::object({
Expand Down
37 changes: 34 additions & 3 deletions ext/cfx-ui/src/app/game.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ export class CfxGameService extends GameService {

private inConnecting = false;

private serverHistoryEntry: ServerHistoryEntry = null;
private connectNonce = '';

private profileList: Record<string, string> = {};
card: boolean;

Expand Down Expand Up @@ -506,6 +509,9 @@ export class CfxGameService extends GameService {
});
}

break;
case 'backfillServerInfo':
this.backfillServerInfo(event.data.data);
break;
}
});
Expand Down Expand Up @@ -858,6 +864,24 @@ export class CfxGameService extends GameService {
(<any>window).invokeNative('getMinModeInfo', '');
}

private async backfillServerInfo(eventData: any) {
if (this.connectNonce === '' || eventData.nonce !== this.connectNonce) {
(<any>window).invokeNative('backfillDone', '');
return;
}

const newHistoryEntry: ServerHistoryEntry = {
...this.serverHistoryEntry,
...eventData.server
};

await this.addServerHistory(newHistoryEntry);
this.connectNonce = '';
this.serverHistoryEntry = null;

(<any>window).invokeNative('backfillDone', '');
}

async connectTo(server: Server, enteredAddress?: string) {
if (this.inConnecting) {
return;
Expand All @@ -870,7 +894,7 @@ export class CfxGameService extends GameService {
localStorage.setItem('lastServer', server.address);
this.lastServer = server;

await this.addServerHistory({
const historyEntry: ServerHistoryEntry = {
address: server.address,
hostname: server.hostname.replace(/\^[0-9]/g, ''),
title: enteredAddress || '',
Expand All @@ -879,9 +903,16 @@ export class CfxGameService extends GameService {
rawIcon: '',
vars: server.data?.vars || {},
token: server.data?.vars?.sv_licenseKeyToken || '',
});
};

await this.addServerHistory(historyEntry);
this.serverHistoryEntry = historyEntry;
this.connectNonce = (new Date()).getTime().toString();

(<any>window).invokeNative('connectTo', this.getConnectAddress(server, enteredAddress));
(<any>window).invokeNative('connectTo', JSON.stringify([
this.getConnectAddress(server, enteredAddress),
this.connectNonce,
]));

// temporary, we hope
this.history.push(server.address);
Expand Down

0 comments on commit 50662fa

Please sign in to comment.