Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. We are looking for your feedback about Templates! Tell us about your experiences by taking our survey.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

[LIDGREN TUTORIAL]

Discussion in 'Multiplayer' started by runningbird, Jul 21, 2010.

  1. runningbird

    runningbird

    Joined:
    Sep 3, 2009
    Posts:
    381
    I have been working on getting Unity working with the Lidgren networking library.

    So far I have a simple Chat client where you can connect either with a web player or windows / Mac client to the server and send messages back and forth.

    I will be creating a full blown tutorial with a demo level as well as releasing the server + source for the server.

    Demo Will include:

    • Connecting to server
      Logging in to server
      Sending / Receiving Chat Messages
      Sending / Receiving Transform
      Sending / Receiving Functions
      Instancing of Other Player prefabs
      3RD person and First Person camera modes
      Multiple Spawn Points

    Planned features also will be zones, db access from the server etc for player stats, position, etc.

    This Demo won't be any GameType specific just a networking demo.

    I'm wondering if $25 is a good price for this Demo.

    Here is an example of the ChatClient without the gui etc.

    This is just my debug version and not the finished tutorial code that is using some code from the lidgren samples etc.
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using Lidgren.Network;
    5. using System.Threading;
    6.  
    7. public class ChatMessage
    8.     {
    9.         public string Sender;
    10.         public string Text;
    11.     }
    12.    
    13. public class ClientApp : MonoBehaviour {
    14.    
    15.     public NetClient client;
    16.     public NetPeerConfiguration config;
    17.    
    18.     private static bool s_keepGoing = true;
    19.  
    20.     // Use this for initialization
    21.     void Start () {
    22.        
    23.        
    24.     // create a client with a default configuration
    25.     config = new NetPeerConfiguration("Chat");
    26.     client = new NetClient(config);
    27.     client.Start();
    28.     client.Connect("localhost", 14242);
    29.    
    30.             // Wait half a second to allow server to start up if run via Visual Studio
    31.             Thread.Sleep(500);
    32.             // Send chat message
    33.             //SendMessages("test")
    34.     }
    35.    
    36.    
    37.    
    38.     // Update is called once per frame
    39.     void Update () {
    40.         // create a buffer to read data into
    41.     NetIncomingMessage inc;
    42.    
    43.     RBSChatController rbsCC = GetComponent<RBSChatController>();       
    44.        
    45.    
    46.             // check if any messages has been received
    47.                 while ((inc = client.ReadMessage()) != null)
    48.                 {
    49.                     switch (inc.MessageType)
    50.                     {
    51.                         //case NetIncomingMessageType.ServerDiscovered:
    52.                         //case NetIncomingMessageType.ConnectionRejected:
    53.                             //Console.WriteLine("Rejected: " + buffer.ReadString());
    54.                             //break;
    55.                         case NetIncomingMessageType.DebugMessage:
    56.                         case NetIncomingMessageType.VerboseDebugMessage:
    57.                             //Console.WriteLine(buffer.ReadString());
    58.                             break;
    59.                         case NetIncomingMessageType.StatusChanged:
    60.                             string statusMessage = inc.ReadString();
    61.                             NetConnectionStatus newStatus = (NetConnectionStatus)inc.ReadByte();
    62.                             //rbsCC.AddChatMessage(newStatus.ToString());
    63.                             //Console.WriteLine("New status: " + newStatus + " (" + statusMessage + ")");
    64.                             break;
    65.                         case NetIncomingMessageType.Data:  
    66.                             // The server sent this data!
    67.                            
    68.                             ChatMessage cm = new ChatMessage();
    69.                              inc.ReadAllFields(cm);
    70.                    
    71.                             //Console.WriteLine(msg);
    72.                             rbsCC.AddChatMessage("Received from " + cm.Sender + ": " + cm.Text);
    73.                             break;
    74.                     }
    75.                 }
    76.                
    77.        
    78.             }
    79.    
    80.    
    81.     public void SendMessages(string input){
    82.         // Send chat message
    83.         ChatMessage cm = new ChatMessage();
    84.         cm.Sender = client.UniqueIdentifier.ToString();
    85.         cm.Text = input;
    86.        
    87.         NetOutgoingMessage om = client.CreateMessage();
    88.         om.WriteAllFields(cm);
    89.         client.SendMessage(om, NetDeliveryMethod.ReliableOrdered, 8);
    90.     }
    91. }
    92.  
    [/list]
     
  2. sueds

    sueds

    Joined:
    Sep 18, 2009
    Posts:
    46
    hi !

    25$ sounds fair but be sure to add all lidgren functionality like peer to peer or the ligren mmo stuff if you want to make money. If not I might not want to buy it.

    But that's my opinion.
     
  3. runningbird

    runningbird

    Joined:
    Sep 3, 2009
    Posts:
    381
    What specific MMO and peer to peer stuff would you like to see..

    The demo was going to be just like what you get with the Smartfox demo etc.

    I don't mind adding the other stuff but was thinking of making those modular so if someone wanted a peer to peer game instead of a mmo they could use the same demo etc.
     
  4. sueds

    sueds

    Joined:
    Sep 18, 2009
    Posts:
    46
    I would say how to create a master server using lidgren and allow people to have peer to peer game.

    http://code.google.com/p/lidgren-mmo/

    I haven't look at it but it sound some lidgren side project to create not mmo but 50 to 100 game party.

    he second sound less interesting for my project but I4m sure a lot of people would like to use lidgren to create a 50-100 multiplayer game.

    and it might be it. Also maybe when your tutorial is ready be sure to put it showcase because people didn't really paid attention to it in this networking section.
     
  5. sciguy77

    sciguy77

    Joined:
    Nov 1, 2009
    Posts:
    191
    $25 sounds fair if you include putting multiple characters on the same map and having them interact with one another.
     
  6. runningbird

    runningbird

    Joined:
    Sep 3, 2009
    Posts:
    381
    Yea that's the plan to have it where you can chat with each other and see the other players in the world.
     
  7. liverolA

    liverolA

    Joined:
    Feb 10, 2009
    Posts:
    347
    hi there, i will buy if you can implement this:
    1.make moving smooth(easy i think)
    2.implement the network latency compensation for sync transform
     
  8. runningbird

    runningbird

    Joined:
    Sep 3, 2009
    Posts:
    381
    I will make the movement smoothly and will implement latency compensation.

    Anymore features for this that anyone can think of?
     
  9. liverolA

    liverolA

    Joined:
    Feb 10, 2009
    Posts:
    347
    cool,i will be the first one to buy!!.

    is that diffcult to implment client moving predication??
     
  10. runningbird

    runningbird

    Joined:
    Sep 3, 2009
    Posts:
    381
    Yes the Network prediction is a bit difficult to implement.

    Ok quick update:

    I finally have the local player sending NetworkTransform only when it is different from the last known state.

    Also with the server I'm adding the ability for:
    Login
    Validate User
    GetUserList
    AddUser
    UpdateUser
    DeleteUser

    The user list will be the list of those in the game and it will include their current NetworkTransform so when the client receives the list it will check it's current list and then spawn all remote players.

    This network tutorial will be like the SmartFox tutorial but with more such as the login / verify user

    What kind of login system would you like to see mysql db version? PHP login system, xml list?

    Maybe I will include all three just to make it better.


    Oh btw since I'm using lidgren there will already be 32 different message types.

    I'm using a few of them for the LocalPlayer Transform sending, Remote Players Transform Sending, Server CMD's.

    With the Server CMD's you can put the CMD type at the beginning of the message and use the correct SequenceChannel.

    This way you can create any amount of server commands such as get players inventory, player info, validate user, etc.

    This will only use 1 of the 32 sequence channels leaving many for you to use for whatever you want.

    I'm also using one of the sequence channels for Chat, you could use one of the other sequence channels for other "Chat" channels etc such as combat, guild, zone, etc

    Also with this tutorial you can speed or slow down the sending of movement so if you have a RPG type of game you can send movement every second, 10 milliseconds etc

    But if you are doing a FPS type of game you can send movement updates every frame etc.
     
  11. liverolA

    liverolA

    Joined:
    Feb 10, 2009
    Posts:
    347
    i prefer PHP login system
     
  12. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,153
    I will buy if the tutorial includes a pdf well detailed. :)
     
  13. runningbird

    runningbird

    Joined:
    Sep 3, 2009
    Posts:
    381
    It will include a pdf that is well documented and easy to follow.


    PHP and mySQL will be done in the tutorial.

    The PHP will be handled on the client side where the mySQL Authentication will be handled by the server.
     
  14. ColossalDuck

    ColossalDuck

    Joined:
    Jun 6, 2009
    Posts:
    3,246
    $25? Great price.
     
  15. runningbird

    runningbird

    Joined:
    Sep 3, 2009
    Posts:
    381
    I haven't fallen off the face of the planet yet...just had a ton of personal things to take care of and a new job that I don't have to work 80 + hours a week at.

    Still working on this and will have something soon.
     
  16. runningbird

    runningbird

    Joined:
    Sep 3, 2009
    Posts:
    381
    what does everyone think about the Kaleta.Network distribution library?

    It's built on top of Lidgren and has automatic object syncronization... I've played around with it a bit seems cool

    Going to try to do player movement and remote player movement with it.

    Will update with the results... if this works well then I will have my tutorial finished sooner than I thought.

    Here's a link for Kaleta http://kaleta.codeplex.com/wikipage?title=QuickStart&referringTitle=Home
     
  17. runningbird

    runningbird

    Joined:
    Sep 3, 2009
    Posts:
    381
    Well the Kaleta Library doesn't work well in Visual Studio 2010 for some reason.

    So I went back to just using lidgren's latest version from 11/13/2010

    Made some progress on the handling of the player movement as well as other functions.
     
  18. ColossalDuck

    ColossalDuck

    Joined:
    Jun 6, 2009
    Posts:
    3,246
    Why not use monodevelop?
     
  19. runningbird

    runningbird

    Joined:
    Sep 3, 2009
    Posts:
    381
    True...I just like Visual Studio better than monodevelop.
     
  20. runningbird

    runningbird

    Joined:
    Sep 3, 2009
    Posts:
    381
    Ok I finally have the player movement issues worked out... working on spawn points etc.

    For the tutorial the server will have a Zone / Level spawn point editor or you can edit the Zones.xml file.

    I'll keep working in my spare time to get this to a working demo.
     
  21. jamessimpler

    jamessimpler

    Joined:
    Dec 10, 2009
    Posts:
    4
    Any update for this yet? Would be interested to find out.
     
  22. runningbird

    runningbird

    Joined:
    Sep 3, 2009
    Posts:
    381
    So I have the server side pulling random spawn points and sending the players spawn location to the client.
    No I just have to work out that part.

    Then I'm onto remote player spawning etc.

    Also after these items are done then I'll have it check what map / zone the player is in and pull spawns from that zone.

    I'll keep this updated as soon I have more finished.


    Basic multi-player chat Demo coming soon!
     
    Last edited: Jan 24, 2011
  23. runningbird

    runningbird

    Joined:
    Sep 3, 2009
    Posts:
    381
    Finally got back to working on this ...

    Local player spawning working flawlessly ...
    Remote player spawning is working.

    Remote player movement is my next issue when a player moves they just keep on moving in the direction etc.

    This isn't that big of an issue and should be fixed in the next few days etc.

    So fat this will have

    Chat, Remote players, and projectiles.

    It's also very easy to implement I will make it a package so all you have to do is import it add the prefabs to your game and then edit 3 lines of a config script.

    You'll have to create your Local, remote player, and spawn points.

    soon you'll see the demo.
     
  24. runningbird

    runningbird

    Joined:
    Sep 3, 2009
    Posts:
    381
    WOHOO!!!


    All player movement has been fixed so everything is moving smooth.

    I'm going to clean up the code etc and implement some networked projectiles and add some weapons and we will have a FPS demo..

    So there will be 2 demos
    1. Muli-player Chat
    2. Multi-player FPS


    Note: the FPS demo will only have basic multi-player features and weapons.

    I will be creating a framework from this demo where you will be able to add in stuff such as your basic fps stuff such as weapon switching, score keeping, peer to peer , level switching, etc
     
  25. Tomo-Games

    Tomo-Games

    Joined:
    Sep 20, 2010
    Posts:
    220
    sounds cool keep up the good work. Hope to see a demo soon.
     
  26. runningbird

    runningbird

    Joined:
    Sep 3, 2009
    Posts:
    381
    Wohoo I finally fixed the animations with the remote players although it's not perfect I think it will be enough for a demo.

    I'm going to clean up the project etc and work on getting the basic chat demo up online soon.

    Thanks for all of your patience we will be working on adding projectiles soon.
     
  27. Quietus2

    Quietus2

    Joined:
    Mar 28, 2008
    Posts:
    2,058
    Games generally don't send the animations over the wire. The local client handles animation transitions through changes to it's FSM.
     
  28. runningbird

    runningbird

    Joined:
    Sep 3, 2009
    Posts:
    381
    Yep I was trying to get the animations working correctly for the remote player objects during update so that it would play the run, idle, walk etc animations.

    I'm not sending the animations over the wire just the player information such as speed, rotation, position etc.
     
  29. JFDionne

    JFDionne

    Joined:
    Nov 22, 2010
    Posts:
    9
    Hi runningbird, I'm very interessed to see your work, we are ready to start our projet and we are looking to use lidgren, any idea when you'll release the part 1 of your work? :)
     
  30. runningbird

    runningbird

    Joined:
    Sep 3, 2009
    Posts:
    381
    JFDione I'm hoping to release part 1 next week if you need it sooner just let me know.
     
  31. JFDionne

    JFDionne

    Joined:
    Nov 22, 2010
    Posts:
    9
    hehe, if you ask me, it sure I'll answer you the soon of possible :) but don't wanna to push :)
     
  32. JFDionne

    JFDionne

    Joined:
    Nov 22, 2010
    Posts:
    9
    And, I'll be pay the double for a demo like this one :) but that's my opinion.
     
  33. JFDionne

    JFDionne

    Joined:
    Nov 22, 2010
    Posts:
    9
    Hi runningbirg, don't wanna to push, but, do you have any progress? :)
     
  34. runningbird

    runningbird

    Joined:
    Sep 3, 2009
    Posts:
    381
    it's coming along I should have the server side stuff finished tomorrow, the only thing to work on after that is the soldier animations for the remote player prefab. If you just want the network portion and can make your models work with the network code then I can release this sooner?
     
  35. JFDionne

    JFDionne

    Joined:
    Nov 22, 2010
    Posts:
    9
    sure :) it will be a good start!
     
  36. runningbird

    runningbird

    Joined:
    Sep 3, 2009
    Posts:
    381
    FYI for all who have followed this the network engine does not send / receive animations so you will need to handle them in the remote player class... I have an example of Lerpz in a chat demo etc and now I'm working on the Bootcamp demo.
     
  37. bigballa0831

    bigballa0831

    Joined:
    May 26, 2011
    Posts:
    1
    Hi runningbird, How is the progress coming along? I would love to see what you are working on. I will definitely pay you for your work!
     
  38. JFDionne

    JFDionne

    Joined:
    Nov 22, 2010
    Posts:
    9
    Hello sir, any update on your network code? :) I think I come here and press F5 20x times each hours to be sure I don't miss your "release" date :)
     
  39. runningbird

    runningbird

    Joined:
    Sep 3, 2009
    Posts:
    381
    The only issue I'm working on is removal of remote player objects on client disconnect
    If you want what I have up to now I can release it.

    Currently remote movement, spawn, chat works just fine.
     
  40. JFDionne

    JFDionne

    Joined:
    Nov 22, 2010
    Posts:
    9
    that will be perfect :)
     
  41. runningbird

    runningbird

    Joined:
    Sep 3, 2009
    Posts:
    381
    if more people were willing to pay I could work on this more....I've been working on it during my lunches and nights, and weekends.
     
  42. runningbird

    runningbird

    Joined:
    Sep 3, 2009
    Posts:
    381
    Ok finally have the disconnected players being removed from all connected clients.
    I also added in a player's list to show you all connected players.

    I'm now working on cleaning things up and packaging up the needed scripts etc.

    I'm also starting to write the tutorial finally :)

    If I get some free time I'll even make the projectiles networked....
     
  43. prg

    prg

    Joined:
    May 20, 2011
    Posts:
    15
    good work
     
  44. JFDionne

    JFDionne

    Joined:
    Nov 22, 2010
    Posts:
    9
    hello, any news?
     
  45. runningbird

    runningbird

    Joined:
    Sep 3, 2009
    Posts:
    381
    Just packaged up the scripts etc and now finishing up the implementation document.

    Making some finishing touches on the server application etc.
     
  46. JFDionne

    JFDionne

    Joined:
    Nov 22, 2010
    Posts:
    9
    sound good :)
     
  47. Selfproclaimed

    Selfproclaimed

    Joined:
    Jun 5, 2011
    Posts:
    3
    I'm really looking forward to this, I will gladly pay 25 dollars for this. I do not really like Unity Built in.
     
  48. runningbird

    runningbird

    Joined:
    Sep 3, 2009
    Posts:
    381
    Ok the demo is turning into more of a Network Engine instead of just using lidgren I have built a client / server api that you can place in your game and get a networked game going in a few minutes.

    @JFDionne please go to http://runningbirdstudios.com and sign up so I can give you access to the files.

    The cost of the Network Engine will be $100 and you will receive the chat demo, unity package, implementation documentation, source code for the server/ client and the network engine itself. Also in the near future I will have a FPS starter kit based on the Network engine that will be free to those who purchase the engine.

    The starter kit will be separate in the future for those who want just that for $50 but it will not include the source code for the Network engine, it will include all of the scripts necessary to implement a FPS as well as have a headless server or host your own server .

    For those looking for a lidgren tutorial I'm sorry but it has now turned into a network engine.
    If you want to roll your own using lidgren then I would say look at the chat server / client sample and then implement your own class to send the players movements etc.

    My Network Engine has this already finished so all you have to do is place the local player script on the local player prefab and then add the remote player script on the remote player prefab...set up a few empty game objects with some controller scripts... enter your game name, server ip, and port and you are done.... it's really that easy

    Also with the $100 you get the full source code to the api so you can implement your own functions and message types.

    In the next week I will be fully documenting the source code and adding more documentation to the implementation document.

    Once the FPS starter kit is finished RBS will begin work on the "MMO Kit" since this is the main reason for this network engine in the first place.
     
  49. runningbird

    runningbird

    Joined:
    Sep 3, 2009
    Posts:
    381
    There might be an option for a cheaper access to the Network Engine if you don't require source code access for the api etc

    I might be able to meat the $25 price range for no source code just binary version but it would just include the basic chat demo and the api, documentation etc.

    And if you wanted to get the full source code version later you will only have to pay $75.
     
  50. Selfproclaimed

    Selfproclaimed

    Joined:
    Jun 5, 2011
    Posts:
    3
    This is really cool, But is there any chance you would have any video of how this system works? Or any snippets of example of the engine?
     
unityunity