annotate src/warning.c @ 16:e246e5730173

Removed useless binaries from repository...
author darius
date Wed, 24 Dec 1997 12:36:02 +0000
parents 0836fb919dfa
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1 /*--------------------------------------------------------------------------
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
2 NETREK II -- Paradise
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
3
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
4 Permission to use, copy, modify, and distribute this software and its
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
5 documentation, or any derivative works thereof, for any NON-COMMERCIAL
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
6 purpose and without fee is hereby granted, provided that this copyright
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
7 notice appear in all copies. No representations are made about the
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
8 suitability of this software for any purpose. This software is provided
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
9 "as is" without express or implied warranty.
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
10
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
11 Xtrek Copyright 1986 Chris Guthrie
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
12 Netrek (Xtrek II) Copyright 1989 Kevin P. Smith
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
13 Scott Silvey
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
14 Paradise II (Netrek II) Copyright 1993 Larry Denys
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
15 Kurt Olsen
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
16 Brandon Gillespie
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
17 --------------------------------------------------------------------------*/
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
18
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
19 #include "config.h"
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
20
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
21 #include <stdio.h>
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
22 #include <string.h>
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
23 #include <math.h>
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
24 #include <signal.h>
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
25 #include <sys/time.h>
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
26 #include "defs.h"
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
27 #include "struct.h"
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
28 #include "data.h"
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
29 #include "packets.h"
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
30
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
31 void updateWarnings();
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
32
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
33 #define WQLEN 8
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
34 #define WARN_GAP 300000 /* microseconds */
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
35
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
36 /*
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
37 * * The warning in text will be printed in the warning window. * The message
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
38 * will last WARNTIME/10 seconds unless another message * comes through and
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
39 * overwrites it.
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
40 */
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
41
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
42 /*
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
43 * a small buffer of warnings to be sent... we want to space them out, since
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
44 * warning() is sometimes called in quick succesison
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
45 */
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
46
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
47 static struct warning_spacket w_buf[WQLEN];
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
48 static int numw = 0, whichw = 0;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
49
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
50 static struct timeval space = {0, 0};
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
51
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
52 /*-------------------------------VISIBLE FUNCTIONS------------------------*/
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
53
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
54 /*--------------------------------WARNING---------------------------------*/
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
55 /*
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
56 * This function sends a warning message to the client, or queues the warning
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
57 * to be sent a little later if we just sent one. The warning can be a
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
58 * maximum of 79 characters plus the delimiter.
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
59 */
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
60
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
61
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
62 extern char *strncpy();
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
63 extern int sendClientPacket();
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
64
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
65 void
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
66 warning(text)
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
67 char *text; /* the warning string */
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
68 {
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
69 struct warning_spacket warn; /* warning packet to send warning in */
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
70 struct warning_spacket *wp;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
71 int t;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
72
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
73 t = temporally_spaced(&space, WARN_GAP);
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
74 if (!numw && t)
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
75 {
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
76 /* don't need to queue it */
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
77 warn.type = SP_WARNING; /* set the type */
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
78 strncpy(warn.mesg, text, 80); /* copy message into packet */
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
79 warn.mesg[79] = '\0'; /* chop message to 79 chars + delimeter */
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
80 sendClientPacket((struct player_spacket *) & warn); /* send the warning
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
81 * packet */
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
82 }
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
83 else
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
84 {
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
85 /* first check to see if this warning has already been queued */
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
86 if (!strcmp(text, w_buf[(whichw + numw - 1) % WQLEN].mesg))
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
87 return;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
88
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
89 wp = &w_buf[(whichw + numw) % WQLEN];
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
90
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
91 wp->type = SP_WARNING;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
92 strncpy(wp->mesg, text, 80);
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
93 wp->mesg[79] = '\0';
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
94
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
95 if (++numw == WQLEN)
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
96 numw = WQLEN - 1;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
97
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
98 /* This is useful especially if updates/sec is set low */
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
99 if (t)
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
100 { /* then there's been enough time to send
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
101 * another one */
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
102 sendClientPacket((struct player_spacket *) & w_buf[whichw]);
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
103 whichw = (whichw + 1) % WQLEN;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
104 numw--;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
105 }
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
106 }
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
107 }
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
108
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
109
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
110 /*---------------------------- UPDATEWARNINGS ---------------------------*/
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
111 /*
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
112 * Called by updateClient. Check to see if there are warnings queued, and
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
113 * send one when enough time has gone by
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
114 */
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
115
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
116 void
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
117 updateWarnings()
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
118 {
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
119 if (!numw)
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
120 return; /* nothing queued */
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
121
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
122 if (!temporally_spaced(&space, WARN_GAP))
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
123 return; /* not time yet */
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
124
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
125 /* we're assuming that the entry in w_buf has been properly filled in */
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
126 sendClientPacket((struct player_spacket *) & w_buf[whichw]);
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
127
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
128 whichw = (whichw + 1) % WQLEN;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
129 numw--;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
130 }
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
131
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
132 /*------------------------------ IMM_WARNING ----------------------------*/
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
133
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
134 /*
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
135 * This sends a warning, bypassing the time-interval check. Used for
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
136 * messages that give continuous updates (like bomb and beam messages) that
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
137 * are sent more frequently then the time interval allows.
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
138 */
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
139
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
140 void
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
141 imm_warning(text)
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
142 char *text;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
143 {
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
144 struct warning_spacket warn;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
145
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
146 warn.type = SP_WARNING;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
147 strncpy(warn.mesg, text, 80);
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
148 warn.mesg[79] = '\0';
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
149 sendClientPacket((struct player_spacket *) & warn);
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
150 }
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
151
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
152 /*------------------------------------------------------------------------*/
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
153
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
154
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
155 /*-------END OF FILE-------*/