They are simpler to use that way.
struct telstr {
natid tel_from; /* sender */
- signed char tel_type;
- long tel_length; /* how long */
+ unsigned char tel_type;
+ unsigned tel_length; /* how long */
time_t tel_date; /* when sent */
};
lasttype = -1;
while (fread(&tgm, sizeof(tgm), 1, telfp) == 1) {
readit = 1;
- if (tgm.tel_length < 0) {
- logerror("bad telegram file header in %s", mbox);
- break;
- }
- if (tgm.tel_type < 0 || tgm.tel_type > TEL_LAST) {
+ if (tgm.tel_type > TEL_LAST) {
pr("Bad telegram header. Skipping telegram...\n");
readit = 0;
goto skip;
pr("\n> ");
lastcnum = tgm.tel_from;
lasttype = tgm.tel_type;
- pr("%s ", telnames[(int)tgm.tel_type]);
+ pr("%s ", telnames[tgm.tel_type]);
if ((tgm.tel_type == TEL_NORM) ||
(tgm.tel_type == TEL_ANNOUNCE) ||
(tgm.tel_type == TEL_BULLETIN))
char buf[1024];
char msgbuf[MAXTELSIZE + 1]; /* UTF-8 */
char *msgfilepath;
+ int len;
p = getstarg(player->argp[1], "on, off or motd? ", buf);
if (!p)
else
pr("Enter a new message of the day.\n");
- time(&tgm.tel_date);
- tgm.tel_length = getele("The World", msgbuf);
- if (tgm.tel_length < 0) {
+ len = getele("The World", msgbuf);
+ if (len < 0) {
pr("Ignored\n");
if (msgfilepath == downfil)
pr("NOT disabling logins.\n");
return RET_FAIL;
- } else if (tgm.tel_length == 0) {
+ }
+ if (len == 0) {
if (msgfilepath == motdfil) {
pr("Removing exsting motd.\n");
if ((unlink(msgfilepath) == -1) && (errno != ENOENT)) {
pr("Logins disabled.\n");
memset(&tgm, 0, sizeof(tgm));
+ time(&tgm.tel_date);
+ tgm.tel_length = len;
if ((fwrite(&tgm, sizeof(tgm), 1, fptr) != 1) ||
(fwrite(msgbuf, tgm.tel_length, 1, fptr) != 1)) {
fclose(fptr);
fclose(fp);
return -1;
}
- if (tgm.tel_length >= (long)sizeof(buf)) {
- logerror("text length (%ld) is too long for login message (%s)",
- tgm.tel_length, fname);
+ if (tgm.tel_length >= sizeof(buf)) {
+ logerror("text length (%u) is too long for login message (motdfil)",
+ tgm.tel_length);
fclose(fp);
return -1;
}
if (fread(buf, tgm.tel_length, 1, fp) != 1) {
- logerror("bad length %ld on login message", tgm.tel_length);
+ logerror("bad length %u on login message", tgm.tel_length);
fclose(fp);
return -1;
}
int
typed_wu(natid from, natid to, char *message, int type)
{
- int len;
+ size_t len;
struct telstr tel;
struct natstr *np;
struct iovec iov[2];
while (fread(&tgm, sizeof(tgm), 1, annfp) == 1) {
writeit = 1;
- if (tgm.tel_length < 0 || tgm.tel_length > MAXTELSIZE) {
- logerror("bad telegram file header (length=%ld)",
+ if (tgm.tel_length > MAXTELSIZE) {
+ logerror("bad telegram file header (length=%d)",
tgm.tel_length);
return 0;
}
- if (tgm.tel_type < 0 || tgm.tel_type > TEL_LAST) {
- logerror("bad telegram file header (type=%d)",
- tgm.tel_type);
+ if (tgm.tel_type > TEL_LAST) {
+ logerror("bad telegram file header (type=%d)", tgm.tel_type);
return 0;
}
++saved;
} else
++deleted;
- if (fread(message, 1, tgm.tel_length, annfp) !=
- (size_t)tgm.tel_length) {
+ if (fread(message, 1, tgm.tel_length, annfp) != tgm.tel_length) {
logerror("error reading body from telegram file %s",
annfil);
return 0;
}
if (writeit) {
- if (fwrite(message, 1, tgm.tel_length, tmpfp) !=
- (size_t)tgm.tel_length) {
+ if (fwrite(message, 1, tgm.tel_length, tmpfp)
+ != tgm.tel_length) {
logerror("error writing body to temporary telegram "
"file %s", tmp_filename);
return 0;