mirror of
https://github.com/Sanae6/SmoOnlineServer.git
synced 2024-11-25 04:35:18 +00:00
fix: don't output empty player IDs or RemoteEndPoints in the log
Make and use a copy of the RemoteEndPoint at the start of the HandleSocket method, because in some cases when the socket is disposed the RemoteEndPoint inside of it is cleared and isn't available for the following disconnect log entries.
This commit is contained in:
parent
9e6c312c8e
commit
2f4cd0509a
1 changed files with 9 additions and 3 deletions
|
@ -127,6 +127,7 @@ public class Server {
|
||||||
|
|
||||||
private async void HandleSocket(Socket socket) {
|
private async void HandleSocket(Socket socket) {
|
||||||
Client client = new Client(socket) {Server = this};
|
Client client = new Client(socket) {Server = this};
|
||||||
|
var remote = socket.RemoteEndPoint;
|
||||||
IMemoryOwner<byte> memory = null!;
|
IMemoryOwner<byte> memory = null!;
|
||||||
await client.Send(new InitPacket {
|
await client.Send(new InitPacket {
|
||||||
MaxPlayers = Settings.Instance.Server.MaxPlayers
|
MaxPlayers = Settings.Instance.Server.MaxPlayers
|
||||||
|
@ -142,7 +143,7 @@ public class Server {
|
||||||
int size = await socket.ReceiveAsync(readMem[readOffset..readSize], SocketFlags.None);
|
int size = await socket.ReceiveAsync(readMem[readOffset..readSize], SocketFlags.None);
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
// treat it as a disconnect and exit
|
// treat it as a disconnect and exit
|
||||||
Logger.Info($"Socket {socket.RemoteEndPoint} disconnected.");
|
Logger.Info($"Socket {remote} disconnected.");
|
||||||
if (socket.Connected) await socket.DisconnectAsync(false);
|
if (socket.Connected) await socket.DisconnectAsync(false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -247,7 +248,7 @@ public class Server {
|
||||||
tempBuffer.Dispose();
|
tempBuffer.Dispose();
|
||||||
});
|
});
|
||||||
|
|
||||||
Logger.Info($"Client {client.Name} ({client.Id}/{socket.RemoteEndPoint}) connected.");
|
Logger.Info($"Client {client.Name} ({client.Id}/{remote}) connected.");
|
||||||
} else if (header.Id != client.Id && client.Id != Guid.Empty) {
|
} else if (header.Id != client.Id && client.Id != Guid.Empty) {
|
||||||
throw new Exception($"Client {client.Name} sent packet with invalid client id {header.Id} instead of {client.Id}");
|
throw new Exception($"Client {client.Name} sent packet with invalid client id {header.Id} instead of {client.Id}");
|
||||||
}
|
}
|
||||||
|
@ -294,7 +295,12 @@ public class Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnect:
|
disconnect:
|
||||||
Logger.Info($"Client {socket.RemoteEndPoint} ({client.Name}/{client.Id}) disconnected from the server");
|
if (client.Name != "Unknown User" && client.Id != Guid.Parse("00000000-0000-0000-0000-000000000000")) {
|
||||||
|
Logger.Info($"Client {remote} ({client.Name}/{client.Id}) disconnected from the server");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Logger.Info($"Client {remote} disconnected from the server");
|
||||||
|
}
|
||||||
|
|
||||||
// Clients.Remove(client)
|
// Clients.Remove(client)
|
||||||
client.Connected = false;
|
client.Connected = false;
|
||||||
|
|
Loading…
Reference in a new issue