eonarheim / AntAICompetition

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

Multiple issues running it locally #12

Open szalapski opened 9 years ago

szalapski commented 9 years ago

I got the sample agent to run well against the Azure site, but not locally. Locally, I got the following UnsupportedMediaTypeException. I might look into it.

No MediaTypeFormatter is available to read an object of type 'LogonResult' from content with media type 'text/html'.

Stack Trace at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken) at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable1 formatters, IFormatterLogger formatterLogger) at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, IEnumerable1 formatters) at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content) at SampleAgent.AgentBase.<Logon>d__2.MoveNext() in c:\Projects\github\AntAICompetition\SampleAgent\AgentBase.cs:line 39 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at SampleAgent.AgentBase.d__19.MoveNext() in c:\Projects\github\AntAICompetition\SampleAgent\AgentBase.cs:line 90

szalapski commented 9 years ago

Generated from: var agent = new ProvidedSampleAgent("Sample Agent", "http://localhost:16901/"); agent.Start().Wait();

szalapski commented 9 years ago

Hmmm, seems to be because I am getting a 401 locally. Request: {Method: POST, RequestUri: 'http://localhost:16901/api/game/logon', Version: 1.1, Content: System.Net.Http.ObjectContent`1[[SampleAgent.ApiDTOs.LogonRequest, SampleAgent, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], Headers: { Accept: application/json Content-Type: application/json; charset=utf-8 Content-Length: 42 }}

Response: {StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { X-SourceFiles: =?UTF-8?B?QzpcUHJvamVjdHNcZ2l0aHViXEFudEFJQ29tcGV0aXRpb25cQW50QUlDb21wZXRpdGlvblxhcGlcZ2FtZVxsb2dvbg==?= Cache-Control: private Server: Microsoft-IIS/8.0 WWW-Authenticate: Negotiate WWW-Authenticate: NTLM X-Powered-By: ASP.NET Date: Wed, 07 Jan 2015 19:14:50 GMT Content-Length: 6129 Content-Type: text/html; charset=utf-8 }}

szalapski commented 9 years ago

Is this intended to work locally?

eonarheim commented 9 years ago

@szalapski It is intended to work locally, based on your error it almost looks like it is trying to use windows authentication and piping back a 401. Are you running the site locally via IIS or through the vs debugger?

szalapski commented 9 years ago

Default settings, which seem to be IIS Express. So probably I should disable authentication and just use anonymous?

eonarheim commented 9 years ago

@szalapski I think so, but it is strange that you are having the issue locally and I am not.

szalapski commented 9 years ago

I added the following to my web.config, but doing so gives me an error "The requested page cannot be accessed because the related configuration data for the page is invalid", with " This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false". " Never saw that before.

<system.webServer> <security> <authentication> <anonymousAuthentication enabled="true" /> <windowsAuthentication enabled="false" /> </authentication> </security> ...

szalapski commented 9 years ago

I got past this by editing my applicationhost.config (at My Documents\IISExpress\config\applicationhost.config) and removing the overrideModeDefault="Deny" attributes for the authentication options.

szalapski commented 9 years ago

OK, got it working but without an opponent. I assume the Azure hosted one does this on the server but the code for that is different somehow locally. Any tips on how to set up an opponent?

szalapski commented 9 years ago

I debugged it and I see that game.Players has 1, but game._numPlayers ==2, and there is no demo player, and the code that adds the Demo Player did indeed execute.

szalapski commented 9 years ago

capture

szalapski commented 9 years ago

Hmmm, two things:

(1) game.LogonDemoAgent starts a new task and then returns. LogonDemoAgent isn't async itself. What if the task isn't done before it returns? (The Wait here is happening inside the task--it doesn't make the containing function itself wait.)

(2) The agent started in game.LogonDemoAgent is never added to the game. Is this right?

eonarheim commented 9 years ago

@szalapski (2)When running locally, the server uses the SampleAgent project in the solution. So it is possible that modifications to the SampleAgent project would cause the agent to not logon properly. I'd be interested to review your local configuration to pin point the issue, I'm not able to reproduce on my machine.

For (1) I assume the chunk of code you are talking about is

public void LogonDemoAgent()
{
    if (!_demoAgentStarted)
    {
        _demoAgentStarted = true;
        var agentTask = Task.Factory.StartNew(() =>
        {
            var agent = new Agent("Demo Agent");
            agent.Start(this.Id).Wait();
        });
    }
}

I think that this is okay since the Demo agent is a long running task on the game server, hence why I fired it off with the Task.Factory and block on the async agent.Start with the .Wait()

FourierTransformer commented 9 years ago

I too am getting a similar result of having a "one player game". This is from a fresh clone of the repo with no modifications to any of the code running through the VS debugger.

szalapski commented 9 years ago

For me, I had to be sure to adjust the client endpoint of both agents in a game. The server (local or remote) will not do this for you.

On Sat, Jan 17, 2015 at 5:06 PM, Shakil Thakur notifications@github.com wrote:

I too am getting a similar result of having a "one player game". This is from a fresh clone of the repo with no modifications to any of the code running through the VS debugger.

— Reply to this email directly or view it on GitHub https://github.com/eonarheim/AntAICompetition/issues/12#issuecomment-70388532 .

FourierTransformer commented 9 years ago

Ah, that makes sense and now I've got it working! Thanks!

— Sent from Mailbox

On Sat, Jan 17, 2015 at 6:03 PM, szalapski notifications@github.com wrote:

For me, I had to be sure to adjust the client endpoint of both agents in a game. The server (local or remote) will not do this for you. On Sat, Jan 17, 2015 at 5:06 PM, Shakil Thakur notifications@github.com wrote:

I too am getting a similar result of having a "one player game". This is from a fresh clone of the repo with no modifications to any of the code running through the VS debugger.

— Reply to this email directly or view it on GitHub https://github.com/eonarheim/AntAICompetition/issues/12#issuecomment-70388532 .


Reply to this email directly or view it on GitHub: https://github.com/eonarheim/AntAICompetition/issues/12#issuecomment-70390304

eonarheim commented 9 years ago

@szalapski Thanks for the help! Definitely need that readme #11