aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--build/client.js48
-rw-r--r--build/server.js11
-rw-r--r--src/Types.hx4
-rw-r--r--src/client/Main.hx26
-rw-r--r--src/server/Main.hx7
5 files changed, 86 insertions, 10 deletions
diff --git a/build/client.js b/build/client.js
index 3c9515c..8d796a3 100644
--- a/build/client.js
+++ b/build/client.js
@@ -259,6 +259,25 @@ Std.__name__ = true;
Std.string = function(s) {
return js_Boot.__string_rec(s,"");
};
+Std.parseInt = function(x) {
+ if(x != null) {
+ var _g = 0;
+ var _g1 = x.length;
+ while(_g < _g1) {
+ var i = _g++;
+ var c = x.charCodeAt(i);
+ if(c <= 8 || c >= 14 && c != 32 && c != 45) {
+ var v = parseInt(x, (x[(i + 1)]=="x" || x[(i + 1)]=="X") ? 16 : 10);
+ if(isNaN(v)) {
+ return null;
+ } else {
+ return v;
+ }
+ }
+ }
+ }
+ return null;
+};
var StringTools = function() { };
StringTools.__name__ = true;
StringTools.startsWith = function(s,start) {
@@ -410,6 +429,7 @@ var client_Main = function(host,port) {
if(port == null) {
port = 4201;
}
+ this.matchNumbers = new EReg("^-?[0-9]+$","");
this.onTimeGet = new haxe_Timer(2000);
this.isConnected = false;
this.personal = new Client(null,null,"Unknown",0);
@@ -603,6 +623,9 @@ client_Main.prototype = {
this.player.pause();
}
break;
+ case "Rewind":
+ this.player.setTime(data.rewind.time);
+ break;
case "SetLeader":
ClientTools.setLeader(this.clients,data.setLeader.clientName);
this.updateUserList();
@@ -790,12 +813,18 @@ client_Main.prototype = {
nameDiv.className = "username";
nameDiv.innerHTML = name + ": ";
var textDiv = window.document.createElement("span");
- var _g = 0;
- var _g1 = this.filters;
- while(_g < _g1.length) {
- var filter = _g1[_g];
- ++_g;
- text = text.replace(filter.regex.r,filter.replace);
+ if(StringTools.startsWith(text,"/")) {
+ if(name == this.personal.name) {
+ this.handleCommands(HxOverrides.substr(text,1,null));
+ }
+ } else {
+ var _g = 0;
+ var _g1 = this.filters;
+ while(_g < _g1.length) {
+ var filter = _g1[_g];
+ ++_g;
+ text = text.replace(filter.regex.r,filter.replace);
+ }
}
textDiv.innerHTML = text;
var isInChatEnd = msgBuf.scrollHeight - msgBuf.scrollTop == msgBuf.clientHeight;
@@ -807,7 +836,7 @@ client_Main.prototype = {
while(msgBuf.children.length > 200) msgBuf.removeChild(msgBuf.firstChild);
msgBuf.scrollTop = msgBuf.scrollHeight;
}
- if(this.personal.name == name) {
+ if(name == this.personal.name) {
msgBuf.scrollTop = msgBuf.scrollHeight;
}
if(window.document.hidden && this.onBlinkTab == null) {
@@ -822,6 +851,11 @@ client_Main.prototype = {
this.onBlinkTab.run();
}
}
+ ,handleCommands: function(text) {
+ if(this.matchNumbers.match(text)) {
+ this.send({ type : "Rewind", rewind : { time : Std.parseInt(text)}});
+ }
+ }
,setLeaderButton: function(flag) {
var leaderBtn = window.document.querySelector("#leader_btn");
if((this.personal.group & 2) != 0) {
diff --git a/build/server.js b/build/server.js
index 6c35793..611ca9c 100644
--- a/build/server.js
+++ b/build/server.js
@@ -794,6 +794,17 @@ server_Main.prototype = {
}));
this.broadcast(data);
break;
+ case "Rewind":
+ if(this.videoList.length == 0) {
+ return;
+ }
+ data.rewind.time += this.videoTimer.getTime();
+ if(data.rewind.time < 0) {
+ data.rewind.time = 0;
+ }
+ this.videoTimer.setTime(data.rewind.time);
+ this.broadcast(data);
+ break;
case "SetLeader":
ClientTools.setLeader(this.clients,data.setLeader.clientName);
this.broadcast({ type : "SetLeader", setLeader : { clientName : data.setLeader.clientName}});
diff --git a/src/Types.hx b/src/Types.hx
index 8a0bde2..643fd4f 100644
--- a/src/Types.hx
+++ b/src/Types.hx
@@ -84,6 +84,9 @@ typedef WsEvent = {
?setTime:{
time:Float
},
+ ?rewind:{
+ time:Float
+ },
?setLeader:{
clientName:String
}
@@ -105,6 +108,7 @@ enum abstract WsEventType(String) {
var Play;
var GetTime;
var SetTime;
+ var Rewind;
var SetLeader;
var ClearChat;
}
diff --git a/src/client/Main.hx b/src/client/Main.hx
index f9232eb..dc5a803 100644
--- a/src/client/Main.hx
+++ b/src/client/Main.hx
@@ -201,6 +201,8 @@ class Main {
final time = player.getTime();
if (Math.abs(time - newTime) < 2) return;
player.setTime(newTime);
+ case Rewind:
+ player.setTime(data.rewind.time);
case SetLeader:
clients.setLeader(data.setLeader.clientName);
updateUserList();
@@ -366,8 +368,12 @@ class Main {
nameDiv.innerHTML = name + ": ";
final textDiv = document.createSpanElement();
- for (filter in filters) {
- text = filter.regex.replace(text, filter.replace);
+ if (text.startsWith("/")) {
+ if (name == personal.name) handleCommands(text.substr(1));
+ } else {
+ for (filter in filters) {
+ text = filter.regex.replace(text, filter.replace);
+ }
}
textDiv.innerHTML = text;
@@ -380,7 +386,7 @@ class Main {
while (msgBuf.children.length > 200) msgBuf.removeChild(msgBuf.firstChild);
msgBuf.scrollTop = msgBuf.scrollHeight;
}
- if (personal.name == name) {
+ if (name == personal.name) {
msgBuf.scrollTop = msgBuf.scrollHeight;
}
if (document.hidden && onBlinkTab == null) {
@@ -394,6 +400,20 @@ class Main {
}
}
+ final matchNumbers = ~/^-?[0-9]+$/;
+
+ function handleCommands(text:String):Void {
+ switch (text) {
+ case "clear":
+ if (isAdmin()) send({type: ClearChat});
+ }
+ if (matchNumbers.match(text)) {
+ send({type: Rewind, rewind: {
+ time: Std.parseInt(text)
+ }});
+ }
+ }
+
function setLeaderButton(flag:Bool):Void {
final leaderBtn = ge("#leader_btn");
if (isLeader()) {
diff --git a/src/server/Main.hx b/src/server/Main.hx
index 45be2af..cdf6924 100644
--- a/src/server/Main.hx
+++ b/src/server/Main.hx
@@ -219,6 +219,13 @@ class Main {
if (!client.isLeader) return;
videoTimer.setTime(data.setTime.time);
broadcastExcept(client, data);
+ case Rewind:
+ if (videoList.length == 0) return;
+ // TODO permission
+ data.rewind.time += videoTimer.getTime();
+ if (data.rewind.time < 0) data.rewind.time = 0;
+ videoTimer.setTime(data.rewind.time);
+ broadcast(data);
case SetLeader:
clients.setLeader(data.setLeader.clientName);
broadcast({
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage