# @social-colyseus/server

> Social Colyseus - A Library of social actions & user persistence library for Colyseus

Latest version **0.4.3** (published 2021-09-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install @social-colyseus/server
pnpm add @social-colyseus/server
yarn add @social-colyseus/server
bun add @social-colyseus/server
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.3 |
| Published | 2021-09-09 |
| First published | 2021-08-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=14.17.5 |
| Dependencies | 11 |
| Unpacked size | 172.4 KB |
| Known vulnerabilities | 0 (+11 in 3 direct dependencies) |
| Install scripts | no |
| Author | Orkun ÇAKILKAYA |
| Maintainers | orkun |

## Links

- npm: https://www.npmjs.com/package/@social-colyseus/server
- npm.io page: https://npm.io/package/@social-colyseus/server

## Dependencies (11)

- [cors](https://npm.io/package/cors.md) ^2.8.5
- [http](https://npm.io/package/http.md) ^0.0.1-security
- [bcrypt](https://npm.io/package/bcrypt.md) ^5.0.1
- [events](https://npm.io/package/events.md) ^3.3.0
- [express](https://npm.io/package/express.md) ^4.16.4
- [colyseus](https://npm.io/package/colyseus.md) ^0.14.0
- [mongoose](https://npm.io/package/mongoose.md) ^5.13.7
- [body-parser](https://npm.io/package/body-parser.md) ^1.19.0
- [express-jwt](https://npm.io/package/express-jwt.md) ^6.1.0
- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^8.5.1
- [express-validator](https://npm.io/package/express-validator.md) ^6.12.1

## Recent versions

- 0.4.3 (latest) — 2021-09-09
- 0.4.2 — 2021-09-06
- 0.4.1 — 2021-09-06
- 0.3.1 — 2021-09-06
- 0.3.0 — 2021-09-06
- 0.2.1 — 2021-09-06
- 0.0.2 — 2021-08-25
- 0.0.1 — 2021-08-25

## README

# SocialColyseus - Server

SocialColyseus - Server is an extension for Colyseus. This package adds Authentication, Friendship, Invitation System
and more features to Colyseus servers. SocialColyseus uses MongoDB for database. It also provides Rest API.

## How to use?

### Env File

First copy .env.template to .env file and fill the necessary fields.

```typescript
import * as dotenv from 'dotenv';

dotenv.config();
```

### Initialize Express

```typescript
import express from 'express';
import cors from 'cors';

const app = express();
app.use(express.json());
app.use(cors());
```

### Create Game Server

```typescript
import {createServer} from 'http';
import {Server} from 'colyseus';
import {WebSocketTransport} from '@colyseus/ws-transport';

const server = createServer(app);

const gameServer = new Server({
    transport: new WebSocketTransport({
        server,
    }),
});
```

### Import SocialColyseus App

```typescript
import {SocialColyseusApp} from '../index';

const socialApp = new SocialColyseusApp(gameServer, {
    database: {
        host: process.env.DB_HOST,
        name: process.env.DB_NAME,
        pass: process.env.DB_PASS,
        port: process.env.DB_PORT,
        user: process.env.DB_USER,
    },
});
app.use(socialApp.httpHandler());
```

### Define your room via SocialColyseus

Otherwise authentication and other features won't work

```typescript
socialApp.defineRoom('privateRoom', PrivateRoom);
```

### SocialColyseus Rooms

Now add SocialColyseus App to your rooms for authentication and other features

```typescript
export class PrivateRoom extends Room {
    protected app: SocialColyseusApp;

    onCreate(options: any): void | Promise<any> {
        if (!options.app) {
            return Promise.reject();
        }
        this.app = options.app; // Initializes SocialColyseus to your room
        this.setPrivate(true).finally();
    }

    onAuth(client: Client, options: any): any {
        return authenticate(this.app, {token: options?.token}); // Authenticates your user via token
    }
}
```

### Run your server

```typescript
gameServer.listen(5567, '0.0.0.0').finally();
```

## Example Repository

### [Click here for example repository](https://github.com/social-colyseus/server-example)

## Roadmap

- [ ] Room Invitation
  - [X] Create invitation
  - [X] Accept invitation
  - [X] Reject invitation
  - [ ] Only host invites
  - [ ] No re-invite friends
  - [ ] Remove player from invitation list if user is in target room
- [ ] Leaderboard
- [ ] Clans
- [ ] Parties

## Note

This package is not version 1.0.0, it may or may not get breaking changes. Use it at your own risk on production
environment.

---
_Source: https://npm.io/package/@social-colyseus/server · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
