Step 1.1 is done. If a moderator could change name of thread (just get rid of "need help!" that would be appreciated.
Change log:
* Users can now create accounts and log into them. (Cannot do both with same log in)
* Implemented Fast Len, which requires IanM's plugin. Len is a suitable replacement.
* Implemented Compare, which requires IanM's Plugin. Password$ = ActualPassword$ is a suitable replacement.
* Implemented Open Datafile to Write, Write Datafile String, and Close Datafile. I'm not sure if Open to Write is a valid substitute.
* Implemented Text Fields, which requires BBB Gui plugin. Input fields can work with modification.
* Got a DDNS for the project. All users can log into one account. Please!
* Commented all the work, thus far.
Attached is:
// Client
* Client_LogIn.dba
* BBBGUI_Constants.dba // so you won't forget
* USkin.dll // Needed for exe with BBB GUI
// Server
* Server_LogIn.dba
// Application
* Client.exe // Server isn't dedicated, so it may be offline
Server Side:
// Makes things work... Just used the cube world example for the constants
#constant OP_NEWPLAYER 0
#constant OP_LEFTPLAYER 1
// Set the port to something open and forwarded on router
LocalPort = 2525
// Set the IP to localhost
LocalIP$ = ""
// Max Simotaneous Clients
MaxClients = 50
// Makes things work... Just used the cube world example
UDPMode = 1
// DarkNet automatically will use all cores for processing data... VERY cool
NoThreads = 0
NoInstances = 1
// Packets we need
SendPacket = mn create packet()
RecvPacket = mn create packet()
// Arbitraily large packet size
mn set memory size SendPacket,1024
// Start DarkNet, Set to Localhost, and Start the server
mn Start NoInstances,NoThreads
mn Set Local 0,LocalIP$,LocalPort,LocalIP$,LocalPort
Result = mn Start Server(0, MaxClients,0,UDPMode)
// Trouble Shooting
if Result = 0
print "Server started"
print
print "Server local TCP port: "
print mn Get Local Port TCP(0)
print "Server local UDP port: "
print mn Get Local Port UDP(0)
else
print "Server failed to start"
Wait Key
end
endif
// Main Loop. Must be running prior to new incoming clients
do
// Detect new client
Joined = mn Client Joined(0)
if Joined > 0
print "A new client has joined with a client ID of ";
print Joined
print " Client TCP IP is: ";
print mn Get Client IP TCP(0, Joined)
print " Client TCP port is: ";
print mn Get Client Port TCP(0, Joined)
print " Client UDP IP is: ";
print mn Get Client IP UDP(0, Joined)
print " Client UDP port is: ";
print mn Get Client Port UDP(0, Joined)
Client as integer
for Client = 1 to MaxClients
if mn Client Connected(0, Client) = 1
if Client <> Joined
mn Add Int SendPacket,OP_NEWPLAYER
mn Add Int SendPacket,Client
mn Send TCP 0,SendPacket,Joined,0,0
endif
endif
next Client
mn Add Int SendPacket, OP_NEWPLAYER
mn Add Int SendPacket, Joined
mn Send TCP All 0,SendPacket,0,0,Joined
endif
// detect client leaving
Left = mn Client Left(0)
if Left > 0
print "Client ";
print str$(Left);
print " has disconnected"
mn Add Int SendPacket,OP_LEFTPLAYER
mn Add Int SendPacket,Left
mn Send TCP All 0,SendPacket,0,0,Left
endif
// Actual Login Stuff
for Client = 1 to maxclients
TCPPackets = mn Recv TCP(0, RecvPacket,Client)
if TCPPackets > 0
// Packet taken apart the same way the client makes it
Login$ = mn Get String (RecvPacket, 0, 1)
// Much easier than having a fourth value for the next account data
Username$ = "Users/" + mn Get String (RecvPacket, 0, 1) + ".txt"
// Not yet secure
Password$ = mn Get String (RecvPacket, 0, 1)
Print Login$
Print Username$
Print Password$
// If loging in
if Login$ = "Y"
// Accurate Error Handeling
if file exist (Username$) = 1
Open To Read 1, Username$
Read String 1, ActualPassword$
Close File 1
// Can be replaced by Password$ = ActualPassword$
if Compare(Password$,ActualPassword$) = 0
ReturnPacket$ = "Successful Login"
Length = fast len(ReturnPacket$)
Else
ReturnPacket$ = "Password does not match."
Length = fast len(ReturnPacket$)
EndIf
Else
ReturnPacket$ = "Username does not exist."
Length = fast len(ReturnPacket$)
EndIf
EndIf
// If creating an account
if Login$ = "N"
// More Error Handeling
if file exist (Username$) = 0
Make File Username$
// Open to Write wasn't working for myself. This command uses IanM's plugin... you can try Open to Write if you want.
Open Datafile to Write 1, Username$
Write Datafile String 1, Password$
Close Datafile 1
ReturnPacket$ = "Account made Successfully."
Length = fast len(ReturnPacket$)
Else
ReturnPacket$ = "Username already exists."
Length = fast len(ReturnPacket$)
EndIf
EndIf
// Because I didn't want to copy and paste this 5 times. Return to client
mn Add String SendPacket, ReturnPacket$, Length, 1
mn Send TCP 0, SendPacket, Client, 0, 1
EndIf
Next Client
loop
Client Side:
// Because it looks better
start bbb gui "Media\Ruby.msstyles"
// Set our window for BBB
dbpro_w=get dbpro window() : set main window dbpro_w
// Setup Packets
RecvPacket = mn Create Packet()
SendPacket = mn Create Packet()
mn set memory size SendPacket, 1024
// Start up DarkNet, 1 Instance, All Cores
mn Start 1, 0
// Get IP Address
IPAddress$ = mn DNS("csmith.servegame.com")
// Set to open port from server
PortNumber = 2525
// Connect
mn Connect 0, IPAddress$, PortNumber, IPAddress$, PortNumber, 5, 1
// Get ID from handshaking
ClientID = mn Get Client ID (0)
// Because I haven't made buttons yet.
Input "1 to Log in 2 to Create an Account", option
cls
// Sets up to login or create account
If option = 1
Login$ = "Y"
Else
Login$ = "N"
EndIf
// Make Editboxes for username and password.
UsernameLabel = make label(0,20,150,20,"Email",dbpro_w)
UsernameEditbox = make editbox(0,45,150,20,ES_AUTOHSCROLL,dbpro_w)
If option = 2 then text 160,70, "Please don't use you're Email account's password. Files are not encrypted!"
PasswordLabel = make label(0,70,150,20,"Password",dbpro_w)
PasswordEditbox = make editbox(0,95,150,20,ES_PASSWORD,dbpro_w)
// Make a submit button
LoginButton = make button (0, 120, 150, 20, "Log in", dbpro_w)
window set property LoginButton, "id", "1"
// Check for submit button being pressed
Repeat
get event
h=event get handle()
m=event get message()
if h=get main window()
if m=WM_CLOSE
end bbb gui : end
endif
endif
// Once pressed call the end of the loop
if button clicked(LoginButton) = 1
//Data for Packet
Username$ = Window Get Text (UsernameEditbox)
Password$ = Window Get Text (PasswordEditbox)
SendData = 1
Endif
Until SendData = 1
// Get Lengths of Username and password
PasswordLength = fast len(Password$)
UsernameLength = fast len(Username$)
// Length of Login is alread known
mn add string SendPacket, Login$, 1, 1
mn add string SendPacket, Username$, UsernameLength, 1
mn add string SendPacket, Password$, PasswordLength, 1
// Send
mn Send TCP 0, SendPacket, ClientID, 0, 1
Do
get event
h=event get handle()
m=event get message()
if h=get main window()
if m=WM_CLOSE
end bbb gui : end
endif
endif
// Recieve Feedback from server
TCPPackets = mn Recv TCP(0, RecvPacket, ClientID)
if TCPPackets > 0
Returned$ = mn Get String (RecvPacket, 0, 1)
Print Returned$
EndIf
Loop
If at first you dont succeed, LOWER YOUR STANDARDS.