It is currently 27 Jan 2020, 15:15
Text Size

Manalink 3.0 multiplayers setup and test

Discuss Upcoming Releases, Coding New Cards, Etc.

Moderators: BAgate, drool66, stassy, Aswan jaguar, gmzombie, CCGHQ Admins

Re: Manalink 3.0 multiplayers setup and test

Postby Korath » 14 Sep 2015, 18:39

The three most obvious things that'll desync multiplayer are
  1. generating random numbers and not sending them over the network
  2. calling the non-network-aware versions of low-level UI choice functions (I think the only one Manalink uses is choose_a_card()) without communicating the result over the network
  3. treating players 0 (the human in a human-AI duel, or the local player in multiplayer) and 1 (the AI in a human-AI duel, or the remote player in multiplayer) differently.
Misuse of random numbers is easy to find - grep finds 152 uses of internal_rand() in Manalink source, essentially all of them problematic - but not terribly difficult to fix. There's a function at 0x44E070 that I've labeled network_rand_raw() which takes a player and an upper bound (the same way internal_rand() does), and either picks a random number and sends it if player is the local player, or waits to receive the random number if player is the remote one. All you need to do is make a front end that calls that instead of internal_rand() during multiplayer, like I've done in network_rand() in src/shandalar/ai.cpp.

There's no premade network-aware front end for choose_a_card(), since it was originally only used for Ring of Ma'ruf, but the network handling for it can be lifted out of that card's function in magic.exe.

The third case is the hardest to automatically find, the most extensive, and the hardest to fix. There are many, many cases where, instead of coaxing the AI to choose to do the right thing, it's instead forced to - Energy Arc, for example, can only legally target non-attacking creatures if player 0 is casting it; and many cards similar to Bloodthirsty Ogre have end-of-turn triggers forcing them to activate if controlled by player 1. So if one player - remember, both players in a network game think they're player 0, and the other is player 1 - casts Energy Arc and targets a blocking creature, the other player is going to think the target's illegal; and if someone controls an untapped Bloodthirsty Ogre at the end of his opponent's turn, the other player is going to think it has more devotion counters than it should. Kaboom.
User avatar
Posts: 3412
Joined: 02 Jun 2013, 05:57
Has thanked: 482 times
Been thanked: 955 times


Return to Development

Who is online

Users browsing this forum: No registered users and 1 guest

Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest (based on users active over the past 10 minutes)
Most users ever online was 955 on 14 Jan 2020, 08:22

Users browsing this forum: No registered users and 1 guest

Login Form