Mercurial > ~darius > hgwebdir.cgi > paradise_client
comparison feature.c @ 3:5a977ccbc7a9 default tip
Empty changelog
author | darius |
---|---|
date | Sat, 06 Dec 1997 05:41:29 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2:fba0b6e6cdc7 | 3:5a977ccbc7a9 |
---|---|
1 /* $Id: feature.c,v 1.1.1.1 1997/12/06 05:41:29 darius Exp $ */ | |
2 | |
3 /* | |
4 * Feature.c | |
5 * | |
6 * March, 1994. Joe Rumsey, Tedd Hadley | |
7 * | |
8 * most of the functions needed to handle SP_FEATURE/CP_FEATURE | |
9 * packets. fill in the features list below for your client, and | |
10 * add a call to reportFeatures just before the RSA response is sent. | |
11 * handleFeature should just call checkFeature, which will search the | |
12 * list and set the appropriate variable. features unknown to the | |
13 * server are set to the desired value for client features, and off | |
14 * for server/client features. | |
15 * | |
16 * feature packets look like: | |
17 struct feature_cpacket { | |
18 char type; | |
19 char feature_type; | |
20 char arg1, | |
21 arg2; | |
22 int value; | |
23 char name[80]; | |
24 }; | |
25 | |
26 * type is CP_FEATURE, which is 60. feature_spacket is identical. | |
27 */ | |
28 | |
29 | |
30 #ifdef FEATURE | |
31 #include "copyright.h" | |
32 | |
33 #include <stdio.h> | |
34 #include <sys/types.h> | |
35 #include <netinet/in.h> | |
36 #include "Wlib.h" | |
37 #include "defs.h" | |
38 #include "struct.h" | |
39 #include "data.h" | |
40 #include "proto.h" | |
41 #include "packets.h" | |
42 | |
43 | |
44 void sendFeature P((char *name, int feature_type, | |
45 int value, int arg1, int arg2)); | |
46 void reportFeatures P((void)); | |
47 | |
48 /* not the actual packets: this holds a list of features to report for */ | |
49 /* this client. */ | |
50 struct feature { | |
51 char *name; | |
52 int *var; /* holds allowed/enabled status */ | |
53 char feature_type; /* 'S' or 'C' for server/client */ | |
54 int value; /* desired status */ | |
55 char *arg1, *arg2; /* where to copy args, if non-null */ | |
56 } features[] = { | |
57 /* | |
58 also sent seperately, put here for checking later. should be ok that | |
59 it's sent twice. | |
60 */ | |
61 {"FEATURE_PACKETS", &F_feature_packets, 'S', 1, 0, 0}, | |
62 | |
63 {"VIEW_BOX", &allowViewBox, 'C', 1, 0, 0}, | |
64 {"SHOW_ALL_TRACTORS", &allowShowAllTractorPressor, 'S', 1, 0, 0}, | |
65 #ifdef CONTINUOUS_MOUSE | |
66 {"CONTINUOUS_MOUSE", &allowContinuousMouse, 'C', 1, 0, 0}, | |
67 #endif | |
68 {"NEWMACRO", &F_UseNewMacro, 'C', 1, 0, 0}, | |
69 /* {"SMARTMACRO",&UseSmartMacro, 'C', 1, 0, 0}, */ | |
70 {"MULTIMACROS", &F_multiline_enabled, 'S', 1, 0, 0}, | |
71 {"WHY_DEAD", &why_dead, 'S', 1, 0, 0}, | |
72 {"CLOAK_MAXWARP", &cloakerMaxWarp, 'S', 1, 0, 0}, | |
73 /*{"DEAD_WARP", &F_dead_warp, 'S', 1, 0, 0},*/ | |
74 #ifdef RC_DISTRESS | |
75 {"RC_DISTRESS", &F_gen_distress, 'S', 1, 0, 0}, | |
76 #ifdef BEEPLITE | |
77 {"BEEPLITE", &F_allow_beeplite, 'C', 1, (char*)&F_beeplite_flags, 0}, | |
78 #endif | |
79 #endif | |
80 /* terrain features */ | |
81 {"TERRAIN", &F_terrain, 'S', 1, (char*)&F_terrain_major, (char*)&F_terrain_minor}, | |
82 /* Gzipped MOTD */ | |
83 {"GZ_MOTD", &F_gz_motd, 'S', 1, (char*)&F_gz_motd_major, (char*)&F_gz_motd_minor}, | |
84 {0, 0, 0, 0, 0, 0} | |
85 }; | |
86 | |
87 void | |
88 checkFeature(packet) | |
89 struct feature_spacket *packet; | |
90 { | |
91 int i; | |
92 int value = ntohl(packet->value); | |
93 | |
94 #ifdef FEAT_DEBUG | |
95 if (packet->type != SP_FEATURE) { | |
96 printf("Packet type %d sent to checkFeature!\n", packet->type); | |
97 return; | |
98 } | |
99 #endif | |
100 printf("%s: %s(%d)\n", &packet->name[0], | |
101 ((value == 1) ? "ON" : (value == 0) ? "OFF" : "UNKNOWN"), | |
102 value); | |
103 | |
104 for (i = 0; features[i].name != 0; i++) { | |
105 if (strcmpi(packet->name, features[i].name) == 0) { | |
106 /* | |
107 if server returns unknown, set to off for server mods, desired | |
108 value for client mods. Otherwise, set to value from server. | |
109 */ | |
110 *features[i].var = (value == -1 ? | |
111 (features[i].feature_type == 'S' ? 0 : features[i].value) : | |
112 value); | |
113 if (features[i].arg1) | |
114 *features[i].arg1 = packet->arg1; | |
115 if (features[i].arg2) | |
116 *features[i].arg2 = packet->arg2; | |
117 break; | |
118 } | |
119 } | |
120 if (features[i].name == 0) { | |
121 printf("Feature %s from server unknown to client!\n", packet->name); | |
122 } | |
123 /* special cases: */ | |
124 if ((strcmpi(packet->name, "FEATURE_PACKETS")==0)) | |
125 reportFeatures(); | |
126 else if ((strcmpi(packet->name, "RC_DISTRESS") == 0) && F_gen_distress) | |
127 distmacro = dist_prefered; | |
128 else if ((strcmpi(packet->name, "BEEPLITE") == 0)) { | |
129 switch (value) { | |
130 case -1: /* Unknown, we can use all of the features! */ | |
131 F_beeplite_flags = LITE_PLAYERS_MAP | | |
132 LITE_PLAYERS_LOCAL | | |
133 LITE_SELF | | |
134 LITE_PLANETS | | |
135 LITE_SOUNDS | | |
136 LITE_COLOR; | |
137 break; | |
138 case 1: | |
139 if (F_beeplite_flags == 0) { /* Server says we can have | |
140 beeplite, but no | |
141 options??? must be | |
142 configured wrong. */ | |
143 F_beeplite_flags = LITE_PLAYERS_MAP | | |
144 LITE_PLAYERS_LOCAL | | |
145 LITE_SELF | | |
146 LITE_PLANETS | | |
147 LITE_SOUNDS | | |
148 LITE_COLOR; | |
149 } | |
150 if (!(F_beeplite_flags & LITE_PLAYERS_MAP)) | |
151 printf(" LITE_PLAYERS_MAP disabled\n"); | |
152 if (!(F_beeplite_flags & LITE_PLAYERS_LOCAL)) | |
153 printf(" LITE_PLAYERS_LOCAL disabled\n"); | |
154 if (!(F_beeplite_flags & LITE_SELF)) | |
155 printf(" LITE_SELF disabled\n"); | |
156 if (!(F_beeplite_flags & LITE_PLANETS)) | |
157 printf(" LITE_PLANETS disabled\n"); | |
158 if (!(F_beeplite_flags & LITE_SOUNDS)) | |
159 printf(" LITE_SOUNDS disabled\n"); | |
160 if (!(F_beeplite_flags & LITE_COLOR)) | |
161 printf(" LITE_COLOR disabled\n"); | |
162 break; | |
163 default: | |
164 break; | |
165 } | |
166 } | |
167 } | |
168 | |
169 /* call this from handleReserved */ | |
170 void | |
171 reportFeatures() | |
172 { | |
173 struct feature *f; | |
174 | |
175 /* | |
176 Don't send features[0], which is the feature for FEATURE_PACKETS itself. | |
177 That's sent from main() | |
178 */ | |
179 for (f = &features[1]; f->name != 0; f++) { | |
180 sendFeature(f->name, | |
181 f->feature_type, | |
182 f->value, | |
183 (f->arg1 ? *f->arg1 : 0), | |
184 (f->arg2 ? *f->arg2 : 0)); | |
185 #ifdef FEAT_DEBUG | |
186 printf("(C->S) %s (%c): %d\n", f->name, f->feature_type, f->value); | |
187 #endif | |
188 } | |
189 } | |
190 | |
191 void | |
192 sendFeature(name, feature_type, value, arg1, arg2) | |
193 char *name; | |
194 int feature_type; | |
195 int value; | |
196 int arg1, arg2; | |
197 { | |
198 struct feature_cpacket packet; | |
199 | |
200 #ifdef FEAT_DEBUG | |
201 printf( "Sending feature %s (value = %d)\n", name, value ); | |
202 #endif | |
203 strncpy(packet.name, name, sizeof(packet.name)); | |
204 packet.type = CP_FEATURE; | |
205 packet.name[sizeof(packet.name) - 1] = 0; | |
206 packet.feature_type = feature_type; | |
207 packet.value = htonl(value); | |
208 packet.arg1 = arg1; | |
209 packet.arg2 = arg2; | |
210 sendServerPacket((struct player_spacket *) & packet); | |
211 } | |
212 | |
213 void | |
214 handleFeature(packet) | |
215 struct feature_spacket *packet; | |
216 { | |
217 #ifdef FEAT_DEBUG | |
218 printf( "Handling Feature packet\n" ); | |
219 #endif | |
220 checkFeature(packet); | |
221 } | |
222 #endif /* FEATURE */ |