Hallo alle zusammen, ich habe mich seid einiger Zeit mit dem Thema TCP Chat usw.. beschäftigt und dazu auch hier im Forum einige Scripte gefunden, zum teil auch eine "OnlineUserlist" , dies wollte ich nun auch in mein Chat mit einbauen habe da aber so einige Schwierigkeiten..
vielleicht kann mir ja jemand hier weiter helfen..
MFG Marvin
Client
Spoiler anzeigen
#NoTrayIcon
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <AutoItObject.au3>
#include <Misc.au3>
#include <functions.au3>
#include <EditConstants.au3>
#include <Date.au3>
;#Chat Login Form
[/autoit] [autoit][/autoit] [autoit]_AutoItObject_Startup()
TCPStartup()
global $port=7500
global $kicolor="0xFF0000"
Global $nickname=IniRead("config\clienttemp.ini","opt","nickname","Gast")
Global $serverip=IniRead("config\clienttemp.ini","opt","serverip","")
global $owncolor=iniread("config\clientcfg.ini","opt","owncolor","0xFF0000")
global $othcolor=iniread("config\clientcfg.ini","opt","othcolor","0x0000FF")
global $chatbg=iniread("config\clientcfg.ini","opt","chatbg","0xC6E2FF")
global $imgp=iniread("config\clientcfg.ini","opt","imgp","")
global $mypw="PWbTSAE"
global $icon=($imgp & "\icon\")
if $serverip="" Then
$input=InputBox("Server-IP","Server-IP oder Name des Servers eingeben:",@ComputerName)
if _stringgetnum($input,".")=4 then
$serverip=$input
Else
$serverip=TCPNameToIP($input)
EndIf
EndIf
;#Bild Source wählen bzw setzen
if $imgp="" then
$imgp=@ScriptDir&"\png"
EndIf
while DirGetSize($imgp)<=0
$imgp=FileSelectFolder("Wähle den Ordner der Bilddateien aus (Eingabe exit->Ende):","",6,$imgp)
if StringLower($imgp)="exit" Then
TCPShutdown()
_AutoItObject_Shutdown()
Exit
EndIf
WEnd
;#Verbindung zum Server
global $sock=0
$sock=TCPConnect($serverip,$port)
if $sock=-1 then
err("Es konnte keine Verbindung zum Server hergestellt werden.")
$sock=0
Exit
EndIf
TCPSend2($sock,"conn:"&$nickname)
;#Chatbox
[/autoit] [autoit][/autoit] [autoit]global $title="Chatroom ASV Frankfurt"
$x=iniread("MCC.ini","win","x",192)
$y=iniread("MCC.ini","win","y",124)
$Form1 = GUICreate($title, 600, 433, $x, $y, $GUI_SS_DEFAULT_GUI)
global $Chat = _Chatbox_Create($Form1, 15, 10, 393, 270, $chatbg, "", $imgp)
$Edit1 = GUICtrlCreateEdit("", 16, 296, 393, 97)
$onlineuser_liste = GUICtrlCreateEdit("", 420, 10, 170, 270,$ES_READONLY)
$Button1 = GUICtrlCreateButton("Smileys", 16, 400, 85, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Senden", 205, 400, 81, 25, $WS_GROUP)
$Button3 = GUICtrlCreateButton("Optionen",110,400,85,25,$WS_GROUP)
;$smiley_ = GUICtrlCreateButton("", 420, 298, 27, 25, $BS_ICON)
;GUICtrlSetImage(-1, $imgp & "\icon\" & "cool.ico", "", 0)
GUISetState(@SW_SHOW, $Form1)
[/autoit] [autoit][/autoit] [autoit];#Chat Optionen
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]$Form2 = GUICreate("Einstellungen", 220, 155, 400, 245, $GUI_SS_DEFAULT_GUI, default, $Form1)
$b1 = GUICtrlCreateButton("Eigene Farbe", 16, 16, 185, 25)
GUICtrlSetTip($b1,"Wird erst nach Programmneustart angezeigt")
$b2 = GUICtrlCreateButton("Farbe der übrigen User", 16, 48, 185, 25)
GUICtrlSetTip($b2,"Wird erst nach Programmneustart angezeigt")
$b3 = GUICtrlCreateButton("Hintergrund Farbe", 16, 80, 185, 25)
GUICtrlSetTip($b3,"Wird erst nach Programmneustart angezeigt")
$b4 = GUICtrlCreateButton("Schließen", 16, 112, 185, 25)
GUISetState(@SW_HIDE, $Form2)
GUICtrlSetState($Edit1, $GUI_FOCUS)
#EndRegion ### END Koda GUI section ###
while 1
$enMsg = GUIGetMsg(1)
$nMsg=$enMsg[0]
Switch $enMsg[1]
case $Form1
switch $nMsg
Case $GUI_EVENT_CLOSE
ende()
case $Button1
_Chatbox_SmileyToText($Edit1, $imgp&"\", -1, -1, $Form1)
GUICtrlSetState($Edit1, $GUI_FOCUS)
$t=GUICtrlRead($Edit1)
GUICtrlSetData($Edit1,$t)
Case $Button2
$tmp=GUICtrlRead($Edit1)
$tmp=stringreplace($tmp," ","")
$tmp=stringreplace($tmp,@crlf,"")
if $tmp<>"" Then
;~ _Chatbox_SetData($Chat, "[" & _NowTime() & "] "&$nickname&": " &@crlf& GUICtrlRead($Edit1), $owncolor)
TCPSend2($sock,"chat:"&$nickname&": " &@crlf&GUICtrlRead($Edit1))
GUICtrlSetData($Edit1,"")
GUICtrlSetState($Edit1, $GUI_FOCUS)
endif
Case $Button3
GUISetState(@SW_SHOW,$Form2)
WinActivate("Einstellungen")
GUISetState(@SW_DISABLE,$Form1)
EndSwitch
case $Form2
switch $nMsg
Case $GUI_EVENT_CLOSE
GUISetState(@SW_ENABLE,$Form1)
guisetstate(@SW_HIDE,$Form2)
Case $b1
$owncolor = _ChooseColor(2,$owncolor,2)
Case $b2
$othcolor = _ChooseColor(2,$othcolor,2)
Case $b3
$chatbg = _ChooseColor(2,$chatbg,2)
Case $b4
$msg1 = MsgBox(4,"Speichern & Chat schließen?","Der Chat muss neugestartet werden " & @CRLF & "um die Einstellungen zu übernehmen" & @CRLF & "Chat jetzt schließen?")
If $msg1 = 6 Then
ende()
Else
GUISetState(@SW_ENABLE,$Form1)
guisetstate(@SW_HIDE,$Form2)
EndIf
EndSwitch
EndSwitch
if winactive($title)<>0 Then
if _IsPressed("1B") then ende()
if _IsPressed("0D") Then
if not _IsPressed("10") then
$tmp=GUICtrlRead($Edit1)
$tmp=stringreplace($tmp," ","")
$tmp=stringreplace($tmp,@crlf,"")
;#####################################################################
if $tmp="getip:" then
TCPSend2($sock,"getip:"&$nickname)
ContinueLoop
EndIf
;#####################################################################
if $tmp<>"" Then
;~ _Chatbox_SetData($Chat, "[" & _NowTime() & "] "&$nickname&": " &@crlf& GUICtrlRead($Edit1), $owncolor)
TCPSend2($sock,"chat:"&$nickname&": " &@crlf&GUICtrlRead($Edit1))
GUICtrlSetData($Edit1,"")
GUICtrlSetState($Edit1, $GUI_FOCUS)
endif
EndIf
EndIf
EndIf
if $sock<>0 Then
$txt=code(TCPRecv($sock,1024),$mypw)
if $txt<>"" then
dobefs($txt)
EndIf
EndIf
;~ sleep(50)
WEnd
;#############################
; FUNCTIONS
;#############################
func newmsg($txt="",$color="0x00FF00")
_Chatbox_SetData($Chat, "[" & _NowTime() & "] " & $txt, $color)
EndFunc
func dobefs($tmp)
$bef=stringlower(li($tmp))
switch $bef
Case "kick"
newmsg("Du wurdest gekickt: "&re($tmp),$kicolor)
TCPCloseSocket($sock)
$sock=0
Exit
case "close"
TCPCloseSocket($sock)
$sock=0
case "chat"
newmsg(re($tmp),$othcolor)
EndSwitch
EndFunc
func li($txt)
if StringInStr($txt,":",0,1)<1 then return ""
$ntxt=stringmid($txt,1,stringinstr($txt,":",0,1)-1)
return $ntxt
EndFunc
func re($txt)
if StringInStr($txt,":",0,1)<1 then return ""
$ntxt=stringmid($txt,stringinstr($txt,":",0,1)+1)
return $ntxt
EndFunc
func ende()
;saves and closes
TCPSend2($sock,"left:"&$nickname)
IniWrite("config\clientcfg.ini","opt","imgp",$imgp)
iniwrite("config\clientcfg.ini","opt","chatbg",$chatbg)
iniwrite("config\clientcfg.ini","opt","owncolor",$owncolor)
iniwrite("config\clientcfg.ini","opt","othcolor",$othcolor)
$wp=WinGetPos($title)
IniWrite("config\clientcfg.ini","win","x",$wp[0])
IniWrite("config\clientcfg.ini","win","y",$wp[1])
iniwrite("config\clientcfg.ini","opt","nick",$nickname)
iniwrite("config\clientcfg.ini","opt","serip",$serverip)
TCPCloseSocket($sock)
TCPShutdown()
_AutoItObject_Shutdown()
GUIDelete($Form1)
GUIDelete($Form2)
Exit
EndFunc
Func err($txt="",$tit="")
if $tit="" then $tit="Client-"
msgbox(16,$tit&"Error",$txt)
EndFunc
Func SocketToIP($SHOCKET)
Local $sockaddr, $aRet
$sockaddr = DllStructCreate("short;ushort;uint;char[8]")
[/autoit] [autoit][/autoit] [autoit]$aRet = DllCall("Ws2_32.dll", "int", "getpeername", "int", $SHOCKET, _
"ptr", DllStructGetPtr($sockaddr), "int*", DllStructGetSize($sockaddr))
If Not @error And $aRet[0] = 0 Then
$aRet = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($sockaddr, 3))
If Not @error Then $aRet = $aRet[0]
Else
$aRet = 0
EndIf
$sockaddr = 0
[/autoit] [autoit][/autoit] [autoit]Return $aRet
EndFunc ;==>SocketToIP
Func code($txt, $passwort)
$neustring=""
$x=stringlen($passwort)
For $i = 1 To stringLen($txt)
if $i>$x then
$ii=$x
Else
$ii=$i
endif
$xxx=stringMid($passwort,$ii,1)
$encode_letter = Chr(BitXOR(Asc(stringMid($txt,$i,1)) , (Mod($i , stringLen($passwort) + 1 + Asc($xxx)))))
$neustring = $neustring & $encode_letter
Next
Return $neustring
EndFunc
func TCPSend2($socke,$text)
return TCPSend($socke,code($text,$mypw))
EndFunc
Server
Spoiler anzeigen
#include <AutoItObject.au3>
#include <Misc.au3>
#include <functions.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Date.au3>
;~ Opt("TCPTimeout",1000)
global $ips=@IPAddress1
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit];#####################################################################################################
[/autoit] [autoit][/autoit] [autoit];#####################################################################################################
[/autoit] [autoit][/autoit] [autoit]_AutoItObject_Startup()
TCPStartup()
$maxpend=10 ;maximale verbindungen
global $port=7500 ;Serverport
global $mypw="PWbTSAE"
dim $verb[$maxpend+1] ;verbindungen
$verb[0]=$maxpend ;anzahl verbs-max
global $verbs=0 ;anzahl verbundener
global $listen=TCPListen(@IPAddress1,$port,$maxpend) ;listener IP_1
Global $userliste = ""
Global $User[$maxpend]
Global $Userarraysize = UBound($User) - 1
Global $Username[$maxpend]
Global $Usernamearraysize = UBound($Username) - 1
if $listen<0 then err("Kann keine Verbindung aufbauen")
for $x=1 to $maxpend
$verb[$x]=makeobj()
Next
AdlibRegister("sendeuserliste",5000)
while 1
;Win
$enMsg = GUIGetMsg(1)
;acc,rec,send(î)
$new=TCPAccept($listen)
if $new<>-1 Then
$fi=getff() ;GET First Free obj
if $fi<=$verb[0] and $fi>0 Then
$verb[$fi].saved($new)
Else
TCPSend($new,"chat:Server ist voll")
TCPSend($new,"close:")
TCPCloseSocket($new)
EndIf
EndIf
for $x=1 to $verb[0]
if $verb[$x].sock<>0 Then
$txt=$verb[$x].rec()
if $txt<>"" then
getbefs($txt,$x)
EndIf
EndIf
Next
;~ sleep(50)
WEnd
func getbefs($tmp,$memb=0)
$bef=stringlower(li($tmp))
switch $bef
case "chat"
sendall("chat:"&re($tmp))
case "conn"
$verb[$memb].nick=re($tmp)
sendall("chat:"&re($tmp)&" ist dem Chat beigetreten")
case "left"
$name=stringlower(re($tmp))
for $x=1 to $verb[0]
if stringlower($verb[$x].nick)=$name then
sendall("chat:"&$verb[$x].nick&" hat den Chat verlassen")
$verb[$x].close()
exitloop
endif
Next
case "setna"
$tmp=re($tmp)
$name=stringlower(li($tmp))
for $x=1 to $verb[0]
if stringlower($verb[$x].nick)=$name then
$verb[$x].nick=re($tmp)
exitloop
endif
Next
sendall("chat:"&li($tmp)&" heißt nun "&re($tmp)&"")
EndSwitch
EndFunc
func li($txt)
if StringInStr($txt,":",0,1)=0 then return "0"
$ntxt=stringmid($txt,1,stringinstr($txt,":",0,1)-1)
return $ntxt
EndFunc
func re($txt)
if StringInStr($txt,":",0,1)=0 then return "0"
$ntxt=stringmid($txt,stringinstr($txt,":",0,1)+1)
return $ntxt
EndFunc
func sendall($txt)
for $x=1 to $verb[0]
if $verb[$x].sock<>0 Then
$verb[$x].send($txt)
EndIf
Next
EndFunc
func ende()
;saves and closes
for $x=1 to $verb[0]
if $verb[$x].sock<>0 Then
$verb[$x].send("chat:Server wurde geschlossen")
$verb[$x].close()
EndIf
Next
if $verbs>0 then err("Es konnten nicht alle Verbindungen geschlossen werden")
TCPCloseSocket($listen)
TCPShutdown()
_AutoItObject_Shutdown()
Exit
EndFunc
Func makeobj()
local $obj=_AutoItObject_Create()
_AutoItObject_AddMethod($obj,"rec","tcp_rec")
_AutoItObject_AddMethod($obj,"send","tcp_send")
_AutoItObject_AddMethod($obj,"close","tcp_close")
_AutoItObject_AddMethod($obj,"saved","tcp_sd")
_AutoItObject_AddProperty($obj,"sock")
_AutoItObject_AddProperty($obj,"ip")
_AutoItObject_AddProperty($obj,"nick")
return $obj
EndFunc
Func tcp_close($obj)
TCPCloseSocket($obj.sock)
$obj.sock=0
$verbs=$verbs-1
if $verbs<0 then $verbs=0
$obj.nick=""
$obj.ip=""
EndFunc
func tcp_send($obj,$txt="")
if $obj.sock=0 then return 0
$err=TCPSend($obj.sock,code($txt,$mypw))
if @error or $err=-1 then
err("Nachricht kann nicht gesendet werden")
return -1
endif
return 1
EndFunc
func tcp_rec($obj,$len=1024)
if $obj.sock=0 then return ""
$txt=code(TCPRecv($obj.sock,$len),$mypw)
if @error then
err("Fehler beim empfangen der Nachricht")
return "-1"
EndIf
return $txt
EndFunc
func tcp_sd($obj,$socket,$nick="")
$obj.sock=$socket
$obj.ip=SocketToIP($obj.sock)
$obj.nick=$nick
$verbs=$verbs+1
EndFunc
Func err($txt="",$tit="")
if $tit="" then $tit="Server-"
msgbox(16,$tit&"Error",$txt)
EndFunc
func getff()
for $x=1 to $verb[0]
if $verb[$x].sock=0 then return $x
Next
EndFunc
Func SocketToIP($SHOCKET)
Local $sockaddr, $aRet
$sockaddr = DllStructCreate("short;ushort;uint;char[8]")
[/autoit] [autoit][/autoit] [autoit]$aRet = DllCall("Ws2_32.dll", "int", "getpeername", "int", $SHOCKET, _
"ptr", DllStructGetPtr($sockaddr), "int*", DllStructGetSize($sockaddr))
If Not @error And $aRet[0] = 0 Then
$aRet = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($sockaddr, 3))
If Not @error Then $aRet = $aRet[0]
Else
$aRet = 0
EndIf
$sockaddr = 0
[/autoit] [autoit][/autoit] [autoit]Return $aRet
EndFunc ;==>SocketToIP
Func code($txt, $passwort)
$neustring=""
local $x=stringlen($passwort)
For $i = 1 To stringLen($txt)
if $i>$x then
$ii=$x
Else
$ii=$i
endif
$xxx=stringMid($passwort,$ii,1)
$encode_letter = Chr(BitXOR(Asc(stringMid($txt,$i,1)) , (Mod($i , stringLen($passwort) + 1 + Asc($xxx)))))
$neustring = $neustring & $encode_letter
Next
Return $neustring
EndFunc
func sendeuserliste()
$userliste = ""
For $iZ = 0 to $Userarraysize
If $user[$iZ] <> -1 then $userliste &= $username[$iZ] & ""
Next
For $iY = 0 To $Userarraysize
If $User[$iY] <> -1 Then TCPSend($User[$iY], "liste " & $userliste)
Next
EndFunc
Danke..