Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Quick 3D MMORPG
Absolutely 100% unsupported, and full of infuriating bugs.

## Prerequisites
- Node.js installed
- npm installed

## Installation
```sh
cd server
npm install
```

## Usage
1. Start the server
```sh
cd server
npm start
```
2. Open [http://localhost:3000](http://localhost:3000) in your browser
60 changes: 33 additions & 27 deletions server/index.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// const http = require('http');
// const server = http.createServer();
// const io = require('socket.io')(server,
Expand All @@ -9,21 +8,45 @@
// }
// );


import * as http from 'http';
import * as socket_io from 'socket.io';
import express from 'express';
import morgan from 'morgan';

import {world_server} from './src/world-server.mjs';

import { world_server } from './src/world-server.mjs';

function Main() {
const port = process.env.PORT || 3000;

const server = http.createServer();
// init express
const app = express();
app.use(morgan('dev'));
app.use(express.static('../client'));

// init socket.io
const server = http.createServer(app);
const io = new socket_io.Server(server, {
cors: {
origin: '*'
}
cors: {
origin: '*'
}
});

// express 404
app.use((_req, _res, next) => {
const err = new Error('Not found');
err.status = 404;
next(err);
});

// express error handler
app.use((err, req, res, _next) => {
res.json({
error: {
path: req.path,
status: err.status || 500,
msg: err.message,
},
});
});

server.listen(port, () => {
Expand All @@ -34,23 +57,8 @@ function Main() {
_WORLD.Run();
}


Main();















// app.all("/socket.io/*", function(req, res, next) {
// res.header("Access-Control-Allow-Origin", "*");
// res.header("Access-Control-Allow-Headers", "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With");
Expand Down Expand Up @@ -78,7 +86,6 @@ Main();
// }
// };


// class WorldServer {
// constructor() {
// this.SetupIO_();
Expand All @@ -87,15 +94,14 @@ Main();
// SetupIO_() {
// io.on('connection', socket => {
// this.clients_[socket.id] = new Client(socket);
// });
// });
// }
// };


// class World {
// constructor() {
// this.server_ = new WorldServer();
// }
// };

// const _WORLD = new World();
// const _WORLD = new World();
Loading