1 /* SCCS Id: @(#)nhlan.c 3.4 1999/11/21 */
2 /* Copyright (c) Michael Allison, 1997 */
3 /* NetHack may be freely redistributed. See license for details. */
6 * Currently shared by the following ports:
9 * The code in here is used to take advantage of added features
10 * that might be available in a Local Area Network environment.
12 * Network Username of player
16 * To implement this: code, data files, and configuration
17 * files need to be separated from writeable files such
18 * as level files, bones files, and save files.
28 /* Port specific code needs to implement these routines for LAN_MAIL */
29 extern char *FDECL(get_username, (int *));
30 extern boolean NDECL(mail_check);
31 extern boolean FDECL(mail_fetch, (struct lan_mail_struct *));
32 extern void FDECL(mail_init, (char *));
33 extern void NDECL(mail_finish);
35 struct lan_mail_struct mailmessage;
39 void init_lan_features()
45 #ifdef LAN_SHARED_BONES
49 * The get_lan_username() call is a required call, since some of
50 * the other LAN features depend on a unique username being available.
53 char lusername[MAX_LAN_USERNAME];
54 int lusername_size = MAX_LAN_USERNAME;
59 lu = get_username(&lusername_size);
61 Strcpy(lusername, lu);
63 } else return (char *)0;
70 struct lan_mail_struct *msg;
74 for (size = 0; size < qt_msg->size; size += (long)strlen(in_line)) {
75 (void) dlb_fgets(in_line, 80, msg_file);
85 struct lan_mail_struct *msg;
88 winid datawin = create_nhwindow(NHW_TEXT);
97 putstr(datawin, 0, buf);
103 } else if (*get == '\n') {
105 putstr(datawin, 0, buf);
109 } else if (!isprint(*get)) {
117 putstr(datawin, 0, buf);
118 putstr(datawin, 0, "");
119 display_nhwindow(datawin, TRUE);
120 destroy_nhwindow(datawin);
123 /* this returns TRUE if there is mail ready to be read */
124 boolean lan_mail_check()
127 if (mail_check()) return TRUE;
132 void lan_mail_read(otmp)
136 (void) mail_fetch(&mailmessage);
137 /* after a successful fetch iflags.lan_mail_fetched
138 * should be TRUE. If it isn't then we don't
139 * trust the contents of mailmessage. This
140 * ensures that things work correctly across
141 * save/restores where mailmessage isn't
142 * saved (nor should it be since it may be
143 * way out of context by then).
145 if (iflags.lan_mail_fetched) {
146 if (mailmessage.body_in_ram) {
147 mail_by_window(&mailmessage);
152 pline_The("text has faded and is no longer readable.");
157 if (!flags.biff) return;
158 (void) mail_init(lusername);
161 void lan_mail_finish()
164 (void) mail_finish();
167 /* If ever called, the underlying mail system ran into trouble
168 * and wants us to cease bothering it immediately.
169 * Don't call mail_finish() because the underlying mail system
170 * may already be unavailable. Just clean up the NetHack side
171 * of things to prevent a crash.
173 void lan_mail_terminate()
175 /* Step 1. Clear iflags.lan_mail to indicate "not inited" */
176 iflags.lan_mail = FALSE;
178 /* Step 2. Clear iflags.lan_mail_fetched */
179 iflags.lan_mail_fetched = FALSE;
181 /* Once having gotten to this point, the only
182 way to resume NetHack mail features again is
183 to Save/Quit game, or for the user to clear
184 iflags.biff and then set it once again,
185 which triggers mail initialization */
190 #endif /*LAN_FEATURES*/