-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientLogic.js
More file actions
executable file
·112 lines (99 loc) · 3.6 KB
/
ClientLogic.js
File metadata and controls
executable file
·112 lines (99 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
var logText, name, text, consoleOut, parsedCommand, commandArgs,userList;
var logUpdateMultiplier = 2;
var nameSelected = false;
var consoleSplash =
"#######################################################################################\n#######################################################################################\n## _ _ _ ##\n## | | ___ __ _ __ _ _ _ __ __ ____ _| |__| |_ __ __ _ _ _ _ _ ___ ##\n## | |__/ _ \\/ _` / _` | ' \\ _ \\ V V / _` | / _` | ' \\/ _` | ' \\ _ | '_/ _ \\ ##\n## |____\\___/\\__, \\__,_|_||_| (_) \\_/\\_/\\__,_|_\\__,_|_|_|_\\__,_|_||_| (_) |_| \\___/ ##\n## |___/ ##\n## ##\n#######################################################################################\n#######################################################################################";
console.log(consoleSplash);
$(
function()
{
$('html, body').scrollTop( $(document).height() );
$("#submit").click(function()
{
text = $("#text").val();
if (text !== "")
{
$("#text").val("");
console.log(text);
if (text.lastIndexOf("/",0) === 0)
{
commandPreProccesor(text.slice(1,text.length));
} else {
$.post("ServerLogic.php",{name: name,text: text,request: "update_log"});
}
}
updateClientLog();
});
$("#update").click(updateClientLog);
$("#selectUserName").click(function() {
//console.log("hem");
$.post("ServerLogic.php",{request: "find_user",user_name: $("#name").val()}).done(function(data) {
logText = JSON.parse(data);
console.log(data);
name = $("#userName").val();
$("#UserName").val("");
$("#login").fadeOut();
$("#main").fadeIn();
nameSelected = true;
$.post("ServerLogic.php",{name : name, request : "user_join"});
updateClientLog();
});
});
setInterval(updateClientLog,logUpdateMultiplier*1000);
$("#userName").keypress(function(e)
{
if(e.which == 13) $("#selectuserName").trigger("click");
});
}
);
function updateClientLog()
{
$('html, body').scrollTop( $(document).height() );
if(nameSelected) {
$.post("ServerLogic.php",{request: "poll_log"}).done(function(data){
logText = JSON.parse(data);
consoleOut = logText.log;
consoleOut = consoleOut.replace(/\n/g , "<br />");
$("#console").text("");
$("#console").html(consoleOut);
updateUserList();
});
}
}
function updateUserList()
{
$.post("ServerLogic.php",{request:"list_users"}).done(function(data)
{
$("#userList").html("<h2>Users:</h2>");
userList = JSON.parse(data);
userList = userList.users;
for(var itt=0; itt<userList.length; itt++)
{
$("#userList").append("<p>"+userList[itt]+"</p>");
$("#userList").css("bottom","0");
}
});
}
window.onbeforeunload = function() {
$.post("ServerLogic.php",{name : name, request : "user_leave"});
};
function commandPreProccesor(rawInput) {
console.log("boop");
var command = rawInput.slice(0,rawInput.indexOf(" "));
var rawArgs = rawInput.slice(rawInput.indexOf(" ")+1,rawInput.length);
var args = [];
console.log((rawArgs.match(/ /g) || []).length);
for(var itr; itr <= (rawArgs.match(/ /g) || []).length +1;itr++)
{
rawArgs = rawArgs.slice(rawArgs.indexOf(" "),rawArgs.length);
args.push(0,rawArgs.indexOf(" ")+1);
console.log(rawArgs);
}
console.log(args.length);
for (var i; i <= args.length;i++)
{
console.log(args[i] + ":");
}
}
function commandHelp(args){
}