@endel thank you, i will try this.
Posts made by hardik_sl
Error !
colyseus@0.9.24 postinstall /home/fancytee/nodevenv/game_server/8/lib/node_modules/colyseus
npm run -s donate
while running npm install on my server through ssh
here is a screen shot
in case image not visible
https://drive.google.com/file/d/1VM9z4aAC2nuPnkNWQr4FnKwbzBFfePoP/view?usp=sharing
@endel thank you. and i am just using cards array for push and pop only i am not mutating and thanks again for help.
My state is like this:
onInit(options)
this.maxClients = 5;
this.minClients = 3;
this.setState({
players: {},
apid: [],
dpid: [1, 2, 3, 4, 5],
});
onJoin(client, options) {
var id;
id = this.state.dpid.shift();
this.state.apid.push(id);
this.state.players[client.sessionId] = {
playerId: id,
cards: [],
state: 1,
pack: 0,
trickData: {
Rank: 0,
Sum: 0,
c1: 0,
c2: 0,
c3: 0
}
}
C# code for listen to state change is:
room.Listen("players/:id", OnPlayerChange);
//room.Listen("players/:id/:playerId", OnPlayerIdChange);
//room.Listen("players/:id/:pack", OnPlayerPack);
room.Listen("players/:id/:cards/:number", OnCardsChange);
Problem is when palyersId change the OnPlayerIdChange and OnPlayerPack both getting the this data of state
trickData: {
Rank: 0,
Sum: 0,
c1: 0,
c2: 0,
c3: 0
}
i want to listen to only playerId and pack when this variable changes
[SOLVED]
Thanks @endel but as i am making card game i need to have options for client to choose whether to create a room ( private table ) or join the room ( if there is no room available then auto create room with)
Whenever i try to join room with quick match i get this error
Error: Failed to auto-create room "table" during join request using options "
{"create":false,"requestId":1,"clientId":"7klsqdU1v","sessionId":"eYHS93fBq"}"
at MatchMaker.create (D:\Colysues Server Unity\Server\node_modules\colyseus\lib\MatchMaker.js:228:19)
at MatchMaker.<anonymous> (D:\Colysues Server Unity\Server\node_modules\colyseus\lib\MatchMaker.js:114:31)
at Generator.next (<anonymous>)
at fulfilled (D:\Colysues Server Unity\Server\node_modules\colyseus\lib\MatchMaker.js:4:58)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
although if there is any available room it worked just fine and join that room. problem occurs when there is no room available to join (should not it automatically create a room ?)
here's server onJoin method
requestJoin (options, isNew) {
console.log("request join!", options);
return (options.create)? (options.create && isNew) : this.clients.length > 0;
}
onJoin (client, options) {
console.log("client joined! ", options);
}
Unity client code
string roomName = "table"
//for Quick Join
public void Join()
{
room = client.Join(roomName, new Dictionary<string, object>()
{
{ "create", false}
});
StartCoroutine(ConnectToRoom());
}
//for Creting new room
public void Create()
{
Debug.Log("Let's Crete & join the room!");
room = client.Join(roomName, new Dictionary<string, object>()
{
{ "create", true },
});
StartCoroutine(ConnectToRoom());
}
@endel Yay !! thats work Thanks.
@endel here the code
const http = require("http");
const express = require("express");
const monitor = require("@colyseus/monitor");
const colyseus = require("colyseus");
const GameRoom = require('./game_room');
const PORT = process.env.PORT || 3553;
const app = new express();
const gameServer = new colyseus.Server({
server: http.createServer(app)
});
// Register GameRoom as "table"
gameServer.register("table", GameRoom);
app.get("/something", function (req, res) {
console.log("something!", process.pid);
res.send("Hey!");
});
//colyseus game server monitor panel
app.use("/colyseus", monitor(gameServer));
// Listen on specified PORT number
gameServer.listen(PORT);
console.log("Running on ws://localhost:" + PORT);
@anubiscode i mean that if i use typescript then i can use this code to attach monitor ->
app.use("/colyseus", monitor(gameServer));
but if i use java script that will not work so any other way to attach monitor to game server??
app.use("/colyseus", monitor(gameServer));
cant use this
i'm creating multiplayer card game. i want make a private table (room) , but when i'm connecting to server it all connect to same room.
my code:
public string serverName = "localhost";
public string port = "3553";
public string roomName = "chat";
public IEnumerator Start()
{
String uri = "ws://" + serverName + ":" + port;
Debug.Log(uri);
client = new Client(uri);
client.OnOpen += OnOpenHandler;
client.OnClose += (object sender, EventArgs e) => Debug.Log("CONNECTION CLOSED");
Debug.Log("Let's connect the client!");
yield return StartCoroutine(client.Connect());
room = client.Join(roomName);
}
public void Join()//button event
{
StartCoroutine(ConnectToRoom(rname.text));
rname.text = "";
}
public void Create()//button event
{
StartCoroutine(ConnectToRoom(rname.text));
rname.text = "";
}
IEnumerator ConnectToRoom(String Room_Name)
{
Debug.Log("Let's join the room!");
//if Client Dose not Set room name;
if (Room_Name.Equals(""))
{
Room_Name = "NO ROOM NAME";
}
//Client Connect to Existing room
if (!isExistingRoom)
{
room = client.Join(roomName, new Dictionary<string, object>()
{
{ "create", true },
{ "name", Room_Name }
});
}
else
{
room = client.Join(Room_Name);
isExistingRoom = false;
}
room.OnReadyToConnect += (sender, e) =>
{
Debug.Log("Ready to connect to room!");
StartCoroutine(room.Connect());
};
room.OnJoin += OnRoomJoined;
room.OnStateChange += OnStateChangeHandler;
room.Listen("players/:id", this.OnPlayerChange);//players array
room.Listen("players/:id/:axis", this.OnPlayerMove);//x and y coridinates
room.Listen("messages/:number", this.OnMessageAdded);//message array
room.Listen(this.OnChangeFallback);
room.OnMessage += OnMessage;
while (true)
{
client.Recv();
yield return 0;
}
}
Thanks @endel it is really helpfull
i want to make multiplayer playing card game so , is there any way to determine the turn or restrict players if it is not their turn. or i just have write my own logic??
i'm totaly new to npm . iwas able to run example project but i dont know how can i create my own from scratch