Module: koc

koc

Source:

Methods

attack(userid, turing) → {Q.Promise}

Attack the given user and return the attack detail in case of success
Parameters:
Name Type Argument Description
userid number userid of the defender
turing string <optional>
turing of this page (optional)
Source:
Returns:
Type
Q.Promise

attackfield() → {Q.Promise}

Retrieve the page of the battlefield we are listed on
Source:
Returns:
Type
Q.Promise

attackLog(b_start, o_start) → {Q.Promise}

Retrieve the attack log
Parameters:
Name Type Description
b_start number page (by you)
o_start number page (on you)
Source:
Returns:
Type
Q.Promise

attackOrRaid(attack_type, userid, turing) → {Q.Promise}

Attack or Raid the given user with the given turing (optional)
Parameters:
Name Type Argument Description
attack_type String
userid Number
turing String <optional>
Source:
Returns:
Type
Q.Promise

battlefield(page) → {Q.Promise}

Retrieve the given battlefield page
Parameters:
Name Type Description
page number
Source:
Returns:
Type
Q.Promise

battleReport(attack_id) → {Q.Promise}

Retrieve the battle report
Parameters:
Name Type Description
attack_id number
Source:
Returns:
Type
Q.Promise

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) → {Q.Promise}

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
Q.Promise

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

index() → {Q.Promise}

Retrieve the index
Source:
Returns:
Type
Q.Promise

intelDetail(report_id) → {Q.Promise}

Retrieve the spy report for given report_id
Parameters:
Name Type Description
report_id number
Source:
Returns:
Type
Q.Promise

intelFile(asset_id) → {Q.Promise}

Retrieve the intelligence files for the given asset_id
Parameters:
Name Type Description
asset_id number usually same as the user_id
Source:
Returns:
Type
Q.Promise

intelligence(files_start, intercepted_start) → {Q.Promise}

Retrieve the intelligence log
Parameters:
Name Type Description
files_start number page (b_start : by you)
intercepted_start number page (o_start : on you)
Source:
Returns:
Type
Q.Promise

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. Nest the result under "result", keeping top-level error/success
Source:

raid(userid, turing) → {Q.Promise}

Raid the given user and return the attack detail in case of success
Parameters:
Name Type Argument Description
userid number userid of the defender
turing string <optional>
turing of this page (optional)
Source:
Returns:
Type
Q.Promise

recon(userid, turing) → {Q.Promise}

Spy the given user and return the intel detail in case of success
Parameters:
Name Type Argument Description
userid number userid of the defender
turing string <optional>
turing of this page
Source:
Returns:
Type
Q.Promise

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) → {Q.Promise}

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
Q.Promise

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