Thread Safe all the things

This commit is contained in:
Bluzume 2021-10-25 08:44:47 -04:00
parent 7122d978a6
commit 98d0c4bb5e
29 changed files with 143 additions and 96 deletions

View file

@ -2,6 +2,7 @@
using HISP.Player;
using HISP.Security;
using HISP.Server;
using System;
using System.Collections.Generic;
using System.Linq;
@ -11,6 +12,35 @@ namespace HISP.Game
{
public class Arena
{
private static List<Arena> arenas = new List<Arena>();
private List<ArenaEntry> entries;
private Timer arenaTimeout;
public int Id;
public string Type;
public int EntryCost;
public int RandomId;
public int RaceEvery;
public int Slots;
public string Mode;
public int Timeout;
public static Arena[] Arenas
{
get
{
return arenas.ToArray();
}
}
public ArenaEntry[] Entries
{
get
{
return entries.ToArray();
}
}
public class ArenaEntry
{
public User EnteredUser;
@ -18,7 +48,6 @@ namespace HISP.Game
public int SubmitScore = 0;
public bool Done = false;
}
public static List<Arena> Arenas = new List<Arena>();
public Arena(int id, string type, int entryCost, int raceEvery, int slots, int timeOut)
{
RandomId = RandomID.NextRandomId();
@ -29,29 +58,19 @@ namespace HISP.Game
RaceEvery = raceEvery;
Slots = slots;
Timeout = timeOut;
Arenas.Add(this);
Entries = new List<ArenaEntry>();
arenas.Add(this);
entries = new List<ArenaEntry>();
}
public int Id;
public string Type;
public int EntryCost;
public int RandomId;
public int RaceEvery;
public int Slots;
public string Mode;
public int Timeout;
public List<ArenaEntry> Entries;
private Timer arenaTimeout;
public bool HaveAllPlayersCompleted()
{
int playersCompleted = 0;
foreach(ArenaEntry entry in Entries.ToArray())
foreach(ArenaEntry entry in Entries)
{
if (entry.Done)
playersCompleted++;
}
if (playersCompleted >= Entries.Count)
if (playersCompleted >= Entries.Length)
return true;
else
return false;
@ -133,7 +152,7 @@ namespace HISP.Game
public void Start()
{
Mode = "COMPETING";
if (Entries.Count <= 0)
if (Entries.Length <= 0)
{
reset();
return;
@ -215,7 +234,7 @@ namespace HISP.Game
private void reset()
{
// Delete all entries
Entries.Clear();
entries.Clear();
RandomId = RandomID.NextRandomId();
Mode = "TAKINGENTRIES";
if (arenaTimeout != null)
@ -231,10 +250,10 @@ namespace HISP.Game
string[] avaliblePlacings = new string[6] { Messages.ArenaFirstPlace, Messages.ArenaSecondPlace, Messages.ArenaThirdPlace, Messages.ArenaFourthPlace, Messages.ArenaFifthPlace, Messages.ArenaSixthPlace };
int[] expRewards = new int[Entries.Count];
int[] expRewards = new int[Entries.Length];
expRewards[0] = 1;
int expAwardMul = 1;
for(int i = 1; i < Entries.Count; i++)
for(int i = 1; i < Entries.Length; i++)
{
expRewards[i] = 2 * expAwardMul;
@ -270,7 +289,7 @@ namespace HISP.Game
if (place == 0) // WINNER!
{
int prize = EntryCost * Entries.Count;
int prize = EntryCost * Entries.Length;
entry.EnteredUser.AddMoney(prize);
@ -279,30 +298,30 @@ namespace HISP.Game
// Awards:
if (Entries.Count >= 2 && Type == "JUMPING")
if (Entries.Length >= 2 && Type == "JUMPING")
entry.EnteredUser.Awards.AddAward(Award.GetAwardById(5)); // Good Jumper
if (Entries.Count >= 4 && Type == "JUMPING")
if (Entries.Length >= 4 && Type == "JUMPING")
entry.EnteredUser.Awards.AddAward(Award.GetAwardById(6)); // Great Jumper
if (Entries.Count >= 2 && Type == "RACING")
if (Entries.Length >= 2 && Type == "RACING")
entry.EnteredUser.Awards.AddAward(Award.GetAwardById(7)); // Good Racer
if (Entries.Count >= 4 && Type == "RACING")
if (Entries.Length >= 4 && Type == "RACING")
entry.EnteredUser.Awards.AddAward(Award.GetAwardById(8)); // Great Racer
if (Entries.Count >= 2 && Type == "DRESSAGE")
if (Entries.Length >= 2 && Type == "DRESSAGE")
entry.EnteredUser.Awards.AddAward(Award.GetAwardById(9)); // Good Dressage
if (Entries.Count >= 4 && Type == "DRESSAGE")
if (Entries.Length >= 4 && Type == "DRESSAGE")
entry.EnteredUser.Awards.AddAward(Award.GetAwardById(10)); // Great Dressage
if (Entries.Count >= 2 && Type == "DRAFT")
if (Entries.Length >= 2 && Type == "DRAFT")
entry.EnteredUser.Awards.AddAward(Award.GetAwardById(38)); // Strong Horse Award
if (Entries.Count >= 4 && Type == "DRAFT")
if (Entries.Length >= 4 && Type == "DRAFT")
entry.EnteredUser.Awards.AddAward(Award.GetAwardById(39)); // Strongest Horse Award
}
else
@ -336,7 +355,7 @@ namespace HISP.Game
foreach(ArenaEntry entry in Entries)
if(entry.EnteredUser.Id == user.Id)
{
Entries.Remove(entry);
entries.Remove(entry);
break;
}
}
@ -347,7 +366,7 @@ namespace HISP.Game
ArenaEntry arenaEntry = new ArenaEntry();
arenaEntry.EnteredUser = user;
arenaEntry.EnteredHorse = horse;
Entries.Add(arenaEntry);
entries.Add(arenaEntry);
}
}

View file

@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using HISP.Player;
using HISP.Server;

View file

@ -1,10 +1,11 @@
using HISP.Game.Services;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using HISP.Game.Services;
using HISP.Server;
using HISP.Game.Horse;
using System.Threading;
using HISP.Player;
namespace HISP.Game.Events

View file

@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using HISP.Player;
using HISP.Server;
using HISP.Game.Items;

View file

@ -1,6 +1,7 @@
using HISP.Game.Services;
using HISP.Server;
using HISP.Game.Items;
using System.Collections.Generic;
using System.Linq;

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using HISP.Server;
namespace HISP.Game.Items
@ -41,7 +42,6 @@ namespace HISP.Game.Items
public static DroppedItem[] GetItemsAt(int x, int y)
{
DroppedItem[] droppedItems = droppedItemsList.ToArray();
List<DroppedItem> items = new List<DroppedItem>();
for(int i = 0; i < droppedItems.Length; i++)

View file

@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HISP.Server;

View file

@ -4,12 +4,13 @@ using HISP.Game.Services;
using HISP.Player;
using HISP.Server;
using HISP.Game.Items;
using HISP.Game.Chat;
using HISP.Game.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using HISP.Game.Chat;
using HISP.Game.Events;
namespace HISP.Game
{
@ -2834,7 +2835,7 @@ namespace HISP.Game
}
message += Messages.FormatArenaCurrentlyTakingEntries(lastHours, lastMinutes, amOrPm, arena.RaceEvery - minutes);
if (arena.Entries.Count > arena.Slots)
if (arena.Entries.Length > arena.Slots)
{
message += Messages.ArenaCompetitionFull;
}

View file

@ -1,12 +1,31 @@
using HISP.Player;
using HISP.Server;
using System.Collections.Generic;
using System.Linq;
namespace HISP.Game
{
public class Multiroom
{
public static List<Multiroom> Multirooms = new List<Multiroom>();
private static List<Multiroom> multirooms = new List<Multiroom>();
private List<User> joinedUsers = new List<User>();
public int x;
public int y;
public User[] JoinedUsers
{
get
{
return joinedUsers.ToArray();
}
}
public static Multiroom[] Multirooms
{
get
{
return multirooms.ToArray();
}
}
public static Multiroom GetMultiroom(int x, int y)
{
foreach (Multiroom multiroom in Multirooms)
@ -51,20 +70,14 @@ namespace HISP.Game
this.x = x;
this.y = y;
Multirooms.Add(this);
multirooms.Add(this);
}
public int x;
public int y;
public List<User> JoinedUsers = new List<User>();
public void Join(User user)
{
if (!JoinedUsers.Contains(user))
{
Logger.DebugPrint(user.Username + " Joined multiroom @ " + x.ToString() + "," + y.ToString());
JoinedUsers.Add(user);
joinedUsers.Add(user);
foreach (User joinedUser in JoinedUsers)
if (joinedUser.Id != user.Id)
@ -81,7 +94,7 @@ namespace HISP.Game
if(JoinedUsers.Contains(user))
{
Logger.DebugPrint(user.Username + " Left multiroom @ " + x.ToString() + "," + y.ToString());
JoinedUsers.Remove(user);
joinedUsers.Remove(user);
}
foreach (User joinedUser in JoinedUsers)

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using HISP.Game.Inventory;
using HISP.Player;
using HISP.Server;

View file

@ -172,7 +172,7 @@ namespace HISP.Game.Services
foreach(AuctionBid bid in Bidders) // Cleanup some stuffs
{
if(bid.BidUser != null)
bid.BidUser.Bids.Remove(bid);
bid.BidUser.RemoveBid(bid);
}
Bidders.Clear();
}
@ -199,7 +199,7 @@ namespace HISP.Game.Services
else
newBid.BidAmount = 0;
newBid.PlaceBid(bidAmount);
bidder.Bids.Add(newBid);
bidder.AddBid(newBid);
Bidders.Add(newBid);
auctionRoomPlacedIn.UpdateAuctionRoom();
}

View file

@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

View file

@ -3,7 +3,7 @@ using HISP.Game.Items;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

View file

@ -1,7 +1,7 @@
using HISP.Game.Horse;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

View file

@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

View file

@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

View file

@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

View file

@ -1,6 +1,7 @@
using HISP.Server;
using System.Collections.Generic;
namespace HISP.Game.SwfModules
{
public class Brickpoet

View file

@ -1,7 +1,7 @@
using HISP.Server;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

View file

@ -1,7 +1,7 @@
using HISP.Server;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

View file

@ -117,7 +117,7 @@ namespace HISP.Game
}
private void updateOthers()
{
foreach(User user in this.Multiroom.JoinedUsers.ToArray())
foreach(User user in this.Multiroom.JoinedUsers)
if (IsPlayerInGame(user))
if(user.Id != Invitee.Id && user.Id != Inviting.Id)
GameServer.UpdateArea(user.LoggedinClient);

View file

@ -6,7 +6,7 @@ using HISP.Security;
using HISP.Server;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -58,13 +58,13 @@ namespace HISP.Player
Trader.LoggedinClient.SendPacket(negativeMoneyNotAllowed);
fail = true;
}
if (OtherTrade.Trader.Bids.Count > 0)
if (OtherTrade.Trader.Bids.Length > 0)
{
byte[] tradeNotAllowedWhileOtherBidding = PacketBuilder.CreateChat(Messages.TradeNotAllowedWhileOtherBidding, PacketBuilder.CHAT_BOTTOM_RIGHT);
Trader.LoggedinClient.SendPacket(tradeNotAllowedWhileOtherBidding);
fail = true;
}
if (Trader.Bids.Count > 0)
if (Trader.Bids.Length > 0)
{
byte[] tradeNotAllowedWhileBidding = PacketBuilder.CreateChat(Messages.TradeNotAllowedWhileBidding, PacketBuilder.CHAT_BOTTOM_RIGHT);
Trader.LoggedinClient.SendPacket(tradeNotAllowedWhileBidding);

View file

@ -1,17 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using HISP.Game;
using HISP.Server;
using HISP.Player.Equips;
using HISP.Game.Services;
using HISP.Game.Inventory;
using HISP.Game.Horse;
using System.Linq;
namespace HISP.Player
{
public class User
{
private List<Auction.AuctionBid> bids = new List<Auction.AuctionBid>();
public int Id;
public string Username;
@ -35,10 +38,16 @@ namespace HISP.Player
public bool NoClip = false;
public string Gender;
public bool MetaPriority = false;
public List<Auction.AuctionBid> Bids = new List<Auction.AuctionBid>();
public bool Idle;
public int Facing;
public Auction.AuctionBid[] Bids
{
get
{
return bids.ToArray();
}
}
public int MaxItems
{
get
@ -580,7 +589,15 @@ namespace HISP.Player
return SecCode;
}
public void AddBid(Auction.AuctionBid bid)
{
bids.Add(bid);
}
public void RemoveBid(Auction.AuctionBid bid)
{
bids.Remove(bid);
}
public User(GameClient baseClient, int UserId)
{
if (!Database.CheckUserExist(UserId))
@ -663,7 +680,7 @@ namespace HISP.Player
if(bid.BidAmount > 0)
{
Bids.Add(bid);
bids.Add(bid);
auctionEntry.Bidders.Add(bid);
}

View file

@ -1 +1 @@
1204d586bd47400b2a091e9906481f46da33a22a
7122d978a64c9cb9c9243a61c7d12fd61da558e7

View file

@ -1,6 +1,8 @@
using System.Linq;

using System.Security.Cryptography;
using System.Text;
using System.Linq;
using HISP.Server;
namespace HISP.Security

View file

@ -1,5 +1,4 @@
using System;
namespace HISP.Security
namespace HISP.Security
{
public class RandomID
{

View file

@ -454,7 +454,7 @@ namespace HISP.Server
{
case '3': // Money
if (sender.LoggedinUser.Bids.Count > 0)
if (sender.LoggedinUser.Bids.Length > 0)
{
byte[] cantBuyWhileAuctioning = PacketBuilder.CreateChat(Messages.AuctionNoOtherTransactionAllowed, PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.SendPacket(cantBuyWhileAuctioning);
@ -3832,8 +3832,6 @@ namespace HISP.Server
break;
}
if (!Database.SavedDrawingsExist(sender.LoggedinUser.Id))
Database.CreateSavedDrawings(sender.LoggedinUser.Id);
@ -3877,12 +3875,10 @@ namespace HISP.Server
int roomId = packet[3] - 40;
Drawingroom room;
try
{
try{
room = Drawingroom.GetDrawingRoomById(roomId);
}
catch (KeyNotFoundException)
{
catch (KeyNotFoundException){
Logger.ErrorPrint(sender.LoggedinUser.Username + " tried to load an invalid drawing room: " + roomId);
break;
}
@ -3909,20 +3905,17 @@ namespace HISP.Server
break;
}
if (room.Drawing.Length + drawingToAdd.Length < 65535) // will this max out the db?
{
try {
room.Drawing += drawingToAdd;
Database.SetLastPlayer("D" + room.Id.ToString(), sender.LoggedinUser.Id);
UpdateAreaForAll(sender.LoggedinUser.X, sender.LoggedinUser.Y, true);
}
else
{
catch(DrawingroomFullException){
byte[] roomFullMessage = PacketBuilder.CreateChat(Messages.DrawingPlzClearLoad, PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.SendPacket(roomFullMessage);
break;
}
room.Drawing += drawingToAdd;
Database.SetLastPlayer("D" + room.Id.ToString(), sender.LoggedinUser.Id);
UpdateAreaForAll(sender.LoggedinUser.X, sender.LoggedinUser.Y, true);
UpdateDrawingForAll("D" + room.Id, sender, drawingToAdd, true);
byte[] loadedDrawingMessage = PacketBuilder.CreateChat(Messages.FormatDrawingRoomLoaded(slotNo), PacketBuilder.CHAT_BOTTOM_RIGHT);
@ -3962,22 +3955,19 @@ namespace HISP.Server
string drawing = packetStr.Substring(3, packetStr.Length - 5);
if (drawing.Contains("X")) // Clear byte
{
room.Drawing = "";
}
else if(room.Drawing.Length + drawing.Length < 65535) // will this max out the db?
{
try {
room.Drawing += drawing;
Database.SetLastPlayer("D" + room.Id.ToString(), sender.LoggedinUser.Id);
UpdateAreaForAll(sender.LoggedinUser.X, sender.LoggedinUser.Y, true);
}
else
catch (DrawingroomFullException)
{
byte[] roomFullMessage = PacketBuilder.CreateChat(Messages.DrawingPlzClearDraw, PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.SendPacket(roomFullMessage);
break;
}
Database.SetLastPlayer("D" + room.Id.ToString(), sender.LoggedinUser.Id);
UpdateAreaForAll(sender.LoggedinUser.X, sender.LoggedinUser.Y, true);
UpdateDrawingForAll("D" + room.Id, sender, drawing, false);
}
@ -5279,7 +5269,7 @@ namespace HISP.Server
}
}
if (sender.LoggedinUser.Bids.Count > 0)
if (sender.LoggedinUser.Bids.Length > 0)
{
byte[] cantBuyWhileAuctioning = PacketBuilder.CreateChat(Messages.AuctionNoOtherTransactionAllowed, PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.SendPacket(cantBuyWhileAuctioning);
@ -6921,7 +6911,7 @@ namespace HISP.Server
if (shop != null)
{
int buyCost = shop.CalculateBuyCost(itemInfo) * count;
if (sender.LoggedinUser.Bids.Count > 0)
if (sender.LoggedinUser.Bids.Length > 0)
{
byte[] cantBuyWhileAuctioning = PacketBuilder.CreateChat(Messages.AuctionNoOtherTransactionAllowed, PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.SendPacket(cantBuyWhileAuctioning);

View file

@ -1,7 +1,7 @@
using HISP.Properties;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;