Exemple #1
0
    private void FixedUpdate()
    {
        serverWorldSequenceNumber++;

        //////Debug.Log("<color=blue>inputsequence </color>"+ playerMovingCommandSequenceNumber + "<color=blue>inputs </color> "+ inputs[0]+" "+inputs[1]+" "+inputs[2]+" "+inputs[3]);

        List <WorldGridItem> worldGridItemList = new List <WorldGridItem>();

        for (int i = 0; i < toNetworkTileType.Count; i++)
        {
            List <Vector3Int> positionsOfTile = GridManager.instance.GetAllPositionForTileMap(GridManager.instance.gameStateDependentTileArray[(int)toNetworkTileType[i] - 1].tileMap);
            WorldGridItem     worldGridItem   = new WorldGridItem((int)toNetworkTileType[i], positionsOfTile);
            worldGridItemList.Add(worldGridItem);
        }

        worldUpdatesToBeSentFromServerToClient.Add(new WorldUpdate(serverWorldSequenceNumber, worldGridItemList.ToArray()));

        //Local client sending data
        if (worldUpdatesToBeSentFromServerToClient.Count >= snapShotsInOnePacket)
        {
            if (previousHistoryForWorldUpdatesToBeSentToServerCollection.Count > packetHistorySize)
            {
                previousHistoryForWorldUpdatesToBeSentToServerCollection.RemoveAt(0);
            }
            ServerSend.WorldUpdate(worldUpdatesToBeSentFromServerToClient, previousHistoryForWorldUpdatesToBeSentToServerCollection);

            previousHistoryForWorldUpdatesToBeSentToServerCollection.Add(new PreviousWorldUpdatePacks(worldUpdatesToBeSentFromServerToClient.ToArray()));

            worldUpdatesToBeSentFromServerToClient.Clear();

            //Debug.Log("<color=red>--------------------------------------------------------------------</color>");
        }
    }
Exemple #2
0
    public static void SpawnGridWorld(Packet packet)
    {
        WorldGridItem[] worldItems = new WorldGridItem[packet.ReadInt()];
        for (int i = 0; i < worldItems.Length; i++)
        {
            int tileType = packet.ReadInt();

            int cellPositionCount = packet.ReadInt();

            List <Vector3Int> cellPositionList = new List <Vector3Int>();
            for (int k = 0; k < cellPositionCount; k++)
            {
                Vector3Int cell = packet.ReadVector3Int();
                cellPositionList.Add(cell);
            }

            worldItems[i] = new WorldGridItem(tileType, cellPositionList);
        }

        int worldUpdateSequenceNumber = packet.ReadInt();

        WorldUpdate worldUpdate = new WorldUpdate(worldUpdateSequenceNumber, worldItems);

        ClientSideGameManager.instance.SpawnWorldGridElements(worldUpdate);
    }
Exemple #3
0
    public static void WorldStateUpdated(Packet packet)
    {
        int dataCount = packet.ReadInt();

        for (int j = 0; j < dataCount; j++)
        {
            WorldGridItem[] worldItems = new WorldGridItem[packet.ReadInt()];
            for (int i = 0; i < worldItems.Length; i++)
            {
                int tileType = packet.ReadInt();

                int cellPositionCount = packet.ReadInt();

                List <Vector3Int> cellPositionList = new List <Vector3Int>();
                for (int k = 0; k < cellPositionCount; k++)
                {
                    Vector3Int cell = packet.ReadVector3Int();
                    cellPositionList.Add(cell);
                }

                worldItems[i] = new WorldGridItem(tileType, cellPositionList);
            }

            int worldUpdateSequenceNumber = packet.ReadInt();
            //Debug.LogWarning("<color=green>receiving inputs packet to server </color>playerMovingCommandSequenceNumber : " + worldUpdateSequenceNumber + " w " + inputs[0] + " a " + inputs[1] + " s " + inputs[2] + " d " + inputs[3]);
            ClientSideGameManager.instance.AccumulateWorldUpdatesToBePlayedOnClientFromServer(new WorldUpdate(worldUpdateSequenceNumber, worldItems));
        }

        int previousWorldUpdatePacks = packet.ReadInt();

        for (int i = 0; i < previousWorldUpdatePacks; i++)
        {
            int previousWorldUpdateWorldItemsInPacks = packet.ReadInt();
            for (int j = 0; j < previousWorldUpdateWorldItemsInPacks; j++)
            {
                WorldGridItem[] previousDataWorldItems = new WorldGridItem[packet.ReadInt()];
                for (int k = 0; k < previousDataWorldItems.Length; k++)
                {
                    int tileType          = packet.ReadInt();
                    int cellPositionCount = packet.ReadInt();

                    List <Vector3Int> cellPositionList = new List <Vector3Int>();
                    for (int l = 0; l < cellPositionCount; l++)
                    {
                        Vector3Int cell = packet.ReadVector3Int();
                        cellPositionList.Add(cell);
                    }
                    previousDataWorldItems[k] = new WorldGridItem(tileType, cellPositionList);
                }

                int previousSeqNo = packet.ReadInt();
                ClientSideGameManager.instance.AccumulateWorldUpdatesToBePlayedOnClientFromServer(new WorldUpdate(previousSeqNo, previousDataWorldItems));
            }
        }
    }
    public void SendIntoGame(string playerName)
    {
        serverMasterController = ServerSideGameManager.instance.InstantiatePlayer();
        serverMasterController.Initialise(id, playerName, new Vector3(0.5f, 0.5f, 0f));


        //This will send all other players information to our new player
        foreach (ServerSideClient client in Server.clients.Values)
        {
            if (client.serverMasterController != null)
            {
                if (client.id != id)
                {
                    ServerSend.SpawnPlayer(id, client.serverMasterController);
                }
            }
        }


        //This will send new player information to all other players and themselves
        foreach (ServerSideClient client in Server.clients.Values)
        {
            if (client.serverMasterController != null)
            {
                ServerSend.SpawnPlayer(client.id, serverMasterController);
            }
        }



        List <WorldGridItem> worldGridItemList = new List <WorldGridItem>();

        for (int i = 0; i < ServerSideGameManager.instance.toNetworkTileType.Count; i++)
        {
            List <Vector3Int> positionsOfTile = GridManager.instance.GetAllPositionForTileMap(GridManager.instance.gameStateDependentTileArray[(int)ServerSideGameManager.instance.toNetworkTileType[i] - 1].tileMap);
            WorldGridItem     worldGridItem   = new WorldGridItem((int)ServerSideGameManager.instance.toNetworkTileType[i], positionsOfTile);
            worldGridItemList.Add(worldGridItem);
        }
        WorldUpdate worldUpdate = new WorldUpdate(ServerSideGameManager.instance.serverWorldSequenceNumber, worldGridItemList.ToArray());

        ServerSend.SpawnGridWorld(id, worldUpdate);
    }