DS_list over network

Roa

Member
I have ran into a problem and I can't seem to figure out why nothing displays right.

I have two objects, a client and a server and both transfer to a room as a waiting lobby.
Upon connection I immediately send the players name to the server, the server stores that in a ds_list, then the server takes the whole list, writes it to a buffer, and resend it to all connected clients. The clients then clear their table and re-write with the new data, but I'm always a name short on the most recent client to connect.

server receive data event
Code:
///scr_server_packet_handle(buffer,sender id)
var Buff=argument0;
var Sock=argument1;

buffer_seek(Buff,buffer_seek_start,0);
var header=buffer_read(Buff,buffer_u8);

switch(header)
        {
        case 0:
        var insti=ds_map_find_value(client_map,Sock);
        var namev=buffer_read(Buff,buffer_string);
        insti.name=namev;
        ds_list_add(player_name_list,string(namev))
      
      
       buffer_seek(buff,buffer_seek_start,0);
        buffer_write(buff,buffer_u8,1);
        buffer_write(buff,buffer_u8,ds_list_size(player_name_list)-1);
        var n,val;
        for(n=0; n<ds_list_size(player_name_list)-1; n++)
        {
        val=ds_list_find_value(player_name_list,n);
        buffer_write(buff,buffer_string,val);
        }
      
        scr_server_broadcast();
        break;
        }

scr_server_broadcast (shouldn't matter but Ill show it anyways)
Code:
///scr_server_broadcast
var n, send;
for (n=0; n<ds_list_size(client_list)-1; n+=1)
{
send=ds_list_find_value(client_list,n)
network_send_packet(send,buff,buffer_tell(buff));
}
and the client handle script (this is filtered with an if type=network_type_data)
Code:
var Buff=argument0;

buffer_seek(Buff,buffer_seek_start,0);
var header=buffer_read(Buff,buffer_u8);

switch(header)
        {
        case 1:
        ds_list_clear(player_name_list)
        var reps=buffer_read(Buff,buffer_u8);
        var name;
        repeat(reps){
        name=buffer_read(Buff,buffer_string);
        ds_list_add(player_name_list,name);}
        last_packet=1
        break;
        }
I dont see anything obvious, but the ds_list size doesn't change on the client the first round.

Also noticed the server always has one extra. The first one never counts.
 
Last edited:
Because you are sending ds_list_size(player_name_list)-1. So if the list has 1 player, then it will send over 0, and then the client won't read anything
 
  • Like
Reactions: Roa

Roa

Member
Because you are sending ds_list_size(player_name_list)-1. So if the list has 1 player, then it will send over 0, and then the client won't read anything
I mean, that makes sense, but then it throws outside range errors. I fiddled with that before. Good call though. Maybe its a combo of that and the broadcast script.

Yeah, its funny that works, the name list are equal, but the first one is always a zero and it says its outside the buffer. I just can't put my finger on it even though its staring me in the face. There has got to be one stupid number other than the send ds_list size that is also throwing it off.
 
Top