I’ve been programming in many languages (incuding C) since 1979 but with no formal training. I’ve also used php a lot in web applications and I find SQL programming to be fun!. The only problem is that even with 41 years of experience I STILL SUCK AT PROGRAMMING!
That’s just to establish my skill level. I suck mostly because learning something is a lot of fun but then I get bored of it quickly (same with all my hobbies in truth).
One of the things I’ve always wanted to do was create a multiplayer game but never really understood networking programming well enough to progress beyond anything more than a simple chat server. So that brings me to UE5 (tried UE4 and I sucked at it).
I’ve been learning the basics for probably a year now (how to animate etc) and a few months ago progressed to trying to create a client/server system with a login system and mysql database. failed miserably several times and couldn’t figure out how to have people be in a lobby AND others playing in a MAP on just one server which seemed impossible since in one server you can only have ONE active map.
Then I stumbled across mentions of Online Beacons and they sounded like something I could use. started looking into those and thought C++ would be the only way and suddenly stumbled across the “BluePrintable Online Beacons” package in the marketplace which allows you to skip C++ and use them directly from Blueprints - super cheap too!
After quite a difficult start I finally figure them out (I thought they were much more complicated/difficult than they really are and that was why it was so hard for me). And now I have a way for players to be in a lobby (on their own clients) AND playing a game (in the server) and the lobby can chat with he game etc.
The marketplace item lists three basic beacons when in fact there is only one actual “Beacon” but you can make that beacon do what you want (chat/party/whatever) so they show three examples (I didn’t realize that for quite a while).
Now my system basically does
Client Side: Get server address from player (you have to manually add that, no way around it). Contact the server BEACON and ask for a games list (usually just one but it works with several servers at the same address too). Once it finds a game the client shows it with game name etc (whatever you want it to) and you have a button to query that game. If it is actually running it lets you “join” the server (which doesn’t actually “join”, it just fixates on that particular server) and shows a login screen. Fill it out and submit and the client sends the name/pass to the server.
Serverside:
1st step: BEACON receives a games list request and returns the name etc.
2nd step BEACON receives a login request containing name and password. It then calls a Custom Function in the GameInstance(GI) called Checklogin (runs on server only)
3rd step GI uses VARest subsystem to build a URL and fill fields then connects to it.
4th step APPSrv (or whatever webserver you use) parses everything then calls a php script.
5th step php talks to mysql, sends the name and password and returns true/false, If true they match, if false it didn’t.
6th step GI received the true/false. If false it returns a fail to the client then that simply ends. If True it generates an integer and adds that to an array in the SERVER - this is a code that says “If given this code it is a valid user”. After that it returns that integer to the client which stores it in the CLIENT GI as a single integer variable.
That’s the login validation!
The BEACON is now no longer used, only the SERVER GameMode and CLIENT PlayerController
On the client I connect to the game session (using command line “listen ”. In the CLIENT Player controller EventBeginplay I get the GameInstance and cast it to the one specified by the gamemode (probably best to specify replication to Runs on Owning Client). Then set the CODE integer in the player controller to that stored in the Client GI. Then connection is made to the server (using command line “listen ”.
The SERVER OnPostLogin event supplies the client player controller so cast that to the appropriate one and make sure the CODE is the one in the CODES Array on the server. If it isn’t then disconnect and if it is then carry on as per normal.
That’s it!
I really should figure out how to gracefully handle invalid codes but I am brain freezing now so I need a rest.
I would put this up somewhere for people to pick over but it contains non-free/closed source marketplace items so I don’t think I can.
This is the SERVER CustomEvent that uses VARest to talk to AppServ/Php/mysql - very simple really
And this is the php script for checking the login
<?php
require_once ("dbc.php");
$func = $_GET['func'];
$name = $_GET['name'];
$pass = $_GET['password'];
$result = 'false';
if ($func = "login") {
$sql = 'SELECT * FROM users WHERE username like ? && userpass = ?';
$stmt = $conn->prepare($sql);
$stmt->execute([$name, $pass]);
$users = $stmt->fetchAll();
if (!$users) {
$count = 0;
$result = 'false';
} else {
$count = count($users);
$result = 'true';
}
}
echo '{"Result":"' . $result . '"}';
?>
I know the real programmers are scratching their heads and wondering why I so proud of such a simple thing but hey, I AM DANGIT!