games.dcgi - brcon2024-hackathons - Bitreichcon 2024 Hackathons
(HTM) git clone git://bitreich.org/brcon2024-hackathons git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/brcon2024-hackathons
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Tags
(DIR) Submodules
---
games.dcgi (2560B)
---
1 #!/bin/sh
2 if [ -n "${X_GOPHER_SEARCH}" ];
3 then
4 PAGE=1
5 QUERY="${X_GOPHER_SEARCH}"
6 elif [ -n "${QUERY_STRING}" ];
7 then
8 PAGE="${QUERY_STRING##*:}"
9 if ! printf "%s\n" "${PAGE}" | grep -q '^[0-9][0-9]*$';
10 then
11 PAGE=1
12 elif [ "${PAGE}" -lt 1 ];
13 then
14 PAGE=1
15 fi
16 QUERY="${QUERY_STRING%:*}"
17 else
18 PAGE=1
19 QUERY=""
20 fi
21
22 export PAGE
23 export QUERY
24
25 {
26 if [ -z "${QUERY}" ];
27 then
28 curl -sgG \
29 --data-urlencode "pg=${PAGE}" \
30 --url "https://ifdb.org/search?xml&game&browse"
31 else
32 curl -sgG \
33 --data-urlencode "searchfor=${QUERY}" \
34 --data-urlencode "pg=${PAGE}" \
35 --url "https://ifdb.org/search?xml&game"
36 fi
37 } | \
38 xml2tsv | \
39 awk '
40 function escape(s, f) {
41 gsub(" ", " ", s);
42 gsub("\n", " ", s);
43 if (f)
44 gsub("\\|", "\\|", s);
45 return s;
46 }
47 function item(type, text, selector, server, port) {
48 printf("[%c|%s|%s|%s|%s]\n", escape(type, 1), escape(text, 1), escape(selector, 1), escape(server, 1), escape(port, 1));
49 }
50 BEGIN {
51 FS = "\t";
52
53 server = "server";
54 port = "port";
55 page = ENVIRON["PAGE"];
56 query = ENVIRON["QUERY"];
57 pathinfo = ENVIRON["PATH_INFO"];
58
59 item("1", "..", "..", server, port);
60 printf("%s\n", "Inofficial IFDB Gopher frontend");
61 item("h", "IFDB on the WWW", "URL:https://ifdb.org/", server, port);
62 item("1", "IF-Archive mirror on gopher.661.org", "/if-archive/", "gopher.661.org", "70");
63 printf("----------------------------------------------------------------------\n")
64 item("7", "Search", pathinfo, server, port);
65 if (query)
66 printf("Current Search: %s\n", escape(query));
67
68 printf("----------------------------------------------------------------------\n")
69 }
70 function fold(s, w,
71 i, l) {
72 s = escape(s);
73 l = length(s);
74
75 for (i = 1; i <= l; i += w)
76 printf("%s\n", substr(s, i, w));
77 }
78 function flush(,
79 i, url) {
80 item("1", data["title"] (data["numRatings"] ? sprintf(" (%s stars)", data["starRating"]) : ""), "./game.dcgi?tuid:" data["tuid"], server, port);
81 }
82 $1 == "searchReply/error" {
83 exit
84 }
85 $1 == "/searchReply/games/game" {
86 if (data["tuid"]) {
87 flush();
88 delete data;
89 }
90 }
91 index($1, "/searchReply/games/game/") == 1 {
92 data[substr($1, length("/searchReply/games/game/") + 1)] = $2;
93 next;
94 }
95 END {
96 if (data["tuid"])
97 flush();
98 else if (page > 1)
99 printf("No more entries!\n");
100 else
101 printf("No entries!\n");
102
103 printf("----------------------------------------------------------------------\n")
104
105 if (page > 1)
106 item("1", "Previous Page", pathinfo "?" query ":" (int(page) - 1), server, port);
107 if (data["tuid"])
108 item("1", "Next Page", pathinfo "?" query ":" (int(page) + 1), server, port);
109 }'