Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backend server for Unity3D MMORPG

I am developing a basic MMORPG using Unity engine. I need a simple solution (library, framework) to make an efficient server. What is the best way to accomplish this task?

like image 902
Max Larionov Avatar asked Dec 31 '15 06:12

Max Larionov


1 Answers

Original post is here.

  1. You might try SmartFox, this link might be a good start for you. Below tutorials are also helpful for a quick start:

    • Using SmartFox with C# (I) : Installations and 1st handshaking
    • Using SmartFox with C# (II) : Login and join room
    • Using SmartFox with C# (III) : Frequently used functions

Specifically, you can connect to the smartfox server and get notified on connection:

private SmartFox client;
private string serverIP = "127.0.0.1";
private int serverPort = 9933;  
private string zone = "BasicExamples";

client = new SmartFox();           
client.ThreadSafeMode = false; //true for Unity3D
client.AddEventListener(SFSEvent.CONNECTION, (evt) =>
        {
            bool bSuccess = (bool)evt.Params[“success”];
            Console.WriteLine(client.IsConnected ?
                “Successfully connected to SmartFox Server” :
                “Failed to connect to SmartFox Server”);
        });           
client.Connect(serverIP, serverPort);            

To Login and get hooked when login succeeds:

var request = new LoginRequest("UserName", "Password", zone);  //[1]
client.Send(request);                                          //[2]

client.AddEventListener(SFSEvent.LOGIN, (evt) => {             //[3]
            Console.WriteLine("The User login success");       
});

client.Connect(serverIP, serverPort);   

2. Photon is another popular backend server/service.

Photon Server provides you with turnkey frameworks for multiplayer games. Start from scratch or build your own custom logic on top of several demo applications included in source code with the free server SDKs. This lets you achieve great results fast and easy.

Code snippet for setup connection:

using UnityEngine;

public class RandomMatchmaker : MonoBehaviour
{
    void Start() {
        PhotonNetwork.ConnectUsingSettings("0.1");
    }

    void OnGUI(){
       GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
    }
} 

Code snippet for join room/lobby:

public override void OnJoinedLobby()
{
    PhotonNetwork.JoinRandomRoom();
}

Code snippet for setup logging:

PhotonNetwork.logLevel = PhotonLogLevel.Full;

Code snippet for error handling:

void OnPhotonRandomJoinFailed()
{
    Debug.Log("Can't join random room!");
    PhotonNetwork.CreateRoom(null);
}

A good tutorial on this topic can be found here.


3. Firebase might be the 3rd choice, though the performance is arguably unclear.

  • As an example, in roll20.net, you might find MMO game powered by Firbase.
  • Among others, FireSharp might be a very useful open source project for your quick start.

4. Others (OpenSpace, RedDwarf, ElectroServer, Player.IO, Red5, Mesmotronic Multiuser Server etc.)

See this great post for details.

like image 94
David Avatar answered Sep 21 '22 10:09

David