Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Chat biutente (Server) - Server.frm

Server.frm

Caricato da: Roberto VB
Scarica il programma completo

  1. Option Explicit
  2. Dim iConta As Integer
  3. Dim X As Long
  4. Dim Nick As String
  5. Private Sub cmdconnetti_Click()
  6. Static Stat As Boolean
  7. Dim iPorta As Integer
  8.     'Carico i dati del formlogin
  9.     iPorta = frmLogin.txtPorta
  10.         If Stat = False Then
  11.             If Len(iPorta) > 0 Then
  12.                 TCP.LocalPort = Val(iPorta)
  13.                 TCP.Listen
  14.                 cmdconnetti.Caption = "&Disconnetti"
  15.                 'Imposto la caption del menų
  16.                 mnuAscolta.Caption = "Disconnetti"
  17.                 Stat = True
  18.                 StatusBar1.Panels(1) = "Stato: " & "In ascolto"
  19.             Else
  20.                 MsgBox "Manca la porta!", vbExclamation
  21.             End If
  22.         Else
  23.             TCP.Close
  24.             Stat = False
  25.             cmdInvia.Enabled = False
  26.             cmdTrillo.Enabled = False
  27.             txtInvia.Enabled = False
  28.             StatusBar1.Panels(1) = "Stato: " & "Disconnesso"
  29.             cmdconnetti.Caption = "&Ascolta"
  30.             'Imposto la caption del menų
  31.             mnuAscolta.Caption = "Ascolta"
  32.             'Azzero le Textbox del Nick
  33.             txtNick.Text = ""
  34.             txtMioNick.Text = ""
  35.             'Svuoto le textbox dei nick
  36.             txtNick.Text = ""
  37.             txtMioNick.Text = ""
  38.         End If
  39. End Sub
  40.  
  41. Private Sub cmdInvia_Click()
  42.     If Len(txtInvia) > 0 Then
  43.         TCP.SendData txtInvia.Text
  44.         txtChat.Text = txtChat.Text & Time$ & Nick & ": " & vbCrLf & txtInvia.Text & vbCrLf
  45.         txtChat.SelStart = Len(txtChat.Text)
  46.         txtInvia.Text = vbNullString
  47.         StatusBar1.Panels(1) = "Stato: " & "Inviando " & LenB(txtInvia.Text) & "Bytes"
  48.     End If
  49. End Sub
  50.  
  51. Private Sub cmdRiduci_Click()
  52.  
  53. End Sub
  54.  
  55. Private Sub cmdServer_Click()
  56.     frmLogin.Show vbModal
  57. End Sub
  58.  
  59. Private Sub cmdTrillo_Click()
  60. Dim a As String
  61.     a = "Hai ricevuto un trillo!"
  62.     TCP.SendData a
  63.     txtChat.Text = txtChat.Text & "Hai inviato un trillo!" & vbCrLf
  64.     txtChat.SelStart = Len(txtChat.Text)
  65.     txtInvia.Text = vbNullString
  66.     StatusBar1.Panels(1) = "Nota: " & "E' Stato inviato un trillo!"
  67. End Sub
  68.  
  69. Private Sub Form_Load()
  70.     'Imposto il valore 5 alla variabile iConta
  71.     iConta = 5
  72. End Sub
  73.  
  74. Private Sub mnuHelpAggiornamenti_Click()
  75.     frmAggiornamenti.Show 1
  76. End Sub
  77.  
  78. Private Sub mnuPierotofy_Click()
  79.     X = ShellExecute(hWnd, "Open", "http://www.pierotofy.it", vbNullString, vbNullString, SW_NORMAL)
  80. End Sub
  81.  
  82. Private Sub mnuTipocarattereArial_Click()
  83.     'Imposto come tipo carattere Arial
  84.     txtChat.FontName = "Arial"
  85.     mnuTipocaratterePredefinito.Checked = False
  86.     mnuTipocarattereArial.Checked = True
  87.     mnuTipocarattereTimesnewroman.Checked = False
  88. End Sub
  89.  
  90. Private Sub mnuTipocaratterePredefinito_Click()
  91.     'Imposto come tipo carattere Comic Sans MS
  92.     txtChat.FontName = "Comic Sans MS"
  93.     mnuTipocaratterePredefinito.Checked = True
  94.     mnuTipocarattereArial.Checked = False
  95.     mnuTipocarattereTimesnewroman.Checked = False
  96. End Sub
  97.  
  98. Private Sub mnuTipocarattereTimesnewroman_Click()
  99.     'Imposto come tipo carattere Times New Roman
  100.     txtChat.FontName = "Times New Roman"
  101.     mnuTipocaratterePredefinito.Checked = False
  102.     mnuTipocarattereArial.Checked = False
  103.     mnuTipocarattereTimesnewroman.Checked = True
  104. End Sub
  105.  
  106.  
  107. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  108.     Dim msg As Long
  109.     msg = Me.ScaleX(X, Me.ScaleMode, vbPixels)
  110.     Select Case msg
  111.     Case WM_LBUTTONDBLCLK
  112.         frmServer.Show
  113.         frmServer.WindowState = 0
  114.         Shell_NotifyIcon NIM_DELETE, nid
  115.     End Select
  116. End Sub
  117.  
  118. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  119.     'Forzo la chiusura del programma
  120.     End
  121. End Sub
  122.  
  123. Private Sub mnuAbout_Click()
  124.     'Visualizza frmAbout
  125.     frmAbout.Show
  126. End Sub
  127. Private Sub mnuAscolta_Click()
  128.     'Richiama l'evento Click del tasto connetti
  129.     cmdconnetti_Click
  130. End Sub
  131. Private Sub mnuEsci_Click()
  132. Dim Answer As String
  133.     Answer = MsgBox("Sei sicuro di voler terminare il programma?", vbExclamation + vbYesNo + vbDefaultButton2, "Termina programma")
  134.     If Answer = vbYes Then
  135.         End
  136.     Else
  137.         frmServer.Show
  138.     End If
  139. End Sub
  140.  
  141. Private Sub mnuFileSalva_Click()
  142. Dim NomeFile As String
  143. Dim File As String
  144.     NomeFile = InputBox("Inserisci il nome del file da salvare", "NOME")
  145.     File = "C:/" & NomeFile & ".dat"
  146.     Open File For Output As #1
  147.     Write #1, txtChat.Text
  148.     Close #1
  149. End Sub
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157. Private Sub mnuModificaColorecarattere_Click()
  158.     dlgComune.ShowColor
  159.     txtChat.ForeColor = dlgComune.Color
  160. End Sub
  161.  
  162. Private Sub mnuModificaDimensionecarattereAumenta_Click()
  163.     txtChat.FontSize = txtChat.FontSize + 1
  164.     If txtChat.FontSize >= 25 Then
  165.         txtChat.FontSize = 10
  166.     End If
  167. End Sub
  168.  
  169. Private Sub mnuModificaDimensionecarattereDiminuisci_Click()
  170.     txtChat.FontSize = txtChat.FontSize - 1
  171.     If txtChat.FontSize <= 9 Then
  172.         txtChat.FontSize = 10
  173.     End If
  174. End Sub
  175.  
  176.  
  177.  
  178. Private Sub mnuMostraIP_Click()
  179.     X = ShellExecute(hWnd, "Open", "http://www.ilmioip.it", vbNullString, vbNullString, SW_NORMAL)
  180. End Sub
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190. Private Sub mnuToolPortscan_Click()
  191.     'Visualizzo il Port Scan
  192.     frmPortScan.Show 1
  193. End Sub
  194.  
  195. Private Sub mnuVisualizzaRiduci_Click()
  196.    
  197.     nid.cbSize = Len(nid)
  198.     nid.hWnd = frmServer.hWnd
  199.     nid.uId = 0
  200.     nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
  201.     nid.uCallBackMessage = WM_MOUSEMOVE
  202.     'nid.hIcon = cmdRiduci.Picture
  203.     Shell_NotifyIcon NIM_ADD, nid
  204.     Me.WindowState = vbMinimized
  205.     Me.Hide
  206. End Sub
  207.  
  208.  
  209. Private Sub mnuWebBug_Click()
  210.         X = ShellExecute(hWnd, "Open", "http://otrebor6.altervista.org/bug.html", vbNullString, vbNullString, SW_NORMAL)
  211. End Sub
  212.  
  213. Private Sub mnuWebHomePage_Click()
  214.         X = ShellExecute(hWnd, "Open", "http://otrebor6.altervista.org/chat.html", vbNullString, vbNullString, SW_NORMAL)
  215. End Sub
  216.  
  217. Private Sub TCP_ConnectionRequest(ByVal requestID As Long)
  218.     StatusBar1.Panels(1) = "Stato: " & "Richiesta di connessione"
  219.     If MsgBox("Accettare la connessione?", vbYesNo) = vbYes Then
  220.         TCP.Close
  221.         TCP.Accept requestID
  222.         ' Richiede il Nickname personale dell'utente
  223.         ' e poi lo invia
  224.         Nick = "- " & frmLogin.txtNick
  225.         TCP.SendData Nick
  226.         'Invio un suono per segnalare l'avvenuta connessione
  227.         PlaySound App.Path & "\notify.wav", 0, SND_FILENAME Or SND_SYNC
  228.         StatusBar1.Panels(1) = "Stato: " & "Connesso"
  229.         'Abilita il bottone Invia, Trillo e la Text invia
  230.         cmdInvia.Enabled = True
  231.         cmdTrillo.Enabled = True
  232.         txtInvia.Enabled = True
  233.     Else
  234.         TCP.Close
  235.         TCP.Listen
  236.         'Rifiuta la connessione
  237.         PlaySound App.Path & "\ir_inter.wav", 0, SND_FILENAME Or SND_SYNC
  238.         StatusBar1.Panels(1) = "Stato: " & "Connessione rifiutata"
  239.     End If
  240. End Sub
  241. Private Sub TCP_Close()
  242.     TCP.Close
  243.     PlaySound App.Path & "\ir_inter.wav", 0, SND_FILENAME Or SND_SYNC
  244.     StatusBar1.Panels(1) = "Stato: " & "Disconnesso"
  245.     'Svuoto le textbox dei nick
  246.     txtNick.Text = ""
  247.     txtMioNick.Text = ""
  248.    
  249. End Sub
  250. Private Sub TCP_DataArrival(ByVal bytesTotal As Long)
  251. Dim Data As String
  252.     TCP.GetData Data
  253.     'Quando ricevo Data la caption del form cambia
  254.     'in modo che se un utente ha ridotto ad icona il programma
  255.     'possa accorgersi del nuovo messaggio in arrivo.
  256.     'Dopodichč attivo il timer.
  257.     frmServer.Caption = "New message!"
  258.     Timer1.Enabled = True
  259.     'Se ricevo un trillo allora riproduce il Beep
  260.         If Data = "Hai ricevuto un trillo!" Then Beep
  261.     StatusBar1.Panels(1) = "Stato: " & "In arrivo " & bytesTotal & "Bytes"
  262.     txtChat.Text = txtChat.Text & Time$ & txtNick.Text & ": " & vbCrLf & Data & vbCrLf
  263.     txtChat.SelStart = Len(txtChat.Text)
  264.     ' Se Data inizia con "- " allora vuol dire che il client
  265.     ' Ha inviato il suo Nickname, per cui il valore di Data
  266.     ' verrā salvato nella txtNick
  267.     If Left(Data, 2) = "- " Then
  268.         txtNick.Text = Data
  269.         txtMioNick.Text = Nick
  270.     End If
  271.     End Sub
  272. Private Sub TCP_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
  273.     TCP.Close
  274.     PlaySound App.Path & "\ir_inter.wav", 0, SND_FILENAME Or SND_SYNC
  275.     StatusBar1.Panels(1) = "Stato: " & "Errore IP" & Number
  276. End Sub
  277. Private Sub TCP_SendComplete()
  278.     StatusBar1.Panels(1) = "Nota: " & "Dati inviati con successo"
  279. End Sub
  280.  
  281.  
  282. Private Sub Timer1_Timer()
  283.     'Inizialmente ho dato ad iConta il valore di 5
  284.     'Ogni secondo il suo valore diminuisce.
  285.     'Una volta raggiunto il valore 0:
  286.     'La caption del form cambia e diventa vuota
  287.     'iConta ritorna al suo valore iniziale
  288.     'e il timer viene disattivato
  289.     iConta = iConta - 1
  290.     If iConta = 0 Then
  291.         frmServer.Caption = ""
  292.         iConta = 5
  293.         Timer1.Enabled = False
  294.     End If
  295.     'In caso la casella di testo txtMioNick rimanga vuota, questo codice
  296.     'la riempie con il nick
  297.     txtMioNick.Text = Nick
  298. End Sub