home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / IPXSPX.ZIP / NETCHAT.TXT < prev    next >
Text File  |  1993-12-20  |  14KB  |  525 lines

  1. Option Explicit
  2. Option Base 1
  3.  
  4. Sub About_Click ()
  5.     aboutForm.Show 1
  6. End Sub
  7.  
  8. Sub BinderyObjList_DblCLick ()
  9.     Dim Address As String
  10.     Dim formatString As String
  11.     Dim nwTime As String
  12.     Dim YY, MM, DD, HR, MI, SC, DA As Integer
  13.     Dim nwLoginTime  As Variant
  14.     Dim nwUser As USER_INFO
  15.     Dim ccode, index As Integer
  16.  
  17.     nwUser = netWareUsers(BinderyObjList.ListIndex + 1)
  18.     userName = Mid$(BinderyObjList.Text, 1, 20)
  19.     userConn = nwUser.connNumber
  20.     nwTime = nwUser.loginTime
  21.     YY = Asc(Mid(nwTime, 1, 1)) + 1900
  22.     MM = Asc(Mid(nwTime, 2, 1))
  23.     DD = Asc(Mid(nwTime, 3, 1))
  24.     HR = Asc(Mid(nwTime, 4, 1))
  25.     MI = Asc(Mid(nwTime, 5, 1))
  26.     SC = Asc(Mid(nwTime, 6, 1))
  27.     
  28.     'pretty print the login time
  29.     nwLoginTime = DateSerial(YY, MM, DD)
  30.     formatString = Format$(nwLoginTime, "mm-dd-yyyy")
  31.     userLoginTime = formatString
  32.  
  33.     'pretty print the login date
  34.     formatString = TimeSerial(HR, MI, SC)
  35.     userLoginDay = formatString
  36.     
  37.     'pretty print the internet address
  38.     ccode = NWGetInternetAddress(nwConn, userConn, yourInetAddress)
  39.     If ccode Then
  40.     MsgBox "Error getting internet addresss"
  41.     End If
  42.  
  43.     formatString = yourInetAddress.network & yourInetAddress.node
  44.     FormatInternetAddress formatString
  45.     
  46.     userAddress = formatString
  47.     userPicture.Visible = True
  48.  
  49.     ipx1.RemoteName = yourInetAddress.network & yourInetAddress.node & Chr$(&H54) & Chr$(&H54)
  50.     connectButton.SetFocus
  51.  
  52. End Sub
  53.  
  54. Sub BinderyObjList_KeyPress (KeyAscii As Integer)
  55.     If KeyAscii = 13 Then
  56.     BinderyObjList_DblCLick
  57.     End If
  58. End Sub
  59.  
  60. Sub cancelButton_Click ()
  61.     
  62.     userPicture.Visible = False
  63.     sendBox.Visible = False
  64.     receiveBox.Visible = False
  65.  
  66.     connectButton.Enabled = True
  67.     disconnectButton.Enabled = False
  68.  
  69. End Sub
  70.  
  71. Sub connectButton_Click ()
  72.     Dim formatString As String
  73.     Dim NetData As String
  74.  
  75.     If Mid$(ipx1.LocalName, 1, 10) = Mid$(ipx1.RemoteName, 1, 10) Then
  76.     MsgBox "Unable to chat to yourself"
  77.     Exit Sub
  78.     End If
  79.  
  80.     'Send the connect request and my connection number
  81.     NetData = Chr$(IPXSPX_CONNECT) & Chr$(nwConnNumber / 256) & Chr$(nwConnNumber And &HFF)
  82.     
  83.     netChatState = IPXSPX_SENDCONN
  84.     ipx1.Send = NetData
  85.     
  86.     formatString = yourInetAddress.network & yourInetAddress.node
  87.     FormatInternetAddress formatString
  88.     netChatConnection!connectionLabel = "Attempting to chat with " & formatString
  89.     netChatConnection!connectionOK.Caption = "&Cancel"
  90.  
  91.     netChatConnection.Show 1
  92.     Select Case netChatState
  93.     Case IPXSPX_CONNECT
  94.         sendBox.Visible = True
  95.         receiveBox.Visible = True
  96.         connectButton.Enabled = False
  97.         disconnectButton.Enabled = True
  98.         cancelButton.Enabled = False
  99.         receiveBox.Text = ""
  100.         sendBox.Text = ""
  101.     Case IPXSPX_SENDCONN
  102.         NetData = Chr$(IPXSPX_DISCONNECT)
  103.         ipx1.Send = NetData
  104.         netChatState = IPXSPX_DISCONNECT
  105.     End Select
  106.     
  107. End Sub
  108.  
  109. Sub ConnectionRequest (inetAddress)
  110.     Dim formatString As String
  111.  
  112.     formatString = inetAddress
  113.     FormatInternetAddress formatString
  114.     netChatConnection!connectionLabel = formatString & " calling, will you accept the charges?"
  115.  
  116. End Sub
  117.  
  118. Sub ConnectState (netChatPtr As NetChatInput)
  119.     Dim connNumber As Integer
  120.     Dim Address As String
  121.     Dim formatString As String
  122.     Dim nwTime As String
  123.     Dim YY, MM, DD, HR, MI, SC, DA As Integer
  124.     Dim nwLoginTime  As Variant
  125.     Dim nwUser As USER_INFO
  126.     Dim ccode, index As Integer
  127.  
  128.     Select Case netChatState
  129.     Case IPXSPX_SENDCONN
  130.         If ipx1.ReceivedFrom = ipx1.RemoteName Then
  131.         netChatState = IPXSPX_CONNECT
  132.         Unload netChatConnection
  133.         End If
  134.  
  135.     Case IPXSPX_DISCONNECT
  136.         netChatState = IPXSPX_RECEIVECONN
  137.         ConnectionRequest Mid$(ipx1.ReceivedFrom, 1, 10)
  138.         netChatConnection.Show 1
  139.         If netChatState = IPXSPX_RECEIVECONN Then
  140.         ipx1.RemoteName = ipx1.ReceivedFrom
  141.         connNumber = Asc(Mid$(netChatPtr.data, 2, 1)) * 256 + Asc(Mid$(netChatPtr.data, 3, 1))
  142.         
  143.         ipx1.Send = Chr$(IPXSPX_CONNECT) & Chr$(54) & Chr$(54) & Chr$(nwConnNumber / 256) & Chr$(nwConnNumber And &HFF)
  144.  
  145.         ccode = NWGetConnectionInformation(nwConn, connNumber, ByVal nwUser.objectName, nwUser.objectType, nwUser.objectID, ByVal nwUser.loginTime)
  146.         If ccode Then
  147.             MsgBox "Unable to get connection information"
  148.             Exit Sub
  149.         End If
  150.  
  151.         nwTime = nwUser.loginTime
  152.         YY = Asc(Mid(nwTime, 1, 1)) + 1900
  153.         MM = Asc(Mid(nwTime, 2, 1))
  154.         DD = Asc(Mid(nwTime, 3, 1))
  155.         HR = Asc(Mid(nwTime, 4, 1))
  156.         MI = Asc(Mid(nwTime, 5, 1))
  157.         SC = Asc(Mid(nwTime, 6, 1))
  158.     
  159.         'pretty print the login time
  160.         nwLoginTime = DateSerial(YY, MM, DD)
  161.         formatString = Format$(nwLoginTime, "mm-dd-yyyy")
  162.         userLoginTime = formatString
  163.  
  164.         'pretty print the login date
  165.         formatString = TimeSerial(HR, MI, SC)
  166.         userLoginDay = formatString
  167.     
  168.         'pretty print the internet address
  169.         formatString = ipx1.RemoteName
  170.         FormatInternetAddress formatString
  171.     
  172.         userAddress = formatString
  173.         userPicture.Visible = True
  174.  
  175.         sendBox.Visible = True
  176.         receiveBox.Visible = True
  177.         connectButton.Enabled = False
  178.         disconnectButton.Enabled = True
  179.         cancelButton.Enabled = False
  180.         netChatState = IPXSPX_CONNECT
  181.         receiveBox.Text = ""
  182.         sendBox.Text = ""
  183.         netChatForm.WindowState = 0
  184.         sendBox.SetFocus
  185.         End If
  186.     End Select
  187.  
  188. End Sub
  189.  
  190. Sub ConvertInputToData (NetData, netChatPtr As NetChatInput)
  191.     
  192.     netChatPtr.header.destination.network = Mid$(ipx1.LocalName, 1, 4)
  193.     netChatPtr.header.destination.node = Mid$(ipx1.LocalName, 5, 6)
  194.     netChatPtr.header.destination.socket = Mid$(ipx1.LocalName, 11, 2)
  195.     netChatPtr.header.source.network = Mid$(NetData, 1, 4)
  196.     netChatPtr.header.source.node = Mid$(NetData, 5, 6)
  197.     netChatPtr.header.source.socket = Mid$(NetData, 11, 2)
  198.     netChatPtr.data = Mid$(NetData, 13)
  199.  
  200. End Sub
  201.  
  202. Sub DataState (netChatPtr As NetChatInput)
  203.     Dim netVal As String
  204.     
  205.     Select Case netChatState
  206.     Case IPXSPX_CONNECT
  207.         netVal = Mid$(netChatPtr.data, 2)
  208.         Select Case Asc(netVal)
  209.         Case 13 'return
  210.             receiveBox = receiveBox & Chr$(13) & Chr$(10)
  211.         Case 8 'Backspace
  212.         If Len(receiveBox) > 0 Then
  213.             If Asc(Right$(receiveBox, 1)) = 10 Then
  214.             receiveBox = Left$(receiveBox, Len(receiveBox) - 2)
  215.             Else
  216.             receiveBox = Left$(receiveBox, Len(receiveBox) - 1)
  217.             End If
  218.         End If
  219.         Case Else   ' Must be something else.
  220.             receiveBox = receiveBox & netVal
  221.         
  222.     End Select
  223.  
  224.     End Select
  225. End Sub
  226.  
  227. Sub disconnectButton_Click ()
  228.     
  229.     Dim NetData As String
  230.     
  231.     NetData = Chr$(IPXSPX_DISCONNECT)
  232.     ipx1.Send = NetData
  233.  
  234.     userPicture.Visible = False
  235.     sendBox.Visible = False
  236.     receiveBox.Visible = False
  237.  
  238.     connectButton.Enabled = True
  239.     disconnectButton.Enabled = False
  240.     cancelButton.Enabled = True
  241.     netChatState = IPXSPX_DISCONNECT
  242. End Sub
  243.  
  244. Sub DisconnectionRequest (inetAddress)
  245.     Dim formatString As String
  246.     
  247.     formatString = inetAddress
  248.     FormatInternetAddress formatString
  249.     netChatDisConnection!disconnectionLabel = formatString & " has disconnected"
  250.  
  251. End Sub
  252.  
  253. Sub DisConnectState (netChatPtr As NetChatInput)
  254.     
  255.     Select Case netChatState
  256.     Case IPXSPX_RECEIVECONN
  257.         netChatState = IPXSPX_DISCONNECT
  258.         Unload netChatConnection
  259.  
  260.     Case IPXSPX_SENDCONN
  261.         netChatState = IPXSPX_DISCONNECT
  262.  
  263.     Case IPXSPX_DISCONNECT
  264.         Unload netChatConnection
  265.  
  266.     Case IPXSPX_CONNECT
  267.         If ipx1.ReceivedFrom = ipx1.RemoteName Then
  268.         DisconnectionRequest Mid$(ipx1.ReceivedFrom, 1, 10)
  269.         netChatState = IPXSPX_RECEIVECONNMODAL
  270.         netChatDisConnection.Show 1
  271.         userPicture.Visible = False
  272.         sendBox.Visible = False
  273.         receiveBox.Visible = False
  274.         connectButton.Enabled = True
  275.         disconnectButton.Enabled = False
  276.         cancelButton.Enabled = True
  277.         netChatState = IPXSPX_DISCONNECT
  278.         End If
  279.     End Select
  280.  
  281. End Sub
  282.  
  283. Sub exitButton_Click ()
  284.     Dim NetData As String
  285.     
  286.     'if still connected, send a disconnect
  287.     If netChatState = IPXSPX_CONNECT Then
  288.     NetData = Chr$(IPXSPX_DISCONNECT)
  289.     ipx1.Send = NetData
  290.     End If
  291.  
  292.     End
  293. End Sub
  294.  
  295. Sub Form_Load ()
  296.     Dim title, server, fileServerName As String
  297.     Dim ccode, connID As Integer
  298.     Dim s As String
  299.  
  300.     ccode = NWCallsInit(ByVal 0&, ByVal 0&)
  301.     If ccode Then
  302.     MsgBox "Unable to initialize NWCALLS.DLL"
  303.     End
  304.     End If
  305.  
  306.     Screen.MousePointer = 11        'change mouse cursor to hourglass
  307.  
  308.     server = String$(48, 0)
  309.     server = GetConnections()
  310.  
  311.     ScanUsers server    'scan the bindery of the default server
  312.  
  313.     ServerNameBox.Selected(0) = True
  314.     BinderyObjList.Selected(0) = True
  315.  
  316.     netChatState = IPXSPX_DISCONNECT
  317.  
  318. End Sub
  319.  
  320. Sub FormatInternetAddress (inString)
  321.     Dim nwString, outString As String
  322.     Dim index As Integer
  323.  
  324.     'Pretty printing for the hexidecimal network and node addresses
  325.     outString = "["
  326.     nwString = Mid$(inString, 1, 4)
  327.     For index = 1 To Len(nwString)
  328.        outString = outString & Format$(Hex$(Asc(Mid$(nwString, index, 1))), "00")
  329.     Next index
  330.  
  331.     outString = outString & "]["
  332.     nwString = Mid$(inString, 5, 6)
  333.     For index = 1 To Len(nwString)
  334.     outString = outString & Format$(Hex$(Asc(Mid$(nwString, index, 1))), "00")
  335.     Next index
  336.  
  337.     outString = outString & "]"
  338.  
  339.     inString = outString
  340. End Sub
  341.  
  342. Function GetConnections () As String
  343.  Dim connID As Integer
  344.  Dim fileServerName As String
  345.  Dim ccode, mode, connListSize As Integer
  346.  Dim numConnections As Integer
  347.  ReDim connListBuffer(50) As Integer
  348.  
  349.  ServerNameBox.Clear
  350.  
  351.  mode = 0
  352.  connListSize = 50
  353.  ccode = NWGetConnectionList(mode, connListBuffer(1), connListSize, numConnections)
  354.  
  355.  
  356.  For connID = 1 To numConnections
  357.     'for each connection in workstation's file server name table
  358.     'get the table entry, then see if it's null
  359.     
  360.     fileServerName = String$(48, 0)
  361.     NWGetFileServerName connID, fileServerName
  362.     If Left$(fileServerName, 1) <> Chr$(0) Then
  363.         'you have to explicitly look for a null in the first character,
  364.         'because Visual Basic doesn't know about null-terminated strings
  365.         '(a null prints as a space)
  366.         If connID = 1 Then GetConnections = fileServerName
  367.         ServerNameBox.AddItem fileServerName
  368.     End If
  369.     Next connID
  370.  
  371. End Function
  372.  
  373. Sub ipx1_LinkEvent ()
  374.     
  375.     If ipx1.Event Then
  376.     MsgBox "Error Link: " & ipx1.Event
  377.     Exit Sub
  378.     End If
  379.  
  380. End Sub
  381.  
  382. Sub ipx1_ReceiveData ()
  383.     Dim NetString, NetData As String
  384.     Dim nwConn As Integer
  385.     Dim netChatPtr As NetChatInput
  386.  
  387.     ConvertInputToData ipx1.ReceivedFrom & ipx1.Received, netChatPtr
  388.  
  389.     Select Case Asc(Mid$(netChatPtr.data, 1, 1))
  390.     'select from the first byte of the packet
  391.     'which contains the action type
  392.  
  393.     Case IPXSPX_CONNECT
  394.         ConnectState netChatPtr
  395.  
  396.     Case IPXSPX_DISCONNECT
  397.         DisConnectState netChatPtr
  398.  
  399.     Case IPXSPX_DATA
  400.         DataState netChatPtr
  401.  
  402.     End Select
  403.  
  404. End Sub
  405.  
  406. Sub ipx1_SendData ()
  407.  
  408.     'Fired when packet is sent
  409.  
  410. End Sub
  411.  
  412. Sub Rescan_Click ()
  413.    
  414.     ServerNameBox_DblClick  'same effect as if the user had
  415.                 'double-clicked on a file server name
  416.  
  417. End Sub
  418.  
  419. Sub RescanButton_Click ()
  420.     Dim server As String
  421.  
  422.     server = GetConnections()
  423.     ServerNameBox_DblClick  'same effect as if the user had
  424.                 'double-clicked on a file server name
  425. End Sub
  426.  
  427. Sub ScanUsers (server)
  428.  
  429.     Dim objectType As String * 6
  430.     Dim maxConns As Long
  431.     Dim ccode As Integer
  432.     Dim index As Integer
  433.     Dim nIndex As Integer
  434.     Dim nwUser As USER_INFO
  435.     Dim objectName As String * 48
  436.  
  437.     Screen.MousePointer = 11        'change mouse cursor to hourglass
  438.  
  439.     BinderyObjList.Clear
  440.     
  441.     ccode = NWGetConnectionHandle(server, ByVal 0, nwConn, ByVal 0&)
  442.     'get the connection handle to our default server
  443.     If (ccode) Then
  444.     MsgBox "Unable to get connection"
  445.     Exit Sub
  446.     End
  447.     End If
  448.  
  449.     ccode = NWGetConnectionNumber(nwConn, nwConnNumber)
  450.     'and get the connection number
  451.     If (ccode) Then
  452.     MsgBox "Unable to get connection number"
  453.     Exit Sub
  454.     End
  455.     End If
  456.  
  457.     ccode = NWGetInternetAddress(nwConn, nwConnNumber, myInetAddress)
  458.     Rem myInetAddress = ipx1.LocalName
  459.     ' get our internet address and put it in a global for use later
  460.     If (ccode) Then
  461.     MsgBox "Unable to get internet address"
  462.     Exit Sub
  463.     End
  464.     End If
  465.     
  466.     ccode = NWGetFileServerInformation(nwConn, ByVal 0&, ByVal 0&, ByVal 0&, ByVal 0&, maxConns, ByVal 0&, ByVal 0&, ByVal 0&, ByVal 0&, ByVal 0&)
  467.     ' get the maximum number of connections the file server has used
  468.     If (ccode) Then
  469.     Exit Sub
  470.     End If
  471.  
  472.     ReDim netWareUsers(maxConns)
  473.     nIndex = 1
  474.     'loop through all the possible connection numbers to get
  475.      'all the logged in users
  476.  
  477.     For index = 1 To maxConns
  478.     ccode = NWGetConnectionInformation(nwConn, index, ByVal nwUser.objectName, nwUser.objectType, nwUser.objectID, ByVal nwUser.loginTime)
  479.     If ccode = 0 And Left$(nwUser.objectName, 1) <> Chr$(0) Then
  480.         BinderyObjList.AddItem nwUser.objectName
  481.         nwUser.connNumber = index
  482.         netWareUsers(nIndex) = nwUser
  483.         nIndex = nIndex + 1
  484.     End If
  485.     DoEvents
  486.     Next index
  487.  
  488. EndConns:
  489.     Screen.MousePointer = 0     'change mouse cursor back to how it was
  490.  
  491. End Sub
  492.  
  493. Sub sendBox_KeyPress (KeyAscii As Integer)
  494.     ipx1.Send = Chr$(IPXSPX_DATA) & Chr$(KeyAscii)
  495. End Sub
  496.  
  497. Sub ServerNameBox_DblClick ()
  498.     Dim server, prefServer As String
  499.     Dim index, ccode, connID As Integer
  500.  
  501.     prefServer = ServerNameBox.Text
  502.     
  503.     If Len(prefServer) = 0 Then
  504.     Rem no server selected
  505.     prefServer = ServerNameBox.List(0)
  506.     End If
  507.  
  508.     server = GetConnections()
  509.  
  510.     ScanUsers prefServer 'then go scan its bindery
  511.     index = SendMessage(ServerNameBox.hWnd, LB_FINDSTRING, ByVal -1, ByVal prefServer)
  512.     If (index <> LB_ERR) Then
  513.     ServerNameBox.Selected(index) = True
  514.     Else
  515.     ServerNameBox.Selected(0) = True
  516.     End If
  517.  
  518.     BinderyObjList.Selected(0) = True
  519. End Sub
  520.  
  521. Sub userPictureDrop_DblClick ()
  522.     aboutForm.Show 1
  523. End Sub
  524.  
  525.