Skip to content
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.

Commit

Permalink
Merge 15cf836 into 871bef0
Browse files Browse the repository at this point in the history
  • Loading branch information
Meowvw committed Jan 30, 2015
2 parents 871bef0 + 15cf836 commit b17ecb9
Show file tree
Hide file tree
Showing 12 changed files with 275 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class ProgramHelperWindows extends ProgramHelper {
protected char[] processFileNameBuffer = new char[STRING_BUFFER_LENGTH * 2];
protected int[] lpdwSize = new int[]{STRING_BUFFER_LENGTH};


public ProgramHelperWindows() {
debugLog.debug("Initialising ProgramHelperWindows with {}", processName);
try {
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ tab.decks = Decks
tab.options = Options
tab.about = About
Author = Authors
LandingPanel.label.register = Register
LandingPanel.label.SignIn = Sign In
LandingPanel.label.password = Password:
LandingPanel.label.userId = User ID:
about.utility_l1 = This utility uses screen grab analysis of your Hearthstone window
about.utility_l2 = and does not do any packet sniffing, monitoring, or network
about.utility_l3 = modification of any kind.
Expand Down
51 changes: 37 additions & 14 deletions companion/src/main/scala/net/hearthstats/Main.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package net.hearthstats


import java.awt.Component
import java.io.File

import scala.util.control.NonFatal
import scala.util.{Success,Failure}

import com.softwaremill.macwire.MacwireMacros.wire
import com.softwaremill.macwire.Tagging.Tagging
Expand All @@ -17,13 +19,14 @@ import net.hearthstats.game.{ HearthstoneLogMonitor, LogParser, MatchState }
import net.hearthstats.game.imageanalysis.{ IndividualPixelAnalyser, LobbyAnalyser, ScreenAnalyser }
import net.hearthstats.hstatsapi.{ API, CardUtils, DeckUtils, MatchUtils }
import net.hearthstats.modules.{ FileUploaderFactory, ReplayHandler, VideoEncoderFactory }
import net.hearthstats.ui.{ CompanionFrame, ExportDeckBox, MatchEndPopup }
import net.hearthstats.ui.{ CompanionFrame,LandingFrame,ExportDeckBox, MatchEndPopup }
import net.hearthstats.ui.deckoverlay._
import net.hearthstats.ui.log.Log
import net.hearthstats.ui.notification.DialogNotification
import net.hearthstats.util.{ AnalyticsTrackerFactory, FileObserver, Translation, TranslationConfig, Updater }
import net.sourceforge.tess4j.Tesseract


class Main(
environment: Environment,
config: UserConfig,
Expand Down Expand Up @@ -72,23 +75,43 @@ class Main(
val companionEvents = wire[ScreenEvents]
val exportDeckBox = wire[ExportDeckBox]
val mainFrame: CompanionFrame = wire[CompanionFrame]
val landingFrame: LandingFrame = wire[LandingFrame]
val replayHandler = wire[ReplayHandler]
val startup: Startup = wire[Startup]
val matchUtils = wire[MatchUtils]

val matchUtils: MatchUtils = wire[MatchUtils]


val monitor: GameMonitor = wire[GameMonitor]

def start(): Unit = {
val loadingNotification = new DialogNotification("HearthStats Companion", "Loading ...")
loadingNotification.show()
logSystemInformation()
updater.cleanUp()
cleanupDebugFiles()
mainFrame.createAndShowGui()
loadingNotification.close()
programHelper.createConfig(environment, uiLog)
startup.start()
monitor.start()
config.closedLandingPage.set(false)
landingFrame.createLandingPage()
config.quitLoadingMainFrame.set(false)
val userKeySet = config.userKey.get



while(!config.quitLoadingMainFrame.get){
if(config.closedLandingPage){
mainFrame.decksTab.updateDecks()
landingFrame.dispose()
val password = config.password.get
println("password" + password)
val loadingNotification = new DialogNotification("HearthStats Companion", "Loading ...")
loadingNotification.show()
logSystemInformation()
updater.cleanUp()
cleanupDebugFiles()

mainFrame.createAndShowGui()
loadingNotification.close()
programHelper.createConfig(environment, uiLog)
startup.start()
monitor.start()
config.quitLoadingMainFrame.set(true)
}

}
}

private def logSystemInformation(): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class UserConfig extends Logging with Implicits {

//public options, can be exposed via OptionsTab
val userKey = config("api.userkey", "your_userkey_here")
val auth_token = config("api.auth_token","your_auth_token_here")
val email = config("api.email","your_email_here")
val password = config("api.password","you_password_here")
val userName = config("hearthstone.login", "")
val gameLogFile = config("hearthstone.gameLogFile", "")

Expand All @@ -40,14 +43,18 @@ class UserConfig extends Logging with Implicits {
val videoHeight = config("video.fps", 2000)

val uploadVideo = config("video.upload", true)

val closedLandingPage = config("landingFrame.closed",false)
val quitLoadingMainFrame = config("mainFrame.loading",false)

val gameLanguage = enumConfig("option.gamelanguage", SupportedGameLanguage.EN)
/** Translation for the cards of the game, based on the language option for the game.*/
//TODO : how to cache this when the gameLanguage has not changed
def gameCardsTranslation = new Translation(TranslationConfig("net.hearthstats.resources.card.Card", gameLanguage.get.toString))

//private options, no need to be displayed
val apiBaseUrl = "http://hearthstats.net/api/v1/"
val apiBaseUrl = "http://192.237.249.9/api/v1/"
val apiBaseUrlV2 = "http://192.237.249.9/api/v2/"
val apiTimeoutMs = 15000

val awsBucket = "hearthstats"
Expand Down
69 changes: 68 additions & 1 deletion companion/src/main/scala/net/hearthstats/hstatsapi/API.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import net.hearthstats.core.{ ArenaRun, HearthstoneMatch }
import scala.collection.JavaConversions.{ asScalaBuffer, mapAsJavaMap }
import rapture.json._
import rapture.json.jsonBackends.jawn._
import rapture._
import scala.util._
import net.hearthstats.core.ArenaRun
import net.hearthstats.core.Card
Expand Down Expand Up @@ -69,6 +70,20 @@ class API(config: UserConfig) extends Logging {
data <- _parseResult(resString)
} yield data

def login(email:String, password:String): Boolean =
{
debug("post sent")
val result = postV2("users/sign_in",json"""{"user_login":{"email":$email,"password":$password}}""")
result match {
case Success(result) =>
Some(result.auth_token.as[String])
config.auth_token.set(result.auth_token.as[String])
config.userKey.set(result.userkey.as[String])
true
case Failure(e) =>
false
}
}
private def call(method: String): Try[String] = Try {
val inputStream = buildConnection(method).getInputStream
val resultString = io.Source.fromInputStream(inputStream)("UTF-8").getLines.mkString
Expand All @@ -87,25 +102,61 @@ class API(config: UserConfig) extends Logging {
conn.setReadTimeout(timeout)
conn.asInstanceOf[HttpURLConnection]
}

def buildConnectionToV2(method: String): HttpURLConnection = {
val baseUrlV2 = config.apiBaseUrlV2 + method
debug(s"API get $baseUrlV2********")
val timeout = config.apiTimeoutMs
val urlV2 = new URL(baseUrlV2)
val connV2 = urlV2.openConnection()
connV2.setConnectTimeout(timeout)
connV2.setReadTimeout(timeout)
connV2.asInstanceOf[HttpURLConnection]
}



private def _parseResult(resultString: String): Try[Json] = {
debug(s"parsing $resultString")
val result = Json.parse(resultString)
if (result.status.as[String] == "success") {
Success(result)

} else {
val message = result.message.as[String]
Failure(new Exception(s"API error : $message"))
}
}


private def _parseResultV2(resultString: String): Try[Json] = {
debug(s"parsing $resultString")
val result = Json.parse(resultString)
if (result.success.as[Boolean] == true) {
Success(result)
} else {
val message = result.message.as[String]
Failure(new Exception(s"API error: $message"))
}
}




private def post(method: String, jsonData: Json): Try[Json] = {
for {
resString <- _post(method, jsonData)
data <- _parseResult(resString)
} yield data
}


private def postV2(method: String, jsonData: Json): Try[Json] = {
for {
resString <- _postV2(method, jsonData)
data <- _parseResultV2(resString)
} yield data
}

private def _post(method: String, jsonData: Json): Try[String] = Try {
val httpcon = buildConnection(method)
httpcon.setDoOutput(true)
Expand All @@ -122,4 +173,20 @@ class API(config: UserConfig) extends Logging {
resultString
}

private def _postV2(method: String,jsonData: Json): Try[String] = Try{
val httpconV2 = buildConnectionToV2(method)
httpconV2.setDoOutput(true)
httpconV2.setRequestProperty("Content-Type", "application/json")
httpconV2.setRequestProperty("Accept", "application/json")
httpconV2.setRequestMethod("POST")
httpconV2.connect()
val outputBytes = jsonData.toString.getBytes("UTF-8")
val os = httpconV2.getOutputStream
os.write(outputBytes)
os.close()
val resultString = io.Source.fromInputStream(httpconV2.getInputStream).getLines.mkString("\n")
resultString

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ class CompanionFrame(val environment: Environment,
val aboutPanel: AboutPanel = wire[AboutPanel]
val matchPanel: MatchPanel = wire[MatchPanel]
val decksTab: DecksTab = wire[DecksTab]

def createAndShowGui() {
debug("Creating GUI")
//landingFrame.createAndShowGui()
val icon = new ImageIcon(getClass.getResource("/images/icon.png")).getImage
setIconImage(icon)
setLocation(windowX, windowY)
Expand All @@ -59,6 +60,7 @@ class CompanionFrame(val environment: Environment,
tabbedPane.add(decksTab, t("tab.decks"))
tabbedPane.add(optionsPanel, t("tab.options"))
tabbedPane.add(aboutPanel, t("tab.about"))

matchPanel.updateCurrentMatchUi()
enableMinimizeToTray()
setMinimumSize(new Dimension(500, 600))
Expand Down Expand Up @@ -107,6 +109,7 @@ class CompanionFrame(val environment: Environment,
def checkForUserKey(): Boolean = {
val userKeySet = !userKey.equalsIgnoreCase("your_userkey_here")
if (userKeySet) {
println("userkey checked, no entering")
true
} else {
uiLog.warn(t("error.userkey_not_entered"))
Expand Down

0 comments on commit b17ecb9

Please sign in to comment.