Fully Authoritative Server in Unity3D

Options
storm33229
edited August 2013 in Photon Server
I need some help understanding how Photon integrates into Unity3D, because I just read through this blog post: http://www.pepwuper.com/unity3d-multipl ... omparison/

The claim seems to be the Photon does not provide a simple solution to creating a Unity3D integrated fully-authoritative server. This seems to have been written back in Nov. 2011, so a lot could have changed (or maybe the claim was false).

One of the points brought up is, and I quote:
Photon server application is not aware of Unity geometry, physics and the collision system, which means we would need to recreate all those parts on the server side. This is a difficult task and what’s more important, prevents us from re-using Unity’s built-in features. That is why we used the semi-authoritative approach.

And subsequently:
Synchronizing NPCs gave us a bit of a headache. When synchronizing players, it is clear who is the owner. The player is the owner and the player is responsible for updating its own position. With NPCs, the server should be the owner, but Photon server can’t be the owner because it doesn’t know how to move NPCs. Photon server is not aware of Unity geometry and collisions. Thus, we need to move NPC ownership to one of the players. The server assigns ownership to one of the players who becomes a master client. This also requires logic for shifting ownership to another player in case the master client loses connection, which brings all kinds of synchronization problems.

I would like to get the real scoop from you guys. Does Photon integrate nicely with Unity3D - even in the aforementioned areas?

Comments

  • check out http://u3d.as/content/exit-games/photon ... g-free/2ey

    This tool suppose to port 90% of Unity networking code to be honest I never used it. You can even try the Photon Cloud option it is also easier compared to the server model. I personally prefer writing my own custom authoritative server(using the socketserver), main reason being much faster than any other options and gives me full control over what I want, especially if you are creating an MMO I'd definitely go for the custom server approach. The tradeoff being that you have to write all server logic by yourself, including physics, collision, state sync, and movement. However, I have succeeded in most of it in a Multiplayer RPG(small scale MMO) that I am creating except for the collision part which is what I am still working on. It is hard but the outcome is great :)
  • check out http://u3d.as/content/exit-games/photon ... g-free/2ey

    This tool suppose to port 90% of Unity networking code to be honest I never used it. You can even try the Photon Cloud option it is also easier compared to the server model. I personally prefer writing my own custom authoritative server(using the socketserver), main reason being much faster than any other options and gives me full control over what I want, especially if you are creating an MMO I'd definitely go for the custom server approach. The tradeoff being that you have to write all server logic by yourself, including physics, collision, state sync, and movement. However, I have succeeded in most of it in a Multiplayer RPG(small scale MMO) that I am creating except for the collision part which is what I am still working on. It is hard but the outcome is great :)

    If I choose to use Photon for my project, I would definitely be using the Photon SocketServer. I am not sure that I want to handle all of the physics/collision myself (not my area of expertise). I would prefer that I be able to leverage Unity3D to do this; that would be ideal.
  • Your subject states, "Fully Authoritative Server" it will break the definition of authoritative server if you choose to handle them inside the client. You can never trust the client with stuffs important as these most importantly collision. The client can tell the server that there is nothing in between the player and an object but clearly there is a cave or mountain. This is cheating and not fair for other players and you will end up loosing players because of unfairness. By the way you do not have to handle physics or collision all by yourself. There are libraries available which you can use, for ex. Nvidia's PhysX(which is also what Unity uses) or DigitalRune's physics engine.

    I'll discourage to let the client handle physics or collision, but if you are just creating a game for academic purposes or purely for fun surely you can use the client :)
  • Your subject states, "Fully Authoritative Server" it will break the definition of authoritative server if you choose to handle them inside the client. You can never trust the client with stuffs important as these most importantly collision. The client can tell the server that there is nothing in between the player and an object but clearly there is a cave or mountain. This is cheating and not fair for other players and you will end up loosing players because of unfairness. By the way you do not have to handle physics or collision all by yourself. There are libraries available which you can use, for ex. Nvidia's PhysX(which is also what Unity uses) or DigitalRune's physics engine.

    I'll discourage to let the client handle physics or collision, but if you are just creating a game for academic purposes or purely for fun surely you can use the client :)

    Ah - misunderstanding. I wasn't very clear. When I said I wanted to leverage Unity3D, I meant that I wanted to use Unity3D, or its physics dlls, on the host side. I definitely don't want to leave that up to the clients. Instant teleportation and what not.
  • Tobias
    Options
    Photon does not integrate Unity, the scene or just the physics on the server side. Unless really required, we want to avoid running a physics simulation for every game, cause it costs performance, which means you raise cost/player. This is not a problem for a few games but when you get thousands of players and a lot of action.

    Afaik, Unity's physics and scenes can't be run outside of Unity. There is no integration dll for that, so you will have to run a Unity instance per match, unless you export the scene and run your own physics (you could replace the physics clients side as well).

    The Photon Server SDK opens the doors for any kind of modification, so you could start and run Unity instances per room as needed.These Unity hosts would be special clients actually. You would need one instance started and joining each room, so they could be considered the Master Client and run your logic.

    It's obvious that this is quite some work but still might be worth it:
    With Photon, your setup would be load balanced right away. Multiple game servers can be used, each running X Unity hosts and games. You also get several matchmaking methods and anything that doesn't need simulation could be handled by Photon.
  • Tobias wrote:
    Photon does not integrate Unity, the scene or just the physics on the server side. Unless really required, we want to avoid running a physics simulation for every game, cause it costs performance, which means you raise cost/player. This is not a problem for a few games but when you get thousands of players and a lot of action.

    Afaik, Unity's physics and scenes can't be run outside of Unity. There is no integration dll for that, so you will have to run a Unity instance per match, unless you export the scene and run your own physics (you could replace the physics clients side as well).

    The Photon Server SDK opens the doors for any kind of modification, so you could start and run Unity instances per room as needed.These Unity hosts would be special clients actually. You would need one instance started and joining each room, so they could be considered the Master Client and run your logic.

    It's obvious that this is quite some work but still might be worth it:
    With Photon, your setup would be load balanced right away. Multiple game servers can be used, each running X Unity hosts and games. You also get several matchmaking methods and anything that doesn't need simulation could be handled by Photon.

    Well consider the quotes the I pulled up specifically, how would I control NPC movement from the dedicated fully-authoritative Server (SocketServer)?
  • storm33229 wrote:
    Well consider the quotes the I pulled up specifically, how would I control NPC movement from the dedicated fully-authoritative Server (SocketServer)?

    I had a similar approach to Tobias's in a small scale MMO I am creating at first. However, it was too slow when I had many players on at the same time. Too laggy and hard to do prediction, lag compensation, and most importantly movement but it was fine when the population is low. So, I ended up scratching the idea and decided to handle everything myself.

    For NPC handling, you definitely first need to know the terrain data. So, upload the unity's terrain as a binary array of height data. You can also upload the tile info as an array and use it inside the server for movement. Then use something like interest management to reduce calculations for far away players. In my game I don't update an NPC if it isn't doing anything(reduces cpu calculation)instead I only update npcs or game objects only if it is doing something. You can place the npc at the right position using the terrain data when it moves.
  • For NPC handling, you definitely first need to know the terrain data. So, upload the unity's terrain as a binary array of height data. You can also upload the tile info as an array and use it inside the server for movement. Then use something like interest management to reduce calculations for far away players. In my game I don't update an NPC if it isn't doing anything(reduces cpu calculation)instead I only update npcs or game objects only if it is doing something. You can place the npc at the right position using the terrain data when it moves.

    It is more than just terrain though: fences, trees, rocks, buildings - not to mention dynamic objects you're not supposed to be able to run through like enemies, NPC's, etc.

    The server needs a way to own, and update item positions/behaviors in the world, as well as validate the the player is making legal movements and not running through walls.
  • You need to implement a physics and(or) collision system inside your server, I know its a lot(ALOT) of work, but creating an MMO is not an easy job and that's why you see most companies just give up on them but that doesn't mean it is un-do-able. You can use external physics libraries to do the hard works for you. Most popular engine that can think of is NVIDIA's PhysX engine(which is also what Unity3D uses) but its expensive. Or digitalrunes's physics library which is way cheaper. http://www.digitalrune.com/Products/Gam ... ysics.aspx. And of course there are a lot others too
  • chvetsov
    Options
    do you really need on server exact physics?
    most mmo as you can see do not handle personage interactions. Take a look at WOW for example.
    interaction with trees can be solved by inaccessible zones. I'm mean you can mark on your map some zones as inaccessible and player can not be inside this area. This is already point and polygon interfaction and it can be solved very fast
  • chvetsov wrote:
    do you really need on server exact physics?
    most mmo as you can see do not handle personage interactions. Take a look at WOW for example.
    interaction with trees can be solved by inaccessible zones. I'm mean you can mark on your map some zones as inaccessible and player can not be inside this area. This is already point and polygon interfaction and it can be solved very fast

    That is exactly what I need to do, the question becomes how to do it. I'd still need to export the data from unity3d to a binary format that the server can consume.
  • chvetsov
    Options
    yes, that's true. You still need this. And as far as i know it is not so difficult.
  • chvetsov wrote:
    yes, that's true. You still need this. And as far as i know it is not so difficult.

    I think to start I am going to try an 8-way directional approach, this would allow me to more easily utilize a grid for pass/fail checks to see if the desired destination is "walkable".

    The only downside is how the movement looks... I am sure I can make this look much more smooth though. I am thinking that proper tweaking and playing with rotation and a tight spline interpolation for traveling the actual movement could work pretty well.
  • chvetsov
    Options
    storm33229 wrote:
    The only downside is how the movement looks... I am sure I can make this look much more smooth though. I am thinking that proper tweaking and playing with rotation and a tight spline interpolation for traveling the actual movement could work pretty well.
    you will able to tune this algorithm later. Right now we need to get working server.
  • chvetsov wrote:
    storm33229 wrote:
    The only downside is how the movement looks... I am sure I can make this look much more smooth though. I am thinking that proper tweaking and playing with rotation and a tight spline interpolation for traveling the actual movement could work pretty well.
    you will able to tune this algorithm later. Right now we need to get working server.

    Exactly, so my next step is to create a movement operation of some sort.
  • jayismyson wrote:
    I have succeeded in most of it in a Multiplayer RPG(small scale MMO) that I am creating except for the collision part which is what I am still working on. It is hard but the outcome is great :)[/url]

    I've gone the route of a 2D grid movement system which is being applied to a 3D world. This super simplifies things on the server side.
  • Lizzy
    Options
    Do you have a tutorial how to use DIgialRune or 2D grid movement being applied to a 3D world?