home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / volume14 / okbrdge2 / part13 < prev    next >
Encoding:
Internet Message Format  |  1993-01-26  |  56.0 KB

  1. Path: uunet!zephyr.ens.tek.com!master!saab!billr
  2. From: billr@saab.CNA.TEK.COM (Bill Randle)
  3. Newsgroups: comp.sources.games
  4. Subject: v14i091:  okbridge2 - computer-mediated bridge game, Part13/14
  5. Message-ID: <3530@master.CNA.TEK.COM>
  6. Date: 7 Sep 92 21:43:17 GMT
  7. Sender: news@master.CNA.TEK.COM
  8. Lines: 1733
  9. Approved: billr@saab.CNA.TEK.COM
  10.  
  11. Submitted-by: mclegg@cs.UCSD.EDU (Matthew Clegg)
  12. Posting-number: Volume 14, Issue 91
  13. Archive-name: okbridge2/Part13
  14. Supersedes: okbridge: Volume 13, Issue 16-22
  15. Environment: BSD-derived Unix, NeXT, curses, sockets
  16.  
  17.  
  18.  
  19. #! /bin/sh
  20. # This is a shell archive.  Remove anything before this line, then unpack
  21. # it by saving it into a file and typing "sh file".  To overwrite existing
  22. # files, type "sh file -c".  You can also feed this as standard input via
  23. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  24. # will see the following message at the end:
  25. #        "End of archive 13 (of 14)."
  26. # Contents:  gps.h gps_info.h input.h okbridgerc okshuffle.c scoring.h
  27. #   socket.c socket.h state.h terminal.c terminal.h
  28. # Wrapped by billr@saab on Mon Sep  7 14:33:38 1992
  29. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  30. if test -f 'gps.h' -a "${1}" != "-c" ; then 
  31.   echo shar: Will not clobber existing file \"'gps.h'\"
  32. else
  33. echo shar: Extracting \"'gps.h'\" \(4847 characters\)
  34. sed "s/^X//" >'gps.h' <<'END_OF_FILE'
  35. X/* GPS_client.h -- global playing service, client interface.
  36. X
  37. X   Copyright (C) 1990-1992 by Matthew Clegg.  All Rights Reserved
  38. X
  39. X   OKbridge is made available as a free service to the Internet.
  40. X   Accordingly, the following restrictions are placed on its use:
  41. X
  42. X   1.  OKbridge may not be modified in any way without the explicit 
  43. X       permission of Matthew Clegg.  
  44. X
  45. X   2.  OKbridge may not be used in any way for commercial advantage.
  46. X       It may not be placed on for-profit networks or on for-profit
  47. X       computer systems.  It may not be bundled as part of a package
  48. X       or service provided by a for-profit organization.
  49. X
  50. X   If you have questions about restrictions on the use of OKbridge,
  51. X   write to mclegg@cs.ucsd.edu.
  52. X
  53. X   DISCLAIMER:  The user of OKbridge accepts full responsibility for any
  54. X   damage which may be caused by OKbridge.
  55. X
  56. X
  57. X   The global playing service is a global database of player information.
  58. X   In the initial implementation, it will contain only information
  59. X   about currently playing tables.  At a later date, we will add
  60. X   capabilities for downloading sets of boards and playing competitively.
  61. X
  62. X   Unfortunately, this module is not re-entrant.  This can be a bit of a
  63. X   pain since the GPS_read_line procedure calls Wait_for_input in
  64. X   input.c, which in turn calls Wait_for_event in network.c.
  65. X*/
  66. X
  67. X#ifdef GPS
  68. X
  69. X  int Use_GPS = 1;      
  70. X    /* A boolean flag indicating that we will provide information about 
  71. X       our table to the GPS. */
  72. X
  73. X  int GPS_unavailable = 0;  
  74. X    /* A boolean flag indicating that an error occurred last time we tried
  75. X       to access the GPS. */
  76. X
  77. X  int GPS_socket = 0;
  78. X    /* If nonzero, the socket descriptor of our currently open connection. */
  79. X
  80. X  int GPS_request_in_progress = 0;
  81. X    /* A boolean flag which indicates that a GPS operation is currently
  82. X       being serviced.  This flag is used by the network module when
  83. X       setting up the select flags and also to detect if we experienced 
  84. X       a reset during our last request. */
  85. X
  86. X#else
  87. X
  88. X  extern int Use_GPS, GPS_unavailable, GPS_socket, GPS_request_in_progress;
  89. X
  90. X#endif
  91. X
  92. X
  93. Xvoid GPS_Get_Message_of_the_Day ();
  94. X/* void GPS_Get_Message_of_the_Day (); */
  95. X/* Contacts the GPS and prints out the "message of the day". */
  96. X
  97. Xint GPS_Get_Server_IP ();
  98. X/* int GPS_Get_Server_IP (char *server_name, char *location, int *port); */
  99. X/* Searches the list of currently playing tables for a server whose name
  100. X   matches server_name.  If one is found, then copies the corresponding
  101. X   location and port to the buffers provided by the caller, and returns 0.
  102. X   If no match is found, returns 0.
  103. X*/
  104. X
  105. Xvoid GPS_Broadcast_Server ();
  106. X/* void Broadcast_Server (void); */
  107. X/* Sends a message to the global player service notifying it that we
  108. X   are serving a table.  Sends the names of each of the players at the
  109. X   table in the message.
  110. X*/
  111. X
  112. Xvoid GPS_Broadcast_Server_Silently ();
  113. X/* Same as GPS_Broadcast_Server but does not print an error message if
  114. X   we are not using the GPS or if the GPS was found to be unavailable
  115. X   in a previous call.
  116. X*/
  117. X
  118. Xvoid GPS_Advertise_Message ();
  119. X/* void GPS_Advertise_Message (char *message); */
  120. X/* If we are in server mode, then displays the given message along with
  121. X   our table announcement in the tables display. */
  122. X
  123. Xvoid GPS_List_Tables ();
  124. X/* void GPS_List_Tables (void); */
  125. X/* Contacts the GPS for a list of the currently playing tables.
  126. X   Lists the tables at the terminal.
  127. X*/
  128. X
  129. Xvoid GPS_List_Players ();
  130. X/* void GPS_List_Players (char *server); */
  131. X/* Lists the players at the given table. */
  132. X
  133. Xvoid GPS_End_Server_Mode ();
  134. X/* void GPS_End_Server_Mode (); */
  135. X/* Informs the GPS that we are no longer serving a table. */
  136. X
  137. Xvoid GPS_Reset ();
  138. X/* void GPS_Reset (); */
  139. X/* Resets the state of our GPS connection. */
  140. X
  141. Xvoid GPS_Directory ();
  142. X/* void GPS_Directory (void); */
  143. X/* Returns a listing of the email duplicate files which are available. */
  144. X
  145. Xvoid GPS_Download ();
  146. X/* void GPS_Download (char *download_file); */
  147. X/* Downloads the specified file from the global player service. */
  148. X
  149. Xvoid GPS_Dup ();
  150. X/* void GPS_Dup (int scoring_mode); */
  151. X/* Initiates gps duplicate mode.  Scoring mode should be either 
  152. X * MP_SCORING or IMP_SCORING.
  153. X */
  154. X
  155. XBoard *GPS_Get_Next_Board ();
  156. X/* void GPS_Get_Next_Board (void); */
  157. X/* Downloads the next duplicate board from the GPS. */
  158. X
  159. Xvoid GPS_Upload_Play_Record ();
  160. X/* void GPS_Upload_Play_Record (Play_record *p); */
  161. X/* Uploads the play record p for the current email board to the GPS. */
  162. X
  163. XBoard *GPS_Download_Results ();
  164. X/* Board *GPS_Download_Results (char *player_name); */
  165. X/* Downloads the all of the recorded results in the GPS for the given 
  166. X * player.  Returns a list of boards or NULL if no results are available.
  167. X */
  168. X
  169. Xvoid GPS_Send_Playing_Time ();
  170. X/* void  GPS_Send_Playing_Time (long seconds); */
  171. X/* Sends the playing time for the local player in seconds to the GPS. */
  172. END_OF_FILE
  173. if test 4847 -ne `wc -c <'gps.h'`; then
  174.     echo shar: \"'gps.h'\" unpacked with wrong size!
  175. fi
  176. # end of 'gps.h'
  177. fi
  178. if test -f 'gps_info.h' -a "${1}" != "-c" ; then 
  179.   echo shar: Will not clobber existing file \"'gps_info.h'\"
  180. else
  181. echo shar: Extracting \"'gps_info.h'\" \(1478 characters\)
  182. sed "s/^X//" >'gps_info.h' <<'END_OF_FILE'
  183. X/* GPS_info.h -- Information about the global playing service.
  184. X * 
  185. X ! Copyright (C) 1990-1992 by Matthew Clegg.  All Rights Reserved
  186. X ! 
  187. X ! OKbridge is made available as a free service to the Internet.
  188. X ! Accordingly, the following restrictions are placed on its use:
  189. X ! 
  190. X ! 1.  OKbridge may not be modified in any way without the explicit 
  191. X !     permission of Matthew Clegg.  
  192. X ! 
  193. X ! 2.  OKbridge may not be used in any way for commercial advantage.
  194. X !     It may not be placed on for-profit networks or on for-profit
  195. X !     computer systems.  It may not be bundled as part of a package
  196. X !     or service provided by a for-profit organization.
  197. X ! 
  198. X ! If you have questions about restrictions on the use of OKbridge,
  199. X ! write to mclegg@cs.ucsd.edu.
  200. X ! 
  201. X ! DISCLAIMER:  The user of OKbridge accepts full responsibility for any
  202. X ! damage which may be caused by OKbridge.
  203. X *
  204. X * This module defines common information which is used by both
  205. X * the client and the server side of the global playing service.
  206. X *
  207. X */
  208. X
  209. X#define GPS_REQUEST_MARKER    "-EOR-"
  210. X#define GPS_RESPONSE_MARKER   "-EOF-"
  211. X
  212. X#ifdef GPS
  213. X
  214. X/*char *GPS_IP  = "reciprocity"; */
  215. X  char *GPS_IP  = "132.239.51.7";
  216. X    /* The IP name or number where the GPS server is believed to reside. */
  217. X
  218. X  int  GPS_port = 2001;
  219. X    /* The port number of the GPS server. */
  220. X
  221. X  char *GPS_version = "1.1";
  222. X    /* The current GPS version number. */
  223. X
  224. X#else
  225. X
  226. X  extern char *GPS_IP;
  227. X  extern int  GPS_port;
  228. X  extern char *GPS_version;
  229. X
  230. X#endif
  231. END_OF_FILE
  232. if test 1478 -ne `wc -c <'gps_info.h'`; then
  233.     echo shar: \"'gps_info.h'\" unpacked with wrong size!
  234. fi
  235. # end of 'gps_info.h'
  236. fi
  237. if test -f 'input.h' -a "${1}" != "-c" ; then 
  238.   echo shar: Will not clobber existing file \"'input.h'\"
  239. else
  240. echo shar: Extracting \"'input.h'\" \(6194 characters\)
  241. sed "s/^X//" >'input.h' <<'END_OF_FILE'
  242. X/* input.h -- interface for input module of bridge game.
  243. X *
  244. X ! Copyright (C) 1990-1992 by Matthew Clegg.  All Rights Reserved
  245. X ! 
  246. X ! OKbridge is made available as a free service to the Internet.
  247. X ! Accordingly, the following restrictions are placed on its use:
  248. X ! 
  249. X ! 1.  OKbridge may not be modified in any way without the explicit 
  250. X !     permission of Matthew Clegg.  
  251. X ! 
  252. X ! 2.  OKbridge may not be used in any way for commercial advantage.
  253. X !     It may not be placed on for-profit networks or on for-profit
  254. X !     computer systems.  It may not be bundled as part of a package
  255. X !     or service provided by a for-profit organization.
  256. X ! 
  257. X ! If you have questions about restrictions on the use of OKbridge,
  258. X ! write to mclegg@cs.ucsd.edu.
  259. X ! 
  260. X ! DISCLAIMER:  The user of OKbridge accepts full responsibility for any
  261. X ! damage which may be caused by OKbridge.
  262. X *
  263. X * This file defines the routines for handling the player-input
  264. X * in the bridge game.
  265. X *
  266. X */
  267. X
  268. X/* The input module handles keyboard input.  This includes reading
  269. X * characters from the keyboard, assembling them into buffers, and
  270. X * creating messages from completed input requests.
  271. X *
  272. X * There are three input buffers, called the talk buffer, the play
  273. X * buffer and the query buffer.  The talk buffer gathers characters
  274. X * for talk messages which will be transmitted to the other players.
  275. X * The play buffer gathers bids and plays which will be transmitted
  276. X * to the others.  And the query buffer gathers responses to yes/no
  277. X * questions which may be asked at times.
  278. X *
  279. X * At any given time, one or more of the input buffers will be "active".
  280. X * This means that characters can be added to the buffer.  There will
  281. X * always be exactly one buffer which is "in focus".  This is the buffer
  282. X * in which the next character will be placed.  Characters can be
  283. X * erased from a buffer by pressing backspace or delete.  The entire
  284. X * contents of a buffer can be erased by pressing escape (see Note).  A 
  285. X * buffer will be processed when return is pressed.  And one can switch
  286. X * between buffers by pressing return.  In addition, the following
  287. X * characters have special meaning:
  288. X *
  289. X * ^A   Alerts partner's last bid.
  290. X * ^B   When used during the play of a hand, the bidding is displayed
  291. X *      for review.
  292. X * ^C   Quits the program.  (The program requests confirmation first.)
  293. X * ^D   Toggles the default input mode.  See the /DEFAULT command.
  294. X * ^G   Toggles the bell.  See the /BELL command.
  295. X * ^P   Toggles the prompt.  See the /PROMPT command.
  296. X * ^R   Refreshes the screen.
  297. X * ^T   Returns to talk mode if you have been asked to bid or play.
  298. X * ^W   Sends a wakeup signal to your partner.
  299. X * ^X   Exits the program immediately (only if compiled in debug mode).
  300. X *
  301. X * Note:  The escape key actually has a dual meaning.  During normal input,
  302. X * it will cause the buffer which is in focus to be erased.  But during
  303. X * pause mode, it signals the program that the pause is over.
  304. X *
  305. X * The input processor may be placed in the following modes:
  306. X *
  307. X * TALK_INPUT:  Only the talk buffer is active.
  308. X * BID_INPUT:   The talk and play buffers are active.  When return is
  309. X *  pressed in the play buffer, the text is interpreted as a bid which
  310. X *  if legal is transmitted to the other players.
  311. X * PLAY_INPUT:  The talk and play buffers are active.  When return is
  312. X *  pressed in the play buffer, the text is interpreted as a play which
  313. X *  if legal is transmitted to the other players.
  314. X * QUERY_INPUT: The talk and query buffers are active.  When return is
  315. X *  is pressed in the query buffer, the text is interpreted as a yes/no
  316. X *  answer.
  317. X *
  318. X * If the input text in the talk or play buffer begins with a slash '/',
  319. X * then it is interpreted as a command.  Commands all begin with a
  320. X * keyword and may be followed by one or more parameters, separated
  321. X * by spaces.  For a list of the available commands, see the "command"
  322. X * module.
  323. X */
  324. X
  325. X#define TALK_INPUT    0
  326. X#define BID_INPUT     1
  327. X#define PLAY_INPUT    2
  328. X#define QUERY_INPUT   3
  329. X
  330. X#ifdef _INPUT_
  331. X  int input_mode = TALK_INPUT;  /* The current input mode, as defined above. */
  332. X#else
  333. X  extern int input_mode;
  334. X#endif
  335. X
  336. X
  337. Xvoid Initialize_Input ();
  338. X/* This routine should be called once when the program first begins,
  339. X * in order to set up the input buffers correctly.
  340. X */
  341. X
  342. Xvoid Reinitialize_Input ();
  343. X/* Clears all of the input buffers. */
  344. X
  345. Xvoid Set_Input_Mode ();
  346. X/* Sets the input mode to the given mode.  Redisplays the talk and
  347. X * query buffers, if appropriate.  If the new mode is BID_INPUT (resp.
  348. X * PLAY_INPUT), the set of legal bids (resp. plays) is computed and
  349. X * the default bid (play) is also computed.
  350. X */
  351. X
  352. Xvoid Refresh_Input_Buffers ();
  353. X/* Redisplays any input which may be present in the input buffers.
  354. X * Places the cursor at the end of the current input buffer.
  355. X */
  356. X
  357. Xvoid Clear_Focus_Buffer ();
  358. X/* Clears the focus buffer and places the cursor at the beginning of
  359. X * the line.
  360. X */
  361. X
  362. Xint Talking ();
  363. X/* Returns TRUE if the focus is currently on the talk buffer. */
  364. X
  365. Xvoid Compute_Default_Play ();
  366. X/* Computes the default play for the local player, based upon the informaion
  367. X * contained in Local_board and Local_play. 
  368. X */
  369. X
  370. Xvoid Clear_Default_Play ();
  371. X/* Clears a default play which may have been set earlier. */
  372. X
  373. Xvoid Accept_Keyboard_Characters ();
  374. X/* If any keyboard characters are available, then reads them and adds
  375. X * them to the current focus buffer.  This may result in a change of
  376. X * state of the program or in messages being transmitted to the other
  377. X * players.
  378. X */
  379. X
  380. Xvoid Pause ();
  381. X/* Displays the given message on the status line, and waits for the
  382. X * user to press the escape key.  Returns after escape has been pressed.
  383. X */
  384. X
  385. Xint  Ask ();
  386. X/* Presents the question to the player and asks for a response.
  387. X * Returns 1 if 'y' was entered and '0' otherwise.
  388. X */
  389. X
  390. Xvoid Press_Return_to_Continue ();
  391. X/* Prints the message on the status line and then waits for the user
  392. X   to press return.
  393. X */
  394. X
  395. Xint Reserved_message ();
  396. X/* Compares the given message to the list of card and bid names.  If a
  397. X   match is found, then returns true.  Otherwise, returns false.
  398. X   The purpose of this routine is to discourage players from sending
  399. X   talk messages which reveal intended bids or plays.
  400. X*/
  401. END_OF_FILE
  402. if test 6194 -ne `wc -c <'input.h'`; then
  403.     echo shar: \"'input.h'\" unpacked with wrong size!
  404. fi
  405. # end of 'input.h'
  406. fi
  407. if test -f 'okbridgerc' -a "${1}" != "-c" ; then 
  408.   echo shar: Will not clobber existing file \"'okbridgerc'\"
  409. else
  410. echo shar: Extracting \"'okbridgerc'\" \(6117 characters\)
  411. sed "s/^X//" >'okbridgerc' <<'END_OF_FILE'
  412. X# .okbridgerc
  413. X# 
  414. X# This is an example startup file for the okbridge program.
  415. X# When okbridge first starts up, it searches for the .okbridgerc
  416. X# startup file.  The current working directory is first searched,
  417. X# and if this fails, then the home directory is searched.
  418. X#
  419. X# Comment lines in the .okbridgerc file begin with a pound sign '#'.
  420. X# Noncomment lines contain a keyword and a value associated to that
  421. X# keyword.  The possible keyword, value pairs are described below.
  422. X#
  423. X
  424. X# AUTOSAVE      ON | OFF
  425. X#     Specifies that we will save the options specified by the user
  426. X#    during play of the program to the file .okdefaults after the
  427. X#    program terminates.
  428. X#
  429. X# AUTOSAVE OFF
  430. X
  431. X# BELL        ON | OFF
  432. X#    When requesting input (a bid or a play), the terminal's
  433. X#    bell is rung by default.  However, this can be disabled
  434. X#    by specifying 'BELL OFF'.  This has the same effect as the
  435. X#    '/BELL OFF' command.
  436. X# BELL OFF
  437. X
  438. X# CC           <convention-card>
  439. X#      This is a one line description of the conventions which you
  440. X#      like to use. 
  441. X#
  442. X# CC SA 5cm 1NT:15-17 Wk2 Stm Ger RKC !Jac
  443. X
  444. X# CCDEF        <card-name> <convention-card>
  445. X#      Used to specify a set of named convention cards.  These cards
  446. X#      can then be called up using the /SETCC <card-name> command.
  447. X#
  448. X# CCDEF basic   SA  5cm 1NT:15-7 Wk2 Stm Ger RKC
  449. X# CCDEF simple SA 5cm 1NT:15-7 Wk2 Stm Ger RKC -X4D Mic/2nu!11-15 Inv
  450. X# CCDEF fancy   SA+ 5cm 1NT:16-8 Wk2 Stm Jac Ger !RKC NegX-3S Mic/Unu!11-15
  451. X# CCDEF klingon 3H bids are wild
  452. X# CC simple
  453. X
  454. X#  DEFAULT         ON | OFF
  455. X#       This controls whether or not default inputs will be provided
  456. X#       for bids, plays and questions.
  457. X#  DEFAULT OFF
  458. X
  459. X# EMAIL        <email-address>
  460. X#      This should be your email address.  It is currently used only for
  461. X#      identification purposes.
  462. X#
  463. X# EMAIL mclegg@cs.ucsd.edu
  464. X
  465. X# ESCKEY       <decimal-key-code>
  466. X#      Specifies the key which will be recognized when the program
  467. X#      presents the message "PRESS <ESC> TO CONTINUE."  This should
  468. X#      be a decimal number representing the key code.  If your terminal
  469. X#      does not have an ESC key, then a recommended setting is the
  470. X#      TAB key (code 9).  The RETURN key has code 10, and the ESC
  471. X#      key (the default) has code 27.
  472. X
  473. X# FULLNAME     <your-full-name>
  474. X#      This field is used only for identification purposes, and should
  475. X#      contain your full name as you would wish it to be displayed to others.
  476. X#
  477. X# FULLNAME  Matthew Clegg, University of California
  478. X
  479. X# GPS           ON | OFF
  480. X#    Controls whether or not we will contact the Global Player Service
  481. X#       automatically when the program starts up.
  482. X#
  483. X# GPS OFF
  484. X
  485. X# GPS_IP    <ip-name-or-number-of-GPS> [<GPS-port>]
  486. X#    Specifies the Internet name or number of the GPS
  487. X#
  488. X# GPS_IP 132.239.51.7 2001
  489. X
  490. X# HELPFILE    <directory-name>
  491. X#   This field specifies the location of the okbridge help file.
  492. X#
  493. X# HELPFILE /usr/local/games/okbridge.help
  494. X#   LOG        <filename>
  495. X#    If this statement is present in the startup file, then
  496. X#    the hands will automatically be logged to the given filename.
  497. X#
  498. XLOG okbridge.log
  499. X
  500. X# MY_IP        <local-IP-name-number>
  501. X#      This field specifies the IP number of the local player.
  502. X#      Usually, this okbridge can determine the IP number correctly
  503. X#      a call to gethostbyname(), but on some systems, this will
  504. X#      not give correct results.
  505. X#
  506. X# MY_IP         132.239.51.6
  507. X
  508. X#  NAME        <local-player-name>
  509. X#    This field specifies the name that will be used to identify
  510. X#    the local player to the other players.
  511. X#
  512. X# NAME matt
  513. X
  514. X#  PORT        <positive-integer>
  515. X#    This field specifies the internet port number that will be
  516. X#    used for communications with the server.
  517. X#
  518. X# PORT 1122
  519. X
  520. X#  PROMPT     OFF | ON
  521. X#    The value of this field is only relevant in hands where the
  522. X#    local player is the dummy.  In this case, the dummy is
  523. X#    ordinarily prompted to press RETURN at the end of each trick.
  524. X#    This allows the dummy to see the cards that are played as they
  525. X#    are played.  However, if 'PROMPT NO' is specified, then the
  526. X#    dummy will not be prompted.
  527. X# PROMPT OFF
  528. X
  529. X#  SCORING    RUBBER | DUPLICATE | MP | IMP
  530. X#    This field is only relevant if the local player is north.
  531. X#    In this case, the SCORING field determines the type of scoring
  532. X#    that will be used by default in the game.
  533. X# SCORING MP
  534. X
  535. X#  SEAT     NORTH | EAST | SOUTH | WEST | OBS
  536. X#    This field specifies the local player's position.
  537. X#
  538. XSEAT north
  539. X
  540. X#  SERVER    ME | <internet-name-or-number>
  541. X#    If the value of this field is 'ME', then the local player
  542. X#    will assume the role of server.  If the value of this field
  543. X#    is anything else, then it is interpreted as an internet name
  544. X#    or number of the machine where the server is running.
  545. X# SERVER reciprocity
  546. X
  547. X#  TIMER        ON | OFF
  548. X#       This controls whether or not the timer will automatically
  549. X#       be displayed showing the amount of time spent by the local
  550. X#       player and by all players on the current hand.
  551. X# 
  552. XTIMER ON
  553. X
  554. X# TIMEZONE     <timezone-string>
  555. X#      This is a string which specifies the name of the time zone of
  556. X#      the local player.  Usually, this can be determined from looking
  557. X#      at the tm_zone field of the structure returned by the localtime()
  558. X#      system call, but some systems do not have this field.
  559. X# TIMEZONE     PDT
  560. X
  561. X#  ZLOG         <filename>
  562. X#       This command is similar to the LOG command, in that it opens
  563. X#       a file for recording play, but the format of the file is 
  564. X#       different.
  565. XZLOG okbridge.zlog
  566. X
  567. X# The following two options are only relevant if the position is
  568. X# north and the scoring mode is email.  In this case, these commands
  569. X# can be used to automatically load and store email duplicate boards.
  570. X#
  571. X#   LOAD        <filename>
  572. X#        Causes the boards stored in the email duplicate file
  573. X#        named <filename> to be automatically loaded at the beginning
  574. X#        of the program.
  575. X#
  576. X#   REPLAY      <filename>
  577. X#        Also causes the boards stored in the email duplicate file
  578. X#        named <filename> to be automatically loaded at the beginning
  579. X#        of the program.  After they have been played, the boards along
  580. X#        with the results of play are automatically saved back to the
  581. X#        same file.
  582. END_OF_FILE
  583. if test 6117 -ne `wc -c <'okbridgerc'`; then
  584.     echo shar: \"'okbridgerc'\" unpacked with wrong size!
  585. fi
  586. # end of 'okbridgerc'
  587. fi
  588. if test -f 'okshuffle.c' -a "${1}" != "-c" ; then 
  589.   echo shar: Will not clobber existing file \"'okshuffle.c'\"
  590. else
  591. echo shar: Extracting \"'okshuffle.c'\" \(3739 characters\)
  592. sed "s/^X//" >'okshuffle.c' <<'END_OF_FILE'
  593. X/* shuffle.c -- generate shuffles for use in email duplicate play.
  594. X *
  595. X ! Copyright (C) 1990-1992 by Matthew Clegg.  All Rights Reserved
  596. X ! 
  597. X ! OKbridge is made available as a free service to the Internet.
  598. X ! Accordingly, the following restrictions are placed on its use:
  599. X ! 
  600. X ! 1.  OKbridge may not be modified in any way without the explicit 
  601. X !     permission of Matthew Clegg.  
  602. X ! 
  603. X ! 2.  OKbridge may not be used in any way for commercial advantage.
  604. X !     It may not be placed on for-profit networks or on for-profit
  605. X !     computer systems.  It may not be bundled as part of a package
  606. X !     or service provided by a for-profit organization.
  607. X ! 
  608. X ! If you have questions about restrictions on the use of OKbridge,
  609. X ! write to mclegg@cs.ucsd.edu.
  610. X ! 
  611. X ! DISCLAIMER:  The user of OKbridge accepts full responsibility for any
  612. X ! damage which may be caused by OKbridge.
  613. X *
  614. X * Format of command:
  615. X *   
  616. X *   okshuffle [nboards] [-n board-names] [-r] [-d] [-i] [-m]
  617. X *
  618. X * where
  619. X *   nboards 
  620. X *     is the number of boards to generate.  If omitted, nboards
  621. X *     defaults to 4.
  622. X *
  623. X *   -n board-names
  624. X *     a brief (max 10 chars) name which will be used to identify the
  625. X *     boards.  If this is omitted, then a name is invented which is based
  626. X *     on the current date.
  627. X *
  628. X *   -r, -d, -i, -m
  629. X *     specifies the scoring mode to be respectively rubber, duplicate,
  630. X *     imp or mp.  The default scoring mode is imp.
  631. X *
  632. X * Writes the encoded boards to standard output.
  633. X *
  634. X */
  635. X
  636. X#include <stdio.h>
  637. X#include <sys/types.h>
  638. X#include <sys/time.h>
  639. X#include <errno.h>
  640. X#include <string.h>
  641. X
  642. X#define _BRIDGE_
  643. X
  644. X#include "types.h"
  645. X#include "boards.h"
  646. X#include "state.h"
  647. X
  648. X#ifdef GCC
  649. Xextern fprintf ();
  650. Xextern time_t time ();
  651. X#endif
  652. X
  653. Xextern char *malloc ();
  654. Xextern char *strdup ();
  655. X
  656. Xextern int errno;
  657. Xextern char *sys_errlist[];
  658. Xextern void exit ();
  659. Xextern int  atoi ();
  660. Xextern void srand ();
  661. X
  662. Xstatic void parameter_error (msg)
  663. X     char *msg;
  664. X{
  665. X  fprintf (stderr, "shuffle: error in parameters: %s\n", msg);
  666. X  fprintf (stderr, "shuffle: usage: shuffle [nboards] [-m initial_message]\n");
  667. X  exit (1);
  668. X}
  669. X
  670. Xvoid main (argc, argv)
  671. X     int argc; char *argv[];
  672. X{
  673. X  int i, nboards, know_nboards, print_date;
  674. X  char *board_name;
  675. X  char error_buf[80];
  676. X/*  time_t time_value; */
  677. X  Board *b;
  678. X
  679. X  nboards = 4;
  680. X  know_nboards = 0;
  681. X  print_date = 0;
  682. X  scoring_mode = IMP_SCORING;
  683. X  board_name = NULL;
  684. X
  685. X  for (i = 1; i < argc; i++) {
  686. X    if (!strcmp(argv[i], "-d"))
  687. X      scoring_mode = DUPLICATE_SCORING;
  688. X    else if (!strcmp(argv[i], "-i"))
  689. X      scoring_mode = IMP_SCORING;
  690. X    else if (!strcmp(argv[i], "-m"))
  691. X      scoring_mode = MP_SCORING;
  692. X    else if (!strcmp(argv[i], "-r"))
  693. X      scoring_mode = RUBBER_SCORING;
  694. X    else if (!strcmp(argv[i], "-n")) {
  695. X      i++;
  696. X      if (i < argc)
  697. X    board_name = strdup (argv[i]);
  698. X      else
  699. X    parameter_error ("board_name missing");
  700. X    } else if (!know_nboards) {
  701. X      nboards = atoi (argv[i]);
  702. X      know_nboards = 1;
  703. X      if (nboards <= 0) {
  704. X    sprintf (error_buf, "expected integer nboards, but got %s", argv[i]);
  705. X    parameter_error (error_buf);
  706. X      }
  707. X    } else
  708. X      parameter_error ("too many parameters");
  709. X  }
  710. X
  711. X
  712. X  srand (time(NULL));
  713. X
  714. X/*
  715. X  if (print_date) {
  716. X    time (&time_value);
  717. X    sprintf (date_buffer, "THIS HAND WAS SHUFFLED ON %s", ctime(&time_value));
  718. X    if (date_buffer[strlen(date_buffer)-1] == '\n')
  719. X      date_buffer[strlen(date_buffer)-1] = '\0';
  720. X  }
  721. X*/
  722. X
  723. X  b = NULL;
  724. X  for (i = 0; i < nboards; i++) {
  725. X    if (scoring_mode == RUBBER_SCORING)
  726. X      b = Generate_Random_Rubber_Board (b, NULL);
  727. X    else
  728. X      b = Generate_Random_Match_Board (scoring_mode, b);
  729. X    if (board_name != NULL)
  730. X      b->source = strdup (board_name);
  731. X    Record_Played_Board (b);
  732. X  }
  733. X
  734. X  Write_Email_Duplicate_File (stdout);
  735. X}
  736. END_OF_FILE
  737. if test 3739 -ne `wc -c <'okshuffle.c'`; then
  738.     echo shar: \"'okshuffle.c'\" unpacked with wrong size!
  739. fi
  740. # end of 'okshuffle.c'
  741. fi
  742. if test -f 'scoring.h' -a "${1}" != "-c" ; then 
  743.   echo shar: Will not clobber existing file \"'scoring.h'\"
  744. else
  745. echo shar: Extracting \"'scoring.h'\" \(5309 characters\)
  746. sed "s/^X//" >'scoring.h' <<'END_OF_FILE'
  747. X/* scoring.h -- scoring functions for the bridge program.
  748. X *
  749. X ! Copyright (C) 1990-1992 by Matthew Clegg.  All Rights Reserved
  750. X ! 
  751. X ! OKbridge is made available as a free service to the Internet.
  752. X ! Accordingly, the following restrictions are placed on its use:
  753. X ! 
  754. X ! 1.  OKbridge may not be modified in any way without the explicit 
  755. X !     permission of Matthew Clegg.  
  756. X ! 
  757. X ! 2.  OKbridge may not be used in any way for commercial advantage.
  758. X !     It may not be placed on for-profit networks or on for-profit
  759. X !     computer systems.  It may not be bundled as part of a package
  760. X !     or service provided by a for-profit organization.
  761. X ! 
  762. X ! If you have questions about restrictions on the use of OKbridge,
  763. X ! write to mclegg@cs.ucsd.edu.
  764. X ! 
  765. X ! DISCLAIMER:  The user of OKbridge accepts full responsibility for any
  766. X ! damage which may be caused by OKbridge.
  767. X *
  768. X * This file defines the functions used for computing scores.
  769. X * We provide functions for scoring according to the rules of
  770. X * rubber bridge as well as according to the rules of Chicago style
  771. X * bridge.  Instead of being passed parameters, these functions
  772. X * obtain most of their information from the global variables
  773. X * defined in globals.h.
  774. X *
  775. X * I would like to thank Tom Kronmiller for supplying the code
  776. X * for scoring according to the Chicago rules and David Morrison
  777. X * for supplying the MIMP scoring code.
  778. X */
  779. Xextern int MIMP_scoring_vuln [];
  780. Xextern int MIMP_scoring_nonvuln [];
  781. X
  782. X/*  All of the routines in this module use the same set of parameters:
  783. X *  
  784. X *  vul     := a boolean flag which if true indicates that the declaring
  785. X *             side was vulnerable.
  786. X *  level   := the level of the contract.
  787. X *  suit    := the trump suit (or SUIT_NOTRUMP).
  788. X *  doubled := is 0 for an undoubled contract, 1 for a doubled contract,
  789. X *             and 2 for a redoubled contract.
  790. X *  made    := If the contract was made, then the number of tricks made
  791. X *             minus 6.  Otherwise, the negative of the number of tricks set.
  792. X *  hcp     := Number of highcard points held by the declaring side.
  793. X */
  794. X
  795. X
  796. Xextern int Rubber_score_above ();
  797. X/* int Rubber_score_above (vul, level, suit, doubled, made); */
  798. X/* Computes the above-the-line score for the current contract, assuming
  799. X   the contract was made. */
  800. X
  801. Xextern int Rubber_score_below ();
  802. X/* int Rubber_score_below (vul, level, suit, doubled, made); */
  803. X/* Computes the below-the-line score for the current contract,
  804. X * assuming the contract was made. */
  805. X
  806. Xextern int Rubber_score_set ();
  807. X/* int Rubber_score_set (vul, level, suit, doubled, made); */
  808. X/* Computes the penalty score for the current contract assuming that
  809. X * the contract was set.  
  810. X */
  811. X
  812. Xextern int Chicago_score_made ();
  813. X/* int Chicago_score_made (vul, level, suit, doubled, made); */
  814. X/* Computes the score for the current contract under the Chicago scoring
  815. X * system, assuming that it was made.
  816. X *
  817. X * Original version by Tom Kronmiller.
  818. X */
  819. X
  820. Xextern int Chicago_score_set ();
  821. X/* int Chicago_score_set (vul, level, suit, doubled, made); */
  822. X/* Computes the score for the given contract under the Chicago scoring
  823. X * system, assuming that it was set.
  824. X *
  825. X * Original version by Tom Kronmiller.
  826. X */
  827. X
  828. Xextern int Duplicate_score_made ();
  829. X/* int Duplicate_score_made (vul, level, suit, doubled, made); */
  830. X/* Computes the score for the given contract under the rules of
  831. X * duplicate scoring. 
  832. X */
  833. X
  834. Xextern int Duplicate_score_set ();
  835. X/* int Duplicate_score_set (vul, level, suit, doubled, made); */
  836. X/* Computes the score for the given contract under the rules of
  837. X * duplicate scoring, assuming that it was set.
  838. X */
  839. X
  840. Xint IMP_rating ();
  841. X/* Returns the number of IMPs awarded for the given score difference. 
  842. X * The score is computed according International Match Point Scale of
  843. X * the ACBL (1988).
  844. X */
  845. X
  846. Xextern int Simulated_IMP_score_made ();
  847. X/* int Simulated_IMP_score_made (vul, level, suit, doubled, made, hcp); */
  848. X/* Computes the simulated IMP score for the  contract assuming that it 
  849. X * was made.
  850. X *
  851. X * The Simulated IMP scoring system awards a score which is based on how
  852. X * well the declaring team but offset by their number of highcard points.
  853. X * The duplicate score for the declaring team is computed and then 
  854. X * converted to a corresponding number of IMP points.  From this is
  855. X * subtracted the excess number of highcard points above twenty of
  856. X * the declaring team.  If the declaring team has fewer than 20 hcp,
  857. X * then the deficit is added to the IMP score.
  858. X */
  859. X
  860. Xextern int Simulated_IMP_score_set ();
  861. X/* int Simulated_IMP_score_set (vul, level, suit, doubled, made, hcp); */
  862. X/* Computes the simulated IMP score for the given contract assuming that 
  863. X * it was set.
  864. X */
  865. X
  866. Xextern int MIMP_score_made ();
  867. X/* int MIMP_score_made (vul, level, suit, doubled, made, hcp); */
  868. X/* Computes the MIMP score for the given contract, assuming it was made. 
  869. X * 
  870. X * The MIMP system is similar to spirit to the simulated IMP system,
  871. X * in that the number of points awarded is offset by the highcard holdings
  872. X * of the declaring side.  For a detailed description of the MIMP system,
  873. X * see the article by Gary Greene in the May/June 1990 issue of 
  874. X * Bridge Today.
  875. X */
  876. X
  877. Xextern int MIMP_score_set ();
  878. X/* int MIMP_score_set (vul, level, suit, doubled, made, hcp); */
  879. X/* Computes the MIMP score for the given contract, assuming it was set. */
  880. X
  881. X
  882. END_OF_FILE
  883. if test 5309 -ne `wc -c <'scoring.h'`; then
  884.     echo shar: \"'scoring.h'\" unpacked with wrong size!
  885. fi
  886. # end of 'scoring.h'
  887. fi
  888. if test -f 'socket.c' -a "${1}" != "-c" ; then 
  889.   echo shar: Will not clobber existing file \"'socket.c'\"
  890. else
  891. echo shar: Extracting \"'socket.c'\" \(7124 characters\)
  892. sed "s/^X//" >'socket.c' <<'END_OF_FILE'
  893. X/* socket.c -- routines for establishing socket connections
  894. X *             over the Internet.
  895. X *
  896. X ! Copyright (C) 1990-1992 by Matthew Clegg.  All Rights Reserved
  897. X ! 
  898. X ! OKbridge is made available as a free service to the Internet.
  899. X ! Accordingly, the following restrictions are placed on its use:
  900. X ! 
  901. X ! 1.  OKbridge may not be modified in any way without the explicit 
  902. X !     permission of Matthew Clegg.  
  903. X ! 
  904. X ! 2.  OKbridge may not be used in any way for commercial advantage.
  905. X !     It may not be placed on for-profit networks or on for-profit
  906. X !     computer systems.  It may not be bundled as part of a package
  907. X !     or service provided by a for-profit organization.
  908. X ! 
  909. X ! If you have questions about restrictions on the use of OKbridge,
  910. X ! write to mclegg@cs.ucsd.edu.
  911. X ! 
  912. X ! DISCLAIMER:  The user of OKbridge accepts full responsibility for any
  913. X ! damage which may be caused by OKbridge.
  914. X *
  915. X */
  916. X
  917. X#include <ctype.h>
  918. X#include <sys/errno.h>
  919. X#include <sys/types.h>
  920. X#include <sys/socket.h>
  921. X#include <netinet/in.h>
  922. X#include <arpa/inet.h>
  923. X#include <netdb.h>
  924. X#include <stdio.h>
  925. X#include <string.h>
  926. X#include <sys/time.h>
  927. X#ifdef AIX
  928. X#include <sys/select.h>
  929. X#include <time.h>
  930. X#endif
  931. X
  932. X#include "fds.h"
  933. X
  934. Xextern int errno;
  935. Xextern char *sys_errlist[];
  936. X/* extern int htons (); */
  937. Xextern void sleep (), close ();
  938. Xextern int read (), write ();
  939. Xextern int select ();
  940. Xextern int socket ();
  941. Xextern connect ();
  942. Xextern setsockopt ();
  943. Xextern bind ();
  944. Xextern listen ();
  945. X
  946. Xchar socket_error [80];
  947. X  /* An error message buffer for recording socket errors. */
  948. X
  949. Xint client_init(host, portnum, retry_limit)
  950. X     char *host;
  951. X     int portnum;
  952. X     int retry_limit;
  953. X/* Attempts to establish a connection with the host identified by the
  954. X * string 'host' at port 'portnum'.  If the connection is established,
  955. X * then returns the socket number.  Otherwise, returns -1 and places
  956. X * an error message in socket_error.
  957. X *
  958. X * This routine was adapted from a routine of the same name
  959. X * written by Jarkko Oikarinen of the University of Oulu as part
  960. X * of the Internet Relay Chat package.
  961. X * 
  962. X */
  963. X{
  964. X  int sock, notrys;
  965. X  static struct hostent *hp;
  966. X  static struct sockaddr_in server;
  967. X  int server_avail;
  968. X
  969. X
  970. X  notrys = 0;
  971. X  while (notrys < retry_limit) {
  972. X  /* FIX:  jtrim@duorion.cair.du.edu -- 3/4/89 
  973. X     and jto@tolsun.oulu.fi -- 3/7/89 */
  974. X
  975. X    sock = socket(AF_INET, SOCK_STREAM, 0);
  976. X
  977. X    if (sock < 0) {
  978. X      sprintf (socket_error, "error opening socket: %s",
  979. X           sys_errlist [errno]);
  980. X      return (-1);
  981. X    }
  982. X    server.sin_family = AF_INET;
  983. X    
  984. X    /* MY FIX -- jtrim@duorion.cair.du.edu   (2/10/89) */
  985. X    if ( isdigit(*host))
  986. X      {
  987. X    server.sin_addr.s_addr = inet_addr(host);
  988. X      }
  989. X    else
  990. X      { 
  991. X    hp = gethostbyname(host);
  992. X    if (hp == 0) {
  993. X      sprintf(socket_error, "%s: unknown host", host);
  994. X      return (-1);
  995. X    }
  996. X    bcopy(hp->h_addr, &server.sin_addr, hp->h_length);
  997. X      }
  998. X    server.sin_port = htons(portnum);
  999. X    /* End Fix */
  1000. X    
  1001. X    server_avail = connect(sock, (struct sockaddr *) &server, sizeof(server));
  1002. X    if (server_avail) {
  1003. X            close (sock);
  1004. X        sprintf (socket_error, "connection error: %s", 
  1005. X             sys_errlist [errno]);
  1006. X        notrys++;
  1007. X        if (errno == EINTR) return (-1);
  1008. X        if (notrys < retry_limit)
  1009. X          sleep (5);
  1010. X    } else
  1011. X      return(sock);
  1012. X  }
  1013. X  sprintf (socket_error, "CAN'T SEEM TO CONNECT TO SERVER -- GIVING UP");
  1014. X  return (-1);
  1015. X}
  1016. X
  1017. Xint open_port(portnum)
  1018. X     int portnum;
  1019. X/* Opens a socket port for listening.  If successful, returns the
  1020. X * number of socket which has been established.  If unsuccessful,
  1021. X * returns -1 and places an error string in socket_error.
  1022. X *
  1023. X * This routine was adapted from a routine of the same name
  1024. X * written by Jarkko Oikarinen of the University of Oulu as part
  1025. X * of the Internet Relay Chat package.
  1026. X * 
  1027. X */
  1028. X{
  1029. X  int sock, i;
  1030. X  static struct sockaddr_in server;
  1031. X  /* At first, open a new socket */
  1032. X  sock = socket(AF_INET, SOCK_STREAM, 0);
  1033. X  if (sock < 0) {
  1034. X    sprintf (socket_error, "error opening socket: %s",
  1035. X         sys_errlist[errno]);
  1036. X    return(-1);
  1037. X  }
  1038. X
  1039. X  i = 1;
  1040. X  if(setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,(char *)&i,sizeof(i)) < 0) {
  1041. X    sprintf (socket_error, "error setting REUSE option on socket: %s",
  1042. X         sys_errlist[errno]);
  1043. X    return(-1);
  1044. X  }
  1045. X  /* Bind a port to listen for new connections */
  1046. X  server.sin_family = AF_INET;
  1047. X  server.sin_addr.s_addr = INADDR_ANY;
  1048. X  server.sin_port = htons(portnum);
  1049. X  if (bind(sock, (struct sockaddr *) (&server), sizeof(server))) {
  1050. X    sprintf (socket_error, "error binding stream socket: %s",
  1051. X         sys_errlist[errno]);
  1052. X    close (sock);
  1053. X    return(-1);
  1054. X  }
  1055. X
  1056. X  if(listen(sock, 3)) {
  1057. X    sprintf (socket_error, "error listening on socket: %s",
  1058. X         sys_errlist[errno]);
  1059. X    close (sock);
  1060. X    return (-1);
  1061. X  }
  1062. X
  1063. X  return(sock);
  1064. X}
  1065. X
  1066. Xint fd_readln (fd, buf, buflen)
  1067. Xint fd; char *buf; int buflen;
  1068. X/* Reads characters from the socket fd until a newline character \n
  1069. X * is detected.  Copies up to buflen-1 characters into buf, and
  1070. X * terminates the string with a null byte.  Returns the number of
  1071. X * bytes read.  -1 is returned if the socket is closed or if an
  1072. X * exceptional condition has occurred on the socket. 
  1073. X */
  1074. X{
  1075. X    int buflog, readlog;
  1076. X    char chbuf[2];
  1077. X
  1078. X    buf[0] = '\0';
  1079. X    readlog = read (fd, chbuf, 1);
  1080. X    if (readlog == 0)
  1081. X      sprintf (socket_error, "EOF on read from socket");
  1082. X    else if (readlog < 0)
  1083. X      sprintf (socket_error, "socket read error: %s",
  1084. X           sys_errlist[errno]);
  1085. X    if (readlog <= 0) return (-1);
  1086. X    buflog = 0;
  1087. X    while ((chbuf[0] != '\015') && (chbuf[0] != '\0')) {
  1088. X        if (buflog < buflen-1)
  1089. X            buf[buflog++] = chbuf[0];
  1090. X        readlog = read (fd, chbuf, 1);
  1091. X        if (readlog <= 0) {
  1092. X          buf[0] = '\0';
  1093. X          if (readlog < 0)
  1094. X            sprintf (socket_error, "socket read error: %s",
  1095. X                 sys_errlist[errno]);
  1096. X          else
  1097. X            sprintf (socket_error, "EOF on read from socket");
  1098. X          return (readlog);
  1099. X        }
  1100. X    }
  1101. X    if (chbuf[0] != '\0')
  1102. X      readlog = read (fd, chbuf, 1);
  1103. X    buf[buflog] = '\0';
  1104. X    return (buflog);
  1105. X}
  1106. X
  1107. Xint fd_writeln (fd, buf)
  1108. X     int fd; char *buf;
  1109. X/* Writes the contents of the buffer to the file descriptor fd, terminating
  1110. X   it by a newline character.  Returns the actual number of bytes written,
  1111. X   or -1 if an error occurs.
  1112. X*/
  1113. X{
  1114. X  int n = strlen (buf);
  1115. X  int cc = write (fd, buf, n);
  1116. X  int cr;
  1117. X
  1118. X  if (cc < n)
  1119. X    return (cc);
  1120. X
  1121. X  cr = write (fd, "\015\n", 2);
  1122. X  if (cr < 0)
  1123. X    return (cr);
  1124. X  else 
  1125. X    return (n + cr);
  1126. X}
  1127. X
  1128. Xint Check_for_data (fd)
  1129. X     int fd;
  1130. X/* Checks the socket descriptor fd to see if any incoming data has
  1131. X   arrived.  If yes, then returns 1.  If no, then returns 0.
  1132. X   If an error, returns -1 and stores the error message in socket_error.
  1133. X*/
  1134. X{
  1135. X  int status;                 /* return code from Select call. */
  1136. X  struct fd_set wait_set;     /* A set representing the connections that
  1137. X                 have been established. */
  1138. X  struct timeval tm;          /* A timelimit of zero for polling for new
  1139. X                 connections. */
  1140. X
  1141. X  FD_ZERO (&wait_set);
  1142. X  FD_SET (fd, &wait_set);
  1143. X
  1144. X  tm.tv_sec = 0;
  1145. X  tm.tv_usec = 0;
  1146. X  status = select (FD_SETSIZE, &wait_set, (fd_set *) 0, (fd_set *) 0, &tm);
  1147. X
  1148. X  if (status < 0)
  1149. X    sprintf (socket_error, "Error in select: %s", sys_errlist[errno]);
  1150. X
  1151. X  return (status);
  1152. X
  1153. X}
  1154. END_OF_FILE
  1155. if test 7124 -ne `wc -c <'socket.c'`; then
  1156.     echo shar: \"'socket.c'\" unpacked with wrong size!
  1157. fi
  1158. # end of 'socket.c'
  1159. fi
  1160. if test -f 'socket.h' -a "${1}" != "-c" ; then 
  1161.   echo shar: Will not clobber existing file \"'socket.h'\"
  1162. else
  1163. echo shar: Extracting \"'socket.h'\" \(2844 characters\)
  1164. sed "s/^X//" >'socket.h' <<'END_OF_FILE'
  1165. X/* socket.h -- routines for establishing connections over the internet.
  1166. X *
  1167. X ! Copyright (C) 1990-1992 by Matthew Clegg.  All Rights Reserved
  1168. X ! 
  1169. X ! OKbridge is made available as a free service to the Internet.
  1170. X ! Accordingly, the following restrictions are placed on its use:
  1171. X ! 
  1172. X ! 1.  OKbridge may not be modified in any way without the explicit 
  1173. X !     permission of Matthew Clegg.  
  1174. X ! 
  1175. X ! 2.  OKbridge may not be used in any way for commercial advantage.
  1176. X !     It may not be placed on for-profit networks or on for-profit
  1177. X !     computer systems.  It may not be bundled as part of a package
  1178. X !     or service provided by a for-profit organization.
  1179. X ! 
  1180. X ! If you have questions about restrictions on the use of OKbridge,
  1181. X ! write to mclegg@cs.ucsd.edu.
  1182. X ! 
  1183. X ! DISCLAIMER:  The user of OKbridge accepts full responsibility for any
  1184. X ! damage which may be caused by OKbridge.
  1185. X *
  1186. X */
  1187. X
  1188. X
  1189. Xextern int client_init ();
  1190. X/* int client_init(char *host, int portnum, int retry_limit); */
  1191. X/* Attempts to establish a connection with the host identified by the
  1192. X * string 'host' at port 'portnum'.  If the connection is established,
  1193. X * then returns the socket number.  Otherwise, returns -1 and places
  1194. X * an error message in socket_error.
  1195. X *
  1196. X * This routine was adapted from a routine of the same name
  1197. X * written by Jarkko Oikarinen of the University of Oulu as part
  1198. X * of the Internet Relay Chat package.
  1199. X * 
  1200. X */
  1201. X
  1202. Xextern int open_port ();
  1203. X/* int open_port(int portnum); */
  1204. X/* Opens a socket port for listening.  If successful, returns the
  1205. X * number of socket which has been established.  If unsuccessful,
  1206. X * returns -1 and places an error string in socket_error.
  1207. X *
  1208. X * This routine was adapted from a routine of the same name
  1209. X * written by Jarkko Oikarinen of the University of Oulu as part
  1210. X * of the Internet Relay Chat package.
  1211. X * 
  1212. X */
  1213. X
  1214. Xextern int fd_readln ();
  1215. X/* int fd_readln (int fd, char *buf, int buflen) */
  1216. X/* Reads characters from the socket fd until a newline character \n
  1217. X * is detected.  Copies up to buflen-1 characters into buf, and
  1218. X * terminates the string with a null byte.  Returns the number of
  1219. X * bytes read.  -1 is returned if the socket is closed or if an
  1220. X * exceptional condition has occurred on the socket. 
  1221. X */
  1222. X
  1223. Xextern int fd_writeln ();
  1224. X/* int fd_writeln (int fd, char *buf) */
  1225. X/* Writes the contents of the buffer to the file descriptor fd, terminating
  1226. X * it by a newline character.  Returns the actual number of bytes written,
  1227. X * or -1 if an error occurs.  NOTE:  In a normal write, the number of
  1228. X * bytes written is equal to the length of buf plus one.
  1229. X */
  1230. X
  1231. Xextern int Check_for_data ();
  1232. X/* int Check_for_data (int fd) */
  1233. X/* Checks the socket descriptor fd to see if any incoming data has
  1234. X * arrived.  If yes, then returns 1.  If no, then returns 0.
  1235. X * If an error, returns -1 and stores the error message in socket_error.
  1236. X */
  1237. END_OF_FILE
  1238. if test 2844 -ne `wc -c <'socket.h'`; then
  1239.     echo shar: \"'socket.h'\" unpacked with wrong size!
  1240. fi
  1241. # end of 'socket.h'
  1242. fi
  1243. if test -f 'state.h' -a "${1}" != "-c" ; then 
  1244.   echo shar: Will not clobber existing file \"'state.h'\"
  1245. else
  1246. echo shar: Extracting \"'state.h'\" \(5589 characters\)
  1247. sed "s/^X//" >'state.h' <<'END_OF_FILE'
  1248. X/* state.h -- global data values.
  1249. X *
  1250. X ! Copyright (C) 1990-1992 by Matthew Clegg.  All Rights Reserved
  1251. X ! 
  1252. X ! OKbridge is made available as a free service to the Internet.
  1253. X ! Accordingly, the following restrictions are placed on its use:
  1254. X ! 
  1255. X ! 1.  OKbridge may not be modified in any way without the explicit 
  1256. X !     permission of Matthew Clegg.  
  1257. X ! 
  1258. X ! 2.  OKbridge may not be used in any way for commercial advantage.
  1259. X !     It may not be placed on for-profit networks or on for-profit
  1260. X !     computer systems.  It may not be bundled as part of a package
  1261. X !     or service provided by a for-profit organization.
  1262. X ! 
  1263. X ! If you have questions about restrictions on the use of OKbridge,
  1264. X ! write to mclegg@cs.ucsd.edu.
  1265. X ! 
  1266. X ! DISCLAIMER:  The user of OKbridge accepts full responsibility for any
  1267. X ! damage which may be caused by OKbridge.
  1268. X *
  1269. X * This file contains the definitions of all of the global variables.
  1270. X * These variables represent the state of the current game.  It seems
  1271. X * to be more convenient to make them global variables than to store
  1272. X * them locally and pass them as parameters to various procedures.
  1273. X *
  1274. X * The definition _BRIDGE_ is used to distinguish the external
  1275. X * references to these variables from the actual definitions.  The module
  1276. X * which defines these variables should give a definition to _BRIDGE_
  1277. X * before including this file.
  1278. X */
  1279. X
  1280. X#ifndef TYPES_INCLUDED
  1281. X#include "types.h"
  1282. X#endif
  1283. X
  1284. X#ifndef NETWORK_INCLUDED
  1285. X#include "network.h"
  1286. X#endif
  1287. X
  1288. X#ifdef _BRIDGE_
  1289. X    /* Variables used to control the behavior of the local copy
  1290. X       of the program: */
  1291. X
  1292. X        int prompt_dummy = 1;    /* true if the dummy should be prompted
  1293. X                    after each play. */
  1294. X
  1295. X        int default_plays=1;     /* true if default plays are allowed. */
  1296. X
  1297. X        int autopass_mode = 1;   /* true if the moderator should automatically
  1298. X                    generate PASS bids for absent players
  1299. X                    during PRACTICE play. */
  1300. X
  1301. X        int local_player;        /* the seat assigned to the local player. */
  1302. X
  1303. X        char *local_player_name; /* the nickname of the local player. */
  1304. X        char *local_player_full_name = NULL;
  1305. X          /* The name of the local player as specified with the FULLNAME
  1306. X         field in the .okbridgerc file. */
  1307. X        char *local_player_email = NULL;
  1308. X          /* The email address of the local player as specified with the
  1309. X             EMAIL field in the .okbridgerc file. */
  1310. X
  1311. X        char *local_cc;
  1312. X          /* The convention card of the local player as specified with the
  1313. X             CC field in the .okbridgerc file. */
  1314. X        char *conventions[2] = {NULL, NULL};
  1315. X          /* The convention cards of NS and EW, respectively. */
  1316. X    /* Information regarding the current hand: */
  1317. X        struct Table_struct *Local_table;
  1318. X          /* The table where we are sitting. */
  1319. X        struct Board_struct *Local_board;
  1320. X          /* The current board being played. */
  1321. X        struct Play_record_struct *Local_play;
  1322. X          /* The record of the plays which have been made in the current
  1323. X         board. */
  1324. X
  1325. X        /* Information about the hands which are visible: */
  1326. X        int spectator_mode;     /* true if the observer has been shown
  1327. X                                   any hands. */
  1328. X        int revealed_bidder;    /* the bidder which is currently revealed to
  1329. X                                   the spectator. */
  1330. X        int revealed_hands[4];  /* the hands which have been revealed to
  1331. X                   the player. */
  1332. X
  1333. X        int scoring_mode;       /* the scoring mode which will be used
  1334. X                   in shuffling new boards. */
  1335. X
  1336. X    int hands_played;    /* the number of hands that have been
  1337. X                   played so far. */
  1338. X        /* Additional variables used for maintaining global state: */
  1339. X        int claim_responses,    /* number of responses received so far
  1340. X                   to a claim request. */
  1341. X            claim_accepted;     /* true if neither defender has rejected
  1342. X                   the claim. */
  1343. X
  1344. X        /* Information pertaining to email duplicate play: */
  1345. X        char *email_filename = NULL;   
  1346. X                                /* the filename where we will save the
  1347. X                   hands that have been played. */
  1348. X
  1349. X        int replay_mode = 0;    /* TRUE if we should automatically save
  1350. X                   the hands back to the email_file after
  1351. X                   we have finished playing them. */
  1352. X
  1353. X        int gps_duplicate_mode = 0;  
  1354. X                                /* TRUE if we are playing GPS duplicate. */
  1355. X
  1356. X#else
  1357. X        extern int prompt_dummy;
  1358. X        extern int default_plays;
  1359. X        extern int formal_mode;
  1360. X        extern int autopass_mode;
  1361. X        extern int local_player;
  1362. X        extern char *local_player_name;
  1363. X        extern char *local_player_full_name;
  1364. X        extern char *local_player_email;
  1365. X
  1366. X        extern char *local_cc;
  1367. X        extern char *conventions[];
  1368. X    /* Information regarding the current hand: */
  1369. X        extern struct Table_struct *Local_table;
  1370. X        extern struct Board_struct *Local_board;
  1371. X        extern struct Play_record_struct *Local_play;
  1372. X
  1373. X
  1374. X        /* Information about the spectator: */
  1375. X        extern int spectator_mode, 
  1376. X                   revealed_bidder,
  1377. X                   revealed_hands[4];
  1378. X
  1379. X    /* Information regarding the current trick being played: */
  1380. X    extern int  leader,
  1381. X            no_plays,
  1382. X            plays [];
  1383. X    /* Scoring information: */
  1384. X    extern int  scoring_mode,
  1385. X            hands_played;
  1386. X        /* Additional variables used for maintaining global state: */
  1387. X        extern int  claim_responses, claim_accepted;
  1388. X
  1389. X        /* Information pertaining to email duplicate play: */
  1390. X        extern char *email_filename;
  1391. X        extern int  replay_mode;
  1392. X        extern int  gps_duplicate_mode;
  1393. X
  1394. X#endif
  1395. END_OF_FILE
  1396. if test 5589 -ne `wc -c <'state.h'`; then
  1397.     echo shar: \"'state.h'\" unpacked with wrong size!
  1398. fi
  1399. # end of 'state.h'
  1400. fi
  1401. if test -f 'terminal.c' -a "${1}" != "-c" ; then 
  1402.   echo shar: Will not clobber existing file \"'terminal.c'\"
  1403. else
  1404. echo shar: Extracting \"'terminal.c'\" \(4251 characters\)
  1405. sed "s/^X//" >'terminal.c' <<'END_OF_FILE'
  1406. X/* terminal
  1407. X *
  1408. X ! Copyright (C) 1990-1992 by Matthew Clegg.  All Rights Reserved
  1409. X ! 
  1410. X ! OKbridge is made available as a free service to the Internet.
  1411. X ! Accordingly, the following restrictions are placed on its use:
  1412. X ! 
  1413. X ! 1.  OKbridge may not be modified in any way without the explicit 
  1414. X !     permission of Matthew Clegg.  
  1415. X ! 
  1416. X ! 2.  OKbridge may not be used in any way for commercial advantage.
  1417. X !     It may not be placed on for-profit networks or on for-profit
  1418. X !     computer systems.  It may not be bundled as part of a package
  1419. X !     or service provided by a for-profit organization.
  1420. X ! 
  1421. X ! If you have questions about restrictions on the use of OKbridge,
  1422. X ! write to mclegg@cs.ucsd.edu.
  1423. X ! 
  1424. X ! DISCLAIMER:  The user of OKbridge accepts full responsibility for any
  1425. X ! damage which may be caused by OKbridge.
  1426. X *
  1427. X */
  1428. X#include <ctype.h>
  1429. X#include <stdio.h>
  1430. X#include <sys/types.h>
  1431. X#include <sys/socket.h>
  1432. X#include <sys/time.h>
  1433. X#include <curses.h>
  1434. X
  1435. X#ifdef AIX
  1436. X#include <sys/select.h>
  1437. X#ifndef TIOCGWINSZ
  1438. X#include <termios.h>
  1439. X#endif
  1440. X#endif
  1441. X
  1442. X#ifdef HPUX
  1443. X#ifndef TIOCGWINSZ
  1444. X#include <sys/termio.h>
  1445. X#endif
  1446. X#endif
  1447. X
  1448. X#define _TERMINAL_
  1449. X#include "terminal.h"
  1450. X#include "fds.h"
  1451. X
  1452. X#ifdef GCC
  1453. Xextern printf ();
  1454. X#endif
  1455. X
  1456. Xextern int ioctl ();
  1457. X/* extern int exit (); */
  1458. Xextern int stty ();
  1459. Xextern int select ();
  1460. Xextern void bzero ();
  1461. Xextern int read ();
  1462. X
  1463. Xextern int endwin ();
  1464. Xextern int wmove ();
  1465. Xextern int waddstr ();
  1466. Xextern int wrefresh ();
  1467. Xextern int wclear ();
  1468. X
  1469. Xint cursor_x, cursor_y;   /* The current position of the input cursor. */
  1470. Xint terminal_lines, terminal_cols; 
  1471. X  /* The size of the terminal screen. */
  1472. Xvoid Initialize_Terminal ()
  1473. X/* To be called once at the beginning of the program. */
  1474. X{
  1475. X#ifdef TIOCGWINSZ
  1476. X  struct winsize size;
  1477. X#endif
  1478. X
  1479. X#ifdef SUNOS
  1480. X        newterm (getenv("TERM"), stdout, stdin);
  1481. X#else
  1482. X    initscr ();
  1483. X#endif
  1484. X/*
  1485. X     terminal_lines = curscr->_maxy;
  1486. X    terminal_cols = curscr->_maxx;
  1487. X*/
  1488. X#ifdef TIOCGWINSZ
  1489. X  if (ioctl(0, TIOCGWINSZ, &size) < 0) {
  1490. X    terminal_lines = 24; 
  1491. X    terminal_cols = 80;
  1492. X  } else {
  1493. X    terminal_lines = size.ws_row;
  1494. X    if (terminal_lines == 0) terminal_lines = 24;
  1495. X    terminal_cols = size.ws_col;
  1496. X    if (terminal_cols == 0) terminal_cols = 80;
  1497. X  }
  1498. X#else
  1499. X  terminal_lines = 24;
  1500. X  terminal_cols  = 80;
  1501. X#endif
  1502. X
  1503. X#ifdef DEBUG
  1504. X  if ((terminal_lines < 24) || (terminal_cols < 80)) {
  1505. X    endwin ();
  1506. X    printf ("ERROR! The terminal window appears to small for okbridge.\n");
  1507. X    printf ("Lines = %d, Columns = %d\n", terminal_lines, terminal_cols);
  1508. X    exit (1);
  1509. X  }
  1510. X#endif
  1511. X
  1512. X#ifdef ultrix
  1513. X    crmode ();
  1514. X#else
  1515. X    cbreak ();
  1516. X#endif
  1517. X    noecho ();
  1518. X    nonl ();
  1519. X}
  1520. X
  1521. Xvoid Reinitialize_Terminal ()
  1522. X/* Reconstructs the terminal state.  To be used after a SIGWINCH has
  1523. X   been detected. */
  1524. X{
  1525. X#ifdef SUNOS
  1526. X  endwin();
  1527. X  Initialize_Terminal ();
  1528. X#endif
  1529. X ;
  1530. X}
  1531. Xvoid print (row, col, message)
  1532. X    int row, col; char *message;
  1533. X/* (1,1) specifies the upper left corner of the screen. */
  1534. X{
  1535. X    mvaddstr (row-1, col-1, message);
  1536. X}
  1537. X
  1538. Xvoid restore_cursor ()
  1539. X{
  1540. X  move (cursor_y, cursor_x);
  1541. X  refresh ();
  1542. X}
  1543. X
  1544. Xint char_avail ()
  1545. X/* Returns TRUE if a character is available from the keyboard. */
  1546. X{
  1547. X    struct fd_set wait_set;
  1548. X    struct timeval tm;
  1549. X
  1550. X    restore_cursor ();
  1551. X    FD_ZERO (&wait_set);
  1552. X    FD_SET (fileno(stdin), &wait_set);
  1553. X    tm.tv_sec = tm.tv_usec = 0;
  1554. X        select (FD_SETSIZE, &wait_set, NULL, NULL, &tm);
  1555. X        return (FD_ISSET(fileno(stdin), &wait_set));
  1556. X}
  1557. Xint input_char ()
  1558. X/* Returns the next input character from the keyboard.
  1559. X   (The character is echo'ed if it is not a control character.) */
  1560. X{
  1561. X    int log;
  1562. X    char chbuf[2];
  1563. X    restore_cursor ();
  1564. X    log = 0;
  1565. X    while (log < 1) log = read (0, chbuf, 1);
  1566. X
  1567. X    return (chbuf[0]);
  1568. X}
  1569. Xvoid set_cursor (row, col)
  1570. X    int row, col;
  1571. X/* Places the cursor at the specified (row, col). */
  1572. X{
  1573. X        cursor_x = col-1;
  1574. X    cursor_y = row-1;
  1575. X    restore_cursor ();
  1576. X}
  1577. Xvoid clear_screen ()
  1578. X{
  1579. X  clear ();
  1580. X  refresh ();
  1581. X}
  1582. Xvoid ring_bell ()
  1583. X/* void ring_bell (void); */
  1584. X/* Rings the terminal's bell */
  1585. X{
  1586. X  if (!bell_is_on)
  1587. X    return;
  1588. X
  1589. X#ifdef SUNOS
  1590. X        flash ();
  1591. X    beep ();
  1592. X#else
  1593. X        putchar ('\007');
  1594. X        putchar ('\007');
  1595. X#endif
  1596. X    restore_cursor ();
  1597. X}
  1598. X
  1599. Xvoid Reset_Terminal ()
  1600. X/* To be called at the end of the program to reset the terminal to its
  1601. X   initial operating mode. */
  1602. X{
  1603. X    clear_screen ();
  1604. X    endwin ();
  1605. X}
  1606. END_OF_FILE
  1607. if test 4251 -ne `wc -c <'terminal.c'`; then
  1608.     echo shar: \"'terminal.c'\" unpacked with wrong size!
  1609. fi
  1610. # end of 'terminal.c'
  1611. fi
  1612. if test -f 'terminal.h' -a "${1}" != "-c" ; then 
  1613.   echo shar: Will not clobber existing file \"'terminal.h'\"
  1614. else
  1615. echo shar: Extracting \"'terminal.h'\" \(2844 characters\)
  1616. sed "s/^X//" >'terminal.h' <<'END_OF_FILE'
  1617. X/* terminal
  1618. X *
  1619. X ! Copyright (C) 1990-1992 by Matthew Clegg.  All Rights Reserved
  1620. X ! 
  1621. X ! OKbridge is made available as a free service to the Internet.
  1622. X ! Accordingly, the following restrictions are placed on its use:
  1623. X ! 
  1624. X ! 1.  OKbridge may not be modified in any way without the explicit 
  1625. X !     permission of Matthew Clegg.  
  1626. X ! 
  1627. X ! 2.  OKbridge may not be used in any way for commercial advantage.
  1628. X !     It may not be placed on for-profit networks or on for-profit
  1629. X !     computer systems.  It may not be bundled as part of a package
  1630. X !     or service provided by a for-profit organization.
  1631. X ! 
  1632. X ! If you have questions about restrictions on the use of OKbridge,
  1633. X ! write to mclegg@cs.ucsd.edu.
  1634. X ! 
  1635. X ! DISCLAIMER:  The user of OKbridge accepts full responsibility for any
  1636. X ! damage which may be caused by OKbridge.
  1637. X *
  1638. X * The TERMINAL module serves as one of the main interfaces to the
  1639. X * operating system, the other interface being the NETWORK module.
  1640. X * This module provides primitives for outputting text to the screen
  1641. X * and reading characters from the keyboard.  We assume that
  1642. X * the screen has at least 24 lines and 80 columns, that the cursor
  1643. X * is addressable, and that it is possible to check in advance whether
  1644. X * or not a character is available from the keyboard.
  1645. X */
  1646. X
  1647. X#ifdef _TERMINAL_
  1648. X
  1649. X  int bell_is_on = 1; /* A boolean variable indicating that the bell
  1650. X             should be rung when the ring_bell () procedure
  1651. X             is called. */
  1652. X
  1653. X#else
  1654. X
  1655. X  extern int bell_is_on;
  1656. X
  1657. X#endif
  1658. X
  1659. Xextern int terminal_lines, terminal_cols;
  1660. X  /* The number of lines and columns in the terminal display. */
  1661. Xextern void Initialize_Terminal ();
  1662. X/* To be called once at the beginning of the program. */
  1663. X
  1664. Xextern void Reinitialize_Terminal ();
  1665. X/* Reconstructs the terminal state.  To be used after a SIGWINCH has
  1666. X   been detected. */
  1667. Xextern void print ();
  1668. X/* void print (int row, int col, char *message); */
  1669. X/* (1,1) specifies the upper left corner of the screen. */
  1670. Xextern int char_avail ();
  1671. X/* int char_avail (void); */
  1672. X/* Returns TRUE if a character is available from the keyboard. */
  1673. Xextern int input_char ();
  1674. X/* int input_char (void); */
  1675. X/* Returns the next input character from the keyboard. */
  1676. Xextern void set_cursor ();
  1677. X/* void set_cursor (int row, int col); */
  1678. X/* Places the cursor at the specified (row, col). */
  1679. X
  1680. Xextern void restore_cursor ();
  1681. X/* void restore_cursor (void); */
  1682. X/* Restores the cursor to its location as of the last call to set_cursor. */
  1683. Xextern void clear_screen ();
  1684. X/* void clear_screen (void); */
  1685. X/* Clears the screen and places the cursor in the upper left corner. */
  1686. Xextern void ring_bell ();
  1687. X/* void ring_bell (void); */
  1688. X/* Rings the terminal's bell */
  1689. X
  1690. Xextern void Reset_Terminal ();
  1691. X/* void Reset_Terminal (void); */
  1692. X/* To be called at the end of the program to reset the terminal to its
  1693. X   initial operating mode. */
  1694. END_OF_FILE
  1695. if test 2844 -ne `wc -c <'terminal.h'`; then
  1696.     echo shar: \"'terminal.h'\" unpacked with wrong size!
  1697. fi
  1698. # end of 'terminal.h'
  1699. fi
  1700. echo shar: End of archive 13 \(of 14\).
  1701. cp /dev/null ark13isdone
  1702. MISSING=""
  1703. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ; do
  1704.     if test ! -f ark${I}isdone ; then
  1705.     MISSING="${MISSING} ${I}"
  1706.     fi
  1707. done
  1708. if test "${MISSING}" = "" ; then
  1709.     echo You have unpacked all 14 archives.
  1710.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1711. else
  1712.     echo You still need to unpack the following archives:
  1713.     echo "        " ${MISSING}
  1714. fi
  1715. ##  End of shell archive.
  1716. exit 0
  1717.