3
|
1 /* $Id: findslot.c,v 1.1.1.1 1997/12/06 05:41:29 darius Exp $ */
|
|
2
|
|
3 /*
|
|
4 * findslot.c
|
|
5 *
|
|
6 * Kevin Smith 03/23/88
|
|
7 *
|
|
8 */
|
|
9 #include "copyright2.h"
|
|
10
|
|
11 #include <stdio.h>
|
|
12 #include <sys/types.h>
|
|
13 #include <errno.h>
|
|
14 #include <pwd.h>
|
|
15 #include <string.h>
|
|
16 #include <ctype.h>
|
|
17 #ifdef __STDC__
|
|
18 #include <stdlib.h>
|
|
19 #endif
|
|
20 #include "Wlib.h"
|
|
21 #include "defs.h"
|
|
22 #include "struct.h"
|
|
23 #include "data.h"
|
|
24 #include "proto.h"
|
|
25
|
|
26 #define WAITWIDTH 180
|
|
27 #define WAITHEIGHT 60
|
|
28 #define WAITTITLE 15 /* height of title for wait window */
|
|
29 #define WAITICONHEIGHT 50
|
|
30 #define WAITICONWIDTH 50
|
|
31
|
|
32 /* Prototypes */
|
|
33 static void mapWaitCount P((W_Window countWin, unsigned int count));
|
|
34 static void mapWaitQuit P((W_Window qwin));
|
|
35 static void mapWaitWin P((W_Window waitWin));
|
|
36 static void mapMotdButtonWin P((W_Window motdButtonWin));
|
|
37 static void mapWaitIcon
|
|
38 P((W_Window waitIcon, unsigned int count,
|
|
39 int *motdMapLater));
|
|
40
|
|
41 extern int newMotdStuff; /* from newwin.c */
|
|
42
|
|
43
|
|
44 int findslot()
|
|
45 {
|
|
46 int oldcount = -1;
|
|
47 W_Window waitWin, qwin, countWin, motdButtonWin, waitIcon;
|
|
48 W_Event event;
|
|
49 int motdMapLater = 0;
|
|
50
|
|
51 /* Wait for some kind of indication about in/not in */
|
|
52 while (queuePos == -1) {
|
|
53 socketPause(1, 0);
|
|
54 if (isServerDead()) {
|
|
55 printf("Augh! Ghostbusted!\n");
|
|
56 EXIT(0);
|
|
57 }
|
|
58 readFromServer();
|
|
59 if (me != NULL) {
|
|
60 /* We are in! */
|
|
61 printf("*** socket %d, player %d ( -s %d -G %d [-2] ) ***\n",
|
|
62 nextSocket, me->p_no,
|
|
63 nextSocket, me->p_no);
|
|
64 return (me->p_no);
|
|
65 }
|
|
66 }
|
|
67
|
|
68 /* We have to wait. Make appropriate windows, etc... */
|
|
69 waitWin = W_MakeWindow("wait", 0, 0, WAITWIDTH, WAITHEIGHT, NULL, (char *) 0, 2, foreColor);
|
|
70 countWin = W_MakeWindow("count", WAITWIDTH / 3, WAITTITLE, 2 * WAITWIDTH / 3,
|
|
71 WAITHEIGHT - WAITTITLE, waitWin, (char *) 0, 1, foreColor);
|
|
72 qwin = W_MakeWindow("waitquit", 0, WAITTITLE, WAITWIDTH / 3,
|
|
73 WAITHEIGHT - WAITTITLE, waitWin, (char *) 0, 1, foreColor);
|
|
74 motdButtonWin = W_MakeWindow("motd_select", 2 * WAITWIDTH / 3, WAITTITLE,
|
|
75 WAITWIDTH, WAITHEIGHT - WAITTITLE, waitWin, (char *) 0, 1, foreColor);
|
|
76 waitIcon = W_MakeWindow("wait_icon", 0, 0, WAITICONWIDTH, WAITICONHEIGHT,
|
|
77 NULL, NULL, BORDER, foreColor);
|
|
78 W_SetIconWindow(waitWin, waitIcon);
|
|
79 /* showMotdWin(); */
|
|
80 #ifndef AMIGA
|
|
81 W_MapWindow(waitWin);
|
|
82 W_MapWindow(countWin);
|
|
83 W_MapWindow(qwin);
|
|
84 W_MapWindow(motdButtonWin);
|
|
85 #else
|
|
86 W_MapWindow(waitIcon);
|
|
87 #endif
|
|
88 for (;;) {
|
|
89 socketPause(0, 10000);
|
|
90 readFromServer();
|
|
91 if (isServerDead()) {
|
|
92 printf("We've been ghostbusted!\n");
|
|
93 EXIT(0);
|
|
94 }
|
|
95 if (newMotdStuff)
|
|
96 showMotd(motdWin);
|
|
97 while (W_EventsPending()) {
|
|
98 W_NextEvent(&event);
|
|
99 switch ((int) event.type) {
|
|
100 case W_EV_KEY:
|
|
101 if (event.Window == motdWin) {
|
|
102 motdWinEvent(event.key);
|
|
103 }
|
|
104 #ifdef AMIGA
|
|
105 else if (event.Window == waitIcon) {
|
|
106 switch (event.key) {
|
|
107 case 'q':
|
|
108 case 'Q':
|
|
109 printf("OK, bye!\n");
|
|
110 EXIT(0);
|
|
111 case 'm':
|
|
112 case 'M':
|
|
113 showMotdWin();
|
|
114 break;
|
|
115 default:
|
|
116 break;
|
|
117 }
|
|
118 }
|
|
119 #endif
|
|
120 case W_EV_BUTTON: /* fall through */
|
|
121 if (event.Window == qwin) {
|
|
122 printf("OK, bye!\n");
|
|
123 EXIT(0);
|
|
124 } else if (event.Window == motdButtonWin) {
|
|
125 showMotdWin();
|
|
126 } else if (event.Window == waitIcon) {
|
|
127 mapWaitIcon(waitIcon, queuePos, NULL);
|
|
128 }
|
|
129 break;
|
|
130 case W_EV_EXPOSE:
|
|
131 if (event.Window == waitWin) {
|
|
132 if (motdMapLater) {
|
|
133 showMotd(motdWin);
|
|
134 motdMapLater = 0;
|
|
135 }
|
|
136 mapWaitWin(waitWin);
|
|
137 } else if (event.Window == qwin) {
|
|
138 mapWaitQuit(qwin);
|
|
139 } else if (event.Window == countWin) {
|
|
140 mapWaitCount(countWin, queuePos);
|
|
141 } else if (event.Window == motdWin) {
|
|
142 showMotd(motdWin);
|
|
143 } else if (event.Window == motdButtonWin) {
|
|
144 mapMotdButtonWin(motdButtonWin);
|
|
145 } else if (event.Window == waitIcon) {
|
|
146 mapWaitIcon(waitIcon, queuePos, &motdMapLater);
|
|
147 }
|
|
148 break;
|
|
149 default:
|
|
150 break;
|
|
151 }
|
|
152 }
|
|
153 if (queuePos != oldcount) {
|
|
154 mapWaitCount(countWin, queuePos);
|
|
155 mapWaitIcon(waitIcon, queuePos, NULL);
|
|
156 oldcount = queuePos;
|
|
157 }
|
|
158 if (me != NULL) {
|
|
159 W_DestroyWindow(waitWin);
|
|
160 #ifdef AMIGA
|
|
161 W_DestroyWindow(waitIcon);
|
|
162 #endif
|
|
163 printf("*** socket %d, player %d ( -s %d -G %d [-2] ) ***\n",
|
|
164 nextSocket, me->p_no,
|
|
165 nextSocket, me->p_no);
|
|
166 return (me->p_no);
|
|
167 }
|
|
168 }
|
|
169 }
|
|
170
|
|
171 static void
|
|
172 mapWaitWin(waitWin)
|
|
173 W_Window waitWin;
|
|
174 {
|
|
175 char *s = "Netrek: Game is full.";
|
|
176
|
|
177 W_WriteText(waitWin, 15, 5, textColor, s, strlen(s), W_RegularFont);
|
|
178 }
|
|
179
|
|
180 static void
|
|
181 mapWaitQuit(qwin)
|
|
182 W_Window qwin;
|
|
183 {
|
|
184 char *s = "Quit";
|
|
185
|
|
186 W_WriteText(qwin, 15, 15, textColor, s, strlen(s), W_RegularFont);
|
|
187 }
|
|
188
|
|
189 static void
|
|
190 mapWaitCount(countWin, count)
|
|
191 W_Window countWin;
|
|
192 unsigned int count;
|
|
193 {
|
|
194 char *s = "Wait";
|
|
195 char *t = "Queue";
|
|
196 char buf[10];
|
|
197 register int len;
|
|
198
|
|
199 W_WriteText(countWin, 15, 5, textColor, s, strlen(s), W_RegularFont);
|
|
200 W_WriteText(countWin, 20, 15, textColor, t, strlen(t), W_RegularFont);
|
|
201 sprintf(buf, "%d ", count);
|
|
202 len = strlen(buf);
|
|
203 if (count == -1)
|
|
204 strcpy(buf, "?");
|
|
205 W_WriteText(countWin, WAITWIDTH / 6 - len * W_Textwidth / 2, 25, textColor, buf,
|
|
206 len, W_RegularFont);
|
|
207 }
|
|
208
|
|
209 static void
|
|
210 mapMotdButtonWin(motdButtonWin)
|
|
211 W_Window motdButtonWin;
|
|
212 {
|
|
213 char *s = "MOTD";
|
|
214
|
|
215 W_WriteText(motdButtonWin, 15, 15, textColor, s, strlen(s), W_RegularFont);
|
|
216 }
|
|
217
|
|
218 static void
|
|
219 mapWaitIcon(waitIcon, count, motdMapLater)
|
|
220 W_Window waitIcon;
|
|
221 unsigned int count;
|
|
222 int *motdMapLater;
|
|
223 {
|
|
224 char buf[5];
|
|
225 int len;
|
|
226
|
|
227 sprintf(buf, "%d", count);
|
|
228 len = strlen(buf);
|
|
229 #ifndef AMIGA
|
|
230 if (motdMapLater && W_IsMapped(motdWin)) {
|
|
231 *motdMapLater = 1;
|
|
232 W_UnmapWindow(motdWin);
|
|
233 }
|
|
234 W_WriteText(waitIcon, WAITICONWIDTH / 2 - 10, W_Textheight, textColor, buf, len,
|
|
235 W_BigFont);
|
|
236 #else
|
|
237
|
|
238 W_WriteText(waitIcon, WAITICONWIDTH / 2 - 10, W_Textheight, textColor, buf, len,
|
|
239 W_RegularFont);
|
|
240 /* using the iconWin in place of the 4 separate windows I get otherwise. -JR */
|
|
241 W_WriteText(waitIcon, 0, 0, textColor, serverName, strlen(serverName), W_RegularFont);
|
|
242 W_WriteText(waitIcon, 0, 2 * W_Textheight, textColor, "Q to quit", 9, W_RegularFont);
|
|
243 W_WriteText(waitIcon, 0, 3 * W_Textheight, textColor, "M for Motd", 10, W_RegularFont);
|
|
244 #endif
|
|
245
|
|
246 }
|