annotate udpopt.c @ 3:5a977ccbc7a9 default tip

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