Advertisement
Guest User

Untitled

a guest
Jan 14th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.75 KB | None | 0 0
  1. 1452799300 [14/01/2016], [CEO]Radon (cl_carfui.lua)
  2. ====================
  3. nil
  4. ====================
  5.  
  6. 1452799300 [14/01/2016], [CEO]Radon (cl_carstereo.lua)
  7. ====================
  8. nil
  9. ====================
  10.  
  11. 1452799300 [14/01/2016], [CEO]Radon (cl_floatyuilib.lua)
  12. ====================
  13. nil
  14. ====================
  15.  
  16. 1452799300 [14/01/2016], [CEO]Radon (cl_wcr_soundmuffler.lua)
  17. ====================
  18. nil
  19. ====================
  20.  
  21. 1452799300 [14/01/2016], [CEO]Radon (playxlib.lua)
  22. ====================
  23. -- PlayX
  24. -- Copyright (c) 2009, 2010 sk89q <http://www.sk89q.com>
  25. --
  26. -- This program is free software: you can redistribute it and/or modify
  27. -- it under the terms of the GNU General Public License as published by
  28. -- the Free Software Foundation, either version 2 of the License, or
  29. -- (at your option) any later version.
  30. --
  31. -- This program is distributed in the hope that it will be useful,
  32. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  33. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  34. -- GNU General Public License for more details.
  35. --
  36. -- You should have received a copy of the GNU General Public License
  37. -- along with this program. If not, see <http://www.gnu.org/licenses/>.
  38. --
  39. -- $Id$
  40. -- Version 2.8.5 by Nexus [BR] on 10-01-2014 09:25 PM (-02:00 GMT)
  41.  
  42. playxlib = {}
  43.  
  44. --- Takes a width and height and returns a boolean to indicate whether the shape
  45. -- is optimally a square. This is used by the engine code to determine
  46. -- whether a square screen is better than a rectangular screen for a certain
  47. -- set of screen dimensions.
  48. -- @param Width
  49. -- @param Height
  50. -- @return Boolean
  51. function playxlib.IsSquare(width, height)
  52. -- Square screens with the new Webkit materials added by AzuiSleet
  53. -- seems to observe some serious problems
  54. return false
  55. --return math.abs(width / height - 1) < 0.2
  56. end
  57.  
  58. --- Encodes a string to be placed into a JavaScript string.
  59. -- @param str String to encode
  60. -- @return Encoded
  61. function playxlib.JSEscape(str)
  62. return str:gsub("\\", "\\\\"):gsub("\"", "\\\""):gsub("\'", "\\'")
  63. :gsub("\r", "\\r"):gsub("\n", "\\n")
  64. end
  65.  
  66. --- Percent encodes a value for URLs.
  67. -- @param s String
  68. -- @return Encoded
  69. function playxlib.URLEscape(s)
  70. s = tostring(s)
  71. local new = ""
  72.  
  73. for i = 1, #s do
  74. local c = s:sub(i, i)
  75. local b = c:byte()
  76. if (b >= 65 and b <= 90) or (b >= 97 and b <= 122) or
  77. (b >= 48 and b <= 57) or
  78. c == "_" or c == "." or c == "~" then
  79. new = new .. c
  80. else
  81. new = new .. string.format("%%%X", b)
  82. end
  83. end
  84.  
  85. return new
  86. end
  87.  
  88. --- Percent encodes a table for the query part of a URL.
  89. -- @param vars Table of keys and values
  90. -- @return Encoded string
  91. function playxlib.URLEscapeTable(vars)
  92. local str = ""
  93.  
  94. for k, v in pairs(vars) do
  95. str = str .. playxlib.URLEscape(k) .. "=" .. playxlib.URLEscape(v) .. "&"
  96. end
  97.  
  98. return str:sub(1, -2)
  99. end
  100.  
  101. --- HTML encodes a string.
  102. -- @param str
  103. -- @return Encoded string
  104. function playxlib.HTMLEscape(str)
  105. return str:gsub("&", "&amp;")
  106. :gsub("<", "&lt;")
  107. :gsub(">", "&gt;")
  108. :gsub("\"", "&quot;")
  109. end
  110.  
  111. --- Unescape HTML. This function fudges the job, and it does not handle all of
  112. -- HTML's named entities.
  113. -- @param s The string
  114. -- @return Unescaped string
  115. function playxlib.HTMLUnescape(s)
  116. if not s then return nil end
  117.  
  118. s = s:gsub("<br */?>", "\n")
  119. s = s:gsub("&#([0-9]+);", function(m) return string.char(tonumber(m)) end)
  120. s = s:gsub("&#x(%x+);", function(m) return string.char(tonumber(m, 16)) end)
  121. s = s:gsub("&lt;", "<")
  122. s = s:gsub("&gt;", ">")
  123. s = s:gsub("&quot;", "\"")
  124. s = s:gsub("&amp;", "&")
  125. s = s:gsub("<[^<]+>", "")
  126.  
  127. return s
  128. end
  129.  
  130. --- URL unescapes a string. Doesn't handle %####
  131. -- @param str String
  132. -- @return Unescaped string
  133. function playxlib.URLUnescape(str)
  134. -- Probably should de-anonymize this...
  135. return str:gsub("%%([A-Fa-f0-9][A-Fa-f0-9])", function(m)
  136. local n = tonumber(m, 16)
  137. if not n then return "" end -- Not technically required
  138. return string.char(n)
  139. end)
  140. end
  141.  
  142. --- Parses a query.
  143. -- @param str String to parse
  144. -- @return Table with keys and values
  145. function playxlib.ParseQuery(str)
  146. local str = str:gsub("^%?", "")
  147. local parts = string.Explode("&", str)
  148. local out = {}
  149.  
  150. for _, part in pairs(parts) do
  151. local key, value = part:match("^([^=]+)=([^=]+)$")
  152. if key then
  153. out[playxlib.URLUnescape(key)] = playxlib.URLUnescape(value)
  154. elseif part:Trim() ~= "" then
  155. out[playxlib.URLUnescape(part)] = ""
  156. end
  157. end
  158.  
  159. return out
  160. end
  161.  
  162. --- Attempts to match a list of patterns against a string, and returns
  163. -- the first match, or nil if there were no matches.
  164. -- @param str The string
  165. -- @param patterns Table of patterns
  166. -- @return Table of results, or bil
  167. function playxlib.FindMatch(str, patterns)
  168. for _, pattern in pairs(patterns) do
  169. local m = {str:match(pattern)}
  170. if m[1] then return m end
  171. end
  172.  
  173. return nil
  174. end
  175.  
  176. --- Gets a timestamp in UTC.
  177. -- @param t Time
  178. -- @return Time
  179. function playxlib.UTCTime(t)
  180. local tSecs = os.time(t)
  181. t = os.date("*t", tSecs)
  182. local tUTC = os.date("!*t", tSecs)
  183. tUTC.isdst = t.isdst
  184. local utcSecs = os.time(tUTC)
  185. return tSecs + os.difftime(tSecs, utcSecs)
  186. end
  187.  
  188. --- Turns seconds into minutes and seconds.
  189. -- @param t Time
  190. -- @return String
  191. function playxlib.ReadableTime(t)
  192. return string.format("%s:%02s", math.floor(t / 60), math.floor(t) % 60)
  193. end
  194.  
  195. --- Gets the tags out of a string.
  196. -- @param s
  197. -- @param delim Delimiter
  198. -- @return Table
  199. function playxlib.ParseTags(s, delim)
  200. if not s then return nil end
  201.  
  202. local final = {}
  203.  
  204. local tags = string.Explode(delim, s)
  205. for _, tag in pairs(tags) do
  206. tag = tag:Trim()
  207. if tag ~= "" and not table.HasValue(final, tag) then
  208. table.insert(final, tag)
  209. end
  210. end
  211.  
  212. return final
  213. end
  214.  
  215. --- Casts a console command arg to a string.
  216. -- @param v
  217. -- @param default
  218. -- @return Boolean
  219. function playxlib.CastToString(v, default)
  220. if v == nil then return default end
  221. return tostring(v)
  222. end
  223.  
  224. --- Casts a console command arg to a number.
  225. -- @param v
  226. -- @param default
  227. -- @return Boolean
  228. function playxlib.CastToNumber(v, default)
  229. v = tonumber(v)
  230. if v == nil then return default end
  231. return v
  232. end
  233.  
  234. --- Casts a console command arg to a bool.
  235. -- @param v
  236. -- @param default
  237. -- @return Boolean
  238. function playxlib.CastToBool(v, default)
  239. if v == nil then return default end
  240. if v == "false" then return false end
  241. v = tonumber(v)
  242. if v == nil then return true end
  243. return v ~= 0
  244. end
  245.  
  246. --- Parses a human-readable time string. Returns the number in seconds, or
  247. -- nil if it cannot detect a format. Blank strings will return 0.
  248. -- @param str
  249. -- @return Time
  250. function playxlib.ParseTimeString(str)
  251. if str == "" or str == nil then return 0 end
  252.  
  253. str = str:Trim()
  254.  
  255. if tonumber(str) then
  256. return tonumber(str)
  257. end
  258.  
  259. str = str:gsub("t=", "")
  260. str = str:gsub("#", "")
  261.  
  262. local m, s = str:match("^([0-9]+):([0-9]+)$")
  263. if m then
  264. return tonumber(m) * 60 + tonumber(s)
  265. end
  266.  
  267. local m, s, ms = str:match("^([0-9]+):([0-9]+)(%.[0-9]+)$")
  268. if m then
  269. return tonumber(m) * 60 + tonumber(s) + tonumber(ms)
  270. end
  271.  
  272. local h, m, s = str:match("^([0-9]+):([0-9]+):([0-9]+)$")
  273. if h then
  274. return tonumber(h) * 3600 + tonumber(m) * 60 + tonumber(s)
  275. end
  276.  
  277. local h, m, s, ms = str:match("^([0-9]+):([0-9]+):([0-9]+)(%.[0-9]+)$")
  278. if h then
  279. return tonumber(h) * 3600 + tonumber(m) * 60 + tonumber(s) + tonumber(ms)
  280. end
  281.  
  282. local s = str:match("^([0-9]+)s$")
  283. if s then
  284. return tonumber(s)
  285. end
  286.  
  287. local m, s = str:match("^([0-9]+)m *([0-9]+)s$")
  288. if m then
  289. return tonumber(m) * 60 + tonumber(s)
  290. end
  291.  
  292. local m, s = str:match("^([0-9]+)m$")
  293. if m then
  294. return tonumber(m) * 60
  295. end
  296.  
  297. local h, m, s = str:match("^([0-9]+)h *([0-9]+)m *([0-9]+)s$")
  298. if h then
  299. return tonumber(h) * 3600 + tonumber(m) * 60 + tonumber(s)
  300. end
  301.  
  302. local h, m = str:match("^([0-9]+)h *([0-9]+)m$")
  303. if h then
  304. return tonumber(h) * 3600 + tonumber(m) * 60
  305. end
  306.  
  307. return nil
  308. end
  309.  
  310. --- Parses a string containing data formatted in CSV into a table.
  311. -- Fields can be quoted with double quotations or be unquoted, and characters
  312. -- can be escaped with a backslash. This CSV parser is very forgiving. The
  313. -- return table has each line in a new entry, and each field is then a further
  314. -- entry in a table. Not all the rows may have the same number of fields in
  315. -- the returned table.
  316. -- @param data CSV data
  317. -- @return Table containg data
  318. function playxlib.ParseCSV(data)
  319. local lines = string.Explode("\n", data:gsub("\r", ""))
  320. local result = {}
  321.  
  322. for i, line in pairs(lines) do
  323. local line = line:Trim()
  324.  
  325. if line ~= "" then
  326. local buffer = ""
  327. local escaped = false
  328. local inQuote = false
  329. local fields = {}
  330.  
  331. for c = 1, #line do
  332. local char = line:sub(c, c)
  333. if escaped then
  334. buffer = buffer .. char
  335. escaped = false
  336. else
  337. if char == "\\" then
  338. escaped = true
  339. elseif char == "\"" then
  340. inQuote = not inQuote
  341. elseif char == "," then
  342. if inQuote then
  343. buffer = buffer .. char
  344. else
  345. table.insert(fields, buffer)
  346. buffer = ""
  347. end
  348. else
  349. buffer = buffer .. char
  350. end
  351. end
  352. end
  353.  
  354. table.insert(fields, buffer)
  355. table.insert(result, fields)
  356. end
  357. end
  358.  
  359. return result
  360. end
  361.  
  362. --- Turns a table into CSV data.
  363. -- @param data Table to convert
  364. -- @return CSV data
  365. function playxlib.WriteCSV(data)
  366. local output = ""
  367.  
  368. for _, v in pairs(data) do
  369. local line = ""
  370. for _, p in pairs(v) do
  371. if type(p) == 'boolean' then
  372. line = line .. ",\"" .. (p and "true" or "false") .. "\""
  373. else
  374. line = line .. ",\"" .. tostring(p):gsub("[\"\\]", "\\%1") .. "\""
  375. end
  376. end
  377.  
  378. output = output .. "\n" .. line:sub(2)
  379. end
  380.  
  381. return output:sub(2)
  382. end
  383.  
  384. --- Tries to interpret a string as a boolean. "true," "y," etc. are considered
  385. -- to be true.
  386. -- @param s String
  387. -- @return Boolean
  388. function playxlib.IsTrue(s)
  389. local s = s:lower():Trim()
  390. return s == "t" or s == "true" or s == "1" or s == "y" or s == "yes"
  391. end
  392.  
  393. function playxlib.EmptyToNil(s)
  394. if s == "" then return nil end
  395. return s
  396. end
  397.  
  398. --- Converts a decimal Volume to a Float Volume
  399. -- @param volume String
  400. -- @return number
  401. function playxlib.volumeFloat(volume)
  402. if(volume == 100) then
  403. volume = 1
  404. elseif(volume >= 10) then
  405. volume = tonumber("0."..volume)
  406. elseif(volume <= 9) then
  407. volume = tonumber("0.0"..volume)
  408. end
  409. return volume
  410. end
  411.  
  412. -- Handler result
  413. local HandlerResult = {}
  414. playxlib.HandlerResult = HandlerResult
  415.  
  416. -- Make callable
  417. local mt = {}
  418. mt.__call = function(...)
  419. return HandlerResult.new(...)
  420. end
  421. setmetatable(HandlerResult, mt)
  422.  
  423. function HandlerResult:new(t, js, body, jsURL, center, url)
  424. local css, volumeFunc, playFunc, pauseFunc
  425.  
  426. if type(t) == 'table' then
  427. css = t.css
  428. js = t.js
  429. body = t.body
  430. jsURL = t.jsURL
  431. center = t.center
  432. url = t.url
  433. volumeFunc = t.volumeFunc and t.volumeFunc or nil
  434. playFunc = t.playFunc and t.playFunc or nil
  435. pauseFunc = t.pauseFunc and t.pauseFunc or nil
  436. else
  437. css = t
  438. end
  439.  
  440. css = playxlib.EmptyToNil(css)
  441. js = playxlib.EmptyToNil(js)
  442. jsURL = playxlib.EmptyToNil(jsURL)
  443. url = playxlib.EmptyToNil(url)
  444.  
  445. local instance = {
  446. CSS = css,
  447. Body = body,
  448. JS = js,
  449. JSInclude = jsURL,
  450. Center = center,
  451. ForceURL = url
  452. }
  453.  
  454. if volumeFunc ~= nil then
  455. instance.GetVolumeChangeJS = volumeFunc
  456. end
  457.  
  458. if playFunc ~= nil then
  459. instance.GetPlayJS = playFunc
  460. end
  461.  
  462. if pauseFunc ~= nil then
  463. instance.GetPauseJS = pauseFunc
  464. end
  465.  
  466. setmetatable(instance, self)
  467. self.__index = self
  468. return instance
  469. end
  470.  
  471. function HandlerResult:GetVolumeChangeJS(volume)
  472. return nil
  473. end
  474.  
  475. function HandlerResult:GetPlayJS()
  476. return nil
  477. end
  478.  
  479. function HandlerResult:GetPauseJS()
  480. return nil
  481. end
  482.  
  483. function HandlerResult:AppendJavaScript(js)
  484. self.JS = (self.JS and self.JS or "") .. js
  485. end
  486.  
  487. function HandlerResult:GetHTML()
  488. return [[
  489. <!DOCTYPE html>
  490. <html>
  491. <head>
  492. <title>PlayX</title>
  493. <style type="text/css">
  494. ]] .. self.CSS .. [[
  495. </style>
  496. <script type="text/javascript">
  497. ]] .. (self.JS and self.JS or "") .. [[
  498. </script>
  499. </head>
  500. <body>
  501. ]] .. self.Body .. [[
  502. </body>
  503. </html>
  504. ]]
  505. end
  506.  
  507. --- Generates the HTML for an IFrame.
  508. -- @param width
  509. -- @param height
  510. -- @param url
  511. -- @return HTML
  512. function playxlib.GenerateIFrame(width, height, url)
  513. return playxlib.HandlerResult(nil, nil, nil, nil, false, url)
  514. end
  515.  
  516. --- Generates the HTML for an image viewer. The image viewer will automatiaclly
  517. -- center the image (once size information becomes exposed in JavaScript).
  518. -- @param width
  519. -- @param height
  520. -- @param url
  521. -- @return HTML
  522. function playxlib.GenerateImageViewer(width, height, url)
  523. local url = playxlib.HTMLEscape(url)
  524.  
  525. -- CSS to center the image
  526. local css = [[
  527. body {
  528. margin: 0;
  529. padding: 0;
  530. border: 0;
  531. background: #000000;
  532. overflow: hidden;
  533. }
  534. td {
  535. text-align: center;
  536. vertical-align: middle;
  537. }
  538. ]]
  539.  
  540. -- Resizing code
  541. local js = [[
  542. var keepResizing = true;
  543. function resize(obj) {
  544. var ratio = obj.width / obj.height;
  545. if (]] .. width .. [[ / ]] .. height .. [[ > ratio) {
  546. obj.style.width = (]] .. height .. [[ * ratio) + "px";
  547. } else {
  548. obj.style.height = (]] .. width .. [[ / ratio) + "px";
  549. }
  550. }
  551. setInterval(function() {
  552. if (keepResizing && document.images[0]) {
  553. resize(document.images[0]);
  554. }
  555. }, 1000);
  556. ]]
  557.  
  558. local body = [[
  559. <div style="width: ]] .. width .. [[px; height: ]] .. height .. [[px; overflow: hidden">
  560. <table border="0" cellpadding="0" cellmargin="0" style="width: ]] .. width .. [[px; height: ]] .. height .. [[px">
  561. <tr>
  562. <td style="text-align: center">
  563. <img src="]] .. url .. [[" alt="" onload="resize(this); keepResizing = false" style="margin: auto" />
  564. </td>
  565. </tr>
  566. </table>
  567. </div>
  568. ]]
  569.  
  570. return playxlib.HandlerResult(css, js, body)
  571. end
  572.  
  573. --- Generates the HTML for a Flash player viewer.
  574. -- @param width
  575. -- @param height
  576. -- @param url
  577. -- @param flashVars Table
  578. -- @param js Extra JavaScript to add
  579. -- @param forcePlay Forces the movie to be 'played' every 1 second, if not playing
  580. -- @return HTML
  581. function playxlib.GenerateFlashPlayer(width, height, url, flashVars, js, forcePlay)
  582. local extraParams = ""
  583. local url = playxlib.HTMLEscape(url)
  584. local flashVars = flashVars and playxlib.URLEscapeTable(flashVars) or ""
  585.  
  586. local css = [[
  587. body {
  588. margin: 0;
  589. padding: 0;
  590. border: 0;
  591. background: #000000;
  592. overflow: hidden;
  593. }]]
  594.  
  595. if forcePlay then
  596. js = (js and js or "") .. [[
  597. setInterval(function() {
  598. try {
  599. var player = document.getElementById('player');
  600. if (player && !player.IsPlaying()) {
  601. player.play();
  602. }
  603. } catch (e) {}
  604. }, 1000);
  605. ]]
  606. extraParams = [[
  607. <param name="loop" value="false">
  608. ]]
  609. end
  610.  
  611. local body = [[
  612. <div style="width: ]] .. width .. [[px; height: ]] .. height .. [[px; overflow: hidden">
  613. <object
  614. type="application/x-shockwave-flash"
  615. src="]] .. url .. [["
  616. width="100%" height="100%" id="player">
  617. <param name="movie" value="]] .. url .. [[">
  618. <param name="quality" value="high">
  619. <param name="allowscriptaccess" value="always">
  620. <param name="allownetworking" value="all">
  621. <param name="allowfullscreen" value="false">
  622. <param name="FlashVars" value="]] .. flashVars .. [[">
  623. ]] .. extraParams .. [[
  624. <div style="background: red; color: white; font: 20pt Arial, sans-serif; padding: 10px">
  625. Adobe Flash Player <strong style="text-decoration: underline">for other browsers</strong>
  626. is not installed. Please visit http://get.adobe.com/flashplayer/otherversions/
  627. and select "Other Browsers." Garry's Mod must be restarted after installing.
  628. </div>
  629. </object>
  630. </div>
  631. ]]
  632.  
  633. local result = playxlib.HandlerResult(css, js, body)
  634. if forcePlay then result.ForceIE = true end
  635. return result
  636. end
  637.  
  638. --- Generate the HTML page for the JW player.
  639. -- @param width
  640. -- @param height
  641. -- @param start In seconds
  642. -- @param volume 0-100
  643. -- @param uri
  644. -- @param provider JW player provider ("image", "audio", etc.)
  645. -- @return HTML
  646. function playxlib.GenerateJWPlayer(width, height, start, volume, uri, provider)
  647.  
  648. local volumeFunc = function(volume)
  649. return [[try { jwplayer().setVolume(]] .. tostring(volume) .. [[);} catch (e) {}]]
  650. end
  651.  
  652. local playFunc = function()
  653. return [[try {jwplayer().play();} catch (e) {}]]
  654. end
  655.  
  656. local pauseFunc = function()
  657. return [[try { jwplayer().pause(); } catch (e) {}]]
  658. end
  659.  
  660. return playxlib.HandlerResult{
  661. url = PlayX.HostURL,
  662. center = false,
  663. volumeFunc = volumeFunc,
  664. playFunc = playFunc,
  665. pauseFunc = pauseFunc,
  666. js = [[
  667. jwplayer('player').setup({
  668. file: "]]..uri..[[",
  669. width: "]]..width..[[",
  670. height: "]]..height..[[",
  671. type: "]]..provider..[[",
  672. autostart: 1,
  673. controls: false,
  674. start: "]]..start..[[",
  675. volume: ]]..volume..[[
  676. });
  677.  
  678. var knownState = "";
  679.  
  680. function sendPlayerData(data) {
  681. var str = "";
  682. for (var key in data) {
  683. str += encodeURIComponent(key) + "=" + encodeURIComponent(data[key]) + "&"
  684. }
  685. playx.processPlayerData(str);
  686. }
  687.  
  688. function getStats(duration, position) {
  689. sendPlayerData({ State: jwplayer().getState(), Position: position, Duration: duration });
  690. }
  691.  
  692. jwplayer().onReady(function () {
  693. jwplayer().onTime(getStats)
  694. });
  695. ]]
  696. }
  697. end
  698.  
  699. --- Generates the HTML code for an included JavaScript file.
  700. -- @param width
  701. -- @param height
  702. -- @param url
  703. -- @return HTML
  704. function playxlib.GenerateJSEmbed(width, height, url, js)
  705. local url = playxlib.HTMLEscape(url)
  706.  
  707. local css = [[
  708. body {
  709. margin: 0;
  710. padding: 0;
  711. border: 0;
  712. background: #000000;
  713. overflow: hidden;
  714. }
  715. ]]
  716.  
  717. local body = [[
  718. <div style="width: ]] .. width .. [[px; height: ]] .. height .. [[px; overflow: hidden">
  719. <script src="]] .. url .. [[" type="text/javascript"></script>
  720. </div>
  721. ]]
  722.  
  723. return playxlib.HandlerResult(css, js, body, url)
  724. end
  725.  
  726. --- Parse URL Query
  727. -- @param query String
  728. -- @return table
  729. function playxlib.ParseURLQuery(query)
  730. local parsed = {}
  731. local pos = 0
  732.  
  733. query = string.gsub(query, "&amp;", "&")
  734. query = string.gsub(query, "&lt;", "<")
  735. query = string.gsub(query, "&gt;", ">")
  736.  
  737. local function ginsert(qstr)
  738. local first, last = string.find(qstr, "=")
  739. if first then
  740. parsed[string.sub(qstr, 0, first-1)] = string.sub(qstr, first+1)
  741. end
  742. end
  743.  
  744. while true do
  745. local first, last = string.find(query, "&", pos)
  746. if first then
  747. ginsert(string.sub(query, pos, first-1));
  748. pos = last+1
  749. else
  750. ginsert(string.sub(query, pos));
  751. break;
  752. end
  753. end
  754.  
  755. return parsed
  756. end
  757.  
  758. --- Parse URL
  759. -- @param url String
  760. -- @param default String
  761. -- @return Table
  762. function playxlib.ParseURL(url, default)
  763. -- initialize default parameters
  764. local parsed = {}
  765. for i,v in _G.pairs(default or parsed) do parsed[i] = v end
  766. -- remove whitespace
  767. -- url = string.gsub(url, "%s", "")
  768. -- get fragment
  769. url = string.gsub(url, "#(.*)$", function(f)
  770. parsed.fragment = f
  771. return ""
  772. end)
  773. -- get scheme. Lower-case according to RFC 3986 section 3.1.
  774. url = string.gsub(url, "^([%w][%w%+%-%.]*)%:",
  775. function(s) parsed.scheme = string.lower(s); return "" end)
  776. -- get authority
  777. url = string.gsub(url, "^//([^/]*)", function(n)
  778. parsed.authority = n
  779. return ""
  780. end)
  781. -- get query stringing
  782. url = string.gsub(url, "%?(.*)", function(q)
  783. parsed.query = playxlib.ParseURLQuery(q)
  784. return ""
  785. end)
  786. -- get params
  787. url = string.gsub(url, "%;(.*)", function(p)
  788. parsed.params = p
  789. return ""
  790. end)
  791. -- path is whatever was left
  792. parsed.path = url
  793. local authority = parsed.authority
  794. if not authority then return parsed end
  795. authority = string.gsub(authority,"^([^@]*)@",
  796. function(u) parsed.userinfo = u; return "" end)
  797. authority = string.gsub(authority, ":([0-9]*)$",
  798. function(p) if p ~= "" then parsed.port = p end; return "" end)
  799. if authority ~= "" then parsed.host = authority end
  800. local userinfo = parsed.userinfo
  801. if not userinfo then return parsed end
  802. userinfo = string.gsub(userinfo, ":([^:]*)$",
  803. function(p) parsed.password = p; return "" end)
  804. parsed.user = userinfo
  805. return parsed
  806. end
  807. ====================
  808.  
  809. 1452799300 [14/01/2016], [CEO]Radon (sh_wcr_config.lua)
  810. ====================
  811. nil
  812. ====================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement