diff findslot.c @ 3:5a977ccbc7a9 default tip

Empty changelog
author darius
date Sat, 06 Dec 1997 05:41:29 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/findslot.c	Sat Dec 06 05:41:29 1997 +0000
@@ -0,0 +1,246 @@
+/* $Id: findslot.c,v 1.1.1.1 1997/12/06 05:41:29 darius Exp $ */
+
+/*
+ * findslot.c
+ *
+ * Kevin Smith 03/23/88
+ *
+ */
+#include "copyright2.h"
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <pwd.h>
+#include <string.h>
+#include <ctype.h>
+#ifdef __STDC__
+#include <stdlib.h>
+#endif
+#include "Wlib.h"
+#include "defs.h"
+#include "struct.h"
+#include "data.h"
+#include "proto.h"
+
+#define WAITWIDTH 180
+#define WAITHEIGHT 60
+#define WAITTITLE 15		/* height of title for wait window */
+#define WAITICONHEIGHT 50
+#define WAITICONWIDTH  50
+
+/* Prototypes */
+static void mapWaitCount P((W_Window countWin, unsigned int count));
+static void mapWaitQuit P((W_Window qwin));
+static void mapWaitWin P((W_Window waitWin));
+static void mapMotdButtonWin P((W_Window motdButtonWin));
+static void mapWaitIcon 
+P((W_Window waitIcon, unsigned int count,
+   int *motdMapLater));
+
+    extern int newMotdStuff;	/* from newwin.c */
+
+
+    int     findslot()
+{
+    int     oldcount = -1;
+    W_Window waitWin, qwin, countWin, motdButtonWin, waitIcon;
+    W_Event event;
+    int     motdMapLater = 0;
+
+    /* Wait for some kind of indication about in/not in */
+    while (queuePos == -1) {
+	socketPause(1, 0);
+	if (isServerDead()) {
+	    printf("Augh!  Ghostbusted!\n");
+	    EXIT(0);
+	}
+	readFromServer();
+	if (me != NULL) {
+	    /* We are in! */
+	    printf("*** socket %d, player %d ( -s %d -G %d [-2] ) ***\n",
+		   nextSocket, me->p_no,
+		   nextSocket, me->p_no);
+	    return (me->p_no);
+	}
+    }
+
+    /* We have to wait.  Make appropriate windows, etc... */
+    waitWin = W_MakeWindow("wait", 0, 0, WAITWIDTH, WAITHEIGHT, NULL, (char *) 0, 2, foreColor);
+    countWin = W_MakeWindow("count", WAITWIDTH / 3, WAITTITLE, 2 * WAITWIDTH / 3,
+		 WAITHEIGHT - WAITTITLE, waitWin, (char *) 0, 1, foreColor);
+    qwin = W_MakeWindow("waitquit", 0, WAITTITLE, WAITWIDTH / 3,
+		 WAITHEIGHT - WAITTITLE, waitWin, (char *) 0, 1, foreColor);
+    motdButtonWin = W_MakeWindow("motd_select", 2 * WAITWIDTH / 3, WAITTITLE,
+      WAITWIDTH, WAITHEIGHT - WAITTITLE, waitWin, (char *) 0, 1, foreColor);
+    waitIcon = W_MakeWindow("wait_icon", 0, 0, WAITICONWIDTH, WAITICONHEIGHT,
+			    NULL, NULL, BORDER, foreColor);
+    W_SetIconWindow(waitWin, waitIcon);
+    /* showMotdWin(); */
+#ifndef AMIGA
+    W_MapWindow(waitWin);
+    W_MapWindow(countWin);
+    W_MapWindow(qwin);
+    W_MapWindow(motdButtonWin);
+#else
+    W_MapWindow(waitIcon);
+#endif
+    for (;;) {
+	socketPause(0, 10000);
+	readFromServer();
+	if (isServerDead()) {
+	    printf("We've been ghostbusted!\n");
+	    EXIT(0);
+	}
+	if (newMotdStuff)
+	    showMotd(motdWin);
+	while (W_EventsPending()) {
+	    W_NextEvent(&event);
+	    switch ((int) event.type) {
+	    case W_EV_KEY:
+		if (event.Window == motdWin) {
+		    motdWinEvent(event.key);
+		}
+#ifdef AMIGA
+		else if (event.Window == waitIcon) {
+		    switch (event.key) {
+		    case 'q':
+		    case 'Q':
+			printf("OK, bye!\n");
+			EXIT(0);
+		    case 'm':
+		    case 'M':
+			showMotdWin();
+			break;
+		    default:
+			break;
+		    }
+		}
+#endif
+	    case W_EV_BUTTON:	/* fall through */
+		if (event.Window == qwin) {
+		    printf("OK, bye!\n");
+		    EXIT(0);
+		} else if (event.Window == motdButtonWin) {
+		    showMotdWin();
+		} else if (event.Window == waitIcon) {
+		    mapWaitIcon(waitIcon, queuePos, NULL);
+		}
+		break;
+	    case W_EV_EXPOSE:
+		if (event.Window == waitWin) {
+		    if (motdMapLater) {
+			showMotd(motdWin);
+			motdMapLater = 0;
+		    }
+		    mapWaitWin(waitWin);
+		} else if (event.Window == qwin) {
+		    mapWaitQuit(qwin);
+		} else if (event.Window == countWin) {
+		    mapWaitCount(countWin, queuePos);
+		} else if (event.Window == motdWin) {
+		    showMotd(motdWin);
+		} else if (event.Window == motdButtonWin) {
+		    mapMotdButtonWin(motdButtonWin);
+		} else if (event.Window == waitIcon) {
+		    mapWaitIcon(waitIcon, queuePos, &motdMapLater);
+		}
+		break;
+	    default:
+		break;
+	    }
+	}
+	if (queuePos != oldcount) {
+	    mapWaitCount(countWin, queuePos);
+	    mapWaitIcon(waitIcon, queuePos, NULL);
+	    oldcount = queuePos;
+	}
+	if (me != NULL) {
+	    W_DestroyWindow(waitWin);
+#ifdef AMIGA
+	    W_DestroyWindow(waitIcon);
+#endif
+	    printf("*** socket %d, player %d ( -s %d -G %d [-2] ) ***\n",
+		   nextSocket, me->p_no,
+		   nextSocket, me->p_no);
+	    return (me->p_no);
+	}
+    }
+}
+
+static void
+mapWaitWin(waitWin)
+    W_Window waitWin;
+{
+    char   *s = "Netrek: Game is full.";
+
+    W_WriteText(waitWin, 15, 5, textColor, s, strlen(s), W_RegularFont);
+}
+
+static void
+mapWaitQuit(qwin)
+    W_Window qwin;
+{
+    char   *s = "Quit";
+
+    W_WriteText(qwin, 15, 15, textColor, s, strlen(s), W_RegularFont);
+}
+
+static void
+mapWaitCount(countWin, count)
+    W_Window countWin;
+    unsigned int count;
+{
+    char   *s = "Wait";
+    char   *t = "Queue";
+    char    buf[10];
+    register int len;
+
+    W_WriteText(countWin, 15, 5, textColor, s, strlen(s), W_RegularFont);
+    W_WriteText(countWin, 20, 15, textColor, t, strlen(t), W_RegularFont);
+    sprintf(buf, "%d    ", count);
+    len = strlen(buf);
+    if (count == -1)
+	strcpy(buf, "?");
+    W_WriteText(countWin, WAITWIDTH / 6 - len * W_Textwidth / 2, 25, textColor, buf,
+		len, W_RegularFont);
+}
+
+static void
+mapMotdButtonWin(motdButtonWin)
+    W_Window motdButtonWin;
+{
+    char   *s = "MOTD";
+
+    W_WriteText(motdButtonWin, 15, 15, textColor, s, strlen(s), W_RegularFont);
+}
+
+static void
+mapWaitIcon(waitIcon, count, motdMapLater)
+    W_Window waitIcon;
+    unsigned int count;
+    int    *motdMapLater;
+{
+    char    buf[5];
+    int     len;
+
+    sprintf(buf, "%d", count);
+    len = strlen(buf);
+#ifndef AMIGA
+    if (motdMapLater && W_IsMapped(motdWin)) {
+	*motdMapLater = 1;
+	W_UnmapWindow(motdWin);
+    }
+    W_WriteText(waitIcon, WAITICONWIDTH / 2 - 10, W_Textheight, textColor, buf, len,
+		W_BigFont);
+#else
+
+    W_WriteText(waitIcon, WAITICONWIDTH / 2 - 10, W_Textheight, textColor, buf, len,
+		W_RegularFont);
+/* using the iconWin in place of the 4 separate windows I get otherwise. -JR */
+    W_WriteText(waitIcon, 0, 0, textColor, serverName, strlen(serverName), W_RegularFont);
+    W_WriteText(waitIcon, 0, 2 * W_Textheight, textColor, "Q to quit", 9, W_RegularFont);
+    W_WriteText(waitIcon, 0, 3 * W_Textheight, textColor, "M for Motd", 10, W_RegularFont);
+#endif
+
+}