Debian Codegraph @

terps/tads/tads3/test/data/net4.t

raw
1 #include <tads.h>
2 #include <tadsnet.h>
3 #include <httpsrv.h>
4 #include <httpreq.h>
5 #include <strbuf.h>
6 #include <file.h>
7
8 /* set up a handler for our custom resources, in the net4res/ directory */
9 WebResourceResFile
10 path = static new RexPattern('^/net4res/')
11 ;
12
13 /* the main command window */
14 cmdwin: WebCommandWin
15 ;
16
17 /* the main status window */
18 statwin: WebStatusWin
19 ;
20
21 /*
22 * Main entrypoint
23 */
24 main(args)
25 {
26 randomize();
27
28 local host;
29 if (args.length() >= 2 && args.sublist(2).indexOf('-local') != nil)
30 host = 'localhost';
31 else
32 host = getLocalIP();
33
34 /* set up the server */
35 local srv = new HTTPServer(host, nil, 65535);
36 "HTTP server listening on <<host>>:<<srv.getPortNum()>><br>";
37
38 /* connect to the user interface */
39 webMainWin.connect(srv);
40
41 /* set up the command window and status line */
42 webMainWin.createFrame(cmdwin, 'cmd', '0, stat.bottom, 100%, 100%');
43 webMainWin.createFrame(statwin, 'stat', '0, 0, 100%, content.height');
44
45 /* set the default output function to write to the command window */
46 t3SetSay({txt: cmdwin.write(toString(txt))});
47
48 statwin.setStatus('Welcome');
49 statwin.resize();
50
51 local turnCount = 0;
52 "http://<<host>>:<<srv.getPortNum()>>/?TADS_session=<<webSession.key>><p>";
53 "Hello! This is our first test! We shall see how it goes!";
54 for (;;)
55 {
56 "<p>Please enter your name:<br><nobr>&gt;";
57 statwin.setStatus('Name Entry', turnCount++);
58 local txt = cmdwin.getInputLine();
59 "</nobr>";
60
61 "<p>Well, it looks like you entered <b><<txt.htmlify()>></b>!
62 If this is correct, please press 1. If not, press 2.
63 <br><nobr>&gt;";
64
65 statwin.setStatus('Confirmation', turnCount++);
66 local n = cmdwin.getInputLine();
67 "</nobr>";
68 if (n == '1')
69 {
70 "<p>Great! We\'ll call that a day, then!<br>";
71 break;
72 }
73 else if (n != '2')
74 {
75 "<p>You didn\'t press 1 or 2, but we\'ll assume you
76 need to re-enter your name.";
77 }
78 }
79
80 /* done - shut down the server */
81 "<p>Shutting down the server...<br>";
82 eventPage.sendEvent('<shutdown/>');
83 ClientSession.shutdownWait();
84
85 //t3SetSay(&tadsSay);
86 local x = nil;
87 x.sendEvent();
88 "Shutting down the HTTP server...<br>";
89 srv.shutdown(true);
90 }
91