forked from dragonbytes/CoCoIRC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_command_stuff.asm
2347 lines (2151 loc) · 59.9 KB
/
user_command_stuff.asm
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
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
****************************************
* IRC client user command code
****************************************
; ----------------------------------------------
; connect to an IRC server
; Entry: X = pointer to one character after command word (usually a space or CR)
; ----------------------------------------------
COMMAND_SERVER
pshs U,Y,X,D
lda <connectedStatus
beq COMMAND_SERVER_NOT_CONNECTED
; since we are already connected, do a QUIT before closing ports and reconnecting
lda <networkPath
leax strQuitChangingServer,PCR
lbsr WRITE_CRLF_STRING
leax strUserMsgChangingServer,PCR
lbsr PRINT_INFO_ERROR_MESSAGE
ldx #120
os9 F$Sleep
lbsr DRIVEWIRE_RESET ; close any potential open paths, reset variables
lbsr DESTINATION_INITIALIZE_ARRAY
lbsr STATUS_BAR_UPDATE
COMMAND_SERVER_NOT_CONNECTED
ldx 2,S ; restore X original value from stack
lbsr FIND_NEXT_NONSPACE_CHAR
cmpa #C$CR
bne COMMAND_SERVER_USE_CUSTOM
; if here, no server specified so connect to user's default server
leax strUserMsgDefaultServer,PCR
lbsr PRINT_INFO_ERROR_MESSAGE
leax userServerDefault,U
stx <serverCmdPtr
bra COMMAND_SERVER_USE_DEFAULT
COMMAND_SERVER_USE_CUSTOM
stx <serverCmdPtr ; save pointer to server param
lbsr CHECK_FOR_PORT_NUMBER
bcc COMMAND_SERVER_PORT_ALREADY_PRESENT
; no port specified so append the default onto the command
lda #':'
sta ,X+
ldd #"66"
std ,X++
ldd #"67"
std ,X++
lda #C$CR
clrb
std ,X
COMMAND_SERVER_USE_DEFAULT
COMMAND_SERVER_PORT_ALREADY_PRESENT
; build the command to connect to server
leay outputBuffer,U
leax strIRCserverConnect,PCR
lbsr STRING_COPY_RAW
ldx <serverCmdPtr
lbsr PARAM_COPY
ldd #cr_lf
std ,Y++
clr ,Y
; setup drivewire if it hasnt already been initialized
lbsr DRIVEWIRE_SETUP ; setup a new path to drivewire server
lbcs COMMAND_SERVER_ERROR_NO_DRIVEWIRE
; send command to drivewire server
lda <networkPath
leax outputBuffer,U
lbsr WRITE_CRLF_STRING
; ok we sent connect command. let user know.
leay outputBuffer,U
lbsr STRING_COPY_TIMESTAMP
leax strUserMsgTrying,PCR
lbsr STRING_COPY_RAW
ldx <serverCmdPtr
lbsr PARAM_COPY
ldd #cr_lf
std ,Y++
clr ,Y
leax outputBuffer,U
lbsr PRINT_CHATLOG_NULL_STRING
; let mainloop know we are waiting on connection confirmation. setup timeout signal
clr <connectTimeoutFlag
clr <connectedStatus
inc <connectPendingFlag
lda <nilPath
bmi COMMAND_SERVER_EXIT
ldb #SS.FSet ; code $C7
ldx #1800 ; 30 seconds
ldy #0
ldu #connect_timeout_signal
os9 I$SetStt
COMMAND_SERVER_EXIT
puls D,X,Y,U,PC
COMMAND_SERVER_ERROR_NO_DRIVEWIRE
leax strErrorDWPath1,PCR
lbsr PRINT_INFO_ERROR_MESSAGE
leax strErrorDWPath2,PCR
lbsr PRINT_INFO_ERROR_MESSAGE
COMMAND_SERVER_ERROR_INVALID_PARAMS
leax strErrorMsgMissingParam,PCR
lbsr PRINT_INFO_ERROR_MESSAGE
puls D,X,Y,U,PC
; -----------------------------------
; Exit the IRC client back to nitros9
; -----------------------------------
COMMAND_EXIT
pshs Y,X,D
lda <connectedStatus
beq COMMAND_EXIT_CLOSE_ALL_PATHS
leay outputBuffer,U
leax strIRCserverQuit,PCR
lbsr STRING_COPY_RAW
ldd #" :"
std ,Y++
leax userQuitMessage,U
lbsr STRING_COPY_CR
ldd #cr_lf
std ,Y++
clr ,Y
; write quit command to network
lda <networkPath
leax outputBuffer,U
lbsr WRITE_CRLF_STRING
; wait about a second to make sure server got our command
ldx #120
os9 F$Sleep
COMMAND_EXIT_CLOSE_ALL_PATHS
; close /NIL path
lda <nilPath
bmi COMMAND_EXIT_SKIP_NIL_CLOSE
os9 I$Close
COMMAND_EXIT_SKIP_NIL_CLOSE
; close all the text IO window paths
lda <inputbarPath
os9 I$Close
lda <statusbarPath
os9 I$Close
lda <chatlogPath
os9 I$Close
; finally close the drivewire network path
lda <networkPath
bmi COMMAND_EXIT_SKIP_NETWORK_CLOSE
os9 I$Close ; just in case the path is still somehow open
COMMAND_EXIT_SKIP_NETWORK_CLOSE
clrb
os9 F$Exit
puls D,X,Y,PC
; ----------------------------------------------------
; QUIT from an IRC server (with optional quit message)
; ----------------------------------------------------
COMMAND_QUIT
pshs Y,X,D
lbsr CHECK_CONNECT_STATUS_REPORT_ERROR
bcs COMMAND_QUIT_EXIT
; send actual command word
leay outputBuffer,U
leax strIRCserverQuit,PCR
lbsr STRING_COPY_RAW
lda #':'
sta ,Y+
ldx 2,S ; get X value from stack
; figure out if there is a quit message
lbsr FIND_NEXT_NONSPACE_CHAR
cmpa #C$CR
beq COMMAND_QUIT_NO_MSG
; copy over quit msg
lbsr STRING_COPY_CR
bra COMMAND_QUIT_SEND_NETWORK
COMMAND_QUIT_NO_MSG
; no quit message specified so use default
leax userQuitMessage,U
lbsr STRING_COPY_CR
COMMAND_QUIT_SEND_NETWORK
ldd #cr_lf
std ,Y++
clr ,Y
lda <networkPath
leax outputBuffer,U
lbsr WRITE_CRLF_STRING
ldx #120
os9 F$Sleep ; wait about two seconds to make sure server got our command
COMMAND_QUIT_EXIT
puls D,X,Y,PC
; ----------------------------------------------------------
; join an irc channel
; ----------------------------------------------------------
COMMAND_JOIN
pshs Y,X,D
IFDEF debug_mode
; leax strJoinStart,PCR
; lbsr PRINT_CHATLOG_NULL_STRING
; ldx 2,S
ENDC
lbsr CHECK_CONNECT_STATUS_REPORT_ERROR
bcs COMMAND_JOIN_EXIT
lbsr FIND_NEXT_NONSPACE_CHAR
cmpa #'#'
bne COMMAND_JOIN_INVALID_CHANNEL_NAME
stx <serverCmdPtr
; first check to see if they are trying to join a channel they already are in
lbsr DESTINATION_FIND_ENTRY
bcc COMMAND_JOIN_ERROR_ALREADY_JOINED
; nope, do we have room for another channel in the destination array though?
; since the IRC server parser actually adds the entry to the list, we still have
; to check here first, otherwise we could be joined to a channel and getting traffic
; from it without being able to talk in it or PART it.
lbsr DESTINATION_FIND_EMPTY
lbcs COMMAND_JOIN_ERROR_CHANLIST_FULL
; all good. build the server command string
leay outputBuffer,U
leax strJOINkeyword,PCR
lbsr STRING_COPY
lda #C$SPAC
sta ,Y+
ldx <serverCmdPtr
; add the channel name to the output string
lbsr PARAM_COPY
ldd #cr_lf
std ,Y++ ; terminate it with a CR+LF
; send the irc server command
lda <networkPath
leax outputBuffer,U
lbsr WRITE_CRLF_STRING
IFDEF debug_mode
; leax strJoinEnd,PCR
; lbsr PRINT_CHATLOG_NULL_STRING
; ldx 2,S
ENDC
puls D,X,Y,PC
COMMAND_JOIN_ERROR_CHANLIST_FULL
leax strErrorMsgDestListFull,PCR
bra COMMAND_JOIN_ERROR_EXIT
COMMAND_JOIN_ERROR_ALREADY_JOINED
leax strErrorJoinedAlready,PCR
bra COMMAND_JOIN_ERROR_EXIT
COMMAND_JOIN_INVALID_CHANNEL_NAME
leax strErrorInvalidChanName,PCR
COMMAND_JOIN_ERROR_EXIT
lbsr PRINT_INFO_ERROR_MESSAGE
COMMAND_JOIN_EXIT
puls D,X,Y,PC
; ----------------------------------------------------------
; leave an irc channel
; ----------------------------------------------------------
COMMAND_PART
pshs Y,X,D
lbsr CHECK_CONNECT_STATUS_REPORT_ERROR
bcs COMMAND_PART_EXIT
lbsr FIND_NEXT_NONSPACE_CHAR
; check if user specified a channel or part message
cmpa #'#'
beq COMMAND_PART_GET_MANUAL_CHAN
; if here, use active channel name
stx <serverCmdPtr ; save pointer to part msg
lbsr DESTINATION_GET_ACTIVE
bcs COMMAND_PART_ERROR_NO_ACTIVE ; if carry set, no active destination
; X now should be pointing at currently active channel name
leay destChanName,U
lbsr STRING_COPY
bra COMMAND_PART_DO_MSG
COMMAND_PART_GET_MANUAL_CHAN
leay destChanName,U
lbsr PARAM_COPY
; move to next param (or just CR if its the end)
lbsr FIND_NEXT_NONSPACE_CHAR
stx <serverCmdPtr
COMMAND_PART_DO_MSG
; setup the PART server command
leay outputBuffer,U
leax strIRCserverPart,PCR
lbsr STRING_COPY_RAW
leax destChanName,U
lbsr STRING_COPY
; do we have a part message?
ldx <serverCmdPtr
lda ,X
cmpa #C$CR
beq COMMAND_PART_SKIP_MSG
; add in part msg
ldd #" :"
std ,Y++
lbsr STRING_COPY_CR
COMMAND_PART_SKIP_MSG
ldd #cr_lf
std ,Y++
clr ,Y
; send to network
lda <networkPath
leax outputBuffer,U
lbsr WRITE_CRLF_STRING
puls D,X,Y,PC
COMMAND_PART_ERROR_NO_ACTIVE
leax strErrorMsgNoActiveWin,PCR
lbsr PRINT_INFO_ERROR_MESSAGE
COMMAND_PART_EXIT
puls D,X,Y,PC
; ---------------------------------------------------
; send a private message
; ---------------------------------------------------
COMMAND_MSG
pshs Y,X,D
lbsr CHECK_CONNECT_STATUS_REPORT_ERROR
lbcs COMMAND_MSG_EXIT
lbsr FIND_NEXT_NONSPACE_CHAR
cmpa #C$CR
lbeq COMMAND_MSG_MISSING_PARAMS
; copy destination nickname
leay destNickname,U
lbsr PARAM_COPY
lbsr FIND_NEXT_NONSPACE_CHAR
cmpa #C$CR
beq COMMAND_MSG_MISSING_PARAMS
stx <serverCmdPtr
; setup PRIVMDG command
leay outputBuffer,U
leax strIRCserverMsg,PCR
lbsr STRING_COPY
lda #C$SPAC
sta ,Y+
leax destNickname,U
lbsr STRING_COPY
ldd #" :"
std ,Y++
ldx <serverCmdPtr
lbsr STRING_COPY_CR
ldd #cr_lf
std ,Y++
clr ,Y
; now write out the command to the server
lda <networkPath
leax outputBuffer,U
lbsr WRITE_CRLF_STRING
; now format it for printing to screen
leay outputBuffer,U
lbsr STRING_COPY_TIMESTAMP
lda #'>'
sta ,Y+
lda #colorNickChan
lbsr COPY_COLOR_CODE_FOREGROUND
leax destNickname,U
lbsr STRING_COPY
lda #colorNormal
lbsr COPY_COLOR_CODE_FOREGROUND
lda #'<'
sta ,Y+
lda #C$SPAC
sta ,Y+
ldx <serverCmdPtr
lbsr STRING_COPY_CR
ldd #cr_lf
std ,Y++
clr ,Y
leax outputBuffer,U
lbsr PRINT_CHATLOG_NULL_STRING
puls D,X,Y,PC
COMMAND_MSG_MISSING_PARAMS
leax strErrorMsgMissingParam,PCR
lbsr PRINT_INFO_ERROR_MESSAGE
COMMAND_MSG_EXIT
puls D,X,Y,PC
; ------------------------------------------------------
; change nickname
; ------------------------------------------------------
COMMAND_NICK
pshs Y,X,D
lda <connectedStatus
beq COMMAND_NICK_ERROR_NOT_CONNECTED
lbsr FIND_NEXT_NONSPACE_CHAR
cmpa #C$CR
beq COMMAND_NICK_ERROR_MISSING_PARAMS
stx <serverCmdPtr
leay outputBuffer,U
leax strIRCserverNick,PCR
lbsr STRING_COPY
ldx <serverCmdPtr
lbsr PARAM_COPY
ldd #cr_lf
std ,Y++
clr ,Y
lda <networkPath
leax outputBuffer,U
lbsr WRITE_CRLF_STRING
puls D,X,Y,PC
COMMAND_NICK_ERROR_NOT_CONNECTED
leax strErrorNotConnected,PCR
lbsr PRINT_INFO_ERROR_MESSAGE
bra COMMAND_NICK_EXIT
COMMAND_NICK_ERROR_MISSING_PARAMS
leax strErrorMsgMissingParam,PCR
lbsr PRINT_INFO_ERROR_MESSAGE
COMMAND_NICK_EXIT
puls D,X,Y,PC
; ------------------------------------------------------
; start a private conversation with new nickname as
; destination
; ------------------------------------------------------
COMMAND_QUERY
pshs Y,X,D
lbsr CHECK_CONNECT_STATUS_REPORT_ERROR
bcs COMMAND_QUERY_EXIT
; first check to see if they already have an open query for that nickname
lbsr FIND_NEXT_NONSPACE_CHAR
cmpa #'#'
beq COMMAND_QUERY_INVALID_SYNTAX
stx <serverCmdPtr
lbsr DESTINATION_FIND_ENTRY
bcc COMMAND_QUERY_ALREADY_EXISTS
; if here, then its a new nickname. add it to destination list if not full
clrb
lbsr DESTINATION_ADD_ENTRY
bcs COMMAND_QUERY_ERROR_LIST_FULL
puls D,X,Y,PC
COMMAND_QUERY_ALREADY_EXISTS
; since nick already exists, move active destination to there and redraw statusbar
std destOffset,U
lbsr STATUS_BAR_UPDATE
bra COMMAND_QUERY_EXIT
COMMAND_QUERY_ERROR_LIST_FULL
leax strErrorMsgDestListFull,PCR
bra COMMAND_QUERY_ERROR_EXIT
COMMAND_QUERY_INVALID_SYNTAX
leax strErrorMsgInvalid,PCR
COMMAND_QUERY_ERROR_EXIT
lbsr PRINT_INFO_ERROR_MESSAGE
COMMAND_QUERY_EXIT
puls D,X,Y,PC
; ----------------------------------------------------------
COMMAND_ACTION
pshs Y,X,D
lbsr CHECK_CONNECT_STATUS_REPORT_ERROR
lbcs COMMAND_ACTION_EXIT
lbsr FIND_NEXT_NONSPACE_CHAR
cmpa #C$CR
lbeq COMMAND_ACTION_MISSING_PARAMS
stx <serverCmdPtr ; save pointer to action string
; build string to send to server
leay outputBuffer,U
leax strIRCserverMsg,PCR
lbsr STRING_COPY
lda #C$SPAC
sta ,Y+
lbsr DESTINATION_GET_ACTIVE ; get pointer to current destination
lbcs COMMAND_ACTION_NO_ACTIVE_CHAN
; X should now be pointing to string name of destination
stx <outputBufferPtr
lbsr STRING_COPY
ldd #" :"
std ,Y++
lda #$01 ; IRC control code for CTCP
sta ,Y+
leax strIRCserverAction,PCR
lbsr STRING_COPY
ldx <serverCmdPtr
lbsr STRING_COPY_CR
sta ,Y+ ; add closing control code for CTCP action
ldd #cr_lf
std ,Y++
clr ,Y
; now write out the command to the server
lda <networkPath
leax outputBuffer,U
lbsr WRITE_CRLF_STRING
; now format it for printing to screen
leay outputBuffer,U
lbsr STRING_COPY_TIMESTAMP
lda #'{'
sta ,Y+
; check if action is going to a nick or channel and set color accordingly
ldx <outputBufferPtr
ldb ,X
cmpb #'#'
bne COMMAND_ACTION_NICK_DEST
lda #colorChanName
bra COMMAND_ACTION_CHANGE_COLOR
COMMAND_ACTION_NICK_DEST
lda #colorNickChan
COMMAND_ACTION_CHANGE_COLOR
lbsr COPY_COLOR_CODE_FOREGROUND
lbsr STRING_COPY
lda #colorNormal
lbsr COPY_COLOR_CODE_FOREGROUND
ldd #"} "
std ,Y++
ldd #"* "
std ,Y++
lda #colorYourNick
lbsr COPY_COLOR_CODE_FOREGROUND
leax serverYourNick,U
lbsr STRING_COPY
lda #colorNormal
lbsr COPY_COLOR_CODE_FOREGROUND
lda #C$SPAC
sta ,Y+
ldx <serverCmdPtr
lbsr STRING_COPY_CR
ldd #cr_lf
std ,Y++
clr ,Y
leax outputBuffer,U
lbsr PRINT_CHATLOG_NULL_STRING
puls D,X,Y,PC
COMMAND_ACTION_NO_ACTIVE_CHAN
leax strErrorMsgNoActiveWin,PCR
bra COMMAND_ACTION_ERROR_EXIT
COMMAND_ACTION_MISSING_PARAMS
leax strErrorMsgMissingParam,PCR
COMMAND_ACTION_ERROR_EXIT
lbsr PRINT_INFO_ERROR_MESSAGE
COMMAND_ACTION_EXIT
puls D,X,Y,PC
; ------------------------------------------------------
; request a WHOIS on a nickname
; ------------------------------------------------------
COMMAND_WHOIS
pshs Y,X,D
lbsr CHECK_CONNECT_STATUS_REPORT_ERROR
bcs COMMAND_WHOIS_EXIT
lbsr FIND_NEXT_NONSPACE_CHAR
cmpa #C$CR
bne COMMAND_WHOIS_CHECK_FOR_CHAN
; if here, use the active destination instead
lbsr DESTINATION_GET_ACTIVE
bcs COMMAND_WHOIS_NO_ACTIVE
lda ,X
COMMAND_WHOIS_CHECK_FOR_CHAN
cmpa #'#'
beq COMMAND_WHOIS_INVALID_PARAMS
stx <outputBufferPtr
; build our server command now
leay outputBuffer,U
leax strIRCserverWhois,PCR
lbsr STRING_COPY_RAW
ldx <outputBufferPtr
lbsr PARAM_COPY
lda #C$SPAC
sta ,Y+
ldx <outputBufferPtr
lbsr PARAM_COPY ; send nickname in whois twice to get idle/signon info msgs
ldd #cr_lf
std ,Y++
clr ,Y
; now write out the command to the server
lda <networkPath
leax outputBuffer,U
lbsr WRITE_CRLF_STRING
puls D,X,Y,PC
COMMAND_WHOIS_NO_ACTIVE
leax strErrorMsgNoActiveWin,PCR
bra COMMAND_WHOIS_ERROR_EXIT
COMMAND_WHOIS_INVALID_PARAMS
leax strErrorMsgInvalid,PCR
COMMAND_WHOIS_ERROR_EXIT
lbsr PRINT_INFO_ERROR_MESSAGE
COMMAND_WHOIS_EXIT
puls D,X,Y,PC
; ------------------------------------------------------
; close a destination window
; ------------------------------------------------------
COMMAND_CLOSE
pshs Y,X,D
lbsr FIND_NEXT_NONSPACE_CHAR
cmpa #C$CR
bne COMMAND_CLOSE_MANUAL_DEST
; if here, use the active destination instead
lbsr DESTINATION_GET_ACTIVE
bcs COMMAND_CLOSE_NO_ACTIVE
lda ,X
cmpa #'#'
beq COMMAND_CLOSE_PART_CHAN
; if here, its the active nickname window they want to close. since we already
; are pointing at it's entry, write $0000 to mark it as available and move to next
; available destination to be active if any. then update status bar
ldd #0
std ,X
COMMAND_CLOSE_NEXT_DEST_AND_EXIT
lbsr COMMAND_NEXT_DESTINATION
puls D,X,Y,PC
COMMAND_CLOSE_MANUAL_DEST
cmpa #'#'
beq COMMAND_CLOSE_PART_CHAN ; if they are specifying a channel name, PART it
lbsr DESTINATION_FIND_ENTRY ; attempt to find entry for specified nickname
bcs COMMAND_CLOSE_ERROR_NOT_FOUND
leax destArray,U
leax D,X
ldy #0
sty ,X ; zero out entry to free it up
cmpd destOffset,U ; check if entry we just deleted is current active dest
bne COMMAND_CLOSE_EXIT ; if not, we are done. peace out yo
bra COMMAND_CLOSE_NEXT_DEST_AND_EXIT ; otherwise, move next dest and exit
COMMAND_CLOSE_PART_CHAN
lbsr CHECK_CONNECT_STATUS_REPORT_ERROR
bcs COMMAND_CLOSE_EXIT
; setup server command in outputBuffer
stx <outputBufferPtr
leay outputBuffer,U
leax strIRCserverPart,PCR
lbsr STRING_COPY_RAW
ldx <outputBufferPtr
lbsr PARAM_COPY
ldd #cr_lf
std ,Y++
clr ,Y
; send to network
lda <networkPath
leax outputBuffer,U
lbsr WRITE_CRLF_STRING
; for channel parts, the server parsing code does the actual removal from dest list
; so we are done
COMMAND_CLOSE_EXIT
puls D,X,Y,PC
COMMAND_CLOSE_ERROR_NOT_FOUND
leax strErrorCloseDestNotFound,PCR
bra COMMAND_CLOSE_ERROR_EXIT
COMMAND_CLOSE_NO_ACTIVE
leax strErrorMsgNoActiveWin,PCR
COMMAND_CLOSE_ERROR_EXIT
lbsr PRINT_INFO_ERROR_MESSAGE
puls D,X,Y,PC
; ---------------------------------------------------------------
; send a NOTICE message to an IRC user nickname
; ---------------------------------------------------------------
COMMAND_NOTICE
pshs Y,X,D
lbsr CHECK_CONNECT_STATUS_REPORT_ERROR
bcs COMMAND_NOTICE_EXIT
lbsr FIND_NEXT_NONSPACE_CHAR
cmpa #C$CR
beq COMMAND_NOTICE_ERROR_MISSING_PARAMS
stx <outputBufferPtr
; build the server command
leay outputBuffer,U
leax strIRCserverNotice,PCR
lbsr STRING_COPY_RAW
ldx <outputBufferPtr
lbsr PARAM_COPY
ldd #" :"
std ,Y++
lbsr FIND_NEXT_NONSPACE_CHAR
cmpa #C$CR
beq COMMAND_NOTICE_ERROR_MISSING_PARAMS
lbsr STRING_COPY_CR
ldd #cr_lf
std ,Y++
clr ,Y
; send finished command to network/server
lda <networkPath
leax outputBuffer,U
lbsr WRITE_CRLF_STRING
; now build output string to print to chatlog
leay outputBuffer,U
lbsr STRING_COPY_TIMESTAMP
lda #colorNotice
lbsr COPY_COLOR_CODE_FOREGROUND
ldd #"->"
std ,Y++
lda #colorNickChan
lbsr COPY_COLOR_CODE_FOREGROUND
ldx <outputBufferPtr
lbsr PARAM_COPY
lda #colorNotice
lbsr COPY_COLOR_CODE_FOREGROUND
ldd #"<-"
std ,Y++
lda #C$SPAC
sta ,Y+
lbsr FIND_NEXT_NONSPACE_CHAR
lbsr STRING_COPY_CR
ldd #cr_lf
std ,Y++
clr ,Y
leax outputBuffer,U
lbsr PRINT_CHATLOG_NULL_STRING
puls D,X,Y,PC
COMMAND_NOTICE_ERROR_MISSING_PARAMS
leax strErrorMsgMissingParam,PCR
lbsr PRINT_INFO_ERROR_MESSAGE
COMMAND_NOTICE_EXIT
puls D,X,Y,PC
; ------------------------------------------------------
; kick (or try to kick) out a user from a channel
; ------------------------------------------------------
COMMAND_KICK
pshs Y,X,D
lbsr CHECK_CONNECT_STATUS_REPORT_ERROR
bcs COMMAND_KICK_EXIT
lbsr FIND_NEXT_NONSPACE_CHAR
stx <serverCmdPtr
leay outputBuffer,U
leax strIRCserverKick,PCR
lbsr STRING_COPY_RAW
cmpa #C$CR
beq COMMAND_KICK_ERROR_MISSING_PARAMS
cmpa #'#'
beq COMMAND_KICK_MANUAL_CHAN_SPECIFIED
; use current active destination
lbsr DESTINATION_GET_ACTIVE ; get pointer to current destination
lbcs COMMAND_KICK_NO_ACTIVE_CHAN
lbsr PARAM_COPY ; copy channel name in to output string
ldx <serverCmdPtr
bra COMMAND_KICK_CHAN_COPIED
COMMAND_KICK_MANUAL_CHAN_SPECIFIED
lbsr PARAM_COPY ; copy manual chan name in
COMMAND_KICK_CHAN_COPIED
lda #C$SPAC
sta ,Y+
lbsr FIND_NEXT_NONSPACE_CHAR ; skip white space to find nickname to kick
cmpa #C$CR
beq COMMAND_KICK_ERROR_MISSING_PARAMS
lbsr PARAM_COPY ; copy nickname in
lbsr FIND_NEXT_NONSPACE_CHAR ; skip whitespace to CR or kick message
cmpa #C$CR
beq COMMAND_KICK_NO_MSG
ldd #" :"
std ,Y++
lbsr STRING_COPY_CR
COMMAND_KICK_NO_MSG
ldd #cr_lf
std ,Y++
clr ,Y ; NULL terminate
; send command to network
lda <networkPath
leax outputBuffer,U
lbsr WRITE_CRLF_STRING
; all done. return
puls D,X,Y,PC
COMMAND_KICK_ERROR_MISSING_PARAMS
leax strErrorMsgMissingParam,PCR
lbsr PRINT_INFO_ERROR_MESSAGE
bra COMMAND_KICK_EXIT
COMMAND_KICK_NO_ACTIVE_CHAN
leax strErrorMsgNoActiveWin,PCR
lbsr PRINT_INFO_ERROR_MESSAGE
COMMAND_KICK_EXIT
puls D,X,Y,PC
; ------------------------------------------------------
; this sections has multiple entry points for setting
; various channel modes like +o -v +b etc
; Entry: X = pointer to command parameters
; ------------------------------------------------------
COMMAND_OP
pshs Y,X,D
ldd #"+o"
bra COMMAND_MODES_ALL
COMMAND_DEOP
pshs Y,X,D
ldd #"-o"
bra COMMAND_MODES_ALL
COMMAND_VOICE
pshs Y,X,D
ldd #"+v"
bra COMMAND_MODES_ALL
COMMAND_DEVOICE
pshs Y,X,D
ldd #"-v"
bra COMMAND_MODES_ALL
COMMAND_BAN
pshs Y,X,D
ldd #"+b"
bra COMMAND_MODES_ALL
COMMAND_UNBAN
pshs Y,X,D
ldd #"-b"
bra COMMAND_MODES_ALL
COMMAND_MODE
pshs Y,X,D
ldd #0
COMMAND_MODES_ALL
std strModeOperators,U ; save our flag string or zero for custom MODE flags
lbsr CHECK_CONNECT_STATUS_REPORT_ERROR
bcs COMMAND_MODES_EXIT
leay outputBuffer,U
leax strIRCserverMode,PCR
lbsr STRING_COPY_RAW
ldx 2,S
; copy chan name into outputbuffer from either command or active dest
lbsr COPY_CHAN_FROM_CMD_OR_ACTIVE
bcs COMMAND_MODES_NO_ACTIVE_CHAN
lbsr FIND_NEXT_NONSPACE_CHAR
cmpa #C$CR
beq COMMAND_MODES_ERROR_MISSING_PARAMS
lda #C$SPAC
sta ,Y+
ldd strModeOperators,U
bne COMMAND_MODES_ALL_SPECIFIC_FLAG
lbsr STRING_COPY_CR
bra COMMAND_MODES_ALL_FINISH
COMMAND_MODES_ALL_SPECIFIC_FLAG
std ,Y++
lda #C$SPAC
sta ,Y+
lbsr PARAM_COPY
COMMAND_MODES_ALL_FINISH
ldd #cr_lf
std ,Y++
clr ,Y
; send command to network
lda <networkPath
leax outputBuffer,U
lbsr WRITE_CRLF_STRING
; all done. return
puls D,X,Y,PC
COMMAND_MODES_ERROR_MISSING_PARAMS
leax strErrorMsgMissingParam,PCR
lbsr PRINT_INFO_ERROR_MESSAGE
bra COMMAND_MODES_EXIT
COMMAND_MODES_NO_ACTIVE_CHAN
leax strErrorMsgNoActiveWin,PCR
lbsr PRINT_INFO_ERROR_MESSAGE
COMMAND_MODES_EXIT
puls D,X,Y,PC
; -------------------------------------------------------
; change channel topic if you have operator privledges
; -------------------------------------------------------
COMMAND_TOPIC
pshs Y,X,D
lbsr CHECK_CONNECT_STATUS_REPORT_ERROR
bcs COMMAND_TOPIC_EXIT
leay outputBuffer,U
leax strIRCserverTopic,PCR
lbsr STRING_COPY_RAW
ldx 2,S ; get back pointer to parameters from stack
; skip any whitespace, check if X points to manual chan name. if so, copies it,
; otherwise tries to use active destination
lbsr COPY_CHAN_FROM_CMD_OR_ACTIVE
bcs COMMAND_TOPIC_ERROR_NO_ACTIVE_CHAN
lbsr FIND_NEXT_NONSPACE_CHAR
cmpa #C$CR
beq COMMAND_TOPIC_REQUEST_CURRENT
; if here, user is trying to SET a new topic
ldd #" :"
std ,Y++
lbsr STRING_COPY_CR
bra COMMAND_TOPIC_SEND_OUTPUT
COMMAND_TOPIC_REQUEST_CURRENT
COMMAND_TOPIC_SEND_OUTPUT
ldd #cr_lf
std ,Y++
clr ,Y
; send to network path
lda <networkPath
leax outputBuffer,U
lbsr WRITE_CRLF_STRING
puls D,X,Y,PC
COMMAND_TOPIC_ERROR_MISSING_PARAMS
leax strErrorMsgMissingParam,PCR
bra COMMAND_TOPIC_PRINT_ERROR_EXIT
COMMAND_TOPIC_ERROR_NO_ACTIVE_CHAN
leax strErrorMsgNoActiveWin,PCR
COMMAND_TOPIC_PRINT_ERROR_EXIT
lbsr PRINT_INFO_ERROR_MESSAGE
COMMAND_TOPIC_EXIT
puls D,X,Y,PC
; -------------------------------------------------------
; request list of nicnames in a particular channel
; -------------------------------------------------------
COMMAND_NAMES
pshs Y,X,D
lbsr CHECK_CONNECT_STATUS_REPORT_ERROR
bcs COMMAND_NAMES_EXIT
lbsr FIND_NEXT_NONSPACE_CHAR
cmpa #C$CR
bne COMMAND_NAMES_MANUAL_CHAN
; use active channel if exists
lbsr DESTINATION_GET_ACTIVE ; get pointer to current destination
bcc COMMAND_NAMES_SETUP_NAMES
bra COMMAND_NAMES_ERROR_NO_ACTIVE_CHAN
COMMAND_NAMES_MANUAL_CHAN
cmpa #'#'
bne COMMAND_NAMES_ERROR_INVALID_PARAM
COMMAND_NAMES_SETUP_NAMES
stx <serverCmdPtr ; save pointer to channel name
; setup NAMES command
leay outputBuffer,U
leax strIRCserverNames,PCR
lbsr STRING_COPY_RAW
ldx <serverCmdPtr
lbsr PARAM_COPY
ldd #cr_lf
std ,Y++
clr ,Y
; send to network
lda <networkPath
leax outputBuffer,U
lbsr WRITE_CRLF_STRING
; let the IRC server parser know to defintely display results since it was requested by user
inc <namesRequestedFlag
puls D,X,Y,PC
COMMAND_NAMES_ERROR_NO_ACTIVE_CHAN
leax strErrorMsgNoActiveWin,PCR
bra COMMAND_NAMES_ERROR_EXIT
COMMAND_NAMES_ERROR_INVALID_PARAM
leax strErrorMsgInvalid,PCR
COMMAND_NAMES_ERROR_EXIT
lbsr PRINT_INFO_ERROR_MESSAGE
COMMAND_NAMES_EXIT
puls D,X,Y,PC
; -------------------------------------------------------
; quick way to leave a channel and then rejoin it again
; immediately afterwards automatically
; -------------------------------------------------------
COMMAND_CYCLE
pshs Y,X,D
lbsr CHECK_CONNECT_STATUS_REPORT_ERROR
bcs COMMAND_CYCLE_EXIT