Code archives/Networking/Wrong Client Stopper

This code has been declared by its author to be Public Domain code.

Download source code

Wrong Client Stopper by Ked2006
Little piece of code to make sure that the clients you make are the only ones allowed to log in to the server.

So... make 40 different servers then give them a different name and add them to the file.
;SERVER PART;
Graphics 400,200,32,2
SetBuffer BackBuffer()
AppTitle "Server"

Global msg$,server,t,file,c_name$

server = CreateTCPServer(8080)     ;CREATE SERVER
If server=0 Then End

While Not KeyHit(1)     ;LOOP
Cls

t = AcceptTCPStream(server)

If t     ;CLIENT ASKING SERVER
     msg$=ReadLine(t)
     If msg$="Login to server"
          WriteLine t,"Client name?"
          msg$=ReadLine(t)
               file=ReadFile("Clients.txt")     ;OPEN FILE
               
               Repeat      ;LOOP 2
               c_name$=ReadLine(file)
               If Eof(file) then CloseFile(file):Exit
               Until c_name$=msg$
               
               If c_name$=msg$
                    WriteLine t,"Access Granted"
               Else
                    WriteLine t,"Access Denied"
               EndIf
          EndIf
     EndIf

Flip
Wend
End

;-THE .TXT FILE-;
;Create a simple .txt file. On the first line type "tneilc"
;without the quotes. Save the file with the name ;"Clients.txt", without the quotes.

;CLIENT PART;
Graphics 640,480,32,2
SetBuffer BackBuffer()
AppTitle "Client"

Global c,msg$,clientname$="tneilc"

c=OpenTCPStream("127.0.0.1",8080)
If c=0 Then End

Print "Connected"
Delay 50
Print "Asking to log in"
Delay 100

WriteLine c,"Login to server"
msg$=ReadLine(c)
Print msg$
WriteLine c,clientname$
msg$=ReadLine(c)
Print msg$

WaitKey()
End

Comments

Siopses2007
Didn't work for me.


Code Archives Forum