 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Would you use this script? |
| Yes |
|
77% |
[ 17 ] |
| No |
|
9% |
[ 2 ] |
| Frequently |
|
9% |
[ 2 ] |
| Maybe once or Twice |
|
4% |
[ 1 ] |
|
| Total Votes : 22 |
|
| Author |
Message |
jmanx
Joined: 14 May 2008 Posts: 46
|
Posted: Wed Jun 04, 2008 9:17 am Post subject: TCP/IP Server+Client Chat Script (w/ Features) |
|
|
EDIT: Page 4 contains updated script ( 01 / 08 / 08 )
I like to thank Zed Gecko for his TCP/IP chat script that was the foundation for this script.
Feel free to append the current script to your liking, and if you have any suggestions, please post them here.
Features:
Winsock chat communication
Connected and Disconnected messages
User List
Kick users (server only)
IP grabber (server only)
Command mode (type /cmd)
- Ping
- IP2Location (wrote it awhile back, thought I'd throw it in here)
- VisitWeb
Configure Connection Menu
Hit 'Enter' = Quick Send
Hit 'UP' = Show Last Sent (Up to 5)
Hit 'DOWN' = Scroll Down on Last Sent (Clear if on last sent)
Also has a lot of filters on what you can send or not send.
Some Characters are reserved for certain functions, and also stops empty lines and spaces from being submitted.
And a bunch of other stuff!
The /features and /cmd commands will not work if you are connected. Had conflicting problems with the chat and the output of those commands and just decided to enable while not connected. This way you have your screen to view the outputs of these commands when not connected, and the chat when you are connected.
Everything it has works right now.
Right now it's setup for my home server, but just right click on the tray icon, and hit configure BEFORE you connect to change the address.
here are some pictures. (OUT DATED)
Client-
Server-
btw, Kick feature only works when the name is typed out exactly how it's spelled. You might aswell copy from the userlist. Also, when you hit "hide", just right click on the tray icon and hit "Show" to unhide it.
here you go
Client:
| Code: | #singleinstance force
;#notrayicon
ifnotexist, %a_appdata%\Winsock-Chat
{
Filecreatedir, %a_appdata%\Winsock-Chat
}
menu, tray, icon, %A_Windir%\system32\narrator.exe
menu, tray, nostandard
menu, tray, add, Configure
menu, tray, add, Exit
filedelete, %a_appdata%\Winsock-Chat\i2l.txt
filedelete, %a_appdata%\Winsock-Chat\usernamestemp.txt
on=0
checkornot=0
con=0
end=0
las=1
ClientName=%A_Computername%
Network_Address = 69.136.165.222
Network_Port = 1000
ifexist, %A_appdata%\Winsock-chat\clientinfo.ini
{
iniread, Network_address, %A_appdata%\Winsock-chat\clientinfo.ini, Info, ip
iniread, Network_port, %A_appdata%\Winsock-chat\clientinfo.ini, Info, port
}
menu, tray, tip, Currently Set to`nIP: %Network_Address%`nPort: %Network_Port%
colordef=C0C0C0
gui, color, %colordef%
gui:
stringmid, clientname, clientname, 0, 12
Gui, Add, Edit, x6 y5 w260 h140 readonly vchat,
Gui, Add, Edit, x6 y155 w340 h20 vSendText,
Gui, Add, Edit, x6 y185 w130 h20 limit12 vClientName, %ClientName%
Gui, Add, Button, x146 y185 w80 h20 vsendbutton gSendviaNet, Send
Gui, Add, Button, x236 y185 w70 h20 vconnect gConnection_Init, Connect
Gui, Add, Edit, x276 y5 w110 h140 readonly vuserlistin,
Gui, Add, Button, x316 y185 w70 h20 vedit, Edit
guicontrol, disable, edit
Gui, Show, h218 w394, Client
WinGet Gui_ID, ID, Client
guicontrol,,chat, Welcome to your Chat Client!`n`nTo set a different port or IP address in which to connect to you can right click the Icon in your System Tray then click "Configure"`nYou can also type /features to read about all the features your Chat Client has!
return
Configure:
gui, 3:color, C0C0C0
Gui, 3:Add, Edit, x6 y5 w110 h20 vip, %Network_address%
Gui, 3:Add, Text, x119 y8 w60 h20 , IP Address
Gui, 3:Add, Edit, x6 y25 w110 h20 vport, %Network_port%
Gui, 3:Add, Text, x119 y28 w30 h20 , Port
Gui, 3:Add, Button, x26 y55 w110 h20 , Save
Gui, 3:Show, h80 w175, Configure
Return
3buttonsave:
gui, 3:submit, nohide
gui, 3:destroy
Network_Address=%ip%
Network_port=%port%
menu, tray, tip, Currently Set to`nIP: %Network_Address%`nPort: %Network_Port%
iniwrite, %Network_address%, %A_appdata%\Winsock-chat\clientinfo.ini, Info, ip
iniwrite, %Network_port%, %A_appdata%\Winsock-chat\clientinfo.ini, Info, port
return
3GuiClose:
gui, 3:destroy
return
check:
if on=0
{
Settimer,check,off
return
}
if on=1
{
ifnotinstring, userlistin, %Clientname%
{
Settimer,check,off
Msgbox, 16, Client, Secure Link Could not be established. Please Restart Client
exitapp
}
Settimer,check,off
}
$Enter::
ifwinactive, Client
{
goto, SendviaNet
}
else
send, {ENTER}
return
$UP::
ifwinactive, Client,
{
if las=1
{
guicontrol,,sendtext, %lasttype%
ControlSend Edit2, ^{End}, Client
envadd, las, 1
return
}
if las=2
{
guicontrol,,sendtext, %lasttype2%
ControlSend Edit2, ^{End}, Client
envadd, las, 1
return
}
if las=3
{
guicontrol,,sendtext, %lasttype3%
ControlSend Edit2, ^{End}, Client
envadd, las, 1
return
}
if las=4
{
guicontrol,,sendtext, %lasttype4%
ControlSend Edit2, ^{End}, Client
envadd, las, 1
return
}
if las=5
{
guicontrol,,sendtext, %lasttype5%
ControlSend Edit2, ^{End}, Client
return
}
}
else
send, {UP}
return
$DOWN::
ifwinactive, Client,
{
if las=1
{
guicontrol,,sendtext,
return
}
if las=2
{
guicontrol,,sendtext, %lasttype%
ControlSend Edit2, ^{End}, Client
envsub, las, 1
return
}
if las=3
{
guicontrol,,sendtext, %lasttype2%
ControlSend Edit2, ^{End}, Client
envsub, las, 1
return
}
if las=4
{
guicontrol,,sendtext, %lasttype3%
ControlSend Edit2, ^{End}, Client
envsub, las, 1
return
}
if las=5
{
guicontrol,,sendtext, %lasttype4%
ControlSend Edit2, ^{End}, Client
envsub, las, 1
return
}
}
else
send, {DOWN}
return
Connection_Init:
gui, submit, nohide
ifinstring, Clientname, %A_Space%
{
Msgbox, 16, Client, You cannot use spaces in your name!
return
}
ifinstring, Clientname, *
{
Msgbox, 16, Client, You cannot use asteriks in your name!
return
}
ifinstring, Clientname, RX2
{
Msgbox, 16, Client, You cannot use that in your name!
return
}
ifinstring, Clientname, SR1
{
Msgbox, 16, Client, You cannot use that in your name!
return
}
ifinstring, Clientname, :
{
Msgbox, 16, Client, You cannot use colons in your name!
return
}
ifinstring, Clientname, $
{
Msgbox, 16, Client, $ is reserved for ChatServer Prefix.`n %A_Space% %A_Space% %A_Space% %A_Space%%A_Space% %A_Space%You may not use it!
return
}
if Clientname=Console
{
Msgbox, 16, Client,
(
%A_Space%%A_Space%%A_Space%%A_Space%Please choose a nickname to use while chatting in this server.
You are limited to 12 characters in your nickname.
You will be prevented from using certain characters in your nickname.
)
return
}
menu, tray, delete, Configure
guicontrol,,chat,
guicontrol, disable, edit
guicontrol,hide, connect
guicontrol, hide, clientname
guicontrol, move, sendbutton, x6 y185 w300 h20
OnExit, ExitSub
socket := ConnectToAddress(Network_Address, Network_Port)
if socket = -1
ExitApp
Process, Exist
DetectHiddenWindows On
ScriptMainWindowId := WinExist("ahk_class AutoHotkey ahk_pid " . ErrorLevel)
DetectHiddenWindows Off
NotificationMsg = 0x5555 ; An arbitrary message number, but should be greater than 0x1000.
OnMessage(NotificationMsg, "ReceiveData")
menu, tray, tip, Currently connected to`nIP: %Network_Address%`nPort: %Network_Port%
FD_READ = 1 ; Received when data is available to be read.
FD_CLOSE = 32 ; Received when connection has been closed.
if DllCall("Ws2_32\WSAAsyncSelect", "UInt", socket, "UInt", ScriptMainWindowId, "UInt", NotificationMsg, "Int", FD_READ|FD_CLOSE)
{
MsgBox % "WSAAsyncSelect() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
ExitApp
}
return
SendviaNet:
Gui, Submit, NoHide
lasttype5=%lasttype4%
lasttype4=%lasttype3%
lasttype3=%lasttype2%
lasttype2=%lasttype%
lasttype=%sendtext%
stringgetpos, count2, sendtext, /, L
if count2=0
{
if sendtext=/features
{
if con=1
{
tooltip, That command is only available when not connected!, 220, 180
guicontrol,,sendtext,
Settimer, removetooltip, 4000
return
}
if con=0
{
guicontrol,,sendtext,
Guicontrol,,Chat,
(
Chat Client Features List:
Winsock chat communication
Connected and Disconnected messages
User List
Kick users (server only)
IP grabber (server only)
Command mode
- Ping
- IP2Location
- VisitWeb
Configure Connection Menu
Hit 'Enter' = Quick Send
Hit 'UP' = Show Last Sent (Up to 5)
Hit 'DOWN' = Scroll Down on Last Sent (Clear if on last sent)
)
return
}
}
if Sendtext=/cmd
{
if con=1
{
tooltip, Command mode only available when not connected!, 220, 180
guicontrol,,sendtext,
Settimer, removetooltip, 4000
return
}
if con=0
guicontrol,,sendtext,
guicontrol,,chat, Command Mode Enabled!`n`n Available commands are as follows`nPing - /cmd ping (ip/hostname)`nIP2Location - /cmd i2l (ip)`nVisitWeb - /cmd vw (url)`n`nCommand Usage:`nPing Command- Type in the syntax and fill in the "(ip/hostname)" with an IP or hostname.`nIP2Location Command- Type in the syntax and fill in the "(ip)" with an IP you want located. The script will require Internet access to check with the Whois website.`nYou can also leave the "(ip)" blank, and it will display your current location.`nVisitWeb Command- Write out the syntax and fill in the (url) for a URL you wish to go to.
return
}
ifinstring, sendtext, /cmd ping
{
if con=1
{
tooltip, Command mode only available when not connected!, 220, 180
guicontrol,,sendtext,
Settimer, removetooltip, 4000
return
}
if con=0
{
ping=%sendtext%
guicontrol,,sendtext,
guicontrol,,chat, Starting ping now`nPlease wait for results...
stringreplace, ping2, ping, /cmd,
stringreplace, ping3, ping2, ping,
stringreplace, ping4, ping3, %A_space%,
filedelete, %A_appdata%\Winsock-chat\pinger.bat
filedelete, %A_appdata%\Winsock-chat\Pinglog.txt
detecthiddenwindows, on
loop,
{
Process, close, cmd.exe
Process, exist, cmd.exe
if errorlevel=0
break
}
fileappend,
(
cd\
ping -n 3 %ping4% >> "%A_appdata%\Winsock-chat\Pinglog.txt"
), %A_appdata%\Winsock-chat\pinger.bat
run, pinger.bat, %A_appdata%\Winsock-chat\, hide useerrorlevel,
if errorlevel=ERROR
{
guicontrol,,chat, Could not run ping execution file!
return
}
loop,
{
Process, exist, cmd.exe,
if errorlevel=0
break
}
detecthiddenwindows, off
fileread, outping, %A_appdata%\Winsock-chat\Pinglog.txt
guicontrol,, chat, %outping%
ControlSend Edit1, ^{End}, Client
filedelete, %A_appdata%\Winsock-chat\pinger.bat
filedelete, %A_appdata%\Winsock-chat\Pinglog.txt
return
}
}
ifinstring, sendtext, /cmd i2l
{
if con=1
{
tooltip, Command mode only available when not connected!, 220, 180
guicontrol,,sendtext,
Settimer, removetooltip, 4000
return
}
if con=0
{
i2l=%sendtext%
guicontrol,,sendtext,
guicontrol,,chat,Starting IP2Location Function`nPlease wait for results...
stringreplace, i2l2, i2l, /cmd,
stringreplace, i2l3, i2l2, i2l,
stringreplace, i2l4, i2l3, %A_space%,
;stringtrimleft, i2l4, i2l4, 1
filedelete, %a_appdata%\Winsock-Chat\1.txt
stringreplace, ip2, i2l4, -, ., All
ip=%ip2%
urldownloadtofile, http://www.dnsstuff.com/tools/whois.ch?ip=%ip%, %a_appdata%\Winsock-Chat\1.txt
fileread, 1, %a_appdata%\Winsock-Chat\1.txt
StringGetPos, 2, 1, Location:
stringmid, 3, 1, %2%,
stringreplace, 4, 3, ], `n, All
filedelete, %a_appdata%\Winsock-Chat\2.txt
fileappend, %4%, %a_appdata%\Winsock-Chat\2.txt
filereadline, 5, %a_appdata%\Winsock-Chat\2.txt, 2
bl=
stringreplace, 6, 5, Location:, %bl%, All
filedelete, %a_appdata%\Winsock-Chat\2.txt
filedelete, %a_appdata%\Winsock-Chat\1.txt
if 6=<html xmlns="http://www.w3.org/1999/xhtml">
{
guicontrol,,chat, Could not locate IP!
return
}
if ip=
{
ip=%A_Ipaddress1%
}
fileappend, %ip% found at%6%]`n, %a_appdata%\Winsock-Chat\i2l.txt
fileread, i2lout, %a_appdata%\Winsock-Chat\i2l.txt
guicontrol,,chat, %i2lout%
return
}
}
ifinstring, sendtext, /cmd vw
{
if con=1
{
tooltip, Command mode only available when not connected!, 220, 180
guicontrol,,sendtext,
Settimer, removetooltip, 4000
return
}
if con=0
{
vw=%sendtext%
guicontrol,,sendtext,
guicontrol,,chat,Visiting address now...
stringreplace, vw2, vw, /cmd,
stringreplace, vw3, vw2, vw,
stringreplace, vw4, vw3, %A_space%,
stringtrimleft, vw4, vw4, 1
run, %vw4%,, useerrorlevel
if ERRORlevel=ERROR
{
Guicontrol,,chat,Error when visiting address (%vw4%)`nThis is sometimes caused with having Firefox as your default browser`nIf this is the case, ignore this error, and firefox will open normally.
return
}
Guicontrol,,chat,Address Visited!
return
}
}
}
if Sendtext=
{
return
}
if Sendtext=%A_Space%
{
tooltip, You cannot send blank lines!, 220, 180
guicontrol,,sendtext,
Settimer, removetooltip, 4000
return
}
if Sendtext=%A_Space%%A_Space%
{
tooltip, You cannot send blank lines!, 220, 180
guicontrol,,sendtext,
Settimer, removetooltip, 4000
return
}
ifinstring, Sendtext, %A_Space%%A_Space%%A_Space%
{
tooltip, Too many consecutive spaces!, 220, 180
guicontrol,,sendtext,
Settimer, removetooltip, 4000
return
}
ifinstring, SendText, RX2CLIENTCON:
{
tooltip, You cannot send that text!, 220, 180
guicontrol,,sendtext,
Settimer, removetooltip, 4000
return
}
SendText =%ClientName%: %SendText%
guicontrol,,SendText,
send1:
SendData(socket,SendText)
SendText =
return
RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return
ConnectToAddress(IPAddress, Port)
{
VarSetCapacity(wsaData, 32)
result := DllCall("Ws2_32\WSAStartup", "UShort", 0x0002, "UInt", &wsaData)
if ErrorLevel
{
MsgBox WSAStartup() could not be called due to error %ErrorLevel%. Winsock 2.0 or higher is required.
return -1
}
if result
{
MsgBox % "WSAStartup() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
return -1
}
AF_INET = 2
SOCK_STREAM = 1
IPPROTO_TCP = 6
socket := DllCall("Ws2_32\socket", "Int", AF_INET, "Int", SOCK_STREAM, "Int", IPPROTO_TCP)
if socket = -1
{
MsgBox % "socket() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
return -1
}
SizeOfSocketAddress = 16
VarSetCapacity(SocketAddress, SizeOfSocketAddress)
InsertInteger(2, SocketAddress, 0, AF_INET)
InsertInteger(DllCall("Ws2_32\htons", "UShort", Port), SocketAddress, 2, 2)
InsertInteger(DllCall("Ws2_32\inet_addr", "Str", IPAddress), SocketAddress, 4, 4)
if DllCall("Ws2_32\connect", "UInt", socket, "UInt", &SocketAddress, "Int", SizeOfSocketAddress)
{
MsgBox % "connect() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError") . "?"
return -1
}
return socket
}
ReceiveData(wParam, lParam)
{
Critical
global ShowRecieved
socket := wParam
ReceivedDataSize = 4096
Loop
{
VarSetCapacity(ReceivedData, ReceivedDataSize, 0)
ReceivedDataLength := DllCall("Ws2_32\recv", "UInt", socket, "Str", ReceivedData, "Int", ReceivedDataSize, "Int", 0)
if ReceivedDataLength = 0
ExitApp
if ReceivedDataLength = -1
{
WinsockError := DllCall("Ws2_32\WSAGetLastError")
if WinsockError = 10035
return 1
if WinsockError <> 10054
MsgBox % "recv() indicated Winsock error " . WinsockError
ExitApp
}
Loop, parse, ReceivedData, `n, `r
{
gui, submit, nohide
ShowRecieved = %ShowRecieved%%A_LoopField%
settimer, check, 2500
ifnotinstring, Showrecieved, connected
{
ifnotinstring, Showrecieved, :
{
gosub, adddellist
}
if ShowRecieved= RX2CLIENTCON:
{
gosub, connectpend
gosub, turnon
sleep, 250
con=1
return
}
}
fileappend, %ShowRecieved%`n, %a_appdata%\Winsock-Chat\client.txt
fileread, chat1, %a_appdata%\Winsock-Chat\client.txt
guicontrol,,chat, %chat1%
ShowRecieved =
ControlSend Edit1, ^{End}, Client
ifwinnotactive, Client
{
Soundplay, %a_windir%\Media\chimes.wav
}
}
}
return 1
}
SendData(wParam,SendData)
{
socket := wParam
SendDataSize := VarSetCapacity(SendData)
SendDataSize += 1
sendret := DllCall("Ws2_32\send", "UInt", socket, "Str", SendData, "Int", SendDatasize, "Int", 0)
;send( sockConnected,> welcome, strlen(welcome) + 1, NULL);
}
turnon:
on=1
return
adddellist:
ShowRecieved2=%ShowRecieved%
ifinstring, Showrecieved2, RX2KICKPLAYER
{
stringreplace, Showrecieved2, Showrecieved2, RX2KICKPLAYER,-,All
if Showrecieved2=-%clientname%
{
gosub, kickexit
}
Showrecieved=
exit
}
ifinstring, ShowRecieved2, connected!
{
showrecieved2=
return
}
ifinstring, Showrecieved2, SR1CLIENTADDLIST
{
filedelete, %a_appdata%\Winsock-Chat\userlistc.txt
stringreplace, ShowRecieved2, ShowRecieved2, SR1CLIENTADDLIST,,ALL
stringreplace, ShowRecieved2, ShowRecieved2, *,`n, All
fileappend, %ShowRecieved2%, %a_appdata%\Winsock-Chat\userlistc.txt
fileread, userlist, %a_appdata%\Winsock-Chat\userlistc.txt
;stringreplace, userlist2, userlist, *, `n, ALL
guicontrol,,userlistin, %userlist%
userlist2=%userlist%
stringreplace, userlist2, userlist2, %clientname%, %A_Space%
fileappend, %userlist2%, %a_appdata%\Winsock-Chat\usernamestemp.txt
if checkornot=0
{
Loop, read, %a_appdata%\Winsock-Chat\usernamestemp.txt
{
last_line := A_LoopReadLine
if last_line=%clientname%
{
guicontrol,,userlistin,
sleep, 500
nam=1
exitapp
}
}
checkornot=1
}
filedelete, %a_appdata%\Winsock-Chat\usernamestemp.txt
ShowRecieved=
ShowRecieved2=
exit
}
ShowRecieved2=
return
connectpend:
ShowRecieved=
if con=0
{
SendText=%Clientname% connected!
gosub, Send1
con=1
return
}
else
return
InsertInteger(pInteger, ByRef pDest, pOffset = 0, pSize = 4)
{
Loop %pSize%
DllCall("RtlFillMemory", "UInt", &pDest + pOffset + A_Index-1, "UInt", 1, "UChar", pInteger >> 8*(A_Index-1) & 0xFF)
}
ExitSub:
if nam=1
{
sleep, 500
}
open= %Clientname% disconnected!
SendData(socket,open)
sleep, 250
gui, destroy
sleep, 250
DllCall("Ws2_32\WSACleanup")
;sleep, 2000
filedelete,%a_appdata%\Winsock-Chat\userlistc.txt
filedelete, %a_appdata%\Winsock-Chat\client.txt
filedelete, %a_appdata%\Winsock-Chat\i2l.txt
filedelete, %a_appdata%\Winsock-Chat\usernamestemp.txt
if nam=1
{
Msgbox, 16, Client, Client name already in use!
exitapp
}
ExitApp
Kickexit:
gui, destroy
open= %Clientname% was kicked!
SendData(socket,open)
sleep, 500
DllCall("Ws2_32\WSACleanup")
Msgbox, 16, Client, You were kicked from the Server!
exitapp
Guiclose:
filedelete,%a_appdata%\Winsock-Chat\userlistc.txt
filedelete, %a_appdata%\Winsock-Chat\client.txt
filedelete, %a_appdata%\Winsock-Chat\i2l.txt
filedelete, %a_appdata%\Winsock-Chat\usernamestemp.txt
gosub, exitsub
exit:
if con=0
{
exitapp
}
if con=1
{
goto, exitsub
} |
Server:
| Code: | #singleinstance force
;#notrayicon
ifnotexist, %a_appdata%\Winsock-Chat
{
Filecreatedir, %a_appdata%\Winsock-Chat
}
Network_Address = 0.0.0.0
Network_Port = 1000
menu, tray, tip, Listening on`nIP: %A_Ipaddress1%`nPort: %Network_Port%
menu, tray, icon, %a_windir%\explorer.exe
menu, tray, nostandard
menu, tray, add, Restart
menu, tray, add, Show
menu, tray, add, Exit
colordef=C0C0C0
gui, color, %colordef%
Gui, Add, Edit, x6 y5 w360 h190 readonly vchat,
Gui, Add, Edit, x376 y5 w110 h150 readonly vchatlist,
Gui, Add, Edit, x6 y204 w210 h20 vSendText,
Gui, Add, Button, x226 y204 w70 h20 gSendviaNet, Send
Gui, Add, edit, x306 y204 w70 h20 vkicknick,
Gui, Add, Button, x386 y204 w80 h20 vkick gkick_player, Kick
Gui, Add, Button, x376 y165 w110 h30 , Hide
;guicontrol,disable, kicknick
;guicontrol,disable, kick
Gui, Show, x135 y95 h233 w501, Server
WinGet Gui_ID, ID, Server
Gosub Connection_Init
return
buttonhide:
winhide, Server
return
Show:
winshow, Server
controlsend edit1, ^{end}, Server
return
$Enter::
ifwinactive, Server
{
gosub, SendviaNet
}
else
send, {ENTER}
return
Connection_Init:
OnExit, ExitSub
socket := PrepareForIncomingConnection(Network_Address, Network_Port)
if socket = -1
ExitApp
Process, Exist
DetectHiddenWindows On
ScriptMainWindowId := WinExist("ahk_class AutoHotkey ahk_pid " . ErrorLevel)
DetectHiddenWindows Off
NotificationMsg = 0x5555
OnMessage(NotificationMsg, "ReceiveData")
FD_READ = 1
FD_CLOSE = 32
FD_CONNECT = 20
if DllCall("Ws2_32\WSAAsyncSelect", "UInt", socket, "UInt", ScriptMainWindowId, "UInt", NotificationMsg, "Int", FD_READ|FD_CONNECT)
{
MsgBox % "WSAAsyncSelect() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
ExitApp
}
i=1
Loop
{
VarSetCapacity(SocketAddress, SizeOfSocketAddress:=16)
conectioncheck%i% := DllCall("Ws2_32\accept", "UInt", socket, "UInt", &SocketAddress, "Int*", SizeOfSocketAddress)
if conectioncheck%i% != -1
{
i++
peername := DllCall("Ws2_32\inet_ntoa", "uint", NumGet(SocketAddress,4), "str")
. ":" NumGet(SocketAddress,2,"ushort")
fileappend, %peername% connecting...`n, %a_appdata%\Winsock-Chat\server.txt
fileread, chat2, %a_appdata%\Winsock-Chat\server.txt
guicontrol,,chat, %chat2%
controlsend edit1, ^{end}, Server
Sendtext= RX2CLIENTCON:
gosub, Send1
Sendtext=
}
sleep 500
}
return
SendviaNet:
Gui, Submit, NoHide
SendText =$ChatServer: %SendText%
guicontrol,,SendText,
go:
fileappend, %SendText%`n, %a_appdata%\Winsock-Chat\server.txt
fileread, chat2, %a_appdata%\Winsock-Chat\server.txt
guicontrol,,chat, %chat2%
controlsend edit1, ^{end}, Server
gosub, send1
resend:
SendText= %ShowRecieved%
ShowRecieved=
send1:
Loop %i% {
SendData(conectioncheck%A_Index%,SendText)
}
SendText =
return
PrepareForIncomingConnection(IPAddress, Port)
{
VarSetCapacity(wsaData, 32)
result := DllCall("Ws2_32\WSAStartup", "UShort", 0x0002, "UInt", &wsaData) ; Request Winsock 2.0 (0x0002)
if ErrorLevel
{
MsgBox WSAStartup() could not be called due to error %ErrorLevel%. Winsock 2.0 or higher is required.
return -1
}
if result
{
MsgBox % "WSAStartup() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
return -1
}
AF_INET = 2
SOCK_STREAM = 1
IPPROTO_TCP = 6
socket := DllCall("Ws2_32\socket", "Int", AF_INET, "Int", SOCK_STREAM, "Int", IPPROTO_TCP)
if socket = -1
{
MsgBox % "socket() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
return -1
}
SizeOfSocketAddress = 16
VarSetCapacity(SocketAddress, SizeOfSocketAddress)
InsertInteger(2, SocketAddress, 0, AF_INET) ; sin_family
InsertInteger(DllCall("Ws2_32\htons", "UShort", Port), SocketAddress, 2, 2) ; sin_port
InsertInteger(DllCall("Ws2_32\inet_addr", "Str", IPAddress), SocketAddress, 4, 4) ; sin_addr.s_addr
if DllCall("Ws2_32\bind", "UInt", socket, "UInt", &SocketAddress, "Int", SizeOfSocketAddress)
{
MsgBox % "bind() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError") . "?"
return -1
}
if DllCall("Ws2_32\listen", "UInt", socket, "UInt", "SOMAXCONN")
{
MsgBox % "LISTEN() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError") . "?"
return -1
}
return socket
}
ReceiveData(wParam, lParam)
{
Critical
global ShowRecieved
socket := wParam
ReceivedDataSize = 4096
Loop
{
VarSetCapacity(ReceivedData, ReceivedDataSize, 0)
ReceivedDataLength := DllCall("Ws2_32\recv", "UInt", socket, "Str", ReceivedData, "Int", ReceivedDataSize, "Int", 0)
if ReceivedDataLength = -1
{
WinsockError := DllCall("Ws2_32\WSAGetLastError")
if WinsockError = 10035
return 1
if WinsockError <> 10054
MsgBox % "recv() indicated Winsock error " . WinsockError
ExitApp
}
Loop, parse, ReceivedData, `n, `r
{
ShowRecieved = %ShowRecieved%%A_LoopField%
ifnotinstring, Showrecieved, :
{
gosub, redirects
}
fileappend, %ShowRecieved%`n, %a_appdata%\Winsock-Chat\server.txt
fileread, chat2, %a_appdata%\Winsock-Chat\server.txt
guicontrol,,chat, %chat2%
controlsend edit1, ^{end}, Server
gosub, resend
;ShowRecieved =
}
}
return 1
}
SendData(wParam,SendData)
{
socket := wParam
;fileappend, %socket%`n, %a_appdata%\Winsock-Chat\testing.txt
SendDataSize := VarSetCapacity(SendData)
SendDataSize += 1
sendret := DllCall("Ws2_32\send", "UInt", socket, "Str", SendData, "Int", SendDatasize, "Int", 0)
;send( sockConnected,> welcome, strlen(welcome) + 1, NULL);
}
redirects:
ifinstring, Showrecieved, kicked!
{
return
}
ShowRecieved2=%ShowRecieved%
Stringreplace, Showrecieved2, Showrecieved2, %A_Space%, `n,
filedelete, %a_appdata%\Winsock-Chat\usertemp.txt
fileappend, %ShowRecieved2%, %a_appdata%\Winsock-Chat\usertemp.txt
filereadline, name1, %a_appdata%\Winsock-Chat\usertemp.txt,1
filereadline, cord, %a_appdata%\Winsock-Chat\usertemp.txt,2
filedelete, %a_appdata%\Winsock-Chat\usertemp.txt
if cord=connected!
{
fileappend, %name1%`n, %a_appdata%\Winsock-Chat\userlist.txt
fileread, userlist, %a_appdata%\Winsock-Chat\userlist.txt
guicontrol,,chatlist, %userlist%
stringreplace,userlist,userlist,`n,*,All
sleep, 500
Sendtext=SR1CLIENTADDLIST%userlist%
gosub, send1
name1=
cord=
return
}
if cord=disconnected!
{
fileread, dellist, %a_appdata%\Winsock-Chat\userlist.txt
stringreplace, dellist2, dellist, %name1%`r`n
filedelete, %a_appdata%\Winsock-Chat\userlist.txt
fileappend, %dellist2%, %a_appdata%\Winsock-Chat\userlist.txt
fileread, userlist, %a_appdata%\Winsock-Chat\userlist.txt
guicontrol,,chatlist, %userlist%
stringreplace,userlist,userlist,`n,*,All
Sendtext=SR1CLIENTADDLIST%userlist%
gosub, send1
name1=
cord=
return
}
InsertInteger(pInteger, ByRef pDest, pOffset = 0, pSize = 4)
{
Loop %pSize%
DllCall("RtlFillMemory", "UInt", &pDest + pOffset + A_Index-1, "UInt", 1, "UChar", pInteger >> 8*(A_Index-1) & 0xFF)
}
kick_player:
gui, submit, nohide
guicontrol,,kicknick,
ref=
Sendtext=RX2KICKPLAYER%kicknick%
gosub, send1
sleep, 500
fileread, dellist, %a_appdata%\Winsock-Chat\userlist.txt
stringreplace, dellist2, dellist, %kicknick%`r`n
filedelete, %a_appdata%\Winsock-Chat\userlist.txt
fileappend, %dellist2%, %a_appdata%\Winsock-Chat\userlist.txt
fileread, userlist, %a_appdata%\Winsock-Chat\userlist.txt
guicontrol,,chatlist, %userlist%
stringreplace,userlist,userlist,`n,*,All
Sendtext=SR1CLIENTADDLIST%userlist%
gosub, send1
sendtext=
name1=
kicknick=
cord=
return
restart:
filedelete, %a_appdata%\Winsock-Chat\server.txt
filedelete,%a_appdata%\Winsock-Chat\userlist.txt
DllCall("Ws2_32\WSACleanup")
reload
Exit:
exitapp
ExitSub:
gui, submit, nohide
if chatlist=
{
goto, end
}
Msgbox, 48, Server, Server will shut down 5 second(s) after you hit ok!
gui, destroy
Sendtext= Server is Shutting down in 5 Second(s)
gosub, send1
sleep, 5000
end:
filedelete, %a_appdata%\Winsock-Chat\server.txt
filedelete,%a_appdata%\Winsock-Chat\userlist.txt
DllCall("Ws2_32\WSACleanup")
ExitApp
guiclose:
filedelete,%a_appdata%\Winsock-Chat\userlist.txt
filedelete, %a_appdata%\Winsock-Chat\server.txt
exitapp |
thanks AHK community for the help
Last edited by jmanx on Sat Aug 02, 2008 7:24 am; edited 18 times in total |
|
| Back to top |
|
 |
imapow
Joined: 13 Mar 2008 Posts: 162 Location: Trøndelag, Norway
|
Posted: Wed Jun 04, 2008 10:28 am Post subject: |
|
|
COOOOL
nice script. you realy got something here. _________________ -._.-¨¯¨-._.-IM@PΩW-._.-¨¯¨-._.- |
|
| Back to top |
|
 |
imapow
Joined: 13 Mar 2008 Posts: 162 Location: Trøndelag, Norway
|
Posted: Wed Jun 04, 2008 6:05 pm Post subject: |
|
|
i got errror nr 10060. wot is this.
can you post a error list? _________________ -._.-¨¯¨-._.-IM@PΩW-._.-¨¯¨-._.- |
|
| Back to top |
|
 |
jmanx
Joined: 14 May 2008 Posts: 46
|
Posted: Wed Jun 04, 2008 6:18 pm Post subject: |
|
|
| server or client, and what were u doing? |
|
| Back to top |
|
 |
imapow
Joined: 13 Mar 2008 Posts: 162 Location: Trøndelag, Norway
|
Posted: Wed Jun 04, 2008 6:29 pm Post subject: |
|
|
client, trying to conect. _________________ -._.-¨¯¨-._.-IM@PΩW-._.-¨¯¨-._.- |
|
| Back to top |
|
 |
jmanx
Joined: 14 May 2008 Posts: 46
|
Posted: Wed Jun 04, 2008 6:34 pm Post subject: |
|
|
Oh I know now.
Problems connecting to server.
Caused by:
Server not on
Server not listening on port client is connecting to
Firewall/router settings are not allowing the Server to listen on that port/Client to connect on that port
Basically, server either isn't on or just isn't allowed by firewall to listen.
I can turn on mine if you like? |
|
| Back to top |
|
 |
imapow
Joined: 13 Mar 2008 Posts: 162 Location: Trøndelag, Norway
|
Posted: Wed Jun 04, 2008 6:35 pm Post subject: |
|
|
shure _________________ -._.-¨¯¨-._.-IM@PΩW-._.-¨¯¨-._.- |
|
| Back to top |
|
 |
jmanx
Joined: 14 May 2008 Posts: 46
|
Posted: Wed Jun 04, 2008 6:35 pm Post subject: |
|
|
| it's on, IP is in the client source ^ |
|
| Back to top |
|
 |
SoggyDog
Joined: 02 May 2006 Posts: 225 Location: Greeley, CO
|
Posted: Wed Jun 04, 2008 7:16 pm Post subject: |
|
|
Just finished doing some testing with ''the gang'' and love this!
Great job  _________________
SoggyDog
Download AutoHotKey Wallpaper
Does 'Fuzzy Logic' tickle? |
|
| Back to top |
|
 |
jmanx
Joined: 14 May 2008 Posts: 46
|
Posted: Thu Jun 05, 2008 11:23 am Post subject: |
|
|
| thanks for positive reviews |
|
| Back to top |
|
 |
adamrgolf
Joined: 28 Dec 2006 Posts: 386
|
Posted: Thu Jun 05, 2008 11:32 am Post subject: |
|
|
| This is very cool, nice work. |
|
| Back to top |
|
 |
imapow
Joined: 13 Mar 2008 Posts: 162 Location: Trøndelag, Norway
|
Posted: Fri Jun 06, 2008 11:01 am Post subject: |
|
|
wye use temp files on the desktop insted of just vars? _________________ -._.-¨¯¨-._.-IM@PΩW-._.-¨¯¨-._.- |
|
| Back to top |
|
 |
jmanx
Joined: 14 May 2008 Posts: 46
|
Posted: Fri Jun 06, 2008 1:02 pm Post subject: |
|
|
| easier to keep track of everything, plus I had some problems deleting users off the userlist and keeping blank lines out. Feel free to use variables if you want or change the directory of the temp files location |
|
| Back to top |
|
 |
Guest
|
Posted: Sat Jun 07, 2008 3:07 pm Post subject: |
|
|
| what theme is that?? |
|
| Back to top |
|
 |
Guest
|
Posted: Sat Jun 07, 2008 3:13 pm Post subject: |
|
|
and btw there should be a better way of receiving commands only from the server, someone could easily modify your client script and erase the sending limitations.
Man, that theme is so sick what is it |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|