예제 #1
0
    // CLIENT -> SERVER (NOT MASTER) //
    // sends the client's data to the server.
    void SendDataToServer()
    {
        // gets player position
        byte[] sendData = new byte[clientBufferSize];
        int    index    = 0;

        if (localPlayer == null)
        {
            // searches for local player
            for (int i = 0; i < players.Count; i++)
            {
                PlayerObject p = players[i].player;

                // local player found
                if (p.controllablePlayer)
                {
                    localPlayer = players[i];
                    break;
                }
            }
        }

        // local player is equal to null, so there's nothing to send.
        if (localPlayer == null)
        {
            return;
        }

        // copies data
        byte[] data = localPlayer.GetData();

        Buffer.BlockCopy(data, 0, sendData, index, data.Length);
        index += data.Length;

        client.client.SetSendBufferData(sendData);
    }