Affichage des articles dont le libellé est dedicated server. Afficher tous les articles
Affichage des articles dont le libellé est dedicated server. Afficher tous les articles

mercredi 28 décembre 2016

Dedicated Server packaging

Dedicated server packaging


I found that Url in the wiki : https://wiki.unrealengine.com/Dedicated_Server_Guide_(Windows_%26_Linux)

But I don't know it is outdated, or I have particular case, but following this, didn't success for me.
So I will give you my way to do, and few tricks, because some configuration steps are necessary and there is no place aggregating those informations.

In my game, I will have one server per map, because each map must be persistent, and is not upon a player.
So I have to generate one server per map.

Tricks & Settings


If you have already launched your game through commandLine like "ue4editor projectName mapName -server/-game", it is quite simple, because you give in parameters the name of your map.
So in your test, you can go map/through map just changing your command line parameters.

When you generate/package your game, it will fix these setting once per package.
First step, you will have to configure under the editor the maps & modes settings.
In these window, you precise which map the client will start with, and which map the server will start with.


Another trick is about package non ue4 files. I manage some configurations files, or data files (json files) in my game to store dialogs, missions, ..., and these files are open by C++ code.
So Ue4editor didn't consider them like assets. In consequence, when you package your game, those directory, and files are not packaging. so bad....
So go to your settings, packaging settings, I recommand to uncheck use pak file in a first time, because you will be happy to see the package content in the first time to validate its content.

Go down, to to Additionnal non assets directories to package, and browse to your directory to add it to your package.


You can refer to the wiki for other steps until unreal front cooking. I don't use unreal Front to package & prepare my game.
I use Ue4editor, through file->package project.

Packaged


At the end of the processus, you will have a directory "game" with WindowNoEditor, with two directories Engine, and yourGame.
Go through yourGame/Binaries/<platform>/ you must find a yourgame.exe, and yourgameserver.exe.
If you don't have your executable, maybe you forget to generate with visual studio (see the step in the wiki).
In certain case, you have to copy the binaries yourself, from your building directory, to your game package.

That's it. I recommand to through a shell script, or command line to launch with "-log" parameters to check that your server & games runs without problem.

I hope it will help people who want to manage dedicated server.

Thyshimrod

jeudi 9 juin 2016

Unity : networking part 1

In the way, to have a dedicated server, and client able to connect to it, you can use standard script from unity. One of them, draw a little hud, where you can choose to launch standalone server, a client, or client hosting server.

Another script is more usefull and manage all events upon network : NetworkManager.

For my purpose, I create my onw c# script, inheriting of networkmanager. I wish to override several events, and function, so it is the best way to do. Its name will be ShimNetworkManager.

As in any script, you have a start and update function. In the start function, I will start a server, or start a client.

When the scene will start, this script must be runned. For this, I will add in my scene, a simple GameObject. I will name it NetworkManager.
I will add as component, my newly ShimNetworkManager script.

For now, as you will launch the game, it will execute automatically this script. But how to know if I am a server, or a client?

From my mind, it will be a server, if the game is loading directly this scene.
If the load of the scene comes from an another scene, it is a player trying to connect to a client. It is my assumption.

Pass GameObject scene to scene


I spent lot of time on this question.
When you load a scene, you destroy the old one, and all object belonging to this scene, even those you have instantiated by a script.
Finally, I discover a trick that allow to pass scene to scene some GameObject. So, to know if this is a client that is loading the scene, I test the existence of this object.

I create a second scene, named authentificationLevel. In this scene, I create a GameObject named PlayerOverScene.
I create a c# script named playerScript which will contain in further articles, the information linked to user (name, id, ....).

To allow to an object to be not destroyed, when you change your scene, you have to code this :

void Awake()
    {
        DontDestroyOnLoad(transform.gameObject);
    }

This line of code save your life.

For now, in all scene you will go, this object will remain, and you have a good way to store game information (score, player information, server information,....).

Back to Networking : Client or Server

In ShimNetworkManager, I can test this PLayerOverScene Object to know if I have to run server or client.
public void Start()
    {
         GameObject playerOverScene = GameObject.Find("PlayerOverScene");
        if (playerOverScene == null)
        {
            bool result =this.StartServer();
        }else
        {
            this.StartClient();
        }   
}








dimanche 14 février 2016

Third Party server with UE4 : part 2 : C++ : include package

For now, we need C++ code.
I will not explain how ue manage class, path to includes, and so on. All is not very clear for me.
It seems that when you need to use "package", you have to include it in your build.cs.

Here it is a screenshot of filetree on my computer, of the engine source. In red the non exhaustive list of package under source/runtime.

We will need socket package, and networking, so in my build.cs

using UnrealBuildTool;

public class pocshim : ModuleRules
{
    public pocshim(TargetInfo Target)
    {
        PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore","Blu", "Networking", "Sockets","Json" });

    }
}






Third Party server with UE4 : part 1 : nodejs

I have discovered that ue4 is very good for certain purpose, but not good for others.
One of the point is that if you want to manage persistance, or if you want to have information you can dispatch to all players, you need to use a third party server for this (for chat purpose too for example, because you must know all players who are playing to the game).

I ve found piece of code to write a nodejs server. For the moment, it is the easiest way (if you know javascript of course) to write an external third party server. It is light, easy to write, and enough for my purpose.
This server will:
-- receive connection
-- receive TCP message
   -- receive login message
       -- check if the login/password are ok in database
       -- send a json to the sender by TCP message



var net = require('net');
var mysql = require('mysql');

var mySqlClient = mysql.createConnection({
  host     : "*****",
  user     : "****",
  password : "********",
  database : "*******"
});


// Keep track of the chat clients
var clients = [];

// Start a TCP Server
net.createServer(function (socket) {
   
  // Identify this client
  socket.name = socket.remoteAddress + ":" + socket.remotePort

  // Put this new client in the list
  clients.push(socket);

  // Send a nice welcome message and announce
  //~ socket.write("Welcome " + socket.name + "\n");
  broadcast(socket.name + " joined the chat\n", socket);

  // Handle incoming messages from clients.
  socket.on('data', function (data) {
    //broadcast(socket.name + "> " + data, socket);
      try{
        var val = JSON.parse(data);
        if (val.code == "1"){
            login(socket,val);
        }
      }catch(err){
            console.log("data received not in JSON format : "  + data  + "/////" + err);
      }
  });
    socket.on('error',function(){
        console.log('socket reset');
        clients.splice(clients.indexOf(socket), 1);
    });
  // Remove the client from the list when it leaves
  socket.on('end', function () {
    clients.splice(clients.indexOf(socket), 1);
    broadcast(socket.name + " left the chat.\n");
  });
 
  function login(sender,jsonObj){
      //~ console.log(jsonObj);
      var selectQuery = "SELECT * FROM table where name ='" + jsonObj.login + "' and passwd = '" + jsonObj.password +"'";
       var status=0;
        var sqlQuery = mySqlClient.query(selectQuery);
        sqlQuery.on("result", function(row) {

          status=1;
        });
       
        sqlQuery.on("end", function() {
            //~ if (status){
          //~ mySqlClient.end();
            //~ }
          sender.write('{"code":"1","status":"' + status + '"}');
        });
       
        sqlQuery.on("error", function(error) {
          console.log(error);
            sender.write('{"code":"1","status":"-1"}');
        });

  }
 
  // Send a message to all clients
  function broadcast(message, sender) {
    clients.forEach(function (client) {
      // Don't want to send it to sender
      if (client === sender) return;
      client.write(message);
    });
    // Log it to the server output too
    process.stdout.write(message)
  }

}).listen(5000);

// Put a friendly message on the terminal of the server.
console.log("Chat server running at port 5000\n");







 

vendredi 22 janvier 2016

ue4 multiple level zoning, and architecture

It is important to understand how ue4 works to make a multiplayer game.
A dedicated server runs only one level (physics, replication, ...).
You have multiple possibilities. If all your players are changing of zone at same time, and the zone is loaded only at this moment, your server can change zone, and load it, and the clients will do the same.
One server is enough

But if you wish to have several zone running at same time, you must keep in mind, that you must have one dedicated server per zone.
The client will connect to the server it needs at the moment it wants.
From my side, when client is launched, it is not connected. It shows a level with a tiny scene, and an UI to fill knickname, and a button to connect.
Once player clicks on connect, I send a connection to the first server using IP and port.
it is enough. Once connected, the server will send the level to load, and replicate actors which need to be replicated.

during game, maybe player wish to change zone, to travel elsewhere. I will disconnect to current server, probably load a temporary level, with tiny scene, to wait connection to other server, and then I will connect to a new IP/Port, to reach the new server hosting the level I want to travel to.
Once again, the server will send the name of level to load, and replicate what it needs.

Finally it is quite standard as an architecture, but you don't have choice, it is way to do.

I got a question on instantied zone. I think best way is to have a running server by instance too.

mercredi 6 janvier 2016

ue4 : networking day1

The aim of my game is to do a multiplayer game, with a dedicated server and clients.

It was sometimes hard to find my way, to understand networking in unreal engine, so I will try to take time to explain different things about networking, and to illustrate what I 've done in my game about the different topic.

If you need, more precise focus, let me know.

First of all, because it is dedicated server, server has control over all things. You have to draw blueprint in same blueprint for case of "server", and case of "client".

It is important to understand this. It is important also to understand what will be managed by server and replicated to client, and what is manage by client.

On client board, you will manage essentially UI, special effects, keyboard/mouse input management...
Server will manage AI, movement, physics, spawning, ...

So every time, you wish to move your pawn, through keyboard input, you will have to send the information to server, which will move the pawn, and replicate/broadcast new position.

Ok with this very few basics...

First, I will show you how to manage increase/decrease speed on my spaceship.
First I create new input in project settings








 Next in my pawn Blueprint, I create two variables, speed, and speedmax.
Speed will be replicated. It is an information needed by client to manage UI and FX for example.
Replication is always from server to client.



I ve created next a new custom event in my blueprint. The event receives the new speed, and set the variable with it.
Event must be run on server



 Finally, I receive my speed input (through A or W keyboard input), and I manage the increase of speed, and send it to server.





Pay Attention on switch authority. Switch authority allows to run what is after on server, or client. Here, because it is a client input, I have to manage following on client. So I choose remote.
If it was an event about collision for example, I must switch on authority, to manage it only on server.

If you don't use this switch, it will be run on both (client and server), and you can have strange behavior or maybe error. For example, if you manage to update an UI, on dedicated server, you will have errors, because there is no window for server.

Here, you will manage keyboard input to increase speed, and send the update to server.
Server will update speed variable, and because of that, the update will be replicated to all client.

To do better, you can send the input to server, which will manage the different test case, to be sure and guarantee no cheat :D