Skip to content

Instantly share code, notes, and snippets.

@stelcheck
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stelcheck/ad11d84595b838a7d0e0 to your computer and use it in GitHub Desktop.
Save stelcheck/ad11d84595b838a7d0e0 to your computer and use it in GitHub Desktop.
MAGE test
g++ -g -Wall -std=c++0x -DHTTP_CONNECTOR -I ./src -I ./vendor/libjson-rpc-cpp/src -L ./vendor/libjson-rpc-cpp/build/out -L ./build -ljsonrpc -lmage -ldl /usr/lib/libcurl.dylib examples/test.cpp -o examples/test
#include <mage.h>
#include <iostream>
using namespace mage;
using namespace std;
int main() {
mage::RPC client("game", "localhost:2000");
//
// MAGE works with JSON-RPC: so
// we create variables for the request's
// parameters as well as for the response
//
Json::Value auth;
Json::Value user;
//
// When logging in, you will need to submit:
//
// 1. An engine name, provided to you by the server-side developer
// 2. A username
// 3. A password
//
auth["engineName"] = "cmss";
auth["credentials"]["username"] = "username";
auth["credentials"]["password"] = "password";
//
// Login will return you a user and a session. We take the
// session and set it as our own.
//
// Note: It is possible that you need to call a different login
// method. If it is the case, you should still expect to receive
// the same data structure as with the standard ident module.
//
try {
user = client.Call("ident.login", auth);
} catch (mage::MageRPCError e) {
cerr << "Could not login, an RPC error has occurred: " << e.what() << " (code " << e.code() << ")" << endl;
// CRASH HERE EXC_BAD_ACCESS ********
return 1;
} catch (mage::MageErrorMessage e) {
cerr << "Login failed: " << e.code() << endl;
return 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment