Closed karneaud closed 2 years ago
I notice that the authentication returns a token. Was I suppose to use the token when trying to create to join the room?
token is required for this API method. All available methods in api.ts file. I assume you are getting 400 error because the room with that name is not defined
The easiest way to start using magx server is via magx-client library, or you will have to implement all connection/communication logic yourself
@udamir
Well based on your example I seem to be instantiating it correctly. Only difference is I had to use "https" in order for the monitor to work.
const createServer = require('https').createServer,
fs = require('fs'),
production = process.env.NODE_ENV || false,
port = process.env.PORT || 2567,
Server = require('magx').Server,
server = createServer({
key: fs.readFileSync(__dirname + '/../private.key'),
cert: fs.readFileSync(__dirname + '/../private.crt')
}),
gameServer = new Server(server),
PullOWarRoom = require('./rooms'),
monitor = require('magx-monitor').monitor;
gameServer.define('pullowar', PullOWarRoom);
.....
and I am using the client correctly. Do I need to set the token manually? As I see it being passed in the headers.
const client = new Client({ address: match[3], port: SOCKET_PORT, secure: (/https/i).test(url), serializer: SchemaSerializer })
client.authenticate().then((r) => {
console.log('auth', r) // i get the token
return client.getRooms()
}).then((rooms) => {
console.log('rooms', rooms); // does not return anything
return (ROOM_ID ? client.joinRoom(ROOM_ID) : client.createRoom('pullowar'))
} ).then(room => {
Room = room;
setGameId( room.id)
...
}).catch(e => {
console.log("JOIN ERROR", e); // prints 400 bad request
})
The game says its creating the room
Process 70: Get avalible rooms Find process for room: Current process load: {} All cluster pids [] Process 70 requested: Create room pullowar
However the monitor does not list it.
If I don't use CORs or HTTPS I get the other previous issues I logged in repo.
you need to call monitor(gameServer)
to attach monitor to magx server.
Monitor is very poor module, but it works with http as well as with https.
I tested magx server with https also, and did't have any issues.
If client don't join the room after creation it is closing automatically.
So I'm using cors and https to run the server( port 2567) while I run the game on a different server( port 3000).
While the logs show I'm able to create a room
The client side seems to return a
with the following payload.
Did I need to set additional options for the room to be initialized?