Permalink
Browse files

Login process

Big commit ahead!
- login screen is now working
- you can continue offline
- authorization now works properly
- the user is warned when accessing explore without being logged in
- the user gets a notification when browsing offline

Api still needs changes to adapt to the new flow but it should work. Still need to test extreme cases and common issues.
  • Loading branch information...
Manuel-777 committed Oct 11, 2018
1 parent ca4e8c8 commit 4387e1d58466957f6a585279ec0a0516b935470d
BIN +3.41 KB images/unlink.png
Binary file not shown.
BIN +8.87 KB images/unlink_big.png
Binary file not shown.
12 main.js
@@ -48,6 +48,18 @@ app.on('ready', () => {
overlay.webContents.send("set_settings", arg);
break;
case 'auth':
mainWindow.webContents.send("auth", arg);
break;
case 'login':
background.webContents.send("login", arg);
break;
case 'offline':
mainWindow.webContents.send("offline", arg);
break;
case 'set_status':
mainWindow.webContents.send("set_status", arg);
break;
@@ -3,7 +3,7 @@
"description": "An MTG Arena deck tracker and statistics manager.",
"author": "Manuel-777",
"repository": "https://github.com/Manuel-777/MTG-Arena-Tool",
"version": "2.1.8",
"version": "2.1.9",
"main": "main.js",
"build": {
"appId": "com.github.manuel777.mtgatool",
@@ -122,6 +122,11 @@ label {
top: -400%;
}
.signup_link {
color: rgb(220, 195, 150);
cursor: pointer;
}
@keyframes grow {
from {
transform: scale(0,1) translate(0, 0);
@@ -192,7 +197,7 @@ label {
position: relative;
opacity: 1;
display: flex;
height: calc(100% - 32px);
height: calc(100% - 97px);
z-index: 5;
}
/*
@@ -74,6 +74,8 @@ var duringMatch = false;
var matchBeginTime = 0;
var arenaVersion = '';
var playerPassword = '';
var username = ';'
var playerName = null;
var playerRank = null;
var playerTier = null;
@@ -144,6 +146,22 @@ ipc.on('set_renderer_state', function (event, arg) {
}
});
//
ipc.on('login', function (event, arg) {
playerPassword = arg.password;
if (arg.username == '' && arg.password == '') {
ipc_send("auth", {ok: true, user:-1});
loadPlayerConfig(playerId);
username = '';
logLoopMode = 1;
prevLogSize = 0;
}
else {
username = arg.username;
httpAuth(arg.username, arg.password);
}
});
//
ipc.on('windowBounds', function (event, obj) {
store.set('windowBounds', obj);
@@ -249,11 +267,18 @@ ipc.on('set_economy', function (event, arg) {
});
ipc.on('request_explore', function (event, arg) {
if (arg == "all" || arg == "All" ) {
arg = "";
if (username == '') {
ipc_send("offline", 1);
}
else {
if (arg == "all" || arg == "All" ) {
httpGetTopDecks("");
}
else {
arg = arg.replace("_m_", "_m19_");// dirty hack :(
httpGetTopDecks(arg);
}
}
arg = arg.replace("_m_", "_m19_");// dirty hack :(
httpGetTopDecks(arg);
});
ipc.on('request_course', function (event, arg) {
@@ -427,7 +452,7 @@ function logLoop() {
function readLog() {
//console.log("readLog()");
//ipc_send("ipc_log", "readLog()");
//ipc_send("ipc_log", "readLog("+logLoopMode+")");
if (!firstPass) {
ipc_send("log_read", 1);
}
@@ -507,9 +532,10 @@ function processLog(err, bytecount, buff) {
}
function processLogUser(err, bytecount, buff) {
// Process the log only to find player name and id
let rawString = buff.toString('utf-8', 0, bytecount);
var splitString = rawString.split('[UnityCrossThread');
console.log('Reading:', bytecount, 'bytes, ',splitString.length, ' chunks');
console.log('Reading user:', bytecount, 'bytes, ',splitString.length, ' chunks');
ipc_send("ipc_log", 'Reading: '+bytecount+' bytes, '+splitString.length+' chunks');
if (firstPass) {
@@ -537,6 +563,14 @@ function processLogUser(err, bytecount, buff) {
if (value.indexOf(strCheck) > -1) {
playerName = dataChop(value, strCheck, '"');
ipc_send("init_login", playerName);
ipc_send("ipc_log", 'Arena screen name: '+playerName);
}
// Get Client Version
strCheck = '"ClientVersion":"';
if (value.indexOf(strCheck) > -1) {
arenaVersion = dataChop(value, strCheck, '"');
ipc_send("ipc_log", 'Arena version: '+arenaVersion);
}
if (firstPass) {
@@ -699,7 +733,7 @@ function processLogData(data) {
}
// Get Client Version
strCheck = '"clientVersion":"';
strCheck = '"ClientVersion":"';
if (data.indexOf(strCheck) > -1) {
arenaVersion = dataChop(data, strCheck, '"');
}
@@ -733,8 +767,8 @@ function processLogData(data) {
strCheck = '==> Authenticate(';
if (data.indexOf(strCheck) > -1) {
httpAuth();
loadPlayerConfig(playerId);
//httpAuth();
//loadPlayerConfig(playerId);
return;
}
@@ -1167,15 +1201,15 @@ function gre_to_client(data) {
if (obj.selectedDamageRecipient !== undefined) {
var rec = obj.selectedDamageRecipient;
if (rec.type == "DamageRecType_Player") {
ipc_send("ipc_log", str+getNameBySeat(rec.playerSystemSeatId));
//ipc_send("ipc_log", str+getNameBySeat(rec.playerSystemSeatId));
}
//else if (rec.type == "") {
//}
}
if (obj.legalDamageRecipients !== undefined) {
var rec = obj.legalDamageRecipients.forEach(function(rec) {
if (rec.type == "DamageRecType_Player") {
ipc_send("ipc_log", str+getNameBySeat(rec.playerSystemSeatId));
//ipc_send("ipc_log", str+getNameBySeat(rec.playerSystemSeatId));
}
//else if (rec.type == "") {
//}
@@ -1204,12 +1238,12 @@ function gre_to_client(data) {
turnStorm = msg.gameStateMessage.turnInfo.stormCount;
if (prevTurn !== turnNumber) {
ipc_send("ipc_log", ">");
//ipc_send("ipc_log", ">");
if (playerSeat == turnActive) {
ipc_send("ipc_log", playerName+"'s turn begin. (#"+turnNumber+")");
//ipc_send("ipc_log", playerName+"'s turn begin. (#"+turnNumber+")");
}
else {
ipc_send("ipc_log", oppName+"'s turn begin. (#"+turnNumber+")");
//ipc_send("ipc_log", oppName+"'s turn begin. (#"+turnNumber+")");
}
}
if (!firstPass) {
@@ -1296,7 +1330,7 @@ function gre_to_client(data) {
}
else if (gameObjs[aff] !== undefined) {
//ipc_send("ipc_log", "("+gameObjs[aff].instanceId+") AnnotationType_ZoneTransfer - "+gameObjs[aff].name+" / zone: "+_dest+" - "+zones[_dest].type);
ipc_send("ipc_log", gameObjs[aff].name+" moved to "+zones[_dest].type);
//ipc_send("ipc_log", gameObjs[aff].name+" moved to "+zones[_dest].type);
gameObjs[aff].zoneId = _dest;
gameObjs[aff].zoneName = zones[_dest].type;
}
@@ -1335,10 +1369,10 @@ function gre_to_client(data) {
affected.forEach(function(affd) {
if (gameObjs[aff] !== undefined) {
if (affd == playerSeat || affd == oppSeat) {
ipc_send("ipc_log", gameObjs[aff].name+" dealt "+damage+" damage to "+getNameBySeat(affd));
//ipc_send("ipc_log", gameObjs[aff].name+" dealt "+damage+" damage to "+getNameBySeat(affd));
}
else {
ipc_send("ipc_log", gameObjs[aff].name+" dealt "+damage+" damage to "+gameObjs[affd]);
//ipc_send("ipc_log", gameObjs[aff].name+" dealt "+damage+" damage to "+gameObjs[affd]);
}
}
});
@@ -1742,7 +1776,7 @@ function httpBasic() {
if (_headers.method != 'auth') {
if (tokenAuth == undefined) {
callback({message: "Undefined token"});
removeFromHttp(_headers.reqId);
removeFromHttp(_headers.reqId);
_headers.token = "";
}
else {
@@ -1761,7 +1795,7 @@ function httpBasic() {
var options = { protocol: 'https:', port: 443, hostname: 'magicthegatheringarena.statuspage.io', path: '/index.json', method: 'GET'};
}
else {
var options = { protocol: 'https:', port: 443, hostname: serverAddress, path: '/apiv4.php', method: 'POST', headers: _headers };
var options = { protocol: 'https:', port: 443, hostname: serverAddress, path: '/api.php', method: 'POST', headers: _headers };
}
if (debugNet) {
@@ -1793,6 +1827,10 @@ function httpBasic() {
if (parsedResult.ok) {
if (_headers.method == 'auth') {
tokenAuth = parsedResult.token;
ipc_send("auth", parsedResult);
loadPlayerConfig(playerId);
logLoopMode = 1;
prevLogSize = 0;
}
if (_headers.method == 'get_top_decks') {
ipc_send("set_explore", parsedResult.result);
@@ -1808,6 +1846,9 @@ function httpBasic() {
ipc_send("set_db", parsedResult);
}
}
if (_headers.method == 'auth') {
ipc_send("auth", parsedResult);
}
if (_headers.method == 'get_picks') {
ipc_send("set_draft_picks", parsedResult);
}
@@ -1852,9 +1893,9 @@ function removeFromHttp(req) {
});
}
function httpAuth() {
function httpAuth(user, pass) {
var _id = makeId(6);
httpAsync.push({'reqId': _id, 'method': 'auth', 'uid': playerId, 'version': arenaVersion});
httpAsync.push({'reqId': _id, 'method': 'auth', 'username': user, 'password': pass, 'playerid': playerId, 'playername': playerName, 'mtgaversion': arenaVersion, 'version': window.electron.remote.app.getVersion()});
}
function httpSubmitCourse(_courseId, _course) {
@@ -79,6 +79,17 @@ span i {
background-size: contain;
}
.unlink {
-webkit-app-region: no-drag;
display: none;
background: url(../images/unlink.png) no-repeat center;
width: 24px;
height: 24px;
align-self: center;
position: relative;
margin-right: 16px;
}
.notification {
-webkit-app-region: no-drag;
display: none;
@@ -401,6 +412,14 @@ a:hover {
text-decoration: underline;
}
.message_unlink {
background-image: url("../images/unlink_big.png");
margin-bottom: 32px;
align-self: center;
width: 128px;
height: 128px;
}
.message_center {
position: absolute;
left: 0;
@@ -26,6 +26,7 @@
<div class="top_logo"></div>
</div>
<div class="flex_item">
<div class="unlink" title="You are not logged-in."></div>
<div class="notification"></div>
<div class="button minimize"></div>
<div class="button settings"></div>
@@ -80,17 +81,17 @@
<div class="authenticate">
<div class="message_big green">Welcome!</div>
<label style="display: table">Username</label>
<label style="display: table">Email</label>
<div class="input_login_container">
<input type="username" id="signin_user" autocomplete="off" />
</div>
<label style="display: table">Password</label>
<div class="input_login_container">
<input type="password" id="signin_pass" autocomplete="off" />
</div>
<div class="button_simple centered">Login</div>
<div class="button_simple centered login_link">Login</div>
<div class="message_small">Dont have an account? <a class="signup_link">Sign up!</a></div>
<div class="message_small">You can also <a>continue offline</a></div>
<div class="message_small">You can also <a class="offline_link">continue offline</a></div>
</div>
</div>
</div>
@@ -42,6 +42,7 @@ const chartjs = require('chart.js');
const Database = require('../shared/database.js');
const cardsDb = new Database();
const sha1 = require('js-sha1');
const fs = require("fs");
var mana = {0: "", 1: "white", 2: "blue", 3: "black", 4: "red", 5: "green", 6: "colorless", 7: "", 8: "x"}
@@ -63,6 +64,17 @@ process.on('uncaughtException', (err) => {
ipc_send("ipc_log", "Exception: "+err);
})
//
ipc.on('auth', function (event, arg) {
if (arg.ok) {
$('.message_center').css('display', 'block');
$('.authenticate').hide();
}
else {
pop(arg.error, -1);
}
});
//
ipc.on('set_db', function (event, arg) {
setsList = arg.sets;
@@ -337,6 +349,15 @@ ipc.on('no_log', function (event, arg) {
$('.message_center').html('<div class="message_big red">No Log Found</div><div class="message_sub_16 white">check if it exists at '+arg+'</div><div class="message_sub_16 white">if it does, try closing MTG Arena and deleting it.</div>');
});
//
ipc.on('offline', function (event, arg) {
document.body.style.cursor = "auto";
$('#ux_0').html('<div class="message_center" style="display: flex; position: fixed;"><div class="message_unlink"></div><div class="message_big red">Oops, you are offline!</div><div class="message_sub_16 white">You can <a class="signup_link">sign up</a> to access online features.</div></div>');
$(".signup_link").click(function() {
shell.openExternal('https://mtgatool.com/signup/');
});
});
//
ipc.on('log_read', function (event, arg) {
if ($('.top_nav').hasClass('hidden')) {
@@ -447,6 +468,17 @@ $(document).ready(function() {
shell.openExternal('https://mtgatool.com/signup/');
});
$(".offline_link").click(function() {
ipc_send("login", {username: '', password: ''});
$('.unlink').show();
});
$(".login_link").click(function() {
var user = document.getElementById("signin_user").value;
var pass = sha1(document.getElementById("signin_pass").value);
ipc_send("login", {username: user, password: pass});
});
//
$(".close").click(function () {
ipc_send('renderer_window_close', 1);
@@ -592,6 +624,7 @@ function setHistory(loadMore) {
var match = matchesHistory[match_id];
if (match == undefined) continue;
if (match.opponent == undefined) continue;
if (match.opponent.userid.indexOf("Familiar") !== -1) continue;
console.log("Load match: ", match_id, match);
console.log("Match: ", loadHistory, match.type, match);

0 comments on commit 4387e1d

Please sign in to comment.