game.dcgi - brcon2024-hackathons - Bitreichcon 2024 Hackathons HTML git clone git://bitreich.org/brcon2024-hackathons git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/brcon2024-hackathons DIR Log DIR Files DIR Refs DIR Tags DIR Submodules --- game.dcgi (5012B) --- 1 #!/bin/sh 2 if [ -z "${QUERY_STRING}" ]; 3 then 4 printf "[3|Invalid Request|Err|server|port]\n" 5 exit 6 fi 7 8 if [ "${QUERY_STRING}" = "random" ]; 9 then 10 id="$(sort -R if-archive-index | head -n1)" 11 type="tuid" 12 else 13 id="${QUERY_STRING#*:}" 14 type="${QUERY_STRING%%:*}" 15 fi 16 17 { 18 case "${type}" in 19 tuid ) 20 curl -sgG \ 21 --data-urlencode "id=${id}" \ 22 --url "https://ifdb.org/viewgame?ifiction" 23 ;; 24 ifid ) 25 curl -sgG \ 26 --data-urlencode "ifid=${id}" \ 27 --url "https://ifdb.org/viewgame?ifiction" 28 ;; 29 * ) 30 printf "[3|Invalid Request|Err|server|port]\n" 31 exit 1 32 ;; 33 esac 34 } | \ 35 xml2tsv | \ 36 awk -v"query=${type}:${id}" ' 37 # urlencode gets used on things which should already be correct URLs 38 # this function only encodes not encode unsafe characters which could be 39 # used in a XSS-attack 40 # This is not needed if I patch up geomyidae correctly 41 function urlencode(s) { 42 gsub("<", "%3C", s); 43 gsub(">", "%3E", s); 44 gsub("\"", "%22", s); 45 gsub(sprintf("%c", 39), "%27", s); 46 return s; 47 } 48 function gphescape(s, f) { 49 gsub(" ", " ", s); 50 gsub("\n", " ", s); 51 if (f) 52 gsub("\\|", "\\|", s); 53 return s; 54 } 55 function item(type, text, selector, server, port) { 56 printf("[%c|%s|%s|%s|%s]\n", gphescape(type, 1), gphescape(text, 1), gphescape(selector, 1), gphescape(server, 1), gphescape(port, 1)); 57 } 58 BEGIN { 59 FS = "\t"; 60 61 server = "server"; 62 port = "port"; 63 } 64 $1 == "/viewgame/errorCode" { 65 exit 66 } 67 $1 == "/ifindex/story/bibliographic/description/br" { 68 bibliographic["description"] = bibliographic["description"] "\n\n"; 69 } 70 index($1, "/ifindex/story/bibliographic/description") == 1 { 71 bibliographic["description"] = bibliographic["description"] $2; 72 next; 73 } 74 index($1, "/ifindex/story/bibliographic/") == 1 { 75 bibliographic[substr($1, length("/ifindex/story/bibliographic/") + 1)] = $2; 76 next; 77 } 78 index($1, "/ifindex/story/contact/") == 1 { 79 contact[substr($1, length("/ifindex/story/contact/") + 1)] = $2; 80 next; 81 } 82 $1 == "/ifindex/story/ifdb/downloads/links/link" { 83 links["length"]++; 84 next; 85 } 86 index($1, "/ifindex/story/ifdb/downloads/links/link/") == 1 { 87 links[links["length"], substr($1, length("/ifindex/story/ifdb/downloads/links/link/") + 1)] = $2; 88 next; 89 } 90 index($1, "/ifindex/story/ifdb/") == 1 { 91 ifdb[substr($1, length("/ifindex/story/ifdb/") + 1)] = $2; 92 next; 93 } 94 END { 95 item("0", "About \"" bibliographic["title"] "\"", "./game.cgi?" query, server, port); 96 if (contact["url"]) 97 item("h", contact["url"], "URL:" urlencode(contact["url"]), server, port); 98 item("h", "On ifdb.org", "URL:" urlencode(ifdb["link"]), server, port); 99 100 print ""; 101 102 if (links["length"]) { 103 print "Downloads\n"; 104 for (i = 1; i <= links["length"]; i++) { 105 prefix = ""; 106 if ((i, "isGame") in links) 107 prefix = "[GAME] "; 108 suffix = ""; 109 if (links[i, "format"]) 110 suffix = links[i, "format"] 111 if (links[i, "os"]) 112 suffix = suffix ", " links[i, "os"] 113 sub(/^,/, "", suffix); 114 if (suffix) 115 suffix = " (" suffix ")" 116 title = prefix links[i, "title"] suffix; 117 118 item("h", title, "URL:" urlencode(links[i, "url"]), server, port); 119 if (match(links[i, "url"], /^https?:\/\/((www|mirror)\.)?ifarchive\.org\/if-archive\//)) 120 item("9", title " [gopher.661.org]", "/if-archive/" substr(links[i, "url"], RSTART + RLENGTH), "gopher.661.org", "70") 121 122 # TODO handle compression property 123 # MAYBE pull out information from the if-archive URLs regarding format (for example twine) 124 if ((i, "isGame") in links) { 125 if (links[i, "format"] == "blorb/glulx") 126 item("h", "List of Glulx interpreters", "URL:" urlencode("https://www.ifwiki.org/Glulx_interpreters"), server, port); 127 else if (links[i, "format"] == "zcode" || links[i, "format"] == "blorb/zcode") 128 item("h", "List of Z-Code interpreters", "URL:" urlencode("https://www.ifwiki.org/Z-code_interpreters"), server, port); 129 else if (links[i, "format"] == "hugo") 130 item("h", "List of Hugo interpreters", "URL:" urlencode("https://www.ifwiki.org/Hugo_interpreters"), server, port); 131 else if (links[i, "format"] == "adrift" || links[i, "format"] == "adrift39") 132 item("h", "List of ADRIFT interpreters", "URL:" urlencode("https://www.ifwiki.org/ADRIFT_interpreters"), server, port); 133 else if (links[i, "format"] == "agt") 134 item("h", "List of AGT interpreters", "URL:" urlencode("https://www.ifwiki.org/AGT_interpreters"), server, port); 135 else if (links[i, "format"] == "tads2") 136 item("h", "List of TADS interpreters", "URL:" urlencode("https://www.ifwiki.org/TADS_interpreters"), server, port); 137 else if (links[i, "format"] == "alan2") 138 item("h", "List of Alan interpreters", "URL:" urlencode("https://www.ifwiki.org/Alan_interpreters"), server, port); 139 else if (links[i, "format"] == "hypertextgame") 140 printf("Should work in a modern browser. Most of the time JavaScript is required.\n"); 141 else if (links[i, "format"] == "storyfile") 142 printf("Unknown game type.\n"); 143 } 144 145 if (links[i, "desc"]) { 146 cmd = "fmt -w70"; 147 print gphescape(links[i, "desc"]) | cmd; 148 close(cmd); 149 } 150 print ""; 151 } 152 } 153 }'