[How do i] Setup a simple server or so

Get help using Construct 2

Post » Mon May 13, 2013 6:26 pm

hello i didnt wrote anything in the last tome, but now its changing:
example explanation:
I press the "Build Soldier" button, it builds a soldier on my screen and sends the data: "Enemy build soldier" to the other client.
Its a RTS. the server should be like, a Multiroom Autojoin server.

I have problems understand the servside scripting, and communication between the clients, sending the "messages".
"It's done when it's done"

Shadows of War
Buy on Steam ;)
B
23
S
9
G
7
Posts: 253
Reputation: 4,831

Post » Mon May 13, 2013 8:25 pm

@SgtConti
What server are you using?

What C2 plugin are you using?

Could you please explain what your "Enemy build soldier" message is intended to create?

Is that another player that you can control? How would you control its actions as well as your own player's actions?

Or is it your own player, which other connecting clients need to display?
B
105
S
20
G
12
Posts: 549
Reputation: 20,320

Post » Tue May 14, 2013 2:53 pm

Sry for the lack of explanation.
Server: Node.js but im open for better options
C2 Plugin: Zack0Wack0s modded plugin
The Message should create a enemy soldier on the other players screen.
No, you only can control one player, the message is only there to say to the other client, that my player builld a soldier, and that it should make that on his screen.
So, its my own player wich others need to display ;)
"It's done when it's done"

Shadows of War
Buy on Steam ;)
B
23
S
9
G
7
Posts: 253
Reputation: 4,831

Post » Wed May 15, 2013 3:09 am

@SgtConti
Since you're using Zack0Wack0s modded plugin, you'll get the most/best help if you post in the thread dedicated to that.
B
105
S
20
G
12
Posts: 549
Reputation: 20,320

Post » Thu May 16, 2013 2:30 pm

Well unfortunately it doesnt show anything on how to use it.
Maybe im just stupid and dont get it...
I really need to know from the basics, how you should script something, how it all works.
"It's done when it's done"

Shadows of War
Buy on Steam ;)
B
23
S
9
G
7
Posts: 253
Reputation: 4,831

Post » Fri May 17, 2013 1:05 pm

var io = require('socket.io').listen(1337);

// usernames which are currently connected to the chat
var usernames = {};
var rooms = {};

io.sockets.on('connection', function (socket) {

     // when the client emits 'adduser', this listens and executes
     socket.on('adduser', function(username){
          // we store the username in the socket session for this client
          socket.username = username;
          // add the client's username to the global list
          usernames[username] = username;
          // echo to client they've connected
          socket.emit('updatechat', 'SERVER', 'you have connected');
          // echo globally (all clients) that a person has connected
          socket.broadcast.emit('updatechat', 'SERVER', username + ' has connected');
          // update the list of users in chat, client-side
          io.sockets.emit('updateusers', usernames);
     });

     // when the user disconnects.. perform this
     socket.on('disconnect', function(){
          // remove the username from global usernames list
          delete usernames[socket.username];
          // update list of users in chat, client-side
          io.sockets.emit('updateusers', usernames);
          // echo globally that this client has left
          socket.broadcast.emit('updatechat', 'SERVER', socket.username + ' has disconnected');

     socket.on('getrooms', function(){
          //
          //
          io.sockets.emit('updaterooms', rooms);
          //
          socket.broadcast.emit(socket.rooms);
     });
     });
});

that would be my server (just example), my problem is i cant connect.
Construct 2 client side i say: Socket.io connect to "localhost" port 1337
"It's done when it's done"

Shadows of War
Buy on Steam ;)
B
23
S
9
G
7
Posts: 253
Reputation: 4,831

Post » Sat Jun 01, 2013 11:55 am

Ok i managed it to get the server running, and emitting data through.
And making an Automatch system for 2 players.
but now i have a problem, everytime im emitting a string form my text box through, then i get it back the first time right.
Second time x 2
3rd time x3
4th time x 4...
I have no idea why. Heres a part from my server code in case something is wrong with that:
socket.on("message", function(data){
          socket.on("chatmessage", function(data2){
               io.sockets.in(data).send("chatmessage," + data2);
          });
          socket.on("GameSettings", function(data2){
               io.sockets.in(data).send("GameSettings," + data2);
          });
     });

I know the post is old, but better keeping this alive then always making a new thread for almost the same topic...
"It's done when it's done"

Shadows of War
Buy on Steam ;)
B
23
S
9
G
7
Posts: 253
Reputation: 4,831

Previous

Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 4 guests