Search Unity

SmartFox API 1.1 released + 4 Unity tutorials

Discussion in 'Multiplayer' started by Thomas-Lund, Feb 28, 2009.

  1. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Its a bit of a waste to shoot with two sockets at your network card and firewall when uneeded (you can recreated TCP with UDP, so you can do it on 1 socket actually)
    While only a small thing on the client end, it basically dublicates the amount of connections on the server end.
     
  2. bertelmonster2k

    bertelmonster2k

    Joined:
    Apr 3, 2009
    Posts:
    78
    I subscribe all point from Lars - except there is another option than mixing TCP and (unreliable) UDP. We decided to implement reliable UDP (which allows to mix unreliable and reliable packets).

    We actually implemented the "reliable UDP" protocol based on ENET: http://enet.bespin.org/. The features supported are powerfull. It was pretty hard work to port this to all SDKs (C#/Unity3d, Java, iPhone, Android etc.) and to scalable server code. But we are happy with the result and throughput we see.

    Thanks Unity for making UDP available (especially) in the Browser - with Flash and Silverlight you still have to stick to TCP.

    best, Chris
     
  3. alanis

    alanis

    Joined:
    Mar 4, 2009
    Posts:
    99



    Thats what I am talking about, I am glad someone got to get enet to work with unity. congratulations.

    While browsing thru some other game emgines forums loong time ago, I came across 3d game studio forum user who developed a plugin for it based on enet library, anet-plugin.com nice job he has done there but sadly it is only for 3dgs. I remember once asked him long time ago if he was willing to do something for other engines like unity and he said maybe, but wasnt quite sure when, which I think probably not.

    Anyways, Gratz, I am glad you got the port succeeded from enet to work with unity.
    Were you able to build your own server for it?
    I wish you could have a blog about this port so I can learn your experiences.


    thanks you. and keep up the good work.
     
  4. bertelmonster2k

    bertelmonster2k

    Joined:
    Apr 3, 2009
    Posts:
    78
    ENet is a peer-2-peer solution, so we re-architected it to work in a client-2-server fashion. We have two different implementations:
    1) Client libraries (C#, Java, C/C++, ObjC etc) which have low demands (it actually runs on J2ME phones)
    2) A Server library written in C/C++ tuned for performance and high concurrent connections

    You can give it a try to see if you like it ;].

    Chris
     
  5. oplontis

    oplontis

    Joined:
    May 17, 2009
    Posts:
    12
    is there a way to embed redbox features into Unity?

    The sfs plugin for unity include redbox classes?

    thanks
    marco
     
  6. Thomas-Lund

    Thomas-Lund

    Joined:
    Jan 18, 2008
    Posts:
    465
    Hi,

    No - that is not possible. The redbox elements are not compatible with Unity.

    You might be able to use them in the same webpage and set up some communication between the elements on the same webpage.

    Thats not really API stuff, but somewhere on these forums there are some posts on how to do that

    /Thomas
     
  7. alanis

    alanis

    Joined:
    Mar 4, 2009
    Posts:
    99

    thank you Chris,
    Nice to hear that, let me ask you a question,

    are we talking about photon and its unity sdk?? is all these implemenations from enet has been added to photon?

    or are we talking about something else?

    thanks
     
  8. Thomas-Lund

    Thomas-Lund

    Joined:
    Jan 18, 2008
    Posts:
    465
    Maybe time to make a thread of your own on enet/photon?!?!?!

    :)

    /T
     
  9. alanis

    alanis

    Joined:
    Mar 4, 2009
    Posts:
    99
    Hi Thomas, You are right, sorry about that, didnt to highjack this thread I guess I just got carried away.

    Since it may lead to some more Q's and Answers I will start a ne thread about it.

    thanks again and my appologies.
    good day.
     
  10. Thomas-Lund

    Thomas-Lund

    Joined:
    Jan 18, 2008
    Posts:
    465
    No problemo - just semi irritating to get notification emails that are not related to me :-D

    /T
     
  11. alanis

    alanis

    Joined:
    Mar 4, 2009
    Posts:
    99
    I kno what mean,

    Hey, going back to smartfox, how is it going, I remember a few months ago I once download it and looked at the api for unity and it worked fine from my end you know, the basic chat example, but in the smartfox forums I dont see many tutorials about it. since not a high core programmer, just basics stuff.
    will there be any futyre tutorials, like implementing ingame features, ie: sql database driven stuff, auth login to craft the game logic etc...
     
  12. Thomas-Lund

    Thomas-Lund

    Joined:
    Jan 18, 2008
    Posts:
    465
    Hey alanis!

    Goes pretty well - yeah. There are no further tutorials planned right now, but I have been thinking about making some "paid for tutorials". Just dont know how much demand there is.

    A lot of the database stuff, backend code snippets etc already exist in the "regular" SFS forums and tutorials, as the backend is totally the same for all clients. So you can use those straight up without caring if its flash, Unity webplayer or iPhone version - and they all talk to each other.

    But lets see - I had hoped that the running series in the Unity Developer Magazine would be "the advanced tutorial to beat them all". I wrote the next part of the tutorial series in December for magazine 3 - but it has never hit the street. And I'll not sink more time into it until #3 is in my hands - unfortunately.

    /Thomas
     
  13. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    Thomas, all the work you have put into this is totally top notch, I can't thank you enough!
     
  14. alanis

    alanis

    Joined:
    Mar 4, 2009
    Posts:
    99
    Hi Thomas,

    thanks for your input,

    I ve been searching on SFS forum, but cant seem to find the tutorials or code snippets for sql driven backend. is there a code snippet area in SFS website. cant seem to find it.

    Will appreciate it , thanks.
     
  15. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    the default sfs pro installation contains a sample zones that works with sql database (not the H2 one). you just need to configure it correctly.

    I had it working in past tests, it isn't all that complicated actually once the base connection is working.

    the present H2 and sql database sample zones use modules that make it pretty easy to grasp the base to build upon.
     
  16. Thomas-Lund

    Thomas-Lund

    Joined:
    Jan 18, 2008
    Posts:
    465
    The server extensions forum has a sticky with a link to the cookbook.

    Here it is directly:

    http://www.smartfoxserver.com/docs/docPages/sfsPro/javaCookBook.htm

    Lots of code snippets to take. As dreamora says, there is a database example bundled with the default installation (+ other examples with code). The login cookbook also has a simple example in the above java cookbook.

    Not as nifty packaged I will give you that, but its there.

    Wil poke the SFS guys to make a clearer link and bundle of their stuff :)

    Thanks for all the feedback guys in general. I started out on this adventure making the API for myself, and its great that other people can use it for their work too. And great to see other technologies shoot up too around the networking part. Not every product fits every usage pattern, so having something to choose from is fantastic!

    /Thomas
     
  17. alanis

    alanis

    Joined:
    Mar 4, 2009
    Posts:
    99
    Thanks for the link Thomas, That should get me started
     
  18. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Yes some better interlinking would surely be a good thing as the website isn't that intuitive. With things like the cluster article beeing a "top level" link while other things are burried further down its easy to get lost.

    I recently tried to find the flash engine documentation to reevaluate it (but sadly it seems like that one is a dead product as not even the dec 08 features are in by now and that at its massive price ...). Google was significantly faster than the page.


    Thanks for your time and efforts on this Thomas
     
  19. nimrodgames

    nimrodgames

    Joined:
    Mar 1, 2009
    Posts:
    17

    I'm having trouble logging in to the island demo it won't login with the default settings any help??
     
  20. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    did you start the server locally etc?
     
  21. Thomas-Lund

    Thomas-Lund

    Joined:
    Jan 18, 2008
    Posts:
    465
    Alternatively your local firewall blocks the communication.

    But yes - also forgetting to start the SFS server could be a problem - as well as downloading the "lite" server. The SFS API only works with standard + pro versions
     
  22. nimrodgames

    nimrodgames

    Joined:
    Mar 1, 2009
    Posts:
    17
    yes i started it locally, I download the smartserver island demo and started play and I get and error saying failed to log on.. do you know what that could be?
     
  23. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    firewall interfering or server didn't start correctly (did you check through the admin tool if the corresponding zone is up and running)
     
  24. free60groups

    free60groups

    Joined:
    May 13, 2009
    Posts:
    9
    if you have vista it could be that you installed SmartFox under the program files directory naturally, which in return would prevent you from starting the server correctly and running as a client in unity.


    If that is the case what you gotta do is uninstall SmartFox and then reinstall it under your first directory of your local drive ie: (mine is C:\SmartFoxServer..)

    Hope that helps

    -Jake
     
  25. jjjack

    jjjack

    Joined:
    Aug 19, 2008
    Posts:
    22
    Just wanted to say thanks for working on this. Works really well.

    Jack
     
  26. Thomas-Lund

    Thomas-Lund

    Joined:
    Jan 18, 2008
    Posts:
    465
    Happy to hear - thanks!!

    /Thomas
     
  27. xandeck

    xandeck

    Joined:
    Apr 2, 2009
    Posts:
    563
    Hey Thomas,

    after carefully reading the tutorials and manual of SFS and then all your tutorials, the SFS API for Unity is very good... and not hard to learn too :D

    Did you make the API all you alone? The plans to update or get better (if need to) the API will be dated in SFS foruns?

    Thanks for the API, looks very good so far, made a lot of tests already...
     
  28. gokhanertem

    gokhanertem

    Joined:
    Aug 31, 2009
    Posts:
    95
    thank you for the information, very useful

    in the second tutorial i can not create a lobby, when i enter my name, and click the login button nothin g happens. Is there a pass required? it is not meant in the documentation.

    Thank you
     
  29. Thomas-Lund

    Thomas-Lund

    Joined:
    Jan 18, 2008
    Posts:
    465
    Hi

    Nope - no password required. What does the console log say when you hit the login button?

    /Thomas
     
  30. gokhanertem

    gokhanertem

    Joined:
    Aug 31, 2009
    Posts:
    95
    nothing it just freezes,

    afterwards i managed to run the SFS Island Demo, and i believe there is a big issue here. I have started to run 2 client in different machines, and every second i refreshed the server status, every 2 secs. the traffic showed 2-4 kilobytes! Fro just the translation information of a player. a position and rotation information should take 4 bytes, and since this demo is updated every 0.1 secs, the traffic should shange in 40 bytes but not 4 kilobytes. I can not imagine how much bandwith will be required for an mmo game!

    do you have any ideas? Thank you
     
  31. gokhanertem

    gokhanertem

    Joined:
    Aug 31, 2009
    Posts:
    95
    In the island demo, i can not find out where this NetworkTransformReceiver.cs is binded to, or called from.

    I have used the script

    void Start() {
    Debug.Log("I am attached to "+gameObject.name);
    }


    it gave me "player_7"

    its not listed in the project tree. I am having diffuculty in understanding this island demo.
     
  32. Thomas-Lund

    Thomas-Lund

    Joined:
    Jan 18, 2008
    Posts:
    465
    A few quick answers:

    * Lobby
    Without some kind of info on whats wrong in your end, I cannot help on the lobby part. Works here and never heard of anyone having problems with it

    * SFS island demo network traffic
    First off, as also written in the tutorial text document that comes with it, it is _not_ performance optimized _at all_. It is a proof of concept where you need to optimize it based on your own requirements. It uses the most expensive (bandwidth wise) way of distributing information - text based and XML'ified and broadcasts to all.

    But your calculation is also a bit to optimistic. A transform contains 7 floats (3 for position, 4 for rotation). A float takes 4 bytes (8 for double). So as a minimum you have to use 32 or 64 bytes per update per client. So even if you made a binary protocol you would have approx 0.5 kb per second per client

    But as the demo uses text based protocol, a float is right now taking much more than 4 bytes + the xml overhead.

    This optimization is as I said left to the reader to implement + a lot of other optimizations you would need to do for a MMO with thousands of players (if thats your target)

    * Island demo transform reciever
    It is added via the remote player prefab undet networkPrefabs folder for each remote player avatar that is spawned into the scene.

    Best
    Thomas
     
  33. gokhanertem

    gokhanertem

    Joined:
    Aug 31, 2009
    Posts:
    95
    thank you very much
    i am really working hard here...
     
  34. ashwan

    ashwan

    Joined:
    Mar 3, 2010
    Posts:
    21
    Hi Thomas...

    I tried to instantiate a small cube with the help of island demo tutorial but i cannot see it getting instantiated whenever a player gets connected. The cube has 3rd person view
     
  35. Thomas-Lund

    Thomas-Lund

    Joined:
    Jan 18, 2008
    Posts:
    465
    Hey hey,

    did you put the cube into the existing prefab for the player? It might have lost the link to that prefab.

    Just ideas

    /Thomas
     
  36. ashwan

    ashwan

    Joined:
    Mar 3, 2010
    Posts:
    21
    My plan is to build a small 3rd person view game which small animations like walk jump. I totally started it in a new scene with a cube in it i wanted the same cube to be instantiated when client connects. I tried to do it with the network scripts of island demo but didnot succeed can you help in anyway. There are mamy tutorials for FPS but not for 3rd Person view
     
  37. Thomas-Lund

    Thomas-Lund

    Joined:
    Jan 18, 2008
    Posts:
    465
    You'll have to look a bit more in depth into the code example yourself, sorry. There is no dissection guide of the example - sorry.

    But as mentioned the scripts use a prefab of the "remote player avatar" model. You will need to make a prefab of your cube and link that in similar to the robot model in the example project. Then it should work mostly out of the box!

    /Thomas
     
  38. jerbob92

    jerbob92

    Joined:
    Apr 12, 2010
    Posts:
    10
    How can i make a registration system? Do i have to use WWW or can i do this directly in SmartFox?
     
  39. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    you can do it directly with smartfox, you just have to write a server extension to which you talk
     
  40. jerbob92

    jerbob92

    Joined:
    Apr 12, 2010
    Posts:
    10
    I will look at that later...

    Assets/Game/Scripts/network/NetworkTransform.cs(8,14): warning CS0659: `NetworkTransform' overrides Object.Equals(object) but does not override Object.GetHashCode()


    Im getting this error, im not really sure what the error means, could somebody explain?
     
  41. Thomas-Lund

    Thomas-Lund

    Joined:
    Jan 18, 2008
    Posts:
    465
     
  42. jerbob92

    jerbob92

    Joined:
    Apr 12, 2010
    Posts:
    10
    I know its a warning, but this might be the reason why my chatscript isnt working...
     
  43. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    No it might not.

    Its a warning in relation to the implementation of basic System.Object stuff. Its not related in any way to your problem.

    your problem is more likely related to missing assignements or alike
     
  44. jerbob92

    jerbob92

    Joined:
    Apr 12, 2010
    Posts:
    10
    Code (csharp):
    1. SmartFoxClient sfc =  NetworkController.GetClient();
    2.        
    3. Room rmObj = sfc.GetRoom(sfc.activeRoomId);
    4. User usrObj = rmObj.GetUser(sfc.myUserId);
    5.        
    6. GUI.Label(new Rect(10, 20, 500, 20), "Guest:" +usrObj.GetVariable("Guest"));
    7. GUI.Label(new Rect(10, 40, 500, 20), "UserDBID:"+usrObj.GetVariable("UserDBID"));
    Why doesnt this work?

    When i try getVariables(), it says the function doesnt exists :?

    Im using this to set the variables:

    Code (csharp):
    1. Hashtable uVars = new Hashtable();
    2.                         uVars.Add("UserDBID", exploded[1]);
    3.                         uVars.Add("Guest", 0);
    4.                         smartFox.SetUserVariables(uVars);
    (yes the client is called smartFox in the second code, that is not the problem!)

    Please help
     
  45. jerbob92

    jerbob92

    Joined:
    Apr 12, 2010
    Posts:
    10
    And is it possible to get the roomlist+users in that room before logging in?
     
  46. jerbob92

    jerbob92

    Joined:
    Apr 12, 2010
    Posts:
    10
    Why does Unity give this error:

    `SmartFoxClientAPI.Data.User' does not contain a definition for `getVariables'?
     
  47. CaptainKiyaku

    CaptainKiyaku

    Joined:
    Feb 8, 2009
    Posts:
    324
    Hi,
    you said there is a documentation coming with the Island Demo. I actually really can't find any documentation about it, am i missing something?

    And how exactly can you see that the informations are sent text-based/XML?

    Or is this post already too outdated and the uploaded version is newer and enhanced?

    Thanks in advance, it seems like a great server.
     
  48. CaptainKiyaku

    CaptainKiyaku

    Joined:
    Feb 8, 2009
    Posts:
    324
    Okay i actually found out how it works, i saw the SendXtMessage Function, great.

    Now i am just curious if anyone tried something like an MMO (ala WoW) concept.

    You will need a server who allows you to do things, to attack, apply damage, trade, etc.

    First i thought i could just use SFS for it to validate that files. But what if you want to do things like trading and you have to raycast between 2 players to see if there is no wall between them?

    So i guess you will have to use a unity client as server.

    Now i was wondering if the concept would be like this

    - Client asks to do stuff and sends it to SFS
    - SFS can do some pre-checks to see if it can handle it by itself
    - Otherwise send it to the server (unity headless client)
    - Unity server will check if the client can do that step
    - If yes, send it back to SFS
    - SFS sends it back to the Client

    Does this goes into the right direction or is it too much overhead and there is a "smarter" solution?

    I also was wondering how SFS knows which client is the server so i guess using the server as client ID 0 (or 1, dunno whats first in SFS) so i can always response to user 0/1?

    If anyone has some experience with that, i would really appreciate if you could give some comments about it.
     
  49. Thomas-Lund

    Thomas-Lund

    Joined:
    Jan 18, 2008
    Posts:
    465
    The way to do these things is not to have a Unity headless server. It doesnt scale at all to MMO level.

    What you do is to have an authoritative server coded using extensions inside SFS (or any other networking framework on the server side).

    Your entire world run on the server side as a _data_ simulation. So you will have to represent e.g. your players with a data object on the server side, and this is synced to the clients connected to the simulation regularly.

    Casting spells etc.etc. is then made as extension calls.

    I wrote something about this in the first Unity Developer Magazine, and there is also some of the techniques described in my FPS reply here in the middle:

    http://www.smartfoxserver.com/forums/viewtopic.php?t=7249

    I'm sure there are various extension examples you can take a look at. Beware that once you start to talk MMO in larger scale, you need to think clustering, stateless coding, database replication and a hell of a lot of other complex IT operating thoughts. It is _not_ trivial. But I'm sure you are aware of this.

    One of the more tricky things might be how to make your world representation with (important - not all) collisions. One way is to create an editor script that takes your current scene and saves off in a specially designed file format, which then can be loaded by the server and used for its _data_ simulation. That way you dont have to fiddle in raw transform data, but can do it visually using Unity.

    /Thomas
     
  50. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Or use simulation nodes (lightweight unity headless clients) that perform the collision and physical simulation (gravity and and raycast verifications for attacks) for a given area of the world.
    these nodes then would run along the sfs server and would communicate with it directly.