Compare commits

..

1 Commits

Author SHA1 Message Date
Westin Miller
bd9d549607 Auto-release 2017-08-31 19:01:10 -07:00
8 changed files with 47 additions and 102 deletions

View File

@@ -1,9 +1,9 @@
# Making a Pull Request # Making a Pull Request
* Fork this repository and make sure your local **staging** branch is up to date with the main repository. * Fork this repository and make sure your local **master** branch is up to date with the main repository.
* Create a new branch from the **staging** branch for your addition with an appropriate name, e.g. **add-restart-command** * Create a new branch for your addition with an appropriate name, e.g. **add-restart-command**
* PRs work by submitting the *entire* branch, so this allows you to continue work without locking up your whole repository. * PRs work by submitting the *entire* branch, so this allows you to continue work without locking up your whole repository.
* Commit your changes to that branch, making sure that you **follow the code guidelines below**. * Commit your changes to that branch, making sure that you **follow the code guidelines below**.
* Submit your branch as a PR to be reviewed, with Torch's **staging** branch as the base. * Submit your branch as a PR to be reviewed.
## Naming Conventions ## Naming Conventions
* Types: **PascalCase** * Types: **PascalCase**

View File

@@ -16,7 +16,7 @@ try
tag_name=$tagName tag_name=$tagName
name="Generated $tagName" name="Generated $tagName"
body="" body=""
draft=$TRUE draft=$FALSE
prerelease=$tagName.Contains("alpha") -or $tagName.Contains("beta") prerelease=$tagName.Contains("alpha") -or $tagName.Contains("beta")
} }
Write-Output("Creating new release " + $tagName + "...") Write-Output("Creating new release " + $tagName + "...")

4
Jenkinsfile vendored
View File

@@ -59,8 +59,8 @@ node {
gitSimpleVersion = bat(returnStdout: true, script: "@git describe --tags --abbrev=0").trim() gitSimpleVersion = bat(returnStdout: true, script: "@git describe --tags --abbrev=0").trim()
if (gitVersion == gitSimpleVersion) { if (gitVersion == gitSimpleVersion) {
stage('Release') { stage('Release') {
withCredentials([usernamePassword(credentialsId: 'torch-github', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) { withCredentials([usernamePassword(credentialsId: 'e771beac-b3ee-4bc9-82b7-40a6d426d508', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
powershell "& ./Jenkins/release.ps1 \"https://api.github.com/repos/TorchAPI/Torch/\" \"$gitSimpleVersion\" \"$USERNAME:$PASSWORD\" @(\"bin/torch-server.zip\", \"bin/torch-client.zip\")" powershell "./Jenkins/release.ps1 \"https://api.github.com/repos/TorchAPI/Torch/\" \"$gitSimpleVersion\" \"$USERNAME:$PASSWORD\" @(\"bin/torch-server.zip\", \"bin/torch-client.zip\")"
} }
} }
} }

View File

@@ -8,7 +8,6 @@ using System.Net;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Threading;
using NLog; using NLog;
using Torch.Utils; using Torch.Utils;
@@ -85,15 +84,15 @@ quit";
_server = new TorchServer(_config); _server = new TorchServer(_config);
_server.Init(); _server.Init();
if (_config.NoGui || _config.Autostart)
{
new Thread(_server.Start).Start();
}
if (!_config.NoGui) if (!_config.NoGui)
{ {
var ui = new TorchUI(_server); new TorchUI(_server).ShowDialog();
if (_config.Autostart)
new Thread(_server.Start).Start();
ui.ShowDialog();
} }
else
_server.Start();
_resolver?.Dispose(); _resolver?.Dispose();
} }

View File

@@ -131,7 +131,7 @@ namespace Torch.Server.Managers
public void SaveConfig() public void SaveConfig()
{ {
DedicatedConfig.Save(Path.Combine(Torch.Config.InstancePath, CONFIG_NAME)); DedicatedConfig.Save();
Log.Info("Saved dedicated config."); Log.Info("Saved dedicated config.");
try try

View File

@@ -10,9 +10,20 @@
<RowDefinition/> <RowDefinition/>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<ScrollViewer x:Name="ChatScroller" Grid.Row="0" Margin="5,5,5,5" HorizontalScrollBarVisibility="Disabled"> <ListView Grid.Row="0" x:Name="ChatItems" ItemsSource="{Binding ChatHistory}" Margin="5,5,5,5">
<TextBlock x:Name="ChatItems" /> <ScrollViewer HorizontalScrollBarVisibility="Disabled"/>
</ScrollViewer> <ListView.ItemTemplate>
<DataTemplate>
<WrapPanel>
<TextBlock Text="{Binding Timestamp}"/>
<TextBlock Text=" "/>
<TextBlock Text="{Binding Name}" FontWeight="Bold"/>
<TextBlock Text=": "/>
<TextBlock Text="{Binding Message}"/>
</WrapPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Grid Grid.Row="1"> <Grid Grid.Row="1">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition/> <ColumnDefinition/>

View File

@@ -41,32 +41,23 @@ namespace Torch.Server
{ {
_server = (TorchBase)server; _server = (TorchBase)server;
_multiplayer = (MultiplayerManager)server.Multiplayer; _multiplayer = (MultiplayerManager)server.Multiplayer;
ChatItems.Items.Clear();
DataContext = _multiplayer; DataContext = _multiplayer;
ChatItems.Inlines.Clear();
_multiplayer.ChatHistory.ForEach(InsertMessage);
if (_multiplayer.ChatHistory is INotifyCollectionChanged ncc) if (_multiplayer.ChatHistory is INotifyCollectionChanged ncc)
ncc.CollectionChanged += ChatHistory_CollectionChanged; ncc.CollectionChanged += ChatHistory_CollectionChanged;
ChatScroller.ScrollToBottom();
} }
private void ChatHistory_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) private void ChatHistory_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{ {
foreach (IChatMessage msg in e.NewItems) ChatItems.ScrollToItem(ChatItems.Items.Count - 1);
InsertMessage(msg); /*
} if (VisualTreeHelper.GetChildrenCount(ChatItems) > 0)
private void InsertMessage(IChatMessage msg)
{ {
bool atBottom = ChatScroller.VerticalOffset + 8 > ChatScroller.ScrollableHeight;
var span = new Span(); Border border = (Border)VisualTreeHelper.GetChild(ChatItems, 0);
span.Inlines.Add($"{msg.Timestamp} "); ScrollViewer scrollViewer = (ScrollViewer)VisualTreeHelper.GetChild(border, 0);
span.Inlines.Add(new Run(msg.Name) { Foreground = msg.Name == "Server" ? Brushes.DarkBlue : Brushes.Blue }); scrollViewer.ScrollToBottom();
span.Inlines.Add($": {msg.Message}"); }*/
span.Inlines.Add(new LineBreak());
ChatItems.Inlines.Add(span);
if (atBottom)
ChatScroller.ScrollToBottom();
} }
private void SendButton_Click(object sender, RoutedEventArgs e) private void SendButton_Click(object sender, RoutedEventArgs e)

View File

@@ -23,15 +23,6 @@ namespace Torch.Utils
/// Declaring type of the member to access. If null, inferred from the instance argument type. /// Declaring type of the member to access. If null, inferred from the instance argument type.
/// </summary> /// </summary>
public Type Type { get; set; } = null; public Type Type { get; set; } = null;
/// <summary>
/// Assembly qualified name of <see cref="Type"/>
/// </summary>
public string TypeName
{
get => Type?.AssemblyQualifiedName;
set => Type = value == null ? null : Type.GetType(value, true);
}
} }
/// <summary> /// <summary>
@@ -102,19 +93,6 @@ namespace Torch.Utils
[AttributeUsage(AttributeTargets.Field)] [AttributeUsage(AttributeTargets.Field)]
public class ReflectedMethodAttribute : ReflectedMemberAttribute public class ReflectedMethodAttribute : ReflectedMemberAttribute
{ {
/// <summary>
/// When set the parameters types for the method are assumed to be this.
/// </summary>
public Type[] OverrideTypes { get; set; }
/// <summary>
/// Assembly qualified names of <see cref="OverrideTypes"/>
/// </summary>
public string[] OverrideTypeNames
{
get => OverrideTypes.Select(x => x.AssemblyQualifiedName).ToArray();
set => OverrideTypes = value?.Select(x => x == null ? null : Type.GetType(x)).ToArray();
}
} }
/// <summary> /// <summary>
@@ -254,14 +232,10 @@ namespace Torch.Utils
trueParameterTypes = parameters.Skip(1).Select(x => x.ParameterType).ToArray(); trueParameterTypes = parameters.Skip(1).Select(x => x.ParameterType).ToArray();
} }
var invokeTypes = new Type[trueParameterTypes.Length];
for (var i = 0; i < invokeTypes.Length; i++)
invokeTypes[i] = attr.OverrideTypes?[i] ?? trueParameterTypes[i];
MethodInfo methodInstance = trueType.GetMethod(attr.Name ?? field.Name, MethodInfo methodInstance = trueType.GetMethod(attr.Name ?? field.Name,
(attr is ReflectedStaticMethodAttribute ? BindingFlags.Static : BindingFlags.Instance) | (attr is ReflectedStaticMethodAttribute ? BindingFlags.Static : BindingFlags.Instance) |
BindingFlags.Public | BindingFlags.Public |
BindingFlags.NonPublic, null, CallingConventions.Any, invokeTypes, null); BindingFlags.NonPublic, null, CallingConventions.Any, trueParameterTypes, null);
if (methodInstance == null) if (methodInstance == null)
{ {
string methodType = attr is ReflectedStaticMethodAttribute ? "static" : "instance"; string methodType = attr is ReflectedStaticMethodAttribute ? "static" : "instance";
@@ -271,38 +245,13 @@ namespace Torch.Utils
$"Unable to find {methodType} method {attr.Name ?? field.Name} in type {trueType.FullName} with parameters {methodParams}"); $"Unable to find {methodType} method {attr.Name ?? field.Name} in type {trueType.FullName} with parameters {methodParams}");
} }
if (attr is ReflectedStaticMethodAttribute) if (attr is ReflectedStaticMethodAttribute)
{
if (attr.OverrideTypes != null)
{
ParameterExpression[] paramExp =
parameters.Select(x => Expression.Parameter(x.ParameterType)).ToArray();
var argExp = new Expression[invokeTypes.Length];
for (var i = 0; i < argExp.Length; i++)
if (invokeTypes[i] != paramExp[i].Type)
argExp[i] = Expression.Convert(paramExp[i], invokeTypes[i]);
else
argExp[i] = paramExp[i];
field.SetValue(null,
Expression.Lambda(Expression.Call(methodInstance, argExp), paramExp)
.Compile());
}
else
field.SetValue(null, Delegate.CreateDelegate(field.FieldType, methodInstance)); field.SetValue(null, Delegate.CreateDelegate(field.FieldType, methodInstance));
}
else else
{ {
ParameterExpression[] paramExp = ParameterExpression[] paramExp = parameters.Select(x => Expression.Parameter(x.ParameterType)).ToArray();
parameters.Select(x => Expression.Parameter(x.ParameterType)).ToArray();
var argExp = new Expression[invokeTypes.Length];
for (var i = 0; i < argExp.Length; i++)
if (invokeTypes[i] != paramExp[i + 1].Type)
argExp[i] = Expression.Convert(paramExp[i + 1], invokeTypes[i]);
else
argExp[i] = paramExp[i + 1];
field.SetValue(null, field.SetValue(null,
Expression.Lambda(Expression.Call(paramExp[0], methodInstance, argExp), paramExp) Expression.Lambda(Expression.Call(paramExp[0], methodInstance, paramExp.Skip(1)), paramExp)
.Compile()); .Compile());
} }
} }
@@ -338,7 +287,7 @@ namespace Torch.Utils
if (trueType == null && isStatic) if (trueType == null && isStatic)
throw new ArgumentException("Static field setters need their type defined", nameof(field)); throw new ArgumentException("Static field setters need their type defined", nameof(field));
if (!isStatic && trueType == null) if (!isStatic)
trueType = parameters[0].ParameterType; trueType = parameters[0].ParameterType;
} }
else if (attr is ReflectedGetterAttribute) else if (attr is ReflectedGetterAttribute)
@@ -351,7 +300,7 @@ namespace Torch.Utils
if (trueType == null && isStatic) if (trueType == null && isStatic)
throw new ArgumentException("Static field getters need their type defined", nameof(field)); throw new ArgumentException("Static field getters need their type defined", nameof(field));
if (!isStatic && trueType == null) if (!isStatic)
trueType = parameters[0].ParameterType; trueType = parameters[0].ParameterType;
} }
else else
@@ -369,15 +318,10 @@ namespace Torch.Utils
$"Unable to find field or property for {trueName} in {trueType.FullName} or its base types", nameof(field)); $"Unable to find field or property for {trueName} in {trueType.FullName} or its base types", nameof(field));
ParameterExpression[] paramExp = parameters.Select(x => Expression.Parameter(x.ParameterType)).ToArray(); ParameterExpression[] paramExp = parameters.Select(x => Expression.Parameter(x.ParameterType)).ToArray();
Expression instanceExpr = null;
if (!isStatic)
{
instanceExpr = trueType == paramExp[0].Type ? (Expression) paramExp[0] : Expression.Convert(paramExp[0], trueType);
}
MemberExpression fieldExp = sourceField != null MemberExpression fieldExp = sourceField != null
? Expression.Field(instanceExpr, sourceField) ? Expression.Field(isStatic ? null : paramExp[0], sourceField)
: Expression.Property(instanceExpr, sourceProperty); : Expression.Property(isStatic ? null : paramExp[0], sourceProperty);
Expression impl; Expression impl;
if (attr is ReflectedSetterAttribute) if (attr is ReflectedSetterAttribute)
{ {