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. */ 4 5/* 6 * Currently shared by the following ports: 7 * WIN32 8 * 9 * The code in here is used to take advantage of added features 10 * that might be available in a Local Area Network environment. 11 * 12 * Network Username of player 13 * Mail 14 * Futures 15 * Shared bones 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. 19 * 20 */ 21 22#include "hack.h" 23#include <ctype.h> 24 25#ifdef LAN_FEATURES 26 27#ifdef LAN_MAIL 28/* Port specific code needs to implement these routines for LAN_MAIL */ 29extern char *FDECL(get_username, (int *)); 30extern boolean NDECL(mail_check); 31extern boolean FDECL(mail_fetch, (struct lan_mail_struct *)); 32extern void FDECL(mail_init, (char *)); 33extern void NDECL(mail_finish); 34 35struct lan_mail_struct mailmessage; 36#endif /* LAN_MAIL */ 37 38 39void init_lan_features() 40{ 41 lan_username(); 42#ifdef LAN_MAIL 43 lan_mail_init(); 44#endif 45#ifdef LAN_SHARED_BONES 46#endif 47} 48/* 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. 51 * 52 */ 53char lusername[MAX_LAN_USERNAME]; 54int lusername_size = MAX_LAN_USERNAME; 55 56char *lan_username() 57{ 58 char *lu; 59 lu = get_username(&lusername_size); 60 if (lu) { 61 Strcpy(lusername, lu); 62 return lusername; 63 } else return (char *)0; 64} 65 66# ifdef LAN_MAIL 67#if 0 68static void 69mail_by_pline(msg) 70struct lan_mail_struct *msg; 71{ 72 long size; 73 74 for (size = 0; size < qt_msg->size; size += (long)strlen(in_line)) { 75 (void) dlb_fgets(in_line, 80, msg_file); 76 convert_line(); 77 pline(out_line); 78 } 79 80} 81#endif /* 0 */ 82 83static void 84mail_by_window(msg) 85struct lan_mail_struct *msg; 86{ 87 char buf[BUFSZ]; 88 winid datawin = create_nhwindow(NHW_TEXT); 89 char *get, *put; 90 int ccount = 0; 91 92 get = msg->body; 93 put = buf; 94 while (*get) { 95 if (ccount > 79) { 96 *put = '\0'; 97 putstr(datawin, 0, buf); 98 put = buf; 99 ccount = 0; 100 } 101 if (*get == '\r') { 102 get++; 103 } else if (*get == '\n') { 104 *put = '\0'; 105 putstr(datawin, 0, buf); 106 put = buf; 107 get++; 108 ccount = 0; 109 } else if (!isprint(*get)) { 110 get++; 111 } else { 112 *put++ = *get++; 113 ccount++; 114 } 115 } 116 *put = '\0'; 117 putstr(datawin, 0, buf); 118 putstr(datawin, 0, ""); 119 display_nhwindow(datawin, TRUE); 120 destroy_nhwindow(datawin); 121} 122 123/* this returns TRUE if there is mail ready to be read */ 124boolean lan_mail_check() 125{ 126 if (flags.biff) { 127 if (mail_check()) return TRUE; 128 } 129 return FALSE; 130} 131 132void lan_mail_read(otmp) 133struct obj *otmp; 134{ 135 if (flags.biff) { 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). 144 */ 145 if (iflags.lan_mail_fetched) { 146 if (mailmessage.body_in_ram) { 147 mail_by_window(&mailmessage); 148 return; 149 } 150 } 151 } 152 pline_The("text has faded and is no longer readable."); 153} 154 155void lan_mail_init() 156{ 157 if (!flags.biff) return; 158 (void) mail_init(lusername); 159} 160 161void lan_mail_finish() 162{ 163 if (iflags.lan_mail) 164 (void) mail_finish(); 165} 166 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. 172 */ 173void lan_mail_terminate() 174{ 175 /* Step 1. Clear iflags.lan_mail to indicate "not inited" */ 176 iflags.lan_mail = FALSE; 177 178 /* Step 2. Clear iflags.lan_mail_fetched */ 179 iflags.lan_mail_fetched = FALSE; 180 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 */ 186} 187 188# endif /*LAN_MAIL*/ 189 190#endif /*LAN_FEATURES*/ 191/*nhlan.c*/ 192