Jump to content

Chat Speach


Marlo
 Share

Recommended Posts

OK so today me and a friend decided to play an old time RTS game (Cossacks ftw). The only problem with this game is the chat system sucks as alot of the time you done notice your friends message pop up.

So anyways i decided to make a chat system that actually spoke what you typed. :):o

And thus Chat Speach was born!

It use's Kips event driven TCP system for the connection stuff.

(Get it Here: http://www.autoitscript.com/forum/index.ph...t&id=24094)

It was a bit of a rush job but it did the job i made it for so a success on that part :)

Please tell me what you think.

Code:

#include <TCP.au3>

#cs
    Ask the user whether they want to host or join a chat, then ask for connection info.
    If invalid data is entered then exit.
#ce
If MsgBox(36, "Chat Speach", "Do you want to host the chat?" & @CR & @CR & "Press Yes to Host or No to join") = 6 Then
    Global $iPort = InputBox("Chat Speach", "Enter the port you wish to listen on", 3030)
    If StringIsInt($iPort) = 0 Then _Exit("Invalid Port Entered")
    Global $bServer = True
    _CreateServer()
Else
    Global $sHost = InputBox("Chat Speach", "Enter the Host you wish to connect to")
    If $sHost = "" Then _Exit("No Host Entered")
    Global $iPort = InputBox("Chat Speach", "Enter the port you wish to connect through", 3030)
    If StringIsInt($iPort) = 0 Then _Exit("Invalid Port Entered")
    Global $bServer = False
    _CreateClient()
EndIf

Global $bInput = False
Global $sMessage
HotKeySet("{NUMPAD9}", "_Input") ;This is the hotkey to start/end a chat segment.

While 1
    Sleep(50)
WEnd

;Create the Host with given info and set events.
Func _CreateServer()
    _TCP_Server_Create($iPort)
    _TCP_RegisterEvent($TCP_NEWCLIENT, "_NewCon")
    _TCP_RegisterEvent($TCP_RECEIVE, "_Message")
EndFunc   ;==>_CreateServer

;Create a client using the info given and set events.
Func _CreateClient()
    _TCP_Client_Create($iPort, $sHost)
    _TCP_RegisterEvent($TCP_RECEIVE, "_Message")
    _TCP_RegisterEvent($TCP_CONNECT, "_ClientConnected")
EndFunc   ;==>_CreateClient

;When the client connects sucessfully they are given audio confirmation.
Func _ClientConnected($hSocket, $iError)
    _Speak("Connected")
EndFunc   ;==>_ClientConnected

;When the server has a new connection they are given audio confirmation.
Func _NewCon($hSocket, $iError)
    _Speak("New Connection")
EndFunc   ;==>_NewCon

;When TCP data is received then process it.
Func _Message($hSocket, $iError, $sReceived)
    $sCmd = StringLeft($sReceived, 3)
    $sParam = StringMid($sReceived, 4)

    Switch $sCmd
        Case "msg"
            _Speak($sParam)
    EndSwitch
EndFunc   ;==>_Message

#cs
    When the HotKey has been pressed then set 25 new hotkeys (a-z) and when these new
    hotkeys are pressed then their value is added to the $sMessage variable.
    When the hotkey is pressed again then all the hotkeys are unset and the message is sent
#ce
Func _Input()
    If $bInput = False Then
        HotKeySet(" ", "_KeyPressed")
        For $I = 97 To 122
            HotKeySet(Chr($I), "_KeyPressed")
        Next
        $bInput = True
    Else
        HotKeySet(" ")
        For $I = 97 To 122
            HotKeySet(Chr($I))
        Next
        $bInput = False
        If $bServer = True Then
            _TCP_Server_Send("msg" & $sMessage)
            $sMessage = ""
        Else
            _TCP_Client_Send("msg" & $sMessage)
            $sMessage = ""
        EndIf
    EndIf
EndFunc   ;==>_Input

;Add the key to the $sMEssage variable.
Func _KeyPressed()
    $sMessage &= @HotKeyPressed
EndFunc   ;==>_KeyPressed

;Use the Speach module shipped with windows to output the message.
Func _Speak($sText)
    Local $oSpeech = ObjCreate("SAPI.SpVoice")
    If IsObj($oSpeech) Then $oSpeech.Speak($sText)
EndFunc   ;==>_Speak

;Error handler.
Func _Exit($sError)
    MsgBox(16, "Chat Speach", "Application had to quit for the following reason: " & @CR & @CR & $sError)
    Exit
EndFunc   ;==>_Exit
Click here for the best AutoIt help possible.Currently Working on: Autoit RAT
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...