Merge remote-tracking branch 'upstream/master'

This commit is contained in:
olebeck 2021-11-07 12:36:21 +01:00
commit fb3ae2a2d5
10 changed files with 70 additions and 48 deletions

@ -1 +1 @@
Subproject commit 1f9bc06a178dc61964b989a44231c263cdd4edbb
Subproject commit 0f9268907fb3cd9d0da9c8ab1cba8308de0e5656

View file

@ -16,7 +16,7 @@ namespace HISP.Game
private static List<Arena> arenas = new List<Arena>();
private List<ArenaEntry> entries;
private Timer arenaTimeout;
public static int[] ExpRewards;
public int Id;
public string Type;
public int EntryCost;
@ -247,23 +247,9 @@ namespace HISP.Game
if(Mode == "COMPETING")
{
string chatMessage = Messages.ArenaResultsMessage;
string[] avaliblePlacings = new string[6] { Messages.ArenaFirstPlace, Messages.ArenaSecondPlace, Messages.ArenaThirdPlace, Messages.ArenaFourthPlace, Messages.ArenaFifthPlace, Messages.ArenaSixthPlace };
int[] expRewards = new int[Entries.Length];
expRewards[0] = 1;
int expAwardMul = 1;
for(int i = 1; i < Entries.Length; i++)
{
expRewards[i] = 2 * expAwardMul;
if (expAwardMul == 1)
expAwardMul = 2;
else
expAwardMul += 2;
}
expRewards = expRewards.ToArray().Reverse().ToArray();
int[] expRewards = ExpRewards.ToArray().Reverse().ToArray();
int place = 0;
ArenaEntry[] winners = Entries.OrderByDescending(o => o.SubmitScore).ToArray();

View file

@ -439,15 +439,23 @@ namespace HISP.Game.Chat
if(channel == ChatChannel.Dm)
{
if (to != null)
if (to != null && to != "")
{
List<GameClient> recipiants = new List<GameClient>();
foreach (GameClient client in GameClient.ConnectedClients)
{
if (client.LoggedIn)
{
if (!client.LoggedinUser.MutePrivateMessage && !client.LoggedinUser.MuteAll)
{
if (client.LoggedinUser.Username.ToLower().StartsWith(to.ToLower()))
{
recipiants.Add(client);
break;
}
}
}
}
return recipiants.ToArray();
}

View file

@ -59,7 +59,7 @@ namespace HISP.Game.Inventory
public InventoryItem[] GetItemList()
{
return inventoryItems.OrderBy(o => o.ItemInstances[0].GetItemInfo().SortBy).ToArray();
return inventoryItems.OrderBy(o => Item.GetItemById(o.ItemId).SortBy).ToArray();
}

View file

@ -43,7 +43,9 @@ namespace HISP.Game.Items
public int GetMiscFlag(int no)
{
if (MiscFlags.Length <= no)
if (no < 0)
return 0;
if (no >= MiscFlags.Length)
return 0;
else
return MiscFlags[no];

View file

@ -864,7 +864,7 @@ namespace HISP.Game
{
Highscore.HighscoreTableEntry[] scores = Database.GetTopScores(gameName, 20);
if (scores.Length <= 0)
return "ERROR: No scores recorded.";
return "ERROR: No scores recorded." + Messages.BackToMap + Messages.MetaTerminator;
string message = "";
message += Messages.FormatHighscoreHeader(gameName);
@ -881,7 +881,7 @@ namespace HISP.Game
{
Highscore.HighscoreTableEntry[] scores = Database.GetTopWinners(gameName, 20);
if (scores.Length <= 0)
return "No wins recorded.";
return "ERROR: No wins recorded." + Messages.BackToMap + Messages.MetaTerminator;
string message = "";
message += Messages.FormatWinlooseHeader(gameName);
@ -896,9 +896,9 @@ namespace HISP.Game
}
public static string BuildTopTimes(string gameName)
{
Highscore.HighscoreTableEntry[] scores = Database.GetTopScores(gameName, 20);
Highscore.HighscoreTableEntry[] scores = Database.GetTopScores(gameName, 20, false);
if (scores.Length <= 0)
return "No times recorded.";
return "ERROR: No times recorded. "+Messages.BackToMap+Messages.MetaTerminator;
string message = "";
message += Messages.FormatBestTimeHeader(gameName);
@ -2512,14 +2512,14 @@ namespace HISP.Game
foreach(InventoryItem item in user.Inventory.GetItemList())
{
Item.ItemInformation itemInfo = item.ItemInstances[0].GetItemInfo();
Item.ItemInformation itemInfo = Item.GetItemById(item.ItemId);
if (itemInfo.Type == "TACK")
{
if (horse.Breed.Type == "camel" && itemInfo.GetMiscFlag(2) != 1)
if (horse.Breed.Type == "camel" && itemInfo.GetMiscFlag(1) != 1)
continue;
else if (horse.Breed.Type == "llama" && itemInfo.GetMiscFlag(2) != 2)
else if (horse.Breed.Type == "llama" && itemInfo.GetMiscFlag(1) != 2)
continue;
else if (itemInfo.GetMiscFlag(2) != 0)
else if (itemInfo.GetMiscFlag(1) != 0)
continue;
message += Messages.FormatHorseEquip(itemInfo.IconId, item.ItemInstances.Length, itemInfo.Name, itemInfo.Id);
}

View file

@ -3597,13 +3597,16 @@ namespace HISP.Server
return entires.ToArray();
}
public static Highscore.HighscoreTableEntry[] GetTopScores(string gameTitle, int limit)
public static Highscore.HighscoreTableEntry[] GetTopScores(string gameTitle, int limit, bool scores=true)
{
List<Highscore.HighscoreTableEntry> entires = new();
using MySqlConnection db = Connect();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "SELECT * FROM Leaderboards WHERE minigame=@gameTitle ORDER BY score DESC LIMIT @limit";
if(scores)
sqlCommand.CommandText = "SELECT * FROM Leaderboards WHERE minigame=@gameTitle ORDER BY score DESC LIMIT @limit";
else
sqlCommand.CommandText = "SELECT * FROM Leaderboards WHERE minigame=@gameTitle ORDER BY score ASC LIMIT @limit";
sqlCommand.Parameters.AddWithValue("@gameTitle", gameTitle);
sqlCommand.Parameters.AddWithValue("@limit", limit);
sqlCommand.Prepare();

View file

@ -114,6 +114,8 @@ namespace HISP.Server
// Stop Timers
if (timeoutTimer != null)
timeoutTimer.Dispose();
if (keepAliveTimer != null)
keepAliveTimer.Dispose();
if (warnTimer != null)
warnTimer.Dispose();
if (kickTimer != null)
@ -126,8 +128,11 @@ namespace HISP.Server
LoggedIn = false;
// Close Socket
ClientSocket.Close();
ClientSocket.Dispose();
if(ClientSocket != null)
{
ClientSocket.Close();
ClientSocket.Dispose();
}
}
@ -512,10 +517,8 @@ namespace HISP.Server
{
ClientSocket.Send(PacketData);
}
catch (Exception e)
catch (Exception)
{
if(!(e is SocketException))
Logger.ErrorPrint("Exception occured: " + e.Message);
Disconnect();
}
}

View file

@ -731,19 +731,21 @@ namespace HISP.Server
}
// Register Arenas
int totalArenas = gameData.arena.Count;
int totalArenas = gameData.arena.arena_list.Count;
for (int i = 0; i < totalArenas; i++)
{
int arenaId = gameData.arena[i].arena_id;
string arenaType = gameData.arena[i].arena_type;
int arenaEntryCost = gameData.arena[i].entry_cost;
int raceEvery = gameData.arena[i].race_every;
int slots = gameData.arena[i].slots;
int timeout = gameData.arena[i].timeout;
int arenaId = gameData.arena.arena_list[i].arena_id;
string arenaType = gameData.arena.arena_list[i].arena_type;
int arenaEntryCost = gameData.arena.arena_list[i].entry_cost;
int raceEvery = gameData.arena.arena_list[i].race_every;
int slots = gameData.arena.arena_list[i].slots;
int timeout = gameData.arena.arena_list[i].timeout;
Arena arena = new Arena(arenaId, arenaType, arenaEntryCost, raceEvery, slots, timeout);
Logger.DebugPrint("Registered Arena: " + arena.Id.ToString() + " as " + arena.Type);
}
Arena.ExpRewards = gameData.arena.arena_exp.ToObject<int[]>();
// Register Leaser
int totalLeasers = gameData.leaser.Count;
for (int i = 0; i < totalLeasers; i++)

View file

@ -1642,31 +1642,31 @@ namespace HISP.Server
Arena arena = Arena.GetAreaById(arenaId);
if (!Arena.UserHasEnteredHorseInAnyArena(sender.LoggedinUser))
{
if (horseInstance.BasicStats.Thirst <= 300)
if (horseInstance.BasicStats.Thirst <= 200)
{
byte[] tooThirsty = PacketBuilder.CreateChat(Messages.ArenaTooThirsty, PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.SendPacket(tooThirsty);
break;
}
else if (horseInstance.BasicStats.Hunger <= 300)
else if (horseInstance.BasicStats.Hunger <= 200)
{
byte[] tooHungry = PacketBuilder.CreateChat(Messages.ArenaTooHungry, PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.SendPacket(tooHungry);
break;
}
else if (horseInstance.BasicStats.Shoes <= 300)
else if (horseInstance.BasicStats.Shoes <= 200)
{
byte[] needsFarrier = PacketBuilder.CreateChat(Messages.ArenaNeedsFarrier, PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.SendPacket(needsFarrier);
break;
}
else if (horseInstance.BasicStats.Tiredness <= 300)
else if (horseInstance.BasicStats.Tiredness <= 200)
{
byte[] tooTired = PacketBuilder.CreateChat(Messages.ArenaTooTired, PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.SendPacket(tooTired);
break;
}
else if (horseInstance.BasicStats.Health <= 300)
else if (horseInstance.BasicStats.Health <= 200)
{
byte[] needsVet = PacketBuilder.CreateChat(Messages.ArenaNeedsVet, PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.SendPacket(needsVet);
@ -7553,11 +7553,13 @@ namespace HISP.Server
List<User> usersNearby = new List<User>();
foreach (GameClient client in GameClient.ConnectedClients)
{
if (client.LoggedIn)
{
if (startX <= client.LoggedinUser.X && endX >= client.LoggedinUser.X && startY <= client.LoggedinUser.Y && endY >= client.LoggedinUser.Y)
usersNearby.Add(client.LoggedinUser);
}
}
return usersNearby.ToArray();
}
@ -7602,6 +7604,7 @@ namespace HISP.Server
List<User> usersNearby = new List<User>();
foreach (GameClient client in GameClient.ConnectedClients)
{
if (client.LoggedIn)
{
if (!includeStealth && client.LoggedinUser.Stealth)
@ -7611,6 +7614,7 @@ namespace HISP.Server
if (startX <= client.LoggedinUser.X && endX >= client.LoggedinUser.X && startY <= client.LoggedinUser.Y && endY >= client.LoggedinUser.Y)
usersNearby.Add(client.LoggedinUser);
}
}
return usersNearby.ToArray();
}
@ -7950,12 +7954,26 @@ namespace HISP.Server
foreach (GameClient connectedClient in GameClient.ConnectedClients)
{
if (connectedClient.LoggedIn)
{
if (connectedClient.LoggedinUser.Inventory.HasItemId(id))
{
InventoryItem invItm = connectedClient.LoggedinUser.Inventory.GetItemByItemId(id);
foreach (ItemInstance itm in invItm.ItemInstances.ToArray())
connectedClient.LoggedinUser.Inventory.Remove(itm);
}
}
}
// Remove from shops
foreach(Shop shop in Shop.ShopList)
{
if (shop.Inventory.HasItemId(id))
{
InventoryItem invItm = shop.Inventory.GetItemByItemId(id);
foreach (ItemInstance itm in invItm.ItemInstances.ToArray())
shop.Inventory.Remove(itm);
}
}
DroppedItems.DeleteAllItemsWithId(id); // Delete all dropped items
Database.DeleteAllItemsFromUsers(id); // Delete from offline players