Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 29 additions & 0 deletions login/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<noscript>To play CardShifter, please either enable JavaScript or use a JavaScript-enabled browser.</noscript>
<form name = "login_information">
Server:
<select name = "server">
<option value = "127.0.0.1">Local host</option>
<option value = "dwarftowers.com">dwarftowers.com</option>
<option value = "other">Other...</option>
</select>
<br/>
<div id = "server_other">
Other Server:
<input name = "server_other" type = "text"/>
<br/>
</div>
Username:
<input name = "username" type = "text" placeholder = "John Smith" />
<br/>
Is secure server:
<input name = "secure" type = "checkbox"/>
<br/>
<input name = "submit" type = "button" value = "Log in" />
</form>
</body>
</html>
28 changes: 28 additions & 0 deletions login/login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(function(window, undefined) {
var login_information = document.login_information;

var server = login_information.server;
var serverOther = login_information.server_other;
var serverOtherContainer = document.getElementById("server_other");
var username = login_information.username;
var isSecure = login_information.secure;
var submit = login_information.submit;
var isOther = false;

submit.onclick = function() {
var finalServer = (isOther ? serverOther.value : server.value);
console.log(finalServer);
}

server.onclick = function() {
console.log(this.value);
if(this.value === "other") {
serverOtherContainer.style.display = "block";
isOther = true;
} else {
serverOtherContainer.style.display = "none";
isOther = false;
}
}

})(Function("return this")());
90 changes: 90 additions & 0 deletions server_interface/server_interface.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
(function(window, undefined) {
function Message(command) {
this.command = command;
}
window.CardshifterServerAPI = {
socket: null,
messageTypes: {
LoginMessage: function(username) {
this.username = username;
},
RequestTargetsMessage: function(gameId, id, action) {
this.gamdId = gameId;
this.id = id;
this.action = action;
},
ServerQueryMessage: function(request, message) {
this.request = request;
this.message = message;

this.toString = function() {
return "ServerQueryMessage: Request" + this.request + " message: " + this.message;
};
},
StartGameRequest: function(opponent, gameType) {
this.opponent = opponent;
this.gameType = gameType;
},
TransformerMessage: function(type) {
this.type = type;
},
UseAbilityMessage: function(gameId, id, action, targets) {
this.gameId = gameId;
this.id = id;
this.action = action;
this.targets = targets;

this.toString = function() {
return "UseAbilityMessage [id=" + this.id + ", action=" + this.action + ", gameId=" + this.gameId + ", targets=" + this.targets.toString() + "]";
};
},
ChatMessage: function(chatId, from, message) {
this.chatId = chatId;
this.from = from;
this.message = message;

this.toString = function() {
return "ChatMessage [chatId=" + chatId + ", message=" + message + ", from=" + from + "]";
};
},
InviteRequest: function(id, name, gameType) {
this.id = id;
this.name = name;
this.gameType = gameType;
},
InviteResponse: function(inviteId, accepted) {
this.inviteId = inviteId;
this.accepted = accepted;
},
PlayerConfigMessage: function(gameId, modName, configs) {
this.gameId = gameId;
this.modName = modName;
this.configs = configs;

this.toString = function() {
return "PlayerConfigMessage{ configs=" + configs + ", gameId=" + gameId + ", modName='" + modName + '\'' + '}';
};
}
},
init: function(server, isSecure) {
var types = this.types;

types.LoginMessage.prototype = new Message("login");
types.RequestTargetsMessage.prototype = new Message("requestTargets");
types.ServerQueryMessage.prototype = new Message("query");
types.StartGameRequest.prototype = new Message("startgame");
types.TransformerMessage.prototype = new Message("serial");
types.UseAbilityMessage.prototype = new Message("use");
types.ChatMessage.prototype = new Message("chat");
types.InviteRequest.prototype = new Message("inviteRequest");
types.InviteResponse.prototype = new Message("inviteResponse");
types.PlayerConfigMessage = new Message("playerconfig");

var socket = new WebSocket("ws" + (isSecure ? "s" : "") + "://" + server);
this.socket = socket;
},
sendMessage: function(message) {
this.socket.send(JSON.stringify(message));
}
};
})(Function("return this")());