Need some help on how to make the server active. I tested the connection was working. But when I notice it didn’t update the screen. I build it on window mode. I put the script on the camera.
It only work when it click on the unity3d window to update the server and clients.
client
// Should we hide NAT hosts in the host list?
private var filterNATHosts = false;
private var doneProbingPublicIP = false;
var serverPort = 25000;
function Awake() {
MasterServer.RequestHostList("openworld");
}
function OnGUI() {
GUILayout.Label("server ip: " + MasterServer.ipAddress+" Port:" + MasterServer.port);
if (GUILayout.Button ("Connect Server Test...")) {
ConnectToServer ();
}
if (GUILayout.Button ("Server List...")) {
serverlist ();
}
var i: int;
GUILayout.Label("Player ping values");
for (i=0; i < Network.connections.length; i++) {
GUILayout.Label("Player " +
Network.connections[i] + " - " +
Network.GetAveragePing(Network.connections[i]) + " ms");
}
if (GUILayout.Button ("disconnected")) {
DisconnectServer();
}
}
function ConnectToServer () {
Network.Connect("127.0.0.1", 25000);
}
function serverlist(){
print("checking server list..." + MasterServer.PollHostList().length);
if (MasterServer.PollHostList().length != 0) {
var hostData: HostData[] = MasterServer.PollHostList();
for (var i:int=0; i<hostData.length; i++) {
print("Game name: " + hostData[i].gameName);
}
}
}
function OnConnectedToServer() {
// Send local player name to server ...
print("Connected to server");
}
function DisconnectServer () {
Network.Disconnect();
}
function OnDisconnectedFromServer(info : NetworkDisconnection) {
if (Network.isServer) {
print("Local server connection disconnected");
}
else {
if (info == NetworkDisconnection.LostConnection)
print("Lost connection to the server");
else
print("Successfully diconnected from the server");
}
}
server
DontDestroyOnLoad(this);
var gameName = "You must change this";
var serverPort = 25002;
private var timeoutHostList = 0.0;
private var lastHostListRequest = -1000.0;
private var hostListRefreshTimeout = 10.0;
private var natCapable : ConnectionTesterStatus = ConnectionTesterStatus.Undetermined;
private var filterNATHosts = false;
private var probingPublicIP = false;
private var doneTesting = false;
private var timer : float = 0.0;
private var windowRect = Rect (Screen.width-300,0,300,100);
private var hideTest = false;
private var testMessage = "Undetermined NAT capabilities";
function Update() {
// If test is undetermined, keep running
//if (!doneTesting) {
//TestConnection();
//}
}
function Awake()
{
//if (FindObjectOfType(ConnectGuiMasterServer))
//this.enabled = false;
MasterServer.dedicatedServer = true;
}
function OnGUI() {
if (GUILayout.Button ("Start Server")) {
LaunchServer ();
}
if (GUILayout.Button ("Server List")) {
serverlist ();
}
GUILayout.Label("server ip: " + MasterServer.ipAddress+" Port:" + MasterServer.port);
if (GUILayout.Button ("Disconnect from server")) {
if (Network.connections.length == 1) {
Debug.Log("Disconnecting: "+
Network.connections[0].ipAddress+":"+Network.connections[0].port);
Network.CloseConnection(Network.connections[0], true);
} else if (Network.connections.length == 0)
Debug.Log("No one is connected");
else if (Network.connections.length > 1)
Debug.Log("Too many connections. Are we running a server?");
}
if (GUILayout.Button ("Disconnect first player")) {
if (Network.connections.length > 0) {
Debug.Log("Disconnecting: "+
Network.connections[0].ipAddress+":"+Network.connections[0].port);
Network.CloseConnection(Network.connections[0], true);
}
}
var i: int;
GUILayout.Label("Player ping values");
for (i=0; i < Network.connections.length; i++) {
GUILayout.Label("Player " +
Network.connections[i] + " - " +
Network.GetAveragePing(Network.connections[i]) + " ms");
}
}
function LaunchServer () {
//Network.incomingPassword = "HolyMoly";
//Network.proxyIP = "127.0.0.1";
Network.InitializeServer(32, 25000);
//RegisterHost (gameTypeName : string, gameName : string, comment : string = "")
MasterServer.RegisterHost("openworld", "nonamegame", "l33t game for all");
print("init... server..." + Network.proxyIP);
}
function serverlist(){
print("checking server list..." + MasterServer.PollHostList().length);
if (MasterServer.PollHostList().length != 0) {
var hostData: HostData[] = MasterServer.PollHostList();
for (var i:int=0; i<hostData.length; i++) {
print("Game name: " + hostData[i].gameName);
}
//MasterServer.ClearHostList();
}
}
function StopServer () {
Network.Disconnect();
MasterServer.UnregisterHost();
print("stopping server..." + Network.proxyIP);
print("server ip: " + MasterServer.ipAddress+" Port:" + MasterServer.port);
}
I need to have an active window while being update the connection for the server to client stuff. Can any one help?