Jump to content

Yet another chat program, but with bugs


Recommended Posts

Link to post
Share on other sites

is your timing correct?

Link to post
Share on other sites
  • 2 weeks later...

Well I guess I didn't do it "tomorrow or Tuesday".

Could I release this with a pack of random crap I'm making? It all starts with Dark just because one of my idiotic friends suggested it and I stuck with it. C-:

DarkCom - Command line type thing (Works 100%)

DarkChat - This (Working on)

Darkrypt - Encrypter (Works 100%)

DarkLog - Advanced keylogger (Works 100%)

DarkPlay - Plays music (Works 100%)

EDIT DarkLock - Screen locker (Works 100%)

EDIT DarkMsg - Fake message generator (Working on)

EDIT Dead Pixel: Antivirus Fights Back - Kill all the invding viruses! Its a game. Woo. (Working)

Edited by DarkShadow6
Link to post
Share on other sites
  • 2 months later...

Buh.

I've been working on something else so... I haven't worked on this. Here's the source:

Server:

#cs ====================
Part of the DarkTools package.
AutIt multiclient chat server.
AutoIt version: 3.3.0.0
File version:   3.7.5.5
Language:       English
Author:         DarkShadow6 and TriBlade
#CE ====================


#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <EditConstants.au3>


Global $recieve = "", $received, $listensocket = -1, $track = 0, $connected = 0, $connectionsocket = 0, $data, $empty
GUICreate("DarkChat Server", 430, 500)
GUICtrlCreateLabel("IP Address:", 15, 15, 55, 20)
GUICtrlCreateLabel("Port:", 245, 15, 30, 20)
GUICtrlCreateLabel("Maximum allowed connections:", 15, 45, 150, 20)
$ip = GUICtrlCreateEdit("127.0.0.1", 72.5, 10, 160, 20, $ES_NOHIDESEL)
$port = GUICtrlCreateEdit("8472", 270, 10, 145, 20, $ES_NUMBER)
$maxConnections = GUICtrlCreateEdit("3", 165, 40, 50, 20, $ES_NUMBER)
$textbox = GUICtrlCreateEdit("Welcome to DarkChat Server Edition." & @CRLF & @CRLF, 15, 70, 400, 150, BitOr($ES_READONLY, $ES_AUTOVSCROLL, $ES_NOHIDESEL))
$setMax = GUICtrlCreateButton("Set maximum", 220, 40, 90, 20)
$startButton = GUICtrlCreateButton("Start Server", 15, 230, 65)
$stopButton = GUICtrlCreateButton("Stop Server", 80, 230, 65)
$kickButton = GUICtrlCreateButton("Kick User", 145, 230, 55)
$chatButton = GUICtrlCreateButton("Send Chat", 200, 230, 65)
$FILLERButton = GUICtrlCreateButton("What's This Do?", 265, 230, 85)
$msgButton = GUICtrlCreateButton("Message", 350, 230, 67.5)
$userlist = GUICtrlCreateListView("Screen Name|IP Address|Socket|Number", 15, 265, 400, 222.5, $ES_READONLY)
$currentMax = GUICtrlCreateLabel("", 325, 45, 150, 20)
GUICtrlSetState($stopButton, $GUI_DISABLE)
GUICtrlSetState($kickButton, $GUI_DISABLE)
GUICtrlSetState($chatButton, $GUI_DISABLE)
GUICtrlSetState($FILLERButton, $GUI_DISABLE)
GUICtrlSetState($msgButton, $GUI_DISABLE)
GUISetState(@SW_SHOW)
setMaxGlobal()
For $track = 0 To $max - 1 Step 1
    $acceptedsocket[$track] = -1
Next


While 1
    $msg = GUIGetMsg()
    Select
        Case $msg == $GUI_EVENT_CLOSE
            Close()
        Case $msg == $startButton
            TCPStartUp()
            $listensocket = TCPListen(GUICtrlRead($ip), GUICtrlRead($port), GUICtrlRead($maxConnections))
            $connected = 1
            GUICtrlSetData($textbox, "Server started." & @CRLF, 1)
            GUICtrlSetState($stopButton, $GUI_ENABLE)
            GUICtrlSetState($kickButton, $GUI_ENABLE)
            GUICtrlSetState($chatButton, $GUI_ENABLE)
            GUICtrlSetState($FILLERButton, $GUI_ENABLE)
            GUICtrlSetState($msgButton, $GUI_ENABLE)
            GUICtrlSetState($startButton, $GUI_DISABLE)
            GUICtrlSetState($setMax, $GUI_DISABLE)
            GUICtrlSetState($ip, $GUI_DISABLE)
            GUICtrlSetState($port, $GUI_DISABLE)
            GUICtrlSetState($maxConnections, $GUI_DISABLE)
            mainHandle()
        Case $msg == $stopButton
            MsgBox(16, "Error Disconnecting", "The server isn't connected.")
        Case $msg == $setMax
            setMaxGlobal()
    EndSelect
WEnd


Func Close()
    If $connected == 1 Then
        stopServer()
    EndIf
    Exit
EndFunc


Func stopServer()
    If $connected == 0 Then
        MsgBox(16, "Error", "The server is already stopped.")
        Return False
    EndIf
    $connected = 0
    sendToConnectedSockets("Receive:end")
    For $track = 0 To $max - 1 Step 1
        If $acceptedsocket[$track] <> -1 Then
            TCPCloseSocket($acceptedsocket[$track])
        EndIf
    Next
    TCPShutdown()
    GUICtrlSetData($textbox, "Server stopped." & @CRLF, 1)
    GUICtrlSetState($stopButton, $GUI_DISABLE)
    GUICtrlSetState($startButton, $GUI_ENABLE)
    GUICtrlSetState($setMax, $GUI_ENABLE)
    GUICtrlSetState($kickButton, $GUI_DISABLE)
    GUICtrlSetState($chatButton, $GUI_DISABLE)
    GUICtrlSetState($FILLERButton, $GUI_DISABLE)
    GUICtrlSetState($msgButton, $GUI_DISABLE)
    GUICtrlSetState($ip, $GUI_ENABLE)
    GUICtrlSetState($port, $GUI_ENABLE)
    GUICtrlSetState($maxConnections, $GUI_ENABLE)
    _GUICtrlListView_DeleteAllItems($userlist)
EndFunc


Func mainHandle()
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg == $GUI_EVENT_CLOSE
                Close()
            Case $msg == $startButton
                MsgBox(16, "Error Connecting", "The server is already connected.")
            Case $msg == $stopButton
                stopServer()
                ExitLoop
            Case $msg == $kickButton
                $name = InputBox("Kick", "Enter someone's username here to kick them from the server.", "Username")
                sendToConnectedSockets("Receive:disconnect:" & $name)
            Case $msg == $chatButton
                $message = InputBox("Chat", "Enter a message to send to the clients.", "Chat")
                GUICtrlSetData($textbox, "Server: " & $message & @CRLF, 1)
                sendToConnectedSockets("Server: " & $message)
            Case $msg == $FILLERButton
                $erm = InputBox("Wuh?!", "Some random command. Help me with some ideas for it!", "Erm?")
                ;sendToConnectedSockets()
            Case $msg == $msgButton
                $word = InputBox("Send Message", "Send a pop-up message to everyone on the server.", "Message")
                sendToConnectedSockets("Receive:message:" & $word)
        EndSelect
        If $socketsLeft > 0 then
            $empty = socketSearch()
            If $acceptedsocket[$empty] == -1 Then
                $connectionsocket = TCPAccept($listensocket)
                If $connectionsocket <> -1 Then
                    $acceptedsocket[$empty] = $connectionsocket
                Else
                    sendToConnectedSockets("Receive:overflow")
                    TCPCloseSocket($listensocket)
                EndIf
            EndIf
        EndIf
        $track = 0
        For $track = 0 To $max - 1 Step 1
            If $acceptedsocket[$track] <> -1 Then
                $data = TCPRecv($acceptedsocket[$track], 1024)
                If $data <> "" Then checkCommand($data)
            EndIf
        Next
    WEnd
EndFunc


Func checkCommand($message)
    If StringLeft($message, 8) == "Receive:" Then
        catchCommand(StringTrimLeft($message, 8))
    Else
        If $message <> "" Then
            GUICtrlSetData($textbox, $message & @CRLF, 1)
            sendToConnectedSockets($message)
        EndIf
    EndIf
EndFunc


Func socketSearch()
    Local $track = 0
    For $track = 0 To $max - 1 Step 1
        If $acceptedsocket[$track] == -1 Then Return $track
        Next
        Return $track
EndFunc


Func catchCommand($received)
    Local $found
    Select
        Case StringLeft($received, 8) = "connect:"
            $socketsLeft = $socketsLeft - 1
            $empty = socketSearch()
            $usernameGet = StringSplit(StringTrimLeft($received, 8), "|")
            GUICtrlSetData($textbox, "'" & $usernameGet[1] & "' has connected." & @CRLF, 1)
            sendToConnectedSockets("'" & $usernameGet[1] & "' has connected.")
            GUICtrlCreateListViewItem(StringTrimLeft($received, 8) & "|" & $acceptedsocket[$empty] & "|" & $empty, $userlist)
        Case StringLeft($received, 11) = "disconnect:" And StringTrimLeft($received, 11) <> ""
            $found = _GUICtrlListView_FindInText($userlist, StringTrimLeft($received, 11), -1, $LVFI_STRING)
            $item = _GUICtrlListView_GetItemTextArray($userlist, $found)
            If IsArray($item) Then
                $socketsLeft = $socketsLeft + 1 
                GUICtrlSetData($textbox, "'" & StringTrimLeft($received, 11) & "' has disconnected." & @CRLF, 1)
                sendToConnectedSockets("'" & StringTrimLeft($received, 11) & "' has disconnected.")
                TCPCloseSocket($acceptedsocket[$item[3]])
                $acceptedsocket[$item[3]] = -1
                _GUICtrlListView_DeleteItem($userlist, $found)
            Else
                GUICtrlSetData($textbox, "'" & StringTrimLeft($received, 11) & "' could not be disconnected." & @CRLF, 1)
            EndIf
            $empty = socketSearch()
    EndSelect
EndFunc


Func setMaxGlobal()
    Global $max = GUICtrlRead($maxConnections)
    Global $acceptedsocket[$max]
    For $track = 0 To $max - 1 Step 1
        $acceptedsocket[$track] = -1
    Next
    Global $item[$max]
    Global $socketsLeft = $max
    GUICtrlSetData($currentMax, "Currently set: " & GUICtrlRead($maxConnections))
EndFunc


Func sendToConnectedSockets($message)
    For $track = 0 To $max - 1 Step 1
        If $acceptedsocket[$track] <> -1 Then
            TCPSend($acceptedsocket[$track], $message)
        EndIf
    Next
EndFunc

Client:

#cs ====================
Part of the DarkTools package.
AutIt multiclient chat client for the chat server.
AutoIt version: 3.3.0.0
File version:   3.4.0.1
Language:       English
Author:         DarkShadow6 and TriBlade
#CE ====================


#include <GUIConstants.au3>
#include <EditConstants.au3>


Global $connectsocket = -1
GUICreate("DarkChat Client", 430, 325)
GUICtrlCreateLabel("Username:", 15, 15, 75, 20)
GUICtrlCreateLabel("Server IP Address:", 15, 45, 95, 20)
GUICtrlCreateLabel("Server Port:", 15, 75, 75, 20)
$textbox = GUICtrlCreateEdit("Welcome to DarkChat Client Edition." & @CRLF & @CRLF, 15, 100, 400, 150, BitOr($ES_READONLY, $ES_AUTOVSCROLL))
$username = GUICtrlCreateInput("Anonymous", 110, 10, 100, 20)
$ip = GUICtrlCreateInput("127.0.0.1", 110, 40, 100, 20)
$port = GUICtrlCreateInput("8472", 110, 70, 100, 20)
$text = GUICtrlCreateInput("Type a message here", 15, 260, 400, 20)
$sendButton = GUICtrlCreateButton("Send", 15, 290, 60)
$connectButton = GUICtrlCreateButton("Connect", 80, 290, 70)
$disconnectButton = GUICtrlCreateButton("Disconnect", 155, 290, 70)
GUICtrlSetState($sendButton, $GUI_DISABLE)
GUICtrlSetState($disconnectButton, $GUI_DISABLE)
GUISetState(@SW_SHOW)


While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Close()
        Case $msg = $connectButton
            TCPStartUp()
            $connectsocket = TCPConnect(GUICtrlRead($ip), GUICtrlRead($port))
            If $connectsocket <> -1 Then
                Sleep(100)
                TCPSend($connectsocket, "Receive:connect:" & GUICtrlRead($username) & "|" & @IPAddress1)
                GUICtrlSetState($connectButton, $GUI_DISABLE)
                GUICtrlSetState($sendButton, $GUI_ENABLE)
                GUICtrlSetState($disconnectButton, $GUI_ENABLE)
                GUICtrlSetState($username, $GUI_DISABLE)
                GUICtrlSetState($ip, $GUI_DISABLE)
                GUICtrlSetState($port, $GUI_DISABLE)
                GUICtrlSetData($textbox, "Client connected." & @CRLF, 1)
                mainHandle()
            Else
                GUICtrlSetData($textbox, "Connection failed." & @CRLF, 1)
            EndIf
    EndSelect
WEnd


Func sendTCPChat($sending)
    If StringLeft($sending, 8) == "Receive:" Then Return False
    TCPSend($connectsocket, GUICtrlRead($username) & ": " & $sending)
EndFunc


Func Close()
    Disconnect()
    Exit
EndFunc


Func Disconnect()
    GUICtrlSetState($connectButton, $GUI_ENABLE)
    GUICtrlSetState($sendButton, $GUI_DISABLE)
    GUICtrlSetState($disconnectButton, $GUI_DISABLE)
    GUICtrlSetState($username, $GUI_ENABLE)
    GUICtrlSetState($ip, $GUI_ENABLE)
    GUICtrlSetState($port, $GUI_ENABLE)
    TCPSend($connectsocket, "Receive:disconnect:" & GuiCtrlRead($username))
    Sleep(100)
    If $connectsocket <> -1 Then TCPCloseSocket($connectsocket)
    $connectsocket = -1
    TCPShutdown()
    GUICtrlSetData($textbox, "Client disconnected." & @CRLF, 1)
EndFunc


Func mainHandle()
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Disconnect()
                Close()
            Case $msg = $sendButton
                sendTCPChat(GUICtrlRead($text))
            Case $msg = $connectButton
                MsgBox(16, "Error Connecting" , "Already connected.")
            Case $msg = $disconnectButton
                Disconnect()
                ExitLoop
        EndSelect
        $data = TCPRecv($connectsocket, 1024)
        If $data <> "" Then checkCommand($data)
    WEnd
EndFunc


Func checkCommand($messages)
    If StringLeft($messages, 8) == "Receive:" Then
        catchCommand(StringTrimLeft($messages, 8))
    Else
        If $messages <> "" Then
            GUICtrlSetData($textbox, $messages & @CRLF, 1)
        EndIf
    EndIf
EndFunc


Func catchCommand($received)
    Select
        Case StringLeft($received, 11) == "disconnect:" And StringTrimLeft($received, 11) == GUICtrlRead($username)
            GUICtrlSetData($textbox, "The server administrator has disconnected you." & @CRLF, 1)
            Disconnect()
        Case StringLeft($received, 8) == "message:"
            MsgBox(0, "Server Message", StringTrimLeft($received, 8))
        Case $received == "end"
            GUICtrlSetData($textbox, "The server administrator has shut down the server." & @CRLF, 1)
            Disconnect()
        Case $received == "overflow"
            GUICtrlSetData($textbox, "The server has reached it's occupancy limit." & @CRLF, 1)
            Disconnect()
        EndSelect
EndFunc
Link to post
Share on other sites
  • 2 weeks later...

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...