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
scr_server_broadcast (shouldn't matter but Ill show it anyways)
and the client handle script (this is filtered with an if type=network_type_data)
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.
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));
}
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;
}
Also noticed the server always has one extra. The first one never counts.
Last edited: