Jump to content

Internet-Café Server-Client


Xenobiologist
 Share

Recommended Posts

Hi,

BeZ tried to script an application for "InternetCafé", you know the little rooms in hotels where you can spend some time surfing and have to pay a huge amount of money. :nuke:

I tried it, too. It is not ready, but I'd like to post it already to see whether there are some people who like it and want to see it 100% done.

The Server:

; Internet-Café  Server
#include <GUIConstants.au3>
#include <File.au3>
#include <Array.au3>

;variables
Global $ip = @IPAddress1
Global $MainSocket, $ConnectedSocket = -1
Global $port = 33891

$dollarPerHour = "3.00"
$dollarPerSec = $dollarPerHour / 3600
$procentTax = "2.00"

$timerStatus = "Off"
Dim $update = 5
Dim $time

; Server für Internet-Café

$GUI = GUICreate("Internet-Café Server : " & @IPAddress1 & "                                                (c) Th.Meger", 622, 441, 192, 125)
$admin_G = GUICtrlCreateGroup("Admin-GUI", 8, 48, 593, 153)
GUICtrlCreateLabel("Hostname", 16, 64, 187, 17, $SS_SUNKEN)
GUICtrlCreateLabel("Price / hour", 16, 88, 187, 17, $SS_SUNKEN)
GUICtrlCreateLabel("Tax", 16, 112, 187, 17, $SS_SUNKEN)
GUICtrlCreateLabel("First name", 16, 136, 187, 17, $SS_SUNKEN)
GUICtrlCreateLabel("Last name", 16, 160, 187, 17, $SS_SUNKEN)

$hostname_L = GUICtrlCreateLabel("Hostname", 216, 64, 187, 17, $SS_SUNKEN)
$pricePerHour_I = GUICtrlCreateInput($dollarPerHour, 216, 88, 187, 17, $SS_SUNKEN)
$tax_I = GUICtrlCreateInput($procentTax, 216, 112, 187, 17, $SS_SUNKEN)
$firstName_L = GUICtrlCreateLabel("First name", 216, 136, 187, 17, $SS_SUNKEN)
$lastName_L = GUICtrlCreateLabel("Last name", 216, 160, 187, 17, $SS_SUNKEN)

$cd = GUICtrlCreateButton("Open/close CD-ROM", 420, 64, 157, 17)
$sendMessage = GUICtrlCreateButton("Send Message", 420, 88, 157, 17)
$browser = GUICtrlCreateButton("Open Browser", 420, 112, 157, 17)
$mouse = GUICtrlCreateButton("Start/Stop Mouse", 420, 136, 157, 17)
$block = GUICtrlCreateButton("Block/Unblock", 420, 160, 157, 17)

GUICtrlCreateGroup("", -99, -99, 1, 1)
$time_G = GUICtrlCreateGroup("Time", 8, 208, 593, 57)
GUICtrlCreateLabel("Online :", 16, 232, 187, 17, $SS_SUNKEN)

$time_L = GUICtrlCreateLabel("00:00:00", 216, 232, 347, 17, $SS_SUNKEN + $SS_CENTER)

GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateLabel("Administrator Console", 16, 8, 587, 33)
GUICtrlSetFont(-1, 18, 700, 4, "Times New Roman")
$startStop_G = GUICtrlCreateGroup("Start/Stop Menu", 8, 272, 153, 137)

$start_B = GUICtrlCreateButton("Start", 24, 296, 123, 25)
$stop_B = GUICtrlCreateButton("Stop", 24, 336, 123, 25)

GUICtrlCreateGroup("", -99, -99, 1, 1)
$bill_G = GUICtrlCreateGroup("Bill", 184, 280, 417, 129)
GUICtrlCreateLabel("Price Online", 192, 304, 150, 17, $SS_SUNKEN)
GUICtrlCreateLabel("Tax", 192, 328, 150, 17, $SS_SUNKEN)
GUICtrlCreateLabel("Total Price", 192, 352, 150, 17, $SS_SUNKEN)

$priceOnline_L = GUICtrlCreateLabel("0.00", 392, 304, 150, 17, $SS_SUNKEN + $SS_CENTER)
$tax_L2 = GUICtrlCreateLabel("0.00", 392, 328, 150, 17, $SS_SUNKEN + $SS_CENTER)
$totalPrice_L = GUICtrlCreateLabel("0.00", 392, 352, 150, 17, $SS_SUNKEN + $SS_CENTER)
GUICtrlSetColor(-1, 0xFF0000)

$exit_B = GUICtrlCreateButton("Exit", 512, 376, 75, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$status_L = GUICtrlCreateLabel("Status", 8, 416, 593, 17, $SS_SUNKEN)
GUISetState(@SW_SHOW)

;==============================================
TCPStartup()
; Create a Listening "SOCKET"
;==============================================
$MainSocket = TCPListen($ip, $port, 100)
If $MainSocket = -1 Then Exit
Global $RogueSocket = -1

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $start_B
            If $timerStatus = 'Off' Then
                $Timer = TimerInit()
                GUICtrlSetData($status_L, "Timer started")
                _FileWriteLog(@ScriptDir & '\ServerLog.log', "Timer started")
                If $ConnectedSocket > - 1 Then
                    $ret = TCPSend($ConnectedSocket, "Start") ; HIER WAS ICH SENDEN WILL!!!
                    If @error Then
                        ; ERROR OCCURRED, CLOSE SOCKET AND RESET ConnectedSocket to -1
                        ;----------------------------------------------------------------
                        TCPCloseSocket($ConnectedSocket)
                        $ConnectedSocket = -1
                    ElseIf $ret > 0 Then
                        ; UPDATE EDIT CONTROL WITH DATA WE SENT ; Erfolgreich gesendet (FileWriteLog(gesendeter Text)
                        ;----------------------------------------------------------------
                        _FileWriteLog(@ScriptDir & '\ServerLog.log', $ret)
                    EndIf
                EndIf
            Else
                GUICtrlSetData($status_L, "Timer already started, please stop it first")
            EndIf
        Case $msg = $stop_B
            GUICtrlSetData($status_L, "Timer stopped")
            _FileWriteLog(@ScriptDir & '\ServerLog.log', "Timer stopped")
            _FileWriteLog(@ScriptDir & '\ServerLog.log', GUICtrlRead($totalPrice_L))
            $timerStatus = 'Off'
            If $ConnectedSocket > - 1 Then
                $ret = TCPSend($ConnectedSocket, "Stop" & GUICtrlRead($totalPrice_L)) ; HIER WAS ICH SENDEN WILL!!!
                If @error Then
                    ; ERROR OCCURRED, CLOSE SOCKET AND RESET ConnectedSocket to -1
                    ;----------------------------------------------------------------
                    TCPCloseSocket($ConnectedSocket)
                    $ConnectedSocket = -1
                EndIf
            EndIf
        Case $msg = $exit_B
            _FileWriteLog(@ScriptDir & '\ServerLog.log', "Console closed")
            Exit (0)
        Case $msg = $cd
            TCPSend($ConnectedSocket, "CD")
        Case $msg = $browser
            TCPSend($ConnectedSocket, "BROWSER")
        Case $msg = $sendMessage
            $text = InputBox("Send a message", "Message: ")
            TCPSend($ConnectedSocket, "MESSAGE"&$text)
        Case $msg = $mouse
            TCPSend($ConnectedSocket, "MOUSE")
        Case $msg = $block
            TCPSend($ConnectedSocket, "BLOCK")
    EndSelect
    
    If $RogueSocket > 0 Then
        $recv = TCPRecv($RogueSocket, 512)
        If Not @error Then
            TCPCloseSocket($RogueSocket)
            $RogueSocket = -1
        EndIf
    EndIf
    
    ; If no connection look for one
    ;--------------------
    If $ConnectedSocket = -1 Then
        $ConnectedSocket = TCPAccept($MainSocket)       
        ; If connected try to read some data
        ;--------------------
    Else
        $recv = TCPRecv($ConnectedSocket, 512)
        If $recv <> "" And $recv <> "~~bye" Then
            ; DATA WE RECEIVED
            ;----------------------------------------------------------------
            ;   ['', @ComputerName, @IPAddress1, GUICtrlRead($fname), GUICtrlRead($lname) ]
            If StringLeft($recv, 7) = "MYARRAY" Then
                _FileWriteLog(@ScriptDir & '\ServerLog.log', "Startup Data received")
                Dim $SendedAarray = StringSplit(StringTrimLeft($recv, 7), '|')
                ;_ArrayDisplay($SendedAarray, "SendedArray")
                GUICtrlSetData($hostname_L, $SendedAarray[1] & @TAB & " IP : " & $SendedAarray[2])
                GUICtrlSetData($firstName_L, $SendedAarray[3])
                GUICtrlSetData($lastName_L, $SendedAarray[4])
            EndIf
            If $recv = "Started" Then $timerStatus = 'On'
            _FileWriteLog(@ScriptDir & '\' & @YEAR & "_" & @MON & "_" & @MDAY & '_ReceivedData' & '.log', $recv)
            ; Update der Labels hier                                                      !!!!!!!!!!!!!!!
            
        ElseIf @error Or $recv = "~~bye" Then
            _FileWriteLog(@ScriptDir & '\ServerLog.log', "Error occurred - closed")
            ; ERROR OCCURRED, CLOSE SOCKET AND RESET ConnectedSocket to -1
            ;----------------------------------------------------------------
            TCPCloseSocket($ConnectedSocket)
            $ConnectedSocket = -1
        EndIf
    EndIf
    If $update > 5 Then
        If $timerStatus = 'On' Then
            $time = (TimerDiff($Timer) / 1000)
            GUICtrlSetData($time_L, StringFormat("%.02d" & ":" & "%.02d" & ":" & "%.02d", _
                    Mod($time / 3600, 24), Mod(($time / 60), 60), Mod($time, 60)))
            _calc()
            $update = 0
        EndIf
    EndIf
    $update += 1
WEnd

Func _calc()
    GUICtrlSetData($priceOnline_L, StringFormat("%.3f", $dollarPerSec * $time))
    GUICtrlSetData($tax_L2, GUICtrlRead($tax_I))
    GUICtrlSetData($totalPrice_L, StringFormat("%.2f", GUICtrlRead($priceOnline_L) + GUICtrlRead($tax_I)))
EndFunc   ;==>_calc

Func OnAutoItExit()
    ;ON SCRIPT EXIT close opened sockets and shutdown TCP service
    ;----------------------------------------------------------------------
    If $RogueSocket > - 1 Then
        TCPSend($RogueSocket, "~~bye")
        Sleep(2000)
        TCPRecv($RogueSocket, 512)
        TCPCloseSocket($RogueSocket)
    EndIf
    TCPCloseSocket($MainSocket)
    TCPShutdown()
EndFunc   ;==>OnAutoItExit
oÝ÷ ÙÊ%¢ºM4ÒÊZËr

Two icons attached. (connected / disconnected) client

So long,

Mega :P

icons.zip

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Cool, seems better than mine lol. Only thing is you shouldn't incude taxes because they change sometimes and also they are not a round number (something like 1.13912398471293 here lol). When you punch a price in the cash register it calculates the total amount. If the client sees for exemple 1$ with no +taxes they will think a dollars and not one cent more. So if the client gives me 1$, and in the cash register I punch 1$, I will need to put 1.14$ in the cash register. So im loosing 0.14$ wich seem little but it's with cents that you make dollars. Anyway removing that part shouldn't be hard to me. I guess I'll modify the guy so we can have our logo and open hours :nuke:. As soon as the store close I'll try this. But this is my last day of work so if I have a lot little things to change I guess I'll just stick with mine and take that one when I will come work again. Mine has a problem tho I'll go post this right now in the support forum. Thanks for the script I really want to test this tonight. We increased our price to 4$/hour today and it's cool you made it easy to change (no need to calculate it like mine). But when I look at the script I see nothing wich make the price have a minimum value. If someone come in and go on the internet only for a minute i dotn want to charge him like 0.07$ + taxes loll. Minimum price would be a nice add to the option on the top of the script :P. making an .ini file would be could so I can change these values without having to go in the script.

Thanks for the script and I got to go now, last day of work.

BeZ

EDIT: We're not an internet cafe :). We have a commerce and we work 12-14hours a day for almost nothing because my father wants to compete with the bigger one here like staples and future shop... Only problem is we are in a village with something like 250 person living here loll and the average age of people here is in the 60...

Edited by BeZ
Link to comment
Share on other sites

Hi,

thanks for testing.

Tax is included, cause you wrote you need it. :P I will change it to one-time charge.

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • 6 months later...
Link to comment
Share on other sites

Nice work, although it is very limited because you can only run 1 client.

Link to comment
Share on other sites

Hi,

I guess it should be no problem to do this with 5 computers.

But I only did this for fun, cause there are already tools like VNC. Should be hard, but write an better Autoit script than VNC or NetOp.

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • 1 year later...

I didn't look at this in detail.

But if it was for a small number of clients, like you said 5 Ed.

You could just run 5 instances of the server one one machine, each with a different port

And configure each client with the corresponding port.

Kenny

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

err...superbump?

:) Any questions concerning this old thread?

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

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...