00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <config.h>
00035
00036 #include <errno.h>
00037 #include <unistd.h>
00038 #include "tel.h"
00039 #include "commands.h"
00040 #include "optlist.h"
00041
00042
00043
00044
00045 int
00046 turn(void)
00047 {
00048 FILE *fptr;
00049 struct telstr tgm;
00050 char *p;
00051 char buf[1024];
00052 char msgbuf[MAXTELSIZE + 1];
00053 char *msgfilepath;
00054
00055 p = getstarg(player->argp[1], "on, off or motd? ", buf);
00056 if (!p)
00057 return RET_SYN;
00058 if (strcmp(p, "off") == 0) {
00059 msgfilepath = downfil;
00060 } else if (strcmp(p, "on") == 0) {
00061 pr("Removing no-login message and re-enabling logins.\n");
00062 if ((unlink(downfil) == -1) && (errno != ENOENT)) {
00063 pr("Could not remove no-login file, logins still disabled.\n");
00064 logerror("Could not remove no-login file (%s).\n", downfil);
00065 return RET_SYS;
00066 }
00067 return RET_OK;
00068 } else {
00069 msgfilepath = motdfil;
00070 }
00071
00072 if (msgfilepath == downfil)
00073 pr("Enter a message shown to countries trying to log in.\n");
00074 else
00075 pr("Enter a new message of the day.\n");
00076
00077 time(&tgm.tel_date);
00078 tgm.tel_length = getele("The World", msgbuf);
00079
00080 if (tgm.tel_length < 0) {
00081 pr("Ignored\n");
00082 if (msgfilepath == downfil)
00083 pr("NOT disabling logins.\n");
00084 return RET_SYN;
00085 } else if (tgm.tel_length == 0) {
00086 if (msgfilepath == motdfil) {
00087 pr("Removing exsting motd.\n");
00088 if ((unlink(msgfilepath) == -1) && (errno != ENOENT)) {
00089 pr("Could not remove motd.\n");
00090 logerror("Could not remove motd file (%s).\n",
00091 msgfilepath);
00092 return RET_SYS;
00093 }
00094 return RET_OK;
00095 } else
00096 pr("Writing empty no-login message.\n");
00097 }
00098
00099 fptr = fopen(msgfilepath, "wb");
00100 if (fptr == NULL) {
00101 pr("Something went wrong opening the message file.\n");
00102 logerror("Could not open message file (%s).\n", msgfilepath);
00103 return RET_SYS;
00104 }
00105
00106 if (msgfilepath == downfil)
00107 pr("Logins disabled.\n");
00108
00109 if ((fwrite(&tgm, sizeof(tgm), 1, fptr) != 1) ||
00110 (fwrite(msgbuf, tgm.tel_length, 1, fptr) != 1)) {
00111 fclose(fptr);
00112 pr("Something went wrong writing the message file.\n");
00113 logerror("Could not properly write message file (%s).\n",
00114 msgfilepath);
00115 return RET_SYS;
00116 }
00117 if (fclose(fptr)) {
00118 pr("Something went wrong closing the message.\n");
00119 logerror("Could not properly close message file (%s).\n",
00120 msgfilepath);
00121 return RET_SYS;
00122 }
00123
00124 pr("\n");
00125
00126 return RET_OK;
00127 }