Get Player/Server calls.
This commit is contained in:
parent
98d8ae180f
commit
1c5119a36d
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -193,12 +193,32 @@ namespace BattleBitAPI.Server
|
|||
}
|
||||
|
||||
// ---- Team ----
|
||||
public IEnumerable<TPlayer> GetAllPlayers()
|
||||
public IEnumerable<TPlayer> AllPlayers
|
||||
{
|
||||
var list = new List<TPlayer>(this.mInternal.Players.Values.Count);
|
||||
foreach (var item in this.mInternal.Players.Values)
|
||||
list.Add((TPlayer)item);
|
||||
return list;
|
||||
get
|
||||
{
|
||||
var list = new List<TPlayer>(this.mInternal.Players.Values.Count);
|
||||
lock (this.mInternal.Players)
|
||||
{
|
||||
foreach (var item in this.mInternal.Players.Values)
|
||||
list.Add((TPlayer)item);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
public bool TryGetPlayer(ulong steamID, out TPlayer player)
|
||||
{
|
||||
lock (this.mInternal.Players)
|
||||
{
|
||||
if (this.mInternal.Players.TryGetValue(steamID, out var _player))
|
||||
{
|
||||
player = (TPlayer)_player;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
player = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---- Virtual ----
|
||||
|
|
|
@ -571,11 +571,21 @@ namespace BattleBitAPI.Server
|
|||
}
|
||||
private async Task mHandleGameServer(TGameServer server)
|
||||
{
|
||||
bool isTicking = false;
|
||||
|
||||
using (server)
|
||||
{
|
||||
async Task mTickAsync()
|
||||
{
|
||||
isTicking = true;
|
||||
await server.OnTick();
|
||||
isTicking = false;
|
||||
}
|
||||
|
||||
while (server.IsConnected)
|
||||
{
|
||||
server.OnTick();
|
||||
if (!isTicking)
|
||||
mTickAsync();
|
||||
|
||||
await server.Tick();
|
||||
await Task.Delay(10);
|
||||
|
@ -585,7 +595,7 @@ namespace BattleBitAPI.Server
|
|||
{
|
||||
server.OnDisconnected();
|
||||
|
||||
if (this.OnGameServerDisconnected!= null)
|
||||
if (this.OnGameServerDisconnected != null)
|
||||
this.OnGameServerDisconnected(server);
|
||||
}
|
||||
}
|
||||
|
@ -972,6 +982,36 @@ namespace BattleBitAPI.Server
|
|||
}
|
||||
}
|
||||
|
||||
// --- Public ---
|
||||
public IEnumerable<TGameServer> ConnectedGameServers
|
||||
{
|
||||
get
|
||||
{
|
||||
var list = new List<TGameServer>(mActiveConnections.Count);
|
||||
lock (mActiveConnections)
|
||||
{
|
||||
foreach (var item in mActiveConnections.Values)
|
||||
list.Add(item.server);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
public bool TryGetGameServer(IPAddress ip, ushort port, out TGameServer server)
|
||||
{
|
||||
var hash = ((ulong)port << 32) | (ulong)ip.ToUInt();
|
||||
lock (mActiveConnections)
|
||||
{
|
||||
if (mActiveConnections.TryGetValue(hash, out var _server))
|
||||
{
|
||||
server = (TGameServer)_server.server;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
server = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
// --- Disposing ---
|
||||
public void Dispose()
|
||||
{
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
using BattleBitAPI;
|
||||
using BattleBitAPI.Common;
|
||||
using BattleBitAPI.Server;
|
||||
using System.Net;
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var listener = new ServerListener<MyPlayer, MyGameServer>();
|
||||
|
||||
listener.Start(29294);
|
||||
Thread.Sleep(-1);
|
||||
}
|
||||
|
@ -23,4 +21,8 @@ class MyGameServer : GameServer<MyPlayer>
|
|||
{
|
||||
return true;
|
||||
}
|
||||
public override async Task OnTick()
|
||||
{
|
||||
await Task.Delay(3000);
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue