-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
112 lines (93 loc) · 2.58 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// EventEmitter = require('events'); // to execute scripts
// const express = require('express'),
// http = require('http'),
// socket = require('socket.io'), // for easier connexion
// fs = require('fs'), // file system
// vm = require('vm');
//import { SocketClient } from "models/gameserver.js";
import EventEmitter from 'events';
import express from 'express';
import http from 'http';
import vm from 'vm';
import fs from 'fs';
import socket from 'socket.io';
import GameServer from './models/gameserver.js';
const app = express();
const server = http.createServer(app);
const io = socket.listen(server);
import Game from './models/game.js';
const files = [
// Tools and tests
// "libs/tools.js",
// "libs/test.js",
// Base types
"libs/iterator.js",
"libs/dict.js",
"libs/tree.js",
// Math types
"libs/group.js",
// "libs/tensor.js",
// "libs/vector.js",
"libs/matrix.js",
// Visual types
"libs/color.js",
"libs/point.js",
"libs/figure.js",
// "libs/line.js",
"libs/form.js",
"libs/basepolygon.js",
"libs/segment.js",
"libs/polygon.js",
"libs/rectangle.js",
"libs/square.js",
"libs/circle.js",
// Physics types
"libs/motion.js",
"libs/body.js",
"libs/plane.js",
"libs/context.js",
"libs/entity.js",
"libs/manager.js",
// Game types
"models/gameentity.js",
"models/missile.js",
"models/missilegroup.js",
"models/life.js",
"models/follower.js",
"models/shooter.js",
"models/asteroid.js",
"models/asteroidgroup.js",
"models/spaceship.js",
"models/spaceshipgroup.js",
"models/meteor.js",
"models/meteorgroup.js",
"models/collider.js",
"models/gamemap.js",
"models/supergroup.js",
"models/game.js",
// Entry point
"models/gameserver.js",
];
// for (const file of files) {
// console.log(file);
// let data = fs.readFileSync(file);
// let script = new vm.Script(data);
// script.runInThisContext();
// }
server.listen(process.env.PORT || 8000)
app.use('/libs', express.static('libs'));
app.use('/models', express.static('models'));
app.use('/dist', express.static('dist'));
import path from 'path';
const __dirname = path.resolve();
console.log(__dirname)
// var path = __dirname.split("/");
// path = path.slice(0,-1).join("/");
app.get('/', function (req, res) {
res.sendFile(__dirname + "/views/index.html");
});
const game = Game.random();
//console.log(`Le group ${game.group.get('asteroidGroup')}`);
const gameServer = new GameServer(game, io);
gameServer.setUp();
gameServer.main();