Skip to content

Commit

Permalink
Merge branch 'release/v0.7.3' into 'main'
Browse files Browse the repository at this point in the history
chore: Merge release v0.7.3 into main

See merge request elympics/unity-sdk-package!195
  • Loading branch information
Dawid Sygocki committed Jun 29, 2023
2 parents 7e36cad + 132236d commit 9469bc1
Show file tree
Hide file tree
Showing 50 changed files with 629 additions and 241 deletions.
4 changes: 3 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ default:

.node_before_script: &node_before_script
before_script:
- npm install -g conventional-changelog-cli
- npm install -g conventional-changelog-cli@2.2.2

.unity_before_script: &unity_before_script
before_script:
Expand Down Expand Up @@ -178,6 +178,8 @@ test:editmode:
artifacts: false
- job: test:editmode
artifacts: false
inherit:
variables: false
variables:
CI_ELYMPICS_SDK_VERSION_OVERRIDE: $CI_COMMIT_SHA
CI_ELYMPICS_SDK_SOURCE_OVERRIDE: "$CI_PROJECT_URL.git"
Expand Down
9 changes: 5 additions & 4 deletions .scripts/ci/bump_version_and_generate_changelog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ set -e
echo "Branch: $BRANCH_VERSION"
echo "Package: $PACKAGE_VERSION"

verlte() {
[ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]
function verlte {
[ "$1" = "$(echo -e "$1\n$2" | sort -V | head -n1)" ]
}

if verlte $BRANCH_VERSION $PACKAGE_VERSION; then
if verlte "$BRANCH_VERSION" "$PACKAGE_VERSION"; then
echo "Trying to release invalid version: $BRANCH_VERSION"
exit 1
fi

echo "Running changelog generation..."

node ./.scripts/ci/update_version.js ../../package.json ../../Runtime/AssemblyInfo.cs $BRANCH_VERSION
node ./.scripts/ci/update_version.js ../../package.json ../../Runtime/AssemblyInfo.cs "$BRANCH_VERSION"
node ./.scripts/ci/update_version.js ../../package.json ../../Editor/AssemblyInfo.cs "$BRANCH_VERSION"

echo "Version updated"
echo "Generating changelog..."
Expand Down
2 changes: 1 addition & 1 deletion .scripts/ci/commit_changelog_and_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set -e

git add package.json Runtime/AssemblyInfo.cs CHANGELOG.md
git commit -m "chore: Bump version and add changelog for version $BRANCH_VERSION"
git push gitlab_origin HEAD:$CI_COMMIT_BRANCH -o ci.skip
git push gitlab_origin "HEAD:$CI_COMMIT_BRANCH" -o ci.skip
10 changes: 5 additions & 5 deletions .scripts/ci/create_testing_project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ echo "Creating Testing Project"
PACKAGE_FOLDER=${UNITY_DIR}/Assets/ElympicsSDK/

${UNITY_EXECUTABLE:-xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' unity-editor} \
-createProject $UNITY_DIR \
-createProject "$UNITY_DIR" \
-logFile /dev/stdout \
-batchmode \
-nographics \
Expand All @@ -22,9 +22,9 @@ fi

echo "Moving Package files to appropriate directories"

mkdir -p ${PACKAGE_FOLDER}
cp -r Editor ${PACKAGE_FOLDER}
cp -r Runtime ${PACKAGE_FOLDER}
cp -r Tests ${PACKAGE_FOLDER}
mkdir -p "$PACKAGE_FOLDER"
cp -r Editor "$PACKAGE_FOLDER"
cp -r Runtime "$PACKAGE_FOLDER"
cp -r Tests "$PACKAGE_FOLDER"

echo "Elympics moved ✅"
2 changes: 1 addition & 1 deletion .scripts/ci/ensure_tag_does_not_exist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fi

TAG=$1

git rev-parse -q --verify $TAG
git rev-parse -q --verify "$TAG"

RESULT=$?
if [ $RESULT -ne 0 ]; then
Expand Down
3 changes: 1 addition & 2 deletions .scripts/ci/get_activation_file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
-username "$UNITY_USERNAME" -password "$UNITY_PASSWORD" |
tee ./unity-output.log

cat ./unity-output.log |
grep 'LICENSE SYSTEM .* Posting *' |
grep 'LICENSE SYSTEM .* Posting *' ./unity-output.log |
sed 's/.*Posting *//' > "${activation_file}"

# Fail job if unity.alf is empty
Expand Down
14 changes: 7 additions & 7 deletions .scripts/ci/semver_from_branch.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#!/usr/bin/env bash

if [ $# -ne 1 ]; then
echo "Usage: ./semver_from_brach release/v0.2.4"
echo "Usage: ./semver_from_brach hotfix/v0.2.4"
echo "Usage: ./semver_from_branch release/v0.2.4"
echo "Usage: ./semver_from_branch hotfix/v0.2.4"
exit 1
fi

DESCRIBE=$1

if [[ "${DESCRIBE}" =~ ^(release|hotfix)/v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
FULL_VERSION=`echo $DESCRIBE | awk '{split($0,a,"/v"); print a[2]}'`
MAJOR=`echo $FULL_VERSION | awk '{split($0,a,"."); print a[1]}'`
MINOR=`echo $FULL_VERSION | awk '{split($0,a,"."); print a[2]}'`
PATCH=`echo $FULL_VERSION | awk '{split($0,a,"."); print a[3]}'`
FULL_VERSION=$(echo "$DESCRIBE" | awk '{split($0,a,"/v"); print a[2]}')
MAJOR=$(echo "$FULL_VERSION" | awk '{split($0,a,"."); print a[1]}')
MINOR=$(echo "$FULL_VERSION" | awk '{split($0,a,"."); print a[2]}')
PATCH=$(echo "$FULL_VERSION" | awk '{split($0,a,"."); print a[3]}')

echo ${MAJOR}.${MINOR}.${PATCH}
echo "${MAJOR}.${MINOR}.${PATCH}"
else
echo "Invalid version. Expected format (release|hotfix)/vX.X.X"
exit 1
Expand Down
2 changes: 1 addition & 1 deletion .scripts/ci/semver_from_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ fi

PACKAGE_PATH=$1

cat ${PACKAGE_DIR:-.}/$PACKAGE_PATH | jq -r '.version'
jq -r '.version' "${PACKAGE_DIR:-.}/$PACKAGE_PATH"
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## [0.7.3](https://github.com/Elympics/Unity-SDK/compare/v0.7.2...v0.7.3) (2023-06-29)


### Bug Fixes 🪲

* Fix the format of Ethereum address used in EthAddr authentication ([29deca5](https://github.com/Elympics/Unity-SDK/commit/29deca522ddddebefadedda68a0eabe24d293a48))
* Make CI-targeted build method throw on error ([719da0d](https://github.com/Elympics/Unity-SDK/commit/719da0dadccb79e6db1d78d37aac87a0a8bf78d8))
* Make real player count (retrieved from match data) available through ElympicsGameConfig.Players ([0ca518b](https://github.com/Elympics/Unity-SDK/commit/0ca518bef2e9df20e6b80898ecbaaa06385a9794))
* Mark implicit ElympicsVar cast as deprecated ([561ed5d](https://github.com/Elympics/Unity-SDK/commit/561ed5d33f5d42dbdf682e3d34b2abbd1dc88639))



## [0.7.2](https://github.com/Elympics/Unity-SDK/compare/v0.7.1...v0.7.2) (2023-06-22)


Expand Down
7 changes: 7 additions & 0 deletions Editor/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System.Reflection;
using System.Runtime.CompilerServices;

[assembly: AssemblyCompany("Elympics")]
[assembly: AssemblyProduct("Elympics SDK")]
[assembly: AssemblyVersion("0.7.3.0")]
[assembly: InternalsVisibleTo("Elympics.Editor.Tests")]
3 changes: 3 additions & 0 deletions Editor/AssemblyInfo.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 11 additions & 7 deletions Editor/ElympicsWebIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Text;
using System.Web;
using JetBrains.Annotations;
using Newtonsoft.Json;
using UnityEditor;
using UnityEngine;
Expand Down Expand Up @@ -370,13 +371,16 @@ private static void HandleUploadResults(ElympicsGameConfig currentGameConfig, Un
Debug.Log($"Uploaded game {currentGameConfig.GameName} with version {currentGameConfig.GameVersion}");
}

[UsedImplicitly]
public static void BuildAndUploadServerInBatchmode(string username, string password)
{
var gameConfig = ElympicsConfig.LoadCurrentElympicsGameConfig();
if (gameConfig == null)
throw new ArgumentNullException("No elympics game config found. Configure your game first before trying to build a server.");
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
throw new ArgumentNullException($"Login credentials not found.");
throw new ElympicsException("No Elympics game config found. Configure your game before trying to build a server.");
if (string.IsNullOrEmpty(username))
throw new ArgumentNullException(nameof(username));
if (string.IsNullOrEmpty(password))
throw new ArgumentNullException(nameof(password));

var loginOp = Login(username, password);

Expand All @@ -385,17 +389,17 @@ public static void BuildAndUploadServerInBatchmode(string username, string passw
LoginHandler(loginOp.webRequest);

if (!ElympicsConfig.IsLogin)
throw new Exception("Login operation failed. Check log for details");
throw new ElympicsException("Login operation failed. Check log for details");

if (!BuildTools.BuildElympicsServerLinux())
return;
throw new ElympicsException("Build failed");

var currentGameConfig = ElympicsConfig.LoadCurrentElympicsGameConfig();
if (!TryPack(currentGameConfig.GameId, currentGameConfig.GameVersion, BuildTools.EnginePath, EngineSubdirectory, out var enginePath))
throw new Exception("Problem with packing engine");
throw new ElympicsException("Problem with packing engine");

if (!TryPack(currentGameConfig.GameId, currentGameConfig.GameVersion, BuildTools.BotPath, BotSubdirectory, out var botPath))
throw new Exception("Problem with packing bot");
throw new ElympicsException("Problem with packing bot");

var url = GetCombinedUrl(ElympicsWebEndpoint, GamesRoutes.BaseRoute, currentGameConfig.GameId, GamesRoutes.GameVersionsRoute);
var uploadOp = ElympicsEditorWebClient.SendEnginePostRequestApi(url, currentGameConfig.GameVersion, new[] { enginePath, botPath });
Expand Down
5 changes: 4 additions & 1 deletion Runtime/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System.Reflection;
using System.Runtime.CompilerServices;

[assembly: AssemblyCompany("Elympics")]
[assembly: AssemblyProduct("Elympics SDK")]
[assembly: AssemblyVersion("0.7.3.0")]
[assembly: InternalsVisibleTo("Elympics.Tests")]
[assembly: InternalsVisibleTo("Elympics.Editor")]
[assembly: AssemblyVersion("0.7.2.0")]
[assembly: InternalsVisibleTo("Elympics.Editor.Tests")]
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void OnPostStateDeserialize()
{
for (var i = 0; i < _layerStatuses.Length; i++)
if (_layerStatuses[i].Enabled)
Animator.SetLayerWeight(i, _layerWeights.Values[i]);
Animator.SetLayerWeight(i, _layerWeights.Values[i].Value);

for (var i = 0; i < _boolStatuses.Count; i++)
if (_boolStatuses[i].Enabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ElympicsGameObjectActiveSynchronizer : MonoBehaviour, IStateSeriali

public void OnPostStateDeserialize()
{
gameObject.SetActive(_gameObjectActive);
gameObject.SetActive(_gameObjectActive.Value);
}

public void OnPreStateSerialize()
Expand Down
20 changes: 10 additions & 10 deletions Runtime/BehaviourPredefined/ElympicsRigidBody2DSynchronizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,25 @@ public void Initialize()
public void OnPostStateDeserialize()
{
if (_position.EnabledSynchronization)
Rigidbody2D.position = _position;
Rigidbody2D.position = _position.Value;
if (_rotation.EnabledSynchronization)
Rigidbody2D.rotation = _rotation;
Rigidbody2D.rotation = _rotation.Value;
if (_velocity.EnabledSynchronization)
Rigidbody2D.velocity = _velocity;
Rigidbody2D.velocity = _velocity.Value;
if (_angularVelocity.EnabledSynchronization)
Rigidbody2D.angularVelocity = _angularVelocity;
Rigidbody2D.angularVelocity = _angularVelocity.Value;
if (_drag.EnabledSynchronization)
Rigidbody2D.drag = _drag;
Rigidbody2D.drag = _drag.Value;
if (_angularDrag.EnabledSynchronization)
Rigidbody2D.angularDrag = _angularDrag;
Rigidbody2D.angularDrag = _angularDrag.Value;
if (_inertia.EnabledSynchronization)
Rigidbody2D.inertia = _inertia;
Rigidbody2D.inertia = _inertia.Value;
if (SynchronizeMass)
Rigidbody2D.mass = _mass;
Rigidbody2D.mass = _mass.Value;
if (_gravityScale.EnabledSynchronization)
Rigidbody2D.gravityScale = _gravityScale;
Rigidbody2D.gravityScale = _gravityScale.Value;
if (_isKinematic.EnabledSynchronization)
Rigidbody2D.isKinematic = _isKinematic;
Rigidbody2D.isKinematic = _isKinematic.Value;
}

public void OnPreStateSerialize()
Expand Down
18 changes: 9 additions & 9 deletions Runtime/BehaviourPredefined/ElympicsRigidBodySynchronizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,23 @@ public void Initialize()
public void OnPostStateDeserialize()
{
if (_position.EnabledSynchronization)
Rigidbody.position = _position;
Rigidbody.position = _position.Value;
if (_rotation.EnabledSynchronization)
Rigidbody.rotation = _rotation;
Rigidbody.rotation = _rotation.Value;
if (_velocity.EnabledSynchronization)
Rigidbody.velocity = _velocity;
Rigidbody.velocity = _velocity.Value;
if (_angularVelocity.EnabledSynchronization)
Rigidbody.angularVelocity = _angularVelocity;
Rigidbody.angularVelocity = _angularVelocity.Value;
if (_mass.EnabledSynchronization)
Rigidbody.mass = _mass;
Rigidbody.mass = _mass.Value;
if (_drag.EnabledSynchronization)
Rigidbody.drag = _drag;
Rigidbody.drag = _drag.Value;
if (_angularDrag.EnabledSynchronization)
Rigidbody.angularDrag = _angularDrag;
Rigidbody.angularDrag = _angularDrag.Value;
if (_useGravity.EnabledSynchronization)
Rigidbody.useGravity = _useGravity;
Rigidbody.useGravity = _useGravity.Value;
if (_isKinematic.EnabledSynchronization)
Rigidbody.isKinematic = _isKinematic;
Rigidbody.isKinematic = _isKinematic.Value;
}

public void OnPreStateSerialize()
Expand Down
6 changes: 3 additions & 3 deletions Runtime/BehaviourPredefined/ElympicsTransformSynchronizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public void OnPostStateDeserialize()
{
var cachedTransform = transform;
if (_localPosition.EnabledSynchronization)
cachedTransform.localPosition = _localPosition;
cachedTransform.localPosition = _localPosition.Value;
if (_localScale.EnabledSynchronization)
cachedTransform.localScale = _localScale;
cachedTransform.localScale = _localScale.Value;
if (_localRotation.EnabledSynchronization)
cachedTransform.localRotation = _localRotation;
cachedTransform.localRotation = _localRotation.Value;
}

public void OnPreStateSerialize()
Expand Down
35 changes: 29 additions & 6 deletions Runtime/Communication/Remote/RemoteAuthClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using Elympics.Models.Authentication;
using AuthRoutes = Elympics.Models.Authentication.Routes;
Expand All @@ -13,6 +14,9 @@ internal class RemoteAuthClient : IAuthClient
// TODO: softcode this address ~dsygocki 2023-04-19
private const string AuthBaseUrl = "https://api.elympics.cc/v2/auth";

private readonly Regex _ethAddressRegex = new Regex("^(0x)?[0-9a-f]{40}$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
private readonly Regex _ethSignatureRegex = new Regex("^(0x)?[0-9a-f]{130}$", RegexOptions.IgnoreCase | RegexOptions.Compiled);

private readonly string _clientSecretAuthUrl;
private readonly string _ethAddressNonceUrl;
private readonly string _ethAddressAuthUrl;
Expand Down Expand Up @@ -52,9 +56,18 @@ public async void AuthenticateWithEthAddress(IEthSigner ethSigner, Action<Result
return;
}

ethAddress = ethAddress.StartsWith("0x", true, CultureInfo.InvariantCulture)
? ethAddress.Substring(2)
: ethAddress;
var addressMatch = _ethAddressRegex.Match(ethAddress);
if (!addressMatch.Success)
{
onResult(Result<AuthData, string>.Failure(
$"Invalid format for address provided by {nameof(IEthSigner)}.{nameof(IEthSigner.ProvideAddressAsync)}: "
+ ethAddress));
return;
}

var addressHasPrefix = addressMatch.Groups[1].Success;
if (!addressHasPrefix)
ethAddress = "0x" + ethAddress;

var nonceRequest = new EthAddressNonceRequest { address = ethAddress };
ElympicsWebClient.SendPutRequest<string>(_ethAddressNonceUrl, nonceRequest, callback: OnNonceResponse, ct: ct);
Expand Down Expand Up @@ -87,14 +100,24 @@ async void OnNonceResponse(Result<string, Exception> result)
return;
}

if (signature.StartsWith("0x", true, CultureInfo.InvariantCulture))
signature = signature.Substring(2);
var signatureMatch = _ethSignatureRegex.Match(signature);
if (!signatureMatch.Success)
{
onResult(Result<AuthData, string>.Failure(
$"Invalid format for signature provided by {nameof(IEthSigner)}.{nameof(IEthSigner.SignAsync)}: "
+ signature));
return;
}

var signatureHasPrefix = signatureMatch.Groups[1].Success;
if (!signatureHasPrefix)
signature = "0x" + signature;

var authRequest = new EthAddressAuthRequest
{
address = ethAddress,
msg = hexEncodedMessage,
sig = signature
sig = signature,
};
ElympicsWebClient.SendPostRequest<AuthenticationDataResponse>(_ethAddressAuthUrl, authRequest, callback: OnAuthResponse, ct: ct);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ internal override void Commit()

public override string ToString() => Value?.ToString() ?? "null";

[Obsolete("Refrain from using implicit casts to " + nameof(ElympicsVar) + " value as it reduces readability.")]
public static implicit operator T(ElympicsVar<T> v) => v.Value;

public override void Deserialize(BinaryReader br, bool ignoreTolerance = false)
Expand Down

0 comments on commit 9469bc1

Please sign in to comment.