-
Notifications
You must be signed in to change notification settings - Fork 0
/
nethack-nhlaunch.el
87 lines (69 loc) · 3.06 KB
/
nethack-nhlaunch.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
;;; nethack-nhlaunch.el --- Negotiate with nhlaunch to start a game of nethack
;; Copyright (C) 2005 Shawn Betts
;; Author: Shawn Betts <[email protected]>
;; Keywords:
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;;
;;; Code:
(require 'nethack)
(defvar nethack-network-server "sputnik.emmett.ca"
"The user to login as")
(defvar nethack-network-port 23
"The user to login as")
(defvar nethack-network-user (user-login-name)
"The user to login as")
(defvar nethack-network-password nil
"The password to use")
(defvar nethack-network-game "nethack"
"The game to play")
(defvar nh-network-password nil)
(defvar nh-network-game nil)
(defun nh-network-filter (proc str)
(cond ((or (string-equal str "Welcome to the nethack-el server.\n")
(string-equal str (format "User %s added successfully.\n" nethack-network-user)))
(process-send-string proc (format "login %s %s\n" nethack-network-user nh-network-password)))
((string-equal str (format "Welcome back %s.\n" nethack-network-user))
(message "Starting nethack...")
(process-send-string proc (format "play %s\n" nh-network-game))
(nethack-start proc))
((or (string-equal str (format "Failed to login %s.\n" nethack-network-user))
(string-equal str "Error parsing name and password.\n"))
(delete-process proc)
(message str))
((string-equal str (format "Unknown user %s.\n" nethack-network-user))
(process-send-string proc (format "new %s %s\n" nethack-network-user nh-network-password)))))
;;;###autoload
(defun nethack-connect-to-server (&optional prefix)
"Connect to the nethack server specified by `nethack-network-server'
`nethack-network-port' `nethack-network-user' `nethack-network-passwd'
and `nethack-network-game'. When called with a universal arg, it
prompts for the game."
(interactive "P")
(if (nethack-is-running)
(message "Nethack process already running...")
(if (get-buffer nh-proc-buffer-name)
(kill-buffer nh-proc-buffer-name))
(setq nh-network-password (or nethack-network-password
(read-from-minibuffer "Password: ")))
(setq nh-network-game (if prefix
(read-from-minibuffer "Game: ")
nethack-network-game))
(message nh-network-game)
(let ((proc (open-network-stream "nh" nh-proc-buffer-name
nethack-network-server
nethack-network-port)))
(set-process-filter proc 'nh-network-filter))))
(provide 'nethack-nhlaunch)
;;; nethack-nhlaunch.el ends here