-
Notifications
You must be signed in to change notification settings - Fork 5
/
MVS.RELAY.EXEC
714 lines (647 loc) · 26.7 KB
/
MVS.RELAY.EXEC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
/* RELAY EXEC CHAT PROGRAM */
/* */
/* An NJE (bitnet/HNET) chat server */
/* for z/VM, VM/ESA and VM/SP, MVS 3.8 */
/* by collaboration of Peter Jacob, */
/* Mike Grossman, Moshix */
/* */
/* copyright 2020, 2021 by moshix */
/* Apache 2.0 license */
/***************************************/
/* CHANGE HISTORY */
/* V0.1-1.0: testing WAKEUP mechanism */
/* v1.0-1.9: double linked list for in memory processing,bug fixing*/
/* v2.0 : Configurble parameters, remove hardwired data */
/* v2.1 : Add LPAR and machine measurement for stats */
/* v2.2 : Add /SYSTEM command */
/* v2.3 : Make VM/SPrel6 compatible via compatibility=1 parm */
/* v2.4 : Add /FORCE option to force off users (sysop only) */
/* v2.5 : Loop detetector incoming msg counter v1.0 */
/* v2.6 : Add federation v1.0, loop detector v2.0 */
/* v2.7 : loop detector v2.0 */
/* v2.7.1 : autodetect who am i */
/* v2.7.2 : fix stats, high msg rate and last time user seen */
/* v2.7.3 : loop detector disabled for now until i figure it out */
/* v2.7.4 : differentiate compatibility for VMSP,VMESA and z/VM */
/* v2.7.5 : port to BREXX/MVS 3.8 */
/* v2.7.6 : removed federation, whoami, highrate, */
/* v2.7.7 : add /ROOM option */
/* v2.7.8 : add HEARTBEAT function to check availability of RELAY */
/* v2.7.9 : added many error conditions detection */
/* v3.0.0 : Ported forward to RELAY EXEC 3.0.0 for z/VM, VM */
/* v3.0.1 : Allow empty message lines when sendin */
SIGNAL on SYNTAX /* allow graceful termination in case of errors */
/* configuraiton parameters - IMPORTANT */
relaychatversion="3.0.1" /* needed for federation compatibility check */
timezone="CDT" /* adjust for your server IMPORTANT */
maxdormant =1800 /* max time user can be dormat */
localnode="HOUCICS" /* localnode is now autodetected as 2.7.1 */
shutdownpswd="132322229" /* any user with this passwd shuts down rver*/
osversion="MVS 3.8 tk4-8"/* OS version for enquries and stats */
typehost="Hyperion" /* what kind of machine */
hostloc ="Chicago,IL " /* where is this machine */
sysopname="Moshix " /* who is the sysop for this chat server */
sysopemail="000001@gmail" /* where to contact this systop */
compatibility=1 /* 1 VM/SP or MVS3.8, 2=VM/ESA,3=z/VM */
sysopuser='HERC01' /* sysop user who can force users out */
sysopnode=translate(localnode) /* sysop node automatically set */
debugmode=0 /* print debug info on RELAY console when 1 */
raterwatermark=12000 /* max msgs per minute set for this server */
send2ALL=0 /* 0 send chat msgs to users in same room */
/* 1 send chat msgs to all logged-in users */
/* global variables */
returnNJEmsg= "HCPMSG045E"/* messages returning for users not logged on */
returnNJEmsg2="DMTRGX334I"/* looping error message flushed */
returnNJEmsg3="HCPMFS057I"/* RSCS not receiving message */
returnNJEmsg4="DMTPAF208E"/* Invalid user ID message */
returnNJEmsg5="DMTPAF210E"/* RSCS DMTPAF210E Invalid location */
loggedonusers = 0 /* online user at any given moment */
highestusers = 0 /* most users online at any given moment */
totmessages = 0 /* total number of msgs sent */
otime = 0 /* overtime to log off users after n minutes */
starttime=mytime() /* for /SYSTEM */
starttimeSEC=ExTime() /* for msg rate calculation */
logline = " " /* initialize log line */
receivedmsgs=0 /* count received msgs for high rate detec*/
loopCondition=0 /* when 1 there is a msg loop condition */
/*---------------CODE SECTION STARTS BELOW --------------------------*/
whoamiuser="RELAY"
CALL WTO "RELAY CHAT v"||relaychatversion||" on: "||localnode||" has started"
CALL WTO "SEND TO ALL MODE (0=ONLY THOSE IN SAME ROOM, 1=DON'T SEND TO ALL): "||SEND2ALL
NJEUID="RELAY" /* register with NJE38 */
CALL WTO "REL003I THIS NJE USER: "||NJEUID
/* register with NJE38 EXIT now */
CALL __NJEINIT /* SETUP ENVIRONMENT */
RC = __NJEREGISTER(NJEUID) /* REGISTER USERID */
IF RC =0 then _crly=1 /* set NJECRLY is registered */
else do /* when register failed, terminate */
CALL WTO "REL009S USER REGISTRATION FAILED WITH RC("RC")"
exit 8
END
/* ok, we succeeded in registering RELAY to NJE38 */
CALL WTO "REL001I RELAY EXEC HAS REGISTERED WITH NJE38"
/* init double linked list of online users */
call @init
CALL log('List has been initialized..')
CALL log('List size: '||@size())
/*-------------------------------------------*/
receivedmsgs=0
/* --------------------------------------------------------------------
* NJE Message Handler
* runs until stopped by operator command /P in console
* --------------------------------------------------------------------
*/
do forever
event = __njereceive(5000)
select
when event = #msg then do
receivedmsgs= receivedmsgs + 1
CALL WTO "REL010I RECEIVED NJE MESSAGE: "||_data
call handlemsg strip(_data)
end
when event = #stop then ,
call endSTC "NJERELAY STC TERMINATED BY OPERATOR",0
when event = #error then ,
call endstc "NJERELAY STC TERMINATED BY ERROR("_RC")",event
when event = #timeout then do
/* Time out occurred, you can add housekeeping here */
end
end
end
/* --------------------------------------------------------------------
* Shut Down STC
* when its time to quit, come here
* --------------------------------------------------------------------
*/
endSTC:
parse arg msg,exc
CALL WTO 'Before DEREG 'msg', RC= 'exc
say __NJEDEREGISTER(NJEUID)
CALL WTO 'After DEREG 'msg', RC= 'exc
exit exc
/* --------------------------------------------------------------------
* REXX abnormal termination occurred, terminate gracefully
* --------------------------------------------------------------------
*/
syntax:
if _crly=1 then CALL __NJEDEREGISTER(NJEUID)
exit 16
/* --------------------------------------------------------------------
* Old VM coding, not supported in MVS 3.8 NJE
* --------------------------------------------------------------------
*/
/* ####### not supported in MVX
'WAKEUP RESET'; /* turn messages from IUCV to ON */
'SET MSG ON'
'DROPBUF'
* ####### */
exit
/* --------------------------------------------------------------------
* Handle all incoming Messages
* --------------------------------------------------------------------
*/
handlemsg:
/* handle all incoming messages and send to proper method */
/* _data must be parsed for user, node, message */
PARSE ARG . ' ' NODE '(' USERID '):' TEXT
/* "From userid: /... comes in when message was sent by same system*/
if userid='' then do
PARSE ARG . USERID':' TEXT
node = localnode
CALL WTO "REL400I MSG RECEIVED FROM: "||USERID||" @ "||NODE
end
/* TEXT = STRIP(TEXT). */
UMSG = TRANSLATE(TEXT)
node= STRIP(node)
CurrentTime=Extime()
receivedmsgs= receivedmsgs + 1
call highrate (receivedmsgs)
if errorhandler(loopmsg) > 1 then do
loopCondition = 1
/* silently drop message and don't process it */
call log('Loop detector triggered for user: '||userid||'@'||node)
call WTO "REL199S MESSAGE LOOP CONDITION DETECTED!! MAY NEED TO KILL RELAY NOW"
return
end
updbuff=1
SELECT /* HANDLE MESSAGE TYPES */
when (umsg = "/WHO") then
call sendwho userid,node
when (umsg = "/SYSTEM") then
call systeminfo userid,node
when (umsg = "/STATS") then
call sendstats userid,node
when (umsg = "/LOGOFF") then do
call logoffuser userid,node
updbuff=0 /* removed, nothing to update */
end
when (umsg = "/LOGON") then do
call logonuser userid,node
call enterRoom userid,node,'GENERAL'
updbuff=0 /* already up-to-date */
end
when (pos("/ROOMS",umsg)>0) then do
call ShowRooms
end
when (pos("/ROOM",umsg)>0) then do
call EnterRoom userid,node,umsg
end
when umsg='/ECHO' then do
CALL TELLNJE userid 'AT' node 'USER: 'userid' Node: 'node
end
when (pos("/HEARTBEAT",umsg)>0) then do
CALL TELLNJE userid 'AT' node' 'time('L')' 'time('US')
end
when (umsg = "/HELP") then do
call helpuser userid,node
end
when (umsg = shutdownpswd) then do
call log("Shutdown initiated by: "||userid||" at node "||node)
call endstc("Shutdown initiated by: "||userid||" at node "||node,0)
end
otherwise
call sendchatmsg userid,node,text
end
if updBuff=1 then call refreshTime currentTime,userid,node /* for each msg ! */
call CheckTimeout currentTime
return
/* --------------------------------------------------------------------
* tellNJE replaces the VM TELL command and uses NJE38 Message instead
* e.g. CALL TELLNJE userid 'AT' node '/WHO for connected users'
* --------------------------------------------------------------------
*/
tellNJE:
parse arg $userid' 'isat' '$node' 'njemsg
'NJE38 M '$node $userid njemsg
return rc
/* --------------------------------------------------------------------
* SYSOP forces a user out
* --------------------------------------------------------------------
*/
/* -----------------------------------------------------------------
* SENDCHAT Message to all Logged-in users or
* Members of the same room
* -----------------------------------------------------------------
*/
sendchatmsg:
/* what we got is a message to be distributed to all online users */
parse ARG userid,node,msg
listuser = userid || "@"||node
if pos('/'listuser,$.@)=0 then do
/* USER NOT LOGGED ON YET, LET'S SEND HELP TEXT */
CALL TELLNJE userid 'AT' node 'You are currently NOT logged on.'
CALL TELLNJE userid 'AT' node 'Wecome to RELAY chat for z/VM v'relaychatversion
CALL TELLNJE userid 'AT' node '/HELP for help, or /LOGON to logon on'
totmessages = totmessages + 3
return
end
/* USER IS ALREADY LOGGED ON */
/* -----------------------------------------------------------------
* this coding sends the message to all logged-in users
* -----------------------------------------------------------------
*/
if send2ALL=1 then do
do ci=1 to words($.@)
entry=word($.@,ci)
if entry='' then iterate
parse value entry with '/'cuser'@'cnode'('otime')'
if userid \= "RSCS" & userid \= "RELAY" then do
/* This avoids loops for unknown errors coming from RSCS/RELAY */
CALL TELLNJE cuser 'AT' cnode '<> 'userid'@'node':'msg
totmessages = totmessages+ 1
end
end
return
end
/* -----------------------------------------------------------------
* this coding sends the message to all logged-in room mates
* send2ALL is 0
* -----------------------------------------------------------------
*/
myRoom=$Room.userid
do ci=1 to words($Room.myRoom)
entry=word($Room.myRoom,ci)
if entry='' then iterate
if entry=userid'@'node then iterate /* don't send msgs to yourself */
CALL TELLNJE userid 'AT' node 'Message sent to: 'entry
parse value entry with cuser'@'cnode
CALL TELLNJE cuser 'AT' cnode '<> 'userid'@'node':'msg
totmessages = totmessages+ 1
end
return
sendwho:
/* who is online right now on this system? */
userswho = 0 /* counter for seen usres */
parse ARG userid,node
listuser = userid || "@"||node
CALL TELLNJE userid 'AT' node '> List of currently logged on users:'
totmessages = totmessages + 1
do ci=1 to words($.@)
entry=word($.@,ci)
if entry='' then iterate
parse value entry with '/'cuser'@'cnode'('otime')'
currenttime=Extime()
lasttime=currenttime-otime
call TELLNJE ,
userid 'AT' node '> ' cuser'@'cnode' - last seen: 'lasttime' seconds ago'
totmessages = totmessages + 1
userswho = userswho + 1
end
CALL TELLNJE userid 'AT' node '> Total online right now: 'userswho
loggedonusers = userswho
totmessages = totmessages + 1
return
logoffuser:
parse ARG userid,node
listuser = userid || "@"||node
ppos=pos('/'listuser,$.@)
if ppos=0 then do
call log("User logoff rejected, not logged-on: "||listuser)
return
end
rpos=pos(' ',$.@,ppos+1)
if rpos=0 then rpos=length($.@)+1
rlen=rpos-ppos
$.@=overlay(' ',$.@,ppos,rlen)
$.@=space($.@)
loggedonusers = loggedonusers - 1
call exitRoom userid,node
CALL log('List size: '||@size())
CALL TELLNJE userid 'AT' node '-> You are logged off now.'
CALL TELLNJE userid 'AT' node '-> New total number of users: 'loggedonusers
totmessages = totmessages + 2
return
logonuser:
/* add user to linked list */
parse ARG userid,node
listuser = userid"@"node
if pos('/'listuser,$.@)>0 then do
call log("List already logged-on: "||listuser)
CALL TELLNJE userid 'AT' node '-> You are already logged on.'
CALL TELLNJE userid 'AT' node '-> total number of users: 'loggedonusers
end
else do
if loggedonusers < 0 then loggedonusers = 0
loggedonusers = loggedonusers + 1
if highestusers < loggedonusers then highestusers = highestusers + 1
call @put '/'listuser'('currentTime')'
call log("List user added: "||listuser)
CALL log('List size: '||@size())
CALL TELLNJE userid 'AT' node '-> LOGON succeeded. '
CALL TELLNJE userid 'AT' node '-> Total number of users: 'loggedonusers
call announce userid, node /* announce to all users of new user */
end
totmessages = totmessages+ 2
return
/* -----------------------------------------------------------------
* Enter Chat Room. Messages will be sent only to users of the
* same chat room.
* -----------------------------------------------------------------
*/
enterRoom:
parse upper arg _user,_node,_room
if word(_room,1)='/ROOM' then _room=word(_room,2)
rml=length(_room)
if rml<3 | rml>10 then ,
CALL TELLNJE userid 'AT' _node 'Room must not be below 3 or exceed 10 characters :'_room
else do
if symbol('allrooms')<>'VAR' then allrooms=''
else if pos('/'_room,allrooms)=0 then allrooms=allrooms' /'_room
call exitRoom _user,_node
$Room._user=_room
if symbol('$Room._room')=='VAR' then $Room._room=$Room._room' '_user'@'_node
else $Room._room=_user'@'_node
CALL TELLNJE userid 'AT' _node 'You have entered room: '_room
end
totmessages = totmessages + 1
return 0
/* -----------------------------------------------------------------
* Show available Rooms and assigned users
* -----------------------------------------------------------------
*/
ShowRooms:
if symbol('allrooms')<>'VAR' | words(allrooms)=0 then do
CALL TELLNJE userid 'AT' _node 'There are no rooms open yet'
totmessages = totmessages + 1
return
end
do ri=1 to words(allrooms)
troom=substr(word(allrooms,ri),2)
if symbol('$Room.troom')<>'VAR' then iterate
tusers=$Room.troom
CALL TELLNJE userid 'AT' _node troom' has 'words(tusers)' user(s)'
CALL TELLNJE userid 'AT' _node ' Users : 'tusers
totmessages = totmessages+2
end
return 0
/* -----------------------------------------------------------------
* Exit curret CHAT Room, new one will be assigned by enterRoom
* -----------------------------------------------------------------
*/
exitRoom:
parse arg _user,_node
myRoom=$Room._user
$Room._user='' /* clear current room entry */
troom=''
if symbol('$Room._room')<>'VAR' then return
do ci=1 to words($Room.myRoom)
if word($Room.myRoom,ci)=_user'@'node then do
CALL TELLNJE userid 'AT' node '-> You left room 'myRoom
totmessages = totmessages + 1
iterate
end
troom=troom' 'word($Room.myRoom,ci)
end
$Room.myRoom=troom
return
systeminfo:
/* send /SYSTEM info about this host */
parse ARG userid,node
listuser = userid"@"node
CALL TELLNJE userid 'AT' node '-> NJE node name : 'localnode
CALL TELLNJE userid 'AT' node '-> Relay chat version : 'relaychatversion
CALL TELLNJE userid 'AT' node '-> OS for this host : 'osversion
CALL TELLNJE userid 'AT' node '-> Type of host : 'typehost
CALL TELLNJE userid 'AT' node '-> Location of this host: 'hostloc
CALL TELLNJE userid 'AT' node '-> Time Zone of : 'timezone
CALL TELLNJE userid 'AT' node '-> SysOp for this server: 'sysopname
CALL TELLNJE userid 'AT' node '-> SysOp email addr : 'sysopemail
if compatibility > 2 then do
page=paging()
rstor=rstorage()
cfg=configuration()
lcpus=numcpus()
/* parse var mcpu mpage mcf mrstor mlcpus */
CALL TELLNJE userid 'AT' node '-> Pages/Sec : 'page
CALL TELLNJE userid 'AT' node '-> IBM Machine Type : 'cfg
CALL TELLNJE userid 'AT' node '-> Memory in LPAR or VM : 'rstor
CALL TELLNJE userid 'AT' node '-> Number of CPUs : 'lcpus
end
if compatibility > 2 then do
totmessages = totmessages + 12
end
else do
totmessages = totmessages + 8
end
return
sendstats:
/* send usage statistics to whoever asks, even if not logged on */
parse ARG userid,node
onlinenow = countusers(userid,node)
/* parse value translate(diag(8,"INDICATE LOAD"), " ", "15"x) ,
with 1 "AVGPROC-" cpu "%" 1 "PAGING-" page "/"
cpu = right( cpu+0, 3) */
actualtime=Extime()
elapsedsec=(actualtime-starttimeSEC)
if elapsedsec = 0 then elapsedsec = 1 /* avoid division by zero on Jan 1 at 00:00 */
msgsrate = (receivedmsgs + totmessages) / elapsedsec
msgsratef= FORMAT(msgsrate,4,2) /* rounding */
msgsratef = STRIP(msgsratef)
listuser = userid"@"node
CALL TELLNJE userid 'AT' node '-> Total number of users : '@size()
CALL TELLNJE userid 'AT' node '-> Hihgest nr. of users : 'highestusers
CALL TELLNJE userid 'AT' node '-> Total number of msgs : 'totmessages
CALL TELLNJE userid 'AT' node '-> Messages rate /minute : 'msgsratef
CALL TELLNJE userid 'AT' node '-> Server up since : 'starttime' 'timezone
/* CALL TELLNJE userid 'AT' node '-> System CPU laod : 'STRIP(cpu)'%' */
CALL TELLNJE userid 'AT' node '-> RELAY CHAT version : v'relaychatversion
totmessages = totmessages+ 6 /* reduced due to no CPU busy in MVS */
return
helpuser:
/* send help menu */
parse ARG userid,node
listuser = userid"@"node
CALL TELLNJE userid 'AT' node '.____ ____ __ __ _ _ ___ _ _ __ ____ '
CALL TELLNJE userid 'AT' node '( _ \( ___)( ) /__\ ( \/ ) / __)( )_( ) /__\ (_ _)'
CALL TELLNJE userid 'AT' node '.) / )__) )(__ /(__)\ \ / ( (__ ) _ ( /(__)\ )( '
CALL TELLNJE userid 'AT' node '(_)\_)(____)(____)(__)(__)(__) \___)(_) (_)(__)(__)(__) '
CALL TELLNJE userid 'AT' node '. '
CALL TELLNJE userid 'AT' node ' RELAY CHAT for z/VM, VM/ESA, VM/SP MVS v'relaychatversion
CALL TELLNJE userid 'AT' node '. '
CALL TELLNJE userid 'AT' node '. '
CALL TELLNJE userid 'AT' node '/HELP for this help'
CALL TELLNJE userid 'AT' node '/WHO for connected users'
call tellNJE ,
userid 'AT' node '/LOGON to logon and start getting chat messages'
CALL TELLNJE userid 'AT' node '/LOGOFF to logoff and stop getting chat messages'
CALL TELLNJE userid 'AT' node '/STATS for chat statistics'
CALL TELLNJE userid 'AT' node '/SYSTEM for info aobut this host'
CALL TELLNJE userid 'AT' node '/HEARTBEAT to check if still up '
CALL TELLNJE userid 'AT' node '/ROOM to select a ROOM (3-10 chars)'
CALL TELLNJE userid 'AT' node '/ROOMS to see who is in what room'
CALL TELLNJE userid 'AT' node '. '
CALL TELLNJE userid 'AT' node ' messages with <-> are incoming chat messages...'
CALL TELLNJE userid 'AT' node ' messages with > are service messages from chat servers'
totmessages = totmessages + 18
return
countusers:
parse ARG userid,node
listuser = userid"@"node
onlineusers = 0
do ci=1 to words($.@)
entry=word($.@,ci)
if entry='' then iterate
parse value entry with '/'cuser'@'cnode'('otime')'
lasttime=ctime-otime
onlineusers = onlineusers + 1
end
return onlineusers
announce:
/* announce newly logged on user to all users */
parse ARG userid,node
cj=0 /* save logons to remove, else logon buffer doesn't match */
do ci=1 to words($.@)
entry=word($.@,ci)
if entry='' then iterate
parse value entry with '/'cuser'@'cnode'('otime')'
CALL TELLNJE cuser 'AT' cnode '-> New user joined: 'userid' @ 'node
end
return
CheckTimeout:
/* Check if user has not sent any message, automatic LOGOFF */
arg ctime
cj=0 /* save logons to remove, else logon buffer doesn't match */
do ci=1 to words($.@)
entry=word($.@,ci)
if entry='' then iterate
parse value entry with '/'cuser'@'cnode'('otime')'
/* say cuser cnode ctime otime ctime-otime */
if ctime-otime> maxdormant then do /* timeout per configuration */
cj=cj+1
say 'removed user: 'cnode
$remove.cj=cuser','cnode
end
end
do ci=1 to cj
interpret 'call logoffuser '$remove.ci
call log($remove.ci||'logged off due to timeout reached '||maxdormant|| ' minutes')
loggedonusers = loggedonusers -1
end
return
refreshTime:
/* Refresh last transaction time */
/*trace i */
arg ctime,userid,node
listuser=userid'@'node
ppos=pos('/'listuser,$.@)
if ppos=0 then return /* user not logged on */
ppos=pos('(',$.@,ppos+1) /* find timestamp */
if ppos=0 then return /* not found, let it be */
rpos=pos(')',$.@,ppos+1)+1 /* find end of timestamp */
if rpos=0 then return /* ) not found, let it be */
rlen=rpos-ppos
$.@=overlay('('ctime')',$.@,ppos,rlen)
return
exTime:
/* Calculate Seconds in this year */
dd=(date('d')-1)*86400
parse value time() with hh':'mm':'ss
tt=hh*3600+mm*60+ss
return right(dd+tt,8,'0')
mytime: procedure
/* show human readable time and date */
timenow = left(time(),5)
hr = left(timenow,2)
min = right(timenow,2)
if hr > 12 then timenow = (hr - 12)'.'min' pm'
else if hr = 12 then timenow = hr'.'min' pm'
else timenow = hr'.'min' am'
if left(timenow,1) = '0' then timenow = substr(timenow,2)
dow = left(date('weekday'),3)
day = right(date('sorted'),2)
if left(day,1) = '0' then day = substr(day,2)
month = left(date('month'),3)
year = left(date('sorted'),4)
return timenow',' dow day month year
/* below the double linked list constructs */
p: return word(arg(1), 1) /*pick the first word out of many items*/
sy: say;
say left('', 30) " " arg(1) ' ';
return
@init: $.@=;
@adjust: $.@=space($.@);
$.#=words($.@);
return
@hasopt: arg o;
return pos(o, opt)\==0
@size: return $.#
/* */
@del: procedure expose $.;
arg k,m;
call @parms 'km'
_=subword($.@, k, k-1) subword($.@, k+m)
$.@=_;
call @adjust;
return
@get: procedure expose $.; arg k,m,dir,_
call @parms 'kmd'
do j=k for m by dir while j>0 & j<=$.#
_=_ subword($.@, j, 1)
end /*j*/
return strip(_)
@parms: arg opt /*define a variable based on an option.*/
if @hasopt('k') then k=min($.#+1, max(1, p(k 1)))
if @hasopt('m') then m=p(m 1)
if @hasopt('d') then dir=p(dir 1);
return
@put: procedure expose $.;
parse arg x,k;
k=p(k $.#+1);
call @parms 'k'
$.@=subword($.@, 1, max(0, k-1)) x subword($.@, k);
call @adjust
return
@show: procedure expose $.;
parse arg k,m,dir;
if dir==-1 & k=='' then k=$.#
m=p(m $.#);
call @parms 'kmd';
say @get(k,m, dir);
return
list:
/* this is only as examples how to use the double linked list
for future expanesion of this program */
call sy 'initializing the list.' ; call @init
call sy 'building list: blue' ; call @put "blue"
call sy 'displaying list size.' ; say "list size="@size()
call sy 'forward list' ; call @show
call sy 'backward list' ; call @show ,,-1
call sy 'showing 4th item' ; call @show 4,1
call sy 'showing 5th & 6th items' ; call @show 5,2
call sy 'adding item before item 4: black' ; call @put "black",4
call sy 'showing list' ; call @show
call sy 'adding to tail: white' ; call @put "white"
call sy 'showing list' ; call @show
call sy 'adding to head: red' ; call @put "red",0
call sy 'showing list' ; call @show
return
log:
/* log a line to relay machine and/or log */
parse ARG logline
say mytime()' :: 'logline
return
highrate:
/* when too many incoming messages per second exit server to avoid CPU overloading */
/* this function detects high msg rate for loop detection purposes
or for system load abatement purposes */
RATE = 0
parse ARG receivedmsg
currentime=Extime()
elapsedtime=currentime-starttimeSEC
if elapsedtime = 0 then elapsedtime = 3 /* some machines too fast */
rate = receivedmsg/elapsedtime
if rate > raterwatermark then do
call log ('Rate high watermark exceeded, rate: '||rate)
signal xit;
end
else do
return 0
end
return
errorhandler:
/* check for typical errors which lead to msg loops */
parse ARG msg /* what error are we checking for/ */
if (msg = returnNJEmsg) | (msg = returnNJEmsg2) | (msg = returnNJEmsg3) | ,
(msg = returnNJEmsg4) | (msg= returnNJEmsg5) then return 1
else return 0
return