Created
December 30, 2023 05:30
-
-
Save witchiestwitchery/9998d3ec369f8bd9b06bf32718a99b54 to your computer and use it in GitHub Desktop.
Utility module for making direct game join links easier https://devforum.roblox.com/t/1904069
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--!strict | |
-- GameJoinUrlUtil | |
-- A utility module for generation join links for any game | |
-- with url enocoding and launchdata encoding included | |
-- @Kalrnlo | |
-- 30/11/2023 | |
local HTTPService = game:GetService("HttpService") | |
local StartUrlFormat = "https://www.roblox.com/games/start?placeId=%d" | |
local WebsiteBypassUrlFormat = "roblox://placeId=%d" | |
local LaunchDataBypassUrlFormat = `{WebsiteBypassUrlFormat}&launchdata=%s` | |
-- Put the encoded BypassURl as the first string when formatting | |
-- Put the encoded StartUrl as the second string when formatting | |
local AppsFlyerUrlFormat = "ro.blox.com/Ebh5?af_dp=%s&af_web_dp=%s" | |
local LaunchDataStartUrlFormat = `{StartUrlFormat}&launchdata=%s` | |
-- Taken from: | |
-- https://devforum.roblox.com/t/233570/2 | |
local function DecodeCharacter(hex: string) | |
return string.char(tonumber(hex, 16) :: any) | |
end | |
local GameJoinUrlUtil = {} | |
function GameJoinUrlUtil.EncodeLaunchData(LaunchData: string): string | |
-- using string.len as #LaunchData generated faulty results | |
assert(string.len(LaunchData) < 200, "LaunchData encoded exceeds 200 character limit") | |
return HTTPService:UrlEncode(LaunchData) | |
end | |
function GameJoinUrlUtil.MakeAppsFlyerUrl(PlaceId: number, LaunchData: string) | |
local StartUrl: string, BypassUrl: string | |
if LaunchData then | |
local LaunchData = GameJoinUrlUtil.EncodeLaunchData(LaunchData) | |
BypassUrl = string.format(LaunchDataBypassUrlFormat, PlaceId, LaunchData) | |
StartUrl = string.format(LaunchDataStartUrlFormat, PlaceId, LaunchData) | |
else | |
BypassUrl = string.format(WebsiteBypassUrlFormat, PlaceId) | |
StartUrl = string.format(StartUrlFormat, PlaceId) | |
end | |
return string.format(AppsFlyerUrlFormat, BypassUrl, StartUrl) | |
end | |
function GameJoinUrlUtil.MakeStartUrl(PlaceId: number, LaunchData: string) | |
if LaunchData then | |
local LaunchData = GameJoinUrlUtil.EncodeLaunchData(LaunchData) | |
return string.format(LaunchDataStartUrlFormat, PlaceId, LaunchData) | |
else | |
return string.format(StartUrlFormat, PlaceId) | |
end | |
end | |
function GameJoinUrlUtil.DecodeUrl(Url: string) | |
local Output, t = string.gsub(Url, "%%(%x%x)", DecodeCharacter) | |
return Output | |
end | |
return GameJoinUrlUtil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment