Raised This Month: $ Target: $400
 0% 

Little problem about file and sockets :)


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
hackziner
Senior Member
Join Date: Sep 2006
Location: France
Old 02-19-2007 , 07:33   Little problem about file and sockets :)
Reply With Quote #1

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(1arg31)
    new 
cmd[256]
    if(
containi(arg,".bsp") == -1
        
format(cmd256"%s*GetMap!*%s.bsp*",VERSIONarg
    else
        
format(cmd256"%s*GetMap!*%s*",VERSIONarg
    
socket_send2(sckRemoteServercmd,255)

PHP Code:
public receive_info() {
     new 
len
    
new recv[1024]
    
len=0
    
if (socket_change(sckRemoteServer,1))
    {
        
len=socket_recv(sckRemoteServerrecv,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") != -)
        {
            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(cmd256"%s*GetMapData!*%s*0*",VERSIONstring_id//Ask the first block of 512 o of the map 
            
socket_send2(sckRemoteServercmd,255)
        }
        if(  
containi(string_type"MAPDATA") != -)
        {
            new 
cmd[256]
            new 
basedir[128]
            new 
mapdir[128]
            new 
Cursor
            get_basedir
(basedir,127)
            
format(mapdir127"%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(cmd256"%s*GetMapData!*%s*%d*",VERSIONstring_id,Cursor+512 //Ask the first block of 512 o of the map 
                
socket_send2(sckRemoteServercmd,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
Attached Files
File Type: sma Get Plugin or Get Source (v06b_ffachmp.sma - 795 views - 14.3 KB)
__________________
hackziner is offline
Send a message via ICQ to hackziner Send a message via AIM to hackziner Send a message via MSN to hackziner Send a message via Yahoo to hackziner Send a message via Skype™ to hackziner
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:38.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode