| hackziner |
02-19-2007 07:33 |
Little problem about file and sockets :)
1 Attachment(s)
the purpose of this thing is to download map with a plugin into the server. So I have a server which send part of maps in udp packets.
PHP Code:
public MapDownload(id) { new arg[32] read_argv(1, arg, 31) new cmd[256] if(containi(arg,".bsp") == -1) format(cmd, 256, "%s*GetMap!*%s.bsp*",VERSION, arg) else format(cmd, 256, "%s*GetMap!*%s*",VERSION, arg) socket_send2(sckRemoteServer, cmd,255) }
PHP Code:
public receive_info() { new len new recv[1024] len=0 if (socket_change(sckRemoteServer,1)) { len=socket_recv(sckRemoteServer, recv,1024) } if (len > 16 ) { new string_id[64] new string_type[64] new string_score[64] new string_sid[541] new string_a[128] new string_b[700] strtok(recv,string_a,127,string_b,699,'+') strtok(string_a,string_id,63,string_type,63,'*') strtok(string_b,string_score,63,string_sid,540,'*') if( containi(string_type, "MAPINFO") != -1 ) { new cmd[256] MapDownSize=str_to_num(string_score) //Get size in o server_print ( "Server start the download of %s : size : %d",string_id,MapDownSize ) format(cmd, 256, "%s*GetMapData!*%s*0*",VERSION, string_id) //Ask the first block of 512 o of the map socket_send2(sckRemoteServer, cmd,255) } if( containi(string_type, "MAPDATA") != -1 ) { new cmd[256] new basedir[128] new mapdir[128] new Cursor get_basedir(basedir,127) format(mapdir, 127, "%s/../../maps/test/%s",basedir,string_id) new mapfile = fopen(mapdir,"ab+") Cursor = str_to_num(string_score) server_print ( "Server Get data from %d to %d of %s",Cursor,Cursor+512,string_id ) fseek ( mapfile,SEEK_END , 0) if ((MapDownSize-Cursor)<512 ) { fwrite_raw(mapfile,string_sid,MapDownSize-Cursor,BLOCK_INT) server_print ( "Map Downloaded ! : %s",string_id ) } else { fwrite_raw(mapfile,string_sid,512 ,BLOCK_INT) format(cmd, 256, "%s*GetMapData!*%s*%d*",VERSION, string_id,Cursor+512 ) //Ask the first block of 512 o of the map socket_send2(sckRemoteServer, cmd,256 ) } fclose(mapfile) } } return PLUGIN_CONTINUE }
My problem is simple ( perhaps i'm just very bad ... ), i don't manage to write the data from the socket to the file. In fact, i can read and display the right data from the socket, but i don't manage to write them in a file.
If you want to try, use the attach source, or directly send packets to 82.232.102.55:19863
The server apps can't "freeze or bug", so you can try everything :)
|