;-*-MIDAS-*-

	title BYE -- Call luser names and pontificate

;CODE ADDED 9-3-78 BY ED TO USE INQUIR DATA BASE FOR NICKNAME
;10/3/84 Chaosnet BYE server --Moon
;19/5/85 use BYELIB; essentially re-written -- gumby

printx /
Be sure to install the binary on all systems

/

a=1
b=2
c=3
d=4
e=5
f=6
cnt=7
t=15
tt=16
p=17

;;; IO channels
tyi==1
tyoch==2
linch==3
idxch==4                          ; index file input
odxch==5                          ; index file output
lsrch==6

;;; Random constants
pdlsiz==20                      ; pdl
ascbyt==440700                  ; ascii byte ptr waiting to be read

print=1000,,                    ;glik!

call=<pushj p,>
ret=<popj p,>

define	syscall	name,args
	.call	[setz ? sixbit /name/ ? args((setz))]
	termin

;;; Inquir database hackery
lsrpgs=100	;number of pages for lsrtab
$$ulnm==0	;don't assemble useless cruft.
$$ulnp==0
$$unam==0
.insrt syseng;lsrtns >

;;; Network hackery
netwrk"$$serve==1
netwrk"$$chaos==1
.insrt syseng;netwrk >

byelib"$$deth==1
.insrt syseng;byelib >

	subttl	figure out if we're a server; print out messges.

.scalar uname, server, pdl(pdlsiz)

begin:	move	p,[-pdlsiz,,pdl-1]
	.suset	[.rxuname,,uname]
	.suset	[.rjname,,a]
	came	a,[sixbit/chaos/]
	 call	ttyini
	  call	srvini
prlusr:	move	c,uname         ;print special "See you later" msg?
	move	a,[-hakn,,0]
hkloop:	move	b,haknms(a)
	camn	b,c
	 jrst	[print hakmsg
		jrst seewho]
	aobjn	a,hkloop
	print	[asciz /
See Ya Later /]
seewho:	call	unmout
	print	[asciz /... /]
nounam:	call	byelib"getmsg
	syscal	siot,[%climm,,tyoch ? %clin,,a ? %clin,,b]
	 jsr	death
	syscal	finish,[%climm,,tyoch]	;wait for all output to get to tty.
	 .lose	%lssys
	Skipe	server
	 jrst	srvend
exit:	.suset	[.roption,,c]
	tlnn	c,%opbrk        ; Don't .BREAK unless a superior handles it.
	 .logout 1,
	.break	16,124000       ;die as quitely as possible

srvend:	movei	t,netwrk"%coeof
	setzm	netwrk"pktbuf
	dpb	t,[netwrk"$cpkop+netwrk"pktbuf]
	syscal	pktiot,[%climm,,tyoch ? %climm,,netwrk"pktbuf]
	 jfcl
	syscal	finish,[%climm,,tyoch]
	 jfcl
	.sleep	c,		;seems to be needed for some reason
	.logout	1,		;to delay before closing

ttyini:	.suset	[.smask,,[%pityi]]
	syscal	open,[%clbit,,.uao ? %climm,,tyoch ? [sixbit/tty/]]
	 .lose	%lsfil
	syscal	open,[%clbit,,.uai ? %climm,,tyi ? [sixbit/tty/]]
	 .lose	%lsfil
	aos	(p)             ;return to .+2
	ret

srvini:	setom	server		;we're a chaosnet server, not talking to a tty
	.suset	[.smask,,[%piioc]]
	movei	a,tyi
	movei	c,[asciz/BYE/]
	movei	d,5
	call	netwrk"chasrv
	 .logout 1,
	move	a,[440600,,d]
	move	b,[440800,,netwrk"pktbuf+netwrk"%cpkdt]
	ldb	c,[netwrk"$cpknb+netwrk"pktbuf]
	movei	d,0
unmgt1:	ildb	e,b		;get user name from contact args
	caie	e,40
	 sojg	c,unmgt1
	sojle	c,nounam        ;just print msg w/o see ya later bullshit
unmgt2:	ildb	e,b
	caige	e,140
	 subi	e,40
	tlne	a,770000
	 idpb	e,a
	sojg	c,unmgt2
	jumpe	d,nounam
	movem	d,uname
	ret

	subttl	UNMOUT -- print uname or nickname or whatever

;;; c has uname in it...
unmout:	setz	b,		;search our database for nickname
serc:	hlr	a,unms(b)
	camn	c,@a            ;found it?
	 jrst	[hrr	a,unms(b)
		 print	@a      ;print it
		 ret]           ;and return
	aos	b
	caig	b,lunm-unms
	 jrst	serc

	move	a,lsrch         ;not in our database, try inquir
	move	b,[-lsrpgs,,lsrbeg]
	call	lsrtns"lsrmap
	 jrst	ohwell          ;lost, so use xuname
	move	b,uname
	call	lsrtns"lsrunm   ;find his entry in database
	 jrst	ohwell          ;nope, not known to inquir
	.close	lsrch,          ;close lsr file
	movei	a,lsrtns"i$nick
	call	lsrtns"lsritm   ;find his nickname
	 jrst	ohwell          ;nope, hasn't told us his nickname
tyunam:	ildb	b,a             ;found it, type it out.
	jumpe	b,cpopj
	caie	b,^C            ;^C has an equal right to stop us
	 cain	b,",            ;some people have two nicknames, separated by ,
	  ret
	aos	c
	.iot	tyoch,b
	jrst	tyunam

ohwell:	.close	lsrch,          ;close lsr file
	move	a,[440600,,uname]	;here if all else fails, use xuname.
repeat	6,[
	ildb	b,a
	addi	b,40
	.iot	tyoch,b
	]
cpopj:	ret

haknms:	sixbit /jcma/
	sixbit /cstacy/
	sixbit /gavan/
	sixbit /derway/
hakn==.-haknms
hakmsg:	asciz /Seeeee yaauh /



;;; Somehow inquir nicname isn't good enuf for these losers

unms:	[sixbit /devon/],,[asciz /Devon/]
	[sixbit /dht/],,[asciz /Dave/]
	[sixbit /drb/],,[asciz /Dave, you turkey!/]
	[sixbit /ed/],,[asciz /, Alligator, have fun!/]
	[sixbit /ffm/],,[asciz /Steve/]
	[sixbit /fnt/],,[asciz /Ferd/]
	[sixbit /foo/],,[asciz /Loser/]
	[sixbit /gjh/],,[asciz /HAVE A NICE DAY GROG!/]
	[sixbit /gls1/],,[asciz /QUUX1/]
	[sixbit /jlk/],,[asciz /John/]
	[sixbit /jmb/],,[asciz /Joel/]
	[sixbit /jpg/],,[asciz /--MIGHTY MOUSE--/]
	[sixbit /jps/],,[asciz /Mr. Sample/]
	[sixbit /ken/],,[asciz /Kenneth, Have Time./]
	[sixbit /kgk/],,[asciz /You complete random turkey, you!/]
	[sixbit /larswe/],,[asciz /Sicnarf/]
	[sixbit /mab/],,[asciz /Meyer/]
	[sixbit /md/],,[asciz /Doc/]
	[sixbit /mrg/],,[asciz /... Mike, don't be loose./]
	[sixbit /murph/],,[asciz /Richard/]
	[sixbit /neal/],,[asciz /Chiron/]
	[sixbit /rlb/],,[asciz /Rich/]
	[sixbit /rms/],,[asciz /Stallman/]
	[sixbit /rsl/],,[asciz /Rici/]
	[sixbit /stan/],,[asciz /Duckie/]
	[sixbit /stever/],,[asciz /Fellow Star Trek watcher/]
	[sixbit /srf/],,[asciz /Sheldo/]
lunm:	[sixbit /tsamos/],,[asciz /John/]


	subttl	uuo and interrupt handlers

uuoh:	0
	move	a,40
	hrli	a,ascbyt
lo:	ildb 	b,a
	skipn 	b
	 jrst 	@uuoh
	.iot 	tyoch,b
	jrst 	lo

tsint:	0 ? 0
	push	p,a
	move	a,tsint
	trne	a,%piioc
	 jsr	death
	movei	a,tyi
	.ityic	a,
	 jrst	intout
	caie	a,^s
	 cain	a,^g
	  jrst	shutup
intout:	pop	p,a
	.dismiss tsint+1

.scalar debug

death:	0			;jsr here on error
	skipn	debug
	 jrst	exit		; oh well, give up...
	sos	death
	sos	death
	syscal	lose,[movei ? death]

shutup:	.reset	tyoch,
	jrst	exit

;;; dump variables so we can figger out where lsr maps in
consta
variab

-1				;So core gets created!

lsrbeg==<.+1777>/2000		;beginning of LSR pages.

loc 41
	jsr uuoh
	jsr tsint

end begin
