(defmethod handle-data ((m play-mode) message)
(let* ((c (connection m))
(log (logging-stream c)))
- (format log "handle-data ~a~%" message)))
+ (format log "handle-data ~a~%" message)
+ (empire-web:data message)))
(defmethod handle-prompt ((m play-mode) message)
(let* ((c (connection m))
(:use :cl)
(:export :read-message-loop
:read-message
- :make-connection))
+ :make-connection
+ :connect
+ :send-message))
(defpackage :locked-queue
(:use :cl :sb-thread)
(:export :create :enqueue :dequeue))
(defpackage :empire-web
(:use :cl :hunchentoot)
- (:export :start :send :prompt)))
+ (:export :start :send :prompt :data)))
});
}
+function submit_cmdline(cmdline_form) {
+ dojo.xhrGet( {
+ // The following URL must match that used to test the server.
+ url: "/eow/command",
+ handleAs: "text",
+
+ timeout: 30000, // Time in milliseconds
+
+ // The LOAD function will be called on a successful response.
+ load: function(response, ioArgs) {
+ console.log(response);
+ return response;
+ },
+
+ // The ERROR function will be called in an error case.
+ error: function(response, ioArgs) {
+ if (response.dojoType == "timeout") {
+ ioArgs.xhr.abort();
+ return response;
+ }
+
+ console.error("HTTP status code: ", ioArgs.xhr.status);
+ return response;
+ },
+
+ form: cmdline_form
+ });
+}
+
function prompt(minutes, btus) {
eowOut("[" + minutes + "," + btus + "]: ");
get_next_update();
}
+
+function msg(m) {
+ eowOut(m);
+ get_next_update();
+}
+
+function setup_client() {
+ var input = dojo.byId("inputfield");
+ input.focus();
+}
+
+function inputfield_keyup(e) {
+ console.log(e);
+ if (e.keyCode == 13) { // Enter
+ submit_cmdline(e.target.form.id);
+ e.target.value = "";
+ }
+}
--- /dev/null
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html> <head>
+<title>Login</title>
+</head>
+
+<body>
+<h1>Login</h1>
+
+<form action="/eow/login" method="POST">
+<table>
+<tr><td>Username<td><input name="username" type="text">
+<tr><td>Password<td><input name="password" type="password">
+</table>
+<input type="submit" value=" Login ">
+</form>
+
+<hr>
+<address></address>
+<!-- hhmts start --> Last modified: Sun Dec 14 22:16:18 CET 2008 <!-- hhmts end -->
+</body> </html>
<script type="text/javascript">
var init = function(){
console.log("I run after the page is ready. See this in the console");
+ setup_client();
get_next_update();
};
dojo.addOnLoad(init);
<span class="info">Welcome to the Empire over the Web client (EOW).</span>
</div>
<div id="input">
-<form name='f' onsubmit='return false;' class='cmdline' action=''>
-<table class="inputtable"><tr><td><div id='prompt' class='less'>> </div></td><td class="inputtd"><input id='inputfield' name='q' type='text' class='cmdline' autocomplete='off' value="" /></td></tr></table>
+<form id="cmdline" name='f' onsubmit='return false;' class='cmdline' action=''>
+<table class="inputtable"><tr><td><div id='prompt' class='less'>>
+</div></td><td class="inputtd"><input id='inputfield' name='q'
+ type='text' class='cmdline' autocomplete='off' value=""
+ onkeyup="inputfield_keyup(event);" /></td></tr></table>
</form>
</div>
<hr>
<address></address>
-<!-- hhmts start --> Last modified: Sat Nov 29 23:06:08 CET 2008 <!-- hhmts end -->
+<!-- hhmts start --> Last modified: Sun Dec 14 23:04:50 CET 2008 <!-- hhmts end -->
</body> </html>
(defparameter +web-root+ (concatenate 'string +web-root-base+ "/"))
(defparameter +static-web-root+ (concatenate 'string +web-root+ "static/"))
(defparameter +static-files-root+ (concatenate 'string +templates-root+ "static/"))
+(defparameter +login-page+ (concatenate 'string +static-web-root+ "login.html"))
(defun string-starts-with (string prefix)
;; (from Hunchentoot)
(defun prompt (minutes btus)
(send (format nil "prompt(~a,~a);~%" minutes btus)))
+(defun data (message)
+ (send (parenscript:ps* `(msg ,message))))
+
+(defun login ()
+ (let ((connection (session-value 'connection)))
+ (if connection
+ (redirect +root-url+)
+ (redirect +login-page+))))
+
+;; destination of login-form
+(defun login-action ()
+ (let ((connection (empire:connect :user (post-parameter "username")
+ :password (post-parameter "password"))))
+ (setf (session-value 'connection) connection)
+ (redirect +root-url+)))
+
+(defun command-action ()
+ (let ((connection (session-value 'connection)))
+ (empire:send-message connection (get-parameter "q"))))
+
(defun dispatch (request)
(let ((script-name (script-name request)))
(cond
((not (string-starts-with script-name +web-root+)) nil) ; do not handle this request
((string= script-name "/eow/update") 'update)
+ ((string= script-name "/eow/login") 'login-action)
+ ((string= script-name "/eow/command") 'command-action)
((or (string-equal script-name +web-root-base+)
- (string-equal script-name +web-root+)) (redirect +root-url+)) ; go to the start page
+ (string-equal script-name +web-root+)) 'login) ; go to the start page
((string-starts-with script-name +static-web-root+) 'serve-static)))) ; serve static file