Jump to content
Sign in to follow this  
theguy0000

question about tray functions...

Recommended Posts

theguy0000

;CWM SERVER: VERSION 0.0.1:ALPHA
#include <Constants.au3>

If ProcessExists(RegRead ("HKCU\Software\CWMessenger\Server", "version")&".exe") Then ProcessClose (RegRead ("HKCU\Software\CWMessenger\Server", "version")&".exe")

$tray_config = TrayCreateItem ("Server Configuration")
$tray_about = TrayCreateItem ("About CWM Server v0 Alpha")
TrayCreateItem ("")
$tray_disconn = TrayCreateItem ("Disconnect Server")

$CWMdir = RegRead ("HKCU\Software\CWMessenger", "CWMdir")
If $CWMdir = "" Then
    MsgBox (16, "CodeWiz Messenger Server", "Error: Could not read CWMdir from registry HKEY_CURRENT_USER\Software\CWMessenger")
    Exit
EndIf
$Port = 44844
Global $MaxConc = 100
Global $MainSocket = TCPStartServer($Port, $MaxConc)
If @error <> 0 Then Exit MsgBox(16, "Error", "Server unable to initialize.")
MsgBox (64, "CodeWiz Messenger Server", "Server started successfully at "&@IPAddress1)
IniWrite ($CWMdir&"\info.ini", "connected", "connected", 1)
Global Const $MaxLength = 512
Global $ConnectedSocket[$MaxConc]
Global $CurrentSocket = 0
Local $Track = 0
Global Const $MaxConnection = ($MaxConc - 1)
For $Track = 0 To $MaxConnection Step 1
    $ConnectedSocket[$Track] = -1
Next
While 1
    $ConnectedSocket[$CurrentSocket] = TCPAccept($MainSocket)
    If $ConnectedSocket[$CurrentSocket] <> - 1 Then
        $CurrentSocket = SocketSearch()
    EndIf
    $Track = 0
    For $Track = 0 To $MaxConnection Step 1
        If $ConnectedSocket[$Track] <> - 1 Then
            $Data = TCPRecv($ConnectedSocket[$Track], $MaxLength)
            If @error Then
                IniWrite ($CWMdir&"\info.ini", "connected", "disconnected", 0)
                MsgBox (48, "CodeWiz Messenger Server", "The CWM server has been disconnected.")
                ProcessClose (@AutoItPID)
            Else
                IniWrite ($CWMdir&"\info.ini", "connected", "connected", 0)
            EndIf
            If $Data <> "" Then
                CWM_msg_interp($Data, $ConnectedSocket[$Track])
            EndIf
        EndIf
    Next
    $tray_msg = TrayGetMsg()
    If $tray_msg = $tray_about Then CWM_about()
    If $tray_msg = $tray_config Then MsgBox ( 0, "CodeWiz Messenger Server", "Configuration is not ready yet." )
    If $tray_msg = $tray_disconn Then Exit
WEnd

;----------------
#region functions---------------------------------------------------------------------------------------------------------------------
;----------------

Func SocketSearch()
    Local $Track = 0
    For $Track = 0 To $MaxConnection Step 1
        If $ConnectedSocket[$Track] = -1 Then
            Return $Track
        Else
      ; Socket In Use
        EndIf
    Next
EndFunc;==>SocketSearch
Func TCPSendMessageAll($ConnectionLimit, $Data)
    Local $Track = 0
    For $Track = 0 To $ConnectionLimit Step 1
        If $ConnectedSocket[$Track] <> - 1 Then TCPSend($ConnectedSocket[$Track], $Data)
    Next
EndFunc;==>TCPSendMessageAll
Func TCPStartServer($Port, $MaxConnect = 1)
    Local $Socket
    $Socket = TCPStartup()
    If $Socket = 0 Then
        SetError (@error)
        return -1
    EndIf
    Global $Socket = TCPListen(@IPAddress1, $Port, $MaxConnect)
    If $Socket = -1 Then
        SetError(@error)
        Return 0
    EndIf
    SetError(0)
    Return $Socket
EndFunc;==>TCPStartServer

;------------------------------------------

Func CWM_msg_interp ($inputmsg, ByRef $Track_br)
    $msg_split = StringSplit ($inputmsg, ",")
    If $msg_split[0] > 3 Then
        For $i=4 To $msg_split[0]
            $msg_split[3] &= $msg_split[$i]
        Next
    EndIf
    $IP = $msg_split[1]
    $Action = $msg_split[2]
    If $Action <> "CWM_SERVER_PING" Then $info = $msg_split[3]
    $temp_conn = TCPConnect ($IP, $Port)
    Switch $Action
        Case "CWM_ACT_REGISTER"
    ;[IP],CWM_ACT_REGISTER,[username] [password]
            $register_info = StringSplit ($info, " ")
            If IniRead ( $CWMdir&"\info.ini", "registered_users", $register_info[1], "" ) <> "" Then
                TCPSend ($temp_conn, @IPAddress1 & ",CWM_REGISTER_FAILED,Registration was unsuccessfull. The specified username already exists.")
            Else
                If IniWrite ($CWMdir&"\info.ini", "registered_users", $register_info[1], $register_info[2]) = 0 Then
                    TCPSend ($temp_conn, @IPAddress1 & ",CWM_REGISTER_FAILED,Registration was unsuccessfull. The server info file is mode R. please notify theguy0000@gmail.com.")
                    MsgBox ( 48, "CodeWiz Messenger Server", $IP & " tried to register with username "&$register_info[1]&" and password "&$register_info[2]&", but was unsuccessful because the info.ini file is Read-Only.")
                EndIf
            EndIf
        Case "CWM_ACT_LOGIN"
            $input = StringSplit ($info, " ")
            $username = $input[1]
            $password = $input[2]
            $user_ini = IniRead ($CWMdir&"\info.ini", "registered_users", $username, "")
            If $user_ini = "" Then
                TCPSend ($temp_conn, @IPAddress1 & ",CWM_LOGIN_FAILED,Incorrect username/Password")
            Else
                If $user_ini = $password Then
                    IniWrite ($CWMdir&"\info.ini", "logged_users", $username, $IP)
                    TCPSend ($temp_conn, @IPAddress1 & ",CWM_LOGIN_CONFIRM," & $username)
                Else
                    TCPSend ($temp_conn, @IPAddress1 & ",CWM_LOGIN_FAILED,Incorrect username/Password")
                EndIf
            EndIf
        Case "CWM_MSG_SEND"
            $input = StringSplit ($info, " ")
            If $input[0] > 3 Then
                For $i=4 To $input[0]
                    $input[3] &= $input[$i]
                Next
            EndIf
            $to = $input[1]
            $from = $input[2]
            $message = $input[3]
            $temp_conn2 = TCPConnect(CWM_User2Ip($to), $Port)
            TCPSend ($temp_conn2, @IPAddress1 & "CWM_MSG_RECV,"&$from&" "&$message)
        Case "CWM_SERVER_PING"
            TCPSend ($temp_conn, @IPAddress1&",CWM_SERVER_PONG")
        Case "CWM_CLIENT_BYE"
            TCPCloseSocket ($Track_br)
            $Track_br = -1
            $CurrentSocket = SocketSearch()
        Case "CWM_BOUNCEBACK"
            TCPSend ($temp_conn, $info)
        Case "CWM_SERVER_EXIT"
            MsgBox (16, "CodeWiz Messenger Server", $info)
            Exit
    EndSwitch
EndFunc

Func CWM_User2Ip($user)
    Return IniRead ( $CWMdir&"\info.ini", "logged_users", $user, "")
EndFunc

Func CWM_about()
    MsgBox (0, "About CodeWiz Messenger", "CodeWiz Messenger Server v0 Alpha"&@CRLF&"Version 0.0.1-ALPHA"&@CRLF&"Coded by Matt Roth"&@CRLF&"Last Updated 1/22/2006"&@CRLF&""&@CRLF&"PLEASE NOTE: This software is state Alpha, and is subject to being unstable."&@CRLF&"Please send any bugs or other problems to Matt Roth <theguy0000@gmail.com>")
EndFunc

Func OnAutoItExit()
    MsgBox (0, "CodeWiz Messenger Server", "AutoItExit requested. Click OK to disconnect.")
    TCPSendMessageAll ($MaxConnection, @IPAddress1 & ",CWM_MSG_RECV,Global_Server_Message Server has been disconnect due to server exit request.")
    TCPCloseSocket ($Socket)
EndFunc

When I click any of my menu items, it just makes the autoit icon flash with a red X.

what is wrong?

Edited by theguy0000

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
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
Sign in to follow this  

×