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
00035
00036
00037 #include <config.h>
00038
00039 #include "commands.h"
00040
00041 static int chat(struct natstr *, struct natstr *, char *);
00042 static int sendmessage(struct natstr *, struct natstr *, char *, int);
00043
00044 int
00045 flash(void)
00046 {
00047 struct natstr *us;
00048 struct natstr *to;
00049 int tocn;
00050
00051 us = getnatp(player->cnum);
00052 if ((tocn = natarg(player->argp[1], "to which country? ")) < 0)
00053 return RET_SYN;
00054 to = getnatp(tocn);
00055
00056 if (us->nat_stat == STAT_GOD) {
00057
00058 } else if (us->nat_stat == STAT_VIS) {
00059
00060 if (to->nat_stat != STAT_GOD) {
00061 pr("Visitors can only flash the gods.\n");
00062 return RET_SYN;
00063 }
00064 } else {
00065
00066 if (to->nat_stat != STAT_GOD && getrel(to, player->cnum) < FRIENDLY) {
00067 pr("%s is not a deity or friendly with us.\n", to->nat_cnam);
00068 return RET_SYN;
00069 }
00070 }
00071
00072 return chat(us, to, player->comtail[2]);
00073 }
00074
00075 int
00076 wall(void)
00077 {
00078 return chat(getnatp(player->cnum), NULL, player->comtail[1]);
00079 }
00080
00081
00082
00083
00084
00085
00086
00087 static int
00088 chat(struct natstr *us, struct natstr *to, char *message)
00089 {
00090 char buf[1024];
00091
00092 if (message) {
00093 buf[0] = ':';
00094 buf[1] = ' ';
00095 strcpy(buf+2, message);
00096 sendmessage(us, to, buf, 1);
00097 } else {
00098 sendmessage(us, to, "...", 1);
00099 while (ugetstring("> ", buf)) {
00100 if (*buf == '.')
00101 break;
00102 sendmessage(us, to, buf, 0);
00103 }
00104 sendmessage(us, to, "<EOT>", 0);
00105 }
00106 return RET_OK;
00107 }
00108
00109
00110
00111
00112
00113
00114
00115
00116 static int
00117 sendmessage(struct natstr *us, struct natstr *to, char *message, int verbose)
00118 {
00119 struct player *other;
00120 struct tm *tm;
00121 time_t now;
00122 int sent = 0;
00123 struct natstr *wto;
00124
00125 time(&now);
00126 tm = localtime(&now);
00127 for (other = player_next(0); other != 0; other = player_next(other)) {
00128 if (other->state != PS_PLAYING)
00129 continue;
00130 if (to && other->cnum != to->nat_cnum)
00131 continue;
00132 if (!(wto = getnatp(other->cnum)))
00133 continue;
00134 if (!to && !player->god && getrel(wto, player->cnum) != ALLIED)
00135 continue;
00136 if (!player->god && !(wto->nat_flags & NF_FLASH))
00137 continue;
00138 if (player == other)
00139 continue;
00140 if (verbose)
00141 if (to)
00142 pr_flash(other, "FLASH from %s (#%d) @ %02d:%02d%s\n",
00143 us->nat_cnam, us->nat_cnum, tm->tm_hour,
00144 tm->tm_min, message);
00145 else
00146 pr_flash(other, "BROADCAST from %s (#%d) @ %02d:%02d%s\n",
00147 us->nat_cnam, us->nat_cnum, tm->tm_hour,
00148 tm->tm_min, message);
00149
00150 else
00151 pr_flash(other, "%s (#%d): %s\n",
00152 us->nat_cnam, us->nat_cnum, message);
00153 sent++;
00154 }
00155 if (player->god) {
00156 if (to)
00157 if (sent)
00158 pr("Flash sent to %s\n", to->nat_cnam);
00159 else
00160 pr("%s is not logged on\n", to->nat_cnam);
00161 else if (sent)
00162 pr("Broadcast sent to %d players\n", sent);
00163 else
00164 pr("No-one is logged in\n");
00165 }
00166 if (to && !player->god) {
00167
00168
00169 if ((getrel(to, player->cnum) == ALLIED) && !sent) {
00170 if (to->nat_flags & NF_FLASH)
00171 pr("%s is not logged on\n", to->nat_cnam);
00172 else
00173 pr("%s is not accepting flashes\n", to->nat_cnam);
00174 }
00175 }
00176 return 0;
00177 }