Advertisement
Guest User

BYOND Webclient source

a guest
Dec 20th, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.73 KB | None | 0 0
  1. ! function(t) {
  2. function e(t, e) {
  3. var n, o, i = "";
  4. return (n = t.indexOf("#")) < 0 || (i = t.substr(n), t = t.substr(0, n)), (n = t.indexOf("?")) < 0 || (o = t.substr(n), t = t.substr(0, n)), e = o ? o + "&" + e : "?" + e, t + e + i
  5. }
  6.  
  7. function n() {
  8. return q || (q = $("<div></div>").css({
  9. visibility: "hidden",
  10. position: "absolute",
  11. left: -2e4,
  12. top: -2e4,
  13. width: "100%",
  14. height: "100%"
  15. }).appendTo("body")), q
  16. }
  17.  
  18. function o(t, e) {
  19. F = t, G = e, P || (P = $("<iframe id=loginiframe></iframe>").css(z)), P.appendTo(n()).attr("src", K + "&t=" + x()).lightbox($.extend({
  20. canclose: r
  21. }, J))
  22. }
  23.  
  24. function i(t, e) {
  25. F = t, G = e, P || (P = $("<iframe id=loginiframe></iframe>").css(z)), P.appendTo(n()).attr("src", logouturl + "&t=" + x())
  26. }
  27.  
  28. function a() {
  29. f(), P && P.attr("src", ""), $.lightbox_handler && $.lightbox_handler.close(), v(Q + "?command=whoami", l)
  30. }
  31.  
  32. function r() {
  33. return !1
  34. }
  35.  
  36. function l(t) {
  37. var e = F;
  38. V = t, t ? ($("#loginkey").text(t), $("#playlogin").text("Play as " + t)) : ($("#loginkey").text(""), $("#playlogin").text("Play (login)")), F = null, e && e()
  39. }
  40.  
  41. function s() {
  42. f(), W ? d() : w(d)
  43. }
  44.  
  45. function d() {
  46. V ? i(d) : o(b, p)
  47. }
  48.  
  49. function _() {
  50. f(), w()
  51. }
  52.  
  53. function c(t, e) {
  54. h(), u(e), t && l(t)
  55. }
  56.  
  57. function u(t) {
  58. j = t;
  59. var e, n, o, i, a = [{
  60. id: "play",
  61. text: "Play",
  62. svg: "M 0% 0% L 100% 50% L 0% 100% z",
  63. func: s
  64. }],
  65. r = $("#embed_buttons");
  66. if (!r.length) return _();
  67. for (r.children(".embed_button").remove(), e = 0, n = a.length; n > e; ++e) {
  68. if (o = a[e], i = $("<a class=embed_button></a>").attr("id", o.id).text(o.text).appendTo(r), o.svg) {
  69. var l = m(o.svg, 50);
  70. i.empty().append(l), i.attr("title", o.text)
  71. }
  72. o.func ? i.click(o.func) : o.link && i.attr({
  73. href: o.link,
  74. target: "_blank"
  75. })
  76. }
  77. }
  78.  
  79. function f() {
  80. $("#embed_buttons_container").fadeOut()
  81. }
  82.  
  83. function p() {
  84. $("#embed_buttons_container").fadeIn()
  85. }
  86.  
  87. function h() {
  88. var t, n, o, i, a = [{
  89. id: "popout",
  90. text: "Popout",
  91. svg: "M 0 0 L 40% 0 L 40% 10% L 10% 10% L 10% 40% L 0 40% z M 100% 100% L 60% 100% L 60% 90% L 90% 90% L 90% 60% L 100% 60% z M 100% 0 L 100% 40% L 90% 40% L 90% 10% L 60% 10% L 60% 0 z M 0 100% L 0 60% L 10% 60% L 10% 90% L 40% 90% L 40% 100% z",
  92. link: e("" + window.location, "popout=1")
  93. }],
  94. r = $("#embed_footer");
  95. if (r.length)
  96. for (t = 0, n = a.length; n > t; ++t) {
  97. if (o = a[t], i = $("<a class=embed_button></a>").attr("id", o.id).text(o.text).appendTo(r), o.svg) {
  98. var l = m(o.svg, 16);
  99. i.empty().append(l), i.attr("title", o.text)
  100. }
  101. o.func ? i.click(o.func) : o.link && i.attr({
  102. href: o.link,
  103. target: "_blank"
  104. })
  105. }
  106. }
  107.  
  108. function m(t, e) {
  109. var n = "http://www.w3.org/2000/svg",
  110. o = document.createElementNS(n, "svg");
  111. o.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xlink", "http://www.w3.org/1999/xlink"), $(o).css({
  112. width: e,
  113. height: e,
  114. display: "inline-block"
  115. });
  116. var i = document.createElementNS(n, "path");
  117. return i.setAttribute("d", g(t, e)), i.setAttribute("fill", "currentColor"), o.appendChild(i), o
  118. }
  119.  
  120. function g(t, e) {
  121. var n, o;
  122. for (t = t.split(/[\s,\n\r]+/), n = 0, o = t.length; o > n; ++n) t[n].match(/^(-?[\d\.]+)(e[+\-]?\d+)?\%$/i) && (t[n] = (parseFloat(RegExp.$1) * e / 100).toFixed(2).replace(/\.0+$/, "").replace(/(\..*)0+$/, "$1"));
  123. return t.join(" ")
  124. }
  125.  
  126. function v(t, e) {
  127. var n = ajaxObject();
  128. n && (n.onreadystatechange = function() {
  129. if (n && 4 == n.readyState) {
  130. var t = null;
  131. 200 == n.status && (t = n.responseText.replace(/\r/g, "").replace(/^\n+/, "").replace(/\n$/, "")), e(t, n.status)
  132. }
  133. }, n.open("GET", t, !0), n.send(""))
  134. }
  135.  
  136. function b() {
  137. W ? (Z = null, $("#gameframe").attr("src", W)) : w()
  138. }
  139.  
  140. function w(t) {
  141. W = null, v(j + "/query", function(e) {
  142. var n;
  143. if (null == e) return void A("The game is currently not available to play.");
  144. try {
  145. n = JSON.parse(e)
  146. } catch (o) {
  147. console.log(o)
  148. }
  149. return n.fail ? void A($("<div></div>").text(n.fail).html()) : (n.url || (n.url = "/play"), n.url.match(/^https?:\/+/) || (n.url = j + n.url), W = n.url, void(t ? t() : b()))
  150. })
  151. }
  152.  
  153. function y(t, e) {
  154. v(t + "/query", function(n) {
  155. var o;
  156. if (null != n) {
  157. try {
  158. o = JSON.parse(n)
  159. } catch (i) {
  160. console.log(i)
  161. }
  162. o.fail || (o.url || (o.url = "/play"), o.url.match(/^https?:\/+/) || (o.url = t + o.url), O(), W = o.url, e ? e() : b())
  163. }
  164. })
  165. }
  166.  
  167. function T(t) {
  168. var e = t.data;
  169. "closelogin" == e && a()
  170. }
  171.  
  172. function x() {
  173. return (new Date).getTime()
  174. }
  175.  
  176. function E(t) {
  177. var e = new XMLHttpRequest,
  178. n = "command=keyreq&url=" + encodeURIComponent(Z);
  179. t && (n += "&key=" + encodeURIComponent(t)), e.onreadystatechange = function() {
  180. if (this && 4 == this.readyState) {
  181. var t = this.responseText.trim();
  182. t.length < 25 ? C(t) : (M(), I(te, 200 == this.status ? "key:" + t : "key_failed", Z))
  183. }
  184. }, e.open("POST", "/", !0), e.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"), e.send(n)
  185. }
  186.  
  187. function L(e) {
  188. var n, o, i, a, r = e.source,
  189. l = e.data;
  190. if ("string" == typeof l) {
  191. for (; r && r != t;) r = r.parent;
  192. if (r == t) {
  193. if (e.origin && e.origin.match(/^https?:\/+\w+\.byond\.com(\/|$)/)) return void T(e);
  194. if (Z) {
  195. if (Z != e.origin) return
  196. } else Z = e.origin, te = e.source;
  197. if ("key" == l) E();
  198. else if (l.match(/^progress:(\d+)\/(\d+)$/i)) D(RegExp.$1, RegExp.$2);
  199. else if (l.match(/^scripts:(.*)$/i)) "begin" == RegExp.$1 ? D(0, 0, "Connected to world, downloading client") : D();
  200. else if (l.match(/^command:/i)) {
  201. if (l = l.substr(8), i = "", l.match(/^\w*:/) && (n = l.indexOf(":"), o = l.substr(0, n), l = l.substr(n + 1)), l.match(/^\w*:/) && (n = l.indexOf(":"), i = l.substr(n + 1), l = l.substr(0, n)), a = t.webclientCommand, a && a[l]) {
  202. var s = a[l](i, e.source);
  203. o && e.source.postMessage("command_callback:" + JSON.stringify({
  204. name: o,
  205. command: l,
  206. arg: i,
  207. result: s
  208. }), "*")
  209. }
  210. } else l.match(/^ready/i) && N()
  211. }
  212. }
  213. }
  214.  
  215. function I(t, e, n) {
  216. n = n || "*";
  217. try {
  218. t.postMessage(e, n)
  219. } catch (o) {}
  220. }
  221.  
  222. function O() {
  223. $("#backdrop").show(), $("#altContent2").length || $("#notprogress").append('<div id="altContent2" class="embed_div"></div>'), $("#progresstext").text(""), $("#progress").css("width", 0)
  224. }
  225.  
  226. function D(t, e, n) {
  227. try {
  228. t || (t = 0), e || (e = 0), t -= 0, e -= 0, n ? ($("#progresstext").text(n), show = 1) : (t > e && (t = e), $("#progressbar").css("width", t / (e || 1) * 100 + "%"), e && e > t && $("#progresstext").text("Loading resources (" + k(t) + " of " + k(e) + ")"))
  229. } catch (o) {}
  230. }
  231.  
  232. function k(t) {
  233. for (var e = ["B", "KB", "MB", "GB"], n = 0; t >= 1e3 && n + 1 < e.length;) t /= 1024, ++n;
  234. return t = n && 100 > t ? t.toFixed(1) : Math.floor(t + .5), t + " " + e[n]
  235. }
  236.  
  237. function A(t) {
  238. $("#faildiv").show();
  239. var e = $("#fail");
  240. e.length || (X = null, $("<table cellspacing=0 cellpadding=0><tr><td id=failtext></td></tr></table>").css({
  241. border: "none",
  242. maxWidth: "60%",
  243. height: "100%",
  244. margin: "0 auto"
  245. }).appendTo("#faildiv")), $("#failtext").html(t)
  246. }
  247.  
  248. function C(t) {
  249. X || (X = t, pe ? U(!0) : R(!0))
  250. }
  251.  
  252. function M() {
  253. ce && clearTimeout(ce), $(ae).remove(), $("#gameframe,.gameitem").css("visibility", "visible")
  254. }
  255.  
  256. function N() {
  257. $("#backdrop").hide()
  258. }
  259.  
  260. function B() {
  261. $("#faildiv").hide(), M(), E(X)
  262. }
  263.  
  264. function S() {
  265. var t = X;
  266. ee = null, A("Flash is unavailable. Please wait a few seconds for game to load."), X = t, setTimeout(B, 15e3)
  267. }
  268.  
  269. function R(t) {
  270. t ? ee = pe ? U : S : ee && ee != R || (ee = H);
  271. try {
  272. $(ae).append($("<video id=vid1></video>").css({
  273. width: "100%",
  274. height: "100%",
  275. zIndex: "0"
  276. }));
  277. var e = videojs("vid1", {
  278. controls: !1,
  279. autoplay: !1,
  280. width: $(re).width(),
  281. height: $(re).height()
  282. });
  283. e.ads(), e.vast({
  284. url: "http://ads.intergi.com/adrawdata/3.0/5205/3327855/0/4796/ADTECH;cors=yes;width=__WIDTH__;height=__HEIGHT__;referring_url=__WEB_URL__;content_url=__CONTENT_URL__;media_id=__MEDIA_ID__;title=__TITLE__;device=__DEVICE__;model=__MODEL__;os=__OS__;osversion=__OSVERSION__;ua=__UA__;ip=__IP__;uniqueid:__UNIQUEID__;tags=__TAGS__;number=__RANDOM__;time=__TIME__",
  285. skip: 10
  286. }), e.on("adsready", function() {
  287. var t = this;
  288. t.vast.preroll(), e.paused() && (e.one("play", function() {
  289. e.controls(!1)
  290. }), e.controls(!0))
  291. }), e.on("adend", function() {
  292. $("#vid").remove(), B()
  293. }), e.on("adtimeout", function() {
  294. $("#vid").remove(), ee ? (ue = 0, setTimeout(ee, 100)) : H("html5")
  295. }), e.trigger("contentupdate")
  296. } catch (n) {
  297. ++ue < 3 ? setTimeout(R, 100) : ee && (ue = 0, setTimeout(ee, 100))
  298. }
  299. }
  300.  
  301. function U(t) {
  302. if (t ? ee = R : ee && ee != U || (ee = H), !pe) return S();
  303. try {
  304. if (he) {
  305. var e, n = $("body")[0];
  306. e = document.createElement("script");
  307. var o = {
  308. "data-vast-src": "http://ads.intergi.com/adrawdata/3.0/5205/2594435/0/2898/ADTECH;cors=yes;width=__WIDTH__;height=__HEIGHT__;referring_url=__WEB_URL__;content_url=__CONTENT_URL__;media_id=__MEDIA_ID__;title=__TITLE__;device=__DEVICE__;model=__MODEL__;os=__OS__;osversion=__OSVERSION__;ua=__UA__;ip=__IP__;uniqueid:__UNIQUEID__;tags=__TAGS__;number=__RANDOM__;time=__TIME__",
  309. "data-container": ie,
  310. "data-post-ad-container": ie,
  311. "data-autoplay": "true",
  312. "data-autoload": "false",
  313. "data-width": $(re).width(),
  314. "data-height": $(re).height(),
  315. "data-foreground-color": "0xffffff",
  316. "data-background-color": "0x000000"
  317. };
  318. if (e.setAttribute)
  319. for (var i in o) o.hasOwnProperty(i) && e.setAttribute(i, o[i]);
  320. else
  321. for (var i in o) o.hasOwnProperty(i) && (e[i] = o[i]);
  322. e.src = "http://cdn.playwire.com/bolt/js/embed.min.js", n.appendChild(e), boltTries = 0, window.boltDone = function() {
  323. Bolt.removeVideo(ie, !0), B()
  324. }, window.boltFailed = function() {
  325. Bolt.removeVideo(ie, !0), ee ? (ue = 0, setTimeout(ee, 100)) : H()
  326. }, window.startBolt = function() {
  327. return "undefined" != typeof Bolt && Bolt.renderVideo ? (Bolt.addEventListener ? Bolt.addEventListener(ie, "boltAdComplete", boltDone) : $(ae).bind("boltAdComplete", boltDone), Bolt.addEventListener && Bolt.addEventListener(ie, "boltAdError", boltFailed), void Bolt.renderVideo(ie, new AttributesParser(e).data)) : void(++boltTries > 20 ? H() : setTimeout(startBolt, 100))
  328. }, startBolt()
  329. } else {
  330. var e = document.createElement("script"),
  331. n = $("body")[0];
  332. e.src = "http://cdn.playwire.com/wrapper.min.js", n.appendChild(e);
  333. var a = function() {
  334. var t = iwWrapper;
  335. return typeof t === oe ? setTimeout(a, 100) : (t.url = "http://ads.intergi.com/adrawdata/3.0/5205/3245144/0/2898/ADTECH;cors=yes;width=__WIDTH__;height=__HEIGHT__;referring_url=__WEB_URL__;content_url=__CONTENT_URL__;media_id=__MEDIA_ID__;title=__TITLE__;device=__DEVICE__;model=__MODEL__;os=__OS__;osversion=__OSVERSION__;ua=__UA__;ip=__IP__;uniqueid:__UNIQUEID__;tags=__TAGS__;number=__RANDOM__;time=__TIME__", t.to_wrap = ie, t.width = $(re).width(), t.height = $(re).height(), t.callback = B, void t.init())
  336. };
  337. setTimeout(a, 100)
  338. }
  339. } catch (r) {
  340. ++ue < 3 ? setTimeout(U, 100) : ee && (ue = 0, setTimeout(ee, 100))
  341. }
  342. }
  343.  
  344. function H(t) {
  345. ee = null, X = null, ce && clearTimeout(ce), ce = 0;
  346. var e;
  347. e = "flash" == t ? 'To view ads you need <a href="http//get.adobe.com/flashplayer">Flash</a> enabled.' : 'This could be due to an ad blocker or a technical issue.<br/><br/>If you are not blocking ads, please contact <a href="' + se + '">BYOND support</a>. Otherwise, please turn off your ad blocking software for byond.com.', A(de + e + _e)
  348. }
  349. var P, V, j, W, F, G, q, z = {
  350. minWidth: "25vw",
  351. minHeight: "25vh",
  352. maxWidth: "90vw",
  353. maxHeight: "90vh"
  354. },
  355. J = {
  356. foregroundColor: "transparent"
  357. },
  358. Q = window.location.origin,
  359. Y = Q.replace(/^http:/, "https:").replace(/^https:\/+www\./, "https://secure."),
  360. K = Y + "/login.cgi?frame=1&login=1&url=" + Q;
  361. logouturl = Y + "/?command=logout_ajax", byondplay = Q + "/play/";
  362. var X, Z, te, ee, ne = swfobject,
  363. oe = "undefined",
  364. ie = "altContent2",
  365. ae = "#" + ie,
  366. re = "#gamecontainer",
  367. le = "http://www.byond.com/membership",
  368. se = "http://www.byond.com/support",
  369. de = "An advertisement could not be displayed. ",
  370. _e = ' <a href="' + le + '">BYOND Members</a> also have the option to disable ads.',
  371. ce = 0,
  372. ue = 0,
  373. fe = typeof ne !== oe ? ne.getFlashPlayerVersion() : {},
  374. pe = !!fe.major,
  375. he = !(typeof ne === oe || !ne.hasFlashPlayerVersion("11.4"));
  376. t.addEventListener("message", L), $.extend(t, {
  377. login: o,
  378. logout: i,
  379. logged_in: l,
  380. ajaxGet: v,
  381. pinggame: w,
  382. pinglink: y,
  383. progress: D,
  384. setup: c
  385. })
  386. }(window);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement