It is currently 16 Apr 2024, 20:45
   
Text Size

Network Multiplayer (Multi-human players)

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

Re: Network Multiplayer (Multi-human players)

Postby Max mtg » 01 Feb 2015, 19:37

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.
Single class for single responsibility.
Max mtg
Programmer
 
Posts: 1997
Joined: 02 Jul 2011, 14:26
Has thanked: 173 times
Been thanked: 334 times

Re: Network Multiplayer (Multi-human players)

Postby drdev » 01 Feb 2015, 20:59

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.
drdev
Programmer
 
Posts: 1958
Joined: 27 Jul 2013, 02:07
Has thanked: 189 times
Been thanked: 565 times

Re: Network Multiplayer (Multi-human players)

Postby elcnesh » 01 Feb 2015, 22:06

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.
elcnesh
 
Posts: 290
Joined: 16 May 2014, 15:11
Location: Netherlands
Has thanked: 34 times
Been thanked: 92 times

Re: Network Multiplayer (Multi-human players)

Postby Max mtg » 01 Feb 2015, 22:18

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.
Single class for single responsibility.
Max mtg
Programmer
 
Posts: 1997
Joined: 02 Jul 2011, 14:26
Has thanked: 173 times
Been thanked: 334 times

Re: Network Multiplayer (Multi-human players)

Postby elcnesh » 17 Feb 2015, 09:07

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
elcnesh
 
Posts: 290
Joined: 16 May 2014, 15:11
Location: Netherlands
Has thanked: 34 times
Been thanked: 92 times

Re: Network Multiplayer (Multi-human players)

Postby elcnesh » 27 Feb 2015, 14:30

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.
elcnesh
 
Posts: 290
Joined: 16 May 2014, 15:11
Location: Netherlands
Has thanked: 34 times
Been thanked: 92 times

Re: Network Multiplayer (Multi-human players)

Postby friarsol » 07 Mar 2015, 02:09

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();
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: Network Multiplayer (Multi-human players)

Postby drdev » 19 Apr 2015, 14:43

What's the state of this project? Is it worth starting to work on the mobile UI for it?
drdev
Programmer
 
Posts: 1958
Joined: 27 Jul 2013, 02:07
Has thanked: 189 times
Been thanked: 565 times

Re: Network Multiplayer (Multi-human players)

Postby elcnesh » 20 Apr 2015, 13:10

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 :)
elcnesh
 
Posts: 290
Joined: 16 May 2014, 15:11
Location: Netherlands
Has thanked: 34 times
Been thanked: 92 times

Re: Network Multiplayer (Multi-human players)

Postby drdev » 01 Jun 2015, 00:25

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?
Last edited by drdev on 01 Jun 2015, 16:05, edited 1 time in total.
drdev
Programmer
 
Posts: 1958
Joined: 27 Jul 2013, 02:07
Has thanked: 189 times
Been thanked: 565 times

Re: Network Multiplayer (Multi-human players)

Postby fYHGfJ » 01 Jun 2015, 08:14

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?
fYHGfJ
 
Posts: 2
Joined: 01 Jun 2015, 07:41
Has thanked: 0 time
Been thanked: 0 time

Re: Network Multiplayer (Multi-human players)

Postby fYHGfJ » 01 Jun 2015, 08:31

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.
fYHGfJ
 
Posts: 2
Joined: 01 Jun 2015, 07:41
Has thanked: 0 time
Been thanked: 0 time

Re: Network Multiplayer (Multi-human players)

Postby drdev » 06 Jun 2015, 18:37

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
drdev
Programmer
 
Posts: 1958
Joined: 27 Jul 2013, 02:07
Has thanked: 189 times
Been thanked: 565 times

Re: Network Multiplayer (Multi-human players)

Postby Bog Wraith » 11 Jun 2015, 03:17

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.
'Twas in the bogs of Cannelbrae
My mate did meet an early grave
'Twas nothing left for us to save
In the peat-filled bogs of Cannelbrae.
User avatar
Bog Wraith
Global Mod 1 (Ret)
 
Posts: 1108
Joined: 28 May 2008, 22:40
Location: Shandalar
Has thanked: 425 times
Been thanked: 153 times

Re: Network Multiplayer (Multi-human players)

Postby drdev » 13 Jun 2015, 19:46

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.
drdev
Programmer
 
Posts: 1958
Joined: 27 Jul 2013, 02:07
Has thanked: 189 times
Been thanked: 565 times

PreviousNext

Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 59 guests


Who is online

In total there are 59 users online :: 0 registered, 0 hidden and 59 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 59 guests

Login Form