예제 #1
0
        public IEnumerator SetServer(NetConnection server, NetZone zone)
        {
            zone.Assigned = true;

            if (server != Socket.Self)
            {
                var setServerRequest = Socket.Request.Send <string>("AssignZone", server, zone);

                yield return(setServerRequest.WaitUntilDone);

                if (!setServerRequest.IsSuccessful)
                {
                    zone.Assigned = false;
                    yield break;
                }

                zone.PublicEndpoint = setServerRequest.Result;
            }
            else
            {
                NetZoneServer zoneServ = GetComponent <NetZoneServer>();
                zoneServ.AssignZoneSelf(zone);
            }

            zone.Server         = server;
            zone.ServerEndpoint = zone.Server.Endpoint;
            if (string.IsNullOrEmpty(zone.PublicEndpoint))
            {
                zone.PublicEndpoint = zone.Server.Endpoint.ToString();
            }
            ZoneAssigned(zone);
            NetLog.Info("Server assigned to zone. Endpoint: " + server.Endpoint);
            zone.Available = true;
        }
예제 #2
0
        private void Start() {
            socket = GetComponent<NetSocket>();
            viewManager = GetComponent<NetViewManager>();
            zoneManager = GetComponent<NetZoneManager>();
            zoneServer = GetComponent<NetZoneServer>();

            zoneServer.OnAssignment += AssignedToZone;

            socket.ProtocolAuthority = true;
            socket.AcceptConnections = true;
            socket.MaxConnections = 512;

            socket.Events.OnClientDisconnected += ClientDisconnected;
            socket.Events.OnPeerApproval += PeerApproval;
            socket.Events.OnSocketStart += SocketStart;
            socket.Events.OnFailedToConnect += FailedToConnect;

            socket.StartSocket(ServerAddress + ":" + ServerPortRoot);
            socket.RegisterRpcListener(this);
        }
예제 #3
0
        private void Start() {
            socket = GetComponent<NetSocket>();
            zoneManager = GetComponent<NetZoneManager>();
            zoneServer = GetComponent<NetZoneServer>();

            aiManager = GetComponent<AiManager>();

            ExampleItems.PopulateItemDatabase();

            zoneServer.OnAssignment += AssignedToZone;

            socket.ProtocolAuthority = true;
            socket.AcceptConnections = true;
            socket.MaxConnections = 512;

            socket.Events.OnPeerApproval += PeerApproval;
            socket.Events.OnSocketStart += SocketStart;
            socket.Events.OnFailedToConnect += FailedToConnect;

            socket.StartSocket(ServerAddress + ":" + ServerPortRoot);
            socket.RegisterRpcListener(this);
        }
예제 #4
0
    void OnGUI()
    {
        if (mode == netMode.client)
        {
            if (GUI.Button(new Rect(10, 10, 50, 50), "Client")) { }
        }
        else if (mode == netMode.server)
        {
            if (GUI.Button(new Rect(10, 10, 50, 50), "Server")) { }
            if (GUI.Button(new Rect(10, 70, 50, 50), "Peers"))
            {
                zoneManager.ListPeers();
            }
            if (GUI.Button(new Rect(10, 140, 50, 50), "UPeers"))
            {
                zoneManager.ListUPeers();
            }
        }
        else
        {
            if (GUI.Button(new Rect(10, 10, 50, 50), "Server"))
            {
                mode = netMode.server;
        //                netManager = (GameObject)GameObject.Instantiate(Resources.Load("ServerGameManager"));
                gameObject.AddComponent<NetSocket>();
                socket = GetComponent<NetSocket>();

                gameObject.AddComponent<NetViewManager>();
                viewManager = GetComponent<NetViewManager>();

                gameObject.AddComponent<NetZoneManager>();
                zoneManager = GetComponent<NetZoneManager>();

                gameObject.AddComponent<NetZoneServer>();
                zoneServer = GetComponent<NetZoneServer>();
                zoneServer.OnAssignment += AssignedToZone;

                gameObject.AddComponent<NetScopeManager>();

                socket.ProtocolAuthority = true;
                socket.AcceptConnections = true;
                socket.MaxConnections = 512;

                socket.Events.OnClientDisconnected += ClientDisconnected;
                socket.Events.OnPeerApproval += PeerApproval;
                socket.Events.OnSocketStart += SocketStart;
                socket.Events.OnFailedToConnect += FailedToConnect;

                socket.StartSocket(ServerAddress + ":" + ServerPortRoot);
                socket.RegisterRpcListener(this);
                serverCamera.enabled = true;
            }
            if (GUI.Button(new Rect(10, 70, 50, 30), "Client"))
            {
                mode = netMode.client;
                netManager = (GameObject)GameObject.Instantiate(Resources.Load("ClientGameManager"));
            }
        }
    }