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

You are not connected. Please login or register

Unity Ninja Unity 3D Forum » FREE Project Downloads & Recources » Scripts » Initializing Servers of all types [Secured, Publc, Private, GameType, etc]

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

View previous topic View next topic Go down  Message [Page 1 of 1]

BryceCain25


SUPER MODERATOR
SUPER MODERATOR
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)

View user profile

developer23


Moderator
Moderator
Thank you for this BryceCain25! Smile

View user profile http://masterdevelopers.altervista.org/

4kbytes. (xezno)


Member [Lv. 3]
Member [Lv. 3]
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.

View user profile

BryceCain25


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

View user profile

BryceCain25


SUPER MODERATOR
SUPER MODERATOR
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!
=)

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

View user profile http://www.youtube.com/user/misterninjaboy

BryceCain25


SUPER MODERATOR
SUPER MODERATOR
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

View user profile

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum