X
XirmiX
Guest
Previously, I encountered an issue where the client wasn't sending any information to the server. Apparently, the server needed to give permission to the client for sending data to it once the client was connected. Worked fine for the sending of initial data, and though I was a bit butt-hurt, it didn't create me much problems.
However now, when I need to have the client send data to the server constantly (i.e. the position of the client's player object and its direction every time it changes), this becomes a problem. I have everything set up for the client to send this data, but I have no way of getting permission from the server to allow me to send that data to it. And how would I? How would the server know I am moving my player object to allow me to send information about my player object moving, if the server can't know whether my player object is moving without me sending it data about my player object moving. A bit of a mouthful?
Well, in short terms, there is no way for the client to send the server data without it giving the client permission to do so, but to give it permission to do so is impossible if the server doesn't know whether the client's object is moving or not, which it can't if it doesn't allow the client to send it this information in the first place.
A solution to this would be to make it so that once the player has connected and all the normal data has been confirmed, the server just gives permission to the client to send data over and over again. I'm not sure if I have done this correctly though. I have a system where the server gives permission to the client to send some information to it once the client connects. The client then sends initial information to the server about itself and then the server processes it and does what it needs to do (i.e. spawning a representation of the player object in the correlating place for itself, which it does do!).
Except, I added to this processing one more thing now, and that being the permission from the server to the client that the client can keep sending coordinates and the angle direction of its controllable object to the server (I do have cases for the server to process this information too). I think what might be the problem here is that the server only gives permission once, but it needs to keep sending it, so some form of loop in some way would need to be done, may be, although I'm not entirely sure.
Here's the code for where the server sends permission to the client (this is inside a larger piece of code, though I know that the server does reach this piece of code, since above this is where the server actually spawns in a representation of the player's object for itself in its room):
This is where the client processes the information, and based on whether it changes position and direction (which is determined by buffer_type_send, ), it is supposed to send to the server this information:
Then, the server is supposed to process that information, apply this to its own player-representation object (and send it to other clients too, but that's not of importance right now):
Except, though I see my object move around on the client, on the server this does not happen. May be it's because the server is frozen while I have selected the player? Because I do get this in the log:
Pause event has been registered for this frame
Pause event has been unregistered
Though, since the object spawns on the server side as well, even though being frozen and simply doesn't move, I don't think that's the case.
However now, when I need to have the client send data to the server constantly (i.e. the position of the client's player object and its direction every time it changes), this becomes a problem. I have everything set up for the client to send this data, but I have no way of getting permission from the server to allow me to send that data to it. And how would I? How would the server know I am moving my player object to allow me to send information about my player object moving, if the server can't know whether my player object is moving without me sending it data about my player object moving. A bit of a mouthful?
Well, in short terms, there is no way for the client to send the server data without it giving the client permission to do so, but to give it permission to do so is impossible if the server doesn't know whether the client's object is moving or not, which it can't if it doesn't allow the client to send it this information in the first place.
A solution to this would be to make it so that once the player has connected and all the normal data has been confirmed, the server just gives permission to the client to send data over and over again. I'm not sure if I have done this correctly though. I have a system where the server gives permission to the client to send some information to it once the client connects. The client then sends initial information to the server about itself and then the server processes it and does what it needs to do (i.e. spawning a representation of the player object in the correlating place for itself, which it does do!).
Except, I added to this processing one more thing now, and that being the permission from the server to the client that the client can keep sending coordinates and the angle direction of its controllable object to the server (I do have cases for the server to process this information too). I think what might be the problem here is that the server only gives permission once, but it needs to keep sending it, so some form of loop in some way would need to be done, may be, although I'm not entirely sure.
Here's the code for where the server sends permission to the client (this is inside a larger piece of code, though I know that the server does reach this piece of code, since above this is where the server actually spawns in a representation of the player's object for itself in its room):
Code:
//create a buffer with which to send information
var permission_buffer = buffer_create(256, buffer_fixed, 1);
//writing data to send to buffer
buffer_seek(permission_buffer, buffer_seek_start, 0);
buffer_write(permission_buffer, buffer_u8, 1);
network_send_packet(client_socket_current, permission_buffer, buffer_get_size(permission_buffer));
buffer_delete(permission_buffer);
Code:
type = async_load[? "type"];
switch(type)
{
case network_type_data:
buffer = async_load[? "buffer"];
buffer_seek(buffer, buffer_seek_start, 0);
permission_confirmed = buffer_read(buffer, buffer_u8);
switch(permission_confirmed)
{
case 1:
if (buffer_type_send == 6)
{
send_buffer = buffer_create(256, buffer_fixed, 1);
buffer_seek(send_buffer, buffer_seek_start, 0);
buffer_write(send_buffer, buffer_u8, 6);
buffer_write(send_buffer, buffer_f32, mytank.x);
buffer_write(send_buffer, buffer_f32, mytank.y);
network_send_packet(socket_plug, send_buffer, buffer_get_size(send_buffer));
buffer_delete(send_buffer);
}
if (buffer_type_send == 7)
{
send_buffer = buffer_create(256, buffer_fixed, 1);
buffer_seek(send_buffer, buffer_seek_start, 0);
buffer_write(send_buffer, buffer_u8, 7);
buffer_write(send_buffer, buffer_f32, mytank.direction);
network_send_packet(socket_plug, send_buffer, buffer_get_size(send_buffer));
buffer_delete(send_buffer);
}
break;
}
Code:
//sending buffer type 6 (coordinates)
case 6:
var client_id = ds_map_find_value(socket_map, client_socket_current);
var xx = buffer_read(buffer, buffer_f32);
var yy = buffer_read(buffer, buffer_f32);
client_socket_current.instance.x = xx;
client_socket_current.instance.y = yy;
--[code for sending this information about the client who sent this to the server, to other clients]--
break;
//sending buffer type 7 (angles)
case 7:
var client_id = ds_map_find_value(socket_map, client_socket_current);
var angle = buffer_read(buffer, buffer_f32);
client_socket_current.instance.direction = angle;
--[code for sending this information about the client who sent this to the server, to other clients]--
break;
Pause event has been registered for this frame
Pause event has been unregistered
Though, since the object spawns on the server side as well, even though being frozen and simply doesn't move, I don't think that's the case.