Skip to content

Commit

Permalink
Fixing bugs (#47)
Browse files Browse the repository at this point in the history
* Should fix 198, server crash due to projectile trying to hit an event

* Harden accept trade packet to return if counterparty is null.

* Fixing potential NREs

* Fixes another potential NRE and out of bounds error

* Don't want to handle packets for null clients, but also don't want to be throwing exceptions

* Fixes a small error where empty passwords crash the server during migration
  • Loading branch information
jcsnider committed Mar 30, 2020
1 parent faedd06 commit 388dd34
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Intersect.Server/Database/DbInterface.cs
Expand Up @@ -373,6 +373,7 @@ public static User GetUser([NotNull] string username)

public static Player GetUserCharacter(User user, Guid characterId)
{
if (user == null) return null;
foreach (var character in user.Players)
{
if (character.Id == characterId)
Expand Down Expand Up @@ -1892,7 +1893,7 @@ public static string GetPassword()
}
else if (i.Key == ConsoleKey.Backspace)
{
if (pwd.Length > 0)
if (pwd.Length > 1)
{
pwd = pwd.Remove(pwd.Length - 2, 1);
Console.Write("\b \b");
Expand Down
5 changes: 5 additions & 0 deletions Intersect.Server/Entities/Player.cs
Expand Up @@ -3316,6 +3316,11 @@ public void RevokeItem(int slot, int amount)
return;
}

if (slot < 0 || slot >= Trading.Offer.Length || Trading.Offer[slot] == null)
{
return;
}

var itemBase = ItemBase.Get(Trading.Offer[slot].ItemId);
if (itemBase == null)
{
Expand Down
2 changes: 2 additions & 0 deletions Intersect.Server/Entities/ProjectileSpawn.cs
Expand Up @@ -2,6 +2,7 @@

using Intersect.GameObjects;
using Intersect.Server.Entities.Combat;
using Intersect.Server.Entities.Events;
using Intersect.Server.General;
using Intersect.Server.Networking;

Expand Down Expand Up @@ -58,6 +59,7 @@ public bool IsAtLocation(Guid mapId, int x, int y, int z)
public bool HitEntity(Entity en)
{
var targetEntity = en;
if (targetEntity is EventPageInstance) return false;
if (targetEntity != null && targetEntity != Parent.Owner)
{
if (targetEntity.GetType() == typeof(Player)) //Player
Expand Down
6 changes: 4 additions & 2 deletions Intersect.Server/Networking/PacketHandler.cs
Expand Up @@ -39,7 +39,7 @@ public bool PreProcessPacket(IConnection connection, long pSize)
var client = Client.FindBeta4Client(connection);
if (client == null)
{
throw new Exception("Client is null!");
return false;
}

if (client.Banned || client.FloodKicked)
Expand Down Expand Up @@ -1646,7 +1646,7 @@ public void HandlePacket(Client client, Player player, [NotNull] RevokeTradeItem
//AcceptTradePacket
public void HandlePacket(Client client, Player player, AcceptTradePacket packet)
{
if (player == null)
if (player == null || player.Trading.Counterparty == null)
{
return;
}
Expand Down Expand Up @@ -1866,6 +1866,7 @@ public void HandlePacket(Client client, Player player, FriendRequestResponsePack
//SelectCharacterPacket
public void HandlePacket(Client client, Player player, SelectCharacterPacket packet)
{
if (client.User == null) return;
var character = DbInterface.GetUserCharacter(client.User, packet.CharacterId);
if (character != null)
{
Expand All @@ -1887,6 +1888,7 @@ public void HandlePacket(Client client, Player player, SelectCharacterPacket pac
//DeleteCharacterPacket
public void HandlePacket(Client client, Player player, DeleteCharacterPacket packet)
{
if (client.User == null) return;
var character = DbInterface.GetUserCharacter(client.User, packet.CharacterId);
if (character != null)
{
Expand Down

0 comments on commit 388dd34

Please sign in to comment.