UnityNinja Community
Would you like to react to this message? Create an account in a few clicks or log in to continue.

UnityNinja CommunityLog in

UnityNinja - Video Game Development Community, including Resources, Forums, Marketplace & More.


descriptionInitializing Servers of all types [Secured, Publc, Private, GameType, etc] EmptyInitializing Servers of all types [Secured, Publc, Private, GameType, etc]

more_horiz
Hello there! Today I am going to be explaining how you can start running multiplayer servers off of one client, using the Unity engine of course.
To start off with, you need to have already made sure this is a scene running off of a different executable, just so that you have one client and one server and you aren't trying to mix them together =)
By the way this is all in JavaScript =)
Step 1)
Make a new function that will start your server
for example:

Code:

function StartServer () {
}


in this function you need to start writing the code for the master server (Unity's Server)

Code:

Network.incomingPassword = "YourPasswordHere"

Then use this to make sure this server has a public version of their ip address:

Code:

var useNat = !Network.HavePublicAddress();

Finally, this is where you need to make sure which integer is which. The first int is the max connections, the second int is the port number, next is the useNat variable (I talk about this later)

Code:

Network.InitializeServer(32, 25000, useNat);

Alright, it may seem like you are done but we need to actually start the server first. Remember that function we made earlier? We use that in the function Start () function so that is starts up automatically when we startup the server's executable.

Code:

function Start () {
 StartServer();    }



Edit: A little bit more to go!
Now let's register our server with Unity Smile
And make sure our server is dedicated Smile

Code:

MasterServer.dedicatedServer = true;

Code:

MasterServer.RegisterHost("GameType",
         "GameName","Name");


Done! Now make sure to add this script to an empty gameobject and run it on startup, now you have a dedicated server executable! Awesome!

Have any comments? Leave them down below, and I'll answer!
Smile

Last edited by BryceCain25 on Thu Mar 19, 2015 4:27 pm; edited 1 time in total (Reason for editing : Missing issues that are now adressed via the MasterServer registration)

descriptionInitializing Servers of all types [Secured, Publc, Private, GameType, etc] EmptyRe: Initializing Servers of all types [Secured, Publc, Private, GameType, etc]

more_horiz
Thank you for this BryceCain25! Smile

descriptionInitializing Servers of all types [Secured, Publc, Private, GameType, etc] EmptyRe: Initializing Servers of all types [Secured, Publc, Private, GameType, etc]

more_horiz
Thanks for this!
You could also add that you can launch the Unity executable with -nographics (Linux & Windows only) in the command line to launch it without anything showing up, which is great for headless servers, or launch it with -batchmode if you don't want the executable to accept input or display anything. See [You must be registered and logged in to see this link.] for more information.

descriptionInitializing Servers of all types [Secured, Publc, Private, GameType, etc] EmptyRe: Initializing Servers of all types [Secured, Publc, Private, GameType, etc]

more_horiz
developer23 wrote:
Thank you for this BryceCain25! Smile
Sure thing =)

descriptionInitializing Servers of all types [Secured, Publc, Private, GameType, etc] EmptyRe: Initializing Servers of all types [Secured, Publc, Private, GameType, etc]

more_horiz
developer23 wrote:
Thank you for this BryceCain25! Smile
Ohhhh! Nice! Glad to hear there is an alternate way of removing the graphics, as well as launching it with a batch file..I know this is a very common way of starting server files with different windows...awesome!
=)

descriptionInitializing Servers of all types [Secured, Publc, Private, GameType, etc] EmptyRe: Initializing Servers of all types [Secured, Publc, Private, GameType, etc]

more_horiz
Great explanations bryce on your last two script releases! You are really a great contributor to this community Smile

descriptionInitializing Servers of all types [Secured, Publc, Private, GameType, etc] EmptyRe: Initializing Servers of all types [Secured, Publc, Private, GameType, etc]

more_horiz
MisterNinjaBoy wrote:
Great explanations bryce on your last two script releases! You are really a great contributor to this community Smile
Thank you! Very Happy

descriptionInitializing Servers of all types [Secured, Publc, Private, GameType, etc] EmptyRe: Initializing Servers of all types [Secured, Publc, Private, GameType, etc]

more_horiz
privacy_tip Permissions in this forum:
You cannot reply to topics in this forum
power_settings_newLogin to reply