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