Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. We're running great holiday deals on subscriptions, swag and Asset Store packages! Take a peek at this blog for more information!
    Dismiss Notice
  3. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  4. Unity 2017.2 is now released.
    Dismiss Notice
  5. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  6. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  8. Unity 2017.3 beta is now available for download.
    Dismiss Notice

DarkRift - Fast and Flexible Cross Platform Networking

Discussion in 'Assets and Asset Store' started by Jamster, Apr 20, 2015.

  1. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    830
    Not had much time to look I'm afraid!
     
  2. Lisk

    Lisk

    Joined:
    Oct 23, 2013
    Posts:
    90
    Any chance of an update on this? It's a pretty important issue for my game.
     
  3. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    830
    I think I've found the problem, there's a blocking call on send instead of an asynchronous call. I'll remove and that should see a performance increase as well :)

    Jamie
     
  4. Lisk

    Lisk

    Joined:
    Oct 23, 2013
    Posts:
    90
    Oh that's very good news!
     
  5. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    830
    Version 1.4.6 has been released on the asset store!

    This fixes the above issue that meant lagging players caused the entire server to lag and should improve performance as well :)
     
    Lisk likes this.
  6. Kalle801

    Kalle801

    Joined:
    Mar 3, 2013
    Posts:
    46
    Hello dear Dark Rifter. I Need some help cause im completelly new to Coding.
    Could someone post the Code for the "Standard TP and OR FP Character" of unity Standard Assets please?
    I try to get this working but im not able to Code like this.

    This would be very helpfull.

    best Regards and Thanks in Advance.
     
  7. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    830
    I'm afraid I don't have them to hand, I suggest you post in the scripting forum instead as you'll probably get a faster answer!

    I have a feeling the standard assets might have moved to the asset store so maybe check there as well!
     
  8. Basilios03

    Basilios03

    Joined:
    Feb 3, 2014
    Posts:
    2
    Hi, I followed the embedded server you provided with the package to make my own authoritative server project, all was well until I used OnPostPlayerConnect to spawn player. I had to add player spawning to the Enqueue function in the Server class. Since the Action delegate that Enqueue takes doesn't expect any parameters, I had to work around it in a kind-of-hacky way. Am I missing something or should I edit Server.cs to add new delegates?
    Edit: I'm getting a "NotConnectedException" after adding to the queue. Are we not supposed to add events manually?
     
    Last edited: Oct 21, 2017
  9. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    830
    You shouldn't really need to edit the Server.cs file (only in extreme cases), you should just be able to subscribe to the event as normal and spawn the player as you would in the standalone server.

    Can you share more details? :)
     
  10. Basilios03

    Basilios03

    Joined:
    Feb 3, 2014
    Posts:
    2
    Sorry I should've mentioned that it was a threading problem. My guess was that OnPostPlayerConnect is not being handled correctly by Server.cs, or not at all. So I added the spawning function to an event and sent it to the Enqueue function in Server.cs. It's easier to just show you the script :)

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using DarkRift;
    5. using System;
    6.  
    7. public class ServerManager : MonoBehaviour {
    8.     Server server;
    9.     event Action spawnPlayer;
    10.     ConnectionService spawnCon;
    11.  
    12.     private void Awake()
    13.     {
    14.         server = GetComponent<Server>();
    15.     }
    16.  
    17.     void Start()
    18.     {
    19.         spawnPlayer += SpawnPlayer;
    20.         ConnectionService.onData += OnData;
    21.         ConnectionService.onPostPlayerConnect += OnPostPlayerConnect;
    22.     }
    23.  
    24.     private void OnPostPlayerConnect(ConnectionService con)
    25.     {
    26.         Debug.Log("Server: player connected");
    27.         spawnCon = con;
    28.         server.Enqueue(spawnPlayer);
    29.     }
    30.  
    31.     public void SpawnPlayer()
    32.     {
    33.         //Spawn server player.
    34.         ServerPlayer sPlayer = ServerPlayersManager.instance.SpawnPlayer(spawnCon.id);
    35.     }
    36.  
    37.     void OnData(ConnectionService con, ref NetworkMessage data)
    38.     {
    39.     }
    40. }
    41.  
    Initializing directly from OnPostPlayerConnect throws "INTERNAL_CALL_Internal_InstantiateSingle can only be called from the main thread."

    As for the "NotConnectedException", turns out it's because I was sending messages via DarkRiftAPI from the server scene. I'm still trying to find my way around who does what.
     
  11. BadUncleGames

    BadUncleGames

    Joined:
    Aug 10, 2015
    Posts:
    24
    Ho folks,
    This may be a simple question and due to me just getting used to how Darkrift is working but here goes.
    1. I have a dedicated server and three scenes - a login, a character build then a main scene. In standalone this is working fine (it logins via mysql then you can build your UMA and get into the main scene - based on the Yasil.de tutorials)
    2. I have some need of physics and eventually navmesh and from what I read I need to use an embedded server for this

    So my question is, what's the approach for the client changing from login to build to my start scene? Do I put a separate server.cs in an empty unity scene to manage each of three scenes/servers or do i run the start scene in which case how do i use the login and mysql plugins etc.? I'm not clear on the process for this.
    As it will be an mmo style there will be other scenes that characters will eventually switch between etc.

    Any pointers would be appreciated.

    [Edit] - My thoughts about the best way to run this (and happy to be pointed in a better Darkrift direction) is that my login/mysql plugins and scenes could connect to my standalone console server then once authenticated i connect to my embedded server (one per scene or zone) .....with just the Mysql plugin for DB updates (connected to the same DB as the login). Is that a feasible scenario or is there a more efficient way to handle the login/charbuild and then physics embedded scenes?
     
    Last edited: Oct 24, 2017
  12. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    830
    @Basilios03 Yep that's a bug, it's not routed through Server.cs so that'll be fixed soonish :)
    For now you can probably do something similar to this
    Code (csharp):
    1. EnqueueWaitHandle(() => YourOnConnectRoutine).WaitOne();
    which will queue and pause the event until it's executed on the main thread.

    @BadUncleGames You're on the right lines. From what you've said I would probably do this:
    1. Authenticate with a web server over HTTPS and have the webserver store an auth token for the user.
    2. Client connects to the DarkRift embedded server and passes it the token.
    3. DarkRift server checks the token with the database.
    4. Client loads build scene and builds character...
     
  13. Jackk_

    Jackk_

    Joined:
    May 2, 2017
    Posts:
    31
    Hey Jamster, Just want to say I am a massive fan of your work, but I do have an issue that I cannot for the life of me work out how to fix.

    The Problem: The Information sent from my game, isn't getting saved to my MySQL Database.

    Background Information: I have been following Yalis' tutorial on making a MMO in the Unity Engine, and have done everything he has in terms of the coding and database is concerned but for some reason when I send data using DarkRift, It doesn't get stored in the database.

    Stuff Relating to the DarkRift side of things

    I have a network manager assigned to an empty asset on my Unity Game, which determines the port etc: https://gyazo.com/282e0b742fa78fd8d56507d3f23dc2dc
    • This file could be the cause of the problem as the port of my game is 4296 but the port of the MySQL database is 3306
    • This file could also be the cause of the problem as my server is hosted locally but the string IP is "127.0.0.1" so I'm not sure if that should be changed to localhost
    I have Y-Const File: https://gyazo.com/389ddd696bd9375e439c7e7a237ff0c5

    I have a simple Login File: https://gyazo.com/34bafa334cc36a8ed72cc10017955f53

    I have a login manager File: https://gyazo.com/6ce516ff15917b4b2c796a295caceaed
    • The login manager file could also be the cause of the problem as it says SendToServer(Yasil.NT.LoginT, Yasil.NT.LoginS.loginUser, writer) because Yasil was the name that the tutorial used, I'm not sure if it needs to be something different.
    I also have a LoginButton, which basically sends all the information to the database when the login button is pressed on the UI of my Unity Game: https://gyazo.com/39374a5ce0972d1b49ef2643b0650a62

    I also have a MySQL Connector .dll which looks like this: https://gyazo.com/73bd587fcc2a00f80f3860b61faa1335
    *there is more to this image but it seemed irrelevant

    The reason this problem is so hard for me to fix is because when I launch the DarkRift server.exe and Press on the Login button and Add user button, everything on the console seems fine as there are no errors but for some reason the data isn't being sent to my database. Evidence: https://gyazo.com/0000169b652839d3c1000b5499364f76

    Stuff Relating to the SQL Database

    Using MySQL Workbench to make the database

    Database Tables: https://gyazo.com/ff288887c82675315d3320bb7c6c0b2b
    Database Server Status: https://gyazo.com/14ee6c12b9e0f0e1f514b298439b3e5f
    Settings.cnf (The file that knows what my database account is so it can input data using it): https://gyazo.com/c08f5da38a393e5e16ac0f8a80630f9a

    I'm not sure if there are any extra steps that I missed when making my database, so feel free to ask me questions on my setup etc.

    And yes my account is username, password but the account has every possible privilege to all schemas so I really don't understand what is going wrong, if you could please help me solve this problem, I would greatly appreciate it :)
     
  14. Jackk_

    Jackk_

    Joined:
    May 2, 2017
    Posts:
    31
    Issue Resolved
     
    Jamster likes this.
  15. rifttime

    rifttime

    Joined:
    Jun 3, 2017
    Posts:
    2
    Hi,
    i'm trying to test DarkRift but cant figure out.
    I run server on PC, run scene in editor and i get conencted.
    But it don't connect from other PC or Android.
    Unfortunately, i didn't found any instructions for that.
    Can you please help me?
    Thx.
     
  16. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    830
    @Jackk_ Glad you figured out your issue!

    @rifttime Are you running the other PC/android on the same network or are you running from a different network? If the latter, have you port forwarded your router?
     
  17. rifttime

    rifttime

    Joined:
    Jun 3, 2017
    Posts:
    2
    @Jamster i'm running on the same network.
    I didn't change port.
     
  18. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    830
    Hmm... In the case make sure your firewalls are set to give DarkRift access and you can try connecting using Telnet instead to verify if you can connect using a simple example.
     
  19. Nivbot

    Nivbot

    Joined:
    Mar 21, 2015
    Posts:
    5
    Ugh, I am losing my mind trying to figure this out. Aaaaall day looking it up to no avail no matter which networking solution I look at. Darkrift looks really good and I want to use it but I want to start from where I will eventually end up. That might not make sense right now but hear me out.

    I want to work on learning it as I go but I want to start out using my remote machine as other players would remotely. I don’t want to do it from the same machine.

    I already have an apache server hooked up at my home that I can access remotely. How in god’s name do I do this with Darkrift? For instance, how do I put darkrift on a machine with the unity project and say as an example the ip address is 23.123.1.12 to access from outside. How do I set this up? That’s how I want to learn because that’s how I’m going to use it eventually.

    In short, how does ones set up Darkrift to allow for remote connections? Everything just shows using both server and client on one machine. I don’t want that.
     
  20. Nivbot

    Nivbot

    Joined:
    Mar 21, 2015
    Posts:
    5
    Do I just put it on the machine I want use as the server and port forward on its private ip address the set up to use the network’s ip to that machine port from somewhere in the Darkrift server?

    I hope I don’t sound like a complete idiot I’m just not well versed on setting this sort of thing up
     
  21. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    830
    Sounds about right:
    1. Put DarkRift on the server
    2. Port forward your router so port 4296 (unless you change it) directs to port 4296 on your server
    3. Add firewall exceptions if you have one
     
  22. Nivbot

    Nivbot

    Joined:
    Mar 21, 2015
    Posts:
    5
    Just wanted to say thanks. I put the server on my laptop (which will obviously not be used as a real server) and just set port forwarding on 4296 on that machine, changed the example project to connect to my public ip, compiled and ran it on that machine, ran the project from my main computer and voila. It worked.

    Now the real challenge begins
     
    Jamster likes this.