Commit c4463d2c authored by Maxime's avatar Maxime
Browse files

fix afk to short

parent 6c977e04
namespace WebAPI.Model
using System.Diagnostics;
namespace WebAPI.Model
{
public class Game
{
......@@ -29,7 +31,9 @@
{
while (true)
{
Task.Delay(10000).Wait();
Task.Delay(3600000).Wait();
var afkPlayers = Players.Count(x => !x.Online);
Trace.WriteLine($"Cleaning {afkPlayers} afk players(s)");
Players.RemoveAll(x => x.Online == false);
}
});
......
......@@ -37,7 +37,7 @@ namespace WebAPI.Model
{
Task.Delay(10000).Wait();
var unusedGames = Games.Count(x => x.Players.Count == 0);
Trace.WriteLine($"Cleaning {unusedGames} unused game(s)");
Trace.WriteLine($"Cleaning {unusedGames} unused game(s) out of {Games.Count}");
Games.RemoveAll(x => x.Players.Count == 0);
}
});
......
......@@ -25,7 +25,7 @@
{
var x = X;
var y = Y;
Task.Delay(10000).Wait();
Task.Delay(30000).Wait();
Online = x != X || y != Y;
}
});
......
<menu>
<title text="ZZZZZZ" scale="70" x="50" y="15"/>
<input id="ServerIP" text="localhost:3000" scale="20" x="50" y="50" />
<button text="CONNECT" scale="20" x="50" y="70" onClick="MultiplayerConnectClicked" />
<input id="ServerCode" text="enter code" scale="20" x="70" y="50" />
<button text="JOIN" scale="20" x="50" y="50" onClick="MultiplayerJoinClicked" />
<button text="CREATE" scale="20" x="50" y="70" onClick="MultiplayerCreateClicked" />
<image src="back.png" scale="10" x="10" y="80" onClick="MultiplayerBackClicked"/>
</menu>
\ No newline at end of file
......@@ -8,6 +8,7 @@ namespace ZZZZZZ.Entities.Character
public class RemoteCharacter : Entity, ICharacter
{
public int CharacterID { get; set; }
public bool Online { get; set; }
public (bool X, bool Y) Flip
{
......@@ -21,6 +22,7 @@ namespace ZZZZZZ.Entities.Character
public RemoteCharacter(int id = -1)
{
CharacterID = id;
Online = false;
Node.Scale *= 10;
Sprites = new List<Sprite2D>
{
......
using System;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Net;
using System.Net.Http;
using System.Text;
using Urho;
using ZZZZZZ.Entities.Character;
using ZZZZZZ.Objects.Character;
......@@ -14,10 +17,14 @@ namespace ZZZZZZ.WebAPIs
public string Hook { get; }
public HttpClient Client { get; }
public WebAPI(string hook = "https://localhost:5000/")
public WebAPI(string hook = "http://91.170.211.147:5000/")
{
Hook = hook;
Client = new HttpClient();
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
var handler = new HttpClientHandler();
handler.ClientCertificateOptions = ClientCertificateOption.Manual;
handler.ServerCertificateCustomValidationCallback = (httpRequestMessage, cert, cetChain, policyErrors) => { return true; };
Client = new HttpClient(handler);
}
public bool CreateGame()
......@@ -61,6 +68,7 @@ namespace ZZZZZZ.WebAPIs
{
try
{
Console.WriteLine($"Local at\t{(int)player.Node.Position2D.X}\t{(int)player.Node.Position2D.Y}");
var post = Client.PutAsync($"{Hook}Game/SendPlayer?code={Code}&id={player.CharacterID}&x={FormatFloat(player.Node.Position2D.X)}&y={FormatFloat(player.Node.Position2D.Y)}&flipX={player.Flip.X}&flipY={player.Flip.Y}", null);
post.Wait();
var content = post.Result.Content.ReadAsStringAsync();
......@@ -82,9 +90,24 @@ namespace ZZZZZZ.WebAPIs
get.Wait();
var content = get.Result.Content.ReadAsStringAsync();
content.Wait();
var result = content.Result;
return true;
var values = JsonConvert.DeserializeObject<Dictionary<string, string>>(content.Result);
if (values != null)
{
//{"id":1,"x":0,"y":0,"flipX":false,"flipY":false,"online":false}
var x = float.Parse(values["x"], CultureInfo.InvariantCulture);
var y = float.Parse(values["y"], CultureInfo.InvariantCulture);
var flipX = bool.Parse(values["flipX"]);
var flipY = bool.Parse(values["flipY"]);
var online = bool.Parse(values["online"]);
Console.WriteLine($"Remote at\t{(int)x}\t{(int)y}");
remote.Move(new Vector2(x, y));
remote.Flip = (flipX, flipY);
remote.Online = online;
}
return values != null;
}
catch (Exception ex)
{
......@@ -111,7 +134,7 @@ namespace ZZZZZZ.WebAPIs
}
}
private string FormatFloat(float value) => value.ToString("0.00", System.Globalization.CultureInfo.InvariantCulture);
private string FormatFloat(float value) => value.ToString("0.00", CultureInfo.InvariantCulture);
}
}
......@@ -5,6 +5,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="RestSharp" Version="107.2.1" />
<PackageReference Include="UrhoSharp" Version="1.9.67" />
</ItemGroup>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment