- Offizieller Beitrag
Hi!
also ich will ein script schreiben mit dem man per tcp/ip chatten kann! will aber diesmal das das script automatisch erkennt wenn jmd "was von ihm will"(also jetzt chatten^^)
Das Prob:
also ich hab jetzt insgesamt 3 scripts!
das erste:
ist eine liste wie bei icq usw.. das alle anzeigt die du halt geaddet hast.. dann kannst du auf send message gehen und das öffnet dann script 3(s.u.)
#include <GUIConstants.au3>
#include <GuiListView.au3>
Global Const $THRESHOLD = Number(RegRead("HKEY_CURRENT_USER\Control Panel\Mouse", "DoubleClickSpeed"))
Global $TIMER = TimerInit()
$timesini = IniReadSection("list.ini", "USER")
If IsArray($timesini) Then
$timesini = $timesini[0][0]
Else
$timesini = 0
EndIf
Dim $ListViewItem[$timesini + 1],$MainSocket
;~ MsgBox(0,"",$timesini)
$Gui = GUICreate(" ¤¤¤GC¤¤¤", 343, 197, 192, 125)
$ListView = GUICtrlCreateListView("", 8, 8, 250, 150, $LVS_LIST)
For $i = 1 To $timesini
$iniuser = IniRead("list.ini", "USER", $i, "")
If $iniuser = "" Then ContinueLoop
$ListViewItem[$i] = GUICtrlCreateListViewItem($iniuser, $ListView)
Next
$add = GUICtrlCreateButton("&Add", 264, 8, 67, 25)
$del = GUICtrlCreateButton("&Delete", 264, 40, 67, 25)
$send = GUICtrlCreateButton("&Send Message", 8, 168, 250, 25)
$setting = GUICtrlCreateButton("Se&ttings", 264, 72, 67, 25)
$exit = GUICtrlCreateButton("&Exit", 264, 135, 67, 25)
$Progress = GUICtrlCreateProgress(266, 104, 64, 25)
GUICtrlCreateLabel(" ©2006 GtaSpider", 267, 160, 70, 36)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE Or $msg = $exit
ExitLoop
Case $msg = $GUI_EVENT_PRIMARYDOWN
_DoubleClickOnListView($ListView)
Case $msg = $send
_SendMsg(StringReplace(GUICtrlRead(GUICtrlRead($ListView)), "|", ""))
Case $msg = $add
While 1
$IP_Other_PC = InputBox("GtaSpider Chat", @LF & @LF & "IP address or DNS name of PC to chat to:" & @LF & "(Preface DNS name with \)")
If @error Then Exit
If StringLeft($IP_Other_PC, 1) = "" Then
$IP_Other_PC = TCPNameToIP(StringTrimLeft($IP_Other_PC, 1));Convert NAME to IP
If @error Then ContinueLoop
EndIf
ExitLoop
WEnd
$timesini += 1
IniWrite("list.ini", "USER", $timesini, $IP_Other_PC)
_GUICtrlListViewDeleteAllItems ($ListView)
Dim $ListViewItem[$timesini + 1]
For $i = 1 To $timesini
$iniuser = IniRead("list.ini", "USER", $i, "")
If $iniuser = "" Then ContinueLoop
$ListViewItem[$i] = GUICtrlCreateListViewItem($iniuser, $ListView)
Next
Case $msg = $del
If MsgBox(4, "", "Delete this ip from list?") = 7 Then ContinueLoop
$IP_To_DEL = StringReplace(GUICtrlRead(GUICtrlRead($ListView)), "|", "")
For $i = 1 To $timesini
$iniuser = IniRead("list.ini", "USER", $i, "")
If $iniuser = $IP_To_DEL Then
IniDelete("list.ini", "USER", $i)
ExitLoop
EndIf
Next
$i = 0
$ii = 1
$lastii = 0
$timesini = IniReadSection("list.ini", "USER")
If IsArray($timesini) Then
$timesini = $timesini[0][0]
While 1
$i += 1
$iniuser = IniRead("list.ini", "USER", $i, "")
If $iniuser <> "" Then
If $lastii = $ii Then $ii += 1
IniDelete("list.ini", "USER", $i)
IniWrite("list.ini", "USER", $ii, $iniuser)
$lastii = $ii
ContinueLoop
EndIf
$ii += 1
If $ii - 1 = $timesini Then ExitLoop
WEnd
_GUICtrlListViewDeleteAllItems ($ListView)
Dim $ListViewItem[$timesini + 1]
For $i = 1 To $timesini
$iniuser = IniRead("list.ini", "USER", $i, "")
If $iniuser = "" Then ContinueLoop
$ListViewItem[$i] = GUICtrlCreateListViewItem($iniuser, $ListView)
Next
EndIf
EndSelect
WEnd
Exit
Func _SendMsg($IP_Other_PC)
;~ For $i = 1 To 100
;~ GUICtrlSetData($Progress,$i)
;~ Sleep(10)
;~ Next
;~ Run("gc.exe " & $IP_Other_PC)
$MainSocket = TCPConnect(TCPNameToIP($IP_Other_PC), 8000)
If $MainSocket = -1 Then Return MsgBox(0, "Error", "Could Not Connect or Bad Connection")
TCPSend($MainSocket,@IPAddress1)
MsgBox(0,"","")
TCPSend($ConnectedSocket,@IPAddress1)
EndFunc ;==>_SendMsg
Func _DoubleClickOnListView(ByRef $lvctrl)
Dim $MousePos = GUIGetCursorInfo()
If ($MousePos[4] == $lvctrl And GUICtrlRead($lvctrl) > 0 And _GUICtrlListViewGetHotItem ($lvctrl) = _GUICtrlListViewGetCurSel ($lvctrl)) Then
$timerdiff = TimerDiff($TIMER)
If $timerdiff <= $THRESHOLD Then
$ListRead = StringReplace(GUICtrlRead(GUICtrlRead($lvctrl)), "|", "")
_SendMsg($ListRead)
EndIf
$TIMER = TimerInit()
EndIf
EndFunc ;==>_DoubleClickOnListView
Func OnAutoItExit()
TCPCloseSocket($MainSocket)
TCPShutdown()
EndFunc;==>OnAutoItExit
Alles anzeigen
das 2.:
läuft die ganze zeit im hintergrund und checkt ob jmd "anrufen" will!
#cs
$irs = IniReadSection("list.ini","USER")
If @error Then _error("Keine/Falsche List.ini gefunden!")
Global Const $TCP_PORT = 3333
TCPStartup()
For $i = 1 To $irs[0][0]
$ip = $irs[$i][1]
$tcp = TCPListen($ip,$TCP_PORT)
ClipPut($tcp)
If $tcp <> -1 Then ExitLoop
Sleep(1000)
Next
MsgBox(0,$ip,$tcp)
;~ Run("gc.exe "&$ip)
TCPShutdown()
Func _error($text)
MsgBox(16,"Error",$text)
Exit
EndFunc
#ce
Opt("RunErrorsFatal", 0)
Global Const $Port = 8000
Global $MaxConc = 100
Global $MainSocket = TCPStartServer($Port, $MaxConc)
If @error <> 0 Then Exit MsgBox(16, "Error", "Server unable to initialize.")
Global Const $MaxLength = 512
Global $ConnectedSocket[$MaxConc]
Global $CurrentSocket = 0
Local $Track = 0
Global Const $MaxConnection = ($MaxConc - 1)
For $Track = 0 To $MaxConnection Step 1
$ConnectedSocket[$Track] = -1
Next
While 1
$ConnectedSocket[$CurrentSocket] = TCPAccept($MainSocket)
If $ConnectedSocket[$CurrentSocket] <> - 1 Then
$CurrentSocket = SocketSearch()
EndIf
$Track = 0
For $Track = 0 To $MaxConnection Step 1
If $ConnectedSocket[$Track] <> - 1 Then
$Data = TCPRecv($ConnectedSocket[$Track], $MaxLength)
If $Data <> "" Then
_next($Data)
$CurrentSocket = SocketSearch()
EndIf
EndIf
Next
WEnd
Func _next($ip)
MsgBox(0,"","")
RunWait("gc.exe "&$ip)
EndFunc ;==>AutoItExecute
Func SocketSearch()
Local $Track = 0
For $Track = 0 To $MaxConnection Step 1
If $ConnectedSocket[$Track] = -1 Then
Return $Track
Else
; Socket In Use
EndIf
Next
EndFunc ;==>SocketSearch
Func TCPSendMessageAll($ConnectionLimit, $Data)
Local $Track = 0
For $Track = 0 To $ConnectionLimit Step 1
If $ConnectedSocket[$Track] <> - 1 Then TCPSend($ConnectedSocket[$Track], $Data)
Next
EndFunc ;==>TCPSendMessageAll
Func TCPStartServer($Port, $MaxConnect = 1)
Local $Socket
$Socket = TCPStartup()
Select
Case $Socket = 0
SetError(@error)
Return -1
EndSelect
$Socket = TCPListen(@IPAddress1, $Port, $MaxConnect)
Select
Case $Socket = -1
SetError(@error)
Return 0
EndSelect
SetError(0)
Return $Socket
EndFunc ;==>TCPStartServer
Func OnAutoItExit()
TCPCloseSocket($MainSocket)
TCPShutdown()
EndFunc;==>OnAutoItExit
Alles anzeigen
das 3.:
das Main Programm! mit dem du das eigentliche senden/empfangen machst mit einem richtext control und schönen farben
;Single peer-peer TCP example
;Run on one PC and enter the IP or DNS name of PS to chat with...
;Going to create a GUI so include predefined constant variables
#include <GUIConstants.au3>
;Create some constant info
Global Const $TCP_PORT = 3333
$oRP = ObjCreate("RICHTEXT.RichtextCtrl.1")
;Declare our variables
Dim $IP_Other_PC
Dim $over = 0
Dim $nMainSocket = -1
Dim $nSocketRecv = -1
Dim $nSocketSend = -1
Dim $szSendBuffer = ""
Dim $szRecvBuffer = ""
Dim $GUI, $INPUT, $EDIT, $BTN
Dim $n
Dim $bOK_ShowGUI = 0
;cmdline
If $cmdline[0]>0 Then
$IP_Other_PC = $cmdline[1]
$over = 1
EndIf
;Initializes the PC for using TCP sockets
TCPStartup()
;Set Hotkey to quit
HotKeySet("`", "QuitScript")
;Create a listening socket
$nMainSocket = TCPListen($IP_Other_PC, $TCP_PORT)
;Create a User Interface
CreateChatGUI($GUI, $INPUT, $EDIT, $BTN)
;Start the real work
While 1;OUR communication cycle encapsulated in this loop
If $nSocketRecv = -1 Then;Only If no connection
;Initial or broken connection. Ask for an IP to TCP communicate to
While $IP_Other_PC = ""
$IP_Other_PC = InputBox("GtaSpider Chat", @LF & @LF & "IP address or DNS name of PC to chat to:" & @LF & "(Preface DNS name with \)",$IP_Other_PC)
If @error Then Exit
If StringLeft($IP_Other_PC, 1) == "" Then
$IP_Other_PC = TCPNameToIP(StringTrimLeft($IP_Other_PC, 1));Convert NAME to IP
EndIf
WEnd
EndIf
;Wait for an incoming connection
While $nSocketRecv = -1
ToolTip( "waiting for incoming connection...", 0, 0)
$nSocketRecv = TCPAccept($nMainSocket)
If $nSocketSend = -1 Then
$nSocketSend = TCPConnect($IP_Other_PC, $TCP_PORT)
EndIf
If $nSocketSend <> - 1 And $bOK_ShowGUI = 0 Then $bOK_ShowGUI = 1
WEnd
;Attempt an outgoing connecion
If $nSocketSend = -1 Then
ToolTip( "attempting to connect...", 0, 0)
$nSocketSend = TCPConnect($IP_Other_PC, $TCP_PORT)
If $nSocketSend <> - 1 Then $bOK_ShowGUI = 1
Else
If $bOK_ShowGUI = 1 Then
ToolTip("")
GUISetState(@SW_SHOW, $GUI)
$bOK_ShowGUI = 0
EndIf
$szBufferSend = HandleGUIInteraction($GUI, $INPUT, $EDIT, $BTN)
If $szBufferSend <> "" Then
$n = TCPSend($nSocketSend, $szBufferSend)
If @error Then;Connection lost
GUISetState(@SW_HIDE, $GUI)
$nSocketRecv = -1
$nSocketSend = -1
$szBufferSend = ""
Else
$szBufferSend = StringTrimLeft($szBufferSend, $n)
EndIf
EndIf
EndIf
;Attempt to receive data from incoming connection
$szRecvBuffer = TCPRecv($nSocketRecv, 2048)
If @error Then;Connection lost
TCPCloseSocket($nSocketRecv)
$nSocketRecv = -1
$nSocketSend = -1
GUISetState(@SW_HIDE, $GUI)
ElseIf $szRecvBuffer <> "" Then
Update($GUI, $EDIT, $szRecvBuffer)
EndIf
WEnd
Func QuitScript()
TCPShutdown()
Exit
EndFunc ;==>QuitScript
Func CreateChatGUI(ByRef $gui_hwnd, ByRef $input_id, ByRef $edit_id, ByRef $btn_id)
$gui_hwnd = GUICreate( "GtaSpider Chat", 400, 500, -1, -1, BitOR($WS_CAPTION, $WS_SYSMENU))
$input_id = GUICtrlCreateInput("", 10, 10, 380, 20)
$edit_id = GUICtrlCreateObj($oRP, 10, 40, 380, 450)
GUICtrlSetPos(-1, 11, 40, 380, 450)
;~ $edit_id = GUICtrlCreateEdit("", 10, 40, 380, 450)
$btn_id = GUICtrlCreateButton( "hidden", 0, 0, 50, 20, $BS_DEFPUSHBUTTON)
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlSetState($input_id, $GUI_FOCUS)
;~ GUISetState()
EndFunc ;==>CreateChatGUI
Func HandleGUIInteraction(ByRef $gui_hwnd, ByRef $input_id, ByRef $edit_id, ByRef $btn_id)
Local $msg, $szInBuffer, $szEditBuffer
$msg = GUIGetMsg()
If $msg = -3 Then QuitScript()
If $msg = $btn_id Then
$szInBuffer = GUICtrlRead($input_id)
GUICtrlSetState($input_id, $GUI_FOCUS)
If $szInBuffer <> "" Then
$szEditBuffer = GUICtrlRead($edit_id) & $szInBuffer & @CRLF
$oRP.SelText = $szEditBuffer
GUICtrlSetData($input_id, "")
Return $szInBuffer
EndIf
EndIf
Return ""
EndFunc ;==>HandleGUIInteraction
Func Update(ByRef $gui_hwnd, ByRef $edit_id, ByRef $recv_text)
Local $sz
$sz = $recv_text & @CRLF
With $oRP
.SelColor = 0x0000ff
.SelText = $sz
.SelColor = 0x0
EndWith
;~ GUICtrlSetData($edit_id, $sz)
EndFunc ;==>Update
Alles anzeigen
das Prob:
das 1.! undzwar:
$MainSocket = TCPConnect(TCPNameToIP($IP_Other_PC), 8000)
If $MainSocket = -1 Then Return MsgBox(0, "Error", "Could Not Connect or Bad Connection")
TCPSend($MainSocket,@IPAddress1)
MsgBox(0,"","")
TCPSend($ConnectedSocket,@IPAddress1)
hier! er sendet eingentlich so wie er soll! aber nummer 2 auf dem anderen rechener kanns nich empfangen?!
komischer weisse klappt es aber hiermit:
#include <GuiConstants.au3>
#include <GuiEdit.au3>
#include <Misc.au3>
Local $Server = InputBox("Server", "Please input the server you would like to connect to:")
Local $Port = InputBox("Server Port", "Please input the port or the server you would like to connect to:")
TCPStartup()
$MainSocket = TCPConnect(TCPNameToIP($Server), $Port)
MsgBox(0,"",)
If $MainSocket = -1 Then Exit MsgBox(0, "Error", "Could Not Connect or Bad Connection")
GUICreate("Server Client", 390, 210)
$Send = GUICtrlCreateEdit("", 10, 10, 175, 150, $WS_VSCROLL)
Local $History = GUICtrlCreateEdit("Server Messages:", 200, 10, 175, 150, BitOR($WS_VSCROLL, $ES_READONLY))
$SButton = GUICtrlCreateButton("Send", 145, 165, 100, 35)
GUISetState()
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then
Exit
ElseIf $msg = $SButton Or _IsPressed ("0D") = 1 Then
$Text = GUICtrlRead($Send)
$TCPSent = TCPSend($MainSocket, $Text)
GUICtrlSetData($Send, "")
EndIf
$Recv = TCPRecv($MainSocket, 512)
If $Recv <> "" Then
GUICtrlSetData($History, GUICtrlRead($History) & @CRLF & $Recv)
_GUICtrlEditLineScroll ($History, 0, _GUICtrlEditGetLineCount ($History))
EndIf
WEnd
Func OnAutoItExit()
TCPCloseSocket($MainSocket)
TCPShutdown()
EndFunc;==>OnAutoItExit
Alles anzeigen
ich kapiers net?!
will mich autoit möglicherweise ärgern?? ich weiß das haben sich schon viele gefragt, aber diesmal
EDIT : Verd**** Schei** man man man ich hab einfach nur TCPStartup vergessen sry!
von mir aus :CLOSED: