Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
Multiplayer?

Guest
Guest
Quote
2023-06-20 20:49:29

How could I go about setting up multiplayer in Cc6? I dont seem to understand some of the forums regarding multiplayer.


marshallovski
Guest
Quote
2023-07-30 16:38:02

hi,
to create multiplayer, you need an multiplayer server.
example of multiplayer server in Node.js (JavaScript) using fastify and REST API:
(unfortunately, CopperCube doesn't support sending POST, DELETE or PATCH requests, so I'm used only GET)


const fastify = require('fastify')({ logger: false });
const PORT = 3000;

let players = Object.create(null);

// starting the server
(async () => {
try {
await fastify.listen(PORT);
console.log(`Server is running on port 3000`);
} catch (err) {
fastify.log.error(err);
process.exit(1);
}
})();

// set position of player
// example: ccbDoHTTPRequest('http://localhost:3000/player/set/position?playerName=Nick&posX=90&posY=40&posZ=10');

fastify.get('/player/set/position', async (request, reply) => {
const playerName = request.query.playerName;
const playerPosition = {
x: parseInt(request.query.posX),
y: parseInt(request.query.posY),
z: parseInt(request.query.posZ)
};

if (!playerName)
return {
ok: false,
message: 'Please provide `playerName` key in query'
}

if (!request.query.posX || !request.query.posY || !request.query.posZ)
return {
ok: false,
message: 'Please provide `posX`, `posY` and `posZ` keys in query'
}

// setting player position in `players` object
players[playerName].position = playerPosition;

// returning data to client
return { ok: true, position: playerPosition };
});

// get position of player
// example: ccbDoHTTPRequest('http://localhost:3000/player/get/position?playerName=Nick');
fastify.get('/player/get/position', async (request, reply) => {
const playerName = request.query.playerName;

if (!playerName)
return {
ok: false,
message: 'Please provide `playerName` key in query'
}

// returning data to client
return { ok: true, position: players[playerName].position };
});



Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "I?ternational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact