wip
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using Ragon.Server.Logging;
|
||||
|
||||
namespace Ragon.Relay;
|
||||
|
||||
public class Client
|
||||
{
|
||||
private readonly UdpClient _udpClient;
|
||||
private readonly IPEndPoint _endpoint;
|
||||
private readonly IRagonLogger _logger;
|
||||
|
||||
public Client(string host, int port)
|
||||
{
|
||||
_logger = LoggerManager.GetLogger("Client");
|
||||
_udpClient = new UdpClient();
|
||||
_endpoint = new IPEndPoint(IPAddress.Parse(host), port);
|
||||
}
|
||||
|
||||
public void Send(byte[] data)
|
||||
{
|
||||
try
|
||||
{
|
||||
_udpClient.BeginSend(data, data.Length, _endpoint, SendCallback, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void SendCallback(IAsyncResult ar)
|
||||
{
|
||||
try
|
||||
{
|
||||
_udpClient.EndSend(ar);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,56 @@
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.Collections;
|
||||
using Ragon.Server;
|
||||
|
||||
namespace Ragon.Relay;
|
||||
|
||||
public class Reporter
|
||||
{
|
||||
private readonly Client _client;
|
||||
private readonly IRagonServer _server;
|
||||
private readonly RelayConfiguration _configuration;
|
||||
|
||||
public Reporter(
|
||||
RelayConfiguration relayConfiguration,
|
||||
IRagonServer server,
|
||||
string host,
|
||||
int port
|
||||
)
|
||||
{
|
||||
_client = new Client(host, port);
|
||||
_server = server;
|
||||
_configuration = relayConfiguration;
|
||||
}
|
||||
|
||||
public void Done()
|
||||
{
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
var message = new Data();
|
||||
message.Statistics = new Statistics()
|
||||
{
|
||||
Connections = _server.ConnectionRegistry.Contexts.Count,
|
||||
ConnectionsLimit = _configuration.LimitConnections,
|
||||
Rooms = _server.Lobby.Rooms.Count,
|
||||
RoomsLimit = _configuration.LimitRooms,
|
||||
};
|
||||
|
||||
var room = new Room()
|
||||
{
|
||||
Id = $"Room ID {i}",
|
||||
};
|
||||
|
||||
for (var j = 0; j < 10; j++)
|
||||
{
|
||||
room.Players.Add(new Player()
|
||||
{
|
||||
Id = $"Player ID {i}",
|
||||
});
|
||||
}
|
||||
|
||||
message.Room = room;
|
||||
|
||||
_client.Send(message.ToByteArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user