Module: koc

koc

Source:

Methods

buyWeapons(turing, inputNameValue)

Buy weapons. Use getArmory() to find out the turing and inputNameValue.
Parameters:
Name Type Description
turing String The turing of the last armory page you visited
inputNameValue Object example: { "buy_weapon[62]": 1, "buy_weapon[25]: 14 }
Source:

changeRace(new_race) → {Object}

Change the race
Parameters:
Name Type Description
new_race String the race to change to
Source:
Returns:
A promise which will eventually succeed and parse the base
Type
Object

createRequestPromise(options, onSuccess) → {Object}

Given express options, create and return a request promise to KoC server
Parameters:
Name Type Description
options Object The options to send to request
onSuccess function Callback to call on success
Source:
Returns:
the HTTP request promise (use .then() and .fail() on it)
Type
Object

getChangeCommanderInfo() → {Object}

Get the number of times we can change the commander and the statement to copy (image)
Source:
Returns:
A promise which if succeed returns an object with 'success', 'nbTimesCanChange', 'errorMessage' and 'statement' properties
Type
Object

getKoCHost() → {String}

Get the base URL of KoC website
Source:
Returns:
KoC URL
Type
String

getKoCReCaptchaUrl() → {String}

Get the URL of the Javascript to get a new challenge for KoC
Source:
Returns:
captcha url
Type
String

getKoCSessionCookieName() → {String}

Get the name of the cookie that KoC uses to store the session id
Source:
Returns:
the cookie name
Type
String

getRacesInformation() → {Object}

Get the races information
Source:
Returns:
A promise to the races information
Type
Object

getReCaptchaChallenge() → {Object}

Get a new ReCaptcha challenge for KoC
Source:
Returns:
Promise of the HTTP request which should return an object containing "success" and "session" fields at least. Use .then() and .fail() to catch the promise result
Type
Object

getRecaptchaImage(server, challenge) → {String}

Get a link to a ReCaptcha image given the server and the challenge
Parameters:
Name Type Description
server String ReCaptcha Server
challenge String ReCaptcha challenge
Source:
Returns:
URL to the ReCaptcha image
Type
String

getReCaptchaImageFormat() → {String}

Get the format of the URL to get the recaptcha image from (server, challenge)
Source:
Returns:
URL format
Type
String

getRequestOptions(method, page, params, xhr) → {Object}

Get request options that we can pass to node request
Parameters:
Name Type Argument Description
method String HTTP method to use (GET, POST, HEAD)
page String KoC page to request (login.php, battlefield.php, etc...)
params Object <optional>
Parameters for GET and POST requests
xhr Boolean <optional>
Whether or not request through XHR (Ajax)
Source:
Returns:
the options to pass to node request
Type
Object

getSession() → {String}

Get current session id
Source:
Returns:
current session id
Type
String

getUserInfo() → {Object}

Get user info. You need to be logged in and have a session already.
Source:
Returns:
Return an object with 'success', 'error', 'session' and 'user'
Type
Object

hasSession() → {Boolean}

Returns true if there is a session (non empty), false otherwise
Source:
Returns:
whether or not there is a session set (non empty)
Type
Boolean

intelDetail(report_id) → {Object}

Retrieve the spy report for given report_id
Parameters:
Name Type Description
report_id
Source:
Returns:
Type
Object

intelFile(asset_id)

Retrieve the intelligence files for the given asset_id
Parameters:
Name Type Description
asset_id usually same as the user_id
Source:

login(username, password) → {Object}

Login to KoC
Parameters:
Name Type Description
username String
password String
Source:
Returns:
Promise of the HTTP request which should return an object containing "success" and "session" fields at least. Use .then() and .fail() to catch the promise result
Type
Object

prepareResponse()

Wrapper to prepare a response having all the fields. Especially adds the session and the last known location.
Source:

register(race, username, password, email, challenge, challenge_response) → {Object}

Register a new user to KoC
Parameters:
Name Type Description
race String Humans, Dwarves, Elves, Undead, Orcs
username String
password String
email String
challenge String
challenge_response String
Source:
Returns:
Promise of the HTTP request which should return an object containing "success" and "session" fields at least. Use .then() and .fail() to catch the promise result
Type
Object

requestPage(mustBeLoggedIn, method, page, params, onSuccess, xhr) → {Object}

Create a request to KoC website and return a node request promise
Parameters:
Name Type Argument Default Description
mustBeLoggedIn Boolean whether or not the user must be logged in to load that page
method String HTTP method to use (GET, POST, HEAD)
page String KoC page to request (login.php, battlefield.php, etc...)
params Object Parameters for GET and POST requests
onSuccess function Callback to call on success
xhr Boolean <optional>
false Whether or not request through XHR (Ajax)
Source:
Returns:
the HTTP request promise (use .then() and .fail() on it)
Type
Object

setKoCHost(new_koc_host)

Set the base URL of KoC website
Parameters:
Name Type Description
new_koc_host String
Source:

setKoCReCaptchaUrl(new_koc_recaptcha_url)

Set the URL of the Javascript to get a new challenge for KoC
Parameters:
Name Type Description
new_koc_recaptcha_url String
Source:

setKoCSessionCookieName(new_cookie_name)

Set the name of the cookie that KoC uses to store the session id
Parameters:
Name Type Description
new_cookie_name String
Source:

setReCaptchaImageFormat(new_recaptcha_image_format)

Set the format of the URL to get the recaptcha image from (server, challenge)
Parameters:
Name Type Description
new_recaptcha_image_format String
Source:

setSession(new_session)

Set the session id to passed new_session_id
Parameters:
Name Type Description
new_session String new session id to set
Source:

toggleAdvisor() → {Object}

Toggle the New User Advisor on the KoC Account
Source:
Returns:
A promise which will contain user stats if succeed
Type
Object

updateKocSession(headers)

Update the value of KoC session id, if requeted by KoC server
Parameters:
Name Type Description
headers Object The headers received from the server
Source:

verify(username, password, password2) → {Object}

Verify if the provided username and passwords are valid
Parameters:
Name Type Description
username String
password String
password2 String when asked to enter twice the password
Source:
Returns:
Promise of the HTTP request which should return an object containing "success" and "session" fields at least. Use .then() and .fail() to catch the promise result
Type
Object