Jump to content

another chat/client (up to 100 clients)


Nuffilein805
 Share

Recommended Posts

  • Replies 42
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Wow, way to post in a four month old aritcle Gene.

It was new to me. :lmao::king:

Gene

I didn't realize there was a time limit. o:);)

Edited by Gene

[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Link to comment
Share on other sites

I continue to pursue and modify Nuffilein's Chat Client. Messages are now timestamped when they arrive. I added the buttons I mentioned before for a "Wait a minute..." message and "Away from the PC now." I added a button to toggle message logging to a file On and Off. And one more button to allow the user to view the message log file. I don't remember if I talked about it last time but I also added code to put the Client window on top when a message arrives and to sound a weird beep. As with the issues below that works some of the time.

I am still having some problems... part of the time the messages go zipping back and forth just as you would expect, the rest of the time it is inconsistent, I haven't been able to see a pattern. My PC is running Win2K 256Mb on a 1400+ AMD CPU, the other client is running on a 300Mhz, 192Mb Win98se PC, the chat server is running on a 233Mhz, 256Mb Win2K Server PC. The Win2K Server only does logons for 2 people, DNS for itself and 2 PCs runs the chat server and runs a compiled AutoIt script to check that the Internet connection is up about every half a minute. It isn't a speed demon, but that seems a very slight load to me.

I'd really like to have comments critical or otherwise...

Here is the code with the changes mintioned.

;client for 100client-server
;made by Marten Zimmermann

#Include <Date.au3>
#include <guiconstants.au3>

Opt("WinTitleMatchMode",2)
Global $connect_port = 34000
Global $fHandle, $iLogFlg, $sLogVar, $edit
$LogMsg = ""
$iLogFlg = 0
$sFileName = IniRead(@ScriptDir & "\client.ini", "File", "Name", "")

$ip = ""
$ip = IniRead(@ScriptDir & "\client.ini", "Server", "IPaddr", "")
If $ip = "" Then
 $ip = InputBox("IP-Adress", "Gimme the IP-Adress of the Server", @IPAddress1)
 IniWrite(@ScriptDir & "\client.ini", "Server", "IPaddr", $ip)
EndIf

TCPStartup()

$socket = TCPConnect($ip, $connect_port)
If $socket = -1 Then
 Exit
EndIf

Do
 Do
  $user = ""
  $user = IniRead(@ScriptDir & "\client.ini", "Client", "User", "")
  If $user = "" Then
   $user = InputBox("Connected", "Connection established please type in your desired Username")
   IniWrite(@ScriptDir & "\client.ini", "Client", "User", $user)
  EndIf
  If @error = 1 Then
   $end = MsgBox(4, "End client", "Sure you want to exit?")
   If $end = 6 Then
    Exit
   EndIf
  EndIf
 Until StringLen($user) > 2 And StringLen($user) < 12
 TCPSend($socket, "~~us:" & $user)
 
 Do
  $recv = TCPRecv($socket, 512)
  If $recv = "~~password" Then
   $pw = InputBox("Password required", "Please type in the password for " & $user, "", "*")
   TCPSend($socket, "~~pw:" & $pw)
  EndIf
 Until $recv = "~~accepted" Or $recv = "~~rejected" Or @error = 1
Until $recv = "~~accepted" Or $recv = "~~rejected"

If $recv = "~~rejected" Then
 MsgBox(0, "Failure", "Maximum number of users reached or Server currently not availible, please try again later")
 Exit
EndIf
$CCT = "Chat Client - Connection established: " & $user
$main = GUICreate($CCT, 500, 200)
$input = GUICtrlCreateInput("", 10, 10, 280)
$edit = GUICtrlCreateEdit("", 10, 40, 280, 110, $ES_READONLY + $ES_MULTILINE + $WS_VSCROLL + $ES_AUTOVSCROLL)
;$userlist = GUICtrlCreateEdit ("", 300, 10, 190, 180, $ES_READONLY + $ES_MULTILINE + $WS_VSCROLL + $ES_AUTOVSCROLL)
$userlist = GUICtrlCreateEdit("", 300, 10, 95, 180, $ES_READONLY + $ES_MULTILINE + $WS_VSCROLL + $ES_AUTOVSCROLL)
$send = GUICtrlCreateButton("Send", 10, 160, 280, 20, $BS_DEFPUSHBUTTON)
$Wait = GUICtrlCreateButton("Wait a Moment", 406, 10, 85, 41, BitOR($BS_CENTER, $BS_MULTILINE))
$Away = GUICtrlCreateButton("Away from PC", 406, 55, 85, 41, BitOR($BS_CENTER, $BS_MULTILINE))
$LogMsg = GUICtrlCreateButton("", 406, 100, 80, 41, BitOR($BS_CENTER, $BS_MULTILINE))
GUICtrlSetData($LogMsg, "Msg Log Off")
$ViewLog = GUICtrlCreateButton("View Log", 406, 145, 85, 41, BitOR($BS_CENTER, $BS_MULTILINE))
GUICtrlSetState($input, $GUI_FOCUS)
GUISetState(@SW_SHOW)

While 1
 $msg = GUIGetMsg()
 If $msg = $GUI_EVENT_CLOSE Then
  $CCT = "Chat - Client shutting down in 5 seconds."
  If $iLogFlg = 1 Then 
   _MsgLogging($fHandle, $CCT)
   Sleep(100)
   FileClose($fHandle)
  EndIf 
  GUICtrlSetData($edit, $CCT)
  TCPSend($socket, "~~bye")
  Sleep(5000)
  TCPShutdown()
  Exit
 EndIf
 
 If $msg = $LogMsg Then
  If $iLogFlg = 0 Then
   $sFileName = IniRead(@ScriptDir & "\client.ini", "File", "Name", "")
   If $sFileName = "" Then
    $sFileName = FileSaveDialog( "Choose a log file.", @ScriptDir, "All Log Files (*.log)")
    IniWrite(@ScriptDir & "\client.ini", "File", "Name", $sFileName)
   EndIf
   $fHandle = FileOpen($sFileName, 1)
   $iLogFlg = 1
   GUICtrlSetData($LogMsg, "Msg Log On")
  Else
   If $iLogFlg = 1 Then
    $iLogFlg = 0
    GUICtrlSetData($LogMsg, "Msg Log Off")
    FileClose($fHandle)
   EndIf
  EndIf
 EndIf
 
 If $msg = $ViewLog Then
  If $sFileName <> "" Then
   If FileExists( $sFileName) Then 
    Run( "Notepad.exe" & " " & $sFileName)
   Else 
    $sFileName = ""
   EndIf 
  Else 
   MsgBox(0,"Help","A Client Chat Log has not been established.  Click the" & @CRLF & "'Msg Log Off' button to establish a Client Chat Log file.")
  EndIf
 EndIf 
 
 If $msg = $send Or $msg = $Wait Or $msg = $Away Then
  $sLogVar = GUICtrlRead($input)
  Select
   Case $msg = $send
    If GUICtrlRead($input) <> "" Then
      TCPSend($socket, GUICtrlRead($input))
     ;TCPSend($socket, "~~pm:Gene " & _Now() & GUICtrlRead($input))
     GUICtrlSetData($edit, _Now() & @CRLF & GUICtrlRead($input) & @CRLF & GUICtrlRead($edit))
     If $iLogFlg = 1 Then
      _MsgLogging($fHandle, $sLogVar)
     EndIf
     GUICtrlSetData($input, "")
    EndIf
    
   Case $msg = $Wait
    $sMsg = IniRead(@ScriptDir & "\client.ini", "Messages", "Wait", "")
     TCPSend($socket, $sMsg)
    ;TCPSend($socket, "~~pm:Gene " & _Now() & @CRLF & $sMsg)
    GUICtrlSetData($edit, _Now() & @CRLF & $sMsg & @CRLF & GUICtrlRead($edit))
    If $iLogFlg = 1 Then
      _MsgLogging($fHandle, $sLogVar)
    EndIf
    GUICtrlSetData($input, "")
    
   Case $msg = $Away
    $sMsg = IniRead(@ScriptDir & "\client.ini", "Messages", "Away", "")
     TCPSend($socket, _Now() & @CRLF & $sMsg)
    ;TCPSend($socket, "~~pm:Gene " & _Now() & @CRLF & $sMsg)
    GUICtrlSetData($edit, _Now() & @CRLF & $sMsg & @CRLF & GUICtrlRead($edit))
    If $iLogFlg = 1 Then
      _MsgLogging($fHandle, $sLogVar)
    EndIf
    GUICtrlSetData($input, "")
    
  EndSelect
 EndIf
 
 $recv = TCPRecv($socket, 512)
 $err = @error
 
 If $recv = "~~bye" Then
  GUICtrlSetData($edit, "~~Connection Lost" & @CRLF & GUICtrlRead($edit))
  TCPShutdown()
  ExitLoop
 EndIf
 
 If StringInStr($recv, "~~kick:") And StringInStr($recv, $user, 1) Then
  TCPSend($socket, "~~bye")
  GUICtrlSetData($edit, "You have been kicked!" & @CRLF & GUICtrlRead($edit))
  Sleep(2000)
  TCPShutdown()
  ExitLoop
 EndIf
 
 $priv = 0
 If StringInStr($recv, "~~pm:") And StringInStr($recv, $user) Then
  $user1 = $user & " "
  If StringInStr($recv, $user1) Then
   $recv = StringReplace($recv, "~~pm:", "", 1)
   $recv = StringReplace($recv, $user & " ", "", 1)
   GUICtrlSetData($edit, _Now() & @CRLF & $recv & " (private)" & @CRLF & GUICtrlRead($edit))
   WinSetState ( $CCT, "", @SW_ENABLE )
   WinSetState ( $CCT, "", @SW_RESTORE )
   WinSetState ( $CCT, "", @SW_SHOW )
   WinSetOnTop ( $CCT, "", 1)
   WinActivate ( $CCT)
   Sleep(200)
   WinSetOnTop ( $CCT, "", 0)
   _Beeper()
   $priv = 1
  EndIf
 EndIf
 
 If StringInStr($recv, "~~accepted") Then
  $recv = ""
 EndIf
 
 If $recv <> "" And $err = 0 And Not StringInStr($recv, "~~users:") And Not StringInStr($recv, "~~accepted") And Not StringInStr($recv, "~~pm:") And Not StringInStr($recv, "~~kick:") And $priv = 0 Then
  GUICtrlSetData($edit, _Now() & @CRLF & $recv & @CRLF & GUICtrlRead($edit))
  WinSetState ( $CCT, "", @SW_ENABLE )
  WinSetState ( $CCT, "", @SW_RESTORE )
  WinSetState ( $CCT, "", @SW_SHOW )
  WinSetOnTop ( $CCT, "", 1)
  WinActivate ( $CCT)
  Sleep(200)
  WinSetOnTop ( $CCT, "", 0)
  _Beeper()
 EndIf
 
 If StringInStr($recv, "~~users:") Then
  $users = StringTrimLeft($recv, 8)
  $users = StringReplace($users, "|", @CRLF)
  GUICtrlSetData($userlist, $users)
 EndIf
 
 
WEnd

Func _Beeper()
 For $i = 720 To 360 Step - 2
  $pi = 3.14159265358979
 ;$x = sin($pi / 4) ;returns 0.707106781186547 which you should recognize as sqrt(2)/2
  
  $degToRad = $pi / 180
  $y = (Sin($i * $degToRad) * 700)
  
  Beep($y, 11+ (5 / 7))
 Next
EndFunc  ;==>_Beeper

Func _MsgLogging(ByRef $fHandle,$sLogVar)
 FileWrite($fHandle, @YEAR & "-" & @MON & "-" & @MDAY & "--" & @HOUR & ":" & @MIN & ":" & @SEC & "  " & $sLogVar & @CRLF)
EndFunc  ;==>_MsgLogging


Func OnAutoItExit()
 $CCT = "Chat - Client shutting down."
 If $iLogFlg = 1 Then 
  _MsgLogging($fHandle, $CCT)
  Sleep(100)
  FileClose($fHandle)
 EndIf 
 GUICtrlSetData($edit, $CCT & @CRLF & GUICtrlRead($edit))
 TCPSend($socket, "~~bye")
 TCPCloseSocket($socket)
 TCPShutdown()
EndFunc  ;==>OnAutoItExit

[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...