Since I've finally gotten QB64 up and going for myself with TCP/IP connecting across the internet, I thought I'd go ahead and use it to create a semi-permanent server which could be used as a means to facilitate online games, high score lists, chat sessions, and other such things...
The concept here is rather simple:
1) I host a server and try and keep it up and running 24/7 on an old PC in my basement. Warning, it might be laggy and slow, but it works. It's a PITA to use Anti-Virus Protection and Firewalls with open ports, so I prefer if the PC which I'm going to use for this experiment remains independent from the rest of my network, contains no useful information, and is just a bare bones box which I don't have to worry about hackers destroying on me. This server is going to be old, slow, and patience might be needed when accessing it -- but it'll be 100% FREE!! (Unless you guys run up tons of bandwidth usage with it, in which case I might ask for donations to help keep it up and going...)
2)This server will be available for the public to make use of. If you have a game which you want to use with online communications, you're welcome to connect through this server. I'll explain the process behind it, as development goes along.
At the moment, the steps look like the following, but they're open for any and all changes as development occurs:
- You have to connect to the server.
- You user will need to [REGISTER] their chosen name and password. (Names are unique, with only one account allowed for all Steve Server services.)
- Users will need to [LOG IN] to send/receive data using the server.
- Your program will need to respond to [PING][PONG] requests if you plan to stay connected for more than a minute.
- Data needs to be sent to the server following the proper format to be read. This basically consists of "[COMMAND]text", so something like "[REGISTER]SMcNeill,password" would be the command for a new user to register and store a password.
For games, commands would look like:
"[SET GAME]My Game's Name" -- this would set the game which you want to talk to the server about. Only one game can be set at a time, without erroring out.
"[CREATE GAME]User Name #1, User Name #2" -- this would create a game between user1 and user2, and save their moves/chat/history in it's own file on the server's drive.
"[JOIN GAME]User Name #1, User Name #2 -- this is going to allow people to rejoin old games in progress.
"[CHAT GAME]..." -- command to send chat back and forth between the players in the games.
"[CLOSE GAME]...." -- this will close the game and mark it from ACTIVE to FINISHED.
Programs should be able to send and receive basic text, following the sample syntax above to communicate and share information across the server. Large Massively-Multiplayer Games aren't going to be usable (at least not initially) with this concept, but games between limited opponents will be. For now, I'm building it for 2 players, but it should be easy enough to expand to "[CREATE GAME]Player1, Player2, Player3, Player4, Player5, Player6" if necessary, in the future.
A demo of what the bare minimum a client should have (so far) is about this much:
'Messages which we transfer of importance.
'[Connection Successful]
'[OK]
'[ERROR]
CONST DefaultPort$
= "7200" CONST True
= -1, False
= 0
Client = ConnectAsClient(DefaultPort, "localhost")
Send Client, junk$, False
Receive Client, what$
count = count + 1
temp
= _OPENCLIENT("TCP/IP:" + Port$
+ ":" + IP$
) 'attempt to join as client IF Verbose
THEN PRINT "Cannot connect to Host. Terminating program." ConnectAsClient = temp
SUB Send
(Who
, What$
, GetConfirmation
) attempt = attempt + 1
IF GetConfirmation
= False
THEN l
= -l
PUT #Who
, , l
'send the length PUT #Who
, , What$
'send the data l = CheckSum(What$) 'send a checksum to make certain the data we sent was recieved properly
count = count + 1
IF a$
<> "" THEN result$
= result$
+ a$
IF count
> 50 THEN result$
= "[ERROR]" IF Verbose
THEN PRINT "Error sending data. Trying again ("; attempt;
" of 5)." IF Verbose
THEN PRINT "Cannot Send Data. Terminating connection.]"
IF a$
<> "" THEN What$
= What$
+ a$
IF l
> 0 THEN 'the sender wants confirmation that the data received matches what we sent. count = 0
count = count + 1
IF a$
<> "" THEN What$
= What$
+ a$
IF count
> 30 THEN 'If we can't get the last 4 bytes in 3 seconds, we probably screwed up somewhere. 'Send a failure notice back to the user. We can't verify the data without a checksum, and that's
'what the last 4 bytes should be.
Send Who, "[ERROR]", False
What$ = "" 'don't return any value for what$. It wasn't properly received.
'at this point, we should have the data and the 4 digit checksum.
IF c
= CheckSum
(What$
) THEN 'we can confirm it. Send Who, "[OK]", False 'let them know we got the proper data
Send Who, "[ERROR]", False 'let them know we got the proper data
What$ = ""
'And if we've fallen through all the possible IF conditions, we're done!
CheckSum
= CheckSum
+ ASC(What$
, i
)
The first working games which I plan to add to this service will be Checkers and then Chess. The plan isn't to require the players to be active 24/7, but to be able to play at their own pace. Player one makes a move, types a little text to start a conversation with, the server stores that information. Player two logs in, sees that information, they can make their move, respond to the chatting, then log out... Rinse and repeat until the game is won.
If both players can only log in once every few hours, a game of Chess/Checkers might take several days to complete. If both are logged in at the same time, then they could almost play in "real time" against each other.
The idea is in its infancy, with a lot of work left to go before it'll be up and running completely. There's a lot more work required on the host side than it is on the client side, as the host has to read and parse commands, decipher what to do with them, store and retrieve data from files which it's saving on the hard drive, and then send it all back to the initial user (or toss error messages to them, in case of failure along the way), but I'm getting there with it.
At this point, the server is up and running (when I click it on to test it), and I can register and log in and out test accounts. Text can be shared publicly, as per a chat program, and -- when necessary -- data can be verified when sent back and forth between the host and clients (such as when I might want to do a file transfer across the net).
I just need to finalize my game communication protocol/syntax, and teach it how to respond to various different requests, and a prototype version of the server will be available for the public to connect to and play with...
I simply thought I'd mention the concept a little early, in case anybody else out there might be interested in making use of it's services. Storing things like highscore lists and retrieving them should be simple as heck ("create game, join game, send list, receive list, leave game" type commands are all that would need to be implemented), and once those simple lists are working, storing information of games between two (or more) players shouldn't be very far behind...
So, if you're interested guys, feel free to start working on your own games anytime you want. Just remember, players would need to:
1) Register
2) Log In
3) Create or Join a Game
4) Send properly formatted text
5) Be able to parse the properly formatted responses.