AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TCP/IP Server+Client Chat Script (w/ Features)
Goto page Previous  1, 2, 3, 4, 5, 6  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  

Would you use this script?
Yes
73%
 73%  [ 17 ]
No
8%
 8%  [ 2 ]
Frequently
13%
 13%  [ 3 ]
Maybe once or Twice
4%
 4%  [ 1 ]
Total Votes : 23

Author Message
Fry



Joined: 01 Nov 2007
Posts: 689

PostPosted: Thu Jun 12, 2008 8:57 pm    Post subject: Reply with quote

I dont use CCleaner, I use a program I made.
_________________
check out my site
www.eliteknifesquad.com
Back to top
View user's profile Send private message
Slanter



Joined: 28 May 2008
Posts: 397
Location: Minnesota, USA

PostPosted: Thu Jun 12, 2008 9:19 pm    Post subject: Reply with quote

I agree with n-l-i-d, there is simply no reason for putting temp files anywhere near your system files. If you really can't use the script's directory, at least use the system's temporary folder (%A_Temp%), or application data (%A_AppData%) and make a folder for your script in one of those.
Back to top
View user's profile Send private message Visit poster's website
jmanx



Joined: 14 May 2008
Posts: 48

PostPosted: Thu Jun 12, 2008 11:56 pm    Post subject: Reply with quote

Temporary files are now located in
%A_appdata%\Winsock-chat


Also my server is on, I didn't know people wanted it on.

Let's cut the malarkey
Back to top
View user's profile Send private message
n-l-i-d
Guest





PostPosted: Fri Jun 13, 2008 2:40 pm    Post subject: Reply with quote

Great Smile

But, and I mean in no way to be "malarkeyous" ( Question Razz ) why are you still putting files in the C:/ root? That is the traditional startup root, and - again - your files don't belong there. Only system relevant files (@Fry, I'm not talking about folders, even though they should not be there either ideally).

Permission settings are very likely to screw this up anyway, if you are not an admin or super-user.

If you think you somehow need them there, check up on "working directory" settings.

Again, I like your script very much, but I (feel I) must point you to these issues (so everybody can learn).

Simple: use the Windows specified paths for your files only, deviate only if you have to, and save yourself (and your script's users) a lot of headaches Wink
Back to top
jmanx



Joined: 14 May 2008
Posts: 48

PostPosted: Fri Jun 13, 2008 3:04 pm    Post subject: Reply with quote

Honestly, all i did the first time was

stringreplace, clipboard,clipboard, a_windir, a_appdata, All


So forgot about the C:\ files
Those all save in %A_Appdata%\Winsock-chat\ including the temporary files for the ping feature now.
Back to top
View user's profile Send private message
gtr4
Guest





PostPosted: Mon Jun 16, 2008 4:22 am    Post subject: Reply with quote

cool script
Back to top
Guest






PostPosted: Tue Jun 17, 2008 8:40 pm    Post subject: Reply with quote

Wtf is wrong with %A_ScriptDir%\Temp!! The .ini could easily be in the scripts directory! The temporary files could easily be in a sub folder in the scripts directory! Putting them elsewhere is annoying and inconvenient when someone removes your script from their system!
Back to top
wtg



Joined: 04 Oct 2006
Posts: 64
Location: Louisville, KY

PostPosted: Thu Jun 19, 2008 12:35 pm    Post subject: Reply with quote

Anonymous wrote:
Wtf is wrong with %A_ScriptDir%\Temp!! The .ini could easily be in the scripts directory! The temporary files could easily be in a sub folder in the scripts directory! Putting them elsewhere is annoying and inconvenient when someone removes your script from their system!


What the heck is wrong with your manners?!?! Sheesh, don't use the script if the use of a temp file in the standard AppData directory gets you that worked up. Or better yet, modify it and post your improvements.
Back to top
View user's profile Send private message
adamrgolf



Joined: 28 Dec 2006
Posts: 390

PostPosted: Thu Jun 19, 2008 12:49 pm    Post subject: Reply with quote

Anonymous wrote:
Wtf is wrong with [me]!


aka what he should have said Razz
Back to top
View user's profile Send private message
gtr4
Guest





PostPosted: Fri Jun 20, 2008 3:47 pm    Post subject: Reply with quote

lol
Back to top
jmanx



Joined: 14 May 2008
Posts: 48

PostPosted: Tue Jun 24, 2008 11:27 pm    Post subject: Reply with quote

Already fixed the directorys.
Back to top
View user's profile Send private message
Fry



Joined: 01 Nov 2007
Posts: 689

PostPosted: Sat Jul 12, 2008 9:36 pm    Post subject: Reply with quote

Is this dead

cuz i really liked it
_________________
check out my site
www.eliteknifesquad.com
Back to top
View user's profile Send private message
jmanx



Joined: 14 May 2008
Posts: 48

PostPosted: Sat Jul 12, 2008 11:45 pm    Post subject: Reply with quote

You guys can throw up your own servers you know.

You can edit the client to your liking and compile it and produce to others for chatting purposes. If a server gets big though (like 10+ people) I'd appreciate it if you posted your IP and port here so others may join in.
Back to top
View user's profile Send private message
WankaUSR



Joined: 14 Aug 2007
Posts: 33

PostPosted: Tue Jul 15, 2008 11:51 am    Post subject: Reply with quote

I've modified the server script to send an ASCII logo (you can use http://www.autohotkey.com/forum/viewtopic.php?t=33465 ) when connected. The logo can be modified from the tray menu EditLogo
btw can I use the code in one of my project? something like communicating to a server not like a chat
EDIT:
I''ve added disconnect and minimize to tray function to the client and listbox of user (in server doubleclick shows menu to kick )

client.ahk
Code:
#singleinstance force
;#notrayicon
ifnotexist, %a_appdata%\Winsock-Chat
{
Filecreatedir, %a_appdata%\Winsock-Chat
}
configurex=1
menu, tray, icon, %A_Windir%\system32\narrator.exe
menu, tray, nostandard
menu, tray, add, Hide
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 = 127.0.0.1
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 w300 h20 vSendText,
Gui, Add, Button, x316 y155 w70 h20 vhide ghide, HIDE
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, listbox, x276 y5 w110 h140 vuserlistin,
Gui, Add, Button, x316 y185 w70 h20 vedit gdisconn, Log Off
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:
if configurex=1
{
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
}
else
msgbox,,Client,Connection configuration is available only if disconnected!
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

hide:
if hide<>0
{
hide=0
gui,hide
}
else
{
hide=1
Gui, Show, h218 w394, Client
}
return

check:
if on=0
{
Settimer,check,off
return
}
if on=1
{
ifnotinstring, checklist, %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:
configurex=0
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, enable, edit
;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
   TrayTip , MessageBox, New message received!, 3, 1
   }
        }
    }
    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
{
ifinstring, Showrecieved2, SR1LOGIN0
{
st=|
stringreplace, ShowRecieved2, ShowRecieved2, SR1LOGIN0,,ALL
stringreplace, ShowRecieved2, ShowRecieved2, *,|, All
}
filedelete, %a_appdata%\Winsock-Chat\userlistc.txt
stringreplace, ShowRecieved2, ShowRecieved2, SR1CLIENTADDLIST,,ALL
stringreplace, ShowRecieved2, ShowRecieved2, *,|, All
fileappend, %ShowRecieved2%, %a_appdata%\Winsock-Chat\userlistc.txt
fileread,  userlist, %a_appdata%\Winsock-Chat\userlistc.txt
;stringreplace, userlist2, userlist, *, `n, ALL

guicontrol,,userlistin, %st%%userlist%
userlist2=%userlist%
checklist=%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

disconn:
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,,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)
)
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

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.ahk
Code:
#singleinstance force
;#notrayicon
ifnotexist, %a_appdata%\Winsock-Chat
{
Filecreatedir, %a_appdata%\Winsock-Chat
}
ifnotexist, %a_appdata%\Winsock-Chat\logo.txt
{
logo=
(
~~~~~Welcome to Winsock-Chat!~~~~~
)
fileappend,%logo%,%a_appdata%\Winsock-Chat\logo.txt
}
else
fileread,logo,%a_appdata%\Winsock-Chat\logo.txt
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, EditLogo
menu, tray, add, Show
menu, tray, add, Exit

colordef=C0C0C0
gui, color, %colordef%
Gui, Add, Edit, x6 y5 w360 h190 readonly vchat,
Gui, Add, listbox, x376 y5 w110 h150 vchatlist gusropt,
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%|, %a_appdata%\Winsock-Chat\userlist.txt
fileread, userlist, %a_appdata%\Winsock-Chat\userlist.txt
guicontrol,,chatlist, |%userlist%
stringreplace,userlist,userlist,|,*,All
sleep, 500
Sendtext=SR1CLIENTADDLIST%userlist%
gosub, send1
Sendtext=%logo%
gosub, send1
name1=
cord=
return
}
if cord=disconnected!
{
fileread, dellist, %a_appdata%\Winsock-Chat\userlist.txt
stringreplace, dellist2, dellist, %name1%|
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,|,*,All
Sendtext=SR1LOGIN0SR1CLIENTADDLIST%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%|
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,|,*,All
Sendtext=SR1LOGIN0SR1CLIENTADDLIST%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

editlogo:
msgbox,16,Server, You have to restart the app before the logo changes work!
run %a_appdata%\Winsock-Chat\logo.txt
return

usropt:
If A_GuiEvent=DoubleClick
{
Menu, MyMenu, Add, Kick, kick
Menu, MyMenu, Show
}
return

kick:
Gui,Submit,NoHide
kicknick=%chatlist%
Sendtext=Admin is kicking %kicknick%
gosub, send1
sleep, 5000
ref=
Sendtext=RX2KICKPLAYER%kicknick%
gosub, send1
sleep, 500
fileread, dellist, %a_appdata%\Winsock-Chat\userlist.txt
stringreplace, dellist2, dellist, %kicknick%|
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,|,*,All
Sendtext=SR1LOGIN0SR1CLIENTADDLIST%userlist%
gosub, send1
sendtext=
name1=
kicknick=
cord=
return


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


This is such a great project that i decided to improve it by adding some more commands to the client . If anyone is interested in making this program AHK-Chat and want any to add functions please post here. Also if anyone can keep a sever running at least 90% of the time it would be great
Back to top
View user's profile Send private message Visit poster's website
Fry



Joined: 01 Nov 2007
Posts: 689

PostPosted: Tue Jul 29, 2008 9:43 pm    Post subject: Reply with quote

Is this not being developed anymore
_________________
check out my site
www.eliteknifesquad.com
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6  Next
Page 3 of 6

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group