Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink
Share
Go down
avatar
SUPER MODERATOR
SUPER MODERATOR
Posts : 279
Points : 2169
Rep : 58
Join date : 2013-12-16
Age : 17
Location : Boise Idaho United States
View user profile

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

on Thu Mar 19, 2015 4:20 pm
Message reputation : 100% (1 vote)
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)
avatar
Moderator
Moderator
Posts : 329
Points : 2204
Rep : 43
Join date : 2014-03-12
Age : 18
Location : Italy
View user profilehttp://masterdevelopers.altervista.org/

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

on Fri Mar 20, 2015 3:52 pm
Thank you for this BryceCain25! Smile
avatar
Member [Lv. 3]
Member [Lv. 3]
Posts : 28
Points : 1528
Rep : 2
Join date : 2014-10-05
Age : 16
Location : United Kingdom
View user profile

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

on Sun Mar 22, 2015 11:42 am
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.
avatar
SUPER MODERATOR
SUPER MODERATOR
Posts : 279
Points : 2169
Rep : 58
Join date : 2013-12-16
Age : 17
Location : Boise Idaho United States
View user profile

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

on Wed Apr 15, 2015 4:40 pm
developer23 wrote:Thank you for this BryceCain25! Smile
Sure thing =)
avatar
SUPER MODERATOR
SUPER MODERATOR
Posts : 279
Points : 2169
Rep : 58
Join date : 2013-12-16
Age : 17
Location : Boise Idaho United States
View user profile

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

on Wed Apr 15, 2015 4:42 pm
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!
=)
avatar
Admin
Admin
Posts : 608
Points : 3197
Rep : 406
Join date : 2013-12-11
Age : 21
View user profilehttps://www.youtube.com/user/misterninjaboy

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

on Thu Apr 16, 2015 8:44 pm
Great explanations bryce on your last two script releases! You are really a great contributor to this community Smile
avatar
SUPER MODERATOR
SUPER MODERATOR
Posts : 279
Points : 2169
Rep : 58
Join date : 2013-12-16
Age : 17
Location : Boise Idaho United States
View user profile

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

on Wed Apr 22, 2015 5:37 pm
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
Back to top
Permissions in this forum:
You cannot reply to topics in this forum