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

Merge loftar latest changes #18

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ec123be
Add an argument time-factor for SOrthoCam.
dolda2000 Mar 5, 2021
f23ca55
Decode (and ignore) widget barriers.
dolda2000 Mar 5, 2021
6b7eed8
Make CheckBox for analogous to ICheckBox.
dolda2000 Mar 14, 2021
6f50564
Abstracted common checkbox functionality to a superclass.
dolda2000 Mar 14, 2021
4fe3055
Make gob-health more flexible with regards to its granularity.
dolda2000 Mar 22, 2021
61a3cb8
Allow the server to specify an error message on connections.
dolda2000 Mar 22, 2021
34346d7
Improved Utils.hexdump.
dolda2000 Mar 24, 2021
0721d27
Added TTOL encoding to Mesasage.addlist.
dolda2000 Mar 24, 2021
ac0a6d8
Keep a token ID around for the future potential case of multiple tokens.
dolda2000 Mar 24, 2021
d856a93
Use somewhat more reasonable token ID size.
dolda2000 Mar 25, 2021
0b9f252
Make AuthClient Closeable.
dolda2000 Mar 25, 2021
ba92b46
Added support for launcher-embedded token authentication.
dolda2000 Mar 25, 2021
3c24de4
Merge branch 'dev'
dolda2000 Mar 25, 2021
5a2bba4
Fixed inittoken loop bug.
dolda2000 Mar 25, 2021
4a2d281
Cleaned up Bootstrap slightly.
dolda2000 Mar 25, 2021
5724e11
Fixed inittoken looping when failing, too.
dolda2000 Mar 25, 2021
2fcf66c
Fix up token forgetting.
dolda2000 Mar 25, 2021
019f9db
Make manual token saving work properly when session connection fails.
dolda2000 Mar 25, 2021
335a7b8
Merge remote-tracking branch 'github-main/master' into p-master
ProgrammerDan Mar 27, 2021
0f4c0c1
Fixing a java 9 and beyond regression. See github.com/apache/felix/pu…
ProgrammerDan Mar 27, 2021
d8a38aa
Meant to fix this before I committed, had a bad label in the AccountL…
ProgrammerDan Mar 27, 2021
e8e8a63
Fixing GobHealth. Loftar change gob health to float instead of int, f…
ProgrammerDan Mar 27, 2021
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
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
$size[14]{$u{Update for 27.03.21:}
* merged loftar's changes
* fixed a Java 9 regression around ByteBuffer -- see https://github.com/apache/felix/pull/114

$size[14]{$u{Update for 16.03.21:}
* fixed combat damage display not working

Expand Down
75 changes: 75 additions & 0 deletions src/haven/ACheckBox.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* This file is part of the Haven & Hearth game client.
* Copyright (C) 2009 Fredrik Tolf <[email protected]>, and
* Björn Johannessen <[email protected]>
*
* Redistribution and/or modification of this file is subject to the
* terms of the GNU Lesser General Public License, version 3, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Other parts of this source tree adhere to other copying
* rights. Please see the file `COPYING' in the root directory of the
* source tree for details.
*
* A copy the GNU Lesser General Public License is distributed along
* with the source tree of which this file is a part in the file
* `doc/LPGL-3'. If it is missing for any reason, please see the Free
* Software Foundation's website at <http://www.fsf.org/>, or write
* to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*/

package haven;

import java.util.function.*;

public abstract class ACheckBox extends Widget {
public boolean a = false;

public ACheckBox() {}
public ACheckBox(Coord sz) {super(sz);}

public Supplier<Boolean> state = () -> this.a;
public ACheckBox state(Supplier<Boolean> state) {this.state = state; return(this);}
public boolean state() {
return(state.get());
}

public Consumer<Boolean> changed = a -> {
if(canactivate)
wdgmsg("ch", a ? 1 : 0);
};
public ACheckBox changed(Consumer<Boolean> changed) {this.changed = changed; return(this);}
public void changed(boolean val) {changed.accept(val);}

public Consumer<Boolean> set = a -> {
if(this.a != a) {
this.a = a;
changed(a);
}
};
public ACheckBox set(Consumer<Boolean> set) {this.set = set; return(this);}
public void set(boolean a) {set.accept(a);}

public Runnable click = () -> set(!state());
public ACheckBox click(Runnable click) {this.click = click; return(this);}
public void click() {click.run();}

public boolean gkeytype(java.awt.event.KeyEvent ev) {
click();
return(true);
}

public void uimsg(String msg, Object... args) {
if(msg == "ch") {
this.a = ((Integer)args[0]) != 0;
} else {
super.uimsg(msg, args);
}
}
}
44 changes: 41 additions & 3 deletions src/haven/AuthClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.net.*;
import java.security.MessageDigest;

public class AuthClient {
public class AuthClient implements Closeable {
private static final SslHelper ssl;
private Socket sk;
private InputStream skin;
Expand Down Expand Up @@ -98,15 +98,51 @@ public byte[] getcookie() throws IOException {
}
}

public byte[] gettoken() throws IOException {
Message rpl = cmd("mktoken");
public static class TokenInfo {
public byte[] id = new byte[] {};
public String desc = "";

public TokenInfo id(byte[] id) {this.id = id; return(this);}
public TokenInfo desc(String desc) {this.desc = desc; return(this);}

public Object[] encode() {
Object[] ret = {};
if(this.id.length > 0)
ret = Utils.extend(ret, new Object[] {new Object[] {"id", this.id}});
if(this.desc.length() > 0)
ret = Utils.extend(ret, new Object[] {new Object[] {"desc", this.desc}});
return(ret);
}

public static TokenInfo forhost() {
TokenInfo ret = new TokenInfo();
if((ret.id = Utils.getprefb("token-id", ret.id)).length == 0) {
ret.id = new byte[16];
new java.security.SecureRandom().nextBytes(ret.id);
Utils.setprefb("token-id", ret.id);
}
if((ret.desc = Utils.getpref("token-desc", null)) == null) {
try {
ret.desc = InetAddress.getLocalHost().getHostName();
} catch(UnknownHostException e) {
}
}
return(ret);
}
}

public byte[] gettoken(TokenInfo info) throws IOException {
Message rpl = cmd("mktoken", info.encode());
String stat = rpl.string();
if(stat.equals("ok")) {
return(rpl.bytes(32));
} else {
throw(new RuntimeException("Unexpected reply `" + stat + "' from auth server"));
}
}
public byte[] gettoken() throws IOException {
return(gettoken(TokenInfo.forhost()));
}

public void close() throws IOException {
sk.close();
Expand All @@ -129,6 +165,8 @@ private void esendmsg(Object... args) throws IOException {
buf.addstring((String)arg);
} else if(arg instanceof byte[]) {
buf.addbytes((byte[])arg);
} else if(arg instanceof Object[]) {
buf.addlist((Object[])arg);
} else {
throw(new RuntimeException("Illegal argument to esendmsg: " + arg.getClass()));
}
Expand Down
Loading