Esempio n. 1
0
    void OnClientConnected(long aClientId)
    {
        Debug.Log("Calling build terrain with seed " + seed);
        serverNet.CallRPC("BuildTerrain", aClientId, -1, seed);

        // Set the isConnected to true on the player
        foreach (Player p in players)
        {
            if (p.clientId == aClientId)
            {
                p.isConnected = true;
            }
            if (p.playerObject.isSeeking)
            {
                serverNet.CallRPC("PlayerIsSeeker", aClientId, p.playerObject.networkId, p.playerObject.networkId);
            }
            else
            {
                serverNet.CallRPC("PlayerIsNotSeeker", aClientId, p.playerObject.networkId, p.playerObject.networkId);
            }
        }

        /*
         * serverNet.CallRPC("RPCTest", UCNetwork.MessageReceiver.AllClients, -1, 45);
         * ServerNetwork.ClientData data = serverNet.GetClientData(serverNet.SendingClientId);
         * serverNet.CallRPC("NewClientConnected", UCNetwork.MessageReceiver.AllClients, -1, aClientId, "bob");
         */
    }
Esempio n. 2
0
 void OnAddArea(ServerNetwork.AreaChangeInfo info)
 {
     if (objectCurrentlyIt != 0)
     {
         serverNet.CallRPC("SetItState", info.id, objectCurrentlyIt, true);
     }
 }
Esempio n. 3
0
 void Update()
 {
     foreach (var netObjOuter in serverNetwork.networkObjects)
     {
         if (netObjOuter.Value.prefabName == DogPrefabName)            //find a dog
         {
             foreach (var netObjInner in serverNetwork.networkObjects) //compare each person's position to that dog's position
             {
                 if (0.5f > Vector3.Distance(netObjOuter.Value.position, netObjInner.Value.position) &&
                     netObjOuter.Value.networkId != netObjInner.Value.networkId &&
                     netObjInner.Value.prefabName == SheepPrefabName)
                 {
                     serverNetwork.CallRPC("Capture", UCNetwork.MessageReceiver.AllClients, netObjInner.Value.networkId);
                 }
             }
         }
     }
 }//end update
    IEnumerator TestStuff(long aClientId)
    {
        int numClients = 20;
        int numObjects = 45;

        // Create some other clients
        long[] clients     = new long[numClients];
        int[]  clientAreas = new int[numClients];
        for (int i = 0; i < numClients; i++)
        {
            clients[i]     = UnityEngine.Random.Range(int.MaxValue, int.MinValue);
            clientAreas[i] = UnityEngine.Random.Range(0, 50);
            serverNet.CallRPC("UpdateClient", aClientId, -1, clients[i],
                              "" + UnityEngine.Random.Range(0, 256) + "." + UnityEngine.Random.Range(0, 256) + "." + UnityEngine.Random.Range(0, 256) + "." + UnityEngine.Random.Range(0, 256),
                              clientAreas[i],
                              UnityEngine.Random.Range(400, 500),
                              "client");
        }

        // Create some objects
        int[] objects = new int[numObjects];
        for (int i = 0; i < numObjects; i++)
        {
            objects[i] = UnityEngine.Random.Range(1, int.MaxValue);
            int     clientNum     = UnityEngine.Random.Range(0, numClients - 1);
            Vector3 initialPos    = new Vector3(UnityEngine.Random.Range(-500.0f, 500.0f), UnityEngine.Random.Range(-500.0f, 500.0f));
            bool    followsClient = (UnityEngine.Random.Range(0, 10) > 5);

            serverNet.CallRPC("UpdateNetObject", aClientId, -1, objects[i],
                              clientAreas[clientNum],
                              "Monsters/TestMonster/Blah",
                              initialPos,
                              new Quaternion(UnityEngine.Random.Range(-1000.0f, 1000.0f), UnityEngine.Random.Range(-1000.0f, 1000.0f), UnityEngine.Random.Range(-1000.0f, 1000.0f), UnityEngine.Random.Range(-1000.0f, 1000.0f)),
                              followsClient,
                              clients[clientNum]
                              );

            StartCoroutine(UpdateObject(aClientId, objects[i], initialPos, clientAreas[clientNum], clients[clientNum], followsClient));
            yield return(new WaitForSeconds(0.01f));
        }

        yield return(null);
    }
Esempio n. 5
0
    void OnClientConnected(long aClientId)
    {
        Player newPlayer = null;

        // Set the isConnected to true on the player
        foreach (Player p in players)
        {
            if (p.clientId == aClientId)
            {
                p.isConnected = true;
                p.playerId    = ++lastPlayerId;
                serverNet.CallRPC("SetPlayerId", aClientId, -1, p.playerId);
                int teamId = GetTeamId();
                serverNet.CallRPC("SetTeam", aClientId, -1, teamId);
                p.teamId = teamId;

                newPlayer = p;
            }
        }

        if (newPlayer == null)
        {
            Debug.Log("OnClientConnected: Unable to find unknown player for client " + aClientId);
            return;
        }

        // A client has connected, send the data about other connected clients
        for (int i = 0; i < players.Count; i++)
        {
            if (players[i].clientId != aClientId)
            {
                serverNet.CallRPC("NewPlayerConnected", aClientId, -1, players[i].playerId, players[i].teamId);
                if (players[i].name != "")
                {
                    serverNet.CallRPC("PlayerNameChanged", aClientId, -1, players[i].playerId, players[i].name);
                }
                if (players[i].isReady)
                {
                    serverNet.CallRPC("PlayerIsReady", aClientId, -1, players[i].playerId, players[i].isReady);
                }
                if (players[i].playerClass != 0)
                {
                    serverNet.CallRPC("PlayerClassChanged", aClientId, -1, players[i].playerId, (int)(players[i].playerClass));
                }

                // Tell the other client that this player has connected
                serverNet.CallRPC("NewPlayerConnected", players[i].clientId, -1, newPlayer.playerId, newPlayer.teamId);
            }
        }
    }
Esempio n. 6
0
 public void OnClientConnected(long aClientId)
 {
     // When a new client connects, send them a message to start their VoIP service
     serverNet.CallRPC("StartVoIP", aClientId, -1, nextVoIPId);
     nextVoIPId++;
 }
Esempio n. 7
0
 void OnAddArea(ServerNetwork.AreaChangeInfo info)
 {
     serverNet.CallRPC("SetWhoIsIt", info.id, objectCurrentIt);
 }