3
3
* Kevin Smith 03/23/88
7
6
#include "copyright2.h"
10
9
#include <sys/types.h>
17
13
#include "struct.h"
19
15
#include "packets.h"
21
18
#include "defaults.h"
22
19
#include "findslot.h"
23
20
#include "newwin.h"
24
21
#include "socket.h"
30
#define WAITTITLE 15 /* height of title for wait window */
32
extern void terminate(int error);
34
static void mapWaitWin(W_Window waitWin);
35
static void mapWaitQuit(W_Window qwin);
36
static void mapWaitCount(W_Window waitWin, W_Window countWin, int count);
37
static void mapWaitMotdButton(W_Window motdButtonWin);
25
window hierarchy diagram
29
\_ count button (not reactive)
32
w_motd message of the day window
36
/* wait queue window constants, in pixels */
37
#define WQ_W 405 /* window width */
38
#define WQ_H 100 /* window height */
39
#define WQ_HEAD 20 /* heading height */
40
#define BM 10 /* button margin */
42
/* calculate an X coordinate for centering given text */
43
static int xc(char *s)
45
return WQ_W / 6 - BM - strlen(s) * W_Textwidth / 2;
48
/* draw or redraw the heading in the wait queue window */
49
static void draw_heading(W_Window w)
53
sprintf(buf, "You are on the queue at %s, please wait.", serverName);
54
W_WriteText(w, 10, 10, textColor, buf, strlen(buf), W_RegularFont);
57
/* draw or redraw the quit button */
58
static void draw_b_quit(W_Window w)
62
W_WriteText(w, xc(s), 25, textColor, s, strlen(s), W_RegularFont);
65
/* draw or redraw the count button */
66
static void draw_b_count(W_Window ww, W_Window cw, int count)
69
char *s2 = "position";
72
W_WriteText(cw, xc(s1), 5, textColor, s1, strlen(s1), W_RegularFont);
73
W_WriteText(cw, xc(s2), 15, textColor, s2, strlen(s2), W_RegularFont);
74
sprintf(buf, " %d ", count);
75
if (count == -1) strcpy(buf, " ? ");
76
W_WriteText(cw, xc(buf), 35, textColor, buf, strlen(buf), W_RegularFont);
78
/* update the window title bar for the window manager to display */
79
sprintf(buf, "Q%d @ %s", count, serverName);
80
W_SetWindowName(ww, buf);
83
/* draw or redraw the motd button */
84
static void draw_b_motd(W_Window w)
86
char *s1 = "show server";
87
char *s2 = "welcome message";
89
W_WriteText(w, xc(s1), 20, textColor, s1, strlen(s1), W_RegularFont);
90
W_WriteText(w, xc(s2), 30, textColor, s2, strlen(s2), W_RegularFont);
93
/* find a server slot, returns the slot number once it is known, but
94
if the server reports we are placed in a queue then display the wait
95
queue window and maintain the count while optionally showing the
96
server message of the day */
42
W_Window waitWin, qwin, countWin, motdButtonWin;
100
W_Window w, b_quit, b_count, b_motd;
45
extern int MaxMotdLine;
103
extern int motd_last;
46
104
int WaitMotdLine = 0;
47
int mapMotd = booleanDefault("showMotd", 1);
105
int mapMotd = booleanDefault("showMotd", 0);
50
108
/* Wait for some kind of indication about in/not in */
51
while (queuePos == -1)
109
while (queuePos == -1) {
111
if (isServerDead()) {
57
112
#if defined(SOUND)
61
fprintf(stderr, "server connection lost, during pre-queue\n");
115
fprintf(stderr, "server connection lost, during pre-queue\n");
118
readFromServer(NULL);
73
125
/* We have to wait. Make appropriate windows, etc... */
75
waitWin = W_MakeWindow("wait", 0, 0, WAITWIDTH, WAITHEIGHT, NULL, 2,
77
countWin = W_MakeWindow("count", WAITWIDTH / 3, WAITTITLE, WAITWIDTH / 3,
78
WAITHEIGHT - WAITTITLE, waitWin, 1, foreColor);
79
qwin = W_MakeWindow("waitquit", 0, WAITTITLE, WAITWIDTH / 3,
80
WAITHEIGHT - WAITTITLE, waitWin, 1, foreColor);
81
motdButtonWin = W_MakeWindow("motdbutton", 2 * WAITWIDTH / 3, WAITTITLE,
82
WAITWIDTH / 3, WAITHEIGHT - WAITTITLE, waitWin,
85
W_MapWindow(countWin);
86
W_MapWindow(motdButtonWin);
90
motdWin = W_MakeWindow("waitmotd", 1, WAITWIDTH + 1, TWINSIDE,
91
TWINSIDE, 0, 2, foreColor);
93
showMotd(motdWin, WaitMotdLine);
107
fprintf(stderr, "server connection lost, during queue wait\n");
110
while (W_EventsPending())
113
switch ((int) event.type)
117
if (mapMotd && event.Window == motdWin)
119
if (event.key == ' ' || event.key == 'q')
121
W_DestroyWindow(motdWin);
126
if (event.key == 'b')
129
WaitMotdLine = MAX(WaitMotdLine, 0);
134
/* scroll to start if it goes over */
135
if (WaitMotdLine > MaxMotdLine)
138
W_ClearWindow(motdWin);
139
showMotd(motdWin, WaitMotdLine);
143
else if (event.Window == motdButtonWin)
147
W_DestroyWindow(motdWin);
151
motdWin = W_MakeWindow("waitmotd", 1, WAITWIDTH + 1,
152
TWINSIDE, TWINSIDE, 0, 2,
154
W_MapWindow(motdWin);
155
showMotd(motdWin, WaitMotdLine);
159
else if (event.Window == qwin)
164
fprintf(stderr, "you selected quit\n");
169
if (event.Window == waitWin)
173
else if (event.Window == motdWin)
175
showMotd(motdWin, WaitMotdLine);
177
else if (event.Window == qwin)
181
else if (event.Window == countWin)
183
mapWaitCount(waitWin, countWin, queuePos);
185
else if (event.Window == motdButtonWin)
187
mapWaitMotdButton(motdButtonWin);
191
if (event.Window == waitWin) {
193
"you quit, by closing the wait window\n");
201
if (queuePos != oldcount)
203
mapWaitCount(waitWin, countWin, queuePos);
208
W_DestroyWindow(waitWin);
211
W_DestroyWindow(motdWin);
221
static void mapWaitWin(W_Window waitWin)
226
sprintf(buf, "Game full at %s", serverName);
229
W_WriteText(waitWin, 15, 5, textColor, s, strlen(s), W_RegularFont);
232
static void mapWaitQuit(W_Window qwin)
236
W_WriteText(qwin, 10, 15, textColor, s, strlen(s), W_RegularFont);
239
static void mapWaitCount(W_Window waitWin, W_Window countWin, int count)
245
W_WriteText(countWin, 17, 5, textColor, s1, strlen(s1), W_RegularFont);
246
W_WriteText(countWin, 15, 15, textColor, s2, strlen(s2), W_RegularFont);
247
sprintf(buf, "%d ", count);
249
STRNCPY(buf, "?", 2);
250
W_WriteText(countWin, WAITWIDTH / 6 - strlen(buf) * W_Textwidth / 2, 25,
251
textColor, buf, strlen(buf), W_RegularFont);
252
sprintf(buf, "Q%d @ %s", count, serverName);
253
W_SetWindowName(waitWin, buf);
256
static void mapWaitMotdButton(W_Window motdButtonWin)
260
W_WriteText(motdButtonWin, 10, 15, textColor, s, strlen(s), W_RegularFont);
127
w = W_MakeWindow("wait", 0, 0, WQ_W, WQ_H, NULL, 2,
129
b_quit = W_MakeWindow("waitquit", BM, WQ_HEAD + BM,
130
WQ_W / 3 - BM * 2, WQ_H - WQ_HEAD - 2 - BM * 2,
132
b_count = W_MakeWindow("count", WQ_W / 3 + BM, WQ_HEAD + BM,
133
WQ_W / 3 - BM * 2, WQ_H - WQ_HEAD - 2 - BM * 2,
135
b_motd = W_MakeWindow("motdbutton", 2 * WQ_W / 3 + BM, WQ_HEAD + BM,
136
WQ_W / 3 - BM * 2, WQ_H - WQ_HEAD - 2 - BM * 2,
139
W_MapWindow(b_count);
143
w_motd = W_MakeWindow("waitmotd", 1, WQ_W + 1, TWINSIDE,
144
TWINSIDE, 0, 2, foreColor);
146
showMotd(w_motd, WaitMotdLine);
149
/* a local event loop, exits when the player is given a slot, or if
150
the server disconnects, or if the user choses to quit */
153
readFromServer(NULL);
154
if (isServerDead()) {
158
fprintf(stderr, "server connection lost, during queue wait\n");
161
while (W_EventsPending()) {
163
switch ((int) event.type) {
166
if (mapMotd && event.Window == w_motd) {
167
if (event.key == ' ' || event.key == 'q') {
168
W_DestroyWindow(w_motd);
171
if (event.key == 'b') {
173
WaitMotdLine = MAX(WaitMotdLine, 0);
176
if (WaitMotdLine > motd_last)
179
W_ClearWindow(w_motd);
180
showMotd(w_motd, WaitMotdLine);
183
} else if (event.Window == b_motd) {
185
W_DestroyWindow(w_motd);
187
w_motd = W_MakeWindow("waitmotd", 1, WQ_W + 1,
188
TWINSIDE, TWINSIDE, 0, 2,
192
showMotd(w_motd, WaitMotdLine);
195
} else if (event.Window == b_quit || event.key == 'q') {
199
fprintf(stderr, "you selected quit\n");
204
if (event.Window == w) {
206
} else if (event.Window == w_motd) {
207
showMotd(w_motd, WaitMotdLine);
208
} else if (event.Window == b_quit) {
210
} else if (event.Window == b_count) {
211
draw_b_count(w, b_count, queuePos);
212
} else if (event.Window == b_motd) {
217
if (event.Window == w) {
218
fprintf(stderr, "you quit, by closing the wait window\n");
220
} else if (event.Window == w_motd) {
221
W_DestroyWindow(w_motd);
230
/* keep the count button up to date based on the server responses */
231
if (queuePos != oldcount) {
232
draw_b_count(w, b_count, queuePos);
236
/* if we have a slot now, destroy the windows and begin playing */
240
W_DestroyWindow(w_motd);