DSChaos

FTP Chat (Base version) and Updater

4 posts in this topic

#1 ·  Posted (edited)

Hi of all comunity ,now , today i have to submit a my (not-hard project), a FTP (File Transfer Protocol) Chat, with external auto-updater ;) )

 

FTP Chat v1.0.0.0

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <FTPEx.au3>
#include <StaticConstants.au3>

#pragma compile(Out, FTP Chat v1.0.0.0.exe)
#pragma compile(FileDescription, ChatForm 1.0.0.0 - A chat for you!)
#pragma compile(Compatibility, win7)
#pragma compile(ProductName, ChatForm 1.0.0.0)
#pragma compile(ProductVersion, 1.0.0.0)
#pragma compile(FileVersion, 1.0.0.0)
#pragma compile(LegalCopyright, © TeamWork Enterprise)
#pragma compile(CompanyName, 'TeamWork Enterprise')

FileDelete("update.ini")
FileDelete("delta.tfs")

;;;;;;;;;;;;;;;;                                            ;;;;;;;;;;;;;;;;
;               START: Generate a data ID of user for server               ;(IF IS NOT A FORM who required a nikname)
;;;;;;;;;;;;;;;;                                            ;;;;;;;;;;;;;;;;
#cs
$FLLOP=FileOpen("conf.ini")
If $FLLOP=-1 Then
   _filecreate("conf.ini")
   FileWriteLine("config.ini","[DO NOT DELETE THE FILE]")
   $FILECL=_FileCountLines("data.dat")
   For $DN=1 to 15 Step +1
      $RAN=Random(1,$FILECL)
      $FLR=FileReadLine("data.dat",$RAN)
      $filewrite=FileWrite("conf.config",$FLR)
   Next
EndIf
#ce
;;;;;;;;;;;;;;;;                                          ;;;;;;;;;;;;;;;;
;               END: Generate a data ID of user for server               ;
;;;;;;;;;;;;;;;;                                          ;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;                           ;;;;;;;;;;;;;;;;
;               START: Koda gui of software               ;
;;;;;;;;;;;;;;;;                           ;;;;;;;;;;;;;;;;

#Region ### START Koda GUI section ### Form=C:\Users\Giggi\Desktop\webserver_011\Autoit3\Chat\Chat 2.kxf
$Form2 = GUICreate("FTP Chat  v1.0.0.0", 802, 347, 182, 125)
$MenuItem1 = GUICtrlCreateMenu("Menu")
$MenuItem3 = GUICtrlCreateMenuItem("Create a Room", $MenuItem1)
$MenuItem2 = GUICtrlCreateMenuItem("Exit", $MenuItem1)
$Edit1 = GUICtrlCreateEdit("", 0, 0, 801, 201)
GUICtrlSetData(-1, "[SOFTWARE] Loaded!")
$Input1 = GUICtrlCreateInput("Input1", 0, 208, 697, 21)
$Button1 = GUICtrlCreateButton("Send", 704, 207, 91, 23)
$Button2 = GUICtrlCreateButton("Update Chat", 704, 232, 91, 23)
$Button3 = GUICtrlCreateButton("Connect Chat", 704, 257, 91, 23)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;;;;;;;;;;;;;;;;                           ;;;;;;;;;;;;;;;;
;               START: Configuarzione Nikname             ;
;;;;;;;;;;;;;;;;                           ;;;;;;;;;;;;;;;;

$FLLOP=FileOpen("config.ini")
If $FLLOP=-1 Then
   #Region ### START Koda GUI section ### Form=C:\Users\Giggi\Desktop\webserver_011\Autoit3\Chat\DATA Chat 2\SEC NIK.kxf
   $Form2x = GUICreate("Thanks", 443, 161, 418, 289)
   $Label1 = GUICtrlCreateLabel("Thanks for downloading the software, now but you need to create a your nik for chating.", 8, 8, 420, 17)
   $Input1x = GUICtrlCreateInput("", 8, 48, 425, 21)
   $Button1x = GUICtrlCreateButton("Ok", 360, 128, 75, 25)
   $Button2x = GUICtrlCreateButton("Cancel", 8, 128, 75, 25)
   GUISetState(@SW_SHOW)
   #EndRegion ### END Koda GUI section ###

   While 1
       $nMsg = GUIGetMsg()
       Switch $nMsg
            Case $GUI_EVENT_CLOSE
               MsgBox(64,"Nope","You need to put a nikname to use the chat")
               Exit
            Case $Button2x
               Exit
            Case $Button1x
               $GUIR=GUICtrlRead($Input1x)
               _FileCreate("data2.ini")
               _FileCreate("config.ini")
               FileWriteLine("config.ini","[DO NOT DELETE THE FILE]")
               FileWriteLine("config.ini",$GUIR)
               FileWriteLine("config.ini","1.0.0.0")
               FileWriteLine("data2.ini","[UPDATE_SOFTWARE]")
               FileWriteLine("data2.ini","1.0.0.0")
               MsgBox(64,"Succes!","Nikname added succesfull!")
               GUIDelete($Form2x)
               ExitLoop
       EndSwitch
    WEnd
 EndIf

;;;;;;;;;;;;;;;;                           ;;;;;;;;;;;;;;;;
;               END: Configurazione Nikname               ;
;;;;;;;;;;;;;;;;                           ;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;                           ;;;;;;;;;;;;;;;;
;               START: Cheking Update                     ;
;;;;;;;;;;;;;;;;                           ;;;;;;;;;;;;;;;;

$FTPd=_FTP_Open("update_sofware_ftp")
$FTP01d=_FTP_Connect($FTPd,"censured","censured","censured")
_FTP_FileGet($FTP01d,"/update.ini","update.ini")
$LRD=FileReadLine("update.ini",2)
If $LRD>"1.0.0.0" Then
   MsgBox(64,"Update","Downloading a new update....",1)
   Run("update.exe")
   Exit
EndIf
If $LRD<"1.0.0.0" Then
   MsgBox(48,"Downgrade","Downloading the downgrade....",1)
   Run("update.exe")
   Exit
EndIf

;;;;;;;;;;;;;;;;                           ;;;;;;;;;;;;;;;;
;               END: Cheking Update                       ;
;;;;;;;;;;;;;;;;                           ;;;;;;;;;;;;;;;;

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         Case $MenuItem2
            Exit
         Case $MenuItem3
            #Region ### START Koda GUI section ### Form=
            $Form1sd = GUICreate("Create Room", 480, 250, 192, 124)
            $Label1sd = GUICtrlCreateLabel("Name Room: ", 8, 16, 69, 17)
            $Input1sd = GUICtrlCreateInput("Name....", 80, 8, 393, 21)
            $Button1sd = GUICtrlCreateButton("Create", 400, 216, 75, 25)
            GUISetState(@SW_SHOW)
            #EndRegion ### END Koda GUI section ###

            While 1
                $nMsg = GUIGetMsg()
                Switch $nMsg
                    Case $GUI_EVENT_CLOSE
                        GUIDelete($Form1sd)
                        ExitLoop
                     Case $Button1sd
                        $GUIREADCHAT=GUICtrlRead($Input1sd)
                        _FileCreate($GUIREADCHAT&".txt")
                        $FTPX=_FTP_Open("myFTP_ROOM")
                        $FTPX=_FTP_Connect($FTPX,"censured","censured","censured")
                        _FTP_FilePut($FTPX,$GUIREADCHAT&".txt","/chat/"&$GUIREADCHAT&".txt")
                        If @error Then
                           MsgBox(48,"Error","Error to create the Room Chat!")
                        Else
                           MsgBox(64,"Succes","The room has ben created!")
                        EndIf
                        FileDelete($GUIREADCHAT&".txt")
                        GUIDelete($Form1sd)
                        ExitLoop
                EndSwitch
            WEnd
         Case $Button2
            If FileOpen("delta.tfs")=-1 Then
               MsgBox(48,"Error","Please connect a chat")
            Else
               $FTPa=_FTP_Open("my_FTPChat")
               $FTP1a=_FTP_Connect($FTPa,"censured","censured","censured")
               $INPe=FileReadLine("delta.tfs",1)
               _FTP_FileGet($FTP1a,"/chat/"&$INPe&".txt",$INPe&".txt")
               If @error Then
                  MsgBox(0,"ERROR","ERROR: Chat NON trovata e/o NON esistente")
               EndIf
               $FLLT=_FileCountLines($INPe&".txt")
               $FRR0=$FLLT-0
               $FRR1=$FLLT-1
               $FRR2=$FLLT-2
               $FRR3=$FLLT-3
               $FRR4=$FLLT-4
               $FRR5=$FLLT-5
               $FRR6=$FLLT-6
               $FRR7=$FLLT-7
               $FRR8=$FLLT-8
               $FRR9=$FLLT-9
               $FRR10=$FLLT-10
               $FRR11=$FLLT-11
               $FRR12=$FLLT-12
               $FRR13=$FLLT-13
               $FRR14=$FLLT-14
               $FLR014=FileReadLine($INPe&".txt",$FRR14)
               $FLR013=FileReadLine($INPe&".txt",$FRR13)
               $FLR012=FileReadLine($INPe&".txt",$FRR12)
               $FLR011=FileReadLine($INPe&".txt",$FRR11)
               $FLR010=FileReadLine($INPe&".txt",$FRR10)
               $FLR09=FileReadLine($INPe&".txt",$FRR9)
               $FLR08=FileReadLine($INPe&".txt",$FRR8)
               $FLR07=FileReadLine($INPe&".txt",$FRR7)
               $FLR06=FileReadLine($INPe&".txt",$FRR6)
               $FLR05=FileReadLine($INPe&".txt",$FRR5)
               $FLR04=FileReadLine($INPe&".txt",$FRR4)
               $FLR03=FileReadLine($INPe&".txt",$FRR3)
               $FLR02=FileReadLine($INPe&".txt",$FRR2)
               $FLR01=FileReadLine($INPe&".txt",$FRR1)
               $FLR00=FileReadLine($INPe&".txt",$FRR0)
               GUICtrlSetData($Edit1,StringFormat("[SOFTWARE] Load succesfull!\r\n[SOFTWARE] Last 15 messages:\r\n"&$FLR014&"\r\n"&$FLR013&"\r\n"&$FLR012&"\r\n"&$FLR011&"\r\n"&$FLR010&"\r\n"&$FLR09&"\r\n"&$FLR08&"\r\n"&$FLR07&"\r\n"&$FLR06&"\r\n"&$FLR05&"\r\n"&$FLR04&"\r\n"&$FLR03&"\r\n"&$FLR02&"\r\n"&$FLR01&"\r\n"&$FLR00))
               _FTP_Close($FTPa)
            Endif
         Case $Button1
            If FileOpen("delta.tfs")=-1 Then
               MsgBox(48,"Error","Please Connect a chat")
            Else
               $FTPOPP=_FTP_Open("DELTA_UPDATE_FTP")
               $FTP01=_FTP_Connect($FTPOPP,"censured","censured","censured")
               $FLR01=FileReadLine("delta.tfs",1)
               _FTP_FileGet($FTP01,"/chat/"&$FLR01&".txt",$FLR01&".txt")
               $guire=GUICtrlRead($Input1)
               $FLRNIK=FileReadLine("config.ini",2)
               $NIK_FULL="["&$FLRNIK&"] "
               FileWriteLine($FLR01&".txt",$NIK_FULL&$guire)
               _FTP_FilePut($FTP01,$FLR01&".txt","/chat/"&$FLR01&".txt")
               If Not @error Then
                  _FTP_Close($FTPOPP)
                  MsgBox(0,"Succes","Messagio inviato",1)
               Else
                  _FTP_Close($FTPOPP)
                  MsgBox(48,"Error","Prima di Inviare messaggi per favore si connetta ad una chat")
               EndIf
            EndIf
         Case $Button3
            $FTP=_FTP_Open("myftp")
            $FTP1=_FTP_Connect($FTP,"censured","censured","censured")
            If @error Then
               MsgBox(48,"Error","Server not connected!")
            EndIf
            $INP=InputBox("Chat Name","Please put the name of chat! Puplic chat: Paperon De Paperoni")
            If FileOpen("delta.tfs")=1 Then
               FileDelete("delta.tfs")
            Else
               _FileCreate("delta.tfs")
               FileWrite("delta.tfs",$INP)
            EndIf
            If @error Then
               MsgBox(48,"ErroR2","Error: The chat non exist or is problem with server!")
            Else
               _FTP_FileGet($FTP1,"/chat/"&$INP&".txt",$INP&".txt")
               If @error Then
                  MsgBox(48,"Error","Error to connect to chat")
               Else
                  $FLLT=_FileCountLines($INP&".txt")
                  $FRR0=$FLLT-0
                  $FRR1=$FLLT-1
                  $FRR2=$FLLT-2
                  $FRR3=$FLLT-3
                  $FRR4=$FLLT-4
                  $FRR5=$FLLT-5
                  $FRR6=$FLLT-6
                  $FRR7=$FLLT-7
                  $FRR8=$FLLT-8
                  $FRR9=$FLLT-9
                  $FRR10=$FLLT-10
                  $FRR11=$FLLT-11
                  $FRR12=$FLLT-12
                  $FRR13=$FLLT-13
                  $FRR14=$FLLT-14
                  $FLR014=FileReadLine($INP&".txt",$FRR14)
                  $FLR013=FileReadLine($INP&".txt",$FRR13)
                  $FLR012=FileReadLine($INP&".txt",$FRR12)
                  $FLR011=FileReadLine($INP&".txt",$FRR11)
                  $FLR010=FileReadLine($INP&".txt",$FRR10)
                  $FLR09=FileReadLine($INP&".txt",$FRR9)
                  $FLR08=FileReadLine($INP&".txt",$FRR8)
                  $FLR07=FileReadLine($INP&".txt",$FRR7)
                  $FLR06=FileReadLine($INP&".txt",$FRR6)
                  $FLR05=FileReadLine($INP&".txt",$FRR5)
                  $FLR04=FileReadLine($INP&".txt",$FRR4)
                  $FLR03=FileReadLine($INP&".txt",$FRR3)
                  $FLR02=FileReadLine($INP&".txt",$FRR2)
                  $FLR01=FileReadLine($INP&".txt",$FRR1)
                  $FLR00=FileReadLine($INP&".txt",$FRR0)
                  GUICtrlSetData($Edit1,StringFormat("[SOFTWARE] Load succesfull!\r\n[SOFTWARE] Last 15 messages:\r\n"&$FLR014&"\r\n"&$FLR013&"\r\n"&$FLR012&"\r\n"&$FLR011&"\r\n"&$FLR010&"\r\n"&$FLR09&"\r\n"&$FLR08&"\r\n"&$FLR07&"\r\n"&$FLR06&"\r\n"&$FLR05&"\r\n"&$FLR04&"\r\n"&$FLR03&"\r\n"&$FLR02&"\r\n"&$FLR01&"\r\n"&$FLR00))
                  _FTP_Close($FTP)
               EndIf
            EndIf
    EndSwitch
WEnd

;;;;;;;;;;;;;;;;                         ;;;;;;;;;;;;;;;;
;               END: Koda gui of software               ;
;;;;;;;;;;;;;;;;                         ;;;;;;;;;;;;;;;;

 

updater

 

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <FTPEx.au3>
#include <File.au3>
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Downloading update/downgrade", 364, 149, 302, 218)
$Label1 = GUICtrlCreateLabel("Downloading the new version of software....please wait....", 16, 24, 276, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


$FLR=filereadline("update.ini",2)
$FLR1=filereadline("data2.dat",2)
$WOP=_FTP_Open("update_ftp")
MsgBox(0,"","FTP Chat v"&$FLR)
$WOP1=_FTP_Connect($WOP,"censured","censured","censured")
FileDelete("FTP Chat v"&$FLR1&".exe")
_FTP_FileGet($WOP1,"/FTP Chat v"&$FLR&".exe","FTP Chat v"&$FLR&".exe")
If @error Then
   _FTP_Close($WOP)
   MsgBox(48,"Error","Error: Please re-start the updater"&@error)
   Exit
Else
   FileDelete("data2.ini")
   _FileCreate("data2.ini")
   FileWriteLine("data2.ini","[UPDATE_SOFTWARE]")
   FileWriteLine("data2.ini",$FLR)
   FileDelete("update.ini")
   MsgBox(64,"Success","The upgrade have ben succesfull instaled")
   _FTP_Close($WOP)
   GUIDelete($Form2)
endif

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

 

The file .rar contain the FTP Chat and the updater. Here is not the script , why is published here (FULL CODE except the password,host and nik of the server xD )

http://www.mediafire.com/download/c0311b751dr8mq0/DATA_Chat_2.zip

Features: (the version is base, only chat, no ban,no private message or more...)

-Auto Check Update

-Auto Update

-Infinite Room Chat (if the room chat is more than one mont is not used, will delete it.

-Infinite number of user in chat (not reccomanded)

How use it? Easy...

1) When You start for the first time You need to put a nikname (actual here is not a limit of "how long is the nik" , but please not use a nik long more tha 20 caracter...)  completed that , you will receive a message who your username is set and usable.

2) For connect a chat , you need to know the name of a chat (for a public chat use: Paperon'de Paperoni ) and press ok. If is connected to a chat the "edit" will change her data and will load the last 15 messages of that chat ;)

3) For send a message you need to writte the message on the "input" and click  "Send" (NP: The chat will not update (you need to click on "Update" to watch the message who you are written)) if is sended correctly , you will receive a message who remain only for 1 second (and her will disappear).

4) For Update the chat You Need to click the "Update" Button and stop :3 , if is NOT work correctly you will receive a message who is NOT update on the server and ONLY on local.

5) for create a chat room , go to menu>Create a Room and here need to put ONLY the name (for now , but i want to work on a room with password and more features :3 ) If work correctly you will receive a message who the chat is created and full working :D .

 

For now here is the all features of the software :D but i want to work for more much features and options. If anyone have a god idee to implement here please writte down ^^.

 

Edited by DSChaos

Share this post


Link to post
Share on other sites



Hi 

DSChaos

Tried your software but it didn't work.

1. Kept trying to download the updated software (from a blank FTP server)

2. Commented out the update fault and it's still failing

I eventually worked out that it just couldn't connect to my FTP server (Mine doesn't use port 21)

I don't have the time to go through your code and replace all the "_FTP_Connect" you have scatted through the code.

Could i suggest you make an open/connect function something like this

Func FTP_Open_Connect($sAgent, ByRef $hInternetSession, $sServerName, $sUsername, $sPassword, $iPassive = 0, $iServerPort = 21)
    $hInternetSession = _FTP_Open($sAgent)
    If @error Then
        MsgBox($MB_SYSTEMMODAL, '_FTP_Open', 'ERROR=' & @error)
        Return 0
    Else
        $hConn = _FTP_Connect($hInternetSession, $sServerName, $sUsername, $sPassword, $iPassive = 0, $iServerPort)
        If @error Then
            MsgBox($MB_SYSTEMMODAL, '_FTP_Connect', 'ERROR=' & @error)
            Return 0
        Else
            Return $hConn
        EndIf
    EndIf
EndFunc   ;==>FTP_Open_Connect

then you could call it like this

$FTPa = ""
$FTP1a = FTP_Open_Connect("my_FTPChat", $FTPa, $server, $UserName, $password)

_FTP_FileGet($FTP1a, "/chat/" & $INPe & ".txt", $INPe & ".txt")

_FTP_Close($FTPa)

But you need to add a lot more error check/control to your code.  Then test it to make sure it can handle things like the server being out of contact.

Check your update code.  It was trying to update when there was no server.  I should have got a "Server not connected" error or something similar.

Also with the update you appear to be deleting the main EXE before you know if you can download it's replacement.

If something fails in the download the user will be left with nothing.

Good work so far, just need to smooth off the rough edges

I'd love to hear/see an update.  Good Luck!

John

Share this post


Link to post
Share on other sites

I would like to see more of this. It creates endless opportunities. Custom Chat Platform - for office use etc

 


Skysnake

Why is the snake in the sky?

Share this post


Link to post
Share on other sites

hy storme , when i created this version of script , in that time the script are good working , but now is old. I will create a new script whit new function and much more efficient :D. Sorry if i response now , but i not every day here on forum xD

P.S this is only a base chat , don't have a ban system or anti-spam ;) . When i create  a new script i will post here :D .

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