Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Released] SlimNet 0.2 Beta

Discussion in 'Multiplayer' started by fholm, Feb 18, 2012.

  1. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    SlimNet 0.2 Beta

    SlimNet is a networking middle ware for Unity

    After many delays I've finally managed to get everything ready and pack SlimNet up for it's 0.2 release. This release contains a few note-worthy improvements.

    • The core engine is now event-driven instead of stream-driven. This makes for an easier to use model and lower band-width usage.
    • Support for statically typed RPCs
    • A major simplification of the core engine, both from a usability and technical perspective.

    You could consider 0.2 a re-write over the previous released 0.1.x series, but it's not really true as the engine has not really been re-written - just reworked and improved a lot. Many of the features I have shown demos of on this forum are not yet in the engine, I decided to cut them short to be able to bring the code to you so you can test it and give me feedback.

    The features scheduled for the next release, 0.2.1 are as follows:

    • Stand alone server physics
    • Server integrated mode inside unity
    • Linux / OSX server support

    Feedback Bug Reports

    If you want to leave feedback or bug-reports on SlimNet 0.2, please do so in this thread. If you want or need immediate help you can usually find me in #unity3d @ irc.freenode.net under the same nick as on this forum.

    Setup Instructions



    License

    Code (csharp):
    1. /*
    2.  * SlimNet - Networking Middleware For Games
    3.  * Copyright (C) 2011-2012 Fredrik Holmström
    4.  *
    5.  * This software is provided 'as-is', without any express or implied
    6.  * warranty. In no event will the authors be held liable for any damages
    7.  * arising from the use of this software.
    8.  *
    9.  * Attribution
    10.  * The origin of this software must not be misrepresented; you must not
    11.  * claim that you wrote the original software. For any works using this
    12.  * software, reasonable acknowledgment is required.
    13.  *
    14.  * Noncommercial
    15.  * You may not use this software for commercial purposes.
    16.  *
    17.  * Distribution
    18.  * You are free to share, copy and distribute the software in it's original,
    19.  * unmodified form. You are not allowed to distribute or make publicly
    20.  * available the software itself or it's sources in any modified manner.
    21.  * This notice may not be removed or altered from any source distribution.
    22.  */
    Download Links


    Old Releases

     
    Last edited: Feb 18, 2012
  2. Zhosay

    Zhosay

    Joined:
    Dec 12, 2011
    Posts:
    98
    Hey gj on the release, glad you got everything working.

    I looked into your server and can't find any room class. Did you removed it completly? So now it would need multiple Server instances running on different ports? Correct me if I'm wrong.
     
  3. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    Correct, the rooms-support has been removed due the planned unity integrated support which will allow the server to run inside of unity, and there really is no good solution to running several rooms inside the same unity instance.

    I am working on a "rooms" manager (sort of like the master server for unity, but a bit more advanced) which can control and spin/up down server instances in the background.
     
  4. Zhosay

    Zhosay

    Joined:
    Dec 12, 2011
    Posts:
    98
    Hmm okay makes it kinda hard for a moba game. As the instances part was allready the point that scared me away from Ulink.
    Maybe I'll find a solution to that with my own extension.

    Edit: Oh and before I forget :D its cool stuff for RPG/MMORPG check it out guys. Best solution so far.
     
    Last edited: Feb 18, 2012
  5. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    I don't see how this would make it hard for a MOBA game, if i was to make a MOBA (which I am) I would want all the game instances in separate processes due to stability (i.e. if one crashes all other games don't crash).
     
  6. Zhosay

    Zhosay

    Joined:
    Dec 12, 2011
    Posts:
    98
    Yes agree with that. But it would need like an Instance manager.
    Connect the user from the "master client" to subserver listing subservers on mainserver. Am I right?
     
  7. Tommis

    Tommis

    Joined:
    Apr 4, 2010
    Posts:
    15
    Cant find the scene for unity client MMOControler example.
     
  8. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    It's in the Demo/Scenes/DemoScene.unity file inside the Unity Project.
     
  9. Tommis

    Tommis

    Joined:
    Apr 4, 2010
    Posts:
    15
    oh really :), thx.
     
  10. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    I think I managed to crack the Linux/OSX problems, need to do some serious clean up of the implementation, but here's a screenshot of SlimNet running inside Ubuntu 11.10:

     
  11. liverolA

    liverolA

    Joined:
    Feb 10, 2009
    Posts:
    347
    thanks for the share,i downloaded and try this,with vs2010 express,got this error when compiled,

    how to fix this?
     
  12. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    You need to run visual studio with administration privileges.
     
  13. liverolA

    liverolA

    Joined:
    Feb 10, 2009
    Posts:
    347
    thansk,i tried, the same error,i just noticed there is a path setting,like "c:\slimnet",i don't put my project there,is this the problem?
    or where i can config the new copy path? i have to put slimnet in "c:\slimnet\..."?
     
    Last edited: Feb 19, 2012
  14. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    Yes, it should be put in C:\SlimNet2 currently, check the instructions video for more details.
     
  15. RoyAwesome

    RoyAwesome

    Joined:
    Feb 21, 2012
    Posts:
    1
    This looks awesome.

    Obviously it's not very authoritative yet, but is full game simulation planned on the server? I'm looking at multiplayer FPS interactions, and they kinda need to have everything done on the server.
     
  16. Zhosay

    Zhosay

    Joined:
    Dec 12, 2011
    Posts:
    98
    It is full authorative games possible. Just the example is it maybe not (Didnt checked it out that much). Full game simulation is allready possible as you can run the server as Unity project, only the example is a standalone. Watch fholms youtube account for more information.

    http://www.youtube.com/watch?v=ITPdIPV2tMU&feature=player_embedded
     
  17. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    Need more deets! So is the server a Unity instance now from the looks of it?
     
  18. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    The server is very capable of doing authoritative games, including control over position, movement, etc. Exactly what you will need to implement yourself is something that depends fairly much on the game you're building.

    Both yes and no, the server can be ran both as a stand-alone application and inside a unity instance (either using headless mode for dedicated servers or inside one client acting as the server).

    A small update (0.2.0.1), a manual and introduction videos will follow.
     
    Last edited: Feb 21, 2012
  19. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    Interesting. I will definitely give it a shot once the manual is done.

    ...Hey, I'm not Zhosay! Haha.

    PS: I assume the license is as such because of the in-development, beta status right?
     
    Last edited: Feb 21, 2012
  20. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    Yes, correct! If you need a more permissive license contact me over PM.

    I also fixed the quote, something got messed up
     
  21. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    So when you say its event based and not stream based, does that mean no serialization? Everything is reliable/unreliable RPC's?
     
  22. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    There is a stream for tranform data + extra data you can attach, but it's mostly handled automatically by the engine and not something you need to think of. You can write your own position tranform/data stream synchronizer if you for example only need 2 axes (2.5D game, etc) or only one axis of rotation, etc. Or if you want to attach some extra data like rigidbody velocity.

    But in general, most of the data you send back and forth is done using events (not RPCs, they exist also, but are of little real use other then for one off things like "Login", "enter world", etc.).
     
    Last edited: Feb 21, 2012
  23. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    Interesting... so what's a unity code sample look like of say, a client executing an attack or something? both the client side request and the server side event?
     
  24. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    We can take an example from the demo (simplified it a bit to make it easier to understand), first you need to define an event, here's a simple CastSpell event:

    Code (csharp):
    1.  
    2. public sealed class CastSpellEvent : Event<Actor>
    3. {
    4.     public override byte EventId { get { return HeaderBytes.UserStart + 3; } }
    5.     public override ProximityLevel ProximityLevel { get { return SlimNet.ProximityLevel.Horizon; } }
    6.     public override int DataSize { get { return 2; } }
    7.     public override bool Reliable { get { return true; } }
    8.  
    9.     public Actor SpellTarget { get; set; }
    10.  
    11.     public CastSpellEvent()
    12.         : base(EventTargets.Owner | EventTargets.Remotes, EventSources.Owner)
    13.     {
    14.  
    15.     }
    16.  
    17.     public override void Pack(SlimNet.Network.ByteOutStream stream)
    18.     {
    19.         stream.WriteActor(SpellTarget);
    20.     }
    21.  
    22.     public override void Unpack(SlimNet.Network.ByteInStream stream)
    23.     {
    24.         SpellTarget = stream.ReadActor();
    25.     }
    26. }
    27.  
    Explanation of the standard properties of the event:

    • EventId is a byte that is unique to this event, basically it's id.
    • ProximityLevel is an interest based flag that decides what players should get an event based on how close they are to the origin of the event
    • DataSize is the size of the data in the event, in this case 2 as we're sending an actor reference over the wire (the target of the spell)
    • Reliable decides if the event should be reliable or not

    The property SpellTarget is specific to this event, and it's the target of the spell (duh ;p).

    The call to the base constructor is a bit specific, the constructor in SlimNet.Event<T> looks like this:

    Code (csharp):
    1. Event(EventTargets targets, EventSources sources)
    EventTargets controls what peers the event should be raised on.
    EventSources controls what peers are allowed to raise the event.

    In this case of the CastSpellEvent the event will be sent to the owner of the actor (game object) and to all remote players. It's only allowed to be raised from the owner of the object (it would not make a lot of sense to raise "cast spell" for an actor you don't control)

    Pack and Unpack is basically the Serialize/Unserialize methods which packs or unpacks the data of the event.

    Now, assume you have a target selected and want to throw a fireball at it, it would look like this:

    Code (csharp):
    1.  
    2. actor.RaiseEvent<MMODemo.CastSpellEvent>((ev) =>
    3. {
    4.     ev.SpellTarget = target.Value;
    5. });
    6.  
    This event will be raised on your local client (as you're the owner) and then sent to the server which distributes it to all other clients, they listen to the event by doing this:

    Code (csharp):
    1.  
    2.     void Start()
    3.     {
    4.         actor = this.GetSlimNetActor();
    5.         actor.RegisterEventReceiver<MMODemo.CastSpellEvent>(onCast);
    6.     }
    7.  
    8.     void onCast(MMODemo.CastSpellEvent ev)
    9.     {
    10.          // Cast spell
    11.     }
    12.  
     
  25. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    Also note that all events that are sent are automatically synchronized to the movement of the players on the remote clients and server, so there is no need to manually align movement and actions, it's done automatically for you.
     
  26. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    After some really good feedback from a user on IRC I implemented an "embedded development server" inside Unity which compiles and runs the server for you when you hit play, easiest way to explain it is to just watch the video and see it in action:

     
  27. Doddler

    Doddler

    Joined:
    Jul 12, 2011
    Posts:
    269
    I'm impressed how easy it is to set up quick networking with this framework. There's some things I'm not a hundred percent sure how you'd set up. Like I'm trying to get a server to only send nearby entities. Additionally, I want my server to unload sections of the game world not currently in use (my game requires sending map data as the player moves around). It's probably not terribly hard, I guess I'm just not used to this kind of coding standard. It looks really good so far though! I'll mess around with it some more to see if it's what I need.
     
  28. JanHelleman

    JanHelleman

    Joined:
    Oct 11, 2009
    Posts:
    116
    I Might be blind or something, but don't understand how the system knows to instantiate "Player" prefab in the resources folder of the demo. Been searching for 2 hours. Might be missing an open door here? :)
     
  29. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    ActorExtension.cs
     
  30. JanHelleman

    JanHelleman

    Joined:
    Oct 11, 2009
    Posts:
    116
    Call me stupid but this is the code of actorExtension:

    Code (csharp):
    1.  
    2. /*
    3.  * SlimNet - Networking Middleware For Games
    4.  * Copyright (C) 2011-2012 Fredrik Holmström
    5.  *
    6.  * This software is provided 'as-is', without any express or implied
    7.  * warranty. In no event will the authors be held liable for any damages
    8.  * arising from the use of this software.
    9.  *
    10.  * Attribution
    11.  * The origin of this software must not be misrepresented; you must not
    12.  * claim that you wrote the original software. For any works using this
    13.  * software, reasonable acknowledgment is required.
    14.  *
    15.  * Noncommercial
    16.  * You may not use this software for commercial purposes.
    17.  *
    18.  * Distribution
    19.  * You are free to share, copy and distribute the software in it's original,
    20.  * unmodified form. You are not allowed to distribute or make publicly
    21.  * available the software itself or it's sources in any modified manner.
    22.  * This notice may not be removed or altered from any source distribution.
    23.  */
    24.  
    25.  
    26. using UnityEngine;
    27.  
    28. namespace SlimNet.Unity
    29. {
    30.     public static class ActorExtensions
    31.     {
    32.         public static GameObject GetGameObject(this Actor actor)
    33.         {
    34.             return GameObjectMap.Retrieve(actor);
    35.         }
    36.  
    37.         public static UnityEngine.Transform GetUnityTransform(this Actor actor)
    38.         {
    39.             return GameObjectMap.Retrieve(actor).transform;
    40.         }
    41.     }
    42. }
    43.  
    But where does it define that the "Player" prefab should be used as the instantiate object "Actor"?
     
  31. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    it is not in ActorExtentions.cs but in peerutils.cs
     
  32. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    Sorry, he changed it in the latest version, it's located in the PeerUtils.cs
     
  33. JanHelleman

    JanHelleman

    Joined:
    Oct 11, 2009
    Posts:
    116
    Ok I am finding it very hard to understand the structure etc. How does this work? There are 3 prefabs, and for some reason it chooses "Player.prefab" to be the prefab for input etc. I am sorry if I am lacking skills to see this through just like that, but none of the videos talk about this, and for some reason, I just don't get it.

    Why is player.prefab loaded as the actor for input/camera and other players?

    Next to that, what happened to the idea of exporting the scene for the server? Is it still authorative?

    It looks like a promising framework and I'd love to give it a spin but for some reason I get confused like crazy..
     
  34. JanHelleman

    JanHelleman

    Joined:
    Oct 11, 2009
    Posts:
    116
    So yeah I might have been sleeping like a baby or something. The following code loads the actor based on what the derrived name is of ActorDefinition:
    Code (csharp):
    1.  
    2.         public ActorDefinition(Context context)
    3.         {
    4.             Context = context;
    5.             Name =
    6.                 GetType()
    7.                     .Name
    8.                     .Replace("Definition", "")
    9.                     .Replace("Actor", "");
    10.         }
    11.  
    The contextPlugin of MMODemo.Server spawns the actor with prefab "Player" since the name is PlayerActorDefinition (above code removes actor definition to define the prefab name):
    Code (csharp):
    1.  
    2.         public override void PlayerJoined(SlimNet.Player player)
    3.         {
    4.             Context.PlayerEventHandler.Raise<SlimNet.Events.Authenticated>(
    5.                 player,
    6.                 (ev) =>
    7.                 {
    8.                     ev.IsAuthenticated = true;
    9.                     ev.Error = "";
    10.                 }
    11.             );
    12.  
    13.             base.PlayerJoined(player);
    14.  
    15.             Context.Server.SpawnActor<PlayerActorDefinition>(player, new SlimMath.Vector3(45, 10, 45));
    16.         }
    17.     }
    18.  
    I am just filling this in for future reference for others, so they don't have to go through this.

    The only thing I do not understand yet is what config-prefabs.xml has to do with this, and if it does anything, how I'd go and generate it.

    If I would want to spawn say, a car, and this object would be important because the player drives in it and thus its location should be synced at all players based on the input, would I make something like a "CarActorDefinition" and spawn it at some point with a velocityEvent attached?

    Kind regards
     
  35. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    Jan: I will try to give you a longer response later, config-prefabs.xml is part of some old, now unused code and is not needed anywhere. 0.2.1 will be a nice cleanup of all the "old code" being removed + embedded editor + linux/osx support + a proper video tutorial of about 10 parts.

    though, as I said in another post on this forum, I took a big piece out of my index finger with a steak knife yday and can't program for about it a week. It (0.2.1) was supposed to be out mid-end next week, but I have to rest my left hand sadly ;p
     
  36. JanHelleman

    JanHelleman

    Joined:
    Oct 11, 2009
    Posts:
    116
    Hey man didn't know that no worries. Make sure your finger heals right. It just takes a lot of time to go through it all. Have you considered one or more github repos? As I am spitting through for example I'd be happy to make notes here and there..
     
  37. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    I have three github repos, but they are all private currently.
     
  38. JanHelleman

    JanHelleman

    Joined:
    Oct 11, 2009
    Posts:
    116
    Ok, let me know if you want me to help out on something.

    for now my scenario is:

    I want a network synced car that can be controlled by a player. Obviously when the player enters the car it does not need to sync the transform anymore and would become dependant on the car. The car should then start syncing. The player would probably become a child of the car transform (sitting right etc). I'd figure this would be an "enter car event" where the player actor would stop syncing transform and the car starts syncing? Further I guess the car that the player sits in should start beeing considered "IsMine" as well.

    Right now I created a CarActorDefinition and CarBehaviour. It instantiates some dummy Car prefabs correctly when the client connects (obviously). How would you suggest the above scenario and further more, am I following your pattern when I'd be doing it this way?
     
  39. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    JanHelleman: Currently, the engine doesn't support changing ownership of an actor, this will be supported in 0.2.1 however. Other then that what you described is probably what I would do also.

    Also, I'll throw in a quick update on 0.2.1. It's done, but I'm holding it back while finishing up a much better version of the example game and the tutorial videos. Expect everything to land early next week. Here's a screenshot of the demo, complete with working chat + player portrait + three spells.



    (large version: http://dl.dropbox.com/u/19877504/021_demo_3.png)
     
  40. Fishypants

    Fishypants

    Joined:
    Jan 25, 2009
    Posts:
    444
    Cool! Ok, now subscribed to the 0.2 Beta thread. I'm going to take a look at this over the weekend. Excellent stuff from what I can tell so far! :D
     
  41. cez1230

    cez1230

    Joined:
    Feb 10, 2011
    Posts:
    31
    cool ,

    but i find that lidgen is also write by you , what is the differents?

    and the linux epool as the powerfull capacity ,perhaps can deal with 40,000 players , so can we know the capacity of the lidgen and slimNet,
    thanks
     
  42. ant001

    ant001

    Joined:
    Dec 15, 2010
    Posts:
    116
    slimNet
     
  43. ant001

    ant001

    Joined:
    Dec 15, 2010
    Posts:
    116
    fholm, hope your doing ok.
     
  44. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    If you own iOS Pro / Android Pro.
    The UDP / TCP sockets on mobile are pro only features
     
  45. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    Sorry for the silence lately, I've been busy with some of my other projects (which you can find on the asset store) and IRL, I'm getting back to SlimNet soon :)
     
  46. hesa2020

    hesa2020

    Joined:
    Jul 27, 2011
    Posts:
    261
    Hey anyone Played with SlimNet ?
    i do and this is what i done so far :
    I have a php login and when the player login i connect to world server ( to SlimNet )
    and When the connection is done i load the Character Selection Scene.
    From there i want to send a command to SlimNet server for Load The Character, but i have no idea how to create command in slimnet and how to send command to Slimnet.

    If anyone Know how to ... Please share it with me.

    Thank you !
     
  47. ant001

    ant001

    Joined:
    Dec 15, 2010
    Posts:
    116
    hesa2020: waiting on the unity server version so can dev on the mac while traveling /cookies to fholm
     
  48. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    ant001: I'm very close to finishing up 0.2.1 (i know I've said it multiple times, but this time it's actually happening ;p). I got a 4 day weekend in Sweden now also due to easter so expecting to get some crunch time in :)
     
  49. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    Here's a quick screen shot of the spatial partitioning and collision detection inside SlimNet, which also runs on the server outside of Unity:



    This is a rendering of the server space partitions + colliders running on the client (for debugging purposes), and you will notice the red SlimNet collider instead of the standard unity collider.
     
  50. jake-gr

    jake-gr

    Joined:
    Oct 27, 2011
    Posts:
    93
    Looking real nice! Getting very close to being a contender in the networking middleware solutions.
    Would be nice if you could do up a quick tutorial on how to get it working with MonoDev though, I downloaded 0.2.0 and was unable to get anything to build :(
    (granted it may just be my setup though)