Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1601 connectés 

  FORUM HardWare.fr
  Programmation
  Java

  Exploit dans mon code

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Exploit dans mon code

n°2180094
ryuzayke
Posté le 12-03-2013 à 22:05:51  profilanswer
 

So basically I made this code for my game wich is for the fight stage..
This is the code the allow the player to be able to leave the fight, but once he leave the fight in type _PVM, the game think that the player is still in it so at the end at player still receive the ammount of experience for the combat when he shouldn't be getting it..
 
I know the text in english are not perfect -_- I'm french okay ?
 

Code :
  1. public void leftFight(Personnage perso, Personnage target)
  2. {
  3.  if(perso == null)return;
  4.  Fighter F = this.getFighterByPerso(perso);
  5.  Fighter T = null;
  6.  if(target != null) T = this.getFighterByPerso(target);
  7.  if(ElinkEmu.CONFIG_DEBUG)
  8.  {
  9.   if(target != null && T != null)
  10.   {
  11.    GameServer.addToLog(perso.get_name()+" kick "+T.getPersonnage().get_name());
  12.   }else
  13.   {
  14.    GameServer.addToLog(perso.get_name()+" has left the fight" );
  15.   }
  16.  }
  17.  if(F != null)
  18.  {
  19.   switch(_type)
  20.   {
  21.    case Constants.FIGHT_TYPE_CHALLENGE: //challenges
  22.    case Constants.FIGHT_TYPE_KOLI: //Arena
  23.    case Constants.FIGHT_TYPE_AGRESSION: //PVP
  24.    case Constants.FIGHT_TYPE_PVM: //PVM
  25.    case Constants.FIGHT_TYPE_PVT: //Perco
  26.    case Constants.FIGHT_TYPE_CONQUETE: //Prism
  27.     if(_state >= Constants.FIGHT_STATE_ACTIVE)
  28.     {
  29.      if(_ordreJeu.size() == 0){
  30.       endTurn();
  31.      }else if(_ordreJeu.get(_curPlayer).getGUID() == F.getGUID())
  32.      {
  33.       endTurn();
  34.      }
  35.      onFighterDie(F, T);
  36.      boolean StillInFight = false;
  37.      if(_type == Constants.FIGHT_TYPE_CHALLENGE || _type == Constants.FIGHT_TYPE_AGRESSION || _type == Constants.FIGHT_TYPE_PVT|| _type == Constants.FIGHT_TYPE_KOLI)
  38.      {
  39.       StillInFight = verifyStillInFightTeam(F.getGUID());
  40.      }else
  41.      {
  42.       StillInFight = verifyStillInFight();
  43.      }
  44.      if(!StillInFight) //If it stops here nobody left in the fight and the team
  45.      {
  46.       //puts an end to fighting
  47.       verifIfTeamAllDead();
  48.      }else
  49.      {
  50.       F.setLeft(true);
  51.       SocketManager.GAME_SEND_ERASE_ON_MAP_TO_MAP(_map, F.getGUID());
  52.       Personnage P = F.getPersonnage();
  53.       P.set_duelID(-1);
  54.       P.set_ready(false);
  55.       //P.fullPDV(); //Put back life of the player when canceling a challenge.
  56.       P.set_fight(null);
  57.       P.setSitted(false);
  58.       P.set_away(false);
  59.       if(_type == Constants.FIGHT_TYPE_AGRESSION || _type == Constants.FIGHT_TYPE_PVM || _type == Constants.FIGHT_TYPE_PVT|| _type == Constants.FIGHT_TYPE_KOLI)
  60.       {
  61.        /**Energy**/
  62.        int EnergyLoos = Formulas.getLoosEnergy(P.get_lvl(), _type==1, _type==5);
  63.        int Energy = P.get_energy() - EnergyLoos;
  64.        if(Energy < 0) Energy = 0;
  65.        P.set_energy(Energy);
  66.        if(P.isOnline())
  67.         SocketManager.GAME_SEND_Im_PACKET(P, "034;"+EnergyLoos);
  68.        /**Energy**/
  69.        if(_type == Constants.FIGHT_TYPE_AGRESSION || _type == Constants.FIGHT_TYPE_CONQUETE)
  70.        {
  71.         int honor = P.get_honor()-500;
  72.         if(honor < 0) honor = 0;
  73.         P.set_honor(honor);
  74.         if(P.isOnline())
  75.          SocketManager.GAME_SEND_Im_PACKET(P, "076;"+honor);
  76.        }
  77.        try
  78.        {
  79.         Thread.sleep(1000);
  80.        }catch(Exception E){};
  81.        if(Energy == 0)
  82.        {
  83.         P.set_Ghosts();
  84.        }else
  85.        {
  86.         P.warpToSavePos();
  87.         P.set_PDV(1);
  88.        }
  89.       }
  90.       if(P.isOnline())
  91.       {
  92.        try
  93.        {
  94.         Thread.sleep(200);
  95.        }catch(Exception E){};
  96.        SocketManager.GAME_SEND_GV_PACKET(P);
  97.        P.refreshMapAfterFight();
  98.       }
  99.      }
  100.     }else if(_state == Constants.FIGHT_STATE_PLACE)
  101.     {
  102.      boolean isValid1 = false;
  103.      if(T != null)
  104.      {
  105.       if(_init0 != null &&_init0.getPersonnage() != null)
  106.       {
  107.        if(F.getPersonnage().get_GUID() == _init0.getPersonnage().get_GUID())
  108.        {
  109.         isValid1 = true;
  110.        }
  111.       }
  112.       if(_init1 != null &&_init1.getPersonnage() != null)
  113.       {
  114.        if(F.getPersonnage().get_GUID() == _init1.getPersonnage().get_GUID())
  115.        {
  116.         isValid1 = true;
  117.        }
  118.       }
  119.      }
  120.      if(isValid1) //Whoever does the action start the fight and leave another character
  121.      {
  122.       if((T.getTeam() == F.getTeam()) && (T.getGUID() != F.getGUID()))
  123.       {
  124.        if(ElinkEmu.CONFIG_DEBUG) System.out.println("Kick of : "+T.getPersonnage().get_name());
  125.        SocketManager.GAME_SEND_ON_FIGHTER_KICK(this, T.getPersonnage().get_GUID(), getTeamID(T.getGUID()));
  126.        if(_type == Constants.FIGHT_TYPE_AGRESSION || _type == Constants.FIGHT_TYPE_CHALLENGE || _type == Constants.FIGHT_TYPE_PVT|| _type == Constants.FIGHT_TYPE_KOLI) SocketManager.GAME_SEND_ON_FIGHTER_KICK(this, T.getPersonnage().get_GUID(), getOtherTeamID(T.getGUID()));
  127.        Personnage P = T.getPersonnage();
  128.        P.set_duelID(-1);
  129.        P.set_ready(false);
  130.        P.fullPDV();
  131.        P.set_fight(null);
  132.        P.setSitted(false);
  133.        P.set_away(false);
  134.        if(P.isOnline())
  135.        {
  136.         try
  137.         {
  138.          Thread.sleep(200);
  139.         }catch(Exception E){};
  140.         SocketManager.GAME_SEND_GV_PACKET(P);
  141.         P.refreshMapAfterFight();
  142.        }
  143.        //We removes it from the team
  144.        if(_team0.containsKey(T.getGUID()))
  145.        {
  146.         T._cell.removeFighter(T);
  147.         _team0.remove(T.getGUID());
  148.        }
  149.        else if(_team1.containsKey(T.getGUID()))
  150.        {
  151.         T._cell.removeFighter(T);
  152.         _team1.remove(T.getGUID());
  153.        }
  154.        for(Personnage z : _mapOld.getPersos()) FightStateAddFlag(this._mapOld, z);
  155.       }
  156.      }else if(T == null) //Leave it voluntarily so (T = null)
  157.      {
  158.       boolean isValid2 = false;
  159.       if(_init0 != null &&_init0.getPersonnage() != null)
  160.       {
  161.        if(F.getPersonnage().get_GUID() == _init0.getPersonnage().get_GUID())
  162.        {
  163.         isValid2 = true;
  164.        }
  165.       }
  166.       if(_init1 != null &&_init1.getPersonnage() != null)
  167.       {
  168.        if(F.getPersonnage().get_GUID() == _init1.getPersonnage().get_GUID())
  169.        {
  170.         isValid2 = true;
  171.        }
  172.       }
  173.       if(isValid2) //He is going into battle => cancellation of the fight
  174.       {
  175.        for(Fighter f : this.getFighters(F.getTeam2()))
  176.        {
  177.         Personnage P = f.getPersonnage();
  178.         P.set_duelID(-1);
  179.         P.set_ready(false);
  180.         //P.fullPDV();
  181.         P.set_fight(null);
  182.         P.setSitted(false);
  183.         P.set_away(false);
  184.         if(F.getPersonnage().get_GUID() != f.getPersonnage().get_GUID()) //Those who joined the fight go back on the map
  185.         {
  186.          if(P.isOnline())
  187.          {
  188.           try
  189.           {
  190.            Thread.sleep(200);
  191.           }catch(Exception E){};
  192.           SocketManager.GAME_SEND_GV_PACKET(P);
  193.           P.refreshMapAfterFight();
  194.          }
  195.         }else //Whoever did the fight dies loss + honor
  196.         {
  197.          if(_type == Constants.FIGHT_TYPE_AGRESSION || _type == Constants.FIGHT_TYPE_PVM || _type == Constants.FIGHT_TYPE_PVT|| _type == Constants.FIGHT_TYPE_KOLI)
  198.          {
  199.           /**Energy**/
  200.           int EnergyLoos = Formulas.getLoosEnergy(P.get_lvl(), _type==1, _type==5);
  201.           int Energy = P.get_energy() - EnergyLoos;
  202.           if(Energy < 0) Energy = 0;
  203.           P.set_energy(Energy);
  204.           if(P.isOnline())
  205.            SocketManager.GAME_SEND_Im_PACKET(P, "034;"+EnergyLoos);
  206.           /**Energy**/
  207.           if(_type == Constants.FIGHT_TYPE_AGRESSION || _type == Constants.FIGHT_TYPE_CONQUETE)
  208.           {
  209.            int honor = P.get_honor()-500;
  210.            if(honor < 0) honor = 0;
  211.            P.set_honor(honor);
  212.            if(P.isOnline())
  213.             SocketManager.GAME_SEND_Im_PACKET(P, "076;"+honor);
  214.           }
  215.           try
  216.           {
  217.            Thread.sleep(1000);
  218.           }catch(Exception E){};
  219.           if(Energy == 0)
  220.           {
  221.            P.set_Ghosts();
  222.           }else
  223.           {
  224.            P.warpToSavePos();
  225.            P.set_PDV(1);
  226.           }
  227.          }
  228.          if(P.isOnline())
  229.          {
  230.           try
  231.           {
  232.            Thread.sleep(200);
  233.           }catch(Exception E){};
  234.           SocketManager.GAME_SEND_GV_PACKET(P);
  235.           P.refreshMapAfterFight();
  236.          }
  237.         }
  238.        }
  239.        _ticMyTimer_startTime = 0L;
  240.                          _ticMyTimer_endTurn = false;
  241.                          if(_type == Constants.FIGHT_TYPE_AGRESSION || _type == Constants.FIGHT_TYPE_CHALLENGE || _type == Constants.FIGHT_TYPE_PVT|| _type == Constants.FIGHT_TYPE_KOLI)
  242.        {
  243.         for(Fighter f : this.getFighters(F.getOtherTeam()))
  244.         {
  245.          if(f.getPersonnage() == null) continue;
  246.          Personnage P = f.getPersonnage();
  247.          P.set_duelID(-1);
  248.          P.set_ready(false);
  249.          //P.fullPDV();
  250.          P.set_fight(null);
  251.          P.setSitted(false);
  252.          P.set_away(false);
  253.          if(P.isOnline())
  254.          {
  255.           try
  256.           {
  257.            Thread.sleep(200);
  258.           }catch(Exception E){};
  259.           SocketManager.GAME_SEND_GV_PACKET(P);
  260.           P.refreshMapAfterFight();
  261.          }
  262.         }
  263.        }
  264.        _state = 4; //Make sure we do not start the fight
  265.        World.getCarte(_map.get_id()).removeFight(_id);
  266.        SocketManager.GAME_SEND_MAP_FIGHT_COUNT_TO_MAP(World.getCarte(_map.get_id()));
  267.        SocketManager.GAME_SEND_GAME_REMFLAG_PACKET_TO_MAP(this._mapOld,_init0.getGUID());
  268.        if (_type == Constants.FIGHT_TYPE_CONQUETE) {
  269.         String str = _Prisme.getCarte() + "|" + _Prisme.getX() + "|" + _Prisme.getY();
  270.         for (Personnage z : World.getOnlinePersos()) {
  271.          if (z == null)
  272.           continue;
  273.          if (z.get_align() != _Prisme.getalignement())
  274.           continue;
  275.          SocketManager.SEND_CS_SURVIVRE_MESSAGE_PRISME(z, str);
  276.         }
  277.         _Prisme.setInFight(-1);
  278.         _Prisme.setFightID(-1);
  279.         if (perso != null) {
  280.          if (_Prisme != null)
  281.           SocketManager.SEND_CP_INFO_DEFENSEURS_PRISME(perso, getDefenseurs());
  282.         }
  283.         for (Personnage z : World.getCarte((short) _Prisme.getCarte()).getPersos()) {
  284.          if (z == null)
  285.           continue;
  286.          SocketManager.SEND_GM_PRISME_TO_MAP(z.get_compte().getGameThread().get_out(),
  287.            z.get_curCarte());
  288.         }
  289.        }
  290.        if(_type == Constants.FIGHT_TYPE_PVT)
  291.        {
  292.         for(Personnage z : World.getGuild(_guildID).getMembers())
  293.         {
  294.          if(z == null) continue;
  295.          if(z.isOnline())
  296.          {
  297.           SocketManager.GAME_SEND_gITM_PACKET(z, Percepteur.parsetoGuild(z.get_guild().get_id()));
  298.           SocketManager.GAME_SEND_PERCO_INFOS_PACKET(z, F._Perco, "S" );
  299.          }
  300.         }
  301.         _perco.set_inFight((byte)0);
  302.         _perco.set_inFightID((byte)-1);
  303.         _perco.clearDefenseFight();
  304.         for(Personnage z : World.getCarte((short)_perco.get_mapID()).getPersos())
  305.         {
  306.          if(z == null) continue;
  307.          SocketManager.GAME_SEND_MAP_PERCO_GMS_PACKETS(z.get_compte().getGameThread().get_out(), z.get_curCarte());
  308.         }
  309.        }
  310.        if(_type == Constants.FIGHT_TYPE_PVM)
  311.        {
  312.         int align = -1;
  313.         if(_team1.size() >0)
  314.         {
  315.           _team1.get(_team1.keySet().toArray()[0]).getMob().getTemplate().getAlign();
  316.         }
  317.         //Si groupe non fixe
  318.         if(!_mobGroup.isFix())World.getCarte(_map.get_id()).spawnGroup(align, 1, true,_mobGroup.getCellID()); //Respawn group
  319.        }
  320.        _map = null;
  321.        _ordreJeu = null;
  322.       }else //Either he joined the fight => Left to itself
  323.       {
  324.        SocketManager.GAME_SEND_ON_FIGHTER_KICK(this, F.getPersonnage().get_GUID(), getTeamID(F.getGUID()));
  325.        if(_type == Constants.FIGHT_TYPE_AGRESSION || _type == Constants.FIGHT_TYPE_CHALLENGE || _type == Constants.FIGHT_TYPE_PVT|| _type == Constants.FIGHT_TYPE_KOLI) SocketManager.GAME_SEND_ON_FIGHTER_KICK(this, F.getPersonnage().get_GUID(), getOtherTeamID(F.getGUID()));
  326.        Personnage P = F.getPersonnage();
  327.        P.set_duelID(-1);
  328.        P.set_ready(false);
  329.        //P.fullPDV();
  330.        P.set_fight(null);
  331.        P.setSitted(false);
  332.        P.set_away(false);
  333.        if(_type == Constants.FIGHT_TYPE_AGRESSION || _type == Constants.FIGHT_TYPE_PVM || _type == Constants.FIGHT_TYPE_PVT|| _type == Constants.FIGHT_TYPE_KOLI)
  334.        {
  335.         /**Energy**/
  336.         int EnergyLoos = Formulas.getLoosEnergy(P.get_lvl(), _type==1, _type==5);
  337.         int Energy = P.get_energy() - EnergyLoos;
  338.         if(Energy < 0) Energy = 0;
  339.         P.set_energy(Energy);
  340.         if(P.isOnline())
  341.          SocketManager.GAME_SEND_Im_PACKET(P, "034;"+EnergyLoos);
  342.         /**Energy**/
  343.         if(_type == Constants.FIGHT_TYPE_AGRESSION || _type == Constants.FIGHT_TYPE_CONQUETE)
  344.         {
  345.          int honor = P.get_honor()-500;
  346.          if(honor < 0) honor = 0;
  347.          P.set_honor(honor);
  348.          if(P.isOnline())
  349.           SocketManager.GAME_SEND_Im_PACKET(P, "076;"+honor);
  350.         }
  351.         try
  352.         {
  353.          Thread.sleep(1000);
  354.         }catch(Exception E){};
  355.         if(Energy == 0)
  356.         {
  357.          P.set_Ghosts();
  358.         }else
  359.         {
  360.          P.warpToSavePos();
  361.          P.set_PDV(1);
  362.         }
  363.        }
  364.        if(P.isOnline())
  365.        {
  366.         try
  367.         {
  368.          Thread.sleep(200);
  369.         }catch(Exception E){};
  370.         SocketManager.GAME_SEND_GV_PACKET(P);
  371.         P.refreshMapAfterFight();
  372.        }
  373.        //On le supprime de la team
  374.        if(_team0.containsKey(F.getGUID()))
  375.        {
  376.         F._cell.removeFighter(F);
  377.         _team0.remove(F.getGUID());
  378.        }
  379.        else if(_team1.containsKey(F.getGUID()))
  380.        {
  381.         F._cell.removeFighter(F);
  382.         _team1.remove(F.getGUID());
  383.        }
  384.        for(Personnage z : _mapOld.getPersos()) FightStateAddFlag(this._mapOld, z);
  385.       }
  386.      }
  387.     }else
  388.     {
  389.      if(ElinkEmu.CONFIG_DEBUG) GameServer.addToLog("Combat phase unmanaged, type of combat:"+_type+" T:"+T+" F:"+F);
  390.     }
  391.    break;
  392.    default:
  393.     if(ElinkEmu.CONFIG_DEBUG) GameServer.addToLog("Combat phase unmanaged, type of combat:"+_type+" T:"+T+" F:"+F);
  394.    break;
  395.   }
  396.  }else //If character is viewing the fight
  397.  {
  398.   SocketManager.GAME_SEND_GV_PACKET(perso);
  399.   _spec.remove(perso.get_GUID());
  400.   perso.setSitted(false);
  401.   perso.set_fight(null);
  402.   perso.set_away(false);
  403.  }
  404. }


 
And this is the code to verify if the player is still in the fight at the end of the fight..
 

Code :
  1. public boolean verifyStillInFight()//Return true if at least one player is still in combat
  2. {
  3.  for(Fighter f : _team0.values())
  4.  {
  5.   if(f.isPerco()) return true;
  6.   if(f.isInvocation()
  7.   || f.isDead()
  8.   || f.getPersonnage() == null
  9.   || f.getMob() != null
  10.   || f._double != null
  11.   || f.hasLeft())
  12.   {
  13.    continue;
  14.   }
  15.   if(f.getPersonnage() != null && f.getPersonnage().get_fight() != null
  16.     && f.getPersonnage().get_fight().get_id() == this.get_id()) //If it is not in this fight
  17.   {
  18.    return true;
  19.   }
  20.  }
  21.  for(Fighter f : _team1.values())
  22.  {
  23.   if(f.isPerco()) return true;
  24.   if(f.isInvocation()
  25.     || f.isDead()
  26.     || f.getPersonnage() == null
  27.     || f.getMob() != null
  28.     || f._double != null
  29.     || f.hasLeft())
  30.     {
  31.      continue;
  32.     }
  33.   if(f.getPersonnage() != null && f.getPersonnage().get_fight() != null
  34.     && f.getPersonnage().get_fight().get_id() == this.get_id()) //If it is not in this fight
  35.   {
  36.    return true;
  37.   }
  38.  }
  39.  return false;
  40. }

mood
Publicité
Posté le 12-03-2013 à 22:05:51  profilanswer
 

n°2180158
brisssou
8-/
Posté le 13-03-2013 à 10:16:13  profilanswer
 

si t'es français, hésite pas à parler français sur un forum français ;)

 

Sur ce, je retourne lire ton post.

 

edit: rectification, je ne lirais pas les 500 lignes de code que tu as postées. Tu pourrais pas réduire un peu tout ça ? où est le code utile ?


Message édité par brisssou le 13-03-2013 à 10:18:08

---------------
HFR - Mes sujets pour Chrome - Firefox - vérifie les nouveaux posts des topics suivis/favoris
n°2180166
willy le k​id
Posté le 13-03-2013 à 10:38:07  profilanswer
 

Je pense que il y a un cas que tu n'as pas prévu et ton joueur "passe au travers" en se retrouvant dans un état non prévu.
Hors de question que j'inspecte tout ce code d'autant plus que je ne connais pas le workflow des états du joueur.
La solution et de mettre des traces sur l'état du joueur dans tous les bouts d'algo qui modifient justement cet état / statut et ca devrait être simple.


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Java

  Exploit dans mon code

 

Sujets relatifs
Petit soucis avec code checkbox sur VBClasser communes sur une grille depuis Code Postal
[C] Aide pour comprendre un petit codeMacros C++ - Remplacement de la macro par le code final
Code Html pour une fonction multiplication (débutant)Mon petit bout de code est-il vulnérable aux injections ?
aide codecode mppt
[JAVASCRIPT] Que fait ce code ?Changer code php via un bouton (changer affichage Mosaique ou liste)
Plus de sujets relatifs à : Exploit dans mon code


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR