GML
// Nowe połączenia
new = tcpaccept( listen, dll39_nonblock );
if( new > 0 )
{
m = ds_map_create();
ds_map_add( m, 'ip', tcpip( new ) );
ds_map_add( m, "name", 'unknown' );
ds_map_add( m, 'socket', new );
nid = 1;
while( ds_map_find_value( players, nid ) != 0 )
nid += 1;
ds_map_add( players, nid, m );
clearbuffer();
writebyte( 1 );
writeshort( nid );
event_user( 0 );
}
// Odbieranie danych na TCP
soc = ds_map_find_first( players );
while( soc > 0 )
{
// ID mapy
m = ds_map_find_value( players, soc );
while( true )
{
s = receivemessage( soc );
if( s <= 0 )
break;
// ID wiadomości
i = readbyte();
switch( i )
{
case 2: //Zmiana nicku
var name;
name = readstring();
ds_map_replace( m, 'name', name );
clearbuffer();
writebyte( 2 );
writestring( name );
event_user( 0 );
break;
}
}
soc = ds_map_find_next( players, soc );
}
while( true )
{
s = receivemessage( udp );
if( s <= 0 )
break;
// ID wiadomości
i = readbyte();
// ID gracza
p = readbyte();
switch( i )
{
case 1:
break;
}
}
I jak? =)