<?php
session_start();
require_once '../core/config.php';
require_once '../core/classes/user.php';

header('content-type:application/json');
$user = new User($con, $_SESSION['user']);
function sign($script, $key) {
$signature = "";
openssl_sign($script, $signature, $key, OPENSSL_ALGO_SHA1);
return base64_encode($signature);
}

/*
$joinUser = [
    "id" => $_SESSION['user'],
    "username" => $user->getUsername(),
    "mship" => "None"
];*/

$joinUser = [
    "id" => rand(1,5),
    "username" => "Grubloxxer-".getrandmax(),
    "mship" => "None"
];

$place = [
    "id" => $_GET["gameid"]
];

$placeCreator = [
    "id" => 6945435215,
    "username" => "PlaceCreator",
];

$charapp = $site["url"]."/v1.1/avatar-fetch?userId=".$joinUser["id"]."&placeId=".$place["id"];

$server = [
    "ip" => $_GET["ip"],
    "port" => $_GET["port"]
];

$joinscript = [
    "ClientPort" => 0,
    "MachineAddress" => $server["ip"],
    "ServerPort" => $server["port"],
    "PingUrl" => "",
    "PingInterval" => 20,
    "UserName" => $joinUser["username"],
    "SeleniumTestMode" => false,
    "UserId" => $joinUser["id"],
    "SuperSafeChat" => false,
    "CharacterAppearance" => $charapp,
    "ClientTicket" => "",
    "GameId" => $place["id"],
    "PlaceId" => $place["id"],
    "MeasurementUrl" => "",
    "WaitingForCharacterGuid" => "26eb3e21-aa80-475b-a777-b43c3ea5f7d2",
    "BaseUrl" => $site["url"]."/",
    "ChatStyle" => "ClassicAndBubble",
    "VendorId" => "0",
    "ScreenShotInfo" => "",
    "VideoInfo" => "",
    "CreatorId" => $placeCreator["id"],
    "CreatorTypeEnum" => "User",
    "MembershipType" => $joinUser["mship"],
    "AccountAge" => 3000000,
    "CookieStoreFirstTimePlayKey" => "rbx_evt_ftp",
    "CookieStoreFiveMinutePlayKey" => "rbx_evt_fmp",
    "CookieStoreEnabled" => true,
    "IsRobloxPlace" => false,
    "GenerateTeleportJoin" => false,
    "IsUnknownOrUnder13" => false,
    "SessionId" => "",
    "DataCenterId" => 0,
    "UniverseId" => 3,
    "BrowserTrackerId" => 0,
    "UsePortraitMode" => false,
    "FollowUserId" => 0,
    "characterAppearanceId" => $joinUser["id"]
];

$data = json_encode($joinscript, JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
$signature = sign("\r\n" . $data, $gameSettings["privatekey"]);
exit("--rbxsig%". $signature . "%\r\n" . $data);
?>