mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-11-18 10:08:29 +01:00
7d622f9484
deal with socket dying and (maybe) being replaced. Only connect on demand now, when first packet's ready to go.
118 lines
3.2 KiB
C
118 lines
3.2 KiB
C
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */
|
|
/*
|
|
* Copyright 1997-2000 by Eric House (fixin@peak.org). All rights reserved.
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version 2
|
|
* of the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
*/
|
|
|
|
#ifndef _CURSESMAIN_H_
|
|
#define _CURSESMAIN_H_
|
|
|
|
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <netinet/in.h>
|
|
#include <sys/unistd.h>
|
|
#include <sys/poll.h>
|
|
|
|
#include <ncurses.h>
|
|
|
|
#include "draw.h"
|
|
#include "main.h"
|
|
#include "board.h"
|
|
#include "model.h"
|
|
#include "dictnry.h"
|
|
#include "xwstream.h"
|
|
#include "comms.h"
|
|
#include "server.h"
|
|
#include "xwstate.h"
|
|
#include "util.h"
|
|
/* #include "compipe.h" */
|
|
|
|
typedef struct CursesDrawCtx {
|
|
DrawCtxVTable* vtable;
|
|
|
|
WINDOW* boardWin;
|
|
/* WINDOW* trayWin; */
|
|
|
|
} CursesDrawCtx;
|
|
|
|
typedef struct CursesAppGlobals CursesAppGlobals;
|
|
|
|
typedef XP_Bool (*EventFunc)(CursesAppGlobals* globals, int ch);
|
|
/* typedef void (*MenuDrawer)(CursesAppGlobals* globals); */
|
|
|
|
#define FD_MAX 6
|
|
#define FD_STDIN 0
|
|
#define FD_TIMEEVT 1
|
|
#define FD_FIRSTSOCKET 2
|
|
|
|
struct CursesAppGlobals {
|
|
CommonGlobals cGlobals;
|
|
|
|
CursesDrawCtx* draw;
|
|
|
|
DictionaryCtxt* dictionary;
|
|
EngineCtxt* engine;
|
|
CommonPrefs cp;
|
|
|
|
XP_Bool amServer; /* this process acting as server */
|
|
|
|
WINDOW* mainWin;
|
|
WINDOW* menuWin;
|
|
WINDOW* boardWin;
|
|
|
|
XP_Bool timeToExit;
|
|
XP_Bool doDraw;
|
|
struct MenuList* menuList;
|
|
XP_U16 nLinesMenu;
|
|
|
|
union {
|
|
struct {
|
|
XWStreamCtxt* stream; /* how we can reach the server */
|
|
} client;
|
|
struct {
|
|
int serverSocket;
|
|
XP_Bool socketOpen;
|
|
} server;
|
|
} csInfo;
|
|
|
|
short statusLine;
|
|
XWGameState state;
|
|
|
|
struct sockaddr_in listenerSockAddr;
|
|
short fdCount;
|
|
struct pollfd fdArray[FD_MAX]; /* one for stdio, one for listening socket */
|
|
|
|
int timepipe[2]; /* for reading/writing "user events" */
|
|
};
|
|
|
|
|
|
DrawCtx* cursesDrawCtxtMake( WINDOW* boardWin );
|
|
|
|
/* Ports: Client and server pick a port at startup on which they'll listen.
|
|
* If both are to be on the same device using localhost as their ip address,
|
|
* then they need to be listening on different ports. Server finds out what
|
|
* port client is listening on from the return address of the first message
|
|
* client sends -- I think. (I'm not sure that when I create a socket to use
|
|
* to SEND to the server that I specify the port on which I'm listening.
|
|
* Maybe I need to include that in a platform-specific part of the connect
|
|
* message.... Clearly there will need to be such a thing.
|
|
*/
|
|
|
|
|
|
void cursesmain( XP_Bool isServer, LaunchParams* params );
|
|
|
|
#endif
|