 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Would you use this script? |
| Yes |
|
73% |
[ 17 ] |
| No |
|
8% |
[ 2 ] |
| Frequently |
|
13% |
[ 3 ] |
| Maybe once or Twice |
|
4% |
[ 1 ] |
|
| Total Votes : 23 |
|
| Author |
Message |
WankaUSR
Joined: 14 Aug 2007 Posts: 33
|
Posted: Wed Jul 30, 2008 1:50 pm Post subject: |
|
|
| I'm currently working with jmanx on a new version of this script and if you have any suggestions or features request please tell jmanx or if you would like to help |
|
| Back to top |
|
 |
jmanx
Joined: 14 May 2008 Posts: 48
|
Posted: Fri Aug 01, 2008 1:05 am Post subject: |
|
|
Server and Client update
Some features that I can list off the top of my head are:
Fixed Server bug were Showing the hidden server window would reveal a window in TeamSpeak 2 instead
Number Pad Enter is now working as a submit hotkey
Logout button added (wankaUSR)
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 = 0.0.0.0
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 gdiscon, Log Out
guicontrol, disable, edit
Gui, Show, h218 w394, WinSock Chat Client
WinGet Gui_ID, ID, WinSock Chat 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:
if on=1
{
Msgbox, 16, WinSock Chat Client, Cannot configure when connected!
return
}
else
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, WinSock Chat Client, Secure Link Could not be established. Please Restart Client
exitapp
}
guicontrol, enable, edit
Settimer,check,off
}
$numpadenter::
ifwinactive, WinSock Chat Client
{
goto, SendviaNet
}
else
send, {NUMPADENTER}
return
$Enter::
ifwinactive, WinSock Chat Client
{
goto, SendviaNet
}
else
send, {ENTER}
return
$UP::
ifwinactive, WinSock Chat Client,
{
if las=1
{
guicontrol,,sendtext, %lasttype%
ControlSend Edit2, ^{End}, WinSock Chat Client
envadd, las, 1
return
}
if las=2
{
guicontrol,,sendtext, %lasttype2%
ControlSend Edit2, ^{End}, WinSock Chat Client
envadd, las, 1
return
}
if las=3
{
guicontrol,,sendtext, %lasttype3%
ControlSend Edit2, ^{End}, WinSock Chat Client
envadd, las, 1
return
}
if las=4
{
guicontrol,,sendtext, %lasttype4%
ControlSend Edit2, ^{End}, WinSock Chat Client
envadd, las, 1
return
}
if las=5
{
guicontrol,,sendtext, %lasttype5%
ControlSend Edit2, ^{End}, WinSock Chat Client
return
}
}
else
send, {UP}
return
$DOWN::
ifwinactive, WinSock Chat Client,
{
if las=1
{
guicontrol,,sendtext,
return
}
if las=2
{
guicontrol,,sendtext, %lasttype%
ControlSend Edit2, ^{End}, WinSock Chat Client
envsub, las, 1
return
}
if las=3
{
guicontrol,,sendtext, %lasttype2%
ControlSend Edit2, ^{End}, WinSock Chat Client
envsub, las, 1
return
}
if las=4
{
guicontrol,,sendtext, %lasttype3%
ControlSend Edit2, ^{End}, WinSock Chat Client
envsub, las, 1
return
}
if las=5
{
guicontrol,,sendtext, %lasttype4%
ControlSend Edit2, ^{End}, WinSock Chat Client
envsub, las, 1
return
}
}
else
send, {DOWN}
return
Connection_Init:
gui, submit, nohide
ifinstring, Clientname, %A_Space%
{
Msgbox, 16, WinSock Chat Client, You cannot use spaces in your name!
return
}
ifinstring, Clientname, *
{
Msgbox, 16, WinSock Chat Client, You cannot use asteriks in your name!
return
}
ifinstring, Clientname, RX2
{
Msgbox, 16, WinSock Chat Client, You cannot use that in your name!
return
}
ifinstring, Clientname, SR1
{
Msgbox, 16, WinSock Chat Client, You cannot use that in your name!
return
}
ifinstring, Clientname, :
{
Msgbox, 16, WinSock Chat Client, You cannot use colons in your name!
return
}
ifinstring, Clientname, $
{
Msgbox, 16, WinSock Chat 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, WinSock Chat 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}, WinSock Chat 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}, WinSock Chat Client
ifwinnotactive, WinSock Chat 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, WinSock Chat Client, Client name already in use!
exitapp
}
ExitApp
discon:
chat=
open= %Clientname% disconnected!
SendData(socket,open)
sleep, 250
;gui, destroy
sleep, 250
DllCall("Ws2_32\WSACleanup")
filedelete, %a_appdata%\Winsock-Chat\i2l.txt
filedelete, %a_appdata%\Winsock-Chat\usernamestemp.txt
on=0
checkornot=0
con=0
end=0
las=1
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%
guicontrol, disable, edit
guicontrol,show, connect
guicontrol, show, clientname
guicontrol, move, sendbutton, x146 y185 w80 h20
configurex=1
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
return
Kickexit:
gui, destroy
open= %Clientname% was kicked!
SendData(socket,open)
sleep, 500
DllCall("Ws2_32\WSACleanup")
Msgbox, 16, WinSock Chat 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, WinSock Chat Server
WinGet Gui_ID, ID, WinSock Chat Server
Gosub Connection_Init
return
buttonhide:
winhide, WinSock Chat Server
return
Show:
winshow, WinSock Chat Server
controlsend edit1, ^{end}, WinSock Chat Server
return
$numpadenter::
ifwinactive, WinSock Chat Server
{
goto, SendviaNet
}
else
send, {NUMPADENTER}
return
$Enter::
ifwinactive, WinSock Chat 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}, WinSock Chat 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}, WinSock Chat 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}, WinSock Chat 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, WinSock Chat 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 |
Last edited by jmanx on Fri Aug 01, 2008 6:20 am; edited 2 times in total |
|
| Back to top |
|
 |
WankaUSR
Joined: 14 Aug 2007 Posts: 33
|
Posted: Fri Aug 01, 2008 6:05 am Post subject: |
|
|
jmanx I see you used my logout button
shame on you for not mentioning my name (just kidding)  |
|
| Back to top |
|
 |
Jex
Joined: 01 Aug 2008 Posts: 61
|
Posted: Fri Aug 01, 2008 11:34 pm Post subject: |
|
|
any idea if this program works through work/school filters?
cause i sure hope so. i'll test that as soon as i can, but until the end of august thats not going to happen.
And i absolutely love the script, i'm so happy i found it half way through writing my own. _________________ Woot.
Please read forum etiquette |
|
| Back to top |
|
 |
SpiderGames
Joined: 09 Jun 2008 Posts: 464 Location: Canada
|
Posted: Sat Aug 02, 2008 1:58 am Post subject: |
|
|
Very interesting... The client has to be running on both computer biut the server only on one? and teh one with teh server is the Admin? _________________
Xfire: SpiderGames77 |
|
| Back to top |
|
 |
Jex
Joined: 01 Aug 2008 Posts: 61
|
|
| Back to top |
|
 |
jmanx
Joined: 14 May 2008 Posts: 48
|
Posted: Sat Aug 02, 2008 4:23 am Post subject: |
|
|
| You'd have to try it to see if it works at school or not, just don't run the server FROM school. I'd recommend running the server at home and connecting from school with client. |
|
| Back to top |
|
 |
SpiderGames
Joined: 09 Jun 2008 Posts: 464 Location: Canada
|
Posted: Sat Aug 02, 2008 12:50 pm Post subject: |
|
|
my schools a bugger. They wont let you run any safed EXE files. Is there a way to have it running on a USB and when you place it in a computer to run teh script? _________________
Xfire: SpiderGames77 |
|
| Back to top |
|
 |
jmanx
Joined: 14 May 2008 Posts: 48
|
Posted: Sat Aug 02, 2008 7:12 pm Post subject: |
|
|
autofun.inf but that will only work on CDs not USB
USB you have to click on it |
|
| Back to top |
|
 |
SpiderGames
Joined: 09 Jun 2008 Posts: 464 Location: Canada
|
Posted: Sat Aug 02, 2008 9:14 pm Post subject: |
|
|
i can work with CD's tell me more... _________________
Xfire: SpiderGames77 |
|
| Back to top |
|
 |
Jex
Joined: 01 Aug 2008 Posts: 61
|
Posted: Sat Aug 02, 2008 9:35 pm Post subject: |
|
|
i suggest you look at this for more info on AutoRun.inf.
i tried what they said for USB, didn't seem to work.
But as far as i know at my school you can start any .exe file on your USB or network folder.
if you run the files as .ahk you might b ok. _________________ Woot.
Please read forum etiquette |
|
| Back to top |
|
 |
SpiderGames
Joined: 09 Jun 2008 Posts: 464 Location: Canada
|
Posted: Sat Aug 02, 2008 9:36 pm Post subject: |
|
|
.ahk files only work on PC's with ahk _________________
Xfire: SpiderGames77 |
|
| Back to top |
|
 |
Jex
Joined: 01 Aug 2008 Posts: 61
|
Posted: Sat Aug 02, 2008 9:39 pm Post subject: |
|
|
So store AHK on your USB, thats what i do. it works fine. But that might be a difference between school boards... _________________ Woot.
Please read forum etiquette |
|
| Back to top |
|
 |
SpiderGames
Joined: 09 Jun 2008 Posts: 464 Location: Canada
|
Posted: Sat Aug 02, 2008 9:40 pm Post subject: |
|
|
Zipped? I mighted need a bigger CD then...
Thx well I have to wait till September before I can try it. _________________
Xfire: SpiderGames77 |
|
| Back to top |
|
 |
jmanx
Joined: 14 May 2008 Posts: 48
|
Posted: Sat Aug 02, 2008 10:21 pm Post subject: |
|
|
| or you can just compile it.... Wouldnt recommend the UPX packer though (can show up as false positive) |
|
| 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
|