Skip to content
Leonid Pospelov edited this page Aug 3, 2019 · 7 revisions

Constructor: Server(options)

Starts attempt to launch the remote SkyMP server.

let server = new Server({
  // The address and port of SkyMP master server
  masterAddress: '108.108.108.108',
  masterPort: 3000,
  
  // Unique ID for your server
  id: 'my_server',
  
  // Public name of the server, will appear in launcher
  name: 'My Server',
  
  // Player limit, will appear in launcher
  maxPlayers: 5,
  
  // Dev password for server with specified id
  // Prevents people from connecting their gamemodes to your server
  devPassword: 'changeme',
  
  // Relative path to directory containing frontend files (html, css, js, etc.)
  frontEndPath: './front',
});

Property: 'maxPlayers'

Limit of a number of users including bots.

let maxPlayers = await server.maxPlayers;

Event: 'init'

Emitted when the server succeeded or failed to start.

  • errorS - null or string containing details of the error.
server.on('init', (error) => {
  console.error('Init error:', error);
});

Event: 'scriptInit'

Emitted when your gamemode is connected to the server.

server.on('scriptInit', () => {
  console.log('Script init');
});

Event: 'userEnter'

Emitted when a new User has just joined the game (launched SkyMP with your server selected).

  • user - An instance of User.
server.on('userEnter', async user => {
  console.log('New User:', user.id);
});

Event: 'userExit'

Emitted when User leaves the game.

  • user - An instance of User.
server.on('userExit', async user => {
  console.log('Exited User:', user.id);
});

Event: 'userCustomPacket'

Emitted when User's browser sends a custom packet.

  • user - An instance of User.
  • targetSystem - A string from client. Should represent one of the systems in your gamemode.
  • data - An object from client containing "body" of the packet.
server.on('userCustomPacket', async (user, targetSystem, data) => {
  if (targetSystem === 'Auth') {
      // ...
  } else if (targetSystem === 'Barbershop') {
      // ...
  }
}

Event: 'raceMenuExit'

Emitted when character creation is finished.

  • actor - An instance of Actor.
server.on('raceMenuExit', async (actor) => {
    // ...
});

.kill()

Drops connections with server and master server. The server will be removed from the server list in a few seconds.

server.kill();

.createBot()

Creates bot i.e. a dummy user. Bots disconnect when gamemode is disconnected.

let bot = await server.createBot();