1 API Reference
Viktor edited this page 2022-07-09 01:27:55 +04:00

API Reference

Mafia Online API

MafiaOnlineAPI.ChatMessage

Message in chat

Kind: static class of mafiaonline

ChatMessage.ChatMessage#isHistory() ⇒ boolean

Check if message is historic (sent before joining)

Kind: static method of ChatMessage
Returns: boolean -

True if message is historic


ChatMessage.ChatMessage#getSender() ⇒ User

Get sender of message, User class instance

Kind: static method of ChatMessage
Returns: User -

Sender of message


ChatMessage.ChatMessage#getText() ⇒ string

Get text content of message

Kind: static method of ChatMessage
Returns: string -

Clear text of message


ChatMessage.ChatMessage#getSentTimestamp() ⇒ number

Get timestamp of message send in unix timestamp format (seconds since epoch)

Kind: static method of ChatMessage
Returns: number -

Time when message was sent


ChatMessage.ChatMessage#getType() ⇒ string

Returns type of message, one of 'clear_text', 'join', 'left', 'game_started', 'mafia_in_chat', 'mafia_choosing_victim', 'civilian_in_chat', 'civilian_voting', 'civilian_vote', 'clear_text', '[unknown]', 'player_killed', 'civilian_vote', 'no_one_killed', 'civilians_won', 'mafia_won', 'dead_player_last_message'

Kind: static method of ChatMessage
Returns: string -

Type of message in chat


MafiaOnlineAPI.PlayerMiniProfile

Player's mini profile. Used in room.getPlayers()

Kind: static class of mafiaonline

PlayerMiniProfile.PlayerMiniProfile#getID() ⇒ number

Get in-game ID of user

Kind: static method of PlayerMiniProfile
Returns: number -

User ID


PlayerMiniProfile.PlayerMiniProfile#getName() ⇒ string

Get user nickname

Kind: static method of PlayerMiniProfile
Returns: string -

User nickname


PlayerMiniProfile.PlayerMiniProfile#isAlive() ⇒ boolean

Returns true if player is alive in the game

Kind: static method of PlayerMiniProfile
Returns: boolean -

Is player alive


PlayerMiniProfile.PlayerMiniProfile#isMale() ⇒ boolean

Check if user sex is male

Kind: static method of PlayerMiniProfile
Returns: boolean -

True if user is male, false otherwise


PlayerMiniProfile.PlayerMiniProfile#isFemale() ⇒ boolean

Check if user sex is female

Kind: static method of PlayerMiniProfile
Returns: boolean -

True if user is female, false otherwise


PlayerMiniProfile.PlayerMiniProfile#getSex() ⇒ number

Get user sex

Kind: static method of PlayerMiniProfile
Returns: number -

0 if user is male, 0 if user is female


MafiaOnlineAPI.MafiaRoom

Room of Mafia Online

Kind: static class of mafiaonline

MafiaRoom.MafiaRoom#getID() ⇒ string

Get ID of room

Kind: static method of MafiaRoom
Returns: string -

ID of room


MafiaRoom.MafiaRoom#getName() ⇒ string

Get room name

Kind: static method of MafiaRoom
Returns: string -

Name of room


MafiaRoom.MafiaRoom#getMinimumLevel() ⇒ number

Get minimum level required to join the room

Kind: static method of MafiaRoom
Returns: number -

Minimum level for room


MafiaRoom.MafiaRoom#isPasswordProtected() ⇒ boolean

Returns true is room is password protected

Kind: static method of MafiaRoom

MafiaRoom.MafiaRoom#join()

Enters the room

Kind: static method of MafiaRoom

MafiaRoom.MafiaRoom#leave()

Leaves the room

Kind: static method of MafiaRoom

MafiaOnlineAPI.MafiaUser

User of Mafia Online

Kind: static class of mafiaonline

MafiaUser.MafiaUser#getID() ⇒ number

Get in-game ID of user

Kind: static method of MafiaUser
Returns: number -

User ID


MafiaUser.MafiaUser#getName() ⇒ string

Get user nickname

Kind: static method of MafiaUser
Returns: string -

User nickname


MafiaUser.MafiaUser#getExperience() ⇒ number

Get user experience

Kind: static method of MafiaUser
Returns: number -

User experience


MafiaUser.MafiaUser#getLastOnlineDate() ⇒ Date

Get user last date of online

Kind: static method of MafiaUser
Returns: Date -

Date of online


MafiaUser.MafiaUser#getLevel() ⇒ number

Get user level

Kind: static method of MafiaUser
Returns: number -

User level


MafiaUser.MafiaUser#getReputation() ⇒ number

Get user reputation

Kind: static method of MafiaUser
Returns: number -

User reputation


MafiaUser.MafiaUser#getPlayedGames() ⇒ object

Get information about played games

Kind: static method of MafiaUser
Returns: object -

Object with stats


MafiaUser.MafiaUser#getLocale() ⇒ string

Get language of user

Kind: static method of MafiaUser
Returns: string -

User locale


MafiaUser.MafiaUser#isMale() ⇒ boolean

Check if user sex is male

Kind: static method of MafiaUser
Returns: boolean -

True if user is male, false otherwise


MafiaUser.MafiaUser#isFemale() ⇒ boolean

Check if user sex is female

Kind: static method of MafiaUser
Returns: boolean -

True if user is female, false otherwise


MafiaUser.MafiaUser#getSex() ⇒ number

Get user sex

Kind: static method of MafiaUser
Returns: number -

0 if user is male, 0 if user is female


MafiaOnlineAPI.MafiaOnlineAPIAccount#getUser() ⇒ Promise.<MafiaUser>

Get authorized User

Kind: static method of mafiaonline
Returns: Promise.<MafiaUser> -

Instance of User class


MafiaOnlineAPI.MafiaOnlineAPIAccount#setNickname(nickname) ⇒ Promise.<boolean>

Set nickname of authorized user

Kind: static method of mafiaonline
Returns: Promise.<boolean> -

True if nickname set successfully

Param Type Description
nickname string

New nickname of user

MafiaOnlineAPI.MafiaOnlineAPIAccount#setLocale(locale) ⇒ object

Set server language. Mustn't change frequently (once in 6 hours)

Kind: static method of mafiaonline
Returns: object -

Response from server

Param Type Description
locale string

One of 'ru', 'en'

MafiaOnlineAPI.MafiaOnlineAPIAuth#signOut() ⇒ Promise.<object>

Sign out from account and delete session

Kind: static method of mafiaonline
Returns: Promise.<object> -

Response from REST API


See: REST API

MafiaOnlineAPI.MafiaOnlineAPIAuth#verifyEmail() ⇒ Promise.<object>

Send verification email

Kind: static method of mafiaonline
Returns: Promise.<object> -

Response from REST API


See: REST API

MafiaOnlineAPI.MafiaOnlineAPIBase#close() ⇒ Promise

Closes current socket and cleans up all stuff. Does not delete session, use signOut() before close()!

Kind: static method of mafiaonline

MafiaOnlineAPI.MafiaOnlineAPIChat#joinGlobalChat(callback) ⇒ function

Subscribe to global public chat

Kind: static method of mafiaonline
Returns: function -

Unsubscribe function

Param Type Description
callback function

Callback function, that gets called everytime a new message sent by someone in chat with message argument. It is strongly recommended that you check msg.isHistory() before interacting with it, because when you join chat, server sends you a lot of history messages (that were sent before you joined).

MafiaOnlineAPI.MafiaOnlineAPIChat#sendToGlobalChat(content, messageStyle)

Send message to global chat. Must join global chat first using joinGlobalChat(). Must verify email in order to be able to send more than one message.

Kind: static method of mafiaonline

Param Type Default Description
content string

Text content of message

messageStyle number 0

Style of message (VIP-only)

MafiaOnlineAPI.MafiaOnlineAPIChat#_manageChat(events) ⇒ function

Chat manager that handles new messages

Kind: static method of mafiaonline
Returns: function -

Unsubscribe function

Param Type Description
events object

Events object as first arg

events.onMessage function

Callback with message class as argument

events.onUserListUpdate function

Callback with array of users

events.onLeave function

Called on unsubscribing. Must be as simple, as possible

MafiaOnlineAPI.MafiaOnlineAPIRooms#startRoomMonitoring(callback) ⇒ function

Get rooms list and subscribe for changes

Kind: static method of mafiaonline
Returns: function -

Function to unsubscribe

Param Description
callback

Callback that gets called with argument of type Room

MafiaOnlineAPI.MafiaOnlineAPIRooms#joinRoom(room, [password])

Join room. You can also call join() method directly on Room instance

Kind: static method of mafiaonline

Param Type Description
room Room

Room instance. Must be obtained from monitoring by calling startRoomMonitoring() function

[password] string

Optional. Password in clear text, hashing is done on library side

MafiaOnlineAPI.MafiaOnlineAPIRooms#leaveRoom(room)

Leave room. You can also call leave() method directly on Room instance

Kind: static method of mafiaonline

Param Type Description
room Room

Room instance. Must be obtained from monitoring by calling startRoomMonitoring() function

REST API

This method uses HTTP REST API.