Page 11 of 13

Re: Network Multiplayer (Multi-human players)

PostPosted: 01 Feb 2015, 19:37
by Max mtg
I feel like it's totally impossible (for me at least) to make a propper client-server multiplayer out of the current codebase. So I made an attempt to go back to the moment before those 'views' were added (that is early October 2014) and start refactoring from that point.

Not sure if that would lead me to any success, but that seems to be the latest point where I am still able to manage the code.

Re: Network Multiplayer (Multi-human players)

PostPosted: 01 Feb 2015, 20:59
by drdev
If you don't mind me asking, what's your plan? A lot of work has been done in the last 4 months, so it seems a shame to throw it all out. Is there no way to work with the TrackableObject structure I created?

That said, feel free to experiment on a separate branch if you want to try out other ideas. If it ultimately leads to network play, then it will all be worth it.

Re: Network Multiplayer (Multi-human players)

PostPosted: 01 Feb 2015, 22:06
by elcnesh
Oh dear... I've actually been experimenting the last few days with getting multiple games to work (see other thread), for which I've also had to change things like this, separating the view more from the model... Maybe we can get some sort of integrated approach out of this? Some things definitely have to change to get both projects to work (like calls to *the* static Game that's being run by Forge, which should not be a variable that exists anywhere in the code), but I also agree that throwing away 1000 commits is a bit of a waste :)

Maybe we can get together on chat sometime to get a slightly more direct discussion? I feel that the communication through the forum is a bit too indirect to come to a conclusion efficiently.

Re: Network Multiplayer (Multi-human players)

PostPosted: 01 Feb 2015, 22:18
by Max mtg
My plan is to attempt to clean up the game project, just starting with re-engineering the foundation classes such as Card, Triggers, Game, etc. cutting away during the experiments the new sets, mobiles, new game modes.

I want to experiment with card state to hold those over 100 fields present in the card class in a different place. Doubling that amount of fields and members with the *View counterparts would make the task double that hard, so I've stopped on October 6th to possibly plot a different path of forge evolution.

This is a research project, carried out in a separate branch.

We'll see how to keep those 4 months of work later, if I ever manage to start real multiplayer games.

Re: Network Multiplayer (Multi-human players)

PostPosted: 17 Feb 2015, 09:07
by elcnesh
The change I just committed should be another step in the direction of network games. I've separated the connection between game and gui into three parts, which'll need to be tied together using network methods (with which I'm not familiar at all, unfortunately):
  • PlayerControllerHuman requests choices from an IGuiGame (implemented by CMatchUI and MatchController for desktop and mobile, resp.)
  • The Gui makes player-specific requests to an IGameController (implemented by PlayerControllerHuman)
  • The Gui makes non-player-specific requests to a GameView

Re: Network Multiplayer (Multi-human players)

PostPosted: 27 Feb 2015, 14:30
by elcnesh
I'm happy to announce that Agetian and I have just had our first chat conversation IN THE FORGE CLIENT!!! This is actually going somewhere :)

Lots of work to be done before we get an actual working Lobby, let alone playing a real network game, but this shows that at least the network communication works.

Re: Network Multiplayer (Multi-human players)

PostPosted: 07 Mar 2015, 02:09
by friarsol
Ok, I'm pretty sure the reports in the beta thread of blank error messages (for player controllers) are somehow related to this code. Simple repro is to cast Worst Fears and end your turn.

I debugged it down to this:

Code: Select all
AbstractGuiGame.mayView() : if (getGameController().mayLookAtAllCards())
getGameController tries to grab the owner of the turn (the AI who I'm now controlling).

Code: Select all
return gameControllers.get(getCurrentPlayer());
but getCurrentPlayer isn't actually in gameControllers because they are being temporarily controller. I'm not sure what should happen here, or what exactly is going on in this code. (Even if your turn is being taken over, shouldn't you still be able to see all your cards?) but something needs to be fixed here.

I tried just adding a
Code: Select all
getGameController() != null
to this conditional, which gets me past that, but when I press OK to pass priority for the AI I get another crash

Code: Select all
at forge.screens.match.controllers.CPrompt.selectButtonOk(CPrompt.java:100)
at forge.screens.match.controllers.CPrompt$2.actionPerformed(CPrompt.java:71)
And it looks like it's a similar issue because selectButtonOk can't find the controller in the view:

Code: Select all
matchUI.getGameController().selectButtonOk();

Re: Network Multiplayer (Multi-human players)

PostPosted: 19 Apr 2015, 14:43
by drdev
What's the state of this project? Is it worth starting to work on the mobile UI for it?

Re: Network Multiplayer (Multi-human players)

PostPosted: 20 Apr 2015, 13:10
by elcnesh
Currently rewriting some classes for it, but I don't have a lot of time for testing unfortunately... I'm thinking about opening it up to beta (alpha?) testing with the warning that it's extremely unstable right now. Either way it's worth writing a GUI for, although to warn you: I've had to rewrite the entire desktop lobby code to make it network compatible. For mobile this should be easier with only two players, but that's probably still the biggest hurdle. The actual match UI code should hardly need to change. If you have any questions, don't hesitate to ask :)

Re: Network Multiplayer (Multi-human players)

PostPosted: 01 Jun 2015, 00:25
by drdev
So good news. I've now got the mobile app set up so it can connect and communicate with the desktop application via the network support. I haven't tested game play yet, but at least chat communication is working.

NetworkChat.PNG

That said, I'm wondering if people have thoughts on making it easier to connect with others and join a server they've hosted. For now, I'm going to make it copy a url to the clipboard that can be shared over email, etc. where the other person(s) can enter that url when prompted to join that server. I can then add a menu option to copy that url again in case your clipboard gets cleared. As I mentioned, the hostname and port are combined in this url in the form <hostname>:<port>.

Thoughts on this are appreciated. Thanks.
-Dan

EDIT: So I got it set up so it can copy the url to the clipboard, however I can't figure out how to access a public hostname that can be accessed outside of a local area network. Is there a way to get at that so I can copy a url that can be shared with someone elsewhere? Also, is there a way to tell if the hosted server can be accessed publically so I can warn if not?

Re: Network Multiplayer (Multi-human players)

PostPosted: 01 Jun 2015, 08:14
by fYHGfJ
drdev wrote:EDIT: So I got it set up so it can copy the url to the clipboard, however I can't figure out how to access a public hostname that can be accessed outside of a local area network. Is there a way to get at that so I can copy a url that can be shared with someone elsewhere? Also, is there a way to tell if the hosted server can be accessed publically so I can warn if not?
You mean you don't know how to programmatically find out what hostname / public IP the server has? I don't think this is easy without a central matchmaking server. A computer outside the LAN can see the public IP (<- better way), and it might be possible to "ask" the router for the public IP (<- unreliable way).

A more readable public DNS "hostname" representation of the IP may be found by doing a reverse DNS lookup for the public IP (apparently InetAddress.getHostName() does this) or by checking what hostname is configured on the server's computer (e.g. with the gethostname C function). The latter is hard to get at and may not actually be a public hostname. The reverse DNS lookup may return wrong information as well, e.g. my internet service provider has a misconfigured DNS. It might be better to just go with the public IP.

About the second issue: Afaik the only reliable way to tell if a server can be accessed from another computer is to try. Typically, the issue is that a firewall on the server blocks the port or that a router is not configured to forward the port to this particular server. You'd need a computer outside the LAN to try if it can connect. A central matchmaking server could do that, but I don't think Forge will have one?

Re: Network Multiplayer (Multi-human players)

PostPosted: 01 Jun 2015, 08:31
by fYHGfJ
On second thought, you could make it query icanhazip to get the public IP. Better do that only after a manual request by the user though, I don't know if the people hosting icanhazip like entirely automated queries the user may not even be interested in. There's also an FAQ for icanhazip -- I can't post the URL because I'm new to the forum, but you can find it with a quick web search. This would make Forge rely on an external service though that may or may not be available and may or may not serve data that really is your IP.

Re: Network Multiplayer (Multi-human players)

PostPosted: 06 Jun 2015, 18:37
by drdev
So as an update, I took some time and improved the chat screen look for the mobile app. Let me know what you think.

ChatScreen.png

Re: Network Multiplayer (Multi-human players)

PostPosted: 11 Jun 2015, 03:17
by Bog Wraith
I tried to set up a game between my wife who was on my Windows machine and myself on my Mac using our LAN.

We tried it with the Win machine hosting and me connecting and then the other way around. The person who was hosting the game could get to the lobby and select their deck, but the person trying to connect just kept getting timed out and then the game would crash.

No matter how we tried, we could never connect with the person hosting the game. The host was always in the lobby, but the joinee (sic) could never enter the lobby.

Here are the two bug reports from those attempts, one from the Windows machine & one from the Mac.

I have removed all of the ip numbers except the first set in each of the two examples for privacy reasons. (I realize the ip numbers do not reflect my true ip, but I still like to keep the entire address hidden.) The 192. is the first set of numbers for the Windows ip address & the 10. is from the Mac ip's first set.

Windows Crash Report:


| Open
Description: Attempting to connect to lobby.

[spoiler=ConnectException]
Code: Select all
Forge Version:    1.5.41-SNAPSHOT-r-1u
Operating System: Windows 7 6.1 x86
Java Version:     1.8.0_40 Oracle Corporation

java.net.ConnectException: Connection timed out: no further information: /10.
   at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
   at sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)
   at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:208)
   at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:281)
   at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:528)
   at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
   at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
   at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
   at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
   at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
   at java.lang.Thread.run(Unknown Source)
Mac Crash Report:

| Open
Description: Attempting to connect to lobby.

[spoiler=ConnectTimeoutException]
Code: Select all
Forge Version:    1.5.41-SNAPSHOT-r-1u
Operating System: Mac OS X 10.10.3 x86_64
Java Version:     1.7.0_75 Oracle Corporation

io.netty.channel.ConnectTimeoutException: connection timed out: /192.
   at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:212)
   at io.netty.util.concurrent.PromiseTask$RunnableAdapter.call(PromiseTask.java:38)
   at io.netty.util.concurrent.ScheduledFutureTask.run(ScheduledFutureTask.java:123)
   at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:380)
   at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357)
   at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
   at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
   at java.lang.Thread.run(Thread.java:745)
Sorry I can't be more helpful as I am not a programmer or know anything about these technical issues.

I can say that with the same two computers, we have been able to in the past, host & play with both Magic Work Station and XMage as well as some other kinds of games that aren't related to MTG.

Hope this helps. I'm very keen on getting this to work so I am more than willing to test this out as it continues to develop.

Re: Network Multiplayer (Multi-human players)

PostPosted: 13 Jun 2015, 19:46
by drdev
Is network play working for anyone right now? I've been trying to get the mobile app to be able to play a game against the desktop, but right now only the hosting app is getting any game information and if the joining app tries to take an action, the game crashes. I can reproduce with desktop v. desktop, so it's not an issue specific to the mobile app.

The crash is the result of the joining player not having a currentPlayer set in AbstractGuiGame, but I don't know why none of the other game information is syncing.