Java API

For general discussion of the Poker Mavens software
Post Reply
Duration
Posts: 2
Joined: Sun Apr 18, 2021 5:56 am

Java API

Post by Duration »

Hello everyone,
Currently I have an ongoing project to integrateBbriggsoft Poker php api into a Java api.
This allows the integration of any java application to be able to send calls and operate the poker system from an administrator side. Personally I currently develop with java and I turned this into a hobby of mine. The code does not cover the entire Poker system but if everyone wants me to develop the entire thing I can do so. I started writing this a while ago and learned a lot since then. Version 2 will come out later but I hope that this will help people understand what is going on.
Also this code is more geared towards the project that I am currently working on. This was an API bridge between our game and the poker system it self. If you have any questions please let me know. I will release a more universal version in the future.

Code: Select all

package gamble_api;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Scanner;

public class gamble_get_commands {
	
	public static String pokerUrl = "URL";
	public static String pokerApiPassword = "Password";
	static String urlBuilder = "";
	public void setUrlBuilder() {
		urlBuilder = pokerUrl + "api?" + "Password=" + pokerApiPassword + "&Command=";
	}
	public void resetUrlBuilder() {
		urlBuilder = "";
	}
	public String getAccountInformationSystem(String pokerPlayerName,String argument) throws IOException {
		setUrlBuilder();
		urlBuilder = urlBuilder + "AccountsGet&Player="+ pokerPlayerName;
		URL url = new URL(urlBuilder);
		Scanner sc = new Scanner(url.openStream());
		while(sc.hasNext()) {
			String line = sc.next();
			if(line.contains(argument+"=")) {
				String[] splitReader = line.split("=");
				return splitReader[1];
			}
		}
		resetUrlBuilder();
		return "";
	}
	public boolean apiAccountCheckerSystem(String AccountName) throws IOException {
		AccountName = AccountName.toLowerCase();
		setUrlBuilder();
		urlBuilder = urlBuilder + "AccountsList&Fields=Player";
		URL url = new URL(urlBuilder);
		Scanner sc = new Scanner(url.openStream());
		while(sc.hasNext()) {
			String line = sc.next();
			String[] splitReader = line.split("=");
			splitReader[1] = splitReader[1].toLowerCase();
			if(splitReader[1].equals(AccountName)) {
				return true;
			}
		}
		return false;
	}
	public double apiDepositSystem(String PlayerName, int amount) throws IOException {
			PlayerName = PlayerName.toLowerCase();
			setUrlBuilder();
			urlBuilder = urlBuilder + "AccountsIncBalance&Player="+PlayerName+"&Amount="+amount;
			URL url = new URL(urlBuilder);
			Scanner sc = new Scanner(url.openStream());
			while(sc.hasNext()) {
				String line = sc.next();
				if(line.contains("Balance=")) {
					String[] splitReader = line.split("=");
					double bal = Double.parseDouble(splitReader[1]);
					return bal;
				}
			}
			return -403;
	}
	public double apiAccountCreate(String PlayerName, String Password) throws IOException {
		setUrlBuilder();
		String email = "";
		int randomEmail = (int) (Math.random()*10000);
		email = String.valueOf(randomEmail)+"@envisionps.net";
		urlBuilder = urlBuilder +"AccountsAdd&Player="+PlayerName+"&Location=poto&Email="+email+"&PW="+Password;
		URL url = new URL(urlBuilder);
		Scanner sc = new Scanner(url.openStream());
		while(sc.hasNext()) {
			System.out.println("[POKER API][AcountCreation]"+sc.next());
			return -6;
		}
		return -7;
	}
	public double apiWithDrawSystem(String PlayerName, int amount) throws IOException {
			setUrlBuilder();
			PlayerName = PlayerName.toLowerCase();
			String line = getAccountInformationSystem(PlayerName, "Balance");
			setUrlBuilder();
			double bal = Double.parseDouble(line);
			if(bal>amount) {
				urlBuilder = urlBuilder + "AccountsDecBalance&Player="+PlayerName+"&Amount="+amount;
				URL url = new URL(urlBuilder);
				Scanner sc = new Scanner(url.openStream());
				while(sc.hasNext()) {
					String line2 = getAccountInformationSystem(PlayerName,"Balance");
					double bal2 = Double.parseDouble(line);
					return bal2;
				}
				return -4;
			}else {
				return -1;
			}
	}
	public double apiBalance(String PlayerName) throws IOException {
			String line = getAccountInformationSystem(PlayerName,"Balance");
			double bal = Double.parseDouble(line);
			return bal;
	}
	public double apiDeposit(String PlayerName, int amount) throws NumberFormatException, IOException {
		return apiDepositSystem(PlayerName, amount);
	}
	public double apiWithdraw(String PlayerName, int amount) throws IOException {
		return apiWithDrawSystem(PlayerName, amount);
	}
	public double apiBridge(String PlayerName,int a, int amount, String password) {
		if(!apiStatus(pokerUrl)) {
			System.out.println("[POKER API] System Offline");
			return -404;
		}
		if(PlayerName.length()>=13) {
			System.out.println("[POKER API] Username To Long for the API");
			return -3;
		}
		if(PlayerName.length()<=3) {
			PlayerName = PlayerName + "--";
			System.out.println("[POKER API] User" + PlayerName +"Converted");
		}
		try {
			if(!apiAccountCheckerSystem(PlayerName)) {
				System.out.println("[POKER API][apiAccountCheck] Username Not Found");
				System.out.println("[POKER API][apiAccountCheck] Creating user account");
				apiAccountCreate(PlayerName,password);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			return apiControler( PlayerName, a, amount);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return 0;
	}
	public static boolean apiStatus(String URLName) {
	    try {
	        HttpURLConnection.setFollowRedirects(false);
	        HttpURLConnection con = (HttpURLConnection) new URL(URLName).openConnection();
	        con.setConnectTimeout(1000);
	        con.setReadTimeout(1000);
	        con.setRequestMethod("HEAD");
	        return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
	    } catch (Exception e) {
	       // e.printStackTrace();
	        return false;
	    }
	}
	/*
	 -1 = Cant withdraw more then you have
	 -2 = Cant deposit 0
	 -404 = poker client is offline
	 -3 = Username invalid
	 -4 = error getting balance
	 -5 = account creation errror
	 -6 = account created
	 -7 = account creation error
	 -8 = Invalid switch
	 */
	public double apiControler(String PlayerName,int a, int amount) throws IOException {
		switch(a) {
		case 0:return apiBalance(PlayerName);
		case 1:return apiDeposit(PlayerName, amount);
		case 2:return apiWithdraw(PlayerName, amount);
		}
		return -8;
	}
	   public static void main(String args[]) throws IOException {
		   gamble_get_commands object = new gamble_get_commands();
	System.out.println(object.apiBridge("rhandy11",1, 5000000, "Potato"));
	   }
	
}
Post Reply