Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 2019.11.09 #9

Merged
merged 54 commits into from
Nov 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
1d0fed8
Bug fixed
LucBerge Mar 13, 2019
2084aa0
Disable automatic tests during Maven compilation
LucBerge Mar 14, 2019
e035d48
Now include jpcap in maven build and can generate an executable jar
LucBerge Mar 15, 2019
74e8efe
Add eclipse settings files
LucBerge Mar 15, 2019
181abe5
Convert to utf8
LucBerge Mar 15, 2019
aeaa663
Chat menu compatible with internationals servers
LucBerge Jun 5, 2019
a2a2109
Now use external property file
LucBerge Jun 5, 2019
7b0c2d5
Add java-string-similarity dependency
LucBerge Jun 5, 2019
a071c9d
Add Dofus singleton
Jul 19, 2019
5e94476
Add ProgramOptions class
LucBerge Oct 24, 2019
aaf4ea4
Now open a gitHub issues to report a bug
LucBerge Oct 24, 2019
f0322a3
Now use the @BeforeClass annotation
LucBerge Oct 24, 2019
47e7b3c
Fix encoding bug
LucBerge Oct 28, 2019
7d9c484
Renamed tests classes
LucBerge Oct 28, 2019
b325e05
Only throw B4DExceptions
LucBerge Oct 28, 2019
7d30b02
Automaticaly get the calling class
LucBerge Oct 28, 2019
bb3b638
Add Logger API tutorial
LucBerge Oct 28, 2019
3d1cb01
Add Logger API tutorial
LucBerge Oct 28, 2019
7e07382
Add Converter API tutorial
LucBerge Oct 28, 2019
137cd37
Renamed program
LucBerge Oct 28, 2019
9282179
Add Mouse API tutorial
LucBerge Oct 28, 2019
b931d66
Add Keyboard API tutorial
LucBerge Oct 28, 2019
6acc9b8
Add Screen API tutorial
LucBerge Oct 28, 2019
52f0911
Add comments for javadoc
LucBerge Oct 28, 2019
91c1440
Now generate the javadoc
LucBerge Oct 28, 2019
7b185b1
Add javadoc generated with maven
LucBerge Oct 28, 2019
c49cf63
Changed program arguments
LucBerge Oct 28, 2019
fbf6a73
Removed items
LucBerge Oct 28, 2019
f459f2f
Version 1.1
LucBerge Oct 28, 2019
1635ac2
Now use pcap4j
LucBerge Nov 3, 2019
10dc850
Add confirm dialog question
LucBerge Nov 3, 2019
be03070
Fix bug
LucBerge Nov 3, 2019
9e95215
Fix bug
LucBerge Nov 3, 2019
3d08173
Fix bug
LucBerge Nov 3, 2019
3a80edb
Now use pcap4j
LucBerge Nov 3, 2019
2838a3c
Add java doc
LucBerge Nov 3, 2019
0c8b2f3
New version format
LucBerge Nov 3, 2019
82de40b
Update README.md
LucBerge Nov 4, 2019
80686d3
Changed error message
LucBerge Nov 9, 2019
aca8c6d
Now ask for a pseudo
LucBerge Nov 9, 2019
3ae8209
New way to wait, allows interruption during waiting time
LucBerge Nov 9, 2019
edc0925
New way to wait
LucBerge Nov 9, 2019
e92bf1a
New test program
LucBerge Nov 9, 2019
7883baf
Removed TEST program from the list, changed log.
LucBerge Nov 9, 2019
0f16fdb
Changed place
LucBerge Nov 9, 2019
ffb6ccd
Add general channel
LucBerge Nov 9, 2019
a6bf1dc
Add unit tests
LucBerge Nov 9, 2019
2715b14
Changed bug report url
LucBerge Nov 9, 2019
6c775bc
Add button to propose a new program, a feature or a question
LucBerge Nov 9, 2019
2d30521
Add java doc
LucBerge Nov 9, 2019
89f6543
Generated java doc for version 2019-11-09
LucBerge Nov 9, 2019
b1b3ffa
Merge branch 'dev' of https://github.com/MrDomoo/B4D into dev
LucBerge Nov 9, 2019
c5db4bf
Generated javadoc for version 2019-11-09
LucBerge Nov 9, 2019
500838e
Removed X:Y label
LucBerge Nov 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Only throw B4DExceptions
  • Loading branch information
LucBerge committed Oct 28, 2019
commit b325e057bb69a1052190398a803d58545fde67aa
36 changes: 9 additions & 27 deletions src/main/java/fr/B4D/bot/B4DException.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,12 @@ public class B4DException extends Exception{

private static final long serialVersionUID = -2949855971863227080L;

private boolean canSendRepport;

/** Constructeur de l'exception {@code B4DException}.
* Aucun rapport d'erreur ne pourra être envoyé.
* Cela est identique à {@code B4DException(false)}.
*/
public B4DException() {
this(false);
}

/** Constructeur de l'exception {@code B4DException}.
* @param canSendRepport - {@code true} pour avoir la possibilité d'envoyer un rapport d'erreur, {@code false} sinon.
*/
public B4DException(boolean canSendRepport) {
super();
this.canSendRepport = canSendRepport;
}

/** Constructeur de l'exception {@code B4DException}.
Expand All @@ -30,24 +20,16 @@ public B4DException(boolean canSendRepport) {
* @param raison - Raison de l'exception.
*/
public B4DException(String raison)
{
this(raison, true);
}

/** Constructeur de l'exception {@code B4DException}.
* @param raison - Raison de l'exception.
* @param canSendRepport - {@code true} pour avoir la possibilité d'envoyer un rapport d'erreur, {@code false} sinon.
*/
public B4DException(String raison, boolean canSendRepport)
{
super(raison);
this.canSendRepport = canSendRepport;
}

/** Retourne un boolean représentant si un rapport d'erreur peut être envoyé.
* @return {@code true} si un rapport d'erreur peut être envoyé, {@code false} sinon.
*/
public boolean canSendRepport() {
return this.canSendRepport;
}

public B4DException(Throwable cause) {
super(cause);
}

public B4DException(String message, Throwable cause) {
super(message, cause);
}

}
27 changes: 16 additions & 11 deletions src/main/java/fr/B4D/bot/statics/Screen.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.ArrayList;

import fr.B4D.bot.B4D;
import fr.B4D.bot.B4DException;
import fr.B4D.bot.Configuration;
import fr.B4D.program.CancelProgramException;
import fr.B4D.program.StopProgramException;
Expand Down Expand Up @@ -154,33 +155,37 @@ public BufferedImage takeSreenshot() {
/** Permet de faire une reconnaissance optique de caractère sur une zone précise de l'écran.
* @param rectangle - Zone de l'écran.
* @return Chaine de caractère identifiée dans la zone, {@code null} si rien n'a été trouvé.
* @throws TesseractException Si impossible de réaliser l'OCR.
* @throws B4DException Si impossible de réaliser l'OCR.
*/
public String OCR(Rectangle rectangle) throws TesseractException {
BufferedImage image = takeSreenshot(rectangle);
Tesseract tessInst = new Tesseract();
tessInst.setLanguage("fra");
String out = tessInst.doOCR(image);
return out.replaceAll("\n", " ");
public String OCR(Rectangle rectangle) throws B4DException {
try {
BufferedImage image = takeSreenshot(rectangle);
Tesseract tessInst = new Tesseract();
tessInst.setLanguage("fra");
String out = tessInst.doOCR(image);
return out.replaceAll("\n", " ");
} catch (TesseractException e) {
throw new B4DException(e);
}
}

/** Permet de faire une reconnaissance optique de caractère sur une zone précise de l'écran.
* @param topLeftHandCorner - Point suppérieur gauche de la zone en coordonnées simples.
* @param bottomRightHandCorner - Point inférieur droit de la zone en coordonnées simples.
* @return Chaine de caractère identifiée dans la zone, {@code null} si rien n'a été trouvé.
* @throws TesseractException Si impossible de réaliser l'OCR.
* @throws B4DException Si impossible de réaliser l'OCR.
*/
public String OCR(Point topLeftHandCorner, Point bottomRightHandCorner) throws TesseractException {
public String OCR(Point topLeftHandCorner, Point bottomRightHandCorner) throws B4DException {
return OCR(new Rectangle(topLeftHandCorner.x, topLeftHandCorner.y, bottomRightHandCorner.x - topLeftHandCorner.x, bottomRightHandCorner.y - topLeftHandCorner.y));
}

/** Permet de faire une reconnaissance optique de caractère sur une zone précise de l'écran.
* @param topLeftHandCorner - Point suppérieur gauche de la zone en coordonnées relatives.
* @param bottomRightHandCorner - Point inférieur droit de la zone en coordonnées relatives.
* @return Chaine de caractère identifiée dans la zone, {@code null} si rien n'a été trouvé.
* @throws TesseractException Si impossible de réaliser l'OCR.
* @throws B4DException Si impossible de réaliser l'OCR.
*/
public String OCR(PointF topLeftHandCorner, PointF bottomRightHandCorner) throws TesseractException {
public String OCR(PointF topLeftHandCorner, PointF bottomRightHandCorner) throws B4DException {
return OCR(B4D.converter.toPoint(topLeftHandCorner), B4D.converter.toPoint(bottomRightHandCorner));
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/fr/B4D/interaction/Exchange.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import java.io.Serializable;

import fr.B4D.bot.B4D;
import fr.B4D.bot.B4DException;
import fr.B4D.interaction.chat.Message;
import fr.B4D.program.CancelProgramException;
import fr.B4D.program.StopProgramException;
import fr.B4D.utils.PointF;
import fr.B4D.utils.Rectangle;
import net.sourceforge.tess4j.TesseractException;

/** La classe {@code Exchange} représente un échange avec un joueur.<br><br>
* Un échange est défini par un nombre de kamas entrants et un nombre de kamas sortants.
Expand Down Expand Up @@ -120,9 +120,9 @@ public String waitForExchange(int timeout) throws StopProgramException, CancelPr
* @throws ExchangeCanceledException Si l'échange est annulé.
* @throws StopProgramException Si le programme est stoppé.
* @throws CancelProgramException Si le bot programme est annulé.
* @throws TesseractException Si un problème d'OCR survient.
* @throws B4DException Si un problème d'OCR survient.
*/
public BufferedImage exchange(String validationMessage) throws ExchangeCanceledException, TesseractException, StopProgramException, CancelProgramException {
public BufferedImage exchange(String validationMessage) throws ExchangeCanceledException, StopProgramException, CancelProgramException, B4DException {
B4D.logger.debug(this, "Début de l'échange");
Message message;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public class ExchangeCanceledException extends B4DException{
*/
public ExchangeCanceledException()
{
super("The exchange have been canceled.", false);
super("The exchange have been canceled.");
}
}
2 changes: 1 addition & 1 deletion src/main/java/fr/B4D/program/FullInventoryException.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public class FullInventoryException extends B4DException{
*/
public FullInventoryException()
{
super("Your inventory is full.", false);
super("Your inventory is full.");
}
}
16 changes: 6 additions & 10 deletions src/main/java/fr/B4D/program/Program.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package fr.B4D.program;

import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -18,7 +17,6 @@
import fr.B4D.programs.tutorials.ExchangeAPI;
import fr.B4D.programs.tutorials.MessageAPI;
import fr.B4D.programs.tutorials.TransportAPI;
import net.sourceforge.tess4j.TesseractException;

/** La classe {@code Program} représente un programme B4D.<br><br>
* Un programme est défini par un lieux, une catégorie, une sous catégorie, un nom et une sub-routine implémentant l'interface {@code ProgramInterface}.
Expand Down Expand Up @@ -149,7 +147,7 @@ public void start(Person person, ProgramOptions programOptions) {
} catch (CancelProgramException e) {
if(e.getMessage() != null)
B4D.logger.popUp(e.getMessage());
}catch(Exception e){
}catch(B4DException e){
B4D.logger.error(e);
}
}
Expand All @@ -167,9 +165,8 @@ public void start(Person person, ProgramOptions programOptions) {
* @throws StopProgramException Si le programme est stoppé.
* @throws CancelProgramException Si le bot programme est annulé.
* @throws B4DException Si une exception de type B4D est levée.
* @throws IOException Si un problème de fichier survient.
*/
private void intro(Person person, ProgramOptions programOptions) throws StopProgramException, CancelProgramException, B4DException, IOException {
private void intro(Person person, ProgramOptions programOptions) throws StopProgramException, CancelProgramException, B4DException {
Dofus.getInstance().getChat().clear();
if(this.category != Category.Test) {
B4D.screen.focusDofus();
Expand All @@ -196,10 +193,8 @@ private void intro(Person person, ProgramOptions programOptions) throws StopProg
* @throws StopProgramException Si le programme est stoppé.
* @throws CancelProgramException Si le bot programme est annulé.
* @throws B4DException Si une exception de type B4D est levée.
* @throws TesseractException Si une exception Tesseract est levée.
* @throws IOException Si un problème de fichier survient.
*/
private void cycle(Person person, ProgramOptions programOptions) throws B4DException, StopProgramException, CancelProgramException, TesseractException, IOException{
private void cycle(Person person, ProgramOptions programOptions) throws B4DException, StopProgramException, CancelProgramException {

int cycles = programOptions.getCycles();
int deposits = programOptions.getDeposits();
Expand Down Expand Up @@ -227,9 +222,10 @@ private void cycle(Person person, ProgramOptions programOptions) throws B4DExcep
/**Fonction de fin du programme. Celle-ci ne sera éxecutée qu'une seule fois en fin de programme.
* @param person - Personnage avec lequel lancer le programme.
* @param programOptions - Options de lancement du programme.
* @throws CancelProgramException
* @throws CancelProgramException Si le bot programme est annulé.
* @throws B4DException Si une exception de type B4D est levée.
*/
private void outro(Person person, ProgramOptions programOptions) throws CancelProgramException {
private void outro(Person person, ProgramOptions programOptions) throws CancelProgramException, B4DException {
program.outro(person);
B4D.logger.popUp("Le bot s'est correctement terminé.");
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/fr/B4D/program/ProgramInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import fr.B4D.bot.B4DException;
import fr.B4D.bot.Person;
import net.sourceforge.tess4j.TesseractException;

/** Interface représentant un programme et ses sub-routines.
*
Expand All @@ -23,9 +22,8 @@ public interface ProgramInterface{
* @throws CancelProgramException Si le programme est annulé.
* @throws B4DException Si une exception de type B4D est levée.
* @throws FullInventoryException Si l'inventaire est plein.
* @throws TesseractException Si une exception Tesseract est levée.
*/
public void cycle(Person person) throws StopProgramException, CancelProgramException, FullInventoryException, TesseractException, B4DException;
public void cycle(Person person) throws StopProgramException, CancelProgramException, FullInventoryException, B4DException;

/** Fonction de fin du programme. Celle-ci ne sera éxecutée qu'une seule fois en fin de programme.
* @param person - Personnage avec lequel lancer la fonction de fin.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fr/B4D/program/StopProgramException.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public class StopProgramException extends B4DException{
*/
public StopProgramException()
{
super("Program stoped", false);
super("Program stoped");
}
}
4 changes: 2 additions & 2 deletions src/main/java/fr/B4D/programs/Loto.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.google.api.services.drive.model.File;

import fr.B4D.bot.B4DException;
import fr.B4D.bot.Person;
import fr.B4D.google.GoogleDrive;
import fr.B4D.google.GoogleSheet;
Expand All @@ -33,7 +34,6 @@
import fr.B4D.program.ProgramInterface;
import fr.B4D.program.StopProgramException;
import fr.B4D.utils.ClosestString;
import net.sourceforge.tess4j.TesseractException;

public final class Loto {
private static final String CREDENTIALS = "loto.credentials";
Expand Down Expand Up @@ -154,7 +154,7 @@ public void intro(Person person) throws CancelProgramException {
}
}

public void cycle(Person person) throws TesseractException, StopProgramException, NumberFormatException, CancelProgramException {
public void cycle(Person person) throws StopProgramException, NumberFormatException, CancelProgramException, B4DException {
try {
Exchange exchange = new Exchange(Integer.parseInt(properties.getProperty(ticketPriceFieldName)), 0);
String name = exchange.waitForExchange();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/fr/B4D/programs/Test.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.B4D.programs;

import fr.B4D.bot.B4D;
import fr.B4D.bot.B4DException;
import fr.B4D.bot.Person;
import fr.B4D.program.CancelProgramException;
import fr.B4D.program.Category;
Expand All @@ -9,13 +10,12 @@
import fr.B4D.program.Program;
import fr.B4D.program.ProgramInterface;
import fr.B4D.program.StopProgramException;
import net.sourceforge.tess4j.TesseractException;

public final class Test {
public static ProgramInterface test = new ProgramInterface() {
public void intro(Person person) {}
public void outro(Person person) {}
public void cycle(Person person) throws FullInventoryException, TesseractException, StopProgramException, CancelProgramException {
public void cycle(Person person) throws FullInventoryException, StopProgramException, CancelProgramException, B4DException {
B4D.logger.popUp("Le programme de test marche correctement.");
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/fr/B4D/programs/tutorials/ExchangeAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.awt.Image;

import fr.B4D.bot.B4D;
import fr.B4D.bot.B4DException;
import fr.B4D.bot.Person;
import fr.B4D.interaction.Exchange;
import fr.B4D.interaction.ExchangeCanceledException;
Expand All @@ -14,7 +15,6 @@
import fr.B4D.program.Program;
import fr.B4D.program.ProgramInterface;
import fr.B4D.program.StopProgramException;
import net.sourceforge.tess4j.TesseractException;

public final class ExchangeAPI {

Expand All @@ -32,7 +32,7 @@ public final class ExchangeAPI {
public final static Program TUTORIAL1 = new Program(Place.Aucun, Category.Tutorial, "Exchange API", "Tutorial 1", new Channel[] {Channel.PRIVATE}, Status.AVAILABLE, new ProgramInterface() {
public void intro(Person person) {}
public void outro(Person person) {}
public void cycle(Person person) throws StopProgramException, CancelProgramException, TesseractException {
public void cycle(Person person) throws StopProgramException, CancelProgramException, B4DException {
Exchange exchange = new Exchange(100000,0);
String name = exchange.waitForExchange();
try {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/fr/B4D/socket/SocketListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public class SocketListener extends Thread{
public SocketListener() throws B4DException, CaptureDeviceOpenException{

if(System.getProperty("os.arch").contains("64"))
throw new B4DException("Vous exécutez le bot avec une version java 64-bit. Merci d'installer java 32-bit et recommencer.", false);
throw new B4DException("Vous exécutez le bot avec une version java 64-bit. Merci d'installer java 32-bit et recommencer.");

OperatingSystem os = OperatingSystem.getCurrent();
if(!os.libraryExists())
throw new B4DException("Impossible de trouver le fichier " + os.getLibrary() + ".", false);
throw new B4DException("Impossible de trouver le fichier " + os.getLibrary() + ".");

m_pcap = new PacketCapture();
network = os.findActiveDevice();
Expand Down Expand Up @@ -161,7 +161,7 @@ private int getHeaderLength(byte[] data) throws B4DException {
break;
}
if(length == -1)
throw new B4DException("Unknow socket type [" + HexHelper.toString(data) + "]", false);
throw new B4DException("Unknow socket type [" + HexHelper.toString(data) + "]");

return length;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fr/B4D/socket/os/Windows.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public String findActiveDevice() throws B4DException {
}

if(currentAddress == null)
throw new B4DException("Merci de vérifier votre connection internet.", false);
throw new B4DException("Merci de vérifier votre connection internet.");

for (String jpcapDevice : PacketCapture.lookupDevices()) {
NetworkDeviceInfo info = new NetworkDeviceInfo(jpcapDevice);
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/fr/B4D/bot/statics/ScreenTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import org.junit.Before;
import org.junit.Test;

import fr.B4D.bot.B4DException;
import fr.B4D.bot.Configuration;
import fr.B4D.dao.DAOFactory;
import fr.B4D.utils.Rectangle;
import net.sourceforge.tess4j.TesseractException;

public class ScreenTest {

Expand All @@ -23,7 +23,7 @@ public void before() throws ClassNotFoundException, IOException, AWTException {
}

@Test
public void test() throws AWTException, IOException, TesseractException {
public void test() throws B4DException {
String out = screen.OCR(new Rectangle(new Point(0,0), new Point(500,300)));
System.out.println(out);
}
Expand Down