Skip to content

Commit

Permalink
Display network connection error messages and fix networking on MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanballs committed Jan 24, 2020
1 parent 8d3c598 commit 43a94be
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
17 changes: 13 additions & 4 deletions source/networking/connection.d
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,19 @@ class Connection {
}

if (amountRead == Socket.ERROR) {
if (conn.getErrorText() == "Success") {
amountRead = 0;
} else {
throw new Exception("Socket Error: ", conn.getErrorText());
version(linux) {
if (conn.getErrorText() == "Success") {
amountRead = 0;
} else {
throw new Exception("Socket Error: ", conn.getErrorText());
}
}
version(OSX) {
if (conn.getErrorText() == "Undefined error: 0") {
amountRead = 0;
} else {
throw new Exception("Socket Error: ", conn.getErrorText());
}
}
}
recBuffer ~= cast(string) buffer[0..amountRead];
Expand Down
15 changes: 7 additions & 8 deletions source/networking/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,19 @@ private enum serverPort = 420_69;
// (p2p, client/server etc).

// TODO list
// - Exit when window closes - Notifying opponent.
// - Basically entire game logic
// - Validate that strings are valid UTF-8
// - Reconnection.
// - Could this be cleaner with fibers? The layout is not smooth
// - Could this be cleaner with fibers? The layout is not very clean and wont scale very well.

// Handles gamestate for a dice roll
// Document and clean this up please!
class DiceRoll {
bool goFirst;
private bool goFirst;
bool done;
Connection conn;
ulong mySeed;
string oppSeed;
string oppSeedHash;
private Connection conn;
private ulong mySeed;
private string oppSeed;
private string oppSeedHash;

this(Connection conn, bool goFirst) {
this.conn = conn;
Expand Down Expand Up @@ -244,6 +242,7 @@ class NetworkingThread {
}
}
} catch (Exception e) {
writeln("NETWORK THREAD EXCEPTION");
writeln(e);
send(ownerTid, NetworkThreadUnhandledException(e.msg, e.info.to!string));
}
Expand Down
9 changes: 9 additions & 0 deletions source/ui/networkwidget.d
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class NetworkWidget : Dialog {

Box inetBox;
HumanSelector inetHuman;
Label inetErrorMessage;
Button inetStartSearchButton;
Box inetStartSearchBox;
Label inetStartSearchLabel;
Expand Down Expand Up @@ -97,6 +98,11 @@ class NetworkWidget : Dialog {
});
inetStartSearchBox.setHalign(GtkAlign.CENTER);

// In case of any errors we'll put them here
inetErrorMessage = new Label("");
inetErrorMessage.setMarkup("<span foreground='red'>%s<\\span>");
inetBox.packEnd(inetErrorMessage, false, false, 0);

/**
* LAN
*/
Expand Down Expand Up @@ -134,6 +140,9 @@ class NetworkWidget : Dialog {
assert(ng.clientPlayer == Player.P2);
this.onCreateNewGame.emit(new GameState(opponent, player));
}
},
(NetworkThreadUnhandledException e) {
inetErrorMessage.setText(e.message);
}
);
return true;
Expand Down

0 comments on commit 43a94be

Please sign in to comment.