2005-03-19 22:16:49 +00:00
|
|
|
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */
|
|
|
|
/*
|
2009-07-30 12:54:17 +00:00
|
|
|
* Copyright 2005-2009 by Eric House (xwords@eehouse.org). All rights
|
|
|
|
* reserved.
|
2005-03-19 22:16:49 +00:00
|
|
|
*
|
|
|
|
* 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 _XWRELAY_H_
|
|
|
|
#define _XWRELAY_H_
|
|
|
|
|
|
|
|
/* This file is meant to be included by both linux code that doesn't
|
|
|
|
include xptypes and from Crosswords client code.*/
|
|
|
|
|
|
|
|
/* Set if device is acting a server; cleared if as client */
|
|
|
|
#define FLAGS_SERVER_BIT 0x01
|
|
|
|
|
2005-10-02 16:40:16 +00:00
|
|
|
#ifndef CANT_DO_TYPEDEF
|
2005-09-05 15:50:49 +00:00
|
|
|
typedef
|
2005-10-02 16:40:16 +00:00
|
|
|
#endif
|
2005-09-05 15:50:49 +00:00
|
|
|
enum { XWRELAY_NONE /* 0 is an illegal value */
|
2005-03-19 22:16:49 +00:00
|
|
|
|
2005-09-05 15:50:49 +00:00
|
|
|
, XWRELAY_GAME_CONNECT
|
2005-03-19 22:16:49 +00:00
|
|
|
/* Sent from device to relay to establish connection to relay. Format:
|
2005-10-02 15:39:38 +00:00
|
|
|
flags: 1; cookieLen: 1; cookie: <cookieLen>; hostID: 1; nPlayers: 1;
|
|
|
|
nPlayersTotal: 1 */
|
2005-08-08 23:33:51 +00:00
|
|
|
|
2011-08-16 19:41:33 -07:00
|
|
|
, XWRELAY_GAME_RECONNECT /* 1 */
|
2009-08-21 12:00:09 +00:00
|
|
|
/* Connect using connName as well as cookie. Used by a device that's
|
2005-10-01 16:33:45 +00:00
|
|
|
lost its connection to a game in progress. Once a game is locked
|
|
|
|
this is the only way a host can get (back) in. Format: flags: 1;
|
2009-08-21 12:00:09 +00:00
|
|
|
cookieLen: 1; cookie: <cookieLen>; hostID: 1; nPlayers: 1;
|
|
|
|
nPlayersTotal: 1; connNameLen: 1; connName<connNameLen>*/
|
2005-03-19 22:16:49 +00:00
|
|
|
|
2011-08-16 19:41:33 -07:00
|
|
|
, XWRELAY_ACK /* 2 */
|
2010-09-14 13:54:52 -07:00
|
|
|
|
2011-08-16 19:41:33 -07:00
|
|
|
, XWRELAY_GAME_DISCONNECT /* 3 */
|
2005-09-05 15:50:49 +00:00
|
|
|
/* Tell the relay that we're gone for this game. After this message is
|
|
|
|
sent, the host can reconnect on the same socket for a new game.
|
2005-10-01 16:33:45 +00:00
|
|
|
Format: cookieID: 2; srcID: 1 */
|
2005-09-05 15:50:49 +00:00
|
|
|
|
2011-08-16 19:41:33 -07:00
|
|
|
, XWRELAY_CONNECT_RESP /* 4 */
|
2005-10-01 16:33:45 +00:00
|
|
|
/* Sent from relay to device in response to XWRELAY_CONNECT. Format:
|
2009-11-02 01:01:47 +00:00
|
|
|
heartbeat_seconds: 2; players_here: 1; players_sought: 1; */
|
2005-10-01 16:33:45 +00:00
|
|
|
|
2011-08-16 19:41:33 -07:00
|
|
|
, XWRELAY_RECONNECT_RESP /* 5 */
|
2005-10-01 16:33:45 +00:00
|
|
|
/* Sent from relay to device in response to XWRELAY_RECONNECT. Format:
|
2009-11-02 01:01:47 +00:00
|
|
|
same as for XWRELAY_CONNECT_RESP */
|
2005-08-08 23:33:51 +00:00
|
|
|
|
2011-08-16 19:41:33 -07:00
|
|
|
, XWRELAY_ALLHERE /* 6 */
|
2005-10-02 15:39:38 +00:00
|
|
|
/* Sent from relay when it enters the state where all expected devices
|
|
|
|
are here (at start of new game or after having been gone for a
|
|
|
|
while). Devices should not attempt to forward messages before this
|
|
|
|
message is received or after XWRELAY_DISCONNECT_OTHER is received.
|
2009-11-02 01:01:47 +00:00
|
|
|
Format: hostID: 1; connectionID: 2; connNameLen: 1;
|
|
|
|
connName<connNameLen>; */
|
2005-09-03 18:32:12 +00:00
|
|
|
|
2011-08-16 19:41:33 -07:00
|
|
|
, XWRELAY_ALLBACK__UNUSED /* 7 */
|
2010-10-25 18:06:48 -07:00
|
|
|
/* Like XWRELAY_ALLHERE, but indicates a return to all devices being
|
|
|
|
present rather than the first time that's achieved. Has no real
|
|
|
|
purpose now that the relay does store-and-forward, but at least lets
|
|
|
|
devices tell users everybody's home. */
|
|
|
|
|
2011-08-16 19:41:33 -07:00
|
|
|
, XWRELAY_DISCONNECT_YOU /* 8 */
|
2005-09-03 15:41:17 +00:00
|
|
|
/* Sent from relay when existing connection is terminated.
|
|
|
|
Format: errorCode: 1 */
|
|
|
|
|
2011-08-16 19:41:33 -07:00
|
|
|
, XWRELAY_DISCONNECT_OTHER /* 9 */
|
2005-09-03 15:41:17 +00:00
|
|
|
/* Another device has left the game.
|
2005-10-01 16:33:45 +00:00
|
|
|
Format: errorCode: 1; lostHostId: 1 */
|
2005-09-03 06:46:03 +00:00
|
|
|
|
2011-08-16 19:41:33 -07:00
|
|
|
, XWRELAY_CONNECTDENIED /* 10 */
|
2005-08-08 23:33:51 +00:00
|
|
|
/* The relay says go away. Format: reason code: 1 */
|
2005-07-06 01:36:52 +00:00
|
|
|
|
2011-08-16 19:41:33 -07:00
|
|
|
, XWRELAY_HEARTBEAT /* 11 */
|
2005-10-01 16:33:45 +00:00
|
|
|
/* Sent in either direction. Format: cookieID: 2; srcID: 1 */
|
2009-02-01 16:20:18 +00:00
|
|
|
|
2011-08-16 19:41:33 -07:00
|
|
|
, XWRELAY_MSG_FROMRELAY /* 12 */
|
2005-10-01 16:33:45 +00:00
|
|
|
/* Sent from relay to device. Format: cookieID: 2; src_hostID: 1;
|
|
|
|
dest_hostID: 1; data <len-headerLen> */
|
2005-03-19 22:16:49 +00:00
|
|
|
|
2011-08-16 19:41:33 -07:00
|
|
|
, XWRELAY_MSG_TORELAY /* 13 */
|
2005-03-19 22:16:49 +00:00
|
|
|
/* Sent from device to relay. Format: connectionID: 2; src_hostID:
|
2005-10-01 16:33:45 +00:00
|
|
|
1; dest_hostID: 1 */
|
2010-11-11 06:26:59 -08:00
|
|
|
|
2011-08-16 19:41:33 -07:00
|
|
|
, XWRELAY_MSG_STATUS /* 14 message conveying status of some sort.
|
2010-11-11 06:26:59 -08:00
|
|
|
Format: msgCode: 1; varies after that */
|
2011-08-16 19:41:33 -07:00
|
|
|
, XWRELAY_MSG_TORELAY_NOCONN /* 15 same as above, but no cookieID */
|
|
|
|
, XWRELAY_MSG_FROMRELAY_NOCONN /* 16 same as above, but no cookieID */
|
2005-10-02 16:40:16 +00:00
|
|
|
}
|
|
|
|
#ifndef CANT_DO_TYPEDEF
|
|
|
|
XWRelayMsg
|
|
|
|
#endif
|
|
|
|
;
|
2005-03-19 22:16:49 +00:00
|
|
|
|
|
|
|
#ifndef CANT_DO_TYPEDEF
|
|
|
|
typedef unsigned char XWRELAY_Cmd;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define HOST_ID_NONE 0
|
|
|
|
#define HOST_ID_SERVER 1
|
|
|
|
|
2010-11-03 18:38:43 -07:00
|
|
|
#define MAX_INVITE_LEN 31
|
2011-08-16 19:41:33 -07:00
|
|
|
#define MAX_MSG_LEN 1024 /* Used for proxy too! */
|
2009-09-26 14:37:49 +00:00
|
|
|
#define MAX_CONNNAME_LEN 48 /* host ID, boot time, and seeds as hex? */
|
2005-03-19 22:16:49 +00:00
|
|
|
|
2009-11-02 01:01:47 +00:00
|
|
|
#define XWRELAY_PROTO_VERSION_ORIG 0x01
|
|
|
|
#define XWRELAY_PROTO_VERSION_LATE_NAME 0x02
|
|
|
|
#define XWRELAY_PROTO_VERSION_LATE_COOKIEID 0x03
|
2010-09-10 01:30:40 -07:00
|
|
|
#define XWRELAY_PROTO_VERSION_NOCLIENT 0x04
|
2012-01-26 05:43:54 -08:00
|
|
|
#define XWRELAY_PROTO_VERSION_CLIENTVERS 0x05
|
|
|
|
#define XWRELAY_PROTO_VERSION XWRELAY_PROTO_VERSION_CLIENTVERS
|
2005-07-06 01:36:52 +00:00
|
|
|
|
|
|
|
/* Errors passed with denied */
|
2005-10-02 16:40:16 +00:00
|
|
|
#ifndef CANT_DO_TYPEDEF
|
|
|
|
typedef
|
|
|
|
#endif
|
|
|
|
enum {
|
2005-07-06 01:36:52 +00:00
|
|
|
XWRELAY_ERROR_NONE
|
2005-10-14 08:29:58 +00:00
|
|
|
,XWRELAY_ERROR_OLDFLAGS /* You have the wrong flags */
|
2005-07-06 01:36:52 +00:00
|
|
|
,XWRELAY_ERROR_BADPROTO
|
|
|
|
,XWRELAY_ERROR_RELAYBUSY
|
2005-09-03 06:46:03 +00:00
|
|
|
,XWRELAY_ERROR_SHUTDOWN /* relay's going down */
|
|
|
|
,XWRELAY_ERROR_TIMEOUT /* Other players didn't show */
|
2005-09-03 15:41:17 +00:00
|
|
|
,XWRELAY_ERROR_HEART_YOU /* Haven't heard from somebody in too long */
|
2005-09-04 14:35:13 +00:00
|
|
|
,XWRELAY_ERROR_HEART_OTHER /* Haven't heard from other in too long */
|
|
|
|
,XWRELAY_ERROR_LOST_OTHER /* Generic other-left-we-dunno-why error */
|
2009-09-20 18:47:47 +00:00
|
|
|
,XWRELAY_ERROR_OTHER_DISCON /* The other guy disconnected, maybe to start
|
|
|
|
a new game? */
|
2009-12-04 08:03:27 +00:00
|
|
|
,XWRELAY_ERROR_NO_ROOM
|
|
|
|
,XWRELAY_ERROR_DUP_ROOM
|
2009-12-14 04:10:23 +00:00
|
|
|
,XWRELAY_ERROR_TOO_MANY
|
2010-11-11 06:26:59 -08:00
|
|
|
,XWRELAY_ERROR_DELETED
|
2011-06-23 07:12:50 -07:00
|
|
|
,XWRELAY_ERROR_NORECONN /* you can't reconnect; reset and try CONNECTING again */
|
2011-07-06 06:47:25 -07:00
|
|
|
,XWRELAY_ERROR_DEADGAME /* Some device in this game has been deleted */
|
2005-09-03 06:46:03 +00:00
|
|
|
,XWRELAY_ERROR_LASTERR
|
2005-10-02 16:40:16 +00:00
|
|
|
}
|
|
|
|
#ifndef CANT_DO_TYPEDEF
|
|
|
|
XWREASON
|
|
|
|
#endif
|
|
|
|
;
|
2005-09-04 20:55:07 +00:00
|
|
|
|
2010-09-20 04:59:09 -07:00
|
|
|
#ifndef CANT_DO_TYPEDEF
|
|
|
|
typedef
|
|
|
|
#endif
|
2010-09-20 18:31:17 -07:00
|
|
|
enum { PRX_NONE /* 0 is an illegal value */
|
2010-09-21 18:28:31 -07:00
|
|
|
,PRX_PUB_ROOMS /* list all public rooms for lang/nPlayers */
|
|
|
|
,PRX_HAS_MSGS /* return message counts for connName/devid array */
|
2010-11-11 06:26:59 -08:00
|
|
|
,PRX_DEVICE_GONE /* return message counts for connName/devid array */
|
2011-01-22 12:52:26 -08:00
|
|
|
,PRX_GET_MSGS /* return full messages for connName/devid array */
|
2011-08-16 19:41:33 -07:00
|
|
|
,PRX_PUT_MSGS /* incoming set of messages with connName/devid header */
|
2010-09-20 04:59:09 -07:00
|
|
|
}
|
|
|
|
#ifndef CANT_DO_TYPEDEF
|
|
|
|
XWPRXYCMD
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
|
2005-10-02 16:40:16 +00:00
|
|
|
#ifndef CANT_DO_TYPEDEF
|
2005-10-01 16:33:45 +00:00
|
|
|
typedef unsigned short CookieID;
|
2005-10-02 16:40:16 +00:00
|
|
|
#endif
|
|
|
|
|
2011-08-16 19:41:33 -07:00
|
|
|
#define COOKIE_ID_NONE 0
|
2005-09-04 20:55:07 +00:00
|
|
|
|
2005-03-19 22:16:49 +00:00
|
|
|
#endif
|