From 40c34ac030e96dcc651bdf06908d9987c7f9cd06 Mon Sep 17 00:00:00 2001
From: Li
Date: Wed, 31 Aug 2022 20:31:07 +1200
Subject: [PATCH] Add Thread-Safe Lists, and make all list access thread-safe
---
.../HISPd/Resources/DEBIAN/control | 2 +-
HorseIsleServer/LibHISP/Game/AbuseReport.cs | 3 +-
HorseIsleServer/LibHISP/Game/Arena.cs | 4 +-
.../LibHISP/Game/Events/ModsRevenge.cs | 8 +--
.../LibHISP/Game/Events/RealTimeQuiz.cs | 4 +-
.../LibHISP/Game/Horse/WildHorse.cs | 2 +-
.../LibHISP/Game/Inventory/HorseInventory.cs | 2 +-
.../LibHISP/Game/Inventory/InventoryItem.cs | 11 ++-
.../LibHISP/Game/Inventory/PlayerInventory.cs | 4 +-
.../LibHISP/Game/Inventory/ShopInventory.cs | 4 +-
HorseIsleServer/LibHISP/Game/Multiroom.cs | 2 +-
.../LibHISP/Game/Services/Auction.cs | 8 +--
.../LibHISP/Game/SwfModules/Dressup.cs | 4 +-
HorseIsleServer/LibHISP/Game/Tracking.cs | 2 +-
HorseIsleServer/LibHISP/Player/Award.cs | 4 +-
HorseIsleServer/LibHISP/Player/Friends.cs | 4 +-
HorseIsleServer/LibHISP/Player/Highscore.cs | 2 +-
HorseIsleServer/LibHISP/Player/Mailbox.cs | 2 +-
.../LibHISP/Player/MutedPlayers.cs | 4 +-
.../LibHISP/Player/PlayerQuests.cs | 2 +-
.../LibHISP/Properties/AssemblyInfo.cs | 4 +-
HorseIsleServer/LibHISP/Server/GameClient.cs | 2 +-
.../LibHISP/Server/ThreadSafeList.cs | 67 +++++++++++++++++++
.../MPN00BS/Properties/AssemblyInfo.cs | 4 +-
24 files changed, 111 insertions(+), 44 deletions(-)
create mode 100644 HorseIsleServer/LibHISP/Server/ThreadSafeList.cs
diff --git a/HorseIsleServer/HISPd/Resources/DEBIAN/control b/HorseIsleServer/HISPd/Resources/DEBIAN/control
index 3ad3e2f..3a69dec 100755
--- a/HorseIsleServer/HISPd/Resources/DEBIAN/control
+++ b/HorseIsleServer/HISPd/Resources/DEBIAN/control
@@ -1,5 +1,5 @@
Package: hisp
-Version: 1.7.121
+Version: 1.7.123
Depends: coreutils,systemd,mariadb-server,libsqlite3-dev,zlib1g-dev,libicu-dev,libkrb5-dev
Maintainer: Li
Homepage: https://islehorse.com
diff --git a/HorseIsleServer/LibHISP/Game/AbuseReport.cs b/HorseIsleServer/LibHISP/Game/AbuseReport.cs
index 2f4e648..4fb543c 100755
--- a/HorseIsleServer/LibHISP/Game/AbuseReport.cs
+++ b/HorseIsleServer/LibHISP/Game/AbuseReport.cs
@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using HISP.Server;
+using System.Collections.Generic;
namespace HISP.Game
{
public class AbuseReport
diff --git a/HorseIsleServer/LibHISP/Game/Arena.cs b/HorseIsleServer/LibHISP/Game/Arena.cs
index ae54006..3f7d4e2 100755
--- a/HorseIsleServer/LibHISP/Game/Arena.cs
+++ b/HorseIsleServer/LibHISP/Game/Arena.cs
@@ -14,7 +14,7 @@ namespace HISP.Game
{
private static List arenas = new List();
- private List entries;
+ private ThreadSafeList entries;
private Timer arenaTimeout;
public static int[] ExpRewards;
public int Id;
@@ -59,7 +59,7 @@ namespace HISP.Game
Slots = slots;
Timeout = timeOut;
arenas.Add(this);
- entries = new List();
+ entries = new ThreadSafeList();
}
public bool HaveAllPlayersCompleted()
diff --git a/HorseIsleServer/LibHISP/Game/Events/ModsRevenge.cs b/HorseIsleServer/LibHISP/Game/Events/ModsRevenge.cs
index d541eaa..fb8cae6 100755
--- a/HorseIsleServer/LibHISP/Game/Events/ModsRevenge.cs
+++ b/HorseIsleServer/LibHISP/Game/Events/ModsRevenge.cs
@@ -13,7 +13,7 @@ namespace HISP.Game.Events
public ThrowTracker(User thrower)
{
Thrower = thrower;
- thrownAt = new List();
+ thrownAt = new ThreadSafeList();
}
public void AddThrownAt(User user)
@@ -21,7 +21,7 @@ namespace HISP.Game.Events
thrownAt.Add(user);
}
public User Thrower;
- private List thrownAt;
+ private ThreadSafeList thrownAt;
public User[] ThrownAt
{
get
@@ -33,7 +33,7 @@ namespace HISP.Game.Events
public bool Active = false;
public const int REVENGE_TIMEOUT = 10;
- private List trackedThrows;
+ private ThreadSafeList trackedThrows;
private Timer revengeTimeout;
public ThrowTracker[] TrackedThrows
{
@@ -45,7 +45,7 @@ namespace HISP.Game.Events
public ModsRevenge()
{
- trackedThrows = new List();
+ trackedThrows = new ThreadSafeList();
Active = false;
}
diff --git a/HorseIsleServer/LibHISP/Game/Events/RealTimeQuiz.cs b/HorseIsleServer/LibHISP/Game/Events/RealTimeQuiz.cs
index 15cd3e4..6cbaecc 100755
--- a/HorseIsleServer/LibHISP/Game/Events/RealTimeQuiz.cs
+++ b/HorseIsleServer/LibHISP/Game/Events/RealTimeQuiz.cs
@@ -97,11 +97,11 @@ namespace HISP.Game.Events
return participents.ToArray();
}
}
- private List participents;
+ private ThreadSafeList participents;
public RealTimeQuiz()
{
- participents = new List();
+ participents = new ThreadSafeList();
Questions = new QuizQuestion[8];
for(int i = 0; i < 8; i++)
{
diff --git a/HorseIsleServer/LibHISP/Game/Horse/WildHorse.cs b/HorseIsleServer/LibHISP/Game/Horse/WildHorse.cs
index 8d6ddf2..b8c8254 100755
--- a/HorseIsleServer/LibHISP/Game/Horse/WildHorse.cs
+++ b/HorseIsleServer/LibHISP/Game/Horse/WildHorse.cs
@@ -181,7 +181,7 @@ namespace HISP.Game.Horse
Despawn(this);
}
- private static List wildHorses = new List();
+ private static ThreadSafeList wildHorses = new ThreadSafeList();
public static WildHorse[] WildHorses
{
get
diff --git a/HorseIsleServer/LibHISP/Game/Inventory/HorseInventory.cs b/HorseIsleServer/LibHISP/Game/Inventory/HorseInventory.cs
index 0c56761..1caea4b 100755
--- a/HorseIsleServer/LibHISP/Game/Inventory/HorseInventory.cs
+++ b/HorseIsleServer/LibHISP/Game/Inventory/HorseInventory.cs
@@ -8,7 +8,7 @@ namespace HISP.Game.Inventory
public class HorseInventory
{
private User baseUser;
- private List horsesList = new List();
+ private ThreadSafeList horsesList = new ThreadSafeList();
public HorseInstance[] HorseList
{
get
diff --git a/HorseIsleServer/LibHISP/Game/Inventory/InventoryItem.cs b/HorseIsleServer/LibHISP/Game/Inventory/InventoryItem.cs
index 8f4662f..b26faba 100755
--- a/HorseIsleServer/LibHISP/Game/Inventory/InventoryItem.cs
+++ b/HorseIsleServer/LibHISP/Game/Inventory/InventoryItem.cs
@@ -1,21 +1,20 @@
-using System;
-using System.Collections.Generic;
-using HISP.Game.Items;
-
+using HISP.Game.Items;
+using HISP.Server;
+
namespace HISP.Game.Inventory
{
public class InventoryItem
{
public InventoryItem()
{
- itemInstances = new List();
+ itemInstances = new ThreadSafeList();
Infinite = false;
ItemId = 0;
}
public int ItemId;
public bool Infinite;
- private List itemInstances;
+ private ThreadSafeList itemInstances;
public void RemoveItem(ItemInstance itm)
{
itemInstances.Remove(itm);
diff --git a/HorseIsleServer/LibHISP/Game/Inventory/PlayerInventory.cs b/HorseIsleServer/LibHISP/Game/Inventory/PlayerInventory.cs
index 2bde518..0310a95 100755
--- a/HorseIsleServer/LibHISP/Game/Inventory/PlayerInventory.cs
+++ b/HorseIsleServer/LibHISP/Game/Inventory/PlayerInventory.cs
@@ -13,10 +13,10 @@ namespace HISP.Game.Inventory
public User BaseUser;
- private List inventoryItems;
+ private ThreadSafeList inventoryItems;
public PlayerInventory(User forUser)
{
- inventoryItems = new List();
+ inventoryItems = new ThreadSafeList();
BaseUser = forUser;
ItemInstance[] instances = Database.GetPlayerInventory(BaseUser.Id).ToArray();
diff --git a/HorseIsleServer/LibHISP/Game/Inventory/ShopInventory.cs b/HorseIsleServer/LibHISP/Game/Inventory/ShopInventory.cs
index 3869ea2..640da7c 100755
--- a/HorseIsleServer/LibHISP/Game/Inventory/ShopInventory.cs
+++ b/HorseIsleServer/LibHISP/Game/Inventory/ShopInventory.cs
@@ -10,7 +10,7 @@ namespace HISP.Game.Inventory
public class ShopInventory : IInventory
{
private Shop baseShop;
- private List inventoryItems;
+ private ThreadSafeList inventoryItems;
public int Count
{
get
@@ -21,7 +21,7 @@ namespace HISP.Game.Inventory
public ShopInventory(Shop shopkeeper)
{
baseShop = shopkeeper;
- inventoryItems = new List();
+ inventoryItems = new ThreadSafeList();
}
private void addItem(ItemInstance item, bool addToDatabase)
diff --git a/HorseIsleServer/LibHISP/Game/Multiroom.cs b/HorseIsleServer/LibHISP/Game/Multiroom.cs
index effc7b3..c90c923 100755
--- a/HorseIsleServer/LibHISP/Game/Multiroom.cs
+++ b/HorseIsleServer/LibHISP/Game/Multiroom.cs
@@ -8,7 +8,7 @@ namespace HISP.Game
public class Multiroom
{
private static List multirooms = new List();
- private List joinedUsers = new List();
+ private ThreadSafeList joinedUsers = new ThreadSafeList();
public int x;
public int y;
diff --git a/HorseIsleServer/LibHISP/Game/Services/Auction.cs b/HorseIsleServer/LibHISP/Game/Services/Auction.cs
index abbc066..bc57273 100755
--- a/HorseIsleServer/LibHISP/Game/Services/Auction.cs
+++ b/HorseIsleServer/LibHISP/Game/Services/Auction.cs
@@ -8,7 +8,7 @@ namespace HISP.Game.Services
{
public class Auction
{
- private static List auctionRooms = new List();
+ private static ThreadSafeList auctionRooms = new ThreadSafeList();
public static Auction[] AuctionRooms
{
get
@@ -20,7 +20,7 @@ namespace HISP.Game.Services
public Auction(int id)
{
RoomId = id;
- auctionEntries = new List();
+ auctionEntries = new ThreadSafeList();
Database.LoadAuctionRoom(this, RoomId);
}
@@ -122,7 +122,7 @@ namespace HISP.Game.Services
public HorseInstance Horse;
public int OwnerId;
- private List bidders = new List();
+ private ThreadSafeList bidders = new ThreadSafeList();
public AuctionBid[] Bidders
{
get
@@ -297,7 +297,7 @@ namespace HISP.Game.Services
auctionEntries.Add(entry);
}
- private List auctionEntries;
+ private ThreadSafeList auctionEntries;
public int RoomId;
public AuctionEntry[] AuctionEntries
diff --git a/HorseIsleServer/LibHISP/Game/SwfModules/Dressup.cs b/HorseIsleServer/LibHISP/Game/SwfModules/Dressup.cs
index aa18b91..4fd852e 100755
--- a/HorseIsleServer/LibHISP/Game/SwfModules/Dressup.cs
+++ b/HorseIsleServer/LibHISP/Game/SwfModules/Dressup.cs
@@ -17,7 +17,7 @@ namespace HISP.Game.SwfModules
public class DressupRoom
{
public int RoomId;
- private List dressupPeices;
+ private ThreadSafeList dressupPeices;
public DressupPeice[] DressupPeices
{
get
@@ -28,7 +28,7 @@ namespace HISP.Game.SwfModules
public DressupRoom(int roomId)
{
RoomId = roomId;
- dressupPeices = new List();
+ dressupPeices = new ThreadSafeList();
DressupPeice[] peices = Database.LoadDressupRoom(this);
foreach (DressupPeice peice in peices)
diff --git a/HorseIsleServer/LibHISP/Game/Tracking.cs b/HorseIsleServer/LibHISP/Game/Tracking.cs
index 18e12ec..a2f9023 100755
--- a/HorseIsleServer/LibHISP/Game/Tracking.cs
+++ b/HorseIsleServer/LibHISP/Game/Tracking.cs
@@ -57,7 +57,7 @@ namespace HISP.Game
private int count;
private User baseUser;
}
- private List trackingItems = new List();
+ private ThreadSafeList trackingItems = new ThreadSafeList();
private User baseUser;
public TrackedItem[] TrackingItems
{
diff --git a/HorseIsleServer/LibHISP/Player/Award.cs b/HorseIsleServer/LibHISP/Player/Award.cs
index d0ba64b..c6b9cf6 100755
--- a/HorseIsleServer/LibHISP/Player/Award.cs
+++ b/HorseIsleServer/LibHISP/Player/Award.cs
@@ -41,7 +41,7 @@ namespace HISP.Player
}
- private List awardsEarned;
+ private ThreadSafeList awardsEarned;
private User baseUser;
public AwardEntry[] AwardsEarned
{
@@ -84,7 +84,7 @@ namespace HISP.Player
{
baseUser = user;
int[] awards = Database.GetAwards(user.Id);
- awardsEarned = new List();
+ awardsEarned = new ThreadSafeList();
foreach (int awardid in awards)
{
diff --git a/HorseIsleServer/LibHISP/Player/Friends.cs b/HorseIsleServer/LibHISP/Player/Friends.cs
index 7b77d5f..0b33b76 100755
--- a/HorseIsleServer/LibHISP/Player/Friends.cs
+++ b/HorseIsleServer/LibHISP/Player/Friends.cs
@@ -7,7 +7,7 @@ namespace HISP.Player
public class Friends
{
private User baseUser;
- private List list;
+ private ThreadSafeList list;
public int[] List
{
get
@@ -36,7 +36,7 @@ namespace HISP.Player
public Friends(User user)
{
baseUser = user;
- list = new List();
+ list = new ThreadSafeList();
int[] friends = Database.GetBuddyList(user.Id);
foreach(int friendId in friends)
diff --git a/HorseIsleServer/LibHISP/Player/Highscore.cs b/HorseIsleServer/LibHISP/Player/Highscore.cs
index e26c752..8f2b06d 100755
--- a/HorseIsleServer/LibHISP/Player/Highscore.cs
+++ b/HorseIsleServer/LibHISP/Player/Highscore.cs
@@ -24,7 +24,7 @@ namespace HISP.Player
}
private User baseUser;
- private List highScoreList = new List();
+ private ThreadSafeList highScoreList = new ThreadSafeList();
public Highscore(User user)
{
diff --git a/HorseIsleServer/LibHISP/Player/Mailbox.cs b/HorseIsleServer/LibHISP/Player/Mailbox.cs
index 195bf04..f480076 100755
--- a/HorseIsleServer/LibHISP/Player/Mailbox.cs
+++ b/HorseIsleServer/LibHISP/Player/Mailbox.cs
@@ -9,7 +9,7 @@ namespace HISP.Player
public class Mailbox
{
private User baseUser;
- private List mails = new List();
+ private ThreadSafeList mails = new ThreadSafeList();
public int MailCount
{
get
diff --git a/HorseIsleServer/LibHISP/Player/MutedPlayers.cs b/HorseIsleServer/LibHISP/Player/MutedPlayers.cs
index 3ed1cfb..6c0abb0 100755
--- a/HorseIsleServer/LibHISP/Player/MutedPlayers.cs
+++ b/HorseIsleServer/LibHISP/Player/MutedPlayers.cs
@@ -6,10 +6,10 @@ namespace HISP.Player
public class MutedPlayers
{
private User baseUser;
- private List userIds;
+ private ThreadSafeList userIds;
public MutedPlayers(User BaseUser)
{
- userIds = new List();
+ userIds = new ThreadSafeList();
baseUser = BaseUser;
int[] userids = Database.GetMutedPlayers(BaseUser.Id);
diff --git a/HorseIsleServer/LibHISP/Player/PlayerQuests.cs b/HorseIsleServer/LibHISP/Player/PlayerQuests.cs
index 0238249..c23a091 100755
--- a/HorseIsleServer/LibHISP/Player/PlayerQuests.cs
+++ b/HorseIsleServer/LibHISP/Player/PlayerQuests.cs
@@ -5,7 +5,7 @@ namespace HISP.Player
{
public class PlayerQuests
{
- private List trackedQuests = new List();
+ private ThreadSafeList trackedQuests = new ThreadSafeList();
public User BaseUser;
public TrackedQuest[] QuestList
{
diff --git a/HorseIsleServer/LibHISP/Properties/AssemblyInfo.cs b/HorseIsleServer/LibHISP/Properties/AssemblyInfo.cs
index 86deb25..a82e404 100755
--- a/HorseIsleServer/LibHISP/Properties/AssemblyInfo.cs
+++ b/HorseIsleServer/LibHISP/Properties/AssemblyInfo.cs
@@ -30,5 +30,5 @@ using System.Runtime.InteropServices;
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
-[assembly: AssemblyVersion("1.7.121.0")]
-[assembly: AssemblyFileVersion("1.7.121.0")]
+[assembly: AssemblyVersion("1.7.123.0")]
+[assembly: AssemblyFileVersion("1.7.123.0")]
diff --git a/HorseIsleServer/LibHISP/Server/GameClient.cs b/HorseIsleServer/LibHISP/Server/GameClient.cs
index 0e8176e..108efc4 100755
--- a/HorseIsleServer/LibHISP/Server/GameClient.cs
+++ b/HorseIsleServer/LibHISP/Server/GameClient.cs
@@ -12,7 +12,7 @@ namespace HISP.Server
{
public class GameClient
{
- private static List connectedClients = new List();
+ private static ThreadSafeList connectedClients = new ThreadSafeList();
public static GameClient[] ConnectedClients // Done to prevent Enumerator Changed errors.
{
get
diff --git a/HorseIsleServer/LibHISP/Server/ThreadSafeList.cs b/HorseIsleServer/LibHISP/Server/ThreadSafeList.cs
new file mode 100644
index 0000000..35e1b47
--- /dev/null
+++ b/HorseIsleServer/LibHISP/Server/ThreadSafeList.cs
@@ -0,0 +1,67 @@
+using System.Collections;
+using System.Collections.Generic;
+using System.Threading;
+
+namespace HISP.Server
+{
+ public class ThreadSafeList : List
+ {
+ private Mutex listLock = new Mutex();
+ new public void AddRange(IEnumerable collection)
+ {
+ listLock.WaitOne();
+ base.AddRange(collection);
+ listLock.ReleaseMutex();
+ }
+ new public void Add(T value)
+ {
+ listLock.WaitOne();
+ base.Add(value);
+ listLock.ReleaseMutex();
+ }
+ new public void Clear()
+ {
+ listLock.WaitOne();
+ base.Clear();
+ listLock.ReleaseMutex();
+ }
+
+ new public bool Contains(T value)
+ {
+ listLock.WaitOne();
+ bool test = base.Contains(value);
+ listLock.ReleaseMutex();
+
+ return test;
+ }
+ new public IEnumerator GetEnumerator()
+ {
+ listLock.WaitOne();
+ IEnumerator res = base.ToArray().GetEnumerator();
+ listLock.ReleaseMutex();
+ return res;
+ }
+
+ new public void Insert(int index, T value)
+ {
+ listLock.WaitOne();
+ base.Insert(index, value);
+ listLock.ReleaseMutex();
+ }
+
+ new public void Remove(T value)
+ {
+ listLock.WaitOne();
+ base.Remove(value);
+ listLock.ReleaseMutex();
+ }
+
+ new public void RemoveAt(int index)
+ {
+ listLock.WaitOne();
+ base.RemoveAt(index);
+ listLock.ReleaseMutex();
+ }
+
+ }
+}
diff --git a/HorseIsleServer/MPN00BS/Properties/AssemblyInfo.cs b/HorseIsleServer/MPN00BS/Properties/AssemblyInfo.cs
index 14bf052..56341eb 100755
--- a/HorseIsleServer/MPN00BS/Properties/AssemblyInfo.cs
+++ b/HorseIsleServer/MPN00BS/Properties/AssemblyInfo.cs
@@ -30,5 +30,5 @@ using System.Runtime.InteropServices;
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
-[assembly: AssemblyVersion("1.7.121.0")]
-[assembly: AssemblyFileVersion("1.7.121.0")]
+[assembly: AssemblyVersion("1.7.123.0")]
+[assembly: AssemblyFileVersion("1.7.123.0")]