2005-03-19 23:16:49 +01:00
|
|
|
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */
|
|
|
|
/*
|
2009-07-30 14:54:17 +02:00
|
|
|
* Copyright 2005-2009 by Eric House (xwords@eehouse.org). All rights
|
|
|
|
* reserved.
|
2005-03-19 23:16:49 +01: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 18:40:16 +02:00
|
|
|
#ifndef CANT_DO_TYPEDEF
|
2005-09-05 17:50:49 +02:00
|
|
|
typedef
|
2005-10-02 18:40:16 +02:00
|
|
|
#endif
|
2005-09-05 17:50:49 +02:00
|
|
|
enum { XWRELAY_NONE /* 0 is an illegal value */
|
2005-03-19 23:16:49 +01:00
|
|
|
|
2005-09-05 17:50:49 +02:00
|
|
|
, XWRELAY_GAME_CONNECT
|
2005-03-19 23:16:49 +01:00
|
|
|
/* Sent from device to relay to establish connection to relay. Format:
|
2005-10-02 17:39:38 +02:00
|
|
|
flags: 1; cookieLen: 1; cookie: <cookieLen>; hostID: 1; nPlayers: 1;
|
|
|
|
nPlayersTotal: 1 */
|
2005-08-09 01:33:51 +02:00
|
|
|
|
2005-09-05 17:50:49 +02:00
|
|
|
, XWRELAY_GAME_RECONNECT
|
2009-08-21 14:00:09 +02:00
|
|
|
/* Connect using connName as well as cookie. Used by a device that's
|
2005-10-01 18:33:45 +02: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 14:00:09 +02:00
|
|
|
cookieLen: 1; cookie: <cookieLen>; hostID: 1; nPlayers: 1;
|
|
|
|
nPlayersTotal: 1; connNameLen: 1; connName<connNameLen>*/
|
2005-03-19 23:16:49 +01:00
|
|
|
|
2005-09-05 17:50:49 +02:00
|
|
|
, XWRELAY_GAME_DISCONNECT
|
|
|
|
/* 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 18:33:45 +02:00
|
|
|
Format: cookieID: 2; srcID: 1 */
|
2005-09-05 17:50:49 +02:00
|
|
|
|
2005-10-01 18:33:45 +02:00
|
|
|
, XWRELAY_CONNECT_RESP
|
|
|
|
/* Sent from relay to device in response to XWRELAY_CONNECT. Format:
|
2009-09-14 03:55:03 +02:00
|
|
|
heartbeat_seconds: 2; connectionID: 2; connNameLen: 1;
|
|
|
|
connName<connNameLen>*/
|
2005-10-01 18:33:45 +02:00
|
|
|
|
|
|
|
, XWRELAY_RECONNECT_RESP
|
|
|
|
/* Sent from relay to device in response to XWRELAY_RECONNECT. Format:
|
2009-08-21 14:00:09 +02:00
|
|
|
heartbeat_seconds: 2; */
|
2005-08-09 01:33:51 +02:00
|
|
|
|
2005-10-02 17:39:38 +02:00
|
|
|
, XWRELAY_ALLHERE
|
|
|
|
/* 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-09-14 03:55:03 +02:00
|
|
|
Format: hostID: 1; */
|
2005-09-03 20:32:12 +02:00
|
|
|
|
2005-09-03 17:41:17 +02:00
|
|
|
, XWRELAY_DISCONNECT_YOU
|
|
|
|
/* Sent from relay when existing connection is terminated.
|
|
|
|
Format: errorCode: 1 */
|
|
|
|
|
|
|
|
, XWRELAY_DISCONNECT_OTHER
|
|
|
|
/* Another device has left the game.
|
2005-10-01 18:33:45 +02:00
|
|
|
Format: errorCode: 1; lostHostId: 1 */
|
2005-09-03 08:46:03 +02:00
|
|
|
|
2005-07-06 03:36:52 +02:00
|
|
|
, XWRELAY_CONNECTDENIED
|
2005-08-09 01:33:51 +02:00
|
|
|
/* The relay says go away. Format: reason code: 1 */
|
2005-07-06 03:36:52 +02:00
|
|
|
|
2005-03-19 23:16:49 +01:00
|
|
|
, XWRELAY_HEARTBEAT
|
2005-10-01 18:33:45 +02:00
|
|
|
/* Sent in either direction. Format: cookieID: 2; srcID: 1 */
|
2009-02-01 17:20:18 +01:00
|
|
|
|
2005-03-19 23:16:49 +01:00
|
|
|
, XWRELAY_MSG_FROMRELAY
|
2005-10-01 18:33:45 +02:00
|
|
|
/* Sent from relay to device. Format: cookieID: 2; src_hostID: 1;
|
|
|
|
dest_hostID: 1; data <len-headerLen> */
|
2005-03-19 23:16:49 +01:00
|
|
|
|
|
|
|
, XWRELAY_MSG_TORELAY
|
|
|
|
/* Sent from device to relay. Format: connectionID: 2; src_hostID:
|
2005-10-01 18:33:45 +02:00
|
|
|
1; dest_hostID: 1 */
|
2005-10-02 18:40:16 +02:00
|
|
|
}
|
|
|
|
#ifndef CANT_DO_TYPEDEF
|
|
|
|
XWRelayMsg
|
|
|
|
#endif
|
|
|
|
;
|
2005-03-19 23:16:49 +01:00
|
|
|
|
|
|
|
#ifndef CANT_DO_TYPEDEF
|
|
|
|
typedef unsigned char XWRELAY_Cmd;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define HOST_ID_NONE 0
|
|
|
|
#define HOST_ID_SERVER 1
|
|
|
|
|
|
|
|
#define MAX_COOKIE_LEN 15
|
|
|
|
#define MAX_MSG_LEN 256 /* 100 is more like it */
|
2005-10-01 18:33:45 +02:00
|
|
|
#define MAX_CONNNAME_LEN 35 /* host id plus a small integer, typically */
|
2005-03-19 23:16:49 +01:00
|
|
|
|
2005-07-06 03:36:52 +02:00
|
|
|
#define XWRELAY_PROTO_VERSION 0x01
|
|
|
|
|
|
|
|
/* Errors passed with denied */
|
2005-10-02 18:40:16 +02:00
|
|
|
#ifndef CANT_DO_TYPEDEF
|
|
|
|
typedef
|
|
|
|
#endif
|
|
|
|
enum {
|
2005-07-06 03:36:52 +02:00
|
|
|
XWRELAY_ERROR_NONE
|
2005-10-14 10:29:58 +02:00
|
|
|
,XWRELAY_ERROR_OLDFLAGS /* You have the wrong flags */
|
2005-07-06 03:36:52 +02:00
|
|
|
,XWRELAY_ERROR_BADPROTO
|
|
|
|
,XWRELAY_ERROR_RELAYBUSY
|
2005-09-03 08:46:03 +02:00
|
|
|
,XWRELAY_ERROR_SHUTDOWN /* relay's going down */
|
|
|
|
,XWRELAY_ERROR_TIMEOUT /* Other players didn't show */
|
2005-09-03 17:41:17 +02:00
|
|
|
,XWRELAY_ERROR_HEART_YOU /* Haven't heard from somebody in too long */
|
2005-09-04 16:35:13 +02:00
|
|
|
,XWRELAY_ERROR_HEART_OTHER /* Haven't heard from other in too long */
|
|
|
|
,XWRELAY_ERROR_LOST_OTHER /* Generic other-left-we-dunno-why error */
|
2005-07-06 03:36:52 +02:00
|
|
|
|
2005-09-03 08:46:03 +02:00
|
|
|
,XWRELAY_ERROR_LASTERR
|
2005-10-02 18:40:16 +02:00
|
|
|
}
|
|
|
|
#ifndef CANT_DO_TYPEDEF
|
|
|
|
XWREASON
|
|
|
|
#endif
|
|
|
|
;
|
2005-09-04 22:55:07 +02:00
|
|
|
|
2005-10-02 18:40:16 +02:00
|
|
|
#ifndef CANT_DO_TYPEDEF
|
2005-10-01 18:33:45 +02:00
|
|
|
typedef unsigned short CookieID;
|
2005-10-02 18:40:16 +02:00
|
|
|
#endif
|
|
|
|
|
2005-09-04 22:55:07 +02:00
|
|
|
#define COOKIE_ID_NONE 0L
|
|
|
|
|
2005-03-19 23:16:49 +01:00
|
|
|
#endif
|