Monday, November 14, 2011

Playing Magic the Gathering on Linux with Cockatrice

If you ask almost anyone that knows me in person they will attest to the fact that I am a huge nerd. Today I would like to give a short tutorial on how I've combined two of my most nerdy passions:


For the uninformed, Linux is my operating system of choice and Magic the Gathering is a trading card game created by Wizards of the Coast. I recently came across an open source application that is being written in C++ and QT4 called Cockatrice that allows you to play Magic the Gathering games over the internet for no charge. I intend to do a full review/overview of all the features Cockatrice offers at some point in the near future, today however I would simply like to go through how the get this excellent piece of software installed and setup on Linux.

Installation:

If you are using Bodhi Linux then you are in luck, Cockatrice is in our official repositories. Grab it from our App Center or by simply install it by running:

sudo apt-get install cockatrice

If you are running something other than Bodhi Linux that is still Debian based I try to keep the .deb packages I create fairly generic. You can try manually downloading and installing my package from here. If you now have Cockatrice installed you can skip down to configuration section below. 

If that doesn't work (or if you are using some other distribution) compiling Cockatrice from source isn't a huge deal. The exact package names will vary based on your distribution but you need to first install: Git, GCC, QT4 Developmental, QT4 Mobility and Pulse Audio. Next download the source code from here, extract it and run the following from the source directory:

cmake .
make
sudo make install

Depending on the speed of your system the make lines may take a little while, if all goes without errors you will be set to move on.

Configuration:

Next you just need to take care of a few configuration things and you will be ready to start slinging some cards. If you installed Cockatrice from my Debian package you will have two new menu entries under Applications->Games. First you need to run the Cockatrice card downloader (if you built Cockatrice from source run the command oracle). You will be greeted with a window that looks like:



Click File->Download Sets and then select OK on the window that pops up. Next, check the boxes next to the sets you want to download (really it is best to just check them all) and hit start download:


Wait for this to finish (it will take a while based on how fast your internet is). Once it is done, load Cockatrice (cockatrice if you installed from source). You will be greeted by a configuration window that looks like:


You will need to select the path you want to save your decks and downloaded images in. These can be where ever you want (personally I put them right into my dropbox). The third entry needs to point to the card information you just downloaded though. If you installed with my Debian package this file should be located in /opt/cockatrice/oracle/cards.xml:


Once you set these three paths simply hit close and you should be greeted by the main Cockatrice window. Before you can play you will need to make a deck. The deck editor is select-able from the main menu:


Finally once you have a deck saved you can connect to the main cockatrice server and play a few games:



Have any issues feel free to drop a comment below and I'll do my best to help you out. If you see me online feel free to ask for a game - my user name is the very non-creative "JeffHoogland"

Have fun!
~Jeff Hoogland

40 comments:

  1. Thanks for the info. Will have to try this one out.

    I once invested in a few cases of Fallen Empire (shudder). I think there's one still buried somewhere waiting for its sell value to exceed the paper recycling value. I look at the MTG eBay prices with suspicion. I can't imagine why a Black Lotus would be worth more than its weight in gold. Lots of cards for $0.01 USD and they're not land.

    ReplyDelete
  2. This is really cool...bodhi is impressive..

    http://www.youtube.com/watch?v=LO9JTB9EWJc&feature=related

    ReplyDelete
  3. unfortunately, I can't get it to work. I'm trying to run it on Ubuntu 11.10 Oneiric Ocelot. I get as far as installing from the .deb file and downloading the cards, but when trying to run the actual game, nothing happens. When I tried starting it in the terminal I got the following error message:
    "/opt/cockatrice/cockatrice/cockatrice: error while loading shared libraries: libQtMultimediaKit.so.1: wrong ELF class: ELFCLASS64"
    anybody know how to fix this?

    ReplyDelete
  4. What does

    dpkg -l libqtmultimediakit1

    Yield in terminal?

    ReplyDelete
  5. That yields:

    Desired=Unknown/Install/Remove/Purge/Hold
    | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
    |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
    ||/ Name Version Description
    +++-==============-==============-============================================
    ii libqtmultimedi 1.1.0-0ubuntu4 Qt Mobility MultimediaKit module

    ReplyDelete
  6. Ahh - Looks like that package I built will only work on Bodhi and Debian Wheezy. They both use a newer version of that binary (and others) than Ubuntu 11.10 does.

    You should be able to compile from source without issues though.

    ReplyDelete
  7. Hello!
    I'm on ubuntu 10.04, and I installed QT SDK (wich includes mobility) from the QT website. And the cockatrice.deb still asks for qtmobility-dev as a missing dependency... I am probably doing something wrong but I cannot figure what...

    ReplyDelete
  8. On Ubuntu 10.04 you will need to compile cockatrice from source yourself. That .deb appears to only work on Bodhi and Debian.

    ReplyDelete
  9. I tried from source but the "qmake && make" command sends back tons of errors... ex
    ":84: error: ‘event’ was not declared in this scope
    make: *** [build/abstractcounter.o] Erreur 1"

    ReplyDelete
  10. Pastebin the full error if you can.

    ReplyDelete
  11. This is all the errors I can get (I can't even see my command... and it doesn't fit in your comment box ^^):
    src/abstractcounter.cpp:74: error: invalid use of incomplete type ‘struct QAction’
    src/abstractcounter.h:8: error: forward declaration of ‘struct QAction’
    src/abstractcounter.cpp: In member function ‘void AbstractCounter::setValue(int)’:
    src/abstractcounter.cpp:81: error: ‘update’ was not declared in this scope
    src/abstractcounter.cpp: At global scope:
    src/abstractcounter.cpp:84: error: variable or field ‘mousePressEvent’ declared void
    src/abstractcounter.cpp:84: error: ‘QGraphicsSceneMouseEvent’ was not declared in this scope
    src/abstractcounter.cpp:84: error: ‘event’ was not declared in this scope
    make: *** [build/abstractcounter.o] Erreur 1

    ReplyDelete
  12. Did all the previous commands complete without errors? Also "pastebin it" means use pastebin.com - not pasting it into a comment box here :)

    ReplyDelete
  13. Okay =) here it is. I can't even see my command line anymore: http://pastebin.com/vRjYZtk8
    The previous commands went fine... thx for your time =)

    ReplyDelete
  14. My last advances, it seems that there is a version pb, my libqt4 is 4:4.6 and I need to have 4:4.7 to get qtmobility-dev (which I thought was in the qt sdk anyway...). But I can't find it from the repositories and the .deb bugs because it seems to break some dependencies...

    ReplyDelete
  15. Sounds about right. You need to QTMobility packages properly installed. I suggest backing the ones provided form Ubuntu unstable to your current release of Ubuntu. This is what I did to make the Bodhi .deb work.

    ReplyDelete
  16. JeffHoogland said...
    "I suggest backing the ones provided form Ubuntu unstable to your current release of Ubuntu. This is what I did to make the Bodhi .deb work."

    Can you explain how to do that please?

    ReplyDelete
  17. Whoops, I meant to say "Debian Unstable" but its about the same really. You need to grab the sources from here and compile/install them on your Ubuntu system.

    ReplyDelete
  18. Hi Jeff Hoogland.. I've just started using Ubuntu 11.10 and planned on getting Cockatrice functional for it, to start training for the next GP in my area.
    Here is the pastebin link for where it went wrong.

    http://pastebin.com/xtjcAUsx

    Thanks beforehand,
    Michael

    ReplyDelete
  19. Mikael - Looks like you didn't install all the build dependencies you need. Like I mentioned above, these package names will vary based on the distribution you have (Ubuntu has changed some of them around in recent updates) but I believe "build-essential" is still one you need. Also try getting "libqt4-dev" as well as whatever Ubuntu is calling their qtmobility dev package (search in synaptic).

    Good luck!

    ReplyDelete
  20. hi folks,

    Anybody install a cockatrice in a ubuntu 11.10?

    When try compile the program, i've this error:

    g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_NO_DEBUG -DQT_SCRIPT_LIB -DQT_SVG_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtSvg -I/usr/include/qt4/QtScript -I/usr/include/qt4 -I. -Isrc -I../common -Ibuild -o build/soundengine.o src/soundengine.cpp
    src/soundengine.cpp:4:24: fatal error: QAudioFormat: El fitxer o directori no existeix
    compilation terminated.
    make: *** [build/soundengine.o] Error 1

    What's a QAudioFormat? I install Qt4 and QTMobility.

    Thank a lot!

    ReplyDelete
  21. hi Jeff,

    I install the libraries libpulse-dev and persist the same error.

    ReplyDelete
    Replies
    1. Not sure then, give the cockatrice forums a go - the software creator visits there.

      Delete
  22. Hi Jeff

    the compilation is giving me this error:

    g++ -c -pipe -g -Wall -W -O2 -D_REENTRANT -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -DQT_SHARED -DQT_TABLET_SUPPORT -I/usr/share/qt3/mkspecs/default -I. -I. -Isrc -I../cockatrice/src -I/usr/include/qt3 -Ibuild/ -o build/main.o src/main.cpp
    src/main.cpp:1:24: error fatal: QApplication: No such file or directory
    compilation terminated.
    make: *** [build/main.o] Error 1

    could you help me with that?

    ReplyDelete
    Replies
    1. Looks like you are missing QT development headers. Make sure they are installed via your distribution's package manager.

      Delete
  23. If anyone chances by this thread that has successfully compiled Cockatrice for Ubuntu, could they please email me at: benettfreeman@gmail.com ?

    Having to play in a VM because no one has made a proper package suuuuuuuucks!

    ReplyDelete
  24. Hi,
    Thanks for sharing this informative post i enjoyed Magic The Gathering a lot.

    Regards

    ReplyDelete
  25. Hey, another option for those using Ubuntu 10.04 and *lower* (will not work for Ubuntu 10.10 and higher as far as I'm aware) is to add the Bodhi repository to the Ubuntu Software Centre:
    Edit -> Software Sources -> Other Sources -> Add.. "deb http://packages.bodhilinux.com/bodhi lucid main"
    Then, depending on your security settings you can either install directly from the Software Centre or open a console and run "sudo apt-get install cockatrice"
    Enjoy!

    ReplyDelete
  26. Hello again, just to inform you the version of Cockatrice in the Bodhi repository is now outdated and will not allow connection to the main server.

    ReplyDelete
    Replies
    1. Thanks for the heads up - I'll get an updated build into the repo by the end of the week at the latest.

      Delete
  27. Hi Jeff.
    I have the following problem: Qt library not found QTMULTIMEDIA.
    as I fix this?
    thanks

    ReplyDelete
    Replies
    1. Install the development headers for QTMobility that your distribution provides.

      Delete
  28. I can't find the .xml file, installing from Source. any ideas where it shoved the files that oracle downloaded?

    ReplyDelete
    Replies
    1. I'd suggest asking on the cockatrice user boards - its been awhile since I've built this from source.

      Delete
  29. Hi, i can't seem to download the sets information from given URL, know where i could find that ?

    ReplyDelete
    Replies
    1. You can find the latest Cockatrice related things here now -> woogerworks.com

      Delete
  30. Amazing... thank you so much for this. I can practice Modern on my low-end notebook running #! Linux..
    cheers ! <3

    ReplyDelete
  31. Hello, greetings from Argentina. Im using ubuntu 13.10 is this package still working and is it updated to the last expansion (Theros)? Im thinking about installing with ur package and stop using wine to play on cockatrice.

    ReplyDelete
    Replies
    1. I've never tested the .DEB package on anything other than Bodhi Linux (built on Ubuntu 12.04) so YMV on something else.

      That being said - this package has the Wooger works patches, so downloading all sets through BotG will work.

      Delete
    2. Thanks you very very much Jeff is working perfectly in my Ubuntu 13.10 np problem at all... U are a genius man!!!!

      Delete