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