eonarheim / AntAICompetition

Simple Ant Hill AI Competition Simulation Server
4 stars 1 forks source link

server crashes when sending ant update with a null direction #24

Closed FourierTransformer closed 9 years ago

FourierTransformer commented 9 years ago

Just send an antid with a null/empty direction to api/game/update and it'll crash the server and all running games. FUN STUFFS!

eonarheim commented 9 years ago

Woah! That is a huge bug will try to fix that asap!

eonarheim commented 9 years ago

@FourierTransformer I can't reproduce by sending an empty a null/empty direction. There is some check logic that makes sure a direction is valid already.

if (updateRequest.MoveAntRequests.Any(ma => ma.Direction == "up" || ma.Direction == "down" || ma.Direction == "left" || ma.Direction == "right"))
{
    return true;
}

Is it possible you are sending an invalid gameid as well? Cause I can definitely get the server to crash then.

FourierTransformer commented 9 years ago

it is entirely possible - an algo was going ham at the time and returning null values all over the place. I only checked the direction to confirm suspicion - but yeah Entirely possible.

FourierTransformer commented 9 years ago

Actually hold that thought, just rolled back to the commit. Here's the relevant json:

"MoveAntRequests":[{"antId":6},{"antId":3,"direction":"down"},{"antId":9,"direction":"right"},{"antId":1,"direction":"right"}]

it complains about antId:6 and errors out on the direction=direction.ToLower() in Board.cs because there is no direction associated.

        private void UpdateAnt(Game game, int antId, string direction)
        {
            direction = direction.ToLower();
            var ant = Ants.FirstOrDefault(a => a.Id == antId);
            if (ant != null)
            {
                var newX = ant.X;
eonarheim commented 9 years ago

@FourierTransformer Oh yeah, definitely an issue