Skip to main content

Models Reference

Complete reference for all data models, interfaces, and types used throughout the Moitribe SDK.

Player Models

Player

Represents a game player with basic information.

interface Player {
/** Player's unique ID */
playerID: string;
/** Player's display name */
playerName: string;
/** URL to player's icon image */
iconImageURL: string;
/** Last active timestamp (10 digit version) */
lastPlayerTimestamp: number;
/** Player's title/rank */
title: string;
}

Example:

const player = {
playerID: 'player_12345',
playerName: 'AlexGamer',
iconImageURL: 'https://cdn.moitribe.com/icons/player_12345.png',
lastPlayerTimestamp: 1703123456,
title: 'Pro Player'
};

SignedInProfile

Extended profile information for authenticated players.

interface SignedInProfile {
/** Player's unique ID */
id: string;
/** Landscape banner image URL */
bannerimgland: string;
/** Portrait banner image URL */
bannerimgport: string;
/** Player's display name */
name: string;
/** Player's title/rank */
title: string;
/** Profile icon URL */
profileicon: string;
/** High-resolution profile image URL */
profilehiresimg: string;
/** Player's level */
level: string;
/** Array of friend IDs */
friends: string[];
}

Example:

const profile = {
id: 'player_12345',
bannerimgland: 'https://cdn.moitribe.com/banners/land_12345.jpg',
bannerimgport: 'https://cdn.moitribe.com/banners/port_12345.jpg',
name: 'AlexGamer',
title: 'Champion',
profileicon: 'https://cdn.moitribe.com/icons/player_12345.png',
profilehiresimg: 'https://cdn.moitribe.com/hires/player_12345.jpg',
level: '42',
friends: ['player_67890', 'player_11111']
};

Real-Time Multiplayer Models

Room

Represents a real-time multiplayer room.

interface Room {
/** Room's unique ID */
roomID: string;
/** Room's server-side ID */
roomScID?: string;
/** Creator's player ID */
creatorID: string;
/** Room creation timestamp (10 digits) */
creationTimestamp: number;
/** Room status */
status: RoomStatus;
/** Room description */
getDescription: string;
/** Auto-match wait time in seconds */
autoMatchWaitSeconds: number;
/** Room variant (defined by developer) */
variant: number;
/** Minimum automatch players (RTM Standard) */
min_automatch_players?: number;
/** Maximum players (RTM Endless) */
max_players?: number;
/** Maximum automatch players */
max_automatch_players?: number;
/** Exclusive bitmask (8-bits for roles in game) */
exclusive_bitmask: string;
/** Array of participant IDs */
getParticipantsIDs: string[];
/** Array of Participant objects */
participants: Participant[];
/** Is this an auto-match room */
isAutoMatch: boolean;
/** Server info */
server?: any;
/** Connection retry wait time in seconds */
waitTime?: number;
}

RoomStatus

Enum for room connection states.

enum RoomStatus {
AUTO_MATCHING = 1, // Room is auto-matching players
CONNECTING = 2, // Connecting to room
ACTIVE = 3 // Room is active and ready
}

Example:

const room = {
roomID: 'room_abc123',
roomScID: 'sc_xyz789',
creatorID: 'player_12345',
creationTimestamp: 1703123456,
status: RoomStatus.ACTIVE,
getDescription: 'Speed Race Room',
autoMatchWaitSeconds: 30,
variant: 1,
min_automatch_players: 2,
max_automatch_players: 4,
exclusive_bitmask: '15',
getParticipantsIDs: ['part_111', 'part_222'],
participants: [participant1, participant2],
isAutoMatch: true,
waitTime: 5
};

Participant

Represents a player in a room.

interface Participant {
/** Participant's ID (room-specific) */
participantID: string;
/** Player's unique ID */
playerID: string;
/** Player's display name */
name: string;
/** URL to player's icon image */
iconImageURL: string;
/** Participant status */
status: ParticipantStatus;
/** Is the participant connected */
isConnected: boolean;
}

ParticipantStatus

Enum for participant states in a room.

enum ParticipantStatus {
NOT_INVITED_YET = 0, // Participant not yet invited
INVITED = 1, // Participant invited
JOINED = 2, // Participant joined
DECLINED = 3, // Participant declined invitation
LEFT = 4, // Participant left room
FINISHED = 5, // Participant finished game
UNRESPONSIVE = 6 // Participant unresponsive
}

Example:

const participant = {
participantID: 'part_111',
playerID: 'player_12345',
name: 'AlexGamer',
iconImageURL: 'https://cdn.moitribe.com/icons/player_12345.png',
status: ParticipantStatus.JOINED,
isConnected: true
};

RealTimeMessage

Represents a message received in real-time multiplayer.

interface RealTimeMessage {
/** Message data as ArrayBuffer */
messageData: ArrayBuffer;
/** Sender's participant ID */
senderParticipantID: string;
/** Whether the message was sent reliably */
isReliable: boolean;
}

Example:

// Handling received message
function onMessageReceived(messageData, senderParticipantID, isReliable) {
const message = {
messageData: messageData,
senderParticipantID: senderParticipantID,
isReliable: isReliable
};

// Process the message
const view = new DataView(message.messageData);
const messageType = view.getUint8(0);
console.log(`Received ${message.isReliable ? 'reliable' : 'unreliable'} message from ${message.senderParticipantID}`);
}

Leaderboard Models

LeaderboardMeta

Metadata for a leaderboard configuration.

interface LeaderboardMeta {
/** ID of the leaderboard */
leaderboardID: string;
/** Name given on the dashboard */
leaderboardName: string;
/** URL of the leaderboard icon */
leaderboardIconURL: string;
/** Score order: 1 for larger is better, -1 for smaller is better */
leaderboardScoreOrder: number;
/** Leaderboard collection type (Social/All) */
leaderboardCollection: {
Social: number;
All: number;
};
collectionValue?: number;
timeSpanValue?: number;
}

LeaderboardScoreData

Represents a player's score entry on a leaderboard.

interface LeaderboardScoreData {
/** Player's rank on the leaderboard */
playerRank: number;
/** Player's score */
playerScore: number;
/** Player's name */
playerName: string;
/** Timestamp (10 digit version) */
timestamp: number;
/** Player object */
player: Player;
/** URL of the player icon */
iconURL: string;
/** High-resolution URL of the player icon */
hiresURL: string;
/** ID of the leaderboard */
leaderboardID: string;
/** Score tag/metadata */
scoreTag: string;
}

Example:

const leaderboardMeta = {
leaderboardID: 'high_scores',
leaderboardName: 'High Scores',
leaderboardIconURL: 'https://cdn.moitribe.com/icons/high_scores.png',
leaderboardScoreOrder: 1, // Higher scores are better
leaderboardCollection: {
Social: 0,
All: 1
},
collectionValue: 1, // All players
timeSpanValue: 0 // All-time
};

const scoreData = {
playerRank: 5,
playerScore: 15000,
playerName: 'AlexGamer',
timestamp: 1703123456,
player: player,
iconURL: 'https://cdn.moitribe.com/icons/player_12345.png',
hiresURL: 'https://cdn.moitribe.com/hires/player_12345.jpg',
leaderboardID: 'high_scores',
scoreTag: 'level-10-completed'
};

RTM Parameter Models

RTMStandardParams

Parameters for creating/joining standard RTM rooms.

interface RTMStandardParams {
/** Retry timeout in case of connection lost (seconds) */
retryTime?: number;
/** Invitation ID (when joining via invitation) */
invitationID?: string;
/** Variant of the room type */
variant?: number;
/** Array of invited player IDs */
invitedPlayerIDs?: string[];
/** Minimum number of automatch players required */
min_automatch_players?: number;
/** Maximum number of automatch players required */
max_automatch_players?: number;
/** One byte/8-bits for roles in game */
exclusive_bitmask?: string;

// Reconnect callbacks
reconnectSuccessful?: () => void;
attemptingReconnect?: () => void;

// Room connection callbacks
onRoomCreated?: (status: boolean, room: Room) => void;
onJoinedRoom?: (status: boolean, room: Room) => void;
onLeftRoom?: (status: boolean, roomID: string) => void;
onRoomConnected?: (status: boolean, room: Room) => void;

// Message callbacks
onMessageReceived?: (messageData: ArrayBuffer, senderParticipantID: string, isReliable: boolean) => void;

// Room update callbacks
onPeerJoined?: (room: Room, participantList: string[]) => void;
onPeerLeft?: (room: Room, participantList: string[]) => void;
onConnectedToRoom?: (room: Room) => void;
onDisconnectedFromRoom?: (room: Room) => void;
onPeerConnected?: (room: Room, participantList: string[]) => void;
onPeerDisconnected?: (room: Room, participantList: string[]) => void;
}

RTMEndlessParams

Parameters for creating/joining endless RTM rooms.

interface RTMEndlessParams {
/** Retry timeout in case of connection lost (seconds) */
retryTime?: number;
/** Invitation ID (when joining via invitation) */
invitationID?: string;
/** Variant of the room type */
variant?: number;
/** Array of invited player IDs */
invitedPlayerIDs?: string[];
/** Maximum players allowed in the room */
max_players?: number;
/** Maximum number of automatch players required */
max_automatch_players?: number;
/** One byte/8-bits for roles in game */
exclusive_bitmask?: string;

// Reconnect callbacks
reconnectSuccessful?: () => void;
attemptingReconnect?: () => void;

// Room connection callbacks
onRoomCreated?: (status: boolean, room: Room) => void;
onJoinedRoom?: (status: boolean, room: Room) => void;
onLeftRoom?: (status: boolean, roomID: string) => void;

// Message callbacks
onMessageReceived?: (messageData: ArrayBuffer, senderParticipantID: string, isReliable: boolean) => void;

// Room update callbacks
onPeerJoined?: (room: Room, participantList: string[]) => void;
onPeerLeft?: (room: Room, participantList: string[]) => void;
onConnectedToRoom?: (room: Room) => void;
onDisconnectedFromRoom?: (room: Room) => void;
onPeerConnected?: (room: Room, participantList: string[]) => void;
onPeerDisconnected?: (room: Room, participantList: string[]) => void;
}

Usage Examples

Creating Room Parameters

// Standard room parameters
const standardParams = {
variant: 1,
min_automatch_players: 2,
max_automatch_players: 4,
exclusive_bitmask: '15', // All roles available
retryTime: 10,

onRoomCreated: (status, room) => {
if (status) {
console.log('Standard room created:', room.roomID);
}
},

onMessageReceived: (messageData, senderParticipantID, isReliable) => {
console.log(`Message received from ${senderParticipantID}`);
}
};

// Endless room parameters
const endlessParams = {
variant: 1,
max_players: 20,
max_automatch_players: 10,
exclusive_bitmask: '3', // Only first 2 roles available

onPeerJoined: (room, participantList) => {
console.log('New participants:', participantList);
}
};

Processing Leaderboard Data

function processLeaderboardResponse(response) {
const metadata = response.leaderboardMeta;
const scores = response.scores;

console.log(`Leaderboard: ${metadata.leaderboardName}`);
console.log(`Score order: ${metadata.leaderboardScoreOrder === 1 ? 'High to Low' : 'Low to High'}`);

scores.forEach(scoreData => {
console.log(`${scoreData.playerRank}. ${scoreData.playerName}: ${scoreData.playerScore}`);
console.log(` Tag: ${scoreData.scoreTag}`);
console.log(` Time: ${new Date(scoreData.timestamp * 1000)}`);
});
}

Working with Room Participants

function getConnectedParticipants(room) {
return room.participants.filter(participant =>
participant.status === ParticipantStatus.JOINED &&
participant.isConnected
);
}

function getParticipantByName(room, name) {
return room.participants.find(participant =>
participant.name === name
);
}

// Usage
const connectedPlayers = getConnectedParticipants(room);
console.log(`Connected players: ${connectedPlayers.length}`);

const alex = getParticipantByName(room, 'AlexGamer');
if (alex) {
console.log(`Alex's participant ID: ${alex.participantID}`);
}

Message Data Handling

// Create game message
function createGameMessage(type, data) {
const buffer = new ArrayBuffer(5); // 1 byte type + 4 bytes data
const view = new DataView(buffer);

view.setUint8(0, type); // Message type
view.setUint32(1, data, true); // Data (little endian)

return buffer;
}

// Parse received message
function parseGameMessage(messageData) {
const view = new DataView(messageData);
const type = view.getUint8(0);
const data = view.getUint32(1, true);

return { type, data };
}

// Usage
const message = createGameMessage(1, 1000);
// Send via standardmessagetoall or endlessmessagetoall

// In onMessageReceived callback
const parsed = parseGameMessage(messageData);
console.log(`Received message type ${parsed.type} with data ${parsed.data}`);
tip

Use TypeScript interfaces for better type safety and IDE autocomplete when working with these models.

Next Steps