Fix Arena TOCTOU

This commit is contained in:
SilicaAndPina 2021-05-12 22:14:22 +12:00
parent ab05db6cbf
commit 51223172c4
4 changed files with 35 additions and 11 deletions

View file

@ -132,12 +132,12 @@ namespace HISP.Game
}
public void Start()
{
if(Entries.Count <= 0)
Mode = "COMPETING";
if (Entries.Count <= 0)
{
reset();
return;
}
Mode = "COMPETING";
foreach(ArenaEntry entry in Entries.ToArray())
{
string swf = getSwf(entry);
@ -299,7 +299,6 @@ namespace HISP.Game
if (Entries.Count >= 4 && Type == "DRESSAGE")
entry.EnteredUser.Awards.AddAward(Award.GetAwardById(10)); // Great Dressage
if (Entries.Count >= 2 && Type == "DRAFT")
entry.EnteredUser.Awards.AddAward(Award.GetAwardById(38)); // Strong Horse Award
@ -341,12 +340,15 @@ namespace HISP.Game
break;
}
}
public void AddEntry(User user, Horse.HorseInstance horse)
public void AddEntry(User user, HorseInstance horse)
{
ArenaEntry arenaEntry = new ArenaEntry();
arenaEntry.EnteredUser = user;
arenaEntry.EnteredHorse = horse;
Entries.Add(arenaEntry);
if(!UserHasHorseEntered(user))
{
ArenaEntry arenaEntry = new ArenaEntry();
arenaEntry.EnteredUser = user;
arenaEntry.EnteredHorse = horse;
Entries.Add(arenaEntry);
}
}
public static Arena GetArenaUserEnteredIn(User user)
@ -369,7 +371,8 @@ namespace HISP.Game
foreach(Arena arena in Arenas)
{
if (minutes % arena.RaceEvery == 0)
arena.Start();
if(arena.Mode == "TAKINGENTRIES")
arena.Start();
}
}

View file

@ -69,6 +69,8 @@ namespace HISP.Game.Chat
return Command.UnBan(message, args, user);
if (message.ToUpper().StartsWith("%ESCAPE"))
return Command.Escape(message, args, user);
if (message.ToUpper().StartsWith("%CALL HORSE"))
return Command.CallHorse(message, args, user);
return false;
}

View file

@ -4,6 +4,7 @@ using HISP.Game.Items;
using System;
using System.Collections.Generic;
using HISP.Game.Events;
using HISP.Game.Horse;
namespace HISP.Game.Chat
{
@ -354,6 +355,23 @@ namespace HISP.Game.Chat
return true;
}
public static bool CallHorse(string message, string[] args, User user)
{
string formattedmessage = Messages.FormatPlayerCommandCompleteMessage(message.Substring(1));
WildHorse horse = WildHorse.WildHorses[GameServer.RandomNumberGenerator.Next(0, WildHorse.WildHorses.Length)];
horse.X = user.X;
horse.Y = user.Y;
GameServer.UpdateAreaForAll(user.X, user.Y);
byte[] chatPacket = PacketBuilder.CreateChat(formattedmessage, PacketBuilder.CHAT_BOTTOM_LEFT);
user.LoggedinClient.SendPacket(chatPacket);
return true;
}
public static bool Dance(string message, string[] args, User user)
{
string moves = string.Join(" ", args).ToLower();

View file

@ -157,7 +157,7 @@ namespace HISP.Game.Horse
public void Escape()
{
while(true)
for(int i = 0; i < 100; i++)
{
int tryX = X + GameServer.RandomNumberGenerator.Next(-5, 5);
int tryY = Y + GameServer.RandomNumberGenerator.Next(-5, 5);
@ -168,10 +168,11 @@ namespace HISP.Game.Horse
{
X = tryX;
Y = tryY;
break;
return;
}
}
Logger.ErrorPrint("Horse is stuck (cannot move after 1000 tries) " + Instance.Breed.Name + " at X" + X + " Y" + Y);
}
public void Capture(User forUser)