Commit 6c977e04 authored by Maxime's avatar Maxime
Browse files

add afk detection on player

parent ce1ea277
......@@ -11,6 +11,7 @@
{
Code = code;
Players = new List<Player>();
CheckAFKPlayers();
}
public int AddPlayer()
......@@ -22,5 +23,17 @@
return player.Id;
}
private void CheckAFKPlayers()
{
Task.Run(() =>
{
while (true)
{
Task.Delay(10000).Wait();
Players.RemoveAll(x => x.Online == false);
}
});
}
}
}
......@@ -7,12 +7,28 @@
public float Y { get; set; }
public bool FlipX { get; set; }
public bool FlipY { get; set; }
public bool Online { get; set; }
public Player(int id)
{
Id = id;
Online = true;
CheckAFK();
}
private void CheckAFK()
{
Task.Run(() =>
{
while (true)
{
var x = X;
var y = Y;
Task.Delay(10000).Wait();
Online = x != X || y != Y;
}
});
}
}
}
......@@ -18,9 +18,9 @@ namespace ZZZZZZ.Entities.Character
private List<Sprite2D> Sprites;
private float internalTimer;
public RemoteCharacter()
public RemoteCharacter(int id = -1)
{
CharacterID = -1;
CharacterID = id;
Node.Scale *= 10;
Sprites = new List<Sprite2D>
{
......
......@@ -32,7 +32,7 @@ namespace ZZZZZZ
var connected = Server.Connect(ip, port);
if (connected)
{
Current.RemotePlayerManager = new RemotePlayerManager(new RemoteCharacter(), Current.LevelManager);
RemotePlayerManager = new RemotePlayerManager(new RemoteCharacter(), Current.LevelManager);
LocalPlayerManager = new LocalPlayerManager(new LocalCharacter(), new KeyboardInput(), LevelManager);
Server.PlayerManager = LocalPlayerManager;
Navigation.Toast.Show("Connected");
......@@ -60,7 +60,7 @@ namespace ZZZZZZ
{
API.Code = gamecode;
}
var joinedID = API.JoinGame();
if (joinedID != -1)
{
......@@ -75,17 +75,29 @@ namespace ZZZZZZ
InvokeOnMain(() =>
{
LevelManager.Load(Assets.Levels.World0);
LocalPlayerManager = new LocalPlayerManager(new LocalCharacter(joinedID), new JoystickInput(), LevelManager);
Navigation.Load(Assets.UI.Menus.Ingame);
LocalPlayerManager = new LocalPlayerManager(new LocalCharacter(joinedID), new JoystickInput(), LevelManager);
RemotePlayerManager = new RemotePlayerManager(new RemoteCharacter((joinedID + 1) % 2), LevelManager);
});
Task.Delay(50).Wait();
Task.Delay(500).Wait();
while (true)
Task.Run(() =>
{
System.Console.WriteLine($"UPDATE {LocalPlayerManager.Character.CharacterID}");
API.UpdateLocal(LocalPlayerManager.Character as LocalCharacter);
Task.Delay(50).Wait();
}
while (true)
{
API.UpdateLocal(LocalPlayerManager.Character as LocalCharacter);
Task.Delay(50).Wait();
}
});
Task.Run(() =>
{
while (true)
{
API.UpdateRemote(RemotePlayerManager.Character as RemoteCharacter);
Task.Delay(50).Wait();
}
});
}
});
......
......@@ -17,16 +17,9 @@ namespace ZZZZZZ.Player
CharacterID = -1;
LevelManager = levelManager;
Character = character;
Server = GameManager.Current.Server;
Application.Current.Update += Current_Update;
}
private void Current_Update(UpdateEventArgs obj)
{
Character.Move(Server.RemotePosition);
Character.Flip = Server.RemoteFlipped;
}
public void Dispawn()
{
(Character as RemoteCharacter).Dispose();
......
......@@ -83,6 +83,7 @@ namespace ZZZZZZ.WebAPIs
var content = get.Result.Content.ReadAsStringAsync();
content.Wait();
var result = content.Result;
return true;
}
catch (Exception ex)
......
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