Skip to content

Commit a36e8a4

Browse files
committed
Merge branch 'staging' into session-mgr-cmp
2 parents 140000d + 44ebcc5 commit a36e8a4

41 files changed

Lines changed: 2814 additions & 250 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CONTRIBUTING.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Making a Pull Request
2-
* Fork this repository and make sure your local **master** branch is up to date with the main repository.
3-
* Create a new branch for your addition with an appropriate name, e.g. **add-restart-command**
2+
* Fork this repository and make sure your local **staging** branch is up to date with the main repository.
3+
* Create a new branch from the **staging** branch for your addition with an appropriate name, e.g. **add-restart-command**
44
* PRs work by submitting the *entire* branch, so this allows you to continue work without locking up your whole repository.
55
* Commit your changes to that branch, making sure that you **follow the code guidelines below**.
6-
* Submit your branch as a PR to be reviewed.
6+
* Submit your branch as a PR to be reviewed, with Torch's **staging** branch as the base.
77

88
## Naming Conventions
99
* Types: **PascalCase**

‎Jenkins/release.ps1‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
param([string] $ApiBase, [string]$tagName, [string]$authinfo, [string[]] $assetPaths)
2+
Add-Type -AssemblyName "System.Web"
3+
4+
$headers = @{
5+
Authorization = "Basic " + [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($authinfo))
6+
Accept = "application/vnd.github.v3+json"
7+
}
8+
try
9+
{
10+
Write-Output("Checking if release with tag " + $tagName + " already exists...")
11+
$release = Invoke-RestMethod -Uri ($ApiBase+"releases/tags/$tagName") -Method "GET" -Headers $headers
12+
Write-Output(" Using existing release " + $release.id + " at " + $release.html_url)
13+
} catch {
14+
Write-Output(" Doesn't exist")
15+
$rel_arg = @{
16+
tag_name=$tagName
17+
name="Generated $tagName"
18+
body=""
19+
draft=$TRUE
20+
prerelease=$tagName.Contains("alpha") -or $tagName.Contains("beta")
21+
}
22+
Write-Output("Creating new release " + $tagName + "...")
23+
$release = Invoke-RestMethod -Uri ($ApiBase+"releases") -Method "POST" -Headers $headers -Body (ConvertTo-Json($rel_arg))
24+
Write-Output(" Created new release " + $tagName + " at " + $release.html_url)
25+
}
26+
27+
$assetsApiBase = $release.assets_url
28+
Write-Output("Checking for existing assets...")
29+
$existingAssets = Invoke-RestMethod -Uri ($assetsApiBase) -Method "GET" -Headers $headers
30+
$assetLabels = ($assetPaths | ForEach-Object {[System.IO.Path]::GetFileName($_)})
31+
foreach ($asset in $existingAssets) {
32+
if ($assetLabels -contains $asset.name) {
33+
$uri = $asset.url
34+
Write-Output(" Deleting old asset " + $asset.name + " (id " + $asset.id + "); URI=" + $uri)
35+
$result = Invoke-RestMethod -Uri $uri -Method "DELETE" -Headers $headers
36+
}
37+
}
38+
Write-Output("Uploading assets...")
39+
$uploadUrl = $release.upload_url.Substring(0, $release.upload_url.LastIndexOf('{'))
40+
foreach ($asset in $assetPaths) {
41+
$assetName = [System.IO.Path]::GetFileName($asset)
42+
$assetType = [System.Web.MimeMapping]::GetMimeMapping($asset)
43+
$assetData = [System.IO.File]::ReadAllBytes($asset)
44+
$headerExtra = $headers + @{
45+
"Content-Type" = $assetType
46+
Name = $assetName
47+
}
48+
$uri = $uploadUrl + "?name=" + $assetName
49+
Write-Output(" Uploading " + $asset + " as " + $assetType + "; URI=" + $uri)
50+
$result = Invoke-RestMethod -Uri $uri -Method "POST" -Headers $headerExtra -Body $assetData
51+
Write-Output(" ID=" + $result.id + ", found at=" + $result.browser_download_url)
52+
}

‎Jenkinsfile‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,14 @@ node {
5454

5555
archiveArtifacts artifacts: 'bin/x64/Release/Torch*', caseSensitive: false, fingerprint: true, onlyIfSuccessful: true
5656
}
57+
58+
gitVersion = bat(returnStdout: true, script: "@git describe --tags").trim()
59+
gitSimpleVersion = bat(returnStdout: true, script: "@git describe --tags --abbrev=0").trim()
60+
if (gitVersion == gitSimpleVersion) {
61+
stage('Release') {
62+
withCredentials([usernamePassword(credentialsId: 'torch-github', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
63+
powershell "& ./Jenkins/release.ps1 \"https://api.github.com/repos/TorchAPI/Torch/\" \"$gitSimpleVersion\" \"$USERNAME:$PASSWORD\" @(\"bin/torch-server.zip\", \"bin/torch-client.zip\")"
64+
}
65+
}
66+
}
5767
}

‎Torch.API/IChatMessage.cs‎

Lines changed: 0 additions & 31 deletions
This file was deleted.

‎Torch.API/Managers/IChatManagerClient.cs‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using System.Linq;
44
using System.Text;
55
using System.Threading.Tasks;
6+
using Sandbox.Engine.Multiplayer;
7+
using Sandbox.Game.Multiplayer;
68
using VRage.Network;
79

810
namespace Torch.API.Managers
@@ -12,6 +14,38 @@ namespace Torch.API.Managers
1214
/// </summary>
1315
public struct TorchChatMessage
1416
{
17+
/// <summary>
18+
/// Creates a new torch chat message with the given author and message.
19+
/// </summary>
20+
/// <param name="author">Author's name</param>
21+
/// <param name="message">Message</param>
22+
public TorchChatMessage(string author, string message)
23+
{
24+
Timestamp = DateTime.Now;
25+
AuthorSteamId = null;
26+
Author = author;
27+
Message = message;
28+
Font = "Blue";
29+
}
30+
31+
/// <summary>
32+
/// Creates a new torch chat message with the given author and message.
33+
/// </summary>
34+
/// <param name="authorSteamId">Author's steam ID</param>
35+
/// <param name="message">Message</param>
36+
public TorchChatMessage(ulong authorSteamId, string message)
37+
{
38+
Timestamp = DateTime.Now;
39+
AuthorSteamId = authorSteamId;
40+
Author = MyMultiplayer.Static?.GetMemberName(authorSteamId) ?? "Player";
41+
Message = message;
42+
Font = "Blue";
43+
}
44+
45+
/// <summary>
46+
/// This message's timestamp.
47+
/// </summary>
48+
public DateTime Timestamp;
1549
/// <summary>
1650
/// The author's steam ID, if available. Else, null.
1751
/// </summary>

‎Torch.API/Managers/IMultiplayerManagerBase.cs‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,7 @@
77
namespace Torch.API.Managers
88
{
99
/// <summary>
10-
/// Delegate for received messages.
11-
/// </summary>
12-
/// <param name="message">Message data.</param>
13-
/// <param name="sendToOthers">Flag to broadcast message to other players.</param>
14-
public delegate void MessageReceivedDel(IChatMessage message, ref bool sendToOthers);
15-
16-
/// <summary>
17-
/// API for multiplayer related functions.
10+
/// API for multiplayer related functions common to servers and clients.
1811
/// </summary>
1912
public interface IMultiplayerManagerBase : IManager
2013
{

‎Torch.API/Managers/IMultiplayerManagerServer.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
namespace Torch.API.Managers
88
{
9+
/// <summary>
10+
/// API for multiplayer functions that exist on servers and lobbies
11+
/// </summary>
912
public interface IMultiplayerManagerServer : IMultiplayerManagerBase
1013
{
1114
/// <summary>

‎Torch.API/Session/ITorchSession.cs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,15 @@ public interface ITorchSession
2525

2626
/// <inheritdoc cref="IDependencyManager"/>
2727
IDependencyManager Managers { get; }
28+
29+
/// <summary>
30+
/// The current state of the session
31+
/// </summary>
32+
TorchSessionState State { get; }
33+
34+
/// <summary>
35+
/// Event raised when the <see cref="State"/> changes.
36+
/// </summary>
37+
event TorchSessionStateChangedDel StateChanged;
2838
}
2939
}

‎Torch.API/Session/ITorchSessionManager.cs‎

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,20 @@ namespace Torch.API.Session
1717
/// <returns>The manager that will live in the session, or null if none.</returns>
1818
public delegate IManager SessionManagerFactoryDel(ITorchSession session);
1919

20-
/// <summary>
21-
/// Fired when the given session has been completely loaded or is unloading.
22-
/// </summary>
23-
/// <param name="session">The session</param>
24-
public delegate void TorchSessionLoadDel(ITorchSession session);
25-
2620
/// <summary>
2721
/// Manages the creation and destruction of <see cref="ITorchSession"/> instances for each <see cref="Sandbox.Game.World.MySession"/> created by Space Engineers.
2822
/// </summary>
2923
public interface ITorchSessionManager : IManager
3024
{
3125
/// <summary>
32-
/// Fired when a <see cref="ITorchSession"/> has finished loading.
33-
/// </summary>
34-
event TorchSessionLoadDel SessionLoaded;
35-
36-
/// <summary>
37-
/// Fired when a <see cref="ITorchSession"/> has begun unloading.
26+
/// The currently running session
3827
/// </summary>
39-
event TorchSessionLoadDel SessionUnloading;
28+
ITorchSession CurrentSession { get; }
4029

4130
/// <summary>
42-
/// The currently running session
31+
/// Raised when any <see cref="ITorchSession"/> <see cref="ITorchSession.State"/> changes.
4332
/// </summary>
44-
ITorchSession CurrentSession { get; }
33+
event TorchSessionStateChangedDel SessionStateChanged;
4534

4635
/// <summary>
4736
/// Adds the given factory as a supplier for session based managers
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Torch.API.Session
8+
{
9+
/// <summary>
10+
/// Represents the state of a <see cref="ITorchSession"/>
11+
/// </summary>
12+
public enum TorchSessionState
13+
{
14+
/// <summary>
15+
/// The session has been created, and is now loading.
16+
/// </summary>
17+
Loading,
18+
/// <summary>
19+
/// The session has loaded, and is now running.
20+
/// </summary>
21+
Loaded,
22+
/// <summary>
23+
/// The session was running, and is now unloading.
24+
/// </summary>
25+
Unloading,
26+
/// <summary>
27+
/// The session was unloading, and is now unloaded and stopped.
28+
/// </summary>
29+
Unloaded
30+
}
31+
32+
/// <summary>
33+
/// Callback raised when a session's state changes
34+
/// </summary>
35+
/// <param name="session">The session who had a state change</param>
36+
/// <param name="newState">The session's new state</param>
37+
public delegate void TorchSessionStateChangedDel(ITorchSession session, TorchSessionState newState);
38+
}

0 commit comments

Comments
 (0)