Advertisement
biu

Jcoop score saver

biu
Aug 1st, 2012
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // oh look its a proper jcoopz1 score saver,
  2. // that saves player  scores to the server so when it crashes , it restores the danm scores
  3. // How Amazing! ^__^   zombie Y U no add this to jcoopz?
  4.  
  5. /* Changelog
  6.    July 27
  7.      Added savveplayerpawn to remedy the missing playerpawn data
  8.    July 28
  9.      Eliminated  saveplayerpawn funtion by casting to the pri owners instance of jzplayerpawn
  10.      50% speed increase due to eliminating a double  loop search.
  11.    July 29
  12.      cleaned up savefunction   to use a index ,
  13.       this ellimitates the quad illiteration it used to use increasing perfomance.
  14.       Removed all locals
  15.       Added  more data fields  for lastplaydate and a  playtime logger
  16.      Rewrote findplayer function
  17.       loop now will only search once intill it locates a entry and then return.
  18.    Aug 1
  19.       Added options to validate  data by uid instead of playername to increase security
  20.       along with adding almost double the code ;/
  21.      
  22.  
  23. */
  24. class jSaver extends mutator    config(Rising);
  25.  
  26. Struct PlayerData
  27. {   // Make the values fully editable in int
  28.     var() config string PlayerName;        // name
  29.     var() config string PlayerID;          // nope
  30.     var() config float  Score;             // enemykills
  31.     var() config string ip , uid,engine;   // stat
  32.     var() config int    realscore;         // playerpawnscore
  33.     var() config int    DeathCount;        // bang bang
  34.     var() config int    TScore;            // jzpri score
  35.     var() config string lastvisit;         // this
  36.     var() config int    playtime;          // that
  37.  
  38. };
  39.  
  40.  
  41. var() globalconfig PlayerData   Players[100];
  42. var() config int   TimeRate;     // no floats!
  43. var() config bool  BeSemiSecure; // uid toggle
  44.  
  45. simulated function PostBeginPlay()
  46. {
  47. if (TimeRate < 1) { TimeRate = 15;};  // dont want to add defualt properties i am that lazy!
  48. SetTimer(TimeRate,true);              // timer based on user value , used also to calulate playtime later.
  49. SaveConfig();
  50. }
  51.  
  52. simulated function Timer()
  53. {
  54.     local JCZPRI R;
  55.     ForEach AllActors(class'JCZPRI', R)
  56.     {
  57.      findplayerentry(R);
  58.     }
  59.  
  60. }
  61.  
  62.  
  63.  
  64. function string removecrapychars (string nataname)
  65. { // remove un-savable characters  in 225 and return a clean name.
  66.   // why ? 225 save config is unable to handle these characters!
  67.   // no it dosnt cover every possible charater only common ones
  68.   local  string chars[25],outp; // each char of name
  69.   local  int i;
  70.   if( int(Level.EngineVersion) < 227 )
  71.    {  For( i = 0; i <  len(nataname) ; i++  )
  72.       {    chars[i]= Mid(nataname,i,1);
  73.        if (chars[i]=="â") {chars[i]="a";};   if (chars[i]=="å") {chars[i]="a";};   if (chars[i]=="ß") {chars[i]="B";};
  74.        if (chars[i]=="Ð") {chars[i]="d";};   if (chars[i]=="Ð") {chars[i]="d";};   if (chars[i]=="ê") {chars[i]="e";};
  75.        if (chars[i]=="ë") {chars[i]="e";};   if (chars[i]=="~") {chars[i]="-";};   if (chars[i]=="º") {chars[i]="%";};
  76.        if (chars[i]=="»") {chars[i]=">";};   if (chars[i]=="«") {chars[i]="<";};   if (chars[i]=="ï") {chars[i]="i";};
  77.        if (chars[i]=="ñ") {chars[i]="n";};   if (chars[i]=="ü") {chars[i]="u";};   if (chars[i]=="£") {chars[i]="L";};
  78.        if (chars[i]=="ø") {chars[i]="o";};   if (chars[i]=="ó") {chars[i]="o";};   if (chars[i]=="Ø") {chars[i]="O";};
  79.        if (chars[i]=="§") {chars[i]="S";};   if (chars[i]=="") {chars[i]="";};     outp=outp $ chars[i];// rebuild name
  80.       }
  81.      return outp;
  82.  
  83.    }else{
  84.     return nataname;
  85.    }
  86.  
  87. }
  88.  
  89.  function findplayerentry(JCZPRI PRI)
  90.  {
  91.     // Find owner entry , or make a new one.
  92.     // it was faster to pass the save playerdata funtion a index to write to instead of it  illiterateing again .
  93.     local int i;
  94.     local bool befound;
  95.  
  96.     For( i = 0; i <  100 ; i++ )
  97.     {
  98.        if (BeSemiSecure)
  99.        {
  100.          if(jzPlayerPawn(PRI.Owner).PlayerUID == Players[i].uid)
  101.          { // Pre-Existing uid
  102.           befound = true;
  103.           saveplayerentry(pri,i);
  104.           return; // break loop ok , no need to keep looking!
  105.          }
  106.  
  107.        }else{
  108.  
  109.          if(removecrapychars(PRI.PlayerName) == Players[i].playername)
  110.          { // Pre-Existing name
  111.           befound = true;
  112.           saveplayerentry(pri,i);
  113.           return; // break loop ok , no need to keep looking!
  114.          }
  115.  
  116.        }
  117.     }
  118.  
  119.     // OK, So no entry found?
  120.     if (!befound)
  121.     { // Find a Free slot
  122.       For( i = 0; i <  100 ; i++  )
  123.       {
  124.          if (BeSemiSecure)
  125.         {
  126.            // WARNING  uid based names!
  127.           if (Players[i].uid == "" && ! befound )
  128.           { // Create it here!
  129.            Players[i].playername =removecrapychars(PRI.PlayerName);
  130.            // Inforn the server
  131.            log("------------------------------------------------");
  132.            log("Created New secure Score Entry For "$ removecrapychars(PRI.PlayerName));
  133.            log("IP:"$ jzPlayerPawn(PRI.Owner).PlayerIP);
  134.            log("Engine:"$ jzPlayerPawn(PRI.Owner).EngineVersion);
  135.            log("------------------------------------------------");
  136.            // Inform the Client
  137.            Pawn(PRI.Owner).ClientMessage("[New Score Stats Created" $ " @ data slot"$ i$"]", 'Pickup');
  138.            // Inform ourself!
  139.            befound = true;
  140.            saveplayerentry(pri,i);
  141.            saveconfig();
  142.            return;
  143.           }
  144.  
  145.  
  146.         }else{
  147.  
  148.  
  149.           if (Players[i].playername == "" && ! befound )
  150.           { // Create it here!
  151.            Players[i].playername = removecrapychars(PRI.PlayerName);
  152.            // Inforn the server
  153.            log("------------------------------------------------");
  154.            log("Created New Score Entry For "$ removecrapychars(PRI.PlayerName));
  155.            log("IP:"$ jzPlayerPawn(PRI.Owner).PlayerIP);
  156.            log("Engine:"$ jzPlayerPawn(PRI.Owner).EngineVersion);
  157.            log("------------------------------------------------");
  158.            // Inform the Client
  159.            Pawn(PRI.Owner).ClientMessage("[New Score Stats Created" $ " @ data slot"$ i$"]", 'Pickup');
  160.            // Inform ourself!
  161.            befound = true;
  162.            saveplayerentry(pri,i);
  163.            saveconfig();
  164.            return;
  165.           }
  166.         }
  167.  
  168.       }
  169.  
  170.     }
  171.  
  172.  }
  173.  
  174.  
  175. function saveplayerentry(JCZPRI PRI, int indexnum)
  176.  {
  177.     if (BeSemiSecure)
  178.      {
  179.        if( jzPlayerPawn(PRI.Owner).PlayerUID == Players[indexnum].uid)
  180.        { // killme:, we dont need to validate this  as is was alread valitaded before we got here.
  181.          // lets keep it anyway to add a sanity check incase index is thrown 0
  182.  
  183.          if  (Players[indexnum].tscore > PRI.TScore)  {   // Restore the score
  184.              jzPlayerPawn(PRI.Owner).TScore = Players[indexnum].realscore;
  185.              PRI.TScore=Players[indexnum].realscore;
  186.              log(" "$PRI.PlayerName$"'s  score recovered from  save slot"$ indexnum,'jsaver');
  187.  
  188.              if  (string(Players[indexnum].tscore) == string(PRI.TScore))
  189.              { // to stop extranious double messages
  190.               Pawn(PRI.Owner).ClientMessage("[Score has been recovered]" $ "From save slot"$ indexnum, 'Pickup');
  191.              }
  192.  
  193.          }else{ // score is ok , Ammend new data
  194.              Players[indexnum].Score        = PRI.EnemyKillCount;
  195.              Players[indexnum].tscore      = PRI.TScore;
  196.              players[indexnum].DeathCount  = pri.DeathCount;
  197.              Players[indexnum].ip           = jzPlayerPawn(PRI.Owner).PlayerIP;
  198.              Players[indexnum].engine       = jzPlayerPawn(PRI.Owner).EngineVersion;
  199.              Players[indexnum].uid          = jzPlayerPawn(PRI.Owner).PlayerUID;
  200.              Players[indexnum].realscore   = jzPlayerPawn(PRI.Owner).TScore;
  201.              players[indexnum].playtime    = players[indexnum].playtime + TimeRate;
  202.              players[indexnum].lastvisit   = Level.Month $"/"$Level.Day$"/"$level.year;
  203.          }
  204.  
  205.        }
  206.  
  207.      }else{
  208.  
  209.        if(removecrapychars(PRI.PlayerName) == Players[indexnum].playername)
  210.        { // killme:, we dont need to validate this  as is was alread valitaded before we got here.
  211.          // lets keep it anyway to add a sanity check incase index is thrown 0
  212.          if  (Players[indexnum].tscore > PRI.TScore)
  213.          {   // Restore the score
  214.              jzPlayerPawn(PRI.Owner).TScore = Players[indexnum].realscore;
  215.              PRI.TScore=Players[indexnum].realscore;
  216.  
  217.  
  218.              if  (string(Players[indexnum].tscore) == string(PRI.TScore))
  219.              { // To stop extranious double messages when we  check before the player is spawned
  220.               Pawn(PRI.Owner).ClientMessage("[Score has been recovered]" $ "From save slot"$ indexnum, 'Pickup');
  221.               log(" "$PRI.PlayerName$"'s  score recovered from  save slot"$ indexnum,'jsaver');
  222.              }
  223.  
  224.          }else{ // score is ok , Ammend new data
  225.              Players[indexnum].Score        = PRI.EnemyKillCount;
  226.              Players[indexnum].tscore      = PRI.TScore;
  227.              players[indexnum].DeathCount  = pri.DeathCount;
  228.              Players[indexnum].ip           = jzPlayerPawn(PRI.Owner).PlayerIP;
  229.              Players[indexnum].engine       = jzPlayerPawn(PRI.Owner).EngineVersion;
  230.              Players[indexnum].uid          = jzPlayerPawn(PRI.Owner).PlayerUID;
  231.              Players[indexnum].realscore   = jzPlayerPawn(PRI.Owner).TScore;
  232.              players[indexnum].playtime    = players[indexnum].playtime + TimeRate;
  233.              players[indexnum].lastvisit   = Level.Month $"/"$Level.Day$"/"$level.year;
  234.          }
  235.  
  236.         saveconfig();
  237.  
  238.        }
  239.  
  240.      }
  241.  
  242.  
  243.  
  244.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement