Skip to content

Commit

Permalink
Use Nancy.Owin if possible.
Browse files Browse the repository at this point in the history
Move resource files into Asset directory.
Add GameLogModule which serves game logs using WebSocket (Requires Windows 8+). (This feature is WIP.)
Referenced assemblies are moved into "libraries" directory after build.
Remove unused Util class.
  • Loading branch information
RainbowMage committed Apr 3, 2015
1 parent f4be06d commit eee0ff7
Show file tree
Hide file tree
Showing 43 changed files with 1,846 additions and 302 deletions.
72 changes: 72 additions & 0 deletions Assets/gamelog-test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<title>Nancy + Owin WebSocket Test</title>
<style>
body::-webkit-scrollbar {
display: none;
}
html::-webkit-scrollbar {
display: none;
}
#container::-webkit-scrollbar {
display: none;
}
* { font-size: 0.8em; }
html, body { height: 100%; margin: 0; padding: 0; overflow: hidden; }
#container { height: 100%; display: flex; flex-flow: column; }
#header { flex: 0 0 auto; }
#output { flex: 0 1 auto; overflow: scroll; }
#output p { line-height: 80%; }
</style>
</head>
<body style=" max-height: 100%;">
<script>
//var wsUri = "ws://echo.websocket.org/";
var wsUri = "ws://localhost:23456/websocket/log";
var output, websocket;
function init() {
output = document.getElementById("output");
testWebSocket();
}
function testWebSocket() {
websocket = new WebSocket(wsUri);
websocket.onopen = function (evt) { onOpen(evt); };
websocket.onclose = function (evt) { onClose(evt); };
websocket.onmessage = function (evt) { onMessage(evt); };
websocket.onerror = function (evt) { onError(evt); };
}
function onOpen(evt) {
writeToScreen("CONNECTED");
}
function onClose(evt) {
writeToScreen("DISCONNECTED");
}
function onMessage(evt) {
writeToScreen('<span style="color: blue;">LOG: ' + evt.data + '</span>');
}
function onError(evt) {
writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);
}
function doSend(message) {
writeToScreen("SENT: " + message);
websocket.send(message);
}
function writeToScreen(message) {
var pre = document.createElement("p");
pre.style.wordWrap = "break-word";
pre.innerHTML = message;
output.appendChild(pre);
output.scrollTop = output.scrollHeight;
}
window.addEventListener("load", init, false);
</script>
<div id="container" style="overflow:scroll;">
<div id="header">
<h1>Log receiving test</h2>
<button onclick="output.innerHTML = ''">Clear</button>
</div>
<div id="output" style=""></div>
</div>
</body>
</html>
13 changes: 13 additions & 0 deletions Assets/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>ActServer</title>
</head>
<body>
<h1>ActServer</h1>

Copyright &copy; RainbowMage 2015.
</body>
</html>
38 changes: 19 additions & 19 deletions Source/ActServer/resources/actserver.js → Assets/js/actserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
* @param message {String} [Required] Message to unicast.
* @returns {XMLHttpRequest}
*/
sendMessage: function (server, to, message) {
sendMessage: function (server, to, body) {
if (!server) {
throw "'server' is undefined."
throw "'server' is undefined.";
}
if (!to) {
throw "'to' is undefined."
throw "'to' is undefined.";
}
if (!message) {
throw "'message' is undefined."
if (!body) {
throw "'body' is undefined.";
}
if (server.charAt(server.length - 1) != "/") {
server += "/";
Expand All @@ -23,9 +23,9 @@
"action": "sendMessage",
"from": "sender",
"to": to,
"message": message
"body": body
};
return $.getJSON(server + "message/send", query, function (json) {
return $.getJSON(server + "command/message/send", query, function (json) {
if (json.isError) {
console.log(json.message);
}
Expand All @@ -37,22 +37,22 @@
* @param message {String} [Required] Message to broadcast.
* @returns {XMLHttpRequest}
*/
broadcastMessage: function (server, message) {
broadcastMessage: function (server, body) {
if (!server) {
throw "'server' is undefined."
throw "'server' is undefined.";
}
if (!message) {
throw "'message' is undefined."
if (!body) {
throw "'body' is undefined.";
}
if (server.charAt(server.length - 1) != "/") {
server += "/";
}
var query = {
"action": "broadcastMessage",
"from": "sender",
"message": message
"body": body
};
return $.getJSON(server + "message/send", query, function (json) {
return $.getJSON(server + "command/message/send", query, function (json) {
if (json.isError) {
console.log(json.message);
}
Expand Down Expand Up @@ -81,13 +81,13 @@

_pollMessage: function(param, controller) {
if (!param) {
throw "'param' is undefined."
throw "'param' is undefined.";
}
if (!param.server) {
throw "'server' is not specified.";
}
if (!param.name) {
throw "'name' is not specified."
throw "'name' is not specified.";
}

if (param.server.charAt(param.server.length - 1) != "/") {
Expand All @@ -98,7 +98,7 @@
var _this = this;
$.ajax({
dataType: "json",
url: param.server + "message/receive",
url: param.server + "command/message/receive",
data: {
"action": "requestMessage",
"name": param.name,
Expand Down Expand Up @@ -156,13 +156,13 @@
if (!controller._stopped) {

if (!param) {
throw "'param' is undefined."
throw "'param' is undefined.";
}
if (!param.server) {
throw "'server' is not specified.";
}
if (!param.module) {
throw "'module' is not specified."
throw "'module' is not specified.";
}

var data = {
Expand All @@ -180,7 +180,7 @@
var _this = this;
$.ajax({
dataType: "json",
url: param.server + param.module,
url: param.server + "command/" + param.module,
timeout: param.timeout ? param.timeout : 60000,
"data": data,
success: function (json) {
Expand Down
File renamed without changes.
82 changes: 82 additions & 0 deletions Assets/messaging-websocket-test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<title>Nancy + Owin WebSocket Test</title>
<style>
body::-webkit-scrollbar {
display: none;
}
html::-webkit-scrollbar {
display: none;
}
#container::-webkit-scrollbar {
display: none;
}
* { font-size: 0.8em; }
html, body { height: 100%; margin: 0; padding: 0; overflow: hidden; }
#container { height: 100%; display: flex; flex-flow: column; }
#header { flex: 0 0 auto; }
#output { flex: 0 1 auto; overflow: scroll; }
#output p { line-height: 80%; }
</style>
</head>
<body style=" max-height: 100%;">
<script src="js/jquery-2.1.1.min.js" type="text/javascript"></script>
<script>
//var wsUri = "ws://echo.websocket.org/";
var wsUri = "ws://localhost:23456/websocket/message" + "?name=messaging-websocket-test";
var output, websocket;
function init() {
output = document.getElementById("output");
testWebSocket();
}
function testWebSocket() {
websocket = new WebSocket(wsUri);
websocket.onopen = function (evt) { onOpen(evt); };
websocket.onclose = function (evt) { onClose(evt); };
websocket.onmessage = function (evt) { onMessage(evt); };
websocket.onerror = function (evt) { onError(evt); };
}
function onOpen(evt) {
writeToScreen("CONNECTED");
doSend("hello");
}
function onClose(evt) {
writeToScreen("DISCONNECTED");
}
function onMessage(evt) {
try
{
var message = $.parseJSON(evt.data);
writeToScreen('<span style="color: blue;">MESSAGE: from: ' + message.from + ", body:" + message.body + '</span>');
}
catch (e)
{
console.log(evt.data);
}
}
function onError(evt) {
writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);
}
function doSend(message) {
writeToScreen("SENT: " + message);
websocket.send('{ "from": "messaging-websocket-test", "body": "hello" }');
}
function writeToScreen(message) {
var pre = document.createElement("p");
pre.style.wordWrap = "break-word";
pre.innerHTML = message;
output.appendChild(pre);
output.scrollTop = output.scrollHeight;
}
window.addEventListener("load", init, false);
</script>
<div id="container" style="overflow:scroll;">
<div id="header">
<h1>Messaging test</h2>
<button onclick="doSend('hello')">Send</button>
</div>
<div id="output" style=""></div>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<head>
<meta charset="utf-8" />
<title></title>
<script src="jquery-2.1.1.min.js" type="text/javascript"></script>
<script src="actserver.js" type="text/javascript"></script>
<script src="js/jquery-2.1.1.min.js" type="text/javascript"></script>
<script src="js/actserver.js" type="text/javascript"></script>
<script>
var server = "http://localhost:23456/";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
}

</style>
<script src="jquery-2.1.1.min.js" type="text/javascript"></script>
<script src="actserver.js" type="text/javascript"></script>
<script src="js/jquery-2.1.1.min.js" type="text/javascript"></script>
<script src="js/actserver.js" type="text/javascript"></script>
<script>

//
Expand Down Expand Up @@ -154,18 +154,17 @@
$(document).ready(function () {

var server = "http://localhost:23456/";
var dataType = "RainbowMage.MiniParse";
var sortKey = "encdps";
var sortType = "NumericDescending";

var messageReceiver = ActServerApi.startReceiveMessage( {
"server": server,
"name": "miniparse",
"receive": function (data) {
if (data.message == "hide") {
if (data.body == "hide") {
$("#encounter").hide();
$("#combatantTable").hide();
} else if (data.message == "show") {
} else if (data.body == "show") {
$("#encounter").show();
$("#combatantTable").show();
}
Expand All @@ -180,7 +179,6 @@
var dataReceiver = ActServerApi.startReceiveData({
"server": server,
"module": "miniparse",
"dataType": dataType,
"data": {
"sortKey": sortKey,
"sortType": sortType
Expand Down
Loading

0 comments on commit eee0ff7

Please sign in to comment.