ReboundEmulator/Core/Player.cs
Moonbase 2631d3199c Implement Multiplayer Support
Implement Custom Screen Name Support
2026-10-06 19:00:15 -07:00

40 lines
1.2 KiB
C#

using NotPogo.Core.Rooms;
using System.Net.Sockets;
namespace NotPogo.Core
{
public sealed class Player
{
static int _nextId;
public int Id { get; } = Interlocked.Increment(ref _nextId);
public Account? Account { get; set; }
public string ScreenName { get; set; } = "Guest";
public string ProfileId { get; set; } = "100000000000";
public string LoginKey { get; set; } = "";
public Room? Room { get; set; }
public DateTime? LastSeen { get; set; }
readonly NetworkStream _stream;
readonly SemaphoreSlim _writeLock = new(1, 1);
public Player(NetworkStream stream) => _stream = stream;
public async Task SendAsync(params(string key, string value)[] fields)
{
var msg = new Dictionary<string, string>();
foreach(var (k, v) in fields) msg[k] = v;
await SendAsync(msg);
}
public async Task SendAsync(Dictionary<string, string> msg)
{
await _writeLock.WaitAsync();
try { await TCPProtocol.WriteMessageAsync(_stream, msg); }
catch(IOException) {}
catch(ObjectDisposedException) {}
finally { _writeLock.Release(); }
}
}
}