Home » Recent acquisitions » Acorn ADFS disks » adfs_AcornUser_199801_2.adf » Regulars2 » StarInfo/Fletcher/!Setup/Files/Disc1/Program/NetGame/!NetGame/BasicLib/NetGameLib

StarInfo/Fletcher/!Setup/Files/Disc1/Program/NetGame/!NetGame/BasicLib/NetGameLib

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Recent acquisitions » Acorn ADFS disks » adfs_AcornUser_199801_2.adf » Regulars2
Filename: StarInfo/Fletcher/!Setup/Files/Disc1/Program/NetGame/!NetGame/BasicLib/NetGameLib
Read OK:
File size: 2AD7 bytes
Load address: 0000
Exec address: 0000
File contents
   10REM >NetGameLib
   20REM Network game support
   30REM LEN Justin Fletcher, 1997
   40REM Version 1.02 : 17 Jun 1997
   50ERROR &803,"Don't run this, it's a library !"
   60END
   70:
   80REM Routines which must be supplied :
   90REM DEFPROCconnected(host$,type)
  100REM   Will be called when we have connected safely
  110REM   type = ngs_originate if we requested the connection
  120REM        = ngs_answer if we have been contacted
  130REM DEFPROCdisconnected(type)
  140REM   Will be called when they disconnect
  150REM   type = ngs_dead if the connection was just dropped
  160REM        = ngs_going if they are leaving nicely
  170REM DEFPROCincoming(text$)
  180REM   Will be called when we get a message from the other end
  190REM
  200REM Routines which must be called :
  210REM port=FNnetgame_init(port)
  220REM   Call when you want to initialise the game
  230REM   May return -1 to say it couldn't initialise properly
  240REM PROCnetgame_poll
  250REM   Call this every so often to check if things are happening
  260REM   Once a Wimp_Poll, or Wimp_PollIdle if sufficient.
  270REM PROCnetgame_disconnect
  280REM   Call this if you want to disconnect
  290REM PROCnetgame_connect(to$,port)
  300REM   Call this if you want to connect to another computer
  310REM PROCnetgame_send(msg$)
  320REM   Call this to send a message to another program
  330:
  340REM ****************** Network support ************************
  350:
  360REM FNnetgame_init : initialise a network game
  370REM returns the port we are listening on, or -1 if none
  380DEFFNnetgame_init(port)
  390LIBRARY "<SocketLibrary$File>":PROCinitsockets
  400LIBRARY "<DynMenuLibrary$File>":PROCinit_dynmenu
  410ngs_disconnected=0:REM Not connected yet
  420ngs_negotiate_orig=1:REM Connected originate, but not validated
  430ngs_negotiate_ans=2:REM Connected answer, but not validated
  440ngs_connected=3:REM Connected and validated
  450ngs_dead=0:REM Code used when they disconnect without goodbye
  460ngs_going=1:REM Code used when they disconnected ok
  470ngs_failed=2:REM Code used when we couldn't get a connection
  480ngs_originate=0:REM Code used when we are talking to someone else
  490ngs_answer=1:REM Code used when someone is talking to us
  500ng_conto$="":REM Who we are connected to
  510ng_socket=-1:REM Not connected
  520ng_state=ngs_disconnected:REM Not connected
  530ng_time=0:REM The last time they spoke (to catch idlers)
  540ng_idle=3000:REM 30 seconds idle time
  550ng_sitesp=0:REM The preserved sites menu
  560ng_sitesm=0:REM The sites menu
  570ng_sitesl=0:REM The sites list
  580ng_listen=FNsocket_createinet
  590IF ng_listen<>-1 THEN
  600 ng_port=FNsocket_findlisten(ng_listen,0,port,15)
  610ELSE
  620 ng_port=-1
  630ENDIF
  640=ng_port
  650:
  660REM PROCnetgame_final : finalise a network game
  670REM shuts down the network game
  680DEFPROCnetgame_final
  690PROCsocket_close(ng_listen)
  700IF ng_state<>ngs_disconnected THEN
  710 ng_state=ngs_disconnected
  720 PROCsocket_close(ng_socket)
  730ENDIF
  740PROCclosesockets
  750ENDPROC
  760:
  770REM FNnetgame_connected : check if we are connected (TRUE if so)
  780REM FNnetgame_theirname : return their hostname (or null if none)
  790DEFFNnetgame_connected
  800=(ng_state=ngs_connected)
  810DEFFNnetgame_theirname
  820IF ng_state=ngs_connected THEN=ng_conto$
  830=""
  840:
  850REM netgame_poll : find out what's happening
  860DEFPROCnetgame_poll
  870LOCAL sock,len,start,ptr
  880CASE ng_state OF
  890 WHEN ngs_disconnected:REM Awaiting a connection
  900  ng_socket=FNsocket_accept(ng_listen)
  910  REM Is there a connection ?
  920  IF ng_socket<>-1 THEN
  930   REM Yes, lets find out who it is
  940   ng_conto$=FNsocket_getpeername(ng_socket)
  950   REM We're now negotiating for a connection
  960   ng_state=ngs_negotiate_ans
  970   REM Mark the time they connected
  980   ng_time=TIME
  990   REM Allow us to read the buffer as text
 1000   PROCsocket_makebuffered(ng_socket)
 1010  ENDIF
 1020 WHEN ngs_negotiate_orig,ngs_negotiate_ans
 1030  REM Awaiting a message from them saying 'ok'
 1040  IF TIME>ng_time+ng_idle THEN
 1050   REM They took too long to respond - kill them
 1060   PROCsocket_close(ng_socket)
 1070   IF ng_state=ngs_negotiate_orig THEN
 1080    REM Couldn't get a connection
 1090    PROCdisconnected(ngs_failed)
 1100   ENDIF
 1110   ng_state=ngs_disconnected
 1120  ELSE
 1130   sock=FNsocket_accept(ng_listen)
 1140   REM Has someone else connected ?
 1150   IF sock<>-1 THEN
 1160    PROCsocket_sendline(sock,"#Game already in progress")
 1170    PROCsocket_close(sock)
 1180   ELSE
 1190    IF FNsocket_eof(ng_socket) THEN
 1200     REM They came and they went
 1210     PROCsocket_close(ng_socket)
 1220     IF ng_state=ngs_negotiate_orig THEN
 1230      REM Couldn't get a connection
 1240      PROCdisconnected(ngs_failed)
 1250     ENDIF
 1260     ng_state=ngs_disconnected
 1270    ELSE
 1280     len=FNsocket_readline(ng_socket,start)
 1290     IF len<>-1 THEN
 1300      REM We received something
 1310      ptr=0
 1320      WHILE ptr<len
 1330       line$=FNbuffer_getrest(start,len,ptr)
 1340       IF LEFT$(line$,1)<>"#" THEN
 1350        REM Bad opener - kill them
 1360        PROCsocket_close(ng_socket)
 1370        IF ng_state=ngs_negotiate_orig THEN
 1380         REM Couldn't get a connection
 1390         PROCdisconnected(ngs_failed)
 1400        ENDIF
 1410        ng_state=ngs_disconnected
 1420       ELSE
 1430        IF ng_state=ngs_negotiate_ans THEN
 1440         REM We're answering
 1450         IF MID$(line$,2)=Appname$ THEN
 1460          REM Hey, good connection - say hi !
 1470          PROCsocket_sendline(ng_socket,"#Hi! Let's play !")
 1480          REM Yeah ! Got one ! Tell user who they are
 1490          PROCconnected(ng_conto$,ngs_answer)
 1500          ng_state=ngs_connected
 1510         ELSE
 1520          REM No, you're playing the wrong game, go away !
 1530          PROCsocket_sendline(ng_socket,"#No! Wrong game !")
 1540          REM Kill 'em
 1550          PROCsocket_close(ng_socket)
 1560          ng_state=ngs_disconnected
 1570         ENDIF
 1580        ELSE
 1590         REM We're originate
 1600         IF LEFT$(line$,4)="#Hi!" THEN
 1610          REM Good connection made by us
 1620          ng_conto$=FNsocket_getpeername(ng_socket)
 1630          PROCconnected(ng_conto$,ngs_originate)
 1640          ng_state=ngs_connected
 1650         ELSE
 1660          REM They said the wrong thing, walk out on them
 1670          PROCsocket_close(ng_socket)
 1680          REM Couldn't get a connection
 1690          PROCdisconnected(ngs_failed)
 1700          ng_state=ngs_disconnected
 1710         ENDIF
 1720        ENDIF
 1730       ENDIF
 1740      ENDWHILE
 1750     ENDIF
 1760    ENDIF
 1770   ENDIF
 1780  ENDIF
 1790 WHEN ngs_connected:REM Game on !
 1800  sock=FNsocket_accept(ng_listen)
 1810  REM Has someone else connected ?
 1820  IF sock<>-1 THEN
 1830   PROCsocket_sendline(sock,"#Game already in progress")
 1840   PROCsocket_close(sock)
 1850  ELSE
 1860   IF FNsocket_eof(ng_socket) THEN
 1870    REM They've gone, so tell the user
 1880    PROCdisconnected(ngs_dead)
 1890    REM And kill the dead socket
 1900    PROCsocket_close(sock)
 1910    ng_state=ngs_disconnected
 1920   ELSE
 1930    len=FNsocket_readline(ng_socket,start)
 1940    IF len<>-1 THEN
 1950     REM We received something
 1960     ptr=0
 1970     WHILE ptr<len
 1980      line$=FNbuffer_getrest(start,len,ptr)
 1990      IF LEFT$(line$,1)<>"#" THEN
 2000       REM Bad first character - kill them
 2010       PROCsocket_close(sock)
 2020       PROCdisconnected(ngs_dead)
 2030       ng_state=ngs_disconnected
 2040      ELSE
 2050       REM Command ok - pass it on to the program
 2060       line$=MID$(line$,2)
 2070       CASE LEFT$(line$,4) OF
 2080        WHEN "Data":REM Message from the user program
 2090         PROCincoming(MID$(line$,5))
 2100        WHEN "Cya!":REM Peer go bye-bye
 2110         PROCdisconnected(ngs_going)
 2120         PROCsocket_close(ng_socket)
 2130         ng_state=ngs_disconnected
 2140        OTHERWISE
 2150         REM Help... I dunno what's going on - let's kill em
 2160         PROCdisconnected(ngs_dead)
 2170         PROCsocket_close(ng_socket)
 2180         ng_state=ngs_disconnected
 2190       ENDCASE
 2200      ENDIF
 2210     ENDWHILE
 2220    ENDIF
 2230   ENDIF
 2240  ENDIF
 2250
 2260 OTHERWISE:REM What's going on !
 2270  quit%=TRUE:REM Exit because the game is in trouble
 2280ENDCASE
 2290ENDPROC
 2300:
 2310REM PROCnetgame_disconnect : Disconnect us from them ;-(
 2320DEFPROCnetgame_disconnect
 2330IF ng_state<>ngs_disconnected THEN
 2340 REM Say goodbye, like a nice boy
 2350 PROCsocket_sendline(ng_socket,"#Cya!")
 2360 REM Bye bye, little socket
 2370 PROCsocket_close(ng_socket)
 2380 REM Hey, we're not connected any more !
 2390 ng_state=ngs_disconnected
 2400ENDIF
 2410ENDPROC
 2420:
 2430REM PROCnetgame_send : Send a message to the other end
 2440DEFPROCnetgame_send(msg$)
 2450IF ng_state=ngs_connected THEN
 2460 REM Send a data as a message to them
 2470 PROCsocket_sendline(ng_socket,"#Data"+msg$)
 2480ENDIF
 2490ENDPROC
 2500:
 2510REM FNnetgame_connect : Connect to someone ;-)
 2520DEFFNnetgame_connect(to$,port)
 2530LOCAL sock,ok
 2540IF ng_state<>ngs_disconnected THEN
 2550 PROCsocket_close(ng_socket)
 2560 ng_state=ngs_disconnected
 2570ENDIF
 2580REM Get a socket
 2590sock=FNsocket_createinet
 2600IF sock=-1 THEN
 2610 ok=FALSE:REM No sockets left
 2620ELSE
 2630 ok=FNsocket_connect(sock,FNinet_gethostbyname(to$),port)
 2640 IF ok THEN
 2650  REM Wooo... gotcha ! Send our application name ;-)
 2660  PROCsocket_sendline(sock,"#"+Appname$)
 2670  REM Allow us to read the buffer as text
 2680  PROCsocket_makebuffered(sock)
 2690  REM Mark the time we connected in case they're not ready
 2700  ng_time=TIME:ng_state=ngs_negotiate_orig
 2710  REM Remember the socket for later
 2720  ng_socket=sock
 2730 ELSE
 2740  REM Oh dear - no connection ;-(
 2750  PROCsocket_close(sock):ok=FALSE
 2760 ENDIF
 2770ENDIF
 2780=ok
 2790:
 2800REM FNnetgame_sitesmenu : Returns handle of sites menu
 2810DEFFNnetgame_sitesmenu
 2820IF ng_sitesm=0 THENPROCnetgame_makesites
 2830=ng_sitesm
 2840:
 2850REM PROCnetgame_makesites : Produces the sites menu
 2860DEFPROCnetgame_makesites
 2870LOCAL p%
 2880PROCdynmenu_restore(ng_sitesp)
 2890PROCdynmenu_menu("Sites")
 2900p%=ng_sitesl:REM The list of sites
 2910WHILE p%<>0
 2920 PROCdynmenu_add($(p%!4),"",0):REM Add entry
 2930 p%=!p%:REM Next item
 2940ENDWHILE
 2950ng_sitesm=FNdynmenu_end
 2960ENDPROC
 2970:
 2980REM PROCnetgame_readsites : Reads the sites menu in
 2990DEFPROCnetgame_readsites
 3000LOCAL i%,n%,a$,b$,p%
 3010REM First release any space already claimed
 3020WHILE ng_sitesl<>0
 3030 n%=!ng_sitesl:REM The next entry
 3040 PROCrelease(ng_sitesl!4):REM Release it's name
 3050 PROCrelease(ng_sitesl!8):REM Release the host
 3060 PROCrelease(ng_sitesl!12):REM Release the port name
 3070 PROCrelease(ng_sitesl):REM Release the site entry
 3080 ng_sitesl=n%
 3090ENDWHILE
 3100i%=OPENIN(Appdir$+".Sites")
 3110IF i%<>0 THEN
 3120 WHILE NOT EOF#i%
 3130  a$=GET$#i%
 3140  IF LEFT$(a$,1)<>"#" AND NOT EOF#i% THEN
 3150   b$=GET$#i%:REM Host <space> port
 3160   p%=FNclaim(16):REM Claim space for the block
 3170   !p%=ng_sitesl:ng_sitesl=p%:REM Add it to the list
 3180   p%!4=FNstrdup(a$)
 3190   p%!8=FNstrdup(LEFT$(b$,INSTR(b$+" "," ")-1))
 3200   p%!12=FNstrdup(FNstripspaces(MID$(b$,INSTR(b$+" "," ")+1)))
 3210  ENDIF
 3220 ENDWHILE
 3230 CLOSE#i%
 3240ENDIF
 3250ng_sitesm=0
 3260ENDPROC
 3270:
 3280REM PROCnetgame_selectsite : Selects the site number
 3290REM n% = number on menu
 3300REM win% = window for result
 3310REM h% = host icon, or -1 to ignore
 3320REM r% = port icon, or -1 to ignore
 3330REM m% = name icon, or -1 to ignore
 3340DEFPROCnetgame_selectsite(n%,win%,h%,r%,m%)
 3350LOCAL p%:p%=ng_sitesl:REM The list of sites
 3360WHILE p%<>0 AND n%<>0:n%-=1:p%=!p%:ENDWHILE:REM Find it
 3370IF p%<>0 THEN
 3380 IF h%<>-1 THENPROCseticontext(win%,h%,$(p%!8)):REM Host
 3390 IF r%<>-1 THENPROCseticontext(win%,r%,$(p%!12)):REM Port
 3400 IF m%<>-1 THENPROCseticontext(win%,m%,$(p%!4)):REM Name
 3410ENDIF
 3420ENDPROC
 3430:
 3440REM PROCnetgame_editsites : Start editing the sites available
 3450DEFPROCnetgame_editsites(p%)
 3460LOCAL h%,a$:IF p%>0 THENa$=" -port "+STR$p% ELSEa$=""
 3480REM Start the Site editor
 3490SYS "XWimp_StartTask","SiteEdit -app "+Appname$+" -task "+STR$taskhandle+" -site "+Appdir$+".Sites"+a$ TO h%
 3500IF h%=0 THEN
 3510 REM It didn't start... load it into a text editor
 3520 SYS "Wimp_StartTask","Filer_Run "+Appdir$+".Sites"
 3530ENDIF
 3540ENDPROC

� >NetGameLib
� Network game support
� � Justin Fletcher, 1997
( � Version 1.02 : 17 Jun 1997
2-� &803,"Don't run this, it's a library !"
<�
F:
P'� Routines which must be supplied :
Z"� DEFPROCconnected(host$,type)
d4�   Will be called when we have connected safely
n;�   type = ngs_originate if we requested the connection
x3�        = ngs_answer if we have been contacted
�� DEFPROCdisconnected(type)
�+�   Will be called when they disconnect
�:�   type = ngs_dead if the connection was just dropped
�3�        = ngs_going if they are leaving nicely
�� DEFPROCincoming(text$)
�?�   Will be called when we get a message from the other end
��
�%� Routines which must be called :
�� port=FNnetgame_init(port)
�1�   Call when you want to initialise the game
�<�   May return -1 to say it couldn't initialise properly
�� PROCnetgame_poll
�A�   Call this every so often to check if things are happening
9�   Once a Wimp_Poll, or Wimp_PollIdle if sufficient.
� PROCnetgame_disconnect
+�   Call this if you want to disconnect
"#� PROCnetgame_connect(to$,port)
,<�   Call this if you want to connect to another computer
6� PROCnetgame_send(msg$)
@6�   Call this to send a message to another program
J:
TA� ****************** Network support ************************
^:
h0� FNnetgame_init : initialise a network game
r9� returns the port we are listening on, or -1 if none
|ݤnetgame_init(port)
�*ț "<SocketLibrary$File>":�initsockets
�,ț "<DynMenuLibrary$File>":�init_dynmenu
�*ngs_disconnected=0:� Not connected yet
�Angs_negotiate_orig=1:� Connected originate, but not validated
�=ngs_negotiate_ans=2:� Connected answer, but not validated
�-ngs_connected=3:� Connected and validated
�?ngs_dead=0:� Code used when they disconnect without goodbye
�5ngs_going=1:� Code used when they disconnected ok
�>ngs_failed=2:� Code used when we couldn't get a connection
�Cngs_originate=0:� Code used when we are talking to someone else
�:ngs_answer=1:� Code used when someone is talking to us
�*ng_conto$="":� Who we are connected to
� ng_socket=-1:� Not connected
-ng_state=ngs_disconnected:� Not connected
:ng_time=0:� The last time they spoke (to catch idlers)
'ng_idle=3000:� 30 seconds idle time
&*ng_sitesp=0:� The preserved sites menu
0 ng_sitesm=0:� The sites menu
: ng_sitesl=0:� The sites list
D ng_listen=�socket_createinet
N� ng_listen<>-1 �
X4 ng_port=�socket_findlisten(ng_listen,0,port,15)
b�
l ng_port=-1
v�
�=ng_port
�:
�1� PROCnetgame_final : finalise a network game
�!� shuts down the network game
���netgame_final
��socket_close(ng_listen)
�"� ng_state<>ngs_disconnected �
� ng_state=ngs_disconnected
� �socket_close(ng_socket)
��
��closesockets
��
�:
B� FNnetgame_connected : check if we are connected (TRUE if so)
C� FNnetgame_theirname : return their hostname (or null if none)
ݤnetgame_connected
 =(ng_state=ngs_connected)
*ݤnetgame_theirname
4(� ng_state=ngs_connected �=ng_conto$
>=""
H:
R.� netgame_poll : find out what's happening
\��netgame_poll
f� sock,len,start,ptr
pȎ ng_state �
z/ � ngs_disconnected:� Awaiting a connection
�)  ng_socket=�socket_accept(ng_listen)
�  � Is there a connection ?
�  � ng_socket<>-1 �
�%   � Yes, lets find out who it is
�/   ng_conto$=�socket_getpeername(ng_socket)
�/   � We're now negotiating for a connection
�!   ng_state=ngs_negotiate_ans
�%   � Mark the time they connected
�   ng_time=�
�,   � Allow us to read the buffer as text
�&   �socket_makebuffered(ng_socket)
�  �
�+ � ngs_negotiate_orig,ngs_negotiate_ans
0  � Awaiting a message from them saying 'ok'
  � �>ng_time+ng_idle �
2   � They took too long to respond - kill them
$   �socket_close(ng_socket)
.&   � ng_state=ngs_negotiate_orig �
8#    � Couldn't get a connection
B!    �disconnected(ngs_failed)
L   �
V    ng_state=ngs_disconnected
`  �
j%   sock=�socket_accept(ng_listen)
t%   � Has someone else connected ?
~   � sock<>-1 �
�:    �socket_sendline(sock,"#Game already in progress")
�    �socket_close(sock)
�   �
�"    � �socket_eof(ng_socket) �
�"     � They came and they went
�!     �socket_close(ng_socket)
�(     � ng_state=ngs_negotiate_orig �
�%      � Couldn't get a connection
�#      �disconnected(ngs_failed)
�
     �
�"     ng_state=ngs_disconnected
�	    �
.     len=�socket_readline(ng_socket,start)

     � len<>-1 �
!      � We received something
      ptr=0
(      ȕ ptr<len
2/       line$=�buffer_getrest(start,len,ptr)
<       � �line$,1)<>"#" �
F$        � Bad opener - kill them
P$        �socket_close(ng_socket)
Z+        � ng_state=ngs_negotiate_orig �
d(         � Couldn't get a connection
n&         �disconnected(ngs_failed)
x
        �
�%        ng_state=ngs_disconnected
�       �
�*        � ng_state=ngs_negotiate_ans �
�         � We're answering
�#         � �line$,2)=Appname$ �
�/          � Hey, good connection - say hi !
�=          �socket_sendline(ng_socket,"#Hi! Let's play !")
�7          � Yeah ! Got one ! Tell user who they are
�.          �connected(ng_conto$,ngs_answer)
�$          ng_state=ngs_connected
�         �
�<          � No, you're playing the wrong game, go away !
�=          �socket_sendline(ng_socket,"#No! Wrong game !")
          � Kill 'em
&          �socket_close(ng_socket)
'          ng_state=ngs_disconnected
"         �
,
        �
6         � We're originate
@!         � �line$,4)="#Hi!" �
J*          � Good connection made by us
T6          ng_conto$=�socket_getpeername(ng_socket)
^1          �connected(ng_conto$,ngs_originate)
h$          ng_state=ngs_connected
r         �
|;          � They said the wrong thing, walk out on them
�&          �socket_close(ng_socket)
�)          � Couldn't get a connection
�'          �disconnected(ngs_failed)
�'          ng_state=ngs_disconnected
�         �
�
        �
�       �
�      �
�
     �
�	    �
�   �
�  �
�  � ngs_connected:� Game on !
$  sock=�socket_accept(ng_listen)
$  � Has someone else connected ?
  � sock<>-1 �
&9   �socket_sendline(sock,"#Game already in progress")
0   �socket_close(sock)
:  �
D!   � �socket_eof(ng_socket) �
N(    � They've gone, so tell the user
X    �disconnected(ngs_dead)
b"    � And kill the dead socket
l    �socket_close(sock)
v!    ng_state=ngs_disconnected
�   �
�-    len=�socket_readline(ng_socket,start)
�    � len<>-1 �
�      � We received something
�     ptr=0
�     ȕ ptr<len
�.      line$=�buffer_getrest(start,len,ptr)
�      � �line$,1)<>"#" �
�,       � Bad first character - kill them
�       �socket_close(sock)
�"       �disconnected(ngs_dead)
�$       ng_state=ngs_disconnected
�      �
3       � Command ok - pass it on to the program
       line$=�line$,2)
       Ȏ �line$,4) �
 4        � "Data":� Message from the user program
*!         �incoming(�line$,5))
4&        � "Cya!":� Peer go bye-bye
>%         �disconnected(ngs_going)
H%         �socket_close(ng_socket)
R&         ng_state=ngs_disconnected
\
        
f>         � Help... I dunno what's going on - let's kill em
p$         �disconnected(ngs_dead)
z%         �socket_close(ng_socket)
�&         ng_state=ngs_disconnected
�       �
�      �
�
     �
�	    �
�   �
�  �
�
� :� What's going on !
�3  quit%=�:� Exit because the game is in trouble
��
��
�:
	:� PROCnetgame_disconnect : Disconnect us from them ;-(
	��netgame_disconnect
	"� ng_state<>ngs_disconnected �
	$# � Say goodbye, like a nice boy
	.( �socket_sendline(ng_socket,"#Cya!")
	8 � Bye bye, little socket
	B �socket_close(ng_socket)
	L* � Hey, we're not connected any more !
	V ng_state=ngs_disconnected
	`�
	j�
	t:
	~8� PROCnetgame_send : Send a message to the other end
	���netgame_send(msg$)
	�� ng_state=ngs_connected �
	�' � Send a data as a message to them
	�- �socket_sendline(ng_socket,"#Data"+msg$)
	��
	��
	�:
	�0� FNnetgame_connect : Connect to someone ;-)
	�ݤnetgame_connect(to$,port)
	�
� sock,ok
	�"� ng_state<>ngs_disconnected �
	� �socket_close(ng_socket)
 ng_state=ngs_disconnected

�
� Get a socket
sock=�socket_createinet
(� sock=-1 �
2 ok=�:� No sockets left
<�
F; ok=�socket_connect(sock,�inet_gethostbyname(to$),port)
P � ok �
Z6  � Wooo... gotcha ! Send our application name ;-)
d)  �socket_sendline(sock,"#"+Appname$)
n+  � Allow us to read the buffer as text
x   �socket_makebuffered(sock)
�<  � Mark the time we connected in case they're not ready
�+  ng_time=�:ng_state=ngs_negotiate_orig
�%  � Remember the socket for later
�  ng_socket=sock
� �
�#  � Oh dear - no connection ;-(
�  �socket_close(sock):ok=�
� �
��
�=ok
�:
�8� FNnetgame_sitesmenu : Returns handle of sites menu
�ݤnetgame_sitesmenu
%� ng_sitesm=0 ��netgame_makesites
=ng_sitesm
:
"5� PROCnetgame_makesites : Produces the sites menu
,��netgame_makesites
6� p%
@�dynmenu_restore(ng_sitesp)
J�dynmenu_menu("Sites")
T$p%=ng_sitesl:� The list of sites
^ȕ p%<>0
h+ �dynmenu_add($(p%!4),"",0):� Add entry
r p%=!p%:� Next item
|�
�ng_sitesm=�dynmenu_end
��
�:
�5� PROCnetgame_readsites : Reads the sites menu in
���netgame_readsites
�� i%,n%,a$,b$,p%
�-� First release any space already claimed
�ȕ ng_sitesl<>0
�# n%=!ng_sitesl:� The next entry
�. �release(ng_sitesl!4):� Release it's name
�- �release(ng_sitesl!8):� Release the host
�3 �release(ng_sitesl!12):� Release the port name
�1 �release(ng_sitesl):� Release the site entry
 ng_sitesl=n%
�
i%=�(Appdir$+".Sites")
&
� i%<>0 �
0 ȕ � �#i%
:
  a$=�#i%
D  � �a$,1)<>"#" � � �#i% �
N"   b$=�#i%:� Host <space> port
X0   p%=�claim(16):� Claim space for the block
b6   !p%=ng_sitesl:ng_sitesl=p%:� Add it to the list
l   p%!4=�strdup(a$)
v(   p%!8=�strdup(�b$,�b$+" "," ")-1))
�7   p%!12=�strdup(�stripspaces(�b$,�b$+" "," ")+1)))
�  �
� �
�	 �#i%
��
�ng_sitesm=0
��
�:
�6� PROCnetgame_selectsite : Selects the site number
�� n% = number on menu
�� win% = window for result
�%� h% = host icon, or -1 to ignore
�%� r% = port icon, or -1 to ignore

%� m% = name icon, or -1 to ignore

*��netgame_selectsite(n%,win%,h%,r%,m%)

)� p%:p%=ng_sitesl:� The list of sites

 -ȕ p%<>0 � n%<>0:n%-=1:p%=!p%:�:� Find it

*
� p%<>0 �

43 � h%<>-1 ��seticontext(win%,h%,$(p%!8)):� Host

>4 � r%<>-1 ��seticontext(win%,r%,$(p%!12)):� Port

H3 � m%<>-1 ��seticontext(win%,m%,$(p%!4)):� Name

R�

\�

f:

p?� PROCnetgame_editsites : Start editing the sites available

z��netgame_editsites(p%)

�+� h%,a$:� p%>0 �a$=" -port "+�p% �a$=""

�� Start the Site editor

�kș "XWimp_StartTask","SiteEdit -app "+Appname$+" -task "+�taskhandle+" -site "+Appdir$+".Sites"+a$ � h%

�� h%=0 �

�4 � It didn't start... load it into a text editor

�6 ș "Wimp_StartTask","Filer_Run "+Appdir$+".Sites"

��

��
�
00000000  0d 00 0a 11 f4 20 3e 4e  65 74 47 61 6d 65 4c 69  |..... >NetGameLi|
00000010  62 0d 00 14 1a f4 20 4e  65 74 77 6f 72 6b 20 67  |b..... Network g|
00000020  61 6d 65 20 73 75 70 70  6f 72 74 0d 00 1e 1d f4  |ame support.....|
00000030  20 a9 20 4a 75 73 74 69  6e 20 46 6c 65 74 63 68  | . Justin Fletch|
00000040  65 72 2c 20 31 39 39 37  0d 00 28 20 f4 20 56 65  |er, 1997..( . Ve|
00000050  72 73 69 6f 6e 20 31 2e  30 32 20 3a 20 31 37 20  |rsion 1.02 : 17 |
00000060  4a 75 6e 20 31 39 39 37  0d 00 32 2d 85 20 26 38  |Jun 1997..2-. &8|
00000070  30 33 2c 22 44 6f 6e 27  74 20 72 75 6e 20 74 68  |03,"Don't run th|
00000080  69 73 2c 20 69 74 27 73  20 61 20 6c 69 62 72 61  |is, it's a libra|
00000090  72 79 20 21 22 0d 00 3c  05 e0 0d 00 46 05 3a 0d  |ry !"..<....F.:.|
000000a0  00 50 27 f4 20 52 6f 75  74 69 6e 65 73 20 77 68  |.P'. Routines wh|
000000b0  69 63 68 20 6d 75 73 74  20 62 65 20 73 75 70 70  |ich must be supp|
000000c0  6c 69 65 64 20 3a 0d 00  5a 22 f4 20 44 45 46 50  |lied :..Z". DEFP|
000000d0  52 4f 43 63 6f 6e 6e 65  63 74 65 64 28 68 6f 73  |ROCconnected(hos|
000000e0  74 24 2c 74 79 70 65 29  0d 00 64 34 f4 20 20 20  |t$,type)..d4.   |
000000f0  57 69 6c 6c 20 62 65 20  63 61 6c 6c 65 64 20 77  |Will be called w|
00000100  68 65 6e 20 77 65 20 68  61 76 65 20 63 6f 6e 6e  |hen we have conn|
00000110  65 63 74 65 64 20 73 61  66 65 6c 79 0d 00 6e 3b  |ected safely..n;|
00000120  f4 20 20 20 74 79 70 65  20 3d 20 6e 67 73 5f 6f  |.   type = ngs_o|
00000130  72 69 67 69 6e 61 74 65  20 69 66 20 77 65 20 72  |riginate if we r|
00000140  65 71 75 65 73 74 65 64  20 74 68 65 20 63 6f 6e  |equested the con|
00000150  6e 65 63 74 69 6f 6e 0d  00 78 33 f4 20 20 20 20  |nection..x3.    |
00000160  20 20 20 20 3d 20 6e 67  73 5f 61 6e 73 77 65 72  |    = ngs_answer|
00000170  20 69 66 20 77 65 20 68  61 76 65 20 62 65 65 6e  | if we have been|
00000180  20 63 6f 6e 74 61 63 74  65 64 0d 00 82 1f f4 20  | contacted..... |
00000190  44 45 46 50 52 4f 43 64  69 73 63 6f 6e 6e 65 63  |DEFPROCdisconnec|
000001a0  74 65 64 28 74 79 70 65  29 0d 00 8c 2b f4 20 20  |ted(type)...+.  |
000001b0  20 57 69 6c 6c 20 62 65  20 63 61 6c 6c 65 64 20  | Will be called |
000001c0  77 68 65 6e 20 74 68 65  79 20 64 69 73 63 6f 6e  |when they discon|
000001d0  6e 65 63 74 0d 00 96 3a  f4 20 20 20 74 79 70 65  |nect...:.   type|
000001e0  20 3d 20 6e 67 73 5f 64  65 61 64 20 69 66 20 74  | = ngs_dead if t|
000001f0  68 65 20 63 6f 6e 6e 65  63 74 69 6f 6e 20 77 61  |he connection wa|
00000200  73 20 6a 75 73 74 20 64  72 6f 70 70 65 64 0d 00  |s just dropped..|
00000210  a0 33 f4 20 20 20 20 20  20 20 20 3d 20 6e 67 73  |.3.        = ngs|
00000220  5f 67 6f 69 6e 67 20 69  66 20 74 68 65 79 20 61  |_going if they a|
00000230  72 65 20 6c 65 61 76 69  6e 67 20 6e 69 63 65 6c  |re leaving nicel|
00000240  79 0d 00 aa 1c f4 20 44  45 46 50 52 4f 43 69 6e  |y..... DEFPROCin|
00000250  63 6f 6d 69 6e 67 28 74  65 78 74 24 29 0d 00 b4  |coming(text$)...|
00000260  3f f4 20 20 20 57 69 6c  6c 20 62 65 20 63 61 6c  |?.   Will be cal|
00000270  6c 65 64 20 77 68 65 6e  20 77 65 20 67 65 74 20  |led when we get |
00000280  61 20 6d 65 73 73 61 67  65 20 66 72 6f 6d 20 74  |a message from t|
00000290  68 65 20 6f 74 68 65 72  20 65 6e 64 0d 00 be 05  |he other end....|
000002a0  f4 0d 00 c8 25 f4 20 52  6f 75 74 69 6e 65 73 20  |....%. Routines |
000002b0  77 68 69 63 68 20 6d 75  73 74 20 62 65 20 63 61  |which must be ca|
000002c0  6c 6c 65 64 20 3a 0d 00  d2 1f f4 20 70 6f 72 74  |lled :..... port|
000002d0  3d 46 4e 6e 65 74 67 61  6d 65 5f 69 6e 69 74 28  |=FNnetgame_init(|
000002e0  70 6f 72 74 29 0d 00 dc  31 f4 20 20 20 43 61 6c  |port)...1.   Cal|
000002f0  6c 20 77 68 65 6e 20 79  6f 75 20 77 61 6e 74 20  |l when you want |
00000300  74 6f 20 69 6e 69 74 69  61 6c 69 73 65 20 74 68  |to initialise th|
00000310  65 20 67 61 6d 65 0d 00  e6 3c f4 20 20 20 4d 61  |e game...<.   Ma|
00000320  79 20 72 65 74 75 72 6e  20 2d 31 20 74 6f 20 73  |y return -1 to s|
00000330  61 79 20 69 74 20 63 6f  75 6c 64 6e 27 74 20 69  |ay it couldn't i|
00000340  6e 69 74 69 61 6c 69 73  65 20 70 72 6f 70 65 72  |nitialise proper|
00000350  6c 79 0d 00 f0 16 f4 20  50 52 4f 43 6e 65 74 67  |ly..... PROCnetg|
00000360  61 6d 65 5f 70 6f 6c 6c  0d 00 fa 41 f4 20 20 20  |ame_poll...A.   |
00000370  43 61 6c 6c 20 74 68 69  73 20 65 76 65 72 79 20  |Call this every |
00000380  73 6f 20 6f 66 74 65 6e  20 74 6f 20 63 68 65 63  |so often to chec|
00000390  6b 20 69 66 20 74 68 69  6e 67 73 20 61 72 65 20  |k if things are |
000003a0  68 61 70 70 65 6e 69 6e  67 0d 01 04 39 f4 20 20  |happening...9.  |
000003b0  20 4f 6e 63 65 20 61 20  57 69 6d 70 5f 50 6f 6c  | Once a Wimp_Pol|
000003c0  6c 2c 20 6f 72 20 57 69  6d 70 5f 50 6f 6c 6c 49  |l, or Wimp_PollI|
000003d0  64 6c 65 20 69 66 20 73  75 66 66 69 63 69 65 6e  |dle if sufficien|
000003e0  74 2e 0d 01 0e 1c f4 20  50 52 4f 43 6e 65 74 67  |t...... PROCnetg|
000003f0  61 6d 65 5f 64 69 73 63  6f 6e 6e 65 63 74 0d 01  |ame_disconnect..|
00000400  18 2b f4 20 20 20 43 61  6c 6c 20 74 68 69 73 20  |.+.   Call this |
00000410  69 66 20 79 6f 75 20 77  61 6e 74 20 74 6f 20 64  |if you want to d|
00000420  69 73 63 6f 6e 6e 65 63  74 0d 01 22 23 f4 20 50  |isconnect.."#. P|
00000430  52 4f 43 6e 65 74 67 61  6d 65 5f 63 6f 6e 6e 65  |ROCnetgame_conne|
00000440  63 74 28 74 6f 24 2c 70  6f 72 74 29 0d 01 2c 3c  |ct(to$,port)..,<|
00000450  f4 20 20 20 43 61 6c 6c  20 74 68 69 73 20 69 66  |.   Call this if|
00000460  20 79 6f 75 20 77 61 6e  74 20 74 6f 20 63 6f 6e  | you want to con|
00000470  6e 65 63 74 20 74 6f 20  61 6e 6f 74 68 65 72 20  |nect to another |
00000480  63 6f 6d 70 75 74 65 72  0d 01 36 1c f4 20 50 52  |computer..6.. PR|
00000490  4f 43 6e 65 74 67 61 6d  65 5f 73 65 6e 64 28 6d  |OCnetgame_send(m|
000004a0  73 67 24 29 0d 01 40 36  f4 20 20 20 43 61 6c 6c  |sg$)..@6.   Call|
000004b0  20 74 68 69 73 20 74 6f  20 73 65 6e 64 20 61 20  | this to send a |
000004c0  6d 65 73 73 61 67 65 20  74 6f 20 61 6e 6f 74 68  |message to anoth|
000004d0  65 72 20 70 72 6f 67 72  61 6d 0d 01 4a 05 3a 0d  |er program..J.:.|
000004e0  01 54 41 f4 20 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |.TA. ***********|
000004f0  2a 2a 2a 2a 2a 2a 2a 20  4e 65 74 77 6f 72 6b 20  |******* Network |
00000500  73 75 70 70 6f 72 74 20  2a 2a 2a 2a 2a 2a 2a 2a  |support ********|
00000510  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
00000520  0d 01 5e 05 3a 0d 01 68  30 f4 20 46 4e 6e 65 74  |..^.:..h0. FNnet|
00000530  67 61 6d 65 5f 69 6e 69  74 20 3a 20 69 6e 69 74  |game_init : init|
00000540  69 61 6c 69 73 65 20 61  20 6e 65 74 77 6f 72 6b  |ialise a network|
00000550  20 67 61 6d 65 0d 01 72  39 f4 20 72 65 74 75 72  | game..r9. retur|
00000560  6e 73 20 74 68 65 20 70  6f 72 74 20 77 65 20 61  |ns the port we a|
00000570  72 65 20 6c 69 73 74 65  6e 69 6e 67 20 6f 6e 2c  |re listening on,|
00000580  20 6f 72 20 2d 31 20 69  66 20 6e 6f 6e 65 0d 01  | or -1 if none..|
00000590  7c 18 dd a4 6e 65 74 67  61 6d 65 5f 69 6e 69 74  ||...netgame_init|
000005a0  28 70 6f 72 74 29 0d 01  86 2a c8 9b 20 22 3c 53  |(port)...*.. "<S|
000005b0  6f 63 6b 65 74 4c 69 62  72 61 72 79 24 46 69 6c  |ocketLibrary$Fil|
000005c0  65 3e 22 3a f2 69 6e 69  74 73 6f 63 6b 65 74 73  |e>":.initsockets|
000005d0  0d 01 90 2c c8 9b 20 22  3c 44 79 6e 4d 65 6e 75  |...,.. "<DynMenu|
000005e0  4c 69 62 72 61 72 79 24  46 69 6c 65 3e 22 3a f2  |Library$File>":.|
000005f0  69 6e 69 74 5f 64 79 6e  6d 65 6e 75 0d 01 9a 2a  |init_dynmenu...*|
00000600  6e 67 73 5f 64 69 73 63  6f 6e 6e 65 63 74 65 64  |ngs_disconnected|
00000610  3d 30 3a f4 20 4e 6f 74  20 63 6f 6e 6e 65 63 74  |=0:. Not connect|
00000620  65 64 20 79 65 74 0d 01  a4 41 6e 67 73 5f 6e 65  |ed yet...Angs_ne|
00000630  67 6f 74 69 61 74 65 5f  6f 72 69 67 3d 31 3a f4  |gotiate_orig=1:.|
00000640  20 43 6f 6e 6e 65 63 74  65 64 20 6f 72 69 67 69  | Connected origi|
00000650  6e 61 74 65 2c 20 62 75  74 20 6e 6f 74 20 76 61  |nate, but not va|
00000660  6c 69 64 61 74 65 64 0d  01 ae 3d 6e 67 73 5f 6e  |lidated...=ngs_n|
00000670  65 67 6f 74 69 61 74 65  5f 61 6e 73 3d 32 3a f4  |egotiate_ans=2:.|
00000680  20 43 6f 6e 6e 65 63 74  65 64 20 61 6e 73 77 65  | Connected answe|
00000690  72 2c 20 62 75 74 20 6e  6f 74 20 76 61 6c 69 64  |r, but not valid|
000006a0  61 74 65 64 0d 01 b8 2d  6e 67 73 5f 63 6f 6e 6e  |ated...-ngs_conn|
000006b0  65 63 74 65 64 3d 33 3a  f4 20 43 6f 6e 6e 65 63  |ected=3:. Connec|
000006c0  74 65 64 20 61 6e 64 20  76 61 6c 69 64 61 74 65  |ted and validate|
000006d0  64 0d 01 c2 3f 6e 67 73  5f 64 65 61 64 3d 30 3a  |d...?ngs_dead=0:|
000006e0  f4 20 43 6f 64 65 20 75  73 65 64 20 77 68 65 6e  |. Code used when|
000006f0  20 74 68 65 79 20 64 69  73 63 6f 6e 6e 65 63 74  | they disconnect|
00000700  20 77 69 74 68 6f 75 74  20 67 6f 6f 64 62 79 65  | without goodbye|
00000710  0d 01 cc 35 6e 67 73 5f  67 6f 69 6e 67 3d 31 3a  |...5ngs_going=1:|
00000720  f4 20 43 6f 64 65 20 75  73 65 64 20 77 68 65 6e  |. Code used when|
00000730  20 74 68 65 79 20 64 69  73 63 6f 6e 6e 65 63 74  | they disconnect|
00000740  65 64 20 6f 6b 0d 01 d6  3e 6e 67 73 5f 66 61 69  |ed ok...>ngs_fai|
00000750  6c 65 64 3d 32 3a f4 20  43 6f 64 65 20 75 73 65  |led=2:. Code use|
00000760  64 20 77 68 65 6e 20 77  65 20 63 6f 75 6c 64 6e  |d when we couldn|
00000770  27 74 20 67 65 74 20 61  20 63 6f 6e 6e 65 63 74  |'t get a connect|
00000780  69 6f 6e 0d 01 e0 43 6e  67 73 5f 6f 72 69 67 69  |ion...Cngs_origi|
00000790  6e 61 74 65 3d 30 3a f4  20 43 6f 64 65 20 75 73  |nate=0:. Code us|
000007a0  65 64 20 77 68 65 6e 20  77 65 20 61 72 65 20 74  |ed when we are t|
000007b0  61 6c 6b 69 6e 67 20 74  6f 20 73 6f 6d 65 6f 6e  |alking to someon|
000007c0  65 20 65 6c 73 65 0d 01  ea 3a 6e 67 73 5f 61 6e  |e else...:ngs_an|
000007d0  73 77 65 72 3d 31 3a f4  20 43 6f 64 65 20 75 73  |swer=1:. Code us|
000007e0  65 64 20 77 68 65 6e 20  73 6f 6d 65 6f 6e 65 20  |ed when someone |
000007f0  69 73 20 74 61 6c 6b 69  6e 67 20 74 6f 20 75 73  |is talking to us|
00000800  0d 01 f4 2a 6e 67 5f 63  6f 6e 74 6f 24 3d 22 22  |...*ng_conto$=""|
00000810  3a f4 20 57 68 6f 20 77  65 20 61 72 65 20 63 6f  |:. Who we are co|
00000820  6e 6e 65 63 74 65 64 20  74 6f 0d 01 fe 20 6e 67  |nnected to... ng|
00000830  5f 73 6f 63 6b 65 74 3d  2d 31 3a f4 20 4e 6f 74  |_socket=-1:. Not|
00000840  20 63 6f 6e 6e 65 63 74  65 64 0d 02 08 2d 6e 67  | connected...-ng|
00000850  5f 73 74 61 74 65 3d 6e  67 73 5f 64 69 73 63 6f  |_state=ngs_disco|
00000860  6e 6e 65 63 74 65 64 3a  f4 20 4e 6f 74 20 63 6f  |nnected:. Not co|
00000870  6e 6e 65 63 74 65 64 0d  02 12 3a 6e 67 5f 74 69  |nnected...:ng_ti|
00000880  6d 65 3d 30 3a f4 20 54  68 65 20 6c 61 73 74 20  |me=0:. The last |
00000890  74 69 6d 65 20 74 68 65  79 20 73 70 6f 6b 65 20  |time they spoke |
000008a0  28 74 6f 20 63 61 74 63  68 20 69 64 6c 65 72 73  |(to catch idlers|
000008b0  29 0d 02 1c 27 6e 67 5f  69 64 6c 65 3d 33 30 30  |)...'ng_idle=300|
000008c0  30 3a f4 20 33 30 20 73  65 63 6f 6e 64 73 20 69  |0:. 30 seconds i|
000008d0  64 6c 65 20 74 69 6d 65  0d 02 26 2a 6e 67 5f 73  |dle time..&*ng_s|
000008e0  69 74 65 73 70 3d 30 3a  f4 20 54 68 65 20 70 72  |itesp=0:. The pr|
000008f0  65 73 65 72 76 65 64 20  73 69 74 65 73 20 6d 65  |eserved sites me|
00000900  6e 75 0d 02 30 20 6e 67  5f 73 69 74 65 73 6d 3d  |nu..0 ng_sitesm=|
00000910  30 3a f4 20 54 68 65 20  73 69 74 65 73 20 6d 65  |0:. The sites me|
00000920  6e 75 0d 02 3a 20 6e 67  5f 73 69 74 65 73 6c 3d  |nu..: ng_sitesl=|
00000930  30 3a f4 20 54 68 65 20  73 69 74 65 73 20 6c 69  |0:. The sites li|
00000940  73 74 0d 02 44 20 6e 67  5f 6c 69 73 74 65 6e 3d  |st..D ng_listen=|
00000950  a4 73 6f 63 6b 65 74 5f  63 72 65 61 74 65 69 6e  |.socket_createin|
00000960  65 74 0d 02 4e 15 e7 20  6e 67 5f 6c 69 73 74 65  |et..N.. ng_liste|
00000970  6e 3c 3e 2d 31 20 8c 0d  02 58 34 20 6e 67 5f 70  |n<>-1 ...X4 ng_p|
00000980  6f 72 74 3d a4 73 6f 63  6b 65 74 5f 66 69 6e 64  |ort=.socket_find|
00000990  6c 69 73 74 65 6e 28 6e  67 5f 6c 69 73 74 65 6e  |listen(ng_listen|
000009a0  2c 30 2c 70 6f 72 74 2c  31 35 29 0d 02 62 05 cc  |,0,port,15)..b..|
000009b0  0d 02 6c 0f 20 6e 67 5f  70 6f 72 74 3d 2d 31 0d  |..l. ng_port=-1.|
000009c0  02 76 05 cd 0d 02 80 0c  3d 6e 67 5f 70 6f 72 74  |.v......=ng_port|
000009d0  0d 02 8a 05 3a 0d 02 94  31 f4 20 50 52 4f 43 6e  |....:...1. PROCn|
000009e0  65 74 67 61 6d 65 5f 66  69 6e 61 6c 20 3a 20 66  |etgame_final : f|
000009f0  69 6e 61 6c 69 73 65 20  61 20 6e 65 74 77 6f 72  |inalise a networ|
00000a00  6b 20 67 61 6d 65 0d 02  9e 21 f4 20 73 68 75 74  |k game...!. shut|
00000a10  73 20 64 6f 77 6e 20 74  68 65 20 6e 65 74 77 6f  |s down the netwo|
00000a20  72 6b 20 67 61 6d 65 0d  02 a8 13 dd f2 6e 65 74  |rk game......net|
00000a30  67 61 6d 65 5f 66 69 6e  61 6c 0d 02 b2 1c f2 73  |game_final.....s|
00000a40  6f 63 6b 65 74 5f 63 6c  6f 73 65 28 6e 67 5f 6c  |ocket_close(ng_l|
00000a50  69 73 74 65 6e 29 0d 02  bc 22 e7 20 6e 67 5f 73  |isten)...". ng_s|
00000a60  74 61 74 65 3c 3e 6e 67  73 5f 64 69 73 63 6f 6e  |tate<>ngs_discon|
00000a70  6e 65 63 74 65 64 20 8c  0d 02 c6 1e 20 6e 67 5f  |nected ..... ng_|
00000a80  73 74 61 74 65 3d 6e 67  73 5f 64 69 73 63 6f 6e  |state=ngs_discon|
00000a90  6e 65 63 74 65 64 0d 02  d0 1d 20 f2 73 6f 63 6b  |nected.... .sock|
00000aa0  65 74 5f 63 6c 6f 73 65  28 6e 67 5f 73 6f 63 6b  |et_close(ng_sock|
00000ab0  65 74 29 0d 02 da 05 cd  0d 02 e4 11 f2 63 6c 6f  |et)..........clo|
00000ac0  73 65 73 6f 63 6b 65 74  73 0d 02 ee 05 e1 0d 02  |sesockets.......|
00000ad0  f8 05 3a 0d 03 02 42 f4  20 46 4e 6e 65 74 67 61  |..:...B. FNnetga|
00000ae0  6d 65 5f 63 6f 6e 6e 65  63 74 65 64 20 3a 20 63  |me_connected : c|
00000af0  68 65 63 6b 20 69 66 20  77 65 20 61 72 65 20 63  |heck if we are c|
00000b00  6f 6e 6e 65 63 74 65 64  20 28 54 52 55 45 20 69  |onnected (TRUE i|
00000b10  66 20 73 6f 29 0d 03 0c  43 f4 20 46 4e 6e 65 74  |f so)...C. FNnet|
00000b20  67 61 6d 65 5f 74 68 65  69 72 6e 61 6d 65 20 3a  |game_theirname :|
00000b30  20 72 65 74 75 72 6e 20  74 68 65 69 72 20 68 6f  | return their ho|
00000b40  73 74 6e 61 6d 65 20 28  6f 72 20 6e 75 6c 6c 20  |stname (or null |
00000b50  69 66 20 6e 6f 6e 65 29  0d 03 16 17 dd a4 6e 65  |if none)......ne|
00000b60  74 67 61 6d 65 5f 63 6f  6e 6e 65 63 74 65 64 0d  |tgame_connected.|
00000b70  03 20 1d 3d 28 6e 67 5f  73 74 61 74 65 3d 6e 67  |. .=(ng_state=ng|
00000b80  73 5f 63 6f 6e 6e 65 63  74 65 64 29 0d 03 2a 17  |s_connected)..*.|
00000b90  dd a4 6e 65 74 67 61 6d  65 5f 74 68 65 69 72 6e  |..netgame_theirn|
00000ba0  61 6d 65 0d 03 34 28 e7  20 6e 67 5f 73 74 61 74  |ame..4(. ng_stat|
00000bb0  65 3d 6e 67 73 5f 63 6f  6e 6e 65 63 74 65 64 20  |e=ngs_connected |
00000bc0  8c 3d 6e 67 5f 63 6f 6e  74 6f 24 0d 03 3e 07 3d  |.=ng_conto$..>.=|
00000bd0  22 22 0d 03 48 05 3a 0d  03 52 2e f4 20 6e 65 74  |""..H.:..R.. net|
00000be0  67 61 6d 65 5f 70 6f 6c  6c 20 3a 20 66 69 6e 64  |game_poll : find|
00000bf0  20 6f 75 74 20 77 68 61  74 27 73 20 68 61 70 70  | out what's happ|
00000c00  65 6e 69 6e 67 0d 03 5c  12 dd f2 6e 65 74 67 61  |ening..\...netga|
00000c10  6d 65 5f 70 6f 6c 6c 0d  03 66 18 ea 20 73 6f 63  |me_poll..f.. soc|
00000c20  6b 2c 6c 65 6e 2c 73 74  61 72 74 2c 70 74 72 0d  |k,len,start,ptr.|
00000c30  03 70 11 c8 8e 20 6e 67  5f 73 74 61 74 65 20 ca  |.p... ng_state .|
00000c40  0d 03 7a 2f 20 c9 20 6e  67 73 5f 64 69 73 63 6f  |..z/ . ngs_disco|
00000c50  6e 6e 65 63 74 65 64 3a  f4 20 41 77 61 69 74 69  |nnected:. Awaiti|
00000c60  6e 67 20 61 20 63 6f 6e  6e 65 63 74 69 6f 6e 0d  |ng a connection.|
00000c70  03 84 29 20 20 6e 67 5f  73 6f 63 6b 65 74 3d a4  |..)  ng_socket=.|
00000c80  73 6f 63 6b 65 74 5f 61  63 63 65 70 74 28 6e 67  |socket_accept(ng|
00000c90  5f 6c 69 73 74 65 6e 29  0d 03 8e 1f 20 20 f4 20  |_listen)....  . |
00000ca0  49 73 20 74 68 65 72 65  20 61 20 63 6f 6e 6e 65  |Is there a conne|
00000cb0  63 74 69 6f 6e 20 3f 0d  03 98 17 20 20 e7 20 6e  |ction ?....  . n|
00000cc0  67 5f 73 6f 63 6b 65 74  3c 3e 2d 31 20 8c 0d 03  |g_socket<>-1 ...|
00000cd0  a2 25 20 20 20 f4 20 59  65 73 2c 20 6c 65 74 73  |.%   . Yes, lets|
00000ce0  20 66 69 6e 64 20 6f 75  74 20 77 68 6f 20 69 74  | find out who it|
00000cf0  20 69 73 0d 03 ac 2f 20  20 20 6e 67 5f 63 6f 6e  | is.../   ng_con|
00000d00  74 6f 24 3d a4 73 6f 63  6b 65 74 5f 67 65 74 70  |to$=.socket_getp|
00000d10  65 65 72 6e 61 6d 65 28  6e 67 5f 73 6f 63 6b 65  |eername(ng_socke|
00000d20  74 29 0d 03 b6 2f 20 20  20 f4 20 57 65 27 72 65  |t).../   . We're|
00000d30  20 6e 6f 77 20 6e 65 67  6f 74 69 61 74 69 6e 67  | now negotiating|
00000d40  20 66 6f 72 20 61 20 63  6f 6e 6e 65 63 74 69 6f  | for a connectio|
00000d50  6e 0d 03 c0 21 20 20 20  6e 67 5f 73 74 61 74 65  |n...!   ng_state|
00000d60  3d 6e 67 73 5f 6e 65 67  6f 74 69 61 74 65 5f 61  |=ngs_negotiate_a|
00000d70  6e 73 0d 03 ca 25 20 20  20 f4 20 4d 61 72 6b 20  |ns...%   . Mark |
00000d80  74 68 65 20 74 69 6d 65  20 74 68 65 79 20 63 6f  |the time they co|
00000d90  6e 6e 65 63 74 65 64 0d  03 d4 10 20 20 20 6e 67  |nnected....   ng|
00000da0  5f 74 69 6d 65 3d 91 0d  03 de 2c 20 20 20 f4 20  |_time=....,   . |
00000db0  41 6c 6c 6f 77 20 75 73  20 74 6f 20 72 65 61 64  |Allow us to read|
00000dc0  20 74 68 65 20 62 75 66  66 65 72 20 61 73 20 74  | the buffer as t|
00000dd0  65 78 74 0d 03 e8 26 20  20 20 f2 73 6f 63 6b 65  |ext...&   .socke|
00000de0  74 5f 6d 61 6b 65 62 75  66 66 65 72 65 64 28 6e  |t_makebuffered(n|
00000df0  67 5f 73 6f 63 6b 65 74  29 0d 03 f2 07 20 20 cd  |g_socket)....  .|
00000e00  0d 03 fc 2b 20 c9 20 6e  67 73 5f 6e 65 67 6f 74  |...+ . ngs_negot|
00000e10  69 61 74 65 5f 6f 72 69  67 2c 6e 67 73 5f 6e 65  |iate_orig,ngs_ne|
00000e20  67 6f 74 69 61 74 65 5f  61 6e 73 0d 04 06 30 20  |gotiate_ans...0 |
00000e30  20 f4 20 41 77 61 69 74  69 6e 67 20 61 20 6d 65  | . Awaiting a me|
00000e40  73 73 61 67 65 20 66 72  6f 6d 20 74 68 65 6d 20  |ssage from them |
00000e50  73 61 79 69 6e 67 20 27  6f 6b 27 0d 04 10 1b 20  |saying 'ok'.... |
00000e60  20 e7 20 91 3e 6e 67 5f  74 69 6d 65 2b 6e 67 5f  | . .>ng_time+ng_|
00000e70  69 64 6c 65 20 8c 0d 04  1a 32 20 20 20 f4 20 54  |idle ....2   . T|
00000e80  68 65 79 20 74 6f 6f 6b  20 74 6f 6f 20 6c 6f 6e  |hey took too lon|
00000e90  67 20 74 6f 20 72 65 73  70 6f 6e 64 20 2d 20 6b  |g to respond - k|
00000ea0  69 6c 6c 20 74 68 65 6d  0d 04 24 1f 20 20 20 f2  |ill them..$.   .|
00000eb0  73 6f 63 6b 65 74 5f 63  6c 6f 73 65 28 6e 67 5f  |socket_close(ng_|
00000ec0  73 6f 63 6b 65 74 29 0d  04 2e 26 20 20 20 e7 20  |socket)...&   . |
00000ed0  6e 67 5f 73 74 61 74 65  3d 6e 67 73 5f 6e 65 67  |ng_state=ngs_neg|
00000ee0  6f 74 69 61 74 65 5f 6f  72 69 67 20 8c 0d 04 38  |otiate_orig ...8|
00000ef0  23 20 20 20 20 f4 20 43  6f 75 6c 64 6e 27 74 20  |#    . Couldn't |
00000f00  67 65 74 20 61 20 63 6f  6e 6e 65 63 74 69 6f 6e  |get a connection|
00000f10  0d 04 42 21 20 20 20 20  f2 64 69 73 63 6f 6e 6e  |..B!    .disconn|
00000f20  65 63 74 65 64 28 6e 67  73 5f 66 61 69 6c 65 64  |ected(ngs_failed|
00000f30  29 0d 04 4c 08 20 20 20  cd 0d 04 56 20 20 20 20  |)..L.   ...V    |
00000f40  6e 67 5f 73 74 61 74 65  3d 6e 67 73 5f 64 69 73  |ng_state=ngs_dis|
00000f50  63 6f 6e 6e 65 63 74 65  64 0d 04 60 07 20 20 cc  |connected..`.  .|
00000f60  0d 04 6a 25 20 20 20 73  6f 63 6b 3d a4 73 6f 63  |..j%   sock=.soc|
00000f70  6b 65 74 5f 61 63 63 65  70 74 28 6e 67 5f 6c 69  |ket_accept(ng_li|
00000f80  73 74 65 6e 29 0d 04 74  25 20 20 20 f4 20 48 61  |sten)..t%   . Ha|
00000f90  73 20 73 6f 6d 65 6f 6e  65 20 65 6c 73 65 20 63  |s someone else c|
00000fa0  6f 6e 6e 65 63 74 65 64  20 3f 0d 04 7e 13 20 20  |onnected ?..~.  |
00000fb0  20 e7 20 73 6f 63 6b 3c  3e 2d 31 20 8c 0d 04 88  | . sock<>-1 ....|
00000fc0  3a 20 20 20 20 f2 73 6f  63 6b 65 74 5f 73 65 6e  |:    .socket_sen|
00000fd0  64 6c 69 6e 65 28 73 6f  63 6b 2c 22 23 47 61 6d  |dline(sock,"#Gam|
00000fe0  65 20 61 6c 72 65 61 64  79 20 69 6e 20 70 72 6f  |e already in pro|
00000ff0  67 72 65 73 73 22 29 0d  04 92 1b 20 20 20 20 f2  |gress")....    .|
00001000  73 6f 63 6b 65 74 5f 63  6c 6f 73 65 28 73 6f 63  |socket_close(soc|
00001010  6b 29 0d 04 9c 08 20 20  20 cc 0d 04 a6 22 20 20  |k)....   ...."  |
00001020  20 20 e7 20 a4 73 6f 63  6b 65 74 5f 65 6f 66 28  |  . .socket_eof(|
00001030  6e 67 5f 73 6f 63 6b 65  74 29 20 8c 0d 04 b0 22  |ng_socket) ...."|
00001040  20 20 20 20 20 f4 20 54  68 65 79 20 63 61 6d 65  |     . They came|
00001050  20 61 6e 64 20 74 68 65  79 20 77 65 6e 74 0d 04  | and they went..|
00001060  ba 21 20 20 20 20 20 f2  73 6f 63 6b 65 74 5f 63  |.!     .socket_c|
00001070  6c 6f 73 65 28 6e 67 5f  73 6f 63 6b 65 74 29 0d  |lose(ng_socket).|
00001080  04 c4 28 20 20 20 20 20  e7 20 6e 67 5f 73 74 61  |..(     . ng_sta|
00001090  74 65 3d 6e 67 73 5f 6e  65 67 6f 74 69 61 74 65  |te=ngs_negotiate|
000010a0  5f 6f 72 69 67 20 8c 0d  04 ce 25 20 20 20 20 20  |_orig ....%     |
000010b0  20 f4 20 43 6f 75 6c 64  6e 27 74 20 67 65 74 20  | . Couldn't get |
000010c0  61 20 63 6f 6e 6e 65 63  74 69 6f 6e 0d 04 d8 23  |a connection...#|
000010d0  20 20 20 20 20 20 f2 64  69 73 63 6f 6e 6e 65 63  |      .disconnec|
000010e0  74 65 64 28 6e 67 73 5f  66 61 69 6c 65 64 29 0d  |ted(ngs_failed).|
000010f0  04 e2 0a 20 20 20 20 20  cd 0d 04 ec 22 20 20 20  |...     ...."   |
00001100  20 20 6e 67 5f 73 74 61  74 65 3d 6e 67 73 5f 64  |  ng_state=ngs_d|
00001110  69 73 63 6f 6e 6e 65 63  74 65 64 0d 04 f6 09 20  |isconnected.... |
00001120  20 20 20 cc 0d 05 00 2e  20 20 20 20 20 6c 65 6e  |   .....     len|
00001130  3d a4 73 6f 63 6b 65 74  5f 72 65 61 64 6c 69 6e  |=.socket_readlin|
00001140  65 28 6e 67 5f 73 6f 63  6b 65 74 2c 73 74 61 72  |e(ng_socket,star|
00001150  74 29 0d 05 0a 14 20 20  20 20 20 e7 20 6c 65 6e  |t)....     . len|
00001160  3c 3e 2d 31 20 8c 0d 05  14 21 20 20 20 20 20 20  |<>-1 ....!      |
00001170  f4 20 57 65 20 72 65 63  65 69 76 65 64 20 73 6f  |. We received so|
00001180  6d 65 74 68 69 6e 67 0d  05 1e 0f 20 20 20 20 20  |mething....     |
00001190  20 70 74 72 3d 30 0d 05  28 14 20 20 20 20 20 20  | ptr=0..(.      |
000011a0  c8 95 20 70 74 72 3c 6c  65 6e 0d 05 32 2f 20 20  |.. ptr<len..2/  |
000011b0  20 20 20 20 20 6c 69 6e  65 24 3d a4 62 75 66 66  |     line$=.buff|
000011c0  65 72 5f 67 65 74 72 65  73 74 28 73 74 61 72 74  |er_getrest(start|
000011d0  2c 6c 65 6e 2c 70 74 72  29 0d 05 3c 1d 20 20 20  |,len,ptr)..<.   |
000011e0  20 20 20 20 e7 20 c0 6c  69 6e 65 24 2c 31 29 3c  |    . .line$,1)<|
000011f0  3e 22 23 22 20 8c 0d 05  46 24 20 20 20 20 20 20  |>"#" ...F$      |
00001200  20 20 f4 20 42 61 64 20  6f 70 65 6e 65 72 20 2d  |  . Bad opener -|
00001210  20 6b 69 6c 6c 20 74 68  65 6d 0d 05 50 24 20 20  | kill them..P$  |
00001220  20 20 20 20 20 20 f2 73  6f 63 6b 65 74 5f 63 6c  |      .socket_cl|
00001230  6f 73 65 28 6e 67 5f 73  6f 63 6b 65 74 29 0d 05  |ose(ng_socket)..|
00001240  5a 2b 20 20 20 20 20 20  20 20 e7 20 6e 67 5f 73  |Z+        . ng_s|
00001250  74 61 74 65 3d 6e 67 73  5f 6e 65 67 6f 74 69 61  |tate=ngs_negotia|
00001260  74 65 5f 6f 72 69 67 20  8c 0d 05 64 28 20 20 20  |te_orig ...d(   |
00001270  20 20 20 20 20 20 f4 20  43 6f 75 6c 64 6e 27 74  |      . Couldn't|
00001280  20 67 65 74 20 61 20 63  6f 6e 6e 65 63 74 69 6f  | get a connectio|
00001290  6e 0d 05 6e 26 20 20 20  20 20 20 20 20 20 f2 64  |n..n&         .d|
000012a0  69 73 63 6f 6e 6e 65 63  74 65 64 28 6e 67 73 5f  |isconnected(ngs_|
000012b0  66 61 69 6c 65 64 29 0d  05 78 0d 20 20 20 20 20  |failed)..x.     |
000012c0  20 20 20 cd 0d 05 82 25  20 20 20 20 20 20 20 20  |   ....%        |
000012d0  6e 67 5f 73 74 61 74 65  3d 6e 67 73 5f 64 69 73  |ng_state=ngs_dis|
000012e0  63 6f 6e 6e 65 63 74 65  64 0d 05 8c 0c 20 20 20  |connected....   |
000012f0  20 20 20 20 cc 0d 05 96  2a 20 20 20 20 20 20 20  |    ....*       |
00001300  20 e7 20 6e 67 5f 73 74  61 74 65 3d 6e 67 73 5f  | . ng_state=ngs_|
00001310  6e 65 67 6f 74 69 61 74  65 5f 61 6e 73 20 8c 0d  |negotiate_ans ..|
00001320  05 a0 1e 20 20 20 20 20  20 20 20 20 f4 20 57 65  |...         . We|
00001330  27 72 65 20 61 6e 73 77  65 72 69 6e 67 0d 05 aa  |'re answering...|
00001340  23 20 20 20 20 20 20 20  20 20 e7 20 c1 6c 69 6e  |#         . .lin|
00001350  65 24 2c 32 29 3d 41 70  70 6e 61 6d 65 24 20 8c  |e$,2)=Appname$ .|
00001360  0d 05 b4 2f 20 20 20 20  20 20 20 20 20 20 f4 20  |.../          . |
00001370  48 65 79 2c 20 67 6f 6f  64 20 63 6f 6e 6e 65 63  |Hey, good connec|
00001380  74 69 6f 6e 20 2d 20 73  61 79 20 68 69 20 21 0d  |tion - say hi !.|
00001390  05 be 3d 20 20 20 20 20  20 20 20 20 20 f2 73 6f  |..=          .so|
000013a0  63 6b 65 74 5f 73 65 6e  64 6c 69 6e 65 28 6e 67  |cket_sendline(ng|
000013b0  5f 73 6f 63 6b 65 74 2c  22 23 48 69 21 20 4c 65  |_socket,"#Hi! Le|
000013c0  74 27 73 20 70 6c 61 79  20 21 22 29 0d 05 c8 37  |t's play !")...7|
000013d0  20 20 20 20 20 20 20 20  20 20 f4 20 59 65 61 68  |          . Yeah|
000013e0  20 21 20 47 6f 74 20 6f  6e 65 20 21 20 54 65 6c  | ! Got one ! Tel|
000013f0  6c 20 75 73 65 72 20 77  68 6f 20 74 68 65 79 20  |l user who they |
00001400  61 72 65 0d 05 d2 2e 20  20 20 20 20 20 20 20 20  |are....         |
00001410  20 f2 63 6f 6e 6e 65 63  74 65 64 28 6e 67 5f 63  | .connected(ng_c|
00001420  6f 6e 74 6f 24 2c 6e 67  73 5f 61 6e 73 77 65 72  |onto$,ngs_answer|
00001430  29 0d 05 dc 24 20 20 20  20 20 20 20 20 20 20 6e  |)...$          n|
00001440  67 5f 73 74 61 74 65 3d  6e 67 73 5f 63 6f 6e 6e  |g_state=ngs_conn|
00001450  65 63 74 65 64 0d 05 e6  0e 20 20 20 20 20 20 20  |ected....       |
00001460  20 20 cc 0d 05 f0 3c 20  20 20 20 20 20 20 20 20  |  ....<         |
00001470  20 f4 20 4e 6f 2c 20 79  6f 75 27 72 65 20 70 6c  | . No, you're pl|
00001480  61 79 69 6e 67 20 74 68  65 20 77 72 6f 6e 67 20  |aying the wrong |
00001490  67 61 6d 65 2c 20 67 6f  20 61 77 61 79 20 21 0d  |game, go away !.|
000014a0  05 fa 3d 20 20 20 20 20  20 20 20 20 20 f2 73 6f  |..=          .so|
000014b0  63 6b 65 74 5f 73 65 6e  64 6c 69 6e 65 28 6e 67  |cket_sendline(ng|
000014c0  5f 73 6f 63 6b 65 74 2c  22 23 4e 6f 21 20 57 72  |_socket,"#No! Wr|
000014d0  6f 6e 67 20 67 61 6d 65  20 21 22 29 0d 06 04 18  |ong game !")....|
000014e0  20 20 20 20 20 20 20 20  20 20 f4 20 4b 69 6c 6c  |          . Kill|
000014f0  20 27 65 6d 0d 06 0e 26  20 20 20 20 20 20 20 20  | 'em...&        |
00001500  20 20 f2 73 6f 63 6b 65  74 5f 63 6c 6f 73 65 28  |  .socket_close(|
00001510  6e 67 5f 73 6f 63 6b 65  74 29 0d 06 18 27 20 20  |ng_socket)...'  |
00001520  20 20 20 20 20 20 20 20  6e 67 5f 73 74 61 74 65  |        ng_state|
00001530  3d 6e 67 73 5f 64 69 73  63 6f 6e 6e 65 63 74 65  |=ngs_disconnecte|
00001540  64 0d 06 22 0e 20 20 20  20 20 20 20 20 20 cd 0d  |d..".         ..|
00001550  06 2c 0d 20 20 20 20 20  20 20 20 cc 0d 06 36 1e  |.,.        ...6.|
00001560  20 20 20 20 20 20 20 20  20 f4 20 57 65 27 72 65  |         . We're|
00001570  20 6f 72 69 67 69 6e 61  74 65 0d 06 40 21 20 20  | originate..@!  |
00001580  20 20 20 20 20 20 20 e7  20 c0 6c 69 6e 65 24 2c  |       . .line$,|
00001590  34 29 3d 22 23 48 69 21  22 20 8c 0d 06 4a 2a 20  |4)="#Hi!" ...J* |
000015a0  20 20 20 20 20 20 20 20  20 f4 20 47 6f 6f 64 20  |         . Good |
000015b0  63 6f 6e 6e 65 63 74 69  6f 6e 20 6d 61 64 65 20  |connection made |
000015c0  62 79 20 75 73 0d 06 54  36 20 20 20 20 20 20 20  |by us..T6       |
000015d0  20 20 20 6e 67 5f 63 6f  6e 74 6f 24 3d a4 73 6f  |   ng_conto$=.so|
000015e0  63 6b 65 74 5f 67 65 74  70 65 65 72 6e 61 6d 65  |cket_getpeername|
000015f0  28 6e 67 5f 73 6f 63 6b  65 74 29 0d 06 5e 31 20  |(ng_socket)..^1 |
00001600  20 20 20 20 20 20 20 20  20 f2 63 6f 6e 6e 65 63  |         .connec|
00001610  74 65 64 28 6e 67 5f 63  6f 6e 74 6f 24 2c 6e 67  |ted(ng_conto$,ng|
00001620  73 5f 6f 72 69 67 69 6e  61 74 65 29 0d 06 68 24  |s_originate)..h$|
00001630  20 20 20 20 20 20 20 20  20 20 6e 67 5f 73 74 61  |          ng_sta|
00001640  74 65 3d 6e 67 73 5f 63  6f 6e 6e 65 63 74 65 64  |te=ngs_connected|
00001650  0d 06 72 0e 20 20 20 20  20 20 20 20 20 cc 0d 06  |..r.         ...|
00001660  7c 3b 20 20 20 20 20 20  20 20 20 20 f4 20 54 68  ||;          . Th|
00001670  65 79 20 73 61 69 64 20  74 68 65 20 77 72 6f 6e  |ey said the wron|
00001680  67 20 74 68 69 6e 67 2c  20 77 61 6c 6b 20 6f 75  |g thing, walk ou|
00001690  74 20 6f 6e 20 74 68 65  6d 0d 06 86 26 20 20 20  |t on them...&   |
000016a0  20 20 20 20 20 20 20 f2  73 6f 63 6b 65 74 5f 63  |       .socket_c|
000016b0  6c 6f 73 65 28 6e 67 5f  73 6f 63 6b 65 74 29 0d  |lose(ng_socket).|
000016c0  06 90 29 20 20 20 20 20  20 20 20 20 20 f4 20 43  |..)          . C|
000016d0  6f 75 6c 64 6e 27 74 20  67 65 74 20 61 20 63 6f  |ouldn't get a co|
000016e0  6e 6e 65 63 74 69 6f 6e  0d 06 9a 27 20 20 20 20  |nnection...'    |
000016f0  20 20 20 20 20 20 f2 64  69 73 63 6f 6e 6e 65 63  |      .disconnec|
00001700  74 65 64 28 6e 67 73 5f  66 61 69 6c 65 64 29 0d  |ted(ngs_failed).|
00001710  06 a4 27 20 20 20 20 20  20 20 20 20 20 6e 67 5f  |..'          ng_|
00001720  73 74 61 74 65 3d 6e 67  73 5f 64 69 73 63 6f 6e  |state=ngs_discon|
00001730  6e 65 63 74 65 64 0d 06  ae 0e 20 20 20 20 20 20  |nected....      |
00001740  20 20 20 cd 0d 06 b8 0d  20 20 20 20 20 20 20 20  |   .....        |
00001750  cd 0d 06 c2 0c 20 20 20  20 20 20 20 cd 0d 06 cc  |.....       ....|
00001760  0b 20 20 20 20 20 20 ce  0d 06 d6 0a 20 20 20 20  |.      .....    |
00001770  20 cd 0d 06 e0 09 20 20  20 20 cd 0d 06 ea 08 20  | .....    ..... |
00001780  20 20 cd 0d 06 f4 07 20  20 cd 0d 06 fe 20 20 c9  |  .....  ....  .|
00001790  20 6e 67 73 5f 63 6f 6e  6e 65 63 74 65 64 3a f4  | ngs_connected:.|
000017a0  20 47 61 6d 65 20 6f 6e  20 21 0d 07 08 24 20 20  | Game on !...$  |
000017b0  73 6f 63 6b 3d a4 73 6f  63 6b 65 74 5f 61 63 63  |sock=.socket_acc|
000017c0  65 70 74 28 6e 67 5f 6c  69 73 74 65 6e 29 0d 07  |ept(ng_listen)..|
000017d0  12 24 20 20 f4 20 48 61  73 20 73 6f 6d 65 6f 6e  |.$  . Has someon|
000017e0  65 20 65 6c 73 65 20 63  6f 6e 6e 65 63 74 65 64  |e else connected|
000017f0  20 3f 0d 07 1c 12 20 20  e7 20 73 6f 63 6b 3c 3e  | ?....  . sock<>|
00001800  2d 31 20 8c 0d 07 26 39  20 20 20 f2 73 6f 63 6b  |-1 ...&9   .sock|
00001810  65 74 5f 73 65 6e 64 6c  69 6e 65 28 73 6f 63 6b  |et_sendline(sock|
00001820  2c 22 23 47 61 6d 65 20  61 6c 72 65 61 64 79 20  |,"#Game already |
00001830  69 6e 20 70 72 6f 67 72  65 73 73 22 29 0d 07 30  |in progress")..0|
00001840  1a 20 20 20 f2 73 6f 63  6b 65 74 5f 63 6c 6f 73  |.   .socket_clos|
00001850  65 28 73 6f 63 6b 29 0d  07 3a 07 20 20 cc 0d 07  |e(sock)..:.  ...|
00001860  44 21 20 20 20 e7 20 a4  73 6f 63 6b 65 74 5f 65  |D!   . .socket_e|
00001870  6f 66 28 6e 67 5f 73 6f  63 6b 65 74 29 20 8c 0d  |of(ng_socket) ..|
00001880  07 4e 28 20 20 20 20 f4  20 54 68 65 79 27 76 65  |.N(    . They've|
00001890  20 67 6f 6e 65 2c 20 73  6f 20 74 65 6c 6c 20 74  | gone, so tell t|
000018a0  68 65 20 75 73 65 72 0d  07 58 1f 20 20 20 20 f2  |he user..X.    .|
000018b0  64 69 73 63 6f 6e 6e 65  63 74 65 64 28 6e 67 73  |disconnected(ngs|
000018c0  5f 64 65 61 64 29 0d 07  62 22 20 20 20 20 f4 20  |_dead)..b"    . |
000018d0  41 6e 64 20 6b 69 6c 6c  20 74 68 65 20 64 65 61  |And kill the dea|
000018e0  64 20 73 6f 63 6b 65 74  0d 07 6c 1b 20 20 20 20  |d socket..l.    |
000018f0  f2 73 6f 63 6b 65 74 5f  63 6c 6f 73 65 28 73 6f  |.socket_close(so|
00001900  63 6b 29 0d 07 76 21 20  20 20 20 6e 67 5f 73 74  |ck)..v!    ng_st|
00001910  61 74 65 3d 6e 67 73 5f  64 69 73 63 6f 6e 6e 65  |ate=ngs_disconne|
00001920  63 74 65 64 0d 07 80 08  20 20 20 cc 0d 07 8a 2d  |cted....   ....-|
00001930  20 20 20 20 6c 65 6e 3d  a4 73 6f 63 6b 65 74 5f  |    len=.socket_|
00001940  72 65 61 64 6c 69 6e 65  28 6e 67 5f 73 6f 63 6b  |readline(ng_sock|
00001950  65 74 2c 73 74 61 72 74  29 0d 07 94 13 20 20 20  |et,start)....   |
00001960  20 e7 20 6c 65 6e 3c 3e  2d 31 20 8c 0d 07 9e 20  | . len<>-1 .... |
00001970  20 20 20 20 20 f4 20 57  65 20 72 65 63 65 69 76  |     . We receiv|
00001980  65 64 20 73 6f 6d 65 74  68 69 6e 67 0d 07 a8 0e  |ed something....|
00001990  20 20 20 20 20 70 74 72  3d 30 0d 07 b2 13 20 20  |     ptr=0....  |
000019a0  20 20 20 c8 95 20 70 74  72 3c 6c 65 6e 0d 07 bc  |   .. ptr<len...|
000019b0  2e 20 20 20 20 20 20 6c  69 6e 65 24 3d a4 62 75  |.      line$=.bu|
000019c0  66 66 65 72 5f 67 65 74  72 65 73 74 28 73 74 61  |ffer_getrest(sta|
000019d0  72 74 2c 6c 65 6e 2c 70  74 72 29 0d 07 c6 1c 20  |rt,len,ptr).... |
000019e0  20 20 20 20 20 e7 20 c0  6c 69 6e 65 24 2c 31 29  |     . .line$,1)|
000019f0  3c 3e 22 23 22 20 8c 0d  07 d0 2c 20 20 20 20 20  |<>"#" ....,     |
00001a00  20 20 f4 20 42 61 64 20  66 69 72 73 74 20 63 68  |  . Bad first ch|
00001a10  61 72 61 63 74 65 72 20  2d 20 6b 69 6c 6c 20 74  |aracter - kill t|
00001a20  68 65 6d 0d 07 da 1e 20  20 20 20 20 20 20 f2 73  |hem....       .s|
00001a30  6f 63 6b 65 74 5f 63 6c  6f 73 65 28 73 6f 63 6b  |ocket_close(sock|
00001a40  29 0d 07 e4 22 20 20 20  20 20 20 20 f2 64 69 73  |)..."       .dis|
00001a50  63 6f 6e 6e 65 63 74 65  64 28 6e 67 73 5f 64 65  |connected(ngs_de|
00001a60  61 64 29 0d 07 ee 24 20  20 20 20 20 20 20 6e 67  |ad)...$       ng|
00001a70  5f 73 74 61 74 65 3d 6e  67 73 5f 64 69 73 63 6f  |_state=ngs_disco|
00001a80  6e 6e 65 63 74 65 64 0d  07 f8 0b 20 20 20 20 20  |nnected....     |
00001a90  20 cc 0d 08 02 33 20 20  20 20 20 20 20 f4 20 43  | ....3       . C|
00001aa0  6f 6d 6d 61 6e 64 20 6f  6b 20 2d 20 70 61 73 73  |ommand ok - pass|
00001ab0  20 69 74 20 6f 6e 20 74  6f 20 74 68 65 20 70 72  | it on to the pr|
00001ac0  6f 67 72 61 6d 0d 08 0c  1a 20 20 20 20 20 20 20  |ogram....       |
00001ad0  6c 69 6e 65 24 3d c1 6c  69 6e 65 24 2c 32 29 0d  |line$=.line$,2).|
00001ae0  08 16 19 20 20 20 20 20  20 20 c8 8e 20 c0 6c 69  |...       .. .li|
00001af0  6e 65 24 2c 34 29 20 ca  0d 08 20 34 20 20 20 20  |ne$,4) ... 4    |
00001b00  20 20 20 20 c9 20 22 44  61 74 61 22 3a f4 20 4d  |    . "Data":. M|
00001b10  65 73 73 61 67 65 20 66  72 6f 6d 20 74 68 65 20  |essage from the |
00001b20  75 73 65 72 20 70 72 6f  67 72 61 6d 0d 08 2a 21  |user program..*!|
00001b30  20 20 20 20 20 20 20 20  20 f2 69 6e 63 6f 6d 69  |         .incomi|
00001b40  6e 67 28 c1 6c 69 6e 65  24 2c 35 29 29 0d 08 34  |ng(.line$,5))..4|
00001b50  26 20 20 20 20 20 20 20  20 c9 20 22 43 79 61 21  |&        . "Cya!|
00001b60  22 3a f4 20 50 65 65 72  20 67 6f 20 62 79 65 2d  |":. Peer go bye-|
00001b70  62 79 65 0d 08 3e 25 20  20 20 20 20 20 20 20 20  |bye..>%         |
00001b80  f2 64 69 73 63 6f 6e 6e  65 63 74 65 64 28 6e 67  |.disconnected(ng|
00001b90  73 5f 67 6f 69 6e 67 29  0d 08 48 25 20 20 20 20  |s_going)..H%    |
00001ba0  20 20 20 20 20 f2 73 6f  63 6b 65 74 5f 63 6c 6f  |     .socket_clo|
00001bb0  73 65 28 6e 67 5f 73 6f  63 6b 65 74 29 0d 08 52  |se(ng_socket)..R|
00001bc0  26 20 20 20 20 20 20 20  20 20 6e 67 5f 73 74 61  |&         ng_sta|
00001bd0  74 65 3d 6e 67 73 5f 64  69 73 63 6f 6e 6e 65 63  |te=ngs_disconnec|
00001be0  74 65 64 0d 08 5c 0d 20  20 20 20 20 20 20 20 7f  |ted..\.        .|
00001bf0  0d 08 66 3e 20 20 20 20  20 20 20 20 20 f4 20 48  |..f>         . H|
00001c00  65 6c 70 2e 2e 2e 20 49  20 64 75 6e 6e 6f 20 77  |elp... I dunno w|
00001c10  68 61 74 27 73 20 67 6f  69 6e 67 20 6f 6e 20 2d  |hat's going on -|
00001c20  20 6c 65 74 27 73 20 6b  69 6c 6c 20 65 6d 0d 08  | let's kill em..|
00001c30  70 24 20 20 20 20 20 20  20 20 20 f2 64 69 73 63  |p$         .disc|
00001c40  6f 6e 6e 65 63 74 65 64  28 6e 67 73 5f 64 65 61  |onnected(ngs_dea|
00001c50  64 29 0d 08 7a 25 20 20  20 20 20 20 20 20 20 f2  |d)..z%         .|
00001c60  73 6f 63 6b 65 74 5f 63  6c 6f 73 65 28 6e 67 5f  |socket_close(ng_|
00001c70  73 6f 63 6b 65 74 29 0d  08 84 26 20 20 20 20 20  |socket)...&     |
00001c80  20 20 20 20 6e 67 5f 73  74 61 74 65 3d 6e 67 73  |    ng_state=ngs|
00001c90  5f 64 69 73 63 6f 6e 6e  65 63 74 65 64 0d 08 8e  |_disconnected...|
00001ca0  0c 20 20 20 20 20 20 20  cb 0d 08 98 0b 20 20 20  |.       .....   |
00001cb0  20 20 20 cd 0d 08 a2 0a  20 20 20 20 20 ce 0d 08  |   .....     ...|
00001cc0  ac 09 20 20 20 20 cd 0d  08 b6 08 20 20 20 cd 0d  |..    .....   ..|
00001cd0  08 c0 07 20 20 cd 0d 08  ca 04 0d 08 d4 1a 20 7f  |...  ......... .|
00001ce0  3a f4 20 57 68 61 74 27  73 20 67 6f 69 6e 67 20  |:. What's going |
00001cf0  6f 6e 20 21 0d 08 de 33  20 20 71 75 69 74 25 3d  |on !...3  quit%=|
00001d00  b9 3a f4 20 45 78 69 74  20 62 65 63 61 75 73 65  |.:. Exit because|
00001d10  20 74 68 65 20 67 61 6d  65 20 69 73 20 69 6e 20  | the game is in |
00001d20  74 72 6f 75 62 6c 65 0d  08 e8 05 cb 0d 08 f2 05  |trouble.........|
00001d30  e1 0d 08 fc 05 3a 0d 09  06 3a f4 20 50 52 4f 43  |.....:...:. PROC|
00001d40  6e 65 74 67 61 6d 65 5f  64 69 73 63 6f 6e 6e 65  |netgame_disconne|
00001d50  63 74 20 3a 20 44 69 73  63 6f 6e 6e 65 63 74 20  |ct : Disconnect |
00001d60  75 73 20 66 72 6f 6d 20  74 68 65 6d 20 3b 2d 28  |us from them ;-(|
00001d70  0d 09 10 18 dd f2 6e 65  74 67 61 6d 65 5f 64 69  |......netgame_di|
00001d80  73 63 6f 6e 6e 65 63 74  0d 09 1a 22 e7 20 6e 67  |sconnect...". ng|
00001d90  5f 73 74 61 74 65 3c 3e  6e 67 73 5f 64 69 73 63  |_state<>ngs_disc|
00001da0  6f 6e 6e 65 63 74 65 64  20 8c 0d 09 24 23 20 f4  |onnected ...$# .|
00001db0  20 53 61 79 20 67 6f 6f  64 62 79 65 2c 20 6c 69  | Say goodbye, li|
00001dc0  6b 65 20 61 20 6e 69 63  65 20 62 6f 79 0d 09 2e  |ke a nice boy...|
00001dd0  28 20 f2 73 6f 63 6b 65  74 5f 73 65 6e 64 6c 69  |( .socket_sendli|
00001de0  6e 65 28 6e 67 5f 73 6f  63 6b 65 74 2c 22 23 43  |ne(ng_socket,"#C|
00001df0  79 61 21 22 29 0d 09 38  1d 20 f4 20 42 79 65 20  |ya!")..8. . Bye |
00001e00  62 79 65 2c 20 6c 69 74  74 6c 65 20 73 6f 63 6b  |bye, little sock|
00001e10  65 74 0d 09 42 1d 20 f2  73 6f 63 6b 65 74 5f 63  |et..B. .socket_c|
00001e20  6c 6f 73 65 28 6e 67 5f  73 6f 63 6b 65 74 29 0d  |lose(ng_socket).|
00001e30  09 4c 2a 20 f4 20 48 65  79 2c 20 77 65 27 72 65  |.L* . Hey, we're|
00001e40  20 6e 6f 74 20 63 6f 6e  6e 65 63 74 65 64 20 61  | not connected a|
00001e50  6e 79 20 6d 6f 72 65 20  21 0d 09 56 1e 20 6e 67  |ny more !..V. ng|
00001e60  5f 73 74 61 74 65 3d 6e  67 73 5f 64 69 73 63 6f  |_state=ngs_disco|
00001e70  6e 6e 65 63 74 65 64 0d  09 60 05 cd 0d 09 6a 05  |nnected..`....j.|
00001e80  e1 0d 09 74 05 3a 0d 09  7e 38 f4 20 50 52 4f 43  |...t.:..~8. PROC|
00001e90  6e 65 74 67 61 6d 65 5f  73 65 6e 64 20 3a 20 53  |netgame_send : S|
00001ea0  65 6e 64 20 61 20 6d 65  73 73 61 67 65 20 74 6f  |end a message to|
00001eb0  20 74 68 65 20 6f 74 68  65 72 20 65 6e 64 0d 09  | the other end..|
00001ec0  88 18 dd f2 6e 65 74 67  61 6d 65 5f 73 65 6e 64  |....netgame_send|
00001ed0  28 6d 73 67 24 29 0d 09  92 1e e7 20 6e 67 5f 73  |(msg$)..... ng_s|
00001ee0  74 61 74 65 3d 6e 67 73  5f 63 6f 6e 6e 65 63 74  |tate=ngs_connect|
00001ef0  65 64 20 8c 0d 09 9c 27  20 f4 20 53 65 6e 64 20  |ed ....' . Send |
00001f00  61 20 64 61 74 61 20 61  73 20 61 20 6d 65 73 73  |a data as a mess|
00001f10  61 67 65 20 74 6f 20 74  68 65 6d 0d 09 a6 2d 20  |age to them...- |
00001f20  f2 73 6f 63 6b 65 74 5f  73 65 6e 64 6c 69 6e 65  |.socket_sendline|
00001f30  28 6e 67 5f 73 6f 63 6b  65 74 2c 22 23 44 61 74  |(ng_socket,"#Dat|
00001f40  61 22 2b 6d 73 67 24 29  0d 09 b0 05 cd 0d 09 ba  |a"+msg$)........|
00001f50  05 e1 0d 09 c4 05 3a 0d  09 ce 30 f4 20 46 4e 6e  |......:...0. FNn|
00001f60  65 74 67 61 6d 65 5f 63  6f 6e 6e 65 63 74 20 3a  |etgame_connect :|
00001f70  20 43 6f 6e 6e 65 63 74  20 74 6f 20 73 6f 6d 65  | Connect to some|
00001f80  6f 6e 65 20 3b 2d 29 0d  09 d8 1f dd a4 6e 65 74  |one ;-)......net|
00001f90  67 61 6d 65 5f 63 6f 6e  6e 65 63 74 28 74 6f 24  |game_connect(to$|
00001fa0  2c 70 6f 72 74 29 0d 09  e2 0d ea 20 73 6f 63 6b  |,port)..... sock|
00001fb0  2c 6f 6b 0d 09 ec 22 e7  20 6e 67 5f 73 74 61 74  |,ok...". ng_stat|
00001fc0  65 3c 3e 6e 67 73 5f 64  69 73 63 6f 6e 6e 65 63  |e<>ngs_disconnec|
00001fd0  74 65 64 20 8c 0d 09 f6  1d 20 f2 73 6f 63 6b 65  |ted ..... .socke|
00001fe0  74 5f 63 6c 6f 73 65 28  6e 67 5f 73 6f 63 6b 65  |t_close(ng_socke|
00001ff0  74 29 0d 0a 00 1e 20 6e  67 5f 73 74 61 74 65 3d  |t).... ng_state=|
00002000  6e 67 73 5f 64 69 73 63  6f 6e 6e 65 63 74 65 64  |ngs_disconnected|
00002010  0d 0a 0a 05 cd 0d 0a 14  12 f4 20 47 65 74 20 61  |.......... Get a|
00002020  20 73 6f 63 6b 65 74 0d  0a 1e 1b 73 6f 63 6b 3d  | socket....sock=|
00002030  a4 73 6f 63 6b 65 74 5f  63 72 65 61 74 65 69 6e  |.socket_createin|
00002040  65 74 0d 0a 28 0f e7 20  73 6f 63 6b 3d 2d 31 20  |et..(.. sock=-1 |
00002050  8c 0d 0a 32 1b 20 6f 6b  3d a3 3a f4 20 4e 6f 20  |...2. ok=.:. No |
00002060  73 6f 63 6b 65 74 73 20  6c 65 66 74 0d 0a 3c 05  |sockets left..<.|
00002070  cc 0d 0a 46 3b 20 6f 6b  3d a4 73 6f 63 6b 65 74  |...F; ok=.socket|
00002080  5f 63 6f 6e 6e 65 63 74  28 73 6f 63 6b 2c a4 69  |_connect(sock,.i|
00002090  6e 65 74 5f 67 65 74 68  6f 73 74 62 79 6e 61 6d  |net_gethostbynam|
000020a0  65 28 74 6f 24 29 2c 70  6f 72 74 29 0d 0a 50 0b  |e(to$),port)..P.|
000020b0  20 e7 20 6f 6b 20 8c 0d  0a 5a 36 20 20 f4 20 57  | . ok ...Z6  . W|
000020c0  6f 6f 6f 2e 2e 2e 20 67  6f 74 63 68 61 20 21 20  |ooo... gotcha ! |
000020d0  53 65 6e 64 20 6f 75 72  20 61 70 70 6c 69 63 61  |Send our applica|
000020e0  74 69 6f 6e 20 6e 61 6d  65 20 3b 2d 29 0d 0a 64  |tion name ;-)..d|
000020f0  29 20 20 f2 73 6f 63 6b  65 74 5f 73 65 6e 64 6c  |)  .socket_sendl|
00002100  69 6e 65 28 73 6f 63 6b  2c 22 23 22 2b 41 70 70  |ine(sock,"#"+App|
00002110  6e 61 6d 65 24 29 0d 0a  6e 2b 20 20 f4 20 41 6c  |name$)..n+  . Al|
00002120  6c 6f 77 20 75 73 20 74  6f 20 72 65 61 64 20 74  |low us to read t|
00002130  68 65 20 62 75 66 66 65  72 20 61 73 20 74 65 78  |he buffer as tex|
00002140  74 0d 0a 78 20 20 20 f2  73 6f 63 6b 65 74 5f 6d  |t..x   .socket_m|
00002150  61 6b 65 62 75 66 66 65  72 65 64 28 73 6f 63 6b  |akebuffered(sock|
00002160  29 0d 0a 82 3c 20 20 f4  20 4d 61 72 6b 20 74 68  |)...<  . Mark th|
00002170  65 20 74 69 6d 65 20 77  65 20 63 6f 6e 6e 65 63  |e time we connec|
00002180  74 65 64 20 69 6e 20 63  61 73 65 20 74 68 65 79  |ted in case they|
00002190  27 72 65 20 6e 6f 74 20  72 65 61 64 79 0d 0a 8c  |'re not ready...|
000021a0  2b 20 20 6e 67 5f 74 69  6d 65 3d 91 3a 6e 67 5f  |+  ng_time=.:ng_|
000021b0  73 74 61 74 65 3d 6e 67  73 5f 6e 65 67 6f 74 69  |state=ngs_negoti|
000021c0  61 74 65 5f 6f 72 69 67  0d 0a 96 25 20 20 f4 20  |ate_orig...%  . |
000021d0  52 65 6d 65 6d 62 65 72  20 74 68 65 20 73 6f 63  |Remember the soc|
000021e0  6b 65 74 20 66 6f 72 20  6c 61 74 65 72 0d 0a a0  |ket for later...|
000021f0  14 20 20 6e 67 5f 73 6f  63 6b 65 74 3d 73 6f 63  |.  ng_socket=soc|
00002200  6b 0d 0a aa 06 20 cc 0d  0a b4 23 20 20 f4 20 4f  |k.... ....#  . O|
00002210  68 20 64 65 61 72 20 2d  20 6e 6f 20 63 6f 6e 6e  |h dear - no conn|
00002220  65 63 74 69 6f 6e 20 3b  2d 28 0d 0a be 1e 20 20  |ection ;-(....  |
00002230  f2 73 6f 63 6b 65 74 5f  63 6c 6f 73 65 28 73 6f  |.socket_close(so|
00002240  63 6b 29 3a 6f 6b 3d a3  0d 0a c8 06 20 cd 0d 0a  |ck):ok=..... ...|
00002250  d2 05 cd 0d 0a dc 07 3d  6f 6b 0d 0a e6 05 3a 0d  |.......=ok....:.|
00002260  0a f0 38 f4 20 46 4e 6e  65 74 67 61 6d 65 5f 73  |..8. FNnetgame_s|
00002270  69 74 65 73 6d 65 6e 75  20 3a 20 52 65 74 75 72  |itesmenu : Retur|
00002280  6e 73 20 68 61 6e 64 6c  65 20 6f 66 20 73 69 74  |ns handle of sit|
00002290  65 73 20 6d 65 6e 75 0d  0a fa 17 dd a4 6e 65 74  |es menu......net|
000022a0  67 61 6d 65 5f 73 69 74  65 73 6d 65 6e 75 0d 0b  |game_sitesmenu..|
000022b0  04 25 e7 20 6e 67 5f 73  69 74 65 73 6d 3d 30 20  |.%. ng_sitesm=0 |
000022c0  8c f2 6e 65 74 67 61 6d  65 5f 6d 61 6b 65 73 69  |..netgame_makesi|
000022d0  74 65 73 0d 0b 0e 0e 3d  6e 67 5f 73 69 74 65 73  |tes....=ng_sites|
000022e0  6d 0d 0b 18 05 3a 0d 0b  22 35 f4 20 50 52 4f 43  |m....:.."5. PROC|
000022f0  6e 65 74 67 61 6d 65 5f  6d 61 6b 65 73 69 74 65  |netgame_makesite|
00002300  73 20 3a 20 50 72 6f 64  75 63 65 73 20 74 68 65  |s : Produces the|
00002310  20 73 69 74 65 73 20 6d  65 6e 75 0d 0b 2c 17 dd  | sites menu..,..|
00002320  f2 6e 65 74 67 61 6d 65  5f 6d 61 6b 65 73 69 74  |.netgame_makesit|
00002330  65 73 0d 0b 36 08 ea 20  70 25 0d 0b 40 1f f2 64  |es..6.. p%..@..d|
00002340  79 6e 6d 65 6e 75 5f 72  65 73 74 6f 72 65 28 6e  |ynmenu_restore(n|
00002350  67 5f 73 69 74 65 73 70  29 0d 0b 4a 1a f2 64 79  |g_sitesp)..J..dy|
00002360  6e 6d 65 6e 75 5f 6d 65  6e 75 28 22 53 69 74 65  |nmenu_menu("Site|
00002370  73 22 29 0d 0b 54 24 70  25 3d 6e 67 5f 73 69 74  |s")..T$p%=ng_sit|
00002380  65 73 6c 3a f4 20 54 68  65 20 6c 69 73 74 20 6f  |esl:. The list o|
00002390  66 20 73 69 74 65 73 0d  0b 5e 0c c8 95 20 70 25  |f sites..^... p%|
000023a0  3c 3e 30 0d 0b 68 2b 20  f2 64 79 6e 6d 65 6e 75  |<>0..h+ .dynmenu|
000023b0  5f 61 64 64 28 24 28 70  25 21 34 29 2c 22 22 2c  |_add($(p%!4),"",|
000023c0  30 29 3a f4 20 41 64 64  20 65 6e 74 72 79 0d 0b  |0):. Add entry..|
000023d0  72 17 20 70 25 3d 21 70  25 3a f4 20 4e 65 78 74  |r. p%=!p%:. Next|
000023e0  20 69 74 65 6d 0d 0b 7c  05 ce 0d 0b 86 1a 6e 67  | item..|......ng|
000023f0  5f 73 69 74 65 73 6d 3d  a4 64 79 6e 6d 65 6e 75  |_sitesm=.dynmenu|
00002400  5f 65 6e 64 0d 0b 90 05  e1 0d 0b 9a 05 3a 0d 0b  |_end.........:..|
00002410  a4 35 f4 20 50 52 4f 43  6e 65 74 67 61 6d 65 5f  |.5. PROCnetgame_|
00002420  72 65 61 64 73 69 74 65  73 20 3a 20 52 65 61 64  |readsites : Read|
00002430  73 20 74 68 65 20 73 69  74 65 73 20 6d 65 6e 75  |s the sites menu|
00002440  20 69 6e 0d 0b ae 17 dd  f2 6e 65 74 67 61 6d 65  | in......netgame|
00002450  5f 72 65 61 64 73 69 74  65 73 0d 0b b8 14 ea 20  |_readsites..... |
00002460  69 25 2c 6e 25 2c 61 24  2c 62 24 2c 70 25 0d 0b  |i%,n%,a$,b$,p%..|
00002470  c2 2d f4 20 46 69 72 73  74 20 72 65 6c 65 61 73  |.-. First releas|
00002480  65 20 61 6e 79 20 73 70  61 63 65 20 61 6c 72 65  |e any space alre|
00002490  61 64 79 20 63 6c 61 69  6d 65 64 0d 0b cc 13 c8  |ady claimed.....|
000024a0  95 20 6e 67 5f 73 69 74  65 73 6c 3c 3e 30 0d 0b  |. ng_sitesl<>0..|
000024b0  d6 23 20 6e 25 3d 21 6e  67 5f 73 69 74 65 73 6c  |.# n%=!ng_sitesl|
000024c0  3a f4 20 54 68 65 20 6e  65 78 74 20 65 6e 74 72  |:. The next entr|
000024d0  79 0d 0b e0 2e 20 f2 72  65 6c 65 61 73 65 28 6e  |y.... .release(n|
000024e0  67 5f 73 69 74 65 73 6c  21 34 29 3a f4 20 52 65  |g_sitesl!4):. Re|
000024f0  6c 65 61 73 65 20 69 74  27 73 20 6e 61 6d 65 0d  |lease it's name.|
00002500  0b ea 2d 20 f2 72 65 6c  65 61 73 65 28 6e 67 5f  |..- .release(ng_|
00002510  73 69 74 65 73 6c 21 38  29 3a f4 20 52 65 6c 65  |sitesl!8):. Rele|
00002520  61 73 65 20 74 68 65 20  68 6f 73 74 0d 0b f4 33  |ase the host...3|
00002530  20 f2 72 65 6c 65 61 73  65 28 6e 67 5f 73 69 74  | .release(ng_sit|
00002540  65 73 6c 21 31 32 29 3a  f4 20 52 65 6c 65 61 73  |esl!12):. Releas|
00002550  65 20 74 68 65 20 70 6f  72 74 20 6e 61 6d 65 0d  |e the port name.|
00002560  0b fe 31 20 f2 72 65 6c  65 61 73 65 28 6e 67 5f  |..1 .release(ng_|
00002570  73 69 74 65 73 6c 29 3a  f4 20 52 65 6c 65 61 73  |sitesl):. Releas|
00002580  65 20 74 68 65 20 73 69  74 65 20 65 6e 74 72 79  |e the site entry|
00002590  0d 0c 08 11 20 6e 67 5f  73 69 74 65 73 6c 3d 6e  |.... ng_sitesl=n|
000025a0  25 0d 0c 12 05 ce 0d 0c  1c 1a 69 25 3d 8e 28 41  |%.........i%=.(A|
000025b0  70 70 64 69 72 24 2b 22  2e 53 69 74 65 73 22 29  |ppdir$+".Sites")|
000025c0  0d 0c 26 0d e7 20 69 25  3c 3e 30 20 8c 0d 0c 30  |..&.. i%<>0 ...0|
000025d0  0e 20 c8 95 20 ac 20 c5  23 69 25 0d 0c 3a 0d 20  |. .. . .#i%..:. |
000025e0  20 61 24 3d be 23 69 25  0d 0c 44 1e 20 20 e7 20  | a$=.#i%..D.  . |
000025f0  c0 61 24 2c 31 29 3c 3e  22 23 22 20 80 20 ac 20  |.a$,1)<>"#" . . |
00002600  c5 23 69 25 20 8c 0d 0c  4e 22 20 20 20 62 24 3d  |.#i% ...N"   b$=|
00002610  be 23 69 25 3a f4 20 48  6f 73 74 20 3c 73 70 61  |.#i%:. Host <spa|
00002620  63 65 3e 20 70 6f 72 74  0d 0c 58 30 20 20 20 70  |ce> port..X0   p|
00002630  25 3d a4 63 6c 61 69 6d  28 31 36 29 3a f4 20 43  |%=.claim(16):. C|
00002640  6c 61 69 6d 20 73 70 61  63 65 20 66 6f 72 20 74  |laim space for t|
00002650  68 65 20 62 6c 6f 63 6b  0d 0c 62 36 20 20 20 21  |he block..b6   !|
00002660  70 25 3d 6e 67 5f 73 69  74 65 73 6c 3a 6e 67 5f  |p%=ng_sitesl:ng_|
00002670  73 69 74 65 73 6c 3d 70  25 3a f4 20 41 64 64 20  |sitesl=p%:. Add |
00002680  69 74 20 74 6f 20 74 68  65 20 6c 69 73 74 0d 0c  |it to the list..|
00002690  6c 17 20 20 20 70 25 21  34 3d a4 73 74 72 64 75  |l.   p%!4=.strdu|
000026a0  70 28 61 24 29 0d 0c 76  28 20 20 20 70 25 21 38  |p(a$)..v(   p%!8|
000026b0  3d a4 73 74 72 64 75 70  28 c0 62 24 2c a7 62 24  |=.strdup(.b$,.b$|
000026c0  2b 22 20 22 2c 22 20 22  29 2d 31 29 29 0d 0c 80  |+" "," ")-1))...|
000026d0  37 20 20 20 70 25 21 31  32 3d a4 73 74 72 64 75  |7   p%!12=.strdu|
000026e0  70 28 a4 73 74 72 69 70  73 70 61 63 65 73 28 c1  |p(.stripspaces(.|
000026f0  62 24 2c a7 62 24 2b 22  20 22 2c 22 20 22 29 2b  |b$,.b$+" "," ")+|
00002700  31 29 29 29 0d 0c 8a 07  20 20 cd 0d 0c 94 06 20  |1)))....  ..... |
00002710  ce 0d 0c 9e 09 20 d9 23  69 25 0d 0c a8 05 cd 0d  |..... .#i%......|
00002720  0c b2 0f 6e 67 5f 73 69  74 65 73 6d 3d 30 0d 0c  |...ng_sitesm=0..|
00002730  bc 05 e1 0d 0c c6 05 3a  0d 0c d0 36 f4 20 50 52  |.......:...6. PR|
00002740  4f 43 6e 65 74 67 61 6d  65 5f 73 65 6c 65 63 74  |OCnetgame_select|
00002750  73 69 74 65 20 3a 20 53  65 6c 65 63 74 73 20 74  |site : Selects t|
00002760  68 65 20 73 69 74 65 20  6e 75 6d 62 65 72 0d 0c  |he site number..|
00002770  da 19 f4 20 6e 25 20 3d  20 6e 75 6d 62 65 72 20  |... n% = number |
00002780  6f 6e 20 6d 65 6e 75 0d  0c e4 1e f4 20 77 69 6e  |on menu..... win|
00002790  25 20 3d 20 77 69 6e 64  6f 77 20 66 6f 72 20 72  |% = window for r|
000027a0  65 73 75 6c 74 0d 0c ee  25 f4 20 68 25 20 3d 20  |esult...%. h% = |
000027b0  68 6f 73 74 20 69 63 6f  6e 2c 20 6f 72 20 2d 31  |host icon, or -1|
000027c0  20 74 6f 20 69 67 6e 6f  72 65 0d 0c f8 25 f4 20  | to ignore...%. |
000027d0  72 25 20 3d 20 70 6f 72  74 20 69 63 6f 6e 2c 20  |r% = port icon, |
000027e0  6f 72 20 2d 31 20 74 6f  20 69 67 6e 6f 72 65 0d  |or -1 to ignore.|
000027f0  0d 02 25 f4 20 6d 25 20  3d 20 6e 61 6d 65 20 69  |..%. m% = name i|
00002800  63 6f 6e 2c 20 6f 72 20  2d 31 20 74 6f 20 69 67  |con, or -1 to ig|
00002810  6e 6f 72 65 0d 0d 0c 2a  dd f2 6e 65 74 67 61 6d  |nore...*..netgam|
00002820  65 5f 73 65 6c 65 63 74  73 69 74 65 28 6e 25 2c  |e_selectsite(n%,|
00002830  77 69 6e 25 2c 68 25 2c  72 25 2c 6d 25 29 0d 0d  |win%,h%,r%,m%)..|
00002840  16 29 ea 20 70 25 3a 70  25 3d 6e 67 5f 73 69 74  |.). p%:p%=ng_sit|
00002850  65 73 6c 3a f4 20 54 68  65 20 6c 69 73 74 20 6f  |esl:. The list o|
00002860  66 20 73 69 74 65 73 0d  0d 20 2d c8 95 20 70 25  |f sites.. -.. p%|
00002870  3c 3e 30 20 80 20 6e 25  3c 3e 30 3a 6e 25 2d 3d  |<>0 . n%<>0:n%-=|
00002880  31 3a 70 25 3d 21 70 25  3a ce 3a f4 20 46 69 6e  |1:p%=!p%:.:. Fin|
00002890  64 20 69 74 0d 0d 2a 0d  e7 20 70 25 3c 3e 30 20  |d it..*.. p%<>0 |
000028a0  8c 0d 0d 34 33 20 e7 20  68 25 3c 3e 2d 31 20 8c  |...43 . h%<>-1 .|
000028b0  f2 73 65 74 69 63 6f 6e  74 65 78 74 28 77 69 6e  |.seticontext(win|
000028c0  25 2c 68 25 2c 24 28 70  25 21 38 29 29 3a f4 20  |%,h%,$(p%!8)):. |
000028d0  48 6f 73 74 0d 0d 3e 34  20 e7 20 72 25 3c 3e 2d  |Host..>4 . r%<>-|
000028e0  31 20 8c f2 73 65 74 69  63 6f 6e 74 65 78 74 28  |1 ..seticontext(|
000028f0  77 69 6e 25 2c 72 25 2c  24 28 70 25 21 31 32 29  |win%,r%,$(p%!12)|
00002900  29 3a f4 20 50 6f 72 74  0d 0d 48 33 20 e7 20 6d  |):. Port..H3 . m|
00002910  25 3c 3e 2d 31 20 8c f2  73 65 74 69 63 6f 6e 74  |%<>-1 ..seticont|
00002920  65 78 74 28 77 69 6e 25  2c 6d 25 2c 24 28 70 25  |ext(win%,m%,$(p%|
00002930  21 34 29 29 3a f4 20 4e  61 6d 65 0d 0d 52 05 cd  |!4)):. Name..R..|
00002940  0d 0d 5c 05 e1 0d 0d 66  05 3a 0d 0d 70 3f f4 20  |..\....f.:..p?. |
00002950  50 52 4f 43 6e 65 74 67  61 6d 65 5f 65 64 69 74  |PROCnetgame_edit|
00002960  73 69 74 65 73 20 3a 20  53 74 61 72 74 20 65 64  |sites : Start ed|
00002970  69 74 69 6e 67 20 74 68  65 20 73 69 74 65 73 20  |iting the sites |
00002980  61 76 61 69 6c 61 62 6c  65 0d 0d 7a 1b dd f2 6e  |available..z...n|
00002990  65 74 67 61 6d 65 5f 65  64 69 74 73 69 74 65 73  |etgame_editsites|
000029a0  28 70 25 29 0d 0d 84 2b  ea 20 68 25 2c 61 24 3a  |(p%)...+. h%,a$:|
000029b0  e7 20 70 25 3e 30 20 8c  61 24 3d 22 20 2d 70 6f  |. p%>0 .a$=" -po|
000029c0  72 74 20 22 2b c3 70 25  20 8b 61 24 3d 22 22 0d  |rt "+.p% .a$="".|
000029d0  0d 98 1b f4 20 53 74 61  72 74 20 74 68 65 20 53  |.... Start the S|
000029e0  69 74 65 20 65 64 69 74  6f 72 0d 0d a2 6b c8 99  |ite editor...k..|
000029f0  20 22 58 57 69 6d 70 5f  53 74 61 72 74 54 61 73  | "XWimp_StartTas|
00002a00  6b 22 2c 22 53 69 74 65  45 64 69 74 20 2d 61 70  |k","SiteEdit -ap|
00002a10  70 20 22 2b 41 70 70 6e  61 6d 65 24 2b 22 20 2d  |p "+Appname$+" -|
00002a20  74 61 73 6b 20 22 2b c3  74 61 73 6b 68 61 6e 64  |task "+.taskhand|
00002a30  6c 65 2b 22 20 2d 73 69  74 65 20 22 2b 41 70 70  |le+" -site "+App|
00002a40  64 69 72 24 2b 22 2e 53  69 74 65 73 22 2b 61 24  |dir$+".Sites"+a$|
00002a50  20 b8 20 68 25 0d 0d ac  0c e7 20 68 25 3d 30 20  | . h%..... h%=0 |
00002a60  8c 0d 0d b6 34 20 f4 20  49 74 20 64 69 64 6e 27  |....4 . It didn'|
00002a70  74 20 73 74 61 72 74 2e  2e 2e 20 6c 6f 61 64 20  |t start... load |
00002a80  69 74 20 69 6e 74 6f 20  61 20 74 65 78 74 20 65  |it into a text e|
00002a90  64 69 74 6f 72 0d 0d c0  36 20 c8 99 20 22 57 69  |ditor...6 .. "Wi|
00002aa0  6d 70 5f 53 74 61 72 74  54 61 73 6b 22 2c 22 46  |mp_StartTask","F|
00002ab0  69 6c 65 72 5f 52 75 6e  20 22 2b 41 70 70 64 69  |iler_Run "+Appdi|
00002ac0  72 24 2b 22 2e 53 69 74  65 73 22 0d 0d ca 05 cd  |r$+".Sites".....|
00002ad0  0d 0d d4 05 e1 0d ff                              |.......|
00002ad7