Mercurial > ~darius > hgwebdir.cgi > paradise_client
comparison udpopt.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: udpopt.c,v 1.1.1.1 1997/12/06 05:41:31 darius Exp $ */ | |
2 | |
3 /* | |
4 * udpopt.c - present UDP control window | |
5 */ | |
6 #include "copyright.h" | |
7 | |
8 #include <stdio.h> | |
9 #include <ctype.h> | |
10 #include <string.h> | |
11 #include "Wlib.h" | |
12 #include "defs.h" | |
13 #include "struct.h" | |
14 #include "data.h" | |
15 #include "proto.h" | |
16 | |
17 #define UDPBORDER 2 | |
18 #define UDPLEN 35 | |
19 | |
20 /* Set up the UDP control window */ | |
21 void | |
22 udpwindow() | |
23 { | |
24 register int i; | |
25 | |
26 for (i = 0; i < UDP_NUMOPTS; i++) | |
27 udprefresh(i); | |
28 | |
29 /* Map window */ | |
30 W_MapWindow(udpWin); | |
31 } | |
32 | |
33 /* | |
34 * Refresh item i | |
35 */ | |
36 void | |
37 udprefresh(i) | |
38 int i; | |
39 { | |
40 char buf[BUFSIZ]; | |
41 | |
42 switch (i) { | |
43 case UDP_CURRENT: | |
44 sprintf(buf, "UDP channel is %s", (commMode == COMM_TCP) ? | |
45 "CLOSED" : "OPEN"); | |
46 break; | |
47 case UDP_STATUS: | |
48 strcpy(buf, "> Status: "); | |
49 switch (commStatus) { | |
50 case STAT_CONNECTED: | |
51 strcat(buf, "Connected"); | |
52 break; | |
53 case STAT_SWITCH_UDP: | |
54 strcat(buf, "Requesting switch to UDP"); | |
55 break; | |
56 case STAT_SWITCH_TCP: | |
57 strcat(buf, "Requesting switch to TCP"); | |
58 break; | |
59 case STAT_VERIFY_UDP: | |
60 strcat(buf, "Verifying UDP connection"); | |
61 break; | |
62 default: | |
63 fprintf(stderr, "netrek: UDP error: bad commStatus (%d)\n", | |
64 commStatus); | |
65 } | |
66 break; | |
67 case UDP_DROPPED: | |
68 sprintf(buf, "> UDP trans dropped: %d (%d%% | %d%%)", udpDropped, | |
69 udpDropped * 100 / udpTotal, /* (udpTotal always > 0) */ | |
70 udpRecentDropped * 100 / UDP_RECENT_INTR); | |
71 break; | |
72 case UDP_SEQUENCE: | |
73 sprintf(buf, "Sequence checking is %s", (udpSequenceChk) ? | |
74 "ON" : "OFF"); | |
75 break; | |
76 case UDP_DEBUG: | |
77 sprintf(buf, "Debugging info is "); | |
78 switch (udpDebug) { | |
79 case 0: | |
80 strcat(buf, "OFF"); | |
81 break; | |
82 case 1: | |
83 strcat(buf, "ON (connect msgs only)"); | |
84 break; | |
85 case 2: | |
86 strcat(buf, "ON (verbose output)"); | |
87 break; | |
88 } | |
89 break; | |
90 case UDP_SEND: | |
91 sprintf(buf, "Sending with "); | |
92 switch (udpClientSend) { | |
93 case 0: | |
94 strcat(buf, "TCP only"); | |
95 break; | |
96 case 1: | |
97 strcat(buf, "simple UDP"); | |
98 break; | |
99 case 2: | |
100 strcat(buf, "enforced UDP (state only)"); | |
101 break; | |
102 case 3: | |
103 strcat(buf, "enforced UDP (state & weap)"); | |
104 break; | |
105 } | |
106 break; | |
107 case UDP_RECV: | |
108 sprintf(buf, "Receiving with "); | |
109 switch (udpClientRecv) { | |
110 case MODE_TCP: | |
111 strcat(buf, "TCP only"); | |
112 break; | |
113 case MODE_SIMPLE: | |
114 strcat(buf, "simple UDP"); | |
115 break; | |
116 case MODE_FAT: | |
117 strcat(buf, "fat UDP"); | |
118 break; | |
119 #ifdef DOUBLE_UDP | |
120 case MODE_DOUBLE: | |
121 strcat(buf, "double UDP"); | |
122 break; | |
123 #endif /* DOUBLE_UDP */ | |
124 } | |
125 break; | |
126 case UDP_FORCE_RESET: | |
127 sprintf(buf, "Force reset to TCP"); | |
128 break; | |
129 case UDP_UPDATE_ALL: | |
130 sprintf(buf, "Request full update (=)"); | |
131 break; | |
132 #ifdef GATEWAY | |
133 case UDP_GW: | |
134 sprintf(buf, "gw: %s %d/%d/%d", gw_mach, gw_serv_port, gw_port, | |
135 gw_local_port); | |
136 break; | |
137 #endif | |
138 case UDP_DONE: | |
139 strcpy(buf, "Done"); | |
140 break; | |
141 default: | |
142 fprintf(stderr, "netrek: UDP error: bad udprefresh(%d) call\n", i); | |
143 } | |
144 | |
145 W_WriteText(udpWin, 0, i, textColor, buf, strlen(buf), 0); | |
146 } | |
147 | |
148 void | |
149 udpaction(data) | |
150 W_Event *data; | |
151 { | |
152 register int i; | |
153 | |
154 switch (data->y) { | |
155 case UDP_CURRENT: | |
156 if (commMode == COMM_TCP) | |
157 sendUdpReq(COMM_UDP); | |
158 else | |
159 sendUdpReq(COMM_TCP); | |
160 break; | |
161 | |
162 case UDP_STATUS: | |
163 case UDP_DROPPED: | |
164 W_Beep(); | |
165 break; | |
166 case UDP_SEQUENCE: | |
167 udpSequenceChk = !udpSequenceChk; | |
168 udprefresh(UDP_SEQUENCE); | |
169 break; | |
170 case UDP_SEND: | |
171 udpClientSend++; | |
172 if (udpClientSend > 3) | |
173 udpClientSend = 0; | |
174 udprefresh(UDP_SEND); | |
175 break; | |
176 case UDP_RECV: | |
177 udpClientRecv++; | |
178 #ifdef DOUBLE_UDP | |
179 if (udpClientRecv > MODE_DOUBLE) | |
180 udpClientRecv = 0; | |
181 #else | |
182 if (udpClientRecv >= MODE_DOUBLE) | |
183 udpClientRecv = 0; | |
184 #endif | |
185 udprefresh(UDP_RECV); | |
186 sendUdpReq(COMM_MODE + udpClientRecv); | |
187 break; | |
188 case UDP_DEBUG: | |
189 udpDebug++; | |
190 if (udpDebug > 2) | |
191 udpDebug = 0; | |
192 udprefresh(UDP_DEBUG); | |
193 break; | |
194 case UDP_FORCE_RESET: | |
195 /* clobber UDP */ | |
196 UDPDIAG(("*** FORCE RESET REQUESTED\n")); | |
197 sendUdpReq(COMM_TCP); | |
198 commMode = commModeReq = COMM_TCP; | |
199 commStatus = STAT_CONNECTED; | |
200 commSwitchTimeout = 0; | |
201 udpClientSend = udpClientRecv = udpSequenceChk = udpTotal = 1; | |
202 udpDebug = udpDropped = udpRecentDropped = 0; | |
203 if (udpSock >= 0) | |
204 closeUdpConn(); | |
205 for (i = 0; i < UDP_NUMOPTS; i++) | |
206 udprefresh(i); | |
207 break; | |
208 case UDP_UPDATE_ALL: | |
209 sendUdpReq(COMM_UPDATE); | |
210 break; | |
211 #ifdef GATEWAY | |
212 case UDP_GW: | |
213 W_Beep(); | |
214 break; | |
215 #endif | |
216 case UDP_DONE: | |
217 udpdone(); | |
218 break; | |
219 } | |
220 } | |
221 | |
222 void | |
223 udpdone() | |
224 { | |
225 /* Unmap window */ | |
226 W_UnmapWindow(udpWin); | |
227 } |