Ajuda ai Pessoal, Criando INC
#1

Pessoal estou criando um aplicativo DATA WAREHOUSE (ARMAZEN DE DADOS), o meu sistema le um arquivo socket.com que tem os comandos para retorna as seзхes , como pode ver abaixo, ele escreve o retorna da seзгo em um arquivo chamado socket.resp, esta parte estб pronto mas o problema й que quero cria um inc para ficar facil receber e enviar essas informaзхes mas o problema й que fail, quando executo o comando ele da crash no server??

INCLUDE FILE:
Код:
/*
	*-------Star IDE DataWarehouse Control-------*
	*Version: 1.0.0.0 							 *
	*Authors: Marcelo F. A. Jr.					 *
	*Star Ide DataWareHouse Version Compatibilit *
	*Verson: 1.0.0.0							 *
	*--------------------------------------------*
*/

#if defined _dtaw_included
  #endinput
#endif

#define _dtaw_included
#pragma library dtawarehouse

#include <a_samp>

/*Natives
native getTextRes(filename[], password[], section[]);
native setTextRes(filename[], password[], section[], value[]);
*/

stock  getTextRes(filename[], password[], section[])
{
	new cmdStr[256];
	format(cmdStr, sizeof(cmdStr), "GETSECTION:%s:%s:%s", section, filename, password);
	// Envia o Pedido e Fica Tentando Ler A Reposta do DataWareHouse //
	//new string[256]; // Create the string to store the read text in
	new File: file = fopen("sampsc/socket.com", io_read); // Open the file
	if (file)
	{
	   	fremove("sampsc/socket.com");
	}
	fwrite(file, cmdStr);
	//Recebe Resposta
	new lReturn[256];
	lReturn = receiveResp(25);
 	return lReturn;
}

stock receiveResp(tentativas)
{
    new string[256];
	for(new i=0; i<tentativas; i++)
	{
		new File: file = fopen("sampsc/socket.resp", io_read); // Open the file
		if (file)
		{
	    	// Le o Comando
	    	fread(file, string); // Fread from the file and store what's read in 'string'
	    	fclose(file); // Close the file
	    	fremove("sampsc/socket.resp");
			return string;
		}
	}
	return string;
}

stock  setTextRes(filename[], password[], section[], value[])
{
	new cmdStr[256];
	format(cmdStr, sizeof(cmdStr), "EDITSECTION:%s:%s:%s:%s", section, password, filename, value);
	// Envia o Pedido e Fica Tentando Ler A Reposta do DataWareHouse //
	//new string[256]; // Create the string to store the read text in
	new File: file = fopen("sampsc/socket.com", io_read); // Open the file
	if (file)
	{
	   	fremove("sampsc/socket.com");
	}
	fwrite(file, cmdStr);
	//Recebe Resposta
	new lReturn2[256];
	lReturn2 = receiveResp(25);
 	return lReturn2;
}
PAWN Server Teste File:
Код:
#define FILTERSCRIPT

#include <a_samp>
#include <DataWareHouse>

forward TesteSet();
forward TesteGet();

public OnFilterScriptInit()
{
	print("\n--------------------------------------");
	print(" Teste Script DATAWAREHOUSE");
	print("--------------------------------------\n");
	SetTimer("TesteSet",10000,true);
	SetTimer("TesteGet",5000,true);
	
	return 1;
}

public OnFilterScriptExit()
{
	return 1;
}

public TesteSet()
{
	print("Teste de Setar Propriedade em Recurso");
	printf("%s", setTextRes("test.rsc", "CHAVE1", "1.B", "TESTE2"));
	return 1;
}

public TesteGet()
{
	print("Teste de Buscar Propriedade em Recurso");
	printf("%s", getTextRes("test.rsc", "CHAVE1", "1.B"));
	return 1;
}
Reply
#2

Deve ter crashado porque vocк abriu o arquivo em modo io_read e tentou escrever, feche o arquivo(fclose) e abra novamente em modo io_write.

pawn Код:
file = fopen("sampsc/socket.com", io_write);
Reply
#3

"Agora e nun dб crash mas tb nu escreve no arquivo?", mudei uma coisa e funciona obrigado!
Reply
#4

puta coisa complexa :S
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)