Browse Source

chore: 🚀 start server

tags/0.1.0
gsy1519 3 years ago
parent
commit
3fcfcd7f84
7 changed files with 102 additions and 86 deletions
  1. +1
    -1
      installer/Installer/AssemblyInfo.cs
  2. +14
    -7
      installer/Installer/Model.cs
  3. +29
    -23
      installer/Installer/ViewModel.cs
  4. +1
    -1
      launcher/Launcher/AssemblyInfo.cs
  5. +29
    -27
      logic/Server/Game.cs
  6. +26
    -26
      logic/Server/GameServer.cs
  7. +2
    -1
      logic/Server/Program.cs

+ 1
- 1
installer/Installer/AssemblyInfo.cs View File

@@ -1,6 +1,6 @@
using System.Windows;

[assembly:ThemeInfo(
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, // where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)


+ 14
- 7
installer/Installer/Model.cs View File

@@ -26,15 +26,21 @@ namespace starter.viewmodel.settings
/// <summary>
/// Route of files
/// </summary>
public string Route {
get; set; }
public string Route
{
get; set;
}
/// <summary>
/// if the route was set or is under editing
/// </summary>
public bool HaveRoute {
get; set; }
public bool EditingRoute {
get; set; }
public bool HaveRoute
{
get; set;
}
public bool EditingRoute
{
get; set;
}
/// <summary>
/// downloader function
/// </summary>
@@ -144,7 +150,8 @@ namespace Downloader
GetObjectRequest request = new GetObjectRequest(bucket, key, localDir, localFileName);

Dictionary<string, string> test = request.GetRequestHeaders();
request.SetCosProgressCallback(delegate(long completed, long total) {
request.SetCosProgressCallback(delegate (long completed, long total)
{
Console.WriteLine(String.Format("progress = {0:##.##}%", completed * 100.0 / total));
});
// 执行请求


+ 29
- 23
installer/Installer/ViewModel.cs View File

@@ -22,10 +22,12 @@ namespace starter.viewmodel.settings

public string Route
{
get {
get
{
return obj.Route;
}
set {
set
{
obj.Route = value;
this.RaisePropertyChanged("Route");
}
@@ -33,10 +35,12 @@ namespace starter.viewmodel.settings

public bool CanEditRoute // if the user can still edit install route
{
get {
get
{
return !obj.HaveRoute;
}
set {
set
{
obj.HaveRoute = !value;
obj.EditingRoute = value;
this.RaisePropertyChanged("CanEditRoute");
@@ -46,7 +50,8 @@ namespace starter.viewmodel.settings
private BaseCommand clickBrowseCommand;
public BaseCommand ClickBrowseCommand
{
get {
get
{
if (clickBrowseCommand == null)
{
clickBrowseCommand = new BaseCommand(new Action<object>(o =>
@@ -54,28 +59,29 @@ namespace starter.viewmodel.settings
using (FolderBrowserDialog dialog = new FolderBrowserDialog())
{
_ = dialog.ShowDialog();
if (dialog.SelectedPath != String.Empty)
Route = dialog.SelectedPath;
if (dialog.SelectedPath != String.Empty)
Route = dialog.SelectedPath;
}
}));
}
}));
}
return clickBrowseCommand;
}
}
private BaseCommand clickConfirmCommand;
public BaseCommand ClickConfirmCommand
{
get {
if (clickConfirmCommand == null)
return clickBrowseCommand;
}
}
private BaseCommand clickConfirmCommand;
public BaseCommand ClickConfirmCommand
{
get
{
if (clickConfirmCommand == null)
{
clickConfirmCommand = new BaseCommand(new Action<object>(o =>
{
CanEditRoute = false;
obj.install();
}));
}
obj.install();
}));
}
return clickConfirmCommand;
}
}
}
}
}
}
}

+ 1
- 1
launcher/Launcher/AssemblyInfo.cs View File

@@ -1,6 +1,6 @@
using System.Windows;

[assembly:ThemeInfo(
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, // where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)


+ 29
- 27
logic/Server/Game.cs View File

@@ -18,7 +18,7 @@ namespace Server
public bool IsGaming
{
get => Interlocked.CompareExchange(ref isGaming, 0, 0) != 0;
set => Interlocked.Exchange(ref isGaming, value? 1: 0);
set => Interlocked.Exchange(ref isGaming, value ? 1 : 0);
}

public MessageToClient GetCopiedGameInfo()
@@ -36,14 +36,16 @@ namespace Server
return;
if (player.PlayerType == PlayerType.HumanPlayer)
{
gameInfo.HumanMessage.Add(new MessageOfHuman() {
gameInfo.HumanMessage.Add(new MessageOfHuman()
{
PlayerId = player.PlayerId
});
return;
}
if (player.PlayerType == PlayerType.ButcherPlayer)
{
gameInfo.ButcherMessage.Add(new MessageOfButcher() {
gameInfo.ButcherMessage.Add(new MessageOfButcher()
{
PlayerID = player.PlayerId
});
return;
@@ -65,39 +67,39 @@ namespace Server
() => IsGaming,
() =>
{
lock (gameInfo)
{
for (int i = 0; i < gameInfo.HumanMessage.Count; i++)
{
if (gameInfo.HumanMessage[i] != null)
{
gameInfo.HumanMessage[i].X++;
gameInfo.HumanMessage[i].Y--;
}
}
for (int i = 0; i < gameInfo.ButcherMessage.Count; i++)
{
if (gameInfo.ButcherMessage[i] != null)
{
gameInfo.ButcherMessage[i].X--;
gameInfo.ButcherMessage[i].Y++;
}
}
}
lock (gameInfo)
{
for (int i = 0; i < gameInfo.HumanMessage.Count; i++)
{
if (gameInfo.HumanMessage[i] != null)
{
gameInfo.HumanMessage[i].X++;
gameInfo.HumanMessage[i].Y--;
}
}
for (int i = 0; i < gameInfo.ButcherMessage.Count; i++)
{
if (gameInfo.ButcherMessage[i] != null)
{
gameInfo.ButcherMessage[i].X--;
gameInfo.ButcherMessage[i].Y++;
}
}
}
},
100,
() =>
{
IsGaming = false;
waitHandle.Release();
return 0;
IsGaming = false;
waitHandle.Release();
return 0;
},
gameTime
).Start();
}
}
)
{ IsBackground = true }.Start();
return waitHandle;
}
}
}
}

+ 26
- 26
logic/Server/GameServer.cs View File

@@ -79,42 +79,42 @@ namespace Server
1000,
() =>
{
ReportGame(); // 最后发一次消息,唤醒发消息的线程,防止发消息的线程由于有概率处在 Wait 状态而卡住
return 0;
ReportGame(); // 最后发一次消息,唤醒发消息的线程,防止发消息的线程由于有概率处在 Wait 状态而卡住
return 0;
}
).Start();
})
})
{ IsBackground = true }.Start();
new Thread(() =>
{
waitHandle.Wait();
this.endGameSem.Release();
})
this.endGameSem.Release();
})
{ IsBackground = true }.Start();

}
public void WaitForEnd()
{
this.endGameSem.Wait();
}
}
public void WaitForEnd()
{
this.endGameSem.Wait();
}

public void ReportGame()
{
currentGameInfo = game.GetCopiedGameInfo();
public void ReportGame()
{
currentGameInfo = game.GetCopiedGameInfo();

foreach (var kvp in semaDict)
{
kvp.Value.Item1.Release();
}
foreach (var kvp in semaDict)
{
kvp.Value.Item1.Release();
}

foreach (var kvp in semaDict)
{
kvp.Value.Item2.Wait();
}
}
foreach (var kvp in semaDict)
{
kvp.Value.Item2.Wait();
}
}

public GameServer()
{
}
}
public GameServer()
{
}
}
}

+ 2
- 1
logic/Server/Program.cs View File

@@ -14,7 +14,8 @@ namespace Server
try
{
GameServer gameServer = new();
Grpc.Core.Server server = new Grpc.Core.Server(new[] { new ChannelOption(ChannelOptions.SoReuseport, 0) }) {
Grpc.Core.Server server = new Grpc.Core.Server(new[] { new ChannelOption(ChannelOptions.SoReuseport, 0) })
{
Services = { AvailableService.BindService(gameServer) },
Ports = { new ServerPort("0.0.0.0", 8888, ServerCredentials.Insecure) }
};


Loading…
Cancel
Save