It is currently Mon Dec 01, 2008 9:47 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: Datafiles
PostPosted: Mon Feb 20, 2006 11:04 pm 
Offline

Joined: Tue Feb 14, 2006 2:06 pm
Posts: 41
Location: Québec, Canada
Theses are some functions I am currently coding, I have some issues creating the datafile...
Code:
/*
   Logs.inc v1.0
   Logs Staff, player or script cmd in differents files using
   Andromeda UO's utilsdate available at http://groups.yahoo.com/group/pol-scriptforum/files/.
   Author: Developer Beaud.
   Email: DeveloperBeaud@gmail.com
   TODO:
    Add the scriptname to LogScriptEv returned string.
*/
use os;
use uo;
use datafile;

Include "include/utilsDate";

/*
  LogCMD(text)
 
  Stores strings in a txt file located in X/data/ds/logs/
 
  param text: That string will be logged in its user element an sorted by cmdlevel
              Example: LogCMD("Banned " + who.name + "'s account for cheating");           
         
  Notes: It might be usefull to manage a descent staff team.
*/
function LogCMD(who, text)
   var timedate :=  PolCore().systime;
   timedate := CDateStr(timedate) + " " + CTimeStr(timedate);
   var path;
   Case(who.cmdlevel)
   0: path := "logs/players";
   1: path := "logs/counselors";
   2: path := "logs/seers";
   3: path := "logs/gamemasters";
   4: path := "logs/admins";
   5: path := "logs/developers";
   Endcase
   var ldata := OpenDataFile( path );
   If(!ldata)
      ldata := CreateDataFile( path );
   Endif
   var log := ldata.FindElement(who.acctname);
   if(!log)
      log := ldata.CreateElement(who.acctname);
  else
   endif
   log.setprop(CInt(timedate), text);
   UnloadDataFile(path);
endfunction

/*
  LogScriptEv(text)
 
  Stores strings in a txt file located in X/data/ds/logs/
 
  param text: That string will be looged in its script element.
              Example: LogScriptEv("Banned " + who.name + "'s account for inactivity");
         
  Notes: It might be usefull if you need to locate which script is banning
         which were banned.
*/
function LogScriptEv(text)
   var timedate :=  PolCore().systime;
   timedate := CDateStr(timedate) + " " + CTimeStr(timedate);
   var path := "logs/ScriptEv";
   var ldata := OpenDataFile( path );
   If(!ldata)
      ldata := CreateDataFile( path );
   Endif
   var log := ldata.FindElement("polcore");
   if(!log)
      log := ldata.CreateElement("polcore");
   endif
   log.setprop(CInt(timedate), text);
   UnloadDataFile(path);
endfunction


Even if there is no */data/ds/logs/*.txt
It read it and doesn't Create the datafile.
Code:
var ldata := OpenDataFile( path );
If(!ldata)
  ldata := CreateDataFile( path );
Endif

But there is no datafile located in */data/ds/logs/, the folder is not even created.

I hope I been enought clear and that someone will help me.
Im using the POL095 core...

Beaud.

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 21, 2006 4:01 am 
Offline
Packet Maintainer

Joined: Thu Feb 02, 2006 8:33 am
Posts: 324
You have to put the package name into the path.

e.g.:
var path := CStr(":nameofthepackage:test");


Last edited by Pierce on Thu Feb 23, 2006 4:42 am, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 21, 2006 2:18 pm 
Offline

Joined: Tue Feb 14, 2006 2:06 pm
Posts: 41
Location: Québec, Canada
I guess you meant package with such a format ::test.log but Datafiles should be created in */data/ds/...

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 21, 2006 2:29 pm 
Offline
User avatar

Joined: Fri Feb 10, 2006 8:08 am
Posts: 330
Location: Myrtle Beach, South Carolina
after you've logged something save the world and check the data/ds


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 21, 2006 2:47 pm 
Offline

Joined: Tue Feb 14, 2006 2:06 pm
Posts: 41
Location: Québec, Canada
I did as well as some shutdown but its like if the file existed since OpenDataFile(path) is true :S

Maybe
Code:
var ldata := OpenDataFile( path );
   If(!ldata)
      ldata := CreateDataFile( path );
   Endif

Is not the good way to do it :?

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 21, 2006 4:17 pm 
Offline

Joined: Sat Feb 04, 2006 5:15 pm
Posts: 25
Yes, datafiles are stored in \data\ds, however, they are referenced internally by package name.

So, you would want your logging script in a package called "logs". Then, you would use OpenDataFile(":logs:logfilename").

You can use whatever package you would like, you don't have to use "logs". But yes, internally, datafiles are refrerenced by :packagename:filename.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 21, 2006 7:30 pm 
Offline

Joined: Tue Feb 14, 2006 2:06 pm
Posts: 41
Location: Québec, Canada
Could you explain the difference btw this entry in datastore.txt..
Code:
DataFile
{
   Descriptor   ::sysevent/staff
   Name   sysevent/staff
   Flags   0
   Version   6
   OldVersion   5
}

And mine..
Code:
DataFile
{
   Descriptor   ::logs/Developers
   Name   logs/Developers
   Flags   0
   Version   7
   OldVersion   7
}

Why the first one is creating a file called staff.txt in */data/ds/sysevent/..

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 21, 2006 10:20 pm 
Offline

Joined: Sat Feb 04, 2006 5:15 pm
Posts: 25
Just adding an entry to datafile.txt like that doesn't create the datafile. Not that I've ever been able to get it to do anyway, I just tried several different ways to be sure. You need to create the datafile in code.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 22, 2006 4:31 am 
Offline
User avatar

Joined: Fri Feb 10, 2006 8:08 am
Posts: 330
Location: Myrtle Beach, South Carolina
Mithril I hope you aren't referring to his last post, because that's not what he asked.

I had this problem too when I first started using datafiles. I forget what I did to fix it. Anyway check out regionspawner package, it has code using datafile.em. Use that as a referrance to fix your problem.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 22, 2006 5:52 am 
Offline
Packet Maintainer

Joined: Thu Feb 02, 2006 8:33 am
Posts: 324
Sorry, i surely meant package :wink:
First delete the stuff you have written into the datastore.txt while
the server is down.
Second i think the package is called "logs" where you have this script.
Use this code and the files will be stored in data/ds/..

Code:
/*
   Logs.inc v1.0
   Logs Staff, player or script cmd in differents files using
   Andromeda UO's utilsdate available at http://groups.yahoo.com/group/pol-scriptforum/files/.
   Author: Developer Beaud.
   Email: DeveloperBeaud@gmail.com
   TODO:
    Add the scriptname to LogScriptEv returned string.
*/
use os;
use uo;
use datafile;

Include "include/utilsDate";

/*
  LogCMD(text)
 
  Stores strings in a txt file located in X/data/ds/logs/
 
  param text: That string will be logged in its user element an sorted by cmdlevel
              Example: LogCMD("Banned " + who.name + "'s account for cheating");           
         
  Notes: It might be usefull to manage a descent staff team.
*/
function LogCMD(who, text)
   var timedate :=  PolCore().systime;
   timedate := CDateStr(timedate) + " " + CTimeStr(timedate);
   var path;
   Case(who.cmdlevel)
   0: path := "players";
   1: path := "counselors";
   2: path := "seers";
   3: path := "gamemasters";
   4: path := "admins";
   5: path := "developers";
   Endcase
   var ldata := OpenDataFile( path );
   If(!ldata)
      ldata := CreateDataFile( path );
   Endif
   var log := ldata.FindElement(who.acctname);
   if(!log)
      log := ldata.CreateElement(who.acctname);
  else
   endif
   log.setprop(CInt(timedate), text);
   UnloadDataFile(path);
endfunction

/*
  LogScriptEv(text)
 
  Stores strings in a txt file located in X/data/ds/logs/
 
  param text: That string will be looged in its script element.
              Example: LogScriptEv("Banned " + who.name + "'s account for inactivity");
         
  Notes: It might be usefull if you need to locate which script is banning
         which were banned.
*/
function LogScriptEv(text)
   var timedate :=  PolCore().systime;
   timedate := CDateStr(timedate) + " " + CTimeStr(timedate);
   var path := "ScriptEv";
   var ldata := OpenDataFile( path );
   If(!ldata)
      ldata := CreateDataFile( path );
   Endif
   var log := ldata.FindElement("polcore");
   if(!log)
      log := ldata.CreateElement("polcore");
   endif
   log.setprop(CInt(timedate), text);
   UnloadDataFile(path);
endfunction


fileaccess.cfg should be:
Code:
FileAccess
{
  Package *
  Directory *
  AllowRead 1
  AllowWrite 1
  AllowAppend 1
  AllowRemote 1
  Extension .log
}


Last edited by Pierce on Thu Feb 23, 2006 4:41 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 22, 2006 2:10 pm 
Offline

Joined: Tue Feb 14, 2006 2:06 pm
Posts: 41
Location: Québec, Canada
Actually this script is an include located in */scripts/include/...
I use the function is some script to log who used which cmd for X reason..
I have no pkg at all, all I want is a log file created somewhere, I was using "logs/*" because I though it would create it in */data/ds/logs/... But all along this topic you guys talked about pkgs an script, Its just a function located in an include file, I don't get it oO.. I just can't make a .log or a .txt out of this function.

That stuff was created in datastore.txt from the function, I never edited any file..

I have no logs pkg it was just a path i wanted the file to be in, I though it */data/ds/ + path..

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 22, 2006 2:23 pm 
Offline

Joined: Tue Feb 14, 2006 2:06 pm
Posts: 41
Location: Québec, Canada
SpawnRegion
Code:
function GlobalSpawnGroups()
  var dfile := OpenDataFile("SpawnGroups");
  if(!dfile)
    dfile := CreateDataFile("SpawnGroups");
...


Logs.inc
Code:
var ldata := OpenDataFile( path );
   If(!ldata)
      ldata := CreateDataFile( path );
   Endif

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 22, 2006 2:25 pm 
Offline

Joined: Tue Feb 14, 2006 2:06 pm
Posts: 41
Location: Québec, Canada
That fileaccess interest me though If there is a way to specify the path, the file extention as well it would be better than a simple text file in */data/ds/...

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 23, 2006 4:55 am 
Offline
Packet Maintainer

Joined: Thu Feb 02, 2006 8:33 am
Posts: 324
Damn i should not post if i am tired :wink:
The above was not quite correct, i edited it. But nevertheless, if this is an include file in scripts/include/ it won't work imho. It has to be in a package to create these datafiles.

If you want to use file.em functions, it will look something that way, e.g.

Code:
use os;
use uo;
use file;

program tc_sayabove( who, text )
    SendSysMessage( who, "Say above what or whom?" );

    var what := Target( who );
    if (what)
        PrintTextAbove( what, text, color := 6 );
    endif
   var filename := "::pkg/opt/LogSystem/"+ who.acct.name + ".log";
   var logtext := who.name + " says above " + what.name;
   if(what.isa(POLCLASS_NPC))
           logtext := logtext + " [" + what.npctemplate + "]: " + text;
   else
           logtext := logtext + " [" + what.acct.name + "]: " + text;
   endif
   LogToFile( filename, logtext );

endprogram


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Style based on FI Subice by phpBBservice.nl