comparison src/feature.c @ 4:aa38447a4b21

First entry of Paradise Server 2.9 patch 10 Beta
author darius
date Sat, 06 Dec 1997 04:37:03 +0000
parents
children
comparison
equal deleted inserted replaced
3:cafa94d86546 4:aa38447a4b21
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 #ifdef FEATURE
21 #ifdef HPUX
22 #include <sys/types.h>
23 #include <netinet/in.h>
24 #endif
25 #include "defs.h"
26 #include "data.h"
27 #include "struct.h"
28 #include "packets.h"
29
30 void sendClientPacket();
31
32 #ifdef UNIXWARE /* can you BELIEVE it doesn't have strcmpi?? */
33 #if 0 /* just use strcmp for now */
34 int
35 strcmpi(char *a, char *b)
36 {
37
38 char ta, tb;
39
40 while ((*a) && (*b))
41 {
42 ta = ((*a) >= 'a') && ((*b) <= 'z')) ? (*a) & 223 : (*a);
43 tb = ((*b) >= 'a') && ((*b) <= 'z')) ? (*b) & 223 : (*b);
44 if (ta < tb)
45 return (-1);
46 if (ta > tb)
47 return (1);
48 a++;
49 b++;
50 }
51 if (!(*a) && (*b))
52 return (1);
53 if (!(*b) && (*a))
54 return (-1);
55 return (0);
56 }
57 #endif
58 #endif
59
60 /*
61 * Feature.c
62 *
63 * March, 1994. Joe Rumsey, Tedd Hadley
64 *
65 * most of the functions needed to handle SP_FEATURE/CP_FEATURE packets. fill
66 * in the features list below for your client, and add a call to
67 * reportFeatures just before the RSA response is sent. handleFeature should
68 * just call checkFeature, which will search the list and set the appropriate
69 * variable. features unknown to the server are set to the desired value for
70 * client features, and off for server/client features.
71 *
72 * feature packets look like: struct feature_cpacket { char
73 * type; char feature_type; char arg1, arg2;
74 * int value; char name[80]; };
75 *
76 * type is CP_FEATURE, which is 60. feature_spacket is identical.
77 *
78 * Code lifted July 1995 by Bob Glamm - enabled into server code.
79 *
80 */
81
82 void handleFeature(struct feature_cpacket *);
83 void
84 sendFeature(char *name, int feature_type,
85 int value, int arg1, int arg2);
86
87 /* not the actual packets: this holds a list of features to report for */
88 /* this client. */
89 struct feature
90 {
91 char *name;
92 int *var; /* holds allowed/enabled status */
93 char feature_type; /* 'S' or 'C' for server/client */
94 int value; /* desired status */
95 char *arg1, *arg2; /* where to copy args, if non-null */
96 } features[] =
97 {
98 /*
99 * also sent seperately, put here for checking later. should be ok that
100 * it's sent twice.
101 */
102 {
103 "FEATURE_PACKETS", &F_feature_packets, 'S', 1, 0, 0
104 },
105
106 {
107 "VIEW_BOX", &F_allowViewBox, 'C', 1, 0, 0
108 },
109 {
110 "SHOW_ALL_TRACTORS", &F_allowShowAllTractorPressor, 'S', 1, 0, 0
111 },
112 #ifdef CONTINUOUS_MOUSE
113 {
114 "CONTINUOUS_MOUSE", &F_allowContinuousMouse, 'C', 1, 0, 0
115 },
116 #endif
117 {
118 "NEWMACRO", &F_UseNewMacro, 'C', 1, 0, 0
119 },
120 /* {"SMARTMACRO",&F_UseSmartMacro, 'C', 1, 0, 0}, */
121 {
122 "MULTIMACROS", &F_multiline_enabled, 'S', 1, 0, 0
123 },
124 {
125 "WHY_DEAD", &F_why_dead, 'S', 1, 0, 0
126 },
127 {
128 "CLOAK_MAXWARP", &F_cloakerMaxWarp, 'S', 1, 0, 0
129 },
130 /* {"DEAD_WARP", &F_dead_warp, 'S', 1, 0, 0}, */
131 #ifdef RC_DISTRESS
132 {
133 "RC_DISTRESS", &F_gen_distress, 'S', 1, 0, 0
134 },
135 #ifdef BEEPLITE
136 {
137 "BEEPLITE", &F_allow_beeplite, 'C', 1, (char *) &F_beeplite_flags, 0
138 },
139 #endif
140 #endif
141 /* terrain features */
142 {
143 "TERRAIN", &F_terrain, 'S', 1, (char *) &F_terrain_major, (char *) &F_terrain_minor
144 },
145 /* Gzipped MOTD */
146 {
147 "GZ_MOTD", &F_gz_motd, 'S', 1, (char *) &F_gz_motd_major, (char *) &F_gz_motd_minor
148 },
149 {
150 0, 0, 0, 0, 0, 0
151 }
152 };
153
154 void
155 handleFeature(packet)
156 struct feature_cpacket *packet;
157 {
158 int feature = 0;
159 int value = ntohl(packet->value);
160
161 #ifdef FEATURE_DIAG
162 pmessage("Whoohoo! Getting a feature packet.", 0, MALL, MSERVA);
163 #endif
164 while (features[feature].name)
165 {
166 if (!strcmp(features[feature].name, packet->name))
167 {
168 #ifdef FEATURE_DIAG
169 {
170 char buf[80];
171 sprintf(buf, "BEANS! Matched feature %s", packet->name);
172 pmessage(buf, 0, MALL, MSERVA);
173 }
174 #endif
175 /* A match was found. */
176 if (features[feature].var)
177 *features[feature].var = packet->value;
178 if (features[feature].arg1)
179 *features[feature].arg1 = packet->arg1;
180 if (features[feature].arg2)
181 *features[feature].arg2 = packet->arg2;
182
183 /*
184 * tell the client that the server handles all of the above server
185 * features.
186 */
187 if (features[feature].feature_type == 'S')
188 {
189 #ifdef FEATURE_DIAG
190 pmessage("Sending FEATURE_PACKETS right back at ya!", 0, MALL, MSERVA);
191 #endif
192 sendFeature(features[feature].name,
193 features[feature].feature_type,
194 features[feature].value,
195 (features[feature].arg1 ? *features[feature].arg1 : 0),
196 (features[feature].arg2 ? *features[feature].arg2 : 0));
197 }
198 }
199 feature++;
200 }
201 }
202
203 void
204 sendFeature(name, feature_type, value, arg1, arg2)
205 char *name;
206 int feature_type;
207 int value;
208 int arg1, arg2;
209 {
210 struct feature_cpacket packet;
211 #ifdef FEATURE_DIAG
212 char buf[80];
213
214 sprintf(buf, "Sending packet %d, name %s", SP_FEATURE, name);
215 pmessage(buf, 0, MALL, MSERVA);
216 #endif
217
218 strncpy(packet.name, name, sizeof(packet.name));
219 packet.type = SP_FEATURE;
220 packet.name[sizeof(packet.name) - 1] = 0;
221 packet.feature_type = feature_type;
222 packet.value = htonl(value);
223 packet.arg1 = arg1;
224 packet.arg2 = arg2;
225 sendClientPacket((struct player_spacket *) & packet);
226 }
227
228 #endif /* FEATURE */