Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(async () => {
for (let i = 0; i < numClients; i++) {
const client = new Client(endpoint);
const options = (typeof(scripting.requestJoinOptions) === "function")
? await scripting.requestJoinOptions.call(client, i)
: {};
client.joinOrCreate(roomName, options).then(room => {
connections.push(room);
// display serialization method in the UI
const serializerIdText = (headerBox.children[2] as blessed.Widgets.TextElement);
serializerIdText.content = `{yellow-fg}serialization method:{/yellow-fg} ${room.serializerId}`;
room.connection.ws.addEventListener('message', (event) => {
bytesReceived += new Uint8Array(event.data).length;
});
const app = express();
app.use(cors());
//
// DO NOT COPY THIS BLOCK ON YOUR ENVIRONMENT
// development only
//
const webpack = require("webpack");
const webpackDevMiddleware = require("webpack-dev-middleware");
const webpackConfig = require("../webpack.config");
app.use(webpackDevMiddleware(webpack(webpackConfig({ })), { }));
// Create HTTP & WebSocket servers
const server = http.createServer(app);
const gameServer = new Server({
server,
// presence: new RedisPresence()
});
// Register ChatRoom as "chat"
gameServer.register("chat", ChatRoom);
app.use("/colyseus", monitor(gameServer));
gameServer.listen(port);
console.log(`Listening on ws://${ endpoint }:${ port }`)
import { DemoRoom } from "./DemoRoom";
import socialRoutes from "@colyseus/social/express";
import { FossilDeltaTestRoom } from "./FossilDeltaTestRoom";
const PORT = Number(process.env.PORT || 2567);
const app = express();
/**
* CORS should be used during development only.
* Please remove CORS on production, unless you're hosting the server and client on different domains.
*/
app.use(cors());
const gameServer = new Server({
server: http.createServer(app),
pingInterval: 0,
});
// Register DemoRoom as "demo"
gameServer.define("demo", DemoRoom);
gameServer.define("fossildelta", FossilDeltaTestRoom);
app.use("/", socialRoutes);
app.get("/something", function (req, res) {
console.log("something!", process.pid);
res.send("Hey!");
});
// Listen on specified PORT number
const http = require("http");
const express = require("express");
const colyseus = require("colyseus");
const DemoRoom = require('./demo_room');
const PORT = process.env.PORT || 2567;
const app = new express();
const gameServer = new colyseus.Server({
server: http.createServer(app)
});
// Register DemoRoom as "chat"
gameServer.register("demo", DemoRoom);
app.get("/something", function (req, res) {
console.log("something!", process.pid);
res.send("Hey!");
});
// Listen on specified PORT number
gameServer.listen(PORT);
console.log("Running on ws://localhost:" + PORT);
import * as serveIndex from 'serve-index';
import { createServer } from 'http';
import { Server } from 'colyseus';
import { monitor } from '@colyseus/monitor';
// Import demo room handlers
import { GameRoom as ExampleRoom } from "./Games/Example/GameRoom";
import { GameRoom as ExampleBodiesRoom } from './Games/ExampleBodies/GameRoom';
import { GameRoom as BattleGroundRoom } from './Games/BattleGround/GameRoom';
const port = Number(process.env.PORT || 2567);
const app = express();
// Attach WebSocket Server on HTTP Server.
const gameServer = new Server({
server: createServer(app)
});
gameServer.register("ExampleRoom", ExampleRoom);
gameServer.register("ExampleBodiesRoom", ExampleBodiesRoom);
gameServer.register("BattleGroundRoom", BattleGroundRoom);
app.use('/', express.static(path.join(__dirname, "static")));
app.use('/', serveIndex(path.join(__dirname, "static"), {'icons': true}))
// (optional) attach web monitoring panel
app.use('/colyseus', monitor(gameServer));
gameServer.onShutdown(function(){
console.log(`game server is going down.`);
var Room = require('colyseus').Room;
var State = require('../modules/state').state;
var DataLink = require('../modules/datalink');
var share = require('../../shared/constants');
class GameRoom extends Room
{
onInit(options)
{
this.setState(new State());
}
onAuth(options)
{
if(options.isNewUser){
// the last 3 values are for the default role_id = 1, status = 1 and state = 1:
var Room = require('colyseus').Room
class ChatRoom extends Room {
constructor (options) {
super(options)
// this.useTimeline()
this.setPatchRate(1000 / 192);
this.setState({ messages: [] })
// Call game simulation at 60fps (16.6ms)
this.setSimulationInterval( this.tick.bind(this), 1000 / 60 )
console.log("ChatRoom created!", options)
var Room = require('colyseus').Room
class ChatRoom extends Room {
constructor (options) {
options.updateInterval = 1000
super(options, { messages: [] })
console.log("ChatRoom created!", options)
}
onJoin (client) {
this.sendState(client)
console.log("ChatRoom:", client.id, "connected")
}
onLeave (client) {
// console.log("ChatRoom:", client.id, "disconnected")
this.column = column;
this.row = row;
this.xPos = column * cellSize;
this.yPos = row * cellSize;
this.walls = [true, true, true, true]; // 0 = top, 1 = right, 2 = bottom, 3 = left
this.visited = false; // Whether the cell has been traversed or not
}
const Room = require("colyseus").Room;
export class MazeRoom extends Room {
// this room supports only 4 clients connected
onInit (options) {
this.maxClients = 2;
this.maze = new Maze(23, 35);
this.maze.createMaze();
console.log("BasicRoom created!", options);
this.broadcast(this.maze);
}
onJoin (client) {
this.broadcast(`${ client.sessionId } joined.`);
api.get("/", async (req: express.Request, res: express.Response) => {
try {
const rooms: any[] = await matchMaker.query({});
res.json(rooms.map(room => {
const data = room.toJSON();
// additional data
data.locked = room.locked || false;
data.private = room.private;
data.elapsedTime = Date.now() - new Date(room.createdAt).getTime();
return data;
}));
} catch (e) {
const message = e.message;
console.error(message);
res.status(500);
res.json({ message });