Bug fixes and small changes
This commit is contained in:
@ -96,9 +96,7 @@ namespace CoopServer
|
||||
info = new() { Country = "?" };
|
||||
}
|
||||
|
||||
bool responseError = false;
|
||||
|
||||
while (!Program.ReadyToStop && !responseError)
|
||||
while (!Program.ReadyToStop)
|
||||
{
|
||||
string msg =
|
||||
"{ " +
|
||||
@ -114,7 +112,6 @@ namespace CoopServer
|
||||
" }";
|
||||
|
||||
HttpResponseMessage response = null;
|
||||
string responseContent = "";
|
||||
try
|
||||
{
|
||||
response = await httpClient.PostAsync(MainSettings.MasterServer, new StringContent(msg, Encoding.UTF8, "application/json"));
|
||||
@ -123,8 +120,6 @@ namespace CoopServer
|
||||
Logging.Error("MasterServer: Something went wrong!");
|
||||
break;
|
||||
}
|
||||
|
||||
responseContent = await response.Content.ReadAsStringAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -135,7 +130,7 @@ namespace CoopServer
|
||||
if (response.StatusCode != System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
Logging.Error($"MasterServer: {response.StatusCode}");
|
||||
responseError = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -361,7 +356,7 @@ namespace CoopServer
|
||||
packet.NetIncomingMessageToPacket(message);
|
||||
NativeResponsePacket responsePacket = (NativeResponsePacket)packet;
|
||||
|
||||
Client client = Clients.FirstOrDefault(x => x.ID == message.SenderConnection.RemoteUniqueIdentifier);
|
||||
Client client = Clients.Find(x => x.ID == message.SenderConnection.RemoteUniqueIdentifier);
|
||||
if (client != null)
|
||||
{
|
||||
if (client.Callbacks.ContainsKey(responsePacket.ID))
|
||||
@ -419,7 +414,7 @@ namespace CoopServer
|
||||
|
||||
if (modPacket.Target != 0)
|
||||
{
|
||||
NetConnection target = MainNetServer.Connections.FirstOrDefault(x => x.RemoteUniqueIdentifier == modPacket.Target);
|
||||
NetConnection target = MainNetServer.Connections.Find(x => x.RemoteUniqueIdentifier == modPacket.Target);
|
||||
if (target == null)
|
||||
{
|
||||
Logging.Error($"[ModPacket] target \"{modPacket.Target}\" not found!");
|
||||
@ -454,7 +449,7 @@ namespace CoopServer
|
||||
break;
|
||||
case NetIncomingMessageType.ConnectionLatencyUpdated:
|
||||
{
|
||||
Client client = Clients.FirstOrDefault(x => x.ID == message.SenderConnection.RemoteUniqueIdentifier);
|
||||
Client client = Clients.Find(x => x.ID == message.SenderConnection.RemoteUniqueIdentifier);
|
||||
if (client != null)
|
||||
{
|
||||
client.Latency = message.ReadFloat();
|
||||
@ -606,7 +601,7 @@ namespace CoopServer
|
||||
// The connection has been approved, now we need to send all other players to the new player and the new player to all players
|
||||
private static void SendPlayerConnectPacket(NetConnection local, PlayerConnectPacket packet)
|
||||
{
|
||||
Client localClient = Clients.FirstOrDefault(x => x.ID == packet.ID);
|
||||
Client localClient = Clients.Find(x => x.ID == packet.ID);
|
||||
if (localClient == null)
|
||||
{
|
||||
local.Disconnect("No data found!");
|
||||
@ -621,7 +616,7 @@ namespace CoopServer
|
||||
{
|
||||
long targetPlayerID = targetPlayer.RemoteUniqueIdentifier;
|
||||
|
||||
Client targetClient = Clients.FirstOrDefault(x => x.ID == targetPlayerID);
|
||||
Client targetClient = Clients.Find(x => x.ID == targetPlayerID);
|
||||
if (targetClient != null)
|
||||
{
|
||||
NetOutgoingMessage outgoingMessage = MainNetServer.CreateMessage();
|
||||
@ -675,7 +670,7 @@ namespace CoopServer
|
||||
MainNetServer.SendMessage(outgoingMessage, clients, NetDeliveryMethod.ReliableOrdered, 0);
|
||||
}
|
||||
|
||||
Client localClient = Clients.FirstOrDefault(x => x.ID == clientID);
|
||||
Client localClient = Clients.Find(x => x.ID == clientID);
|
||||
if (localClient == null)
|
||||
{
|
||||
return;
|
||||
@ -695,21 +690,16 @@ namespace CoopServer
|
||||
|
||||
private static void FullSyncPlayer(FullSyncPlayerPacket packet)
|
||||
{
|
||||
Client tmpClient = Clients.FirstOrDefault(x => x.ID == packet.Extra.ID);
|
||||
if (tmpClient == null)
|
||||
Client client = Util.GetClientByID(packet.Extra.ID);
|
||||
if (client == null)
|
||||
{
|
||||
NetConnection localConn = MainNetServer.Connections.Find(x => packet.Extra.ID == x.RemoteUniqueIdentifier);
|
||||
if (localConn != null)
|
||||
{
|
||||
localConn.Disconnect("No data found!");
|
||||
}
|
||||
return;
|
||||
}
|
||||
tmpClient.Player.Position = packet.Extra.Position;
|
||||
tmpClient.Player.Health = packet.Extra.Health;
|
||||
client.Player.Position = packet.Extra.Position;
|
||||
client.Player.Health = packet.Extra.Health;
|
||||
|
||||
PlayerPacket playerPacket = packet.Extra;
|
||||
playerPacket.Latency = tmpClient.Latency;
|
||||
playerPacket.Latency = client.Latency;
|
||||
|
||||
packet.Extra = playerPacket;
|
||||
|
||||
@ -734,27 +724,22 @@ namespace CoopServer
|
||||
|
||||
if (MainResource != null)
|
||||
{
|
||||
MainResource.InvokePlayerUpdate(tmpClient);
|
||||
MainResource.InvokePlayerUpdate(client);
|
||||
}
|
||||
}
|
||||
|
||||
private static void FullSyncPlayerVeh(FullSyncPlayerVehPacket packet)
|
||||
{
|
||||
Client tmpClient = Clients.FirstOrDefault(x => x.ID == packet.Extra.ID);
|
||||
if (tmpClient == null)
|
||||
Client client = Util.GetClientByID(packet.Extra.ID);
|
||||
if (client == null)
|
||||
{
|
||||
NetConnection localConn = MainNetServer.Connections.Find(x => packet.Extra.ID == x.RemoteUniqueIdentifier);
|
||||
if (localConn != null)
|
||||
{
|
||||
localConn.Disconnect("No data found!");
|
||||
}
|
||||
return;
|
||||
}
|
||||
tmpClient.Player.Position = packet.Extra.Position;
|
||||
tmpClient.Player.Health = packet.Extra.Health;
|
||||
client.Player.Position = packet.Extra.Position;
|
||||
client.Player.Health = packet.Extra.Health;
|
||||
|
||||
PlayerPacket playerPacket = packet.Extra;
|
||||
playerPacket.Latency = tmpClient.Latency;
|
||||
playerPacket.Latency = client.Latency;
|
||||
|
||||
packet.Extra = playerPacket;
|
||||
|
||||
@ -779,27 +764,22 @@ namespace CoopServer
|
||||
|
||||
if (MainResource != null)
|
||||
{
|
||||
MainResource.InvokePlayerUpdate(tmpClient);
|
||||
MainResource.InvokePlayerUpdate(client);
|
||||
}
|
||||
}
|
||||
|
||||
private static void LightSyncPlayer(LightSyncPlayerPacket packet)
|
||||
{
|
||||
Client tmpClient = Clients.FirstOrDefault(x => x.ID == packet.Extra.ID);
|
||||
if (tmpClient == null)
|
||||
Client client = Util.GetClientByID(packet.Extra.ID);
|
||||
if (client == null)
|
||||
{
|
||||
NetConnection localConn = MainNetServer.Connections.Find(x => packet.Extra.ID == x.RemoteUniqueIdentifier);
|
||||
if (localConn != null)
|
||||
{
|
||||
localConn.Disconnect("No data found!");
|
||||
}
|
||||
return;
|
||||
}
|
||||
tmpClient.Player.Position = packet.Extra.Position;
|
||||
tmpClient.Player.Health = packet.Extra.Health;
|
||||
client.Player.Position = packet.Extra.Position;
|
||||
client.Player.Health = packet.Extra.Health;
|
||||
|
||||
PlayerPacket playerPacket = packet.Extra;
|
||||
playerPacket.Latency = tmpClient.Latency;
|
||||
playerPacket.Latency = client.Latency;
|
||||
|
||||
packet.Extra = playerPacket;
|
||||
|
||||
@ -824,27 +804,22 @@ namespace CoopServer
|
||||
|
||||
if (MainResource != null)
|
||||
{
|
||||
MainResource.InvokePlayerUpdate(tmpClient);
|
||||
MainResource.InvokePlayerUpdate(client);
|
||||
}
|
||||
}
|
||||
|
||||
private static void LightSyncPlayerVeh(LightSyncPlayerVehPacket packet)
|
||||
{
|
||||
Client tmpClient = Clients.FirstOrDefault(x => x.ID == packet.Extra.ID);
|
||||
if (tmpClient == null)
|
||||
Client client = Util.GetClientByID(packet.Extra.ID);
|
||||
if (client == null)
|
||||
{
|
||||
NetConnection localConn = MainNetServer.Connections.Find(x => packet.Extra.ID == x.RemoteUniqueIdentifier);
|
||||
if (localConn != null)
|
||||
{
|
||||
localConn.Disconnect("No data found!");
|
||||
}
|
||||
return;
|
||||
}
|
||||
tmpClient.Player.Position = packet.Extra.Position;
|
||||
tmpClient.Player.Health = packet.Extra.Health;
|
||||
client.Player.Position = packet.Extra.Position;
|
||||
client.Player.Health = packet.Extra.Health;
|
||||
|
||||
PlayerPacket playerPacket = packet.Extra;
|
||||
playerPacket.Latency = tmpClient.Latency;
|
||||
playerPacket.Latency = client.Latency;
|
||||
|
||||
packet.Extra = playerPacket;
|
||||
|
||||
@ -869,7 +844,7 @@ namespace CoopServer
|
||||
|
||||
if (MainResource != null)
|
||||
{
|
||||
MainResource.InvokePlayerUpdate(tmpClient);
|
||||
MainResource.InvokePlayerUpdate(client);
|
||||
}
|
||||
}
|
||||
|
||||
@ -890,7 +865,7 @@ namespace CoopServer
|
||||
|
||||
CommandContext ctx = new()
|
||||
{
|
||||
Client = Clients.FirstOrDefault(x => x.Player.Username == packet.Username),
|
||||
Client = Clients.Find(x => x.Player.Username == packet.Username),
|
||||
Args = argsWithoutCmd
|
||||
};
|
||||
|
||||
|
@ -282,7 +282,7 @@ namespace CoopServer
|
||||
|
||||
public static Client GetClientByUsername(string username)
|
||||
{
|
||||
return Server.Clients.FirstOrDefault(x => x.Player.Username.ToLower() == username.ToLower());
|
||||
return Server.Clients.Find(x => x.Player.Username.ToLower() == username.ToLower());
|
||||
}
|
||||
|
||||
public static void SendChatMessageToAll(string message, string username = "Server")
|
||||
|
@ -52,15 +52,31 @@ namespace CoopServer
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Client GetClientByID(long id)
|
||||
{
|
||||
Client result = Server.Clients.Find(x => x.ID == id);
|
||||
if (result == null)
|
||||
{
|
||||
NetConnection localConn = Server.MainNetServer.Connections.Find(x => id == x.RemoteUniqueIdentifier);
|
||||
if (localConn != null)
|
||||
{
|
||||
localConn.Disconnect("No data found!");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static NetConnection GetConnectionByUsername(string username)
|
||||
{
|
||||
Client client = Server.Clients.FirstOrDefault(x => x.Player.Username.ToLower() == username.ToLower());
|
||||
if (client.Equals(default(Client)))
|
||||
Client client = Server.Clients.Find(x => x.Player.Username.ToLower() == username.ToLower());
|
||||
if (client == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return Server.MainNetServer.Connections.FirstOrDefault(x => x.RemoteUniqueIdentifier == client.ID);
|
||||
return Server.MainNetServer.Connections.Find(x => x.RemoteUniqueIdentifier == client.ID);
|
||||
}
|
||||
|
||||
// Return a list of all connections but not the local connection
|
||||
@ -79,7 +95,7 @@ namespace CoopServer
|
||||
return new(Server.MainNetServer.Connections.FindAll(e =>
|
||||
{
|
||||
Client client = Server.Clients.First(x => x.ID == e.RemoteUniqueIdentifier);
|
||||
return !client.Equals(default(Client)) && client.Player.IsInRangeOf(position, range);
|
||||
return client != null && client.Player.IsInRangeOf(position, range);
|
||||
}));
|
||||
}
|
||||
// Return a list of players within range of ... but not the local one
|
||||
@ -88,7 +104,7 @@ namespace CoopServer
|
||||
return new(Server.MainNetServer.Connections.Where(e =>
|
||||
{
|
||||
Client client = Server.Clients.First(x => x.ID == e.RemoteUniqueIdentifier);
|
||||
return e != local && !client.Equals(default(Client)) && client.Player.IsInRangeOf(position, range);
|
||||
return e != local && client != null && client.Player.IsInRangeOf(position, range);
|
||||
}));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user