/* Jewfish's Multi-Line Chat Config */
/* /Invite added by Hagar */
/* /Join and private added by Bill-e */

Arg Line

call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
call SysLoadFuncs


DefaultChannel = 'General Chat'                               /* Max 15 Chars */
UserChannelCount = Right(AdeptConvert(Line,'{CU'),2,'0')

            queuename='ND'line
               q =rxqueue('delete', queuename)
                 q1 =rxqueue('create',queuename)
                 q2 =rxqueue('set',queuename)
                 q3 =rxqueue('get')
                 queue '1036a.none'



UserName = AdeptGetVar(Line,2)
UserNode = Right(Line,2,'0')
UserCount = AdeptConvert(Line,'{CU')
KeyList = D2C(9)
InputText = ''
LastPVT = ''
Start = Time('M')
newchannel.line=''
Call AdeptInitRexx Line
rc = AdeptSysChatConnectUser(Line)                                               /* Connect to Server */
If rc \= 1 Then Do
   Call AdeptPrint Line, "\r\n\r\nChat Server isn't available!\r\n"
   Call AdeptHitReturn Line
   Exit
End

Call Join
joined:
Call AdeptPrint Line, '\r\n{CS{B2{FC  AdeptXBBS {FGMulti-Line Chatting System v0.02    {B1{F9Ü\r\n'
Call AdeptPrint Line, '{B2  {FFYou have entered the {FC' || DefaultChannel || ' {FFChannel' || Copies(' ',15 - Length(DefaultChannel)) || '  {B1{F9Û\r\n'
Call AdeptPrint Line, '{B2  {FGThere are {FB' || UserChannelCount || ' {FGusers in the Chat Subsystem      {B1{F9Û\r\n'
Call AdeptPrint Line, ' ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß\r\n'
Call AdeptPrint Line, '{FGType /? -or- /H for Quick Help\r\n\r\n'

Call AdeptMenuType Line, 52,""
Call AdeptPrint Line, '\r\n'

Do Forever
   RetC = Strip(AdeptSysChatInput(Line, "USERTEXT", KeyList, InputText),'t')
   InputText = ''
   If (RetC == IRC_CHATWAITING) Then Do
          Call ProcessChatMsg(Line)
          Iterate
   End
   Select
         When RetC == 1 Then Do
                If UserText = 'USERTEXT' Then Iterate
                If Left(UserText,1,1) = '/' Then Call Commands
                Else Do
                   If UserCount \= 999 Then Call AdeptSysChatPubMsg Line, '{FE[{FG' || UserNode || '{F8-{FB' || UserName || '{FE] {FC' || UserText
                   /* Else Call AdeptPrint Line, '\r{FG­ {FFWarning - You are the only person in this channel.\r\n            For a list of people online, type /W' */
                   Call AdeptPrint Line, '\r\n'
                End
                Iterate
         End
         When RetC == 9 Then Do
                If LastPvt \= '' Then InputText = '/S,' || LastPvt || ' '
                Else InputText = '/S,'
                Iterate
         End
         When RetC == IRC_NOTIMELEFT Then Do
                Call AdeptPrint Line, "\r\nYou're outta time sucker!"
                Call Leave('Out of Time')
                Exit
         End
         When RetC == LOSTCARRIER Then Do
                Call Leave('Lost Carrier')
                Exit
         End
         When RetC == IRC_CHATDOWN Then Call AdeptSysChatReconnectUser Line
         When RetC == IRC_CHATWAITING Then Do
                Call AdeptPrint Line, '\r\nThe Chatserver is busy at the moment...\r\n'
                Iterate
         End
         Otherwise Nop
   End
End


Commands:

   If Pos(',',UserText) = 0 Then Parse Var UserText Command NodeTo MsgText
   Else Parse Var UserText Command ',' NodeTo ' ' MsgText
   Command = Translate(Command)
   Select
         When Command = '/W' Then Do
                Call AdeptMenuType Line, 55,""
                Call AdeptPrint Line, '\r\n'
                Return
         End
         When Command = '/Q' Then Do
                Call Leave('Leaving')
                Exit
         End
         When Command = '/S' Then Do
                If NodeTo = '' | MsgText = '' Then Call AdeptPrint Line, '\rYou screwed that command well and good!\r\n'
                Else Do
                     Chkit = AdeptGetVar(NodeTo,44)
                     myrt = AdeptCheckBit(NodeTo,24,Chit)
                     if myrt = 1 then do
                     Call AdeptPrint Line, '\r{F9þ{F5þ{FDþ{FGþ Private Message Not sent, that user has their Chat Flag Disabled... {FGþ{FDþ{F5þ{F9þ\r\n'
                     Return
                     end
                  retc = AdeptSysChatPrivMsg(Line, NodeTo, '{FE[{FG' || UserNode || '{F8-{FB' || UserName || '{FD, Pvt Msg{FE] {FC' || MsgText)
/*                     Call AdeptComWrite NodeTo, '{FE[{FG' || UserNode || '{F8-{FB' || UserName || '{FD, Pvt Msg{FE] {FC' || MsgText     */
                   NodeUserName = AdeptGetVar(NodeTo, 2)
                   If NodeUserName \= '' Then Call AdeptPrint Line, '\r{F9þ{F2þ{FAþ{FCþ{FGþ Private Message sent to {FB' || NodeUserName || ' {FGon Node {FB' || NodeTo || ' {FGþ{FCþ{FAþ{F2þ{F9þ\r\n'
                   Else Call AdeptPrint Line, '\r{F9þ{F5þ{FDþ{FGþ Private Message Not sent, there is no-one on Node {FD' || NodeTo || ' {FGþ{FDþ{F5þ{F9þ\r\n'
                   LastPvt = NodeTo
                End
                Return
         End
         When Command = '/H' | Command = '/?' | Command = '/HELP' Then Do
                /* Convert to Meta Later */
                Call AdeptPrint Line,'\r[40m[0;30;44mÚ[1;34mÄÄÄÄ[37mHELP[34mÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄ[37mEXAMPLES[34mÄÄÄÄÄÄÄÄÄÄÄÄÄ¿[40m'
                Call AdeptPrint Line,'\r\n[0;30;44m³ [1;36m/S,[Node #] [Message] [37mSend a Private Message.    [34m³ [33m/S,1 Hello             [34m³[40m'
                Call AdeptPrint Line,'\r\n[0;30;44m³ [1;36m/ME [Message] [37mAllows you to perform an Action.   [34m³ [33m/ME Laughs!            [34m³[40m'
                Call AdeptPrint Line,'\r\n[0;30;44m³ [1;36m/G,[Node #] [37mGet information about another user.  [34m³ [33m/I                     [34m³[40m'
                Call AdeptPrint Line,'\r\n[0;30;44m³ [1;36m/W [37mShow users Currently logged into the BBS.     [34mÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´[40m'
                Call AdeptPrint Line,'\r\n[0;30;44m³ [1;36m/T [37mTime Statistics        [36m/A [37mShow All Channels   [34m³ [36m/J [37mJoin/Make a Channel [34m³[40m'
                Call AdeptPrint Line,'\r\n[0;30;44m³ [1;36m/L [37mList users in Channel  [36m/CLS [37mClears the Screen [34m³[37mto make private, 1st    [34m³[40m'
                Call AdeptPrint Line,'\r\n[0;30;44m³ [1;36m/I [37mInvite user into your Channel                 [34m³[37mchar in name must be "+"[34m³[40m'
                Call AdeptPrint Line,'\r\n[0;30;44mÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ[1;31m/Q to Quit[0;30;44mÄÄÄÄ[1;34mÁ[0;30;44mÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ[1;34mÙ[0m\r\n\r\n'
         End
         When Command = '/T' Then Do
                Call AdeptPrint Line, '\r{FGTime Statistics:'
                Call AdeptPrint Line, '\r\n[0;36mCurrent time is ' || Time('C') || '.'
                Call AdeptPrint Line, '\r\nYou have been in chat for ' ||  Time('M') - Start || ' Minute(s).'
                Call AdeptPrint Line, '\r\nYou have {T0 minute(s) Remaining on the BBS.\r\n\r\n'
         End
         When Command = '/ME' Then Do
        If NodeTo = '' Then Call AdeptPrint Line, '\rCan you *TRY* to get the format of the command right\r\n'
        Else Do
           Call AdeptSysChatNoPrePubMsg Line, '{FAþ {FF' || UserName || '{ZZ' || SubStr(UserText,4)
           Call AdeptPrint Line, '\r{F9þ{F2þ{FAþ{FCþ{FGþ Public Action Sent {FGþ{FCþ{FAþ{F2þ{F9þ\r\n'
        End
     End
         When Command = '/G' Then Do
                If NodeTo = '' Then Call AdeptPrint Line, '\rInvalid Command. /I,1 to get info from node 1\r\n'
                Else Do
                   Call AdeptPrint Line, '\r{FGInformation About:'
/*                 Call AdeptPrint Line, '\r\n[0;36mUser  : ' || AdeptGetVar(NodeTo,1) || ', on Node ' || NodeTo || ' of ' || AdeptGetVar(Line,137) || '.' */
                   Call AdeptPrint Line, '\r\nAlias : ' || AdeptGetVar(NodeTo,2)
                   Call AdeptPrint Line, '\r\nTime  : ' || AdeptConvert(NodeTo,'{T0') || ' Minute(s) Remaining on the BBS.\r\n\r\n'
                End
         End
         When Command = '/CLS' Then Call AdeptPrint Line, '{CS'
         When Command = '/A' Then Do
                Call AdeptMenuType Line, 52,""
                Call AdeptPrint Line, '\r\n'
                Return
         End
         When Command = '/L' Then Do
                Call AdeptMenuType Line, 53,""
                Call AdeptPrint Line, '\r\n'
                Return
         End
         When Command = '/I' Then Do
if newchannel= '' then roomname=defaultchannel
else roomname=newchannel
Call AdeptCLS Line
Call AdeptMenuType Line, 52,""
/*Call AdeptMenuType Line,42,""*/
Call AdeptPrint Line,"\r\n"
Call AdeptPrint Line,"\r\nSend Invitation to which Node Number, 1-15... \r\nEnter to abort ..."
Node=AdeptInput(Line,1,1)
if Node = '' then signal done
if Node > '5' then signal NoSuchNode
/* if Node < '1' then signal UnAvail */
CheckChat = AdeptGetVar(Node,44)
IsOn = AdeptCheckBit(Node,24,CheckChat)
if IsOn = 0 then signal UnAvail
/*if left(roomname,1)='+' then do
paswrd =  AdeptInput(line,,10,,,'\r\nEnter the Password for your Conference (5 char Max):',,,)
end */
Call AdeptPrint Line,"\r\nInvitation will be sent when you "
Call AdeptHitReturn Line
carrier = AdeptGetVar(Node,276)
cr = X2C('0D')
lf = X2C('0A')
Call Adeptprint Node, cr lf username " is inviting you to the chat lounge room named "roomname cr
if left(roomname,1)='+' then Call Adeptprint Node, cr lf ' The password is: 'paswrd

/* Call AdeptComWrite Node,cr lf "Press <Enter> to continue..."*/
rc = AdeptComPeekByte(Node,1000)
signal done
UnAvail:
Call AdeptCls Line
Call AdeptPrint Line,"\r\nThat Node/User is Currently unavailable for Chat...\r\n"
Call AdeptHitReturn Line
signal done
NoSuchNode:
Call AdeptCls Line
Call AdeptPrint Line,"\r\nNo such Node Number, Node must be between 1 and 5 Inclusive\r\n"
Call AdeptHitReturn Line
signal done

done:
Call AdeptCls Line
return
         End
         When Command = '/J' Then Do
            call adeptprint line, '\r\nEnter the name of your Conference, to make a room PRIVATE'
            newchannel =  AdeptInput(line,,10,,,'\r\nput a '"+"' as the first letter in the room name, ex. +room (10 chars max):',,,)
            if newchannel='' then leave
            if left(newchannel,1)='+' then do
            idcheck='no'
            isfirst='yes'
            pwcheck='no'
            paswrd =  AdeptInput(line,,10,,,'\r\nEnter the Password for your Conference (5 char Max):',,,)

            call adeptprint line, '\r\n'
            call adeptprint line, '\r\nWhen you /I (invite) a person to your room you the system will give the user'
            call adeptprint line, '\r\nthe password 'paswrd'.  This will be transmitted ONLY to the user you are'
            call adeptprint line, '\r\ninviting in.  That user will then enter it along with the room name.'
            call adeptprint line, '\r\n'
            ok = adeptinput(line,,2,,,'\r\n Press enter to continue',,,)


            parse upper var paswrd paswrd
            parse upper var newchannel newchannel
            pw=paswrd
            nc=newchannel
            do i=0 to 16
            queuename='ND'i
               q =rxqueue('set', queuename)
               q= rxqueue('set', queuename)
               parse pull pw1'.'nc1
               if pw1='' then pw1='1036a'
               if nc1='' then nc1 = 'none'
               if queued() =0 then if i=line then do
                 q1 =rxqueue('create',queuename)
                 q2 =rxqueue('set',queuename)
                 q3 =rxqueue('get')
                 queue pw1'.'nc1
               end
               if nc<>nc1 then idcheck='ok'
               if nc=nc1 then isfirst='no'
               if nc=nc1 then idcheck='no'
               if pw=pw1 then pwcheck='ok'
               if isfirst='no' then leave
            end
            if isfirst='yes' then do
            queuename='ND'line
               q0 =rxqueue('delete',queuename)
               q1 =rxqueue('create',queuename)
               q2 =rxqueue('set',queuename)
               q3 =rxqueue('get')
            queuein = pw'.'nc
            queue queuein
            end
            end
            if left(newchannel,1)<>'+' then idcheck='ok'
            if isfirst='yes' then idcheck='ok'
            if isfirst='yes' then pwcheck='ok'
            if idcheck='ok' then do
               rc = AdeptSysChatJoinConf(Line,newchannel)
               If rc = 2 Then rc = AdeptSysChatPubMsg(Line, '{FG¯ {FF' || UserName || ' has Joined the Channel')
               UserChannelCount = Right(AdeptConvert(Line,'{CU'),2,'0')
            end
            if isfirst='no' then if pwcheck='no' then do
            newchannel=defaultchannel
            call adeptprint line, "\r\nSorry, you do not have access to that chat room"
               ok = adeptinput(line,,2,,,'\r\n Press enter to continue',,,)
            end
Call AdeptPrint Line, '\r\n{CS{B2{FC  AdeptXBBS {FGMulti-Line Chatting System v0.02    {B1{F9Ü\r\n'
Call AdeptPrint Line, '{B2  {FFYou have entered the {FC' || newChannel || ' {FFChannel' || Copies(' ',15 - Length(newChannel)) || '  {B1{F9Û\r\n'
Call AdeptPrint Line, '{B2  {FGThere are {FB' || UserChannelCount || ' {FGusers in the Chat Subsystem      {B1{F9Û\r\n'
Call AdeptPrint Line, ' ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß\r\n'
Call AdeptPrint Line, '{FGType /? -or- /H for Quick Help\r\n\r\n'
return
         end

         Otherwise Call AdeptPrint Line, "\r{FG­ {FFUnrecognised Command, Type /H for help.\r\n"
   End
Return





ProcessChatMsg:

   ARG line

   do while(AdeptSysChatMsgWaiting(line) == 1)
           RetC = AdeptSysChatGetMsg(line)

           if(RetC == 3) then do
                  /*
                  Call AdeptPrint Line, '\r\nPktType = ' || PktType || '\r\n'
                  Call AdeptPrint Line, '\r\nRetC = ' || RetC || '\r\n'
                  */
                  if(PktType == 100) then do
                          AdeptPrint(line, "\r" || ChatMsgData || "\r\n")
                  end
                  if(PktType == 101) Then do
                          AdeptPrint(line, "\r" || ChatMsgData || "\r\n")
                  end
                  if(PktType == 102) then do
                          LastPVT = SubStr(ChatMsgData,9,2)
                          AdeptPrint(line, "\r" || ChatMsgData || "\r\n")
                  end
           end
   end
return






Join:
   rc = AdeptSysChatJoinConf(Line, "Main")
   If rc = 2 Then rc = AdeptSysChatPubMsg(Line, '{FG¯ {FF' || UserName || ' has Joined the Channel')
Return

Leave:
   Parse Arg Reason
   rc = AdeptSysChatPubMsg(Line, '{FG® {FF' || UserName || ' has Left the Channel ({FG' || Reason || '{FF)')
   rc = AdeptSysChatLeaveConf(Line)
Return
