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

Commit

Permalink
Merge 5f30b35 into 871bef0
Browse files Browse the repository at this point in the history
  • Loading branch information
Meowvw committed Jan 30, 2015
2 parents 871bef0 + 5f30b35 commit 4a4b585
Show file tree
Hide file tree
Showing 12 changed files with 245 additions and 19 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
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
52 changes: 38 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,7 +19,7 @@ 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
Expand Down Expand Up @@ -72,23 +74,45 @@ 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
println("userkey before while loop = " + userKeySet)

while(!config.quitLoadingMainFrame.get){
val userKeySet = config.userKey.get
println("userkey in the while loop = " + userKeySet)
if(config.closedLandingPage){
mainFrame.decksTab.updateDecks()
landingFrame.dispose()
val userKeySet = config.userKey.get
println("userkey = " + userKeySet)
config.userKey.set(userKeySet)
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
121 changes: 121 additions & 0 deletions companion/src/main/scala/net/hearthstats/ui/LandingFrame.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package net.hearthstats.ui

import net.hearthstats.util.{Browse, Translation}
import net.hearthstats.hstatsapi.API
import net.hearthstats.ui.log.Log
import net.hearthstats.config.{Environment, UserConfig}
import net.hearthstats.ui.util.OptionTextField
import net.hearthstats.ui.util.StringOptionTextField
import net.hearthstats.ui.notification.NotificationQueue

import java.awt.event.{ ActionEvent, ActionListener }
import java.awt.{ Dimension, Font, Graphics, Color }
import java.io.File
import java.awt.image.BufferedImage
import javax.imageio.ImageIO
import javax.swing._
import net.miginfocom.swing.MigLayout


class LandingFrame(translation: Translation,
uilog: Log,
config: UserConfig,
api: API,
val notificationQueue: NotificationQueue,
val environment: Environment)extends JFrame{
import translation.t
import config._

private val signInButton = new JButton("Sign In")
private val registerButton = new JButton("Register")
private val registerUrl:String = "http://hearthstats.net/users/sign_up"


def createLandingPage(){
val icon = new ImageIcon(getClass.getResource("/images/icon.png")).getImage
val titleLabel = new JLabel("Hearthstats Uploader")
titleLabel.setFont(new Font("Ariel",Font.BOLD,24))
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE)
setIconImage(icon)
setLocation(windowX, windowY)
setSize(windowWidth, windowHeight)
setMinimumSize(new Dimension(500, 600))
setVisible(true)
updateTitle

setLayout(new MigLayout)
setBackground(Color.WHITE)

add(new JLabel(" "), "wrap")
add(new JLabel(new ImageIcon(ImageIO.read(getClass.getResource("/images/icon.png")))))

add(titleLabel, "wrap")
add(new JLabel(" "),"wrap")

//entering userID
add(new JLabel(t("LandingPanel.label.userId") + " "), "")
var userEmailField: JTextField = new StringOptionTextField(config.email)
add(userEmailField, "wrap")
config.email.set(userEmailField.getText())

//entering user Password
add(new JLabel(t("LandingPanel.label.password") + " "), "")
var passwordField: JTextField = new StringOptionTextField(config.password)
add(passwordField, "wrap")
config.password.set(passwordField.getText())


add(new JLabel(" "), "wrap")

//add a sign in button
signInButton.addActionListener(new ActionListener {
override def actionPerformed(arg0: ActionEvent) {
checkForPassword
}})
add(signInButton, "")

//add a register button
registerButton.addActionListener(new ActionListener {
override def actionPerformed(arg0: ActionEvent) {
Browse(registerUrl)
}})
add(registerButton, "")

//add a first time help link
val firstTimeHelpIcon = new HelpIcon("https://github.com/HearthStats/HearthStats.net-Uploader/wiki/Options:-Game-Language",
"First time tutorial")
add(firstTimeHelpIcon, "")
add(new JLabel(" "), "wrap")

}

//update title
def updateTitle
{
var title = "HearthStats Companion"
setTitle(title)
}

//close login page
def closeLandingPage
{
config.closedLandingPage.set(true)
}

//check if password and email matched
def checkForPassword{
try{
if (api.login(config.email.get, config.password.get)){
closeLandingPage
}
else{
add(new JLabel("Email or password is incorrect"))
println("invalid password or email")
}
}
catch{
case(e) => println("entered nothing")
}

}
}

0 comments on commit 4a4b585

Please sign in to comment.