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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
/* SCCS Id: @(#)nhlan.c 3.4 1999/11/21 */
/* Copyright (c) Michael Allison, 1997 */
/* NetHack may be freely redistributed. See license for details. */
/*
* Currently shared by the following ports:
* WIN32
*
* The code in here is used to take advantage of added features
* that might be available in a Local Area Network environment.
*
* Network Username of player
* Mail
* Futures
* Shared bones
* To implement this: code, data files, and configuration
* files need to be separated from writeable files such
* as level files, bones files, and save files.
*
*/
#include "hack.h"
#include <ctype.h>
#ifdef LAN_FEATURES
#ifdef LAN_MAIL
/* Port specific code needs to implement these routines for LAN_MAIL */
extern char *FDECL(get_username, (int *));
extern boolean NDECL(mail_check);
extern boolean FDECL(mail_fetch, (struct lan_mail_struct *));
extern void FDECL(mail_init, (char *));
extern void NDECL(mail_finish);
struct lan_mail_struct mailmessage;
#endif /* LAN_MAIL */
void init_lan_features()
{
lan_username();
#ifdef LAN_MAIL
lan_mail_init();
#endif
#ifdef LAN_SHARED_BONES
#endif
}
/*
* The get_lan_username() call is a required call, since some of
* the other LAN features depend on a unique username being available.
*
*/
char lusername[MAX_LAN_USERNAME];
int lusername_size = MAX_LAN_USERNAME;
char *lan_username()
{
char *lu;
lu = get_username(&lusername_size);
if (lu) {
Strcpy(lusername, lu);
return lusername;
} else return (char *)0;
}
# ifdef LAN_MAIL
#if 0
static void
mail_by_pline(msg)
struct lan_mail_struct *msg;
{
long size;
for (size = 0; size < qt_msg->size; size += (long)strlen(in_line)) {
(void) dlb_fgets(in_line, 80, msg_file);
convert_line();
pline(out_line);
}
}
#endif /* 0 */
static void
mail_by_window(msg)
struct lan_mail_struct *msg;
{
char buf[BUFSZ];
winid datawin = create_nhwindow(NHW_TEXT);
char *get, *put;
int ccount = 0;
get = msg->body;
put = buf;
while (*get) {
if (ccount > 79) {
*put = '\0';
putstr(datawin, 0, buf);
put = buf;
ccount = 0;
}
if (*get == '\r') {
get++;
} else if (*get == '\n') {
*put = '\0';
putstr(datawin, 0, buf);
put = buf;
get++;
ccount = 0;
} else if (!isprint(*get)) {
get++;
} else {
*put++ = *get++;
ccount++;
}
}
*put = '\0';
putstr(datawin, 0, buf);
putstr(datawin, 0, "");
display_nhwindow(datawin, TRUE);
destroy_nhwindow(datawin);
}
/* this returns TRUE if there is mail ready to be read */
boolean lan_mail_check()
{
if (flags.biff) {
if (mail_check()) return TRUE;
}
return FALSE;
}
void lan_mail_read(otmp)
struct obj *otmp;
{
if (flags.biff) {
(void) mail_fetch(&mailmessage);
/* after a successful fetch iflags.lan_mail_fetched
* should be TRUE. If it isn't then we don't
* trust the contents of mailmessage. This
* ensures that things work correctly across
* save/restores where mailmessage isn't
* saved (nor should it be since it may be
* way out of context by then).
*/
if (iflags.lan_mail_fetched) {
if (mailmessage.body_in_ram) {
mail_by_window(&mailmessage);
return;
}
}
}
pline_The("text has faded and is no longer readable.");
}
void lan_mail_init()
{
if (!flags.biff) return;
(void) mail_init(lusername);
}
void lan_mail_finish()
{
if (iflags.lan_mail)
(void) mail_finish();
}
/* If ever called, the underlying mail system ran into trouble
* and wants us to cease bothering it immediately.
* Don't call mail_finish() because the underlying mail system
* may already be unavailable. Just clean up the NetHack side
* of things to prevent a crash.
*/
void lan_mail_terminate()
{
/* Step 1. Clear iflags.lan_mail to indicate "not inited" */
iflags.lan_mail = FALSE;
/* Step 2. Clear iflags.lan_mail_fetched */
iflags.lan_mail_fetched = FALSE;
/* Once having gotten to this point, the only
way to resume NetHack mail features again is
to Save/Quit game, or for the user to clear
iflags.biff and then set it once again,
which triggers mail initialization */
}
# endif /*LAN_MAIL*/
#endif /*LAN_FEATURES*/
/*nhlan.c*/
|