第一次提交 游戏界面资源数据已更新
This commit is contained in:
BIN
tools/server2017-64-stable/chromedriver.exe
Normal file
BIN
tools/server2017-64-stable/chromedriver.exe
Normal file
Binary file not shown.
35833
tools/server2017-64-stable/credits.html
Normal file
35833
tools/server2017-64-stable/credits.html
Normal file
File diff suppressed because it is too large
Load Diff
BIN
tools/server2017-64-stable/d3dcompiler_47.dll
Normal file
BIN
tools/server2017-64-stable/d3dcompiler_47.dll
Normal file
Binary file not shown.
1
tools/server2017-64-stable/debug.log
Normal file
1
tools/server2017-64-stable/debug.log
Normal file
@@ -0,0 +1 @@
|
||||
[0116/121914.472:ERROR:registration_protocol_win.cc(56)] CreateFile: 系统找不到指定的文件。 (0x2)
|
||||
BIN
tools/server2017-64-stable/ffmpeg.dll
Normal file
BIN
tools/server2017-64-stable/ffmpeg.dll
Normal file
Binary file not shown.
@@ -0,0 +1,298 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="Expires" content="0">
|
||||
<meta http-equiv="Pragma" content="no-cache">
|
||||
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1 user-scalable=0"/>
|
||||
<title>友乐游戏平台服务器</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="divChat">
|
||||
<textarea name="txtChatMain" id="txtChatMain" readonly="readonly" class="txtarea"></textarea>
|
||||
</div>
|
||||
|
||||
<style type='text/css'>
|
||||
div#divChat { width:30em; }
|
||||
textarea.txtarea { float:left; width: 34em; height: 20em;}
|
||||
</style>
|
||||
<script type="text/javascript" src="minhttp.js"></script>
|
||||
<script type="text/javascript" src="packet.js"></script>
|
||||
<script type="text/javascript">
|
||||
// Websocket object
|
||||
var ws = null;
|
||||
// Websocket 状态
|
||||
var wsisclose = true;
|
||||
// Helper functions
|
||||
function $() {
|
||||
return document.getElementById(arguments[0]);
|
||||
}
|
||||
function logMsg(msg) {
|
||||
$('txtChatMain').value += msg + '\n';
|
||||
}
|
||||
function logmsg(msg) {
|
||||
$('txtChatMain').value += msg + '\n';
|
||||
}
|
||||
function sendMsg(msg) {
|
||||
ws.send(msg);
|
||||
}
|
||||
function sendmsg(msg) {
|
||||
ws.send(msg);
|
||||
}
|
||||
//重新连接
|
||||
function reconnect(){
|
||||
ws = null;
|
||||
connectWebSocket();
|
||||
}
|
||||
// Websocket functions
|
||||
function connectWebSocket() {
|
||||
OnBeginConnectedServerChat();
|
||||
if ("WebSocket" in window) {
|
||||
// Create new websocket connection
|
||||
ws = new WebSocket("ws://127.0.0.1:1088");
|
||||
|
||||
// Called after connection is established
|
||||
ws.onopen = function() {
|
||||
wsisclose = false;
|
||||
logMsg(min_now() + ' tcp connected to: ' + ws.url);
|
||||
sendMsg('dfw19770109'); //告诉ServerChat.exe我是逻辑服务器
|
||||
};
|
||||
|
||||
// Called when connection is closed
|
||||
ws.onclose = function() {
|
||||
wsisclose = true;
|
||||
logMsg(min_now() + " Connection closed!");
|
||||
min_ontimeout(reconnect, 5000);
|
||||
};
|
||||
|
||||
// Called when a new message is received
|
||||
ws.sendall = function (msg) {
|
||||
if (typeof(msg) == 'string') {
|
||||
sendMsg('@toallall:' + msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
var s = JSON.stringify(msg);
|
||||
sendMsg('@toallall:' + s);
|
||||
}
|
||||
}
|
||||
|
||||
//Send message to HTTP client
|
||||
ws.sendtou = function (head, msg) {
|
||||
if (wsisclose){
|
||||
return;
|
||||
}
|
||||
sendMsg(head + msg);
|
||||
}
|
||||
|
||||
//Send message to TCP client
|
||||
ws.sendbyids = function(ids, msg) {
|
||||
if (wsisclose){
|
||||
return;
|
||||
}
|
||||
var s = '@tooneone:';
|
||||
var str_ids;
|
||||
if (typeof(msg) == 'string')
|
||||
{}
|
||||
else
|
||||
{
|
||||
msg = JSON.stringify(msg);
|
||||
}
|
||||
if (typeof(ids) == 'string')
|
||||
{
|
||||
str_ids = ids;
|
||||
}
|
||||
else
|
||||
{
|
||||
//ids:[1,5,8] 要转成字符串 1,5,8
|
||||
str_ids = ids[0];
|
||||
for (var i=1; i<ids.length; i++)
|
||||
{
|
||||
str_ids = str_ids + ',' + ids[i];
|
||||
}
|
||||
}
|
||||
s = s + str_ids + ':' + msg;
|
||||
sendMsg(s);
|
||||
}
|
||||
|
||||
ws.onmessage = function (msg) {
|
||||
if (msg.data)
|
||||
{
|
||||
// logMsg(msg.data);
|
||||
var arr = msg.data;
|
||||
var tou = arr.substr(10, 5);
|
||||
// var arrs = arr.split(":");
|
||||
//取前面50个字符,以免全字符split,提高效率
|
||||
var arr50 = arr.substr(0, 50);
|
||||
var arrs = arr50.split(":");
|
||||
|
||||
if (tou == 'http_')
|
||||
{//http
|
||||
var s1 = '@tooneone' + ':' + arrs[1] + ':';
|
||||
var s2 = "";
|
||||
if (arrs.length > 2)
|
||||
{//是数据,否则是命令
|
||||
s2 = msg.data.substr(s1.length, msg.data.length-s1.length);
|
||||
}
|
||||
OnHttpMessage(s1, s2);
|
||||
}
|
||||
else
|
||||
{//tcp
|
||||
var ss0 = arrs[0];
|
||||
var ss1 = arrs[1];
|
||||
var sip = arrs[2];
|
||||
var s01 = ss0 + ':' + ss1 + ':' + sip + ':';
|
||||
var ss2 = "";
|
||||
if (arrs.length > 3)
|
||||
{//是数据,否则是命令
|
||||
ss2 = msg.data.substr(s01.length, msg.data.length - s01.length);
|
||||
}
|
||||
OnTcpMessage(ss0, ss1, sip, ss2);
|
||||
|
||||
// var ss0 = arrs[0];
|
||||
// var ss1 = arrs[1];
|
||||
// var s01 = ss0 + ':' + ss1 + ':';
|
||||
// var ss2 = "";
|
||||
// if (arrs.length > 2)
|
||||
// {//是数据,否则是命令
|
||||
// ss2 = msg.data.substr(s01.length, msg.data.length - s01.length);
|
||||
// }
|
||||
// OnTcpMessage(ss0, ss1, "", ss2);
|
||||
}
|
||||
};
|
||||
|
||||
return;
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
logMsg('Browser doesn\'t support websockets!');
|
||||
}
|
||||
|
||||
OnAfterConnectedServerChat();
|
||||
}
|
||||
|
||||
//server.html连接ServerChat.exe前的事件
|
||||
function OnBeginConnectedServerChat()
|
||||
{
|
||||
}
|
||||
|
||||
//server.html连接ServerChat.exe后的事件
|
||||
function OnAfterConnectedServerChat()
|
||||
{
|
||||
//给packet_face传递发包函数
|
||||
if (typeof(packet_face) != "undefined")
|
||||
{
|
||||
global.packet_face.SendPack_Tcp = ws.sendbyids;
|
||||
global.packet_face.SendPack_Http = ws.sendtou;
|
||||
}
|
||||
}
|
||||
|
||||
//收到客户端http发包触发的事件
|
||||
function OnHttpMessage(str_httpid, str_data)
|
||||
{
|
||||
try
|
||||
{
|
||||
str_data = min_replaceAll(str_data, "%", "");
|
||||
str_data = decodeURIComponent(str_data); //解码
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
console.log("OnHttpMessage_decodeURIComponent:" + str_data);
|
||||
return;
|
||||
}
|
||||
|
||||
var s = "";
|
||||
s = str_data.substr(0, 6);
|
||||
if (s == "&data=") {
|
||||
str_data = str_data.replace("&data=", "");
|
||||
}
|
||||
s = str_data.substr(0, 5);
|
||||
if (s == "data=") {
|
||||
str_data = str_data.replace("data=", "");
|
||||
}
|
||||
s = str_data.substr(0, 2);
|
||||
if (s == "&=") {
|
||||
str_data = str_data.replace("&=", "");
|
||||
}
|
||||
s = str_data.substr(0, 1);
|
||||
if (s == "&") {
|
||||
str_data = str_data.replace("&", "");
|
||||
}
|
||||
|
||||
if (typeof(packet_face) != "undefined") {
|
||||
if (str_data) {
|
||||
try
|
||||
{
|
||||
var json_data = JSON.parse(str_data);
|
||||
if (json_data){
|
||||
json_data.conmode = "http";
|
||||
json_data.fromid = str_httpid;
|
||||
packet_face.ReceivePack(json_data);
|
||||
}
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
console.log(min_now() + " str_data:" + str_data);
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//收到客户端tcp发包触发的事件
|
||||
function OnTcpMessage(str_com, str_tcpid, str_ip, str_data)
|
||||
{
|
||||
switch (str_com)
|
||||
{
|
||||
case "@toconcon": //连上ServerChat.exe
|
||||
break;
|
||||
|
||||
case "@tologin1": //客户端连接上
|
||||
if (typeof(packet_face) != "undefined")
|
||||
{
|
||||
packet_face.OnTcpConnected(str_tcpid);
|
||||
}
|
||||
break;
|
||||
|
||||
case "@toleave1": //客户端断开
|
||||
if (typeof(packet_face) != "undefined")
|
||||
{
|
||||
packet_face.OnTcpDisConnected(str_tcpid);
|
||||
}
|
||||
break;
|
||||
|
||||
case "@toserver": //客户端发包
|
||||
if (typeof(packet_face) != "undefined")
|
||||
{
|
||||
try
|
||||
{
|
||||
str_data = min_replaceAll(str_data, "%", ""); //去除%,否则decodeURIComponent(str_data)会报错
|
||||
str_data = decodeURIComponent(str_data); //解码
|
||||
var json_data = JSON.parse(str_data);
|
||||
if (json_data){
|
||||
json_data.conmode = "tcp";
|
||||
json_data.fromid = str_tcpid;
|
||||
json_data.ip = str_ip;
|
||||
packet_face.ReceivePack(json_data);
|
||||
}
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
console.log(min_now() + " str_data:" + str_data);
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
window.onload = connectWebSocket();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1 @@
|
||||
min_loadJsFile("server/app.js", function (){});
|
||||
@@ -0,0 +1,77 @@
|
||||
///////////////////////////////////////////////////
|
||||
//////////////cls_app: 应用基础类//////////////////
|
||||
///////////////////////////////////////////////////
|
||||
var cls_app = cls_app || {
|
||||
//构造函数
|
||||
new: function(_str_appname, _obj_packet) {
|
||||
/*
|
||||
参数说明:
|
||||
_str_appname 应用名称
|
||||
_obj_packet 所有应用的总包接口对象
|
||||
*/
|
||||
|
||||
//创建一个实例
|
||||
var app = {};
|
||||
|
||||
// ================= 实例的公有属性 ================= //
|
||||
//应用名称
|
||||
app.appname = _str_appname;
|
||||
//总包接口
|
||||
app.packet_face = _obj_packet;
|
||||
//给客户端发包函数
|
||||
app.SendPack = app.packet_face.SendPack;
|
||||
//给http客户端发包函数
|
||||
app.SendPack_Http = app.packet_face.SendPack_Http;
|
||||
//给tcp客户端发包函数
|
||||
app.SendPack_Tcp = app.packet_face.SendPack_Tcp;
|
||||
//将app添加到packet_face的应用列表中
|
||||
app.packet_face.applist.push(app);
|
||||
|
||||
//模块列表 [{"face":room_face,"facename":"room_face","routename":"room"}]
|
||||
app.modlist = [];
|
||||
|
||||
// ================= 实例的公有方法 ================= //
|
||||
//TCP客户端断开
|
||||
app.OnTcpDisConnected = function(_str_tcpid) {
|
||||
cls_app.OnTcpDisConnected(app, _str_tcpid);
|
||||
}
|
||||
|
||||
//处理数据包
|
||||
app.ReceivePack = function(_pack) {
|
||||
return cls_app.ReceivePack(app, _pack);
|
||||
}
|
||||
|
||||
return app;
|
||||
},
|
||||
|
||||
// ================= 所有实例的共享方法 ================= //
|
||||
//TCP客户端断开
|
||||
OnTcpDisConnected: function(_obj_app, _str_tcpid) {
|
||||
for (var i = 0; i < _obj_app.modlist.length; i++) {
|
||||
if (_obj_app.modlist[i].OnTcpDisConnected) {
|
||||
_obj_app.modlist[i].OnTcpDisConnected(_str_tcpid);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
//处理数据包
|
||||
ReceivePack: function(_obj_app, _pack) {
|
||||
if (typeof(_pack) == "string") {
|
||||
_pack = JSON.parse(_pack); //转换json
|
||||
}
|
||||
//路由各个模块
|
||||
for (var i = 0; i < _obj_app.modlist.length; i++) {
|
||||
if (_pack.route == _obj_app.modlist[i].routename) {
|
||||
if (_obj_app.modlist[i].DoPack) {
|
||||
var repack = _obj_app.modlist[i].DoPack(_pack);
|
||||
//发包
|
||||
if (repack && _obj_app.SendPack) {
|
||||
_obj_app.SendPack(repack);
|
||||
}
|
||||
return repack;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
///////////////////////////////////////////////////
|
||||
//////////////cls_mod: 模块基础类//////////////////
|
||||
///////////////////////////////////////////////////
|
||||
var cls_mod = cls_mod || {
|
||||
//构造函数
|
||||
new: function(_str_modname, _str_routename, _obj_app) {
|
||||
/*
|
||||
_str_modname 模块名称
|
||||
_str_routename 模块的路由名称
|
||||
_obj_app 所属的应用对象
|
||||
*/
|
||||
|
||||
//创建一个实例
|
||||
var mod = {};
|
||||
|
||||
// ================= 实例的公有属性 ================= //
|
||||
//模块名称
|
||||
mod.modname = _str_modname;
|
||||
//路由名称
|
||||
mod.routename = _str_routename;
|
||||
//所属的应用
|
||||
mod.app = _obj_app;
|
||||
//将mod对象添加到app的模块列表中
|
||||
mod.app.modlist.push(mod);
|
||||
mod.app[_str_modname] = mod;
|
||||
|
||||
// ================= 实例的公有方法 ================= //
|
||||
//收包处理
|
||||
mod.DoPack = function(_msg) {
|
||||
return cls_mod.DoPack(mod, _msg);
|
||||
}
|
||||
|
||||
//输出mod
|
||||
cls_mod.OutputMod(mod);
|
||||
|
||||
return mod;
|
||||
},
|
||||
|
||||
DoPack: function(_obj_mod, _msg) {
|
||||
if (typeof(_msg) == "string") {
|
||||
_msg = JSON.parse(_msg); //转换json
|
||||
}
|
||||
//执行rpc
|
||||
if (_msg.rpc) {
|
||||
if (min_ExitsFunction(_obj_mod[_msg.rpc])) {
|
||||
return _obj_mod[_msg.rpc](_msg);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
OutputMod: function(_obj_mod) {
|
||||
if (typeof global !== "undefined")
|
||||
{} else {
|
||||
global = {};
|
||||
}
|
||||
|
||||
if (typeof module !== "undefined")
|
||||
{} else {
|
||||
module = {};
|
||||
module.exports = {};
|
||||
}
|
||||
|
||||
global[_obj_mod.modname] = _obj_mod;
|
||||
global[_obj_mod.modname].DoPack = _obj_mod.DoPack;
|
||||
|
||||
if (module) {
|
||||
module.exports[_obj_mod.modname] = _obj_mod;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
///////////////////////////////////////////////////
|
||||
///////////// cls_mysql: 数据库操作 ///////////////
|
||||
///////////////////////////////////////////////////
|
||||
var cls_mysql = cls_mysql || {
|
||||
|
||||
//构造函数
|
||||
new: function(url, func_fail_sendpack){
|
||||
var mysql = {};
|
||||
//php地址
|
||||
mysql.url = url;
|
||||
//发生错误时的回包函数
|
||||
mysql.func_fail_sendpack = func_fail_sendpack;
|
||||
|
||||
//执行sql语句
|
||||
mysql.execsql = function(method, sql, para, func_succ, pack) {
|
||||
/*
|
||||
method: php方法名 execsql/opensql
|
||||
sql: 要执行的sql语句
|
||||
para: 要执行的sql语句的参数数组
|
||||
func_succ: sql语句执行成功后的回调函数
|
||||
pack: 客户端发来的数据包,执行失败的话会根据pack返回客户端执行失败的结果
|
||||
*/
|
||||
var data = {}
|
||||
data.m = method;
|
||||
data.s = sql;
|
||||
data.p = para;
|
||||
|
||||
var strdata = JSON.stringify(data);
|
||||
//将=号替换为^,php收到后再替换回来,以避免=号POST传参会截断的问题
|
||||
strdata = strdata.replace(/\=/g,"^");
|
||||
|
||||
var cfg = {};
|
||||
cfg.url = mysql.url;
|
||||
cfg.data = "data=" + strdata;
|
||||
cfg.type = "POST";
|
||||
cfg.success = function(str) {
|
||||
try {
|
||||
var result = JSON.parse(str);
|
||||
} catch(e) {
|
||||
console.log(min_now() + " 数据库执行结果转换json失败.");
|
||||
console.log(str);
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.state != 0) {
|
||||
console.log(min_now() + " 请求" + mysql.url + "失败.");
|
||||
console.log("state=" + result.state + "; error=" + result.error);
|
||||
console.log("data:" + strdata);
|
||||
console.log(para);
|
||||
|
||||
if (pack) {
|
||||
console.log(JSON.stringify(pack));
|
||||
//返回客户端执行失败的结果
|
||||
if (mysql.func_fail_sendpack) {
|
||||
pack.data = {};
|
||||
pack.data.state = result.state;
|
||||
pack.data.error = result.error;
|
||||
mysql.func_fail_sendpack(pack);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//执行sql成功执行回调函数
|
||||
if (func_succ) {
|
||||
func_succ(result.data);
|
||||
}
|
||||
}
|
||||
};
|
||||
cfg.error = function(str){
|
||||
console.log(min_now() + " 请求" + mysql.url + "失败.");
|
||||
console.log("error:" + str);
|
||||
console.log("data:" + strdata);
|
||||
|
||||
if (pack) {
|
||||
console.log(JSON.stringify(pack));
|
||||
//返回客户端执行失败的结果
|
||||
if (mysql.func_fail_sendpack) {
|
||||
pack.data = {};
|
||||
pack.data.state = 99;
|
||||
pack.data.error = "请求数据库失败.";
|
||||
mysql.func_fail_sendpack(pack);
|
||||
}
|
||||
}
|
||||
};
|
||||
min_http(cfg);
|
||||
}
|
||||
return mysql;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
///////////////////////////////////////////////////
|
||||
////////////////// cls_pai: 单张牌 ////////////////
|
||||
///////////////////////////////////////////////////
|
||||
var cls_pai = cls_pai || {
|
||||
|
||||
//创建单张牌实例
|
||||
new: function(id, score, dealowner){
|
||||
/*
|
||||
参数说明:
|
||||
id 牌的绝对id
|
||||
score 牌在游戏中的分值
|
||||
dealowner 发牌状态
|
||||
|
||||
扑克牌的统一编码规则:
|
||||
1,牌面花色的定义 5:王 4:黑桃 3:红心 2:梅花 1:方块
|
||||
2,牌面数值的定义 1:A 2:2 3:3 ... 9:9 10:10 11:J 12:Q 13:K 53:小王 54:大王
|
||||
*/
|
||||
var pai = {};
|
||||
|
||||
//属性
|
||||
pai.id = id; //绝对id,即数组下标,从0开始计数
|
||||
pai.score = score; //牌在游戏中的分值
|
||||
pai.dealowner = dealowner; //发牌状态
|
||||
//-1:规则去除的牌
|
||||
// 0:未发的牌,即底牌
|
||||
//>0:发牌发到谁手上,从1开始计数,即座位编号+1,座位编号是从0开始计数的
|
||||
pai.playround = -1; //出牌状态
|
||||
//-1:未出的牌
|
||||
// 0:埋牌
|
||||
//>0:牌是第几轮出出去的,从1开始计数
|
||||
pai.playindex = -1; //本轮中的出牌顺序,从1开始计数
|
||||
pai.playowner = -1; //出牌后被谁得到,与座位编号对应
|
||||
|
||||
//方法
|
||||
pai.method = {};
|
||||
|
||||
//牌面花色
|
||||
pai.method.get_flower = function(){
|
||||
return cls_pai.get_flower(pai);
|
||||
}
|
||||
|
||||
//牌面数值
|
||||
pai.method.get_number = function(){
|
||||
return cls_pai.get_number(pai);
|
||||
}
|
||||
|
||||
return pai;
|
||||
},
|
||||
|
||||
//获取牌面花色
|
||||
get_flower: function(o_pai) {
|
||||
var yu = o_pai.id % 54;
|
||||
if (yu == 52 || yu == 53){ //小王大王
|
||||
return 5;
|
||||
}
|
||||
return parseInt(yu / 13) + 1;
|
||||
},
|
||||
|
||||
//获取牌面数值
|
||||
get_number: function(o_pai) {
|
||||
var yu = o_pai.id % 54;
|
||||
if (yu == 52){ //小王
|
||||
return 53;
|
||||
}
|
||||
if (yu == 53){ //大王
|
||||
return 54;
|
||||
}
|
||||
return yu % 13 + 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
///////////////////////////////////////////////////
|
||||
//////////////// cls_paiju: 单局牌局 //////////////
|
||||
///////////////////////////////////////////////////
|
||||
var cls_paiju = cls_paiju || {
|
||||
|
||||
//创建单张牌实例
|
||||
new: function(){
|
||||
|
||||
var paiju = {};
|
||||
|
||||
|
||||
|
||||
return paiju;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,699 @@
|
||||
(function(wnd, undef){
|
||||
|
||||
//复制json对象
|
||||
function min_copyjson(json)
|
||||
{
|
||||
return JSON.parse(JSON.stringify(json));
|
||||
}
|
||||
|
||||
function min_clone(myObj){
|
||||
if(!myObj)
|
||||
return myObj;
|
||||
if(typeof(myObj) != 'object')
|
||||
return myObj;
|
||||
|
||||
var myNewObj = new Object();
|
||||
|
||||
for(var i in myObj)
|
||||
myNewObj[i] = min_clone(myObj[i]);
|
||||
|
||||
return myNewObj;
|
||||
}
|
||||
|
||||
//json对象转字符串
|
||||
function min_jsontostr(json) {
|
||||
return JSON.stringify(json);
|
||||
}
|
||||
|
||||
//字符串转json对象
|
||||
function min_strtojson(str) {
|
||||
return JSON.parse(str);
|
||||
}
|
||||
|
||||
//字符串转整型 def:转换失败时返回的默认值
|
||||
function min_strtoint(str, def) {
|
||||
var i = parseInt(str);
|
||||
if (i == 0) {
|
||||
return 0;
|
||||
};
|
||||
if (!i) { //=0也会进来
|
||||
if (!def) {
|
||||
def = 0;
|
||||
};
|
||||
i = def;
|
||||
}
|
||||
return i;
|
||||
};
|
||||
|
||||
//整型转字符串
|
||||
function min_inttostr(i) {
|
||||
return i.toString();
|
||||
};
|
||||
|
||||
//去左空格
|
||||
function min_ltrim(s){
|
||||
return s.replace(/(^\s*)/g, "");
|
||||
};
|
||||
|
||||
//去右空格;
|
||||
function min_rtrim(s){
|
||||
return s.replace(/(\s*$)/g, "");
|
||||
};
|
||||
|
||||
//去左右空格;
|
||||
function min_trim(s){
|
||||
return s.replace(/(^\s*)|(\s*$)/g, "");
|
||||
};
|
||||
|
||||
//整除
|
||||
function min_div(i, b)
|
||||
{
|
||||
if (!b) {
|
||||
return parseInt(i);
|
||||
}
|
||||
return parseInt(i / b);
|
||||
};
|
||||
|
||||
//取余数
|
||||
function min_mod(a, b){
|
||||
return a % b;
|
||||
};
|
||||
|
||||
//取绝对值
|
||||
function min_abs(b) {
|
||||
return Math.abs(b);
|
||||
};
|
||||
|
||||
//取随机数(范围包含了min和max)
|
||||
function min_random(min, max) {
|
||||
var Range = max - min;
|
||||
var Rand = Math.random();
|
||||
return (min + Math.round(Rand * Range));
|
||||
};
|
||||
//取随机数1
|
||||
function min_random1(num) {
|
||||
return parseInt(Math.random()*num);
|
||||
};
|
||||
|
||||
//随机字符串
|
||||
function min_randomChar(length){
|
||||
var x = "0123456789";
|
||||
var y = "qwertyuioplkjhgfdsazxcvbnm";
|
||||
var z = "QWERTYUIOPLKJHGFDSAZXCVBNM";
|
||||
var tmp = "";
|
||||
for (var i = 0; i < length; i++) {
|
||||
switch(min_random(0, 2)) {
|
||||
case 0:
|
||||
tmp += x.charAt(Math.ceil(Math.random()*100000000)%x.length);
|
||||
break;
|
||||
case 1:
|
||||
tmp += y.charAt(Math.ceil(Math.random()*100000000)%y.length);
|
||||
break;
|
||||
case 2:
|
||||
tmp += z.charAt(Math.ceil(Math.random()*100000000)%z.length);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
// var timestamp = new Date().getTime();
|
||||
// return timestamp + tmp;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
//取长度
|
||||
function min_length(key) {
|
||||
if (typeof(key) != "string") {
|
||||
var key = key + "";
|
||||
}
|
||||
return key.length;
|
||||
}
|
||||
|
||||
//字符全替换 ignoreCase:true忽略大小写 false不忽略大小写
|
||||
function min_replaceAll(str, str_old, str_new, ignoreCase)
|
||||
{
|
||||
if (!RegExp.prototype.isPrototypeOf(str_old)) {
|
||||
return str.replace(new RegExp(str_old, (ignoreCase ? "gi": "g")), str_new);
|
||||
} else {
|
||||
return str.replace(str_old, str_new);
|
||||
}
|
||||
}
|
||||
|
||||
//取本地当前时间,格式yyyy-MM-dd HH:MM:SS
|
||||
function min_now()
|
||||
{
|
||||
var date = new Date();
|
||||
var seperator1 = "-";
|
||||
var seperator2 = ":";
|
||||
var month = date.getMonth() + 1;
|
||||
var strDate = date.getDate();
|
||||
if (month >= 1 && month <= 9) {
|
||||
month = "0" + month;
|
||||
}
|
||||
if (strDate >= 0 && strDate <= 9) {
|
||||
strDate = "0" + strDate;
|
||||
}
|
||||
var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
|
||||
+ " " + date.getHours() + seperator2 + date.getMinutes()
|
||||
+ seperator2 + date.getSeconds();
|
||||
return currentdate;
|
||||
}
|
||||
|
||||
//取本地当前日期,格式yyyy-MM-dd
|
||||
function min_day()
|
||||
{
|
||||
var date = new Date();
|
||||
var seperator1 = "-";
|
||||
var month = date.getMonth() + 1;
|
||||
var strDate = date.getDate();
|
||||
if (month >= 1 && month <= 9) {
|
||||
month = "0" + month;
|
||||
}
|
||||
if (strDate >= 0 && strDate <= 9) {
|
||||
strDate = "0" + strDate;
|
||||
}
|
||||
var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
|
||||
return currentdate;
|
||||
}
|
||||
|
||||
//本地存储数据
|
||||
function min_writefile_gameid(msg, gameid, fileid) {
|
||||
localStorage.setItem("file_" + gameid + "_" + fileid, msg);
|
||||
}
|
||||
|
||||
//读取本地数据
|
||||
function min_readfile_gameid(gameid, fileid) {
|
||||
return localStorage.getItem("file_" + gameid + "_" + fileid);
|
||||
}
|
||||
|
||||
//取当前页面url中的参数值 def:没取到时返回的默认值
|
||||
function min_getQueryString(name, def) {
|
||||
var self = window;
|
||||
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
|
||||
var r = self.location.search.substr(1).match(reg);
|
||||
if (r != null) {
|
||||
return unescape(r[2])
|
||||
} else {
|
||||
if (def) {
|
||||
return def;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//获取当前页面的路径
|
||||
function min_getUrlRootPath() {
|
||||
var curWwwPath = window.location.host;
|
||||
var pathName = window.location.pathname;
|
||||
return curWwwPath + pathName.substr(0,pathName.lastIndexOf('/'));
|
||||
}
|
||||
|
||||
//设置cookie
|
||||
function min_setCookie(name, value, exp_minute) {
|
||||
if (!exp_minute) {
|
||||
exp_minute = 20; //默认时效20分钟
|
||||
}
|
||||
var exp = new Date();
|
||||
exp.setTime(exp.getTime() + exp_minute*60*1000);
|
||||
document.cookie = name + "=" + value + ";expires=" + exp.toGMTString()+';path=/';
|
||||
}
|
||||
|
||||
//读取cookie
|
||||
function min_getCookie(name) {
|
||||
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
|
||||
if(arr != null)
|
||||
return arr[2];
|
||||
return null;
|
||||
}
|
||||
|
||||
//删除cookie
|
||||
function min_delCookie(name) {
|
||||
var value = min_getCookie(name);
|
||||
if (value) {
|
||||
min_setCookie(name, value, 0);
|
||||
}
|
||||
}
|
||||
|
||||
//获取一个dom
|
||||
function min_getdom(id)
|
||||
{
|
||||
return document.getElementById(id);
|
||||
};
|
||||
|
||||
//设置一个dom属性值 id:dom、或dom的id、或实列,key:属性,val:值
|
||||
function min_setdom(id, key, val) {
|
||||
var obj;
|
||||
if (typeof(id) == 'string') {
|
||||
obj = min_getdom(id);
|
||||
}
|
||||
else {
|
||||
obj = id;
|
||||
}
|
||||
obj.setAttribute(key, val);
|
||||
}
|
||||
|
||||
//添加一段innerHTML
|
||||
function min_uphtml(id, str, isadd) {
|
||||
/*
|
||||
setAttribute是设置网页元素的属性,就是在标签里内如<img />标签的src属性。
|
||||
innerHTML不是属性,只是JS里内代表一个双标记中间的文本,如:<span> </span>中间的字符。
|
||||
*/
|
||||
var obj = window.document.getElementById(id);
|
||||
if (isadd) {
|
||||
obj.innerHTML = obj.innerHTML + str;
|
||||
}
|
||||
else {
|
||||
obj.innerHTML = str;
|
||||
}
|
||||
}
|
||||
|
||||
//新建一个定时器每隔time毫秒执行一次func函数,函数返回定时器id
|
||||
function min_ontime(func, time)
|
||||
{
|
||||
return setInterval(func, time);
|
||||
}
|
||||
|
||||
//新建一个定时器time毫秒后执行一次func函数(只执行一次),函数返回定时器id
|
||||
function min_ontimeout(func, time)
|
||||
{
|
||||
return setTimeout(func, time);
|
||||
}
|
||||
|
||||
//关闭定时器id为timerid的定时器
|
||||
function min_closetime(timerid)
|
||||
{
|
||||
return clearTimeout(timerid);
|
||||
}
|
||||
|
||||
//encode转码
|
||||
function min_encode(s)
|
||||
{
|
||||
return encodeURIComponent(s);
|
||||
}
|
||||
|
||||
//decode解码
|
||||
function min_decode(s)
|
||||
{
|
||||
return decodeURIComponent(s);
|
||||
}
|
||||
|
||||
//新建一个tcp连接
|
||||
function min_tcp(config)
|
||||
{
|
||||
var ws = new WebSocket("ws://" + config.ipport); //不要带htpp,例如127.0.0.1:5414
|
||||
|
||||
//连接上服务器后触发的事件
|
||||
if (config.onopen) {
|
||||
ws.onopen = config.onopen;
|
||||
};
|
||||
|
||||
//收到服务器发来的数据包后触发的事件,onmessage函数会有一个底层的msg参数,其中msg.data才是服务器发过来的业务数据
|
||||
if (config.onmessage) {
|
||||
ws.onmessage = config.onmessage;
|
||||
};
|
||||
|
||||
//断开与服务器的连接后触发的事件
|
||||
if (config.onclose) {
|
||||
ws.onclose = config.onclose; //断开连接的事件
|
||||
};
|
||||
|
||||
//错误事件
|
||||
if (config.onerror) {
|
||||
ws.onerror = config.onerror; //错误事件
|
||||
};
|
||||
|
||||
return ws;
|
||||
}
|
||||
|
||||
//http请求
|
||||
function min_http(config) {
|
||||
/*
|
||||
config =
|
||||
{
|
||||
url: "http://127.0.0.1:5414/index.html",
|
||||
type: "POST", //GET or POST 方法
|
||||
data: "", //请求的数据
|
||||
success: func_callback_succ, //请求成功后的回调函数function(data,status,callbackdata)
|
||||
error: func_callback_err, //请求失败后的回调函数function(data,status)
|
||||
callbackdata: "", //作为回调函数第三个参数带入回调函数的数据
|
||||
//enurl: 0, //是否encodeURIComponent转码, 默认0不转码
|
||||
//deurl: 0, //是否decodeURIComponent解码,默认0不解码
|
||||
debugLog: false, //是否输出debug日志,默认false
|
||||
method: "(OPTIONAL) True for async and False for Non-async | By default its Async"
|
||||
}
|
||||
*/
|
||||
if (!config.debugLog) {
|
||||
config.debugLog = false;
|
||||
}
|
||||
if (!config.enurl) {
|
||||
config.enurl = 0;
|
||||
}
|
||||
if (!config.deurl) {
|
||||
config.deurl = 0;
|
||||
}
|
||||
if (!config.method) {
|
||||
config.method = true;
|
||||
}
|
||||
|
||||
if (!config.url) {
|
||||
if (config.debugLog == true) {
|
||||
console.log("No Url!");
|
||||
}
|
||||
return;
|
||||
};
|
||||
|
||||
if (!config.type) {
|
||||
if (config.debugLog == true) {
|
||||
console.log("No Default type (GET/POST) given!");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var xmlhttp = initXMLhttp();
|
||||
|
||||
xmlhttp.onreadystatechange = function() {
|
||||
if (xmlhttp.readyState == 4 && xmlhttp.status == 200 && config.success)
|
||||
{
|
||||
var responseText = mydecodeURIComponent(xmlhttp.responseText, config.deurl);
|
||||
if (!config.callbackdata) {
|
||||
config.success(responseText, xmlhttp.readyState);
|
||||
}
|
||||
else {
|
||||
config.success(responseText, xmlhttp.readyState, config.callbackdata);
|
||||
}
|
||||
if (config.debugLog == true) {
|
||||
console.log("SuccessResponse");
|
||||
}
|
||||
if (config.debugLog == true) {
|
||||
console.log("Response Data:" + xmlhttp.responseText);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (xmlhttp.readyState == 4 && config.error)
|
||||
{
|
||||
if (!config.callbackdata) {
|
||||
config.error(xmlhttp.readyState, xmlhttp.status);
|
||||
}
|
||||
else {
|
||||
config.error(xmlhttp.readyState, xmlhttp.status, config.callbackdata);
|
||||
}
|
||||
}
|
||||
if (config.debugLog == true) {
|
||||
console.log("FailureResponse --> readyState:" + xmlhttp.readyState + ", Status:" + xmlhttp.status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var sendString = [],
|
||||
sendData = config.data;
|
||||
if (typeof sendData === "string") {
|
||||
var tmpArr = String.prototype.split.call(sendData, '&');
|
||||
for (var i = 0, j = tmpArr.length; i < j; i++) {
|
||||
var datum = tmpArr[i].split('=');
|
||||
if (datum[1]) {
|
||||
sendString.push(myencodeURIComponent(datum[0], config.enurl) + "=" + myencodeURIComponent(datum[1], config.enurl));
|
||||
}
|
||||
else {
|
||||
sendString.push(myencodeURIComponent(datum[0], config.enurl));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (typeof sendData === 'object' && !(sendData instanceof String || (FormData && sendData instanceof FormData))) {
|
||||
for (var k in sendData) {
|
||||
var datum = sendData[k];
|
||||
if (Object.prototype.toString.call(datum) == "[object Array]") {
|
||||
for (var i = 0, j = datum.length; i < j; i++) {
|
||||
sendString.push(myencodeURIComponent(k, config.enurl) + "[]=" + myencodeURIComponent(datum[i], config.enurl));
|
||||
}
|
||||
}
|
||||
else {
|
||||
sendString.push(myencodeURIComponent(k, config.enurl) + "=" + myencodeURIComponent(datum, config.enurl));
|
||||
}
|
||||
}
|
||||
}
|
||||
sendString = sendString.join('&');
|
||||
|
||||
if (config.type == "GET") {
|
||||
var g;
|
||||
var i = config.url.lastIndexOf("?");
|
||||
if (i > 8) {
|
||||
g = "&";
|
||||
} else {
|
||||
g = "?";
|
||||
}
|
||||
var ddata = new Date().getMilliseconds();
|
||||
if (sendString == "") {
|
||||
sendString = '#dfw1977=' + (ddata + min_random(1, 99999) * 1000);
|
||||
} else {
|
||||
sendString = sendString + '#dfw1977=' + (ddata + min_random(1, 99999) * 1000);
|
||||
}
|
||||
xmlhttp.open("GET", config.url + g + sendString, config.method);
|
||||
xmlhttp.send();
|
||||
|
||||
if (config.debugLog == true) {
|
||||
console.log("GET fired at:" + config.url + "?" + sendString);
|
||||
}
|
||||
}
|
||||
if (config.type == "POST") {
|
||||
xmlhttp.open("POST", config.url, config.method);
|
||||
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
||||
xmlhttp.send(sendString);
|
||||
|
||||
if (config.debugLog == true) {
|
||||
console.log("POST fired at:" + config.url + " || Data:" + sendString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function initXMLhttp() {
|
||||
var xmlhttp;
|
||||
if (window.XMLHttpRequest) {
|
||||
//code for IE7,firefox chrome and above
|
||||
xmlhttp = new XMLHttpRequest();
|
||||
} else {
|
||||
//code for Internet Explorer
|
||||
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
|
||||
}
|
||||
return xmlhttp;
|
||||
}
|
||||
|
||||
//转码
|
||||
function myencodeURIComponent(s, ifif)
|
||||
{
|
||||
if (ifif == 1) {
|
||||
return min_encode(s);
|
||||
} else {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
//解码
|
||||
function mydecodeURIComponent(s, ifif)
|
||||
{
|
||||
if (ifif == 1) {
|
||||
return min_decode(s);
|
||||
} else {
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//在数组中根据元素值查找下标
|
||||
function min_ary_indexof(array1, val, name)
|
||||
{
|
||||
for (var i = 0; i < array1.length; i++)
|
||||
{
|
||||
if (!name)
|
||||
{
|
||||
if (array1[i] == val)
|
||||
return i;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (array1[i][name] == val)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
|
||||
//在数组中根据值删除元素
|
||||
function min_ary_delval(array1, val, name)
|
||||
{
|
||||
var index = min_ary_indexof(array1, val, name);
|
||||
if (index > -1)
|
||||
{
|
||||
array1.splice(index, 1);
|
||||
}
|
||||
};
|
||||
|
||||
//在数组中根据下标删除诺干个元素
|
||||
function min_ary_delfromto(array1, from, to)
|
||||
{
|
||||
var rest = array1.slice((to || from) + 1 || array1.length);
|
||||
array1.length = from < 0 ? array1.length + from : from;
|
||||
array1.push.apply(array1, rest);
|
||||
};
|
||||
|
||||
//在数组中删除某一对象元素
|
||||
function min_ary_delobj(array1, object)
|
||||
{
|
||||
for (var i = 0; i < array1.length; ++i)
|
||||
{
|
||||
if (array1[i] === object)
|
||||
{
|
||||
array1.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//数组包含
|
||||
function min_ary_include(aryparent, arychild){
|
||||
for (var i = 0; i < arychild.length; i++) {
|
||||
var found = false;
|
||||
for (var j = 0; j < aryparent.length; j++) {
|
||||
if (aryparent[j] == arychild[i]){
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
//数组相减
|
||||
function min_ary_deduct(aryparent, arychild){
|
||||
var re = [];
|
||||
for (var i = 0; i < aryparent.length; i++){
|
||||
var found = false;
|
||||
for (var j = 0; j < arychild.length; j++){
|
||||
if (aryparent[i] == arychild[j]){
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found){
|
||||
re.push(aryparent[i])
|
||||
}
|
||||
}
|
||||
return re;
|
||||
};
|
||||
|
||||
//是否存在指定函数
|
||||
function min_ExitsFunction(funcName)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (typeof(eval(funcName)) == "function")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch(e)
|
||||
{}
|
||||
return false;
|
||||
}
|
||||
|
||||
//(按顺序)加载js文件
|
||||
function min_loadJsFile(str_jsfile, func_succ, NoRandomFlag)
|
||||
{
|
||||
var domScript = document.createElement('script');
|
||||
if (!NoRandomFlag)
|
||||
{
|
||||
// str_jsfile = str_jsfile + '?' + Math.random() * 10000;
|
||||
// str_jsfile = str_jsfile + '?' + min_random(1, 10000000);
|
||||
str_jsfile = str_jsfile + '?' + min_timestamp();
|
||||
}
|
||||
domScript.src = str_jsfile;
|
||||
func_succ = func_succ || function(){};
|
||||
domScript.onload = domScript.onreadystatechange = function() {
|
||||
if (!this.readyState || 'loaded' === this.readyState || 'complete' === this.readyState) {
|
||||
func_succ();
|
||||
this.onload = this.onreadystatechange = null;
|
||||
this.parentNode.removeChild(this);
|
||||
}
|
||||
}
|
||||
document.getElementsByTagName('head')[0].appendChild(domScript);
|
||||
}
|
||||
|
||||
//生成一个GUID
|
||||
function min_guid()
|
||||
{
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
|
||||
return v.toString(16);});
|
||||
}
|
||||
|
||||
//获取时间戳
|
||||
function min_timestamp()
|
||||
{
|
||||
return new Date().getTime();
|
||||
}
|
||||
|
||||
wnd.min_copyjson = min_copyjson; //复制json对象
|
||||
wnd.min_clone = min_clone;
|
||||
wnd.min_jsontostr = min_jsontostr; //json转字符串
|
||||
wnd.min_strtojson = min_strtojson; //字符串转json
|
||||
wnd.min_inttostr = min_inttostr; //整型转字符型
|
||||
wnd.min_strtoint = min_strtoint; //字符型转整型
|
||||
|
||||
wnd.min_ltrim = min_ltrim; //去左空格
|
||||
wnd.min_rtrim = min_rtrim; //去右空格
|
||||
wnd.min_trim = min_trim; //去左右空格
|
||||
|
||||
wnd.min_div = min_div; //整除
|
||||
wnd.min_mod = min_mod; //取余数
|
||||
wnd.min_abs = min_abs; //取绝对值
|
||||
wnd.min_random = min_random; //取随机数
|
||||
wnd.min_random1 = min_random1; //取随机数1
|
||||
wnd.min_randomChar = min_randomChar; //随机字符串
|
||||
wnd.min_length = min_length; //取长度
|
||||
wnd.min_replaceAll = min_replaceAll; //字符全替换
|
||||
|
||||
wnd.min_now = min_now; //取本地当前时间
|
||||
wnd.min_day = min_day; //取本地当前日期
|
||||
wnd.min_guid = min_guid; //生成一个GUID
|
||||
|
||||
wnd.min_getQueryString = min_getQueryString; //取当前页面url中的参数值
|
||||
wnd.min_getUrlRootPath = min_getUrlRootPath; //获取当前页面的路径
|
||||
|
||||
wnd.min_setCookie = min_setCookie; //设置cookie
|
||||
wnd.min_getCookie = min_getCookie; //读取cookie
|
||||
wnd.min_delCookie = min_delCookie; //删除cookie
|
||||
|
||||
wnd.min_getdom = min_getdom; //获取一个dom
|
||||
wnd.min_setdom = min_setdom; //设置一个dom属性值
|
||||
wnd.min_uphtml = min_uphtml; //添加一段innerHTML
|
||||
|
||||
wnd.min_ontime = min_ontime; //新建一个周期性的定时器
|
||||
wnd.min_ontimeout = min_ontimeout; //新建一个一次性的定时器
|
||||
wnd.min_closetime = min_closetime; //关闭定时器
|
||||
|
||||
wnd.min_writefile_gameid = min_writefile_gameid; //本地存储数据
|
||||
wnd.min_readfile_gameid = min_readfile_gameid; //读取本地数据
|
||||
|
||||
wnd.min_encode = min_encode; //encodeURIComponent转码
|
||||
wnd.min_decode = min_decode; //decodeURIComponent解码
|
||||
|
||||
wnd.min_tcp = min_tcp; //新建一个tcp连接
|
||||
wnd.min_http = min_http; //http请求
|
||||
|
||||
wnd.min_ary_indexof = min_ary_indexof; //在数组中根据元素值查找下标
|
||||
wnd.min_ary_delval = min_ary_delval; //在数组中根据值删除元素
|
||||
wnd.min_ary_delfromto = min_ary_delfromto; //在数组中根据下标删除诺干个元素
|
||||
wnd.min_ary_delobj = min_ary_delobj; //在数组中删除某一对象元素
|
||||
wnd.min_ary_include = min_ary_include; //数组包含
|
||||
wnd.min_ary_deduct = min_ary_deduct; //数组相减
|
||||
|
||||
wnd.min_ExitsFunction = min_ExitsFunction; //是否存在函数
|
||||
wnd.min_loadJsFile = min_loadJsFile; //加载js文件
|
||||
|
||||
wnd.min_guid = min_guid; //生成一个GUID
|
||||
wnd.min_timestamp = min_timestamp; //获取时间戳
|
||||
})(window);
|
||||
@@ -0,0 +1,143 @@
|
||||
//应用类
|
||||
min_loadJsFile("class/class.app.js", function(){
|
||||
//模块类
|
||||
min_loadJsFile("class/class.mod.js", function(){
|
||||
//mysql类
|
||||
min_loadJsFile("class/class.mysql.js", function(){
|
||||
//单张牌类
|
||||
min_loadJsFile("class/class.pai.js", function(){
|
||||
//单局牌局类
|
||||
min_loadJsFile("class/class.paiju.js", function(){
|
||||
//应用列表
|
||||
min_loadJsFile("applist.js", function(){
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
var packet_face = packet_face || {};
|
||||
|
||||
//应用列表
|
||||
packet_face.applist = [];
|
||||
//给tcp客户端主动发包函数
|
||||
packet_face.SendPack_Tcp = null;
|
||||
//给http客户端主动发包函数
|
||||
packet_face.SendPack_Http = null;
|
||||
|
||||
//TCP客户端连接上
|
||||
packet_face.OnTcpConnected = function(str_tcpid)
|
||||
{
|
||||
//通知所有应用
|
||||
for (var i=0; i<packet_face.applist.length; i++)
|
||||
{
|
||||
if (packet_face.applist[i].OnTcpConnected)
|
||||
{
|
||||
packet_face.applist[i].OnTcpConnected(str_tcpid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TCP客户端断开
|
||||
packet_face.OnTcpDisConnected = function(str_tcpid)
|
||||
{
|
||||
//通知所有应用
|
||||
for (var i=0; i<packet_face.applist.length; i++)
|
||||
{
|
||||
if (packet_face.applist[i].OnTcpDisConnected)
|
||||
{
|
||||
packet_face.applist[i].OnTcpDisConnected(str_tcpid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//收到客户端的数据包
|
||||
packet_face.ReceivePack = function(pack)
|
||||
{
|
||||
if (typeof(pack) == "string")
|
||||
{
|
||||
pack = JSON.parse(pack); //转换json
|
||||
}
|
||||
|
||||
//路由应用列表
|
||||
for (var i=0; i<packet_face.applist.length; i++)
|
||||
{
|
||||
if (pack.app == packet_face.applist[i].appname)
|
||||
{
|
||||
if (packet_face.applist[i].ReceivePack)
|
||||
{
|
||||
return packet_face.applist[i].ReceivePack(pack);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//给客户端发包
|
||||
packet_face.SendPack = function(pack, toids)
|
||||
{
|
||||
if (typeof(pack) == "string")
|
||||
{
|
||||
pack = JSON.parse(pack); //转换json
|
||||
}
|
||||
|
||||
var repack = min_copyjson(pack);
|
||||
delete repack.conmode;
|
||||
delete repack.fromid;
|
||||
delete repack.ip;
|
||||
var str = JSON.stringify(repack);
|
||||
|
||||
switch (pack.conmode)
|
||||
{
|
||||
case "tcp":
|
||||
if (packet_face.SendPack_Tcp)
|
||||
{
|
||||
if (toids && (toids.length > 0))
|
||||
{
|
||||
packet_face.SendPack_Tcp(toids, str);
|
||||
}
|
||||
else
|
||||
{
|
||||
packet_face.SendPack_Tcp([pack.fromid], str);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "http":
|
||||
if (packet_face.SendPack_Http)
|
||||
{
|
||||
if (pack.fromid && (pack.fromid != ""))
|
||||
{
|
||||
packet_face.SendPack_Http(pack.fromid, str);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof global !== "undefined")
|
||||
{} else {
|
||||
global = {};
|
||||
}
|
||||
|
||||
if (typeof module !=="undefined")
|
||||
{} else {
|
||||
module = {};
|
||||
module.exports = {};
|
||||
}
|
||||
|
||||
//输出
|
||||
global.packet_face = packet_face;
|
||||
global.packet_face.OnTcpConnected = packet_face.OnTcpConnected;
|
||||
global.packet_face.OnTcpDisConnected = packet_face.OnTcpDisConnected;
|
||||
global.packet_face.ReceivePack = packet_face.ReceivePack;
|
||||
global.packet_face.SendPack = packet_face.SendPack;
|
||||
|
||||
//////////以下为固定代码
|
||||
if (module)
|
||||
{
|
||||
module.exports.packet_face = packet_face;
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
///////////////////////////////////////////////////
|
||||
////////////////////系统服务app////////////////////
|
||||
///////////////////////////////////////////////////
|
||||
var app_server = app_server || cls_app.new("server", packet_face);
|
||||
|
||||
//通道管理
|
||||
min_loadJsFile("server/channel/mod.js", function (){
|
||||
|
||||
});
|
||||
|
||||
|
||||
//TCP客户端连上
|
||||
app_server.OnTcpConnected = function(_str_tcpid) {
|
||||
for (var i = 0; i < app_server.modlist.length; i++) {
|
||||
if (app_server.modlist[i].OnTcpConnected) {
|
||||
app_server.modlist[i].OnTcpConnected(_str_tcpid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,235 @@
|
||||
///////////////////////////////////////////////////
|
||||
////////////////////// 通道管理 ///////////////////
|
||||
///////////////////////////////////////////////////
|
||||
var mod_channel = mod_channel || cls_mod.new("mod_channel", "channel", app_server);
|
||||
|
||||
//最小通道id
|
||||
mod_channel.minid = 100000;
|
||||
//最大通道id
|
||||
mod_channel.maxid = 999999;
|
||||
|
||||
//可用的通道id列表
|
||||
mod_channel.ids = [];
|
||||
mod_channel.ids.length = mod_channel.maxid - mod_channel.minid + 1;
|
||||
for (var i = 0; i < mod_channel.ids.length; i++) {
|
||||
mod_channel.ids[i] = mod_channel.minid + i;
|
||||
};
|
||||
//可用的通道id列表的有效长度
|
||||
mod_channel.validlen = mod_channel.maxid - mod_channel.minid + 1;
|
||||
|
||||
//通道列表
|
||||
mod_channel.list = [];
|
||||
mod_channel.list.length = mod_channel.maxid - mod_channel.minid + 1;
|
||||
|
||||
mod_channel.test = function(pack){
|
||||
pack.data = "123456789";
|
||||
return pack;
|
||||
}
|
||||
|
||||
//创建
|
||||
mod_channel.create = function(pack){
|
||||
//在有效通道id列表中随机数组下标
|
||||
var idx = min_random(0, mod_channel.validlen - 1);
|
||||
//确定通道id
|
||||
var id = mod_channel.ids[idx];
|
||||
//将有效数组的最后一个房号移至该位置
|
||||
if (idx < mod_channel.validlen - 1) {
|
||||
mod_channel.ids[idx] = mod_channel.ids[mod_channel.validlen - 1];
|
||||
};
|
||||
mod_channel.ids[mod_channel.validlen - 1] = 0;
|
||||
//有效数组长度减1
|
||||
mod_channel.validlen = mod_channel.validlen - 1;
|
||||
//根据通道id创建通道
|
||||
var o_channel = {};
|
||||
o_channel.id = id;
|
||||
o_channel.plist = []; //谁在通道里面
|
||||
//添加到通道列表中
|
||||
mod_channel.list[id - mod_channel.minid] = o_channel;
|
||||
|
||||
//返回前端
|
||||
pack.data = {};
|
||||
pack.data.channelid = id;
|
||||
return pack;
|
||||
}
|
||||
|
||||
//释放
|
||||
mod_channel.free = function(pack){
|
||||
var channelid = parseInt(pack.data.channelid);
|
||||
|
||||
//通道序号
|
||||
var idx = channelid - mod_channel.minid;
|
||||
|
||||
//检查通道id
|
||||
if (idx < 0 || idx >= mod_channel.list.length) {
|
||||
pack.data = {};
|
||||
pack.data.state = 1;
|
||||
pack.data.error = "通道id不存在";
|
||||
return pack;
|
||||
}
|
||||
|
||||
if (!mod_channel.list[idx]) {
|
||||
pack.data = {};
|
||||
pack.data.state = 1;
|
||||
pack.data.error = "通道id不存在";
|
||||
return pack;
|
||||
}
|
||||
|
||||
//释放通道
|
||||
mod_channel.list[idx] = null;
|
||||
|
||||
//释放通道id
|
||||
mod_channel.ids[mod_channel.validlen] = channelid;
|
||||
mod_channel.validlen = mod_channel.validlen + 1;
|
||||
|
||||
//返回前端
|
||||
pack.data = {};
|
||||
pack.data.state = 0;
|
||||
return pack;
|
||||
}
|
||||
|
||||
//加入
|
||||
mod_channel.join = function(pack){
|
||||
var channelid = parseInt(pack.data.channelid);
|
||||
|
||||
//通道序号
|
||||
var idx = channelid - mod_channel.minid;
|
||||
|
||||
//检查通道id
|
||||
if (idx < 0 || idx >= mod_channel.list.length) {
|
||||
pack.data = {};
|
||||
pack.data.state = 1;
|
||||
pack.data.error = "通道id不存在";
|
||||
return pack;
|
||||
}
|
||||
|
||||
if (!mod_channel.list[idx]) {
|
||||
pack.data = {};
|
||||
pack.data.state = 1;
|
||||
pack.data.error = "通道id不存在";
|
||||
return pack;
|
||||
}
|
||||
|
||||
o_channel = mod_channel.list[idx];
|
||||
var p = {};
|
||||
p.conmode = pack.conmode;
|
||||
p.fromid = pack.fromid;
|
||||
o_channel.plist.push(p);
|
||||
|
||||
//返回前端
|
||||
pack.data = {};
|
||||
pack.data.state = 0;
|
||||
return pack;
|
||||
}
|
||||
|
||||
//退出
|
||||
mod_channel.exit = function(pack){
|
||||
var channelid = parseInt(pack.data.channelid);
|
||||
|
||||
//通道序号
|
||||
var idx = channelid - mod_channel.minid;
|
||||
|
||||
//检查通道id
|
||||
if (idx < 0 || idx >= mod_channel.list.length) {
|
||||
pack.data = {};
|
||||
pack.data.state = 1;
|
||||
pack.data.error = "通道id不存在";
|
||||
return pack;
|
||||
}
|
||||
|
||||
if (!mod_channel.list[idx]) {
|
||||
pack.data = {};
|
||||
pack.data.state = 1;
|
||||
pack.data.error = "通道id不存在";
|
||||
return pack;
|
||||
}
|
||||
|
||||
o_channel = mod_channel.list[idx];
|
||||
for (var i = 0; i < o_channel.plist.length; i++) {
|
||||
if (o_channel.plist[i]) {
|
||||
if (o_channel.plist[i].fromid == pack.fromid) {
|
||||
o_channel.plist[i] = null;
|
||||
//返回前端
|
||||
pack.data = {};
|
||||
pack.data.state = 0;
|
||||
return pack;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//返回前端
|
||||
pack.data = {};
|
||||
pack.data.state = 1;
|
||||
pack.data.error = "未在通道内";
|
||||
return pack;
|
||||
}
|
||||
|
||||
//广播
|
||||
mod_channel.broadcast = function(pack){
|
||||
var channelid = parseInt(pack.data.channelid);
|
||||
var content = pack.data.msg;
|
||||
|
||||
//通道序号
|
||||
var idx = channelid - mod_channel.minid;
|
||||
|
||||
//检查通道id
|
||||
if (idx < 0 || idx >= mod_channel.list.length) {
|
||||
pack.data = {};
|
||||
pack.data.state = 1;
|
||||
pack.data.error = "通道id不存在";
|
||||
return pack;
|
||||
}
|
||||
|
||||
if (!mod_channel.list[idx]) {
|
||||
pack.data = {};
|
||||
pack.data.state = 1;
|
||||
pack.data.error = "通道id不存在";
|
||||
return pack;
|
||||
}
|
||||
|
||||
o_channel = mod_channel.list[idx];
|
||||
for (var i = 0; i < o_channel.plist.length; i++) {
|
||||
if (o_channel.plist[i]) {
|
||||
//广播前端
|
||||
var msg = {};
|
||||
msg.app = pack.app;
|
||||
msg.route = pack.route;
|
||||
msg.rpc = pack.rpc;
|
||||
msg.conmode = o_channel.plist[i].conmode;
|
||||
msg.fromid = o_channel.plist[i].fromid;
|
||||
msg.data = {};
|
||||
msg.data.state = 0;
|
||||
msg.data.msg = content;
|
||||
mod_channel.app.SendPack(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//断线
|
||||
mod_channel.OnTcpDisConnected = function(str_tcpid){
|
||||
for (var i = 0; i < mod_channel.list.length; i++) {
|
||||
if (mod_channel.list[i]){
|
||||
for (var j = 0; j < mod_channel.list[i].plist.length; j++) {
|
||||
if (mod_channel.list[i].plist[j]) {
|
||||
if (mod_channel.list[i].plist[j].fromid == str_tcpid) {
|
||||
//广播前端
|
||||
var msg = {};
|
||||
msg.app = mod_channel.app.appname;
|
||||
msg.route = mod_channel.routename;
|
||||
msg.rpc = "disconnected";
|
||||
msg.data = {};
|
||||
msg.data.channelid = mod_channel.list[i].id;
|
||||
msg.data.idx = j;
|
||||
for (var k = 0; k < mod_channel.list[i].plist.length; k++) {
|
||||
if (k != j){
|
||||
msg.conmode = mod_channel.list[i].plist[k].conmode;
|
||||
msg.fromid = mod_channel.list[i].plist[k].fromid;
|
||||
mod_channel.app.SendPack(msg);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
BIN
tools/server2017-64-stable/icudtl.dat
Normal file
BIN
tools/server2017-64-stable/icudtl.dat
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/libEGL.dll
Normal file
BIN
tools/server2017-64-stable/libEGL.dll
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/libGLESv2.dll
Normal file
BIN
tools/server2017-64-stable/libGLESv2.dll
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/am.pak
Normal file
BIN
tools/server2017-64-stable/locales/am.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/ar.pak
Normal file
BIN
tools/server2017-64-stable/locales/ar.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/bg.pak
Normal file
BIN
tools/server2017-64-stable/locales/bg.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/bn.pak
Normal file
BIN
tools/server2017-64-stable/locales/bn.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/ca.pak
Normal file
BIN
tools/server2017-64-stable/locales/ca.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/cs.pak
Normal file
BIN
tools/server2017-64-stable/locales/cs.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/da.pak
Normal file
BIN
tools/server2017-64-stable/locales/da.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/de.pak
Normal file
BIN
tools/server2017-64-stable/locales/de.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/el.pak
Normal file
BIN
tools/server2017-64-stable/locales/el.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/en-GB.pak
Normal file
BIN
tools/server2017-64-stable/locales/en-GB.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/en-US.pak
Normal file
BIN
tools/server2017-64-stable/locales/en-US.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/es-419.pak
Normal file
BIN
tools/server2017-64-stable/locales/es-419.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/es.pak
Normal file
BIN
tools/server2017-64-stable/locales/es.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/et.pak
Normal file
BIN
tools/server2017-64-stable/locales/et.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/fa.pak
Normal file
BIN
tools/server2017-64-stable/locales/fa.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/fi.pak
Normal file
BIN
tools/server2017-64-stable/locales/fi.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/fil.pak
Normal file
BIN
tools/server2017-64-stable/locales/fil.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/fr.pak
Normal file
BIN
tools/server2017-64-stable/locales/fr.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/gu.pak
Normal file
BIN
tools/server2017-64-stable/locales/gu.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/he.pak
Normal file
BIN
tools/server2017-64-stable/locales/he.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/hi.pak
Normal file
BIN
tools/server2017-64-stable/locales/hi.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/hr.pak
Normal file
BIN
tools/server2017-64-stable/locales/hr.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/hu.pak
Normal file
BIN
tools/server2017-64-stable/locales/hu.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/id.pak
Normal file
BIN
tools/server2017-64-stable/locales/id.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/it.pak
Normal file
BIN
tools/server2017-64-stable/locales/it.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/ja.pak
Normal file
BIN
tools/server2017-64-stable/locales/ja.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/kn.pak
Normal file
BIN
tools/server2017-64-stable/locales/kn.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/ko.pak
Normal file
BIN
tools/server2017-64-stable/locales/ko.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/lt.pak
Normal file
BIN
tools/server2017-64-stable/locales/lt.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/lv.pak
Normal file
BIN
tools/server2017-64-stable/locales/lv.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/ml.pak
Normal file
BIN
tools/server2017-64-stable/locales/ml.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/mr.pak
Normal file
BIN
tools/server2017-64-stable/locales/mr.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/ms.pak
Normal file
BIN
tools/server2017-64-stable/locales/ms.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/nb.pak
Normal file
BIN
tools/server2017-64-stable/locales/nb.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/nl.pak
Normal file
BIN
tools/server2017-64-stable/locales/nl.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/pl.pak
Normal file
BIN
tools/server2017-64-stable/locales/pl.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/pt-BR.pak
Normal file
BIN
tools/server2017-64-stable/locales/pt-BR.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/pt-PT.pak
Normal file
BIN
tools/server2017-64-stable/locales/pt-PT.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/ro.pak
Normal file
BIN
tools/server2017-64-stable/locales/ro.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/ru.pak
Normal file
BIN
tools/server2017-64-stable/locales/ru.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/sk.pak
Normal file
BIN
tools/server2017-64-stable/locales/sk.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/sl.pak
Normal file
BIN
tools/server2017-64-stable/locales/sl.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/sr.pak
Normal file
BIN
tools/server2017-64-stable/locales/sr.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/sv.pak
Normal file
BIN
tools/server2017-64-stable/locales/sv.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/sw.pak
Normal file
BIN
tools/server2017-64-stable/locales/sw.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/ta.pak
Normal file
BIN
tools/server2017-64-stable/locales/ta.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/te.pak
Normal file
BIN
tools/server2017-64-stable/locales/te.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/th.pak
Normal file
BIN
tools/server2017-64-stable/locales/th.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/tr.pak
Normal file
BIN
tools/server2017-64-stable/locales/tr.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/uk.pak
Normal file
BIN
tools/server2017-64-stable/locales/uk.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/vi.pak
Normal file
BIN
tools/server2017-64-stable/locales/vi.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/zh-CN.pak
Normal file
BIN
tools/server2017-64-stable/locales/zh-CN.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/locales/zh-TW.pak
Normal file
BIN
tools/server2017-64-stable/locales/zh-TW.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/nacl_irt_x86_64.nexe
Normal file
BIN
tools/server2017-64-stable/nacl_irt_x86_64.nexe
Normal file
Binary file not shown.
9674
tools/server2017-64-stable/natives_blob.bin
Normal file
9674
tools/server2017-64-stable/natives_blob.bin
Normal file
File diff suppressed because it is too large
Load Diff
BIN
tools/server2017-64-stable/node.dll
Normal file
BIN
tools/server2017-64-stable/node.dll
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/node_modules/nodejs-websocket.rar
generated
vendored
Normal file
BIN
tools/server2017-64-stable/node_modules/nodejs-websocket.rar
generated
vendored
Normal file
Binary file not shown.
22
tools/server2017-64-stable/node_modules/nodejs-websocket/.jshintrc
generated
vendored
Normal file
22
tools/server2017-64-stable/node_modules/nodejs-websocket/.jshintrc
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"curly": true,
|
||||
"eqeqeq": true,
|
||||
"nonew": true,
|
||||
"latedef": "nofunc",
|
||||
"unused": true,
|
||||
"noarg": true,
|
||||
"asi": true,
|
||||
"trailing": true,
|
||||
"quotmark": true,
|
||||
"strict": true,
|
||||
"undef": true,
|
||||
"expr": true,
|
||||
"newcap": true,
|
||||
"immed": true,
|
||||
"node": true,
|
||||
"camelcase": true,
|
||||
"devel": true,
|
||||
"freeze": true,
|
||||
"-W033": true,
|
||||
"-W058": true
|
||||
}
|
||||
3
tools/server2017-64-stable/node_modules/nodejs-websocket/.npmignore
generated
vendored
Normal file
3
tools/server2017-64-stable/node_modules/nodejs-websocket/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
test
|
||||
samples
|
||||
5
tools/server2017-64-stable/node_modules/nodejs-websocket/.travis.yml
generated
vendored
Normal file
5
tools/server2017-64-stable/node_modules/nodejs-websocket/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.12"
|
||||
- "4.2.1"
|
||||
- "node"
|
||||
616
tools/server2017-64-stable/node_modules/nodejs-websocket/Connection.js
generated
vendored
Normal file
616
tools/server2017-64-stable/node_modules/nodejs-websocket/Connection.js
generated
vendored
Normal file
@@ -0,0 +1,616 @@
|
||||
/**
|
||||
* @file Represents a connection (both client and server sides)
|
||||
*/
|
||||
'use strict'
|
||||
|
||||
var util = require('util'),
|
||||
events = require('events'),
|
||||
crypto = require('crypto'),
|
||||
InStream = require('./InStream'),
|
||||
OutStream = require('./OutStream'),
|
||||
frame = require('./frame'),
|
||||
Server = require('./Server')
|
||||
|
||||
/**
|
||||
* @class
|
||||
* @param {(net.Socket|tls.CleartextStream)} socket a net or tls socket
|
||||
* @param {(Server|{path:string,host:string})} parentOrUrl parent in case of server-side connection, url object in case of client-side
|
||||
* @param {Function} [callback] will be added as a listener to 'connect'
|
||||
* @inherits EventEmitter
|
||||
* @event close the numeric code and string reason will be passed
|
||||
* @event error an error object is passed
|
||||
* @event text a string is passed
|
||||
* @event binary a inStream object is passed
|
||||
* @event pong a string is passed
|
||||
* @event connect
|
||||
*/
|
||||
function Connection(socket, parentOrUrl, callback) {
|
||||
var that = this,
|
||||
connectEvent
|
||||
|
||||
if (parentOrUrl instanceof Server) {
|
||||
// Server-side connection
|
||||
this.server = parentOrUrl
|
||||
this.path = null
|
||||
this.host = null
|
||||
this.extraHeaders = null
|
||||
} else {
|
||||
// Client-side
|
||||
this.server = null
|
||||
this.path = parentOrUrl.path
|
||||
this.host = parentOrUrl.host
|
||||
this.extraHeaders = parentOrUrl.extraHeaders
|
||||
}
|
||||
|
||||
this.socket = socket
|
||||
this.readyState = this.CONNECTING
|
||||
this.buffer = new Buffer(0)
|
||||
this.frameBuffer = null // string for text frames and InStream for binary frames
|
||||
this.outStream = null // current allocated OutStream object for sending binary frames
|
||||
this.key = null // the Sec-WebSocket-Key header
|
||||
this.headers = {} // read only map of header names and values. Header names are lower-cased
|
||||
|
||||
// Set listeners
|
||||
socket.on('readable', function () {
|
||||
that.doRead()
|
||||
})
|
||||
|
||||
socket.on('error', function (err) {
|
||||
that.emit('error', err)
|
||||
})
|
||||
|
||||
if (!this.server) {
|
||||
connectEvent = socket.constructor.name === 'CleartextStream' ? 'secureConnect' : 'connect'
|
||||
socket.on(connectEvent, function () {
|
||||
that.startHandshake()
|
||||
})
|
||||
}
|
||||
|
||||
// Close listeners
|
||||
var onclose = function () {
|
||||
if (that.readyState === that.CONNECTING || that.readyState === that.OPEN) {
|
||||
that.emit('close', 1006, '')
|
||||
}
|
||||
that.readyState = this.CLOSED
|
||||
if (that.frameBuffer instanceof InStream) {
|
||||
that.frameBuffer.end()
|
||||
that.frameBuffer = null
|
||||
}
|
||||
if (that.outStream instanceof OutStream) {
|
||||
that.outStream.end()
|
||||
that.outStream = null
|
||||
}
|
||||
}
|
||||
socket.once('close', onclose)
|
||||
socket.once('finish', onclose)
|
||||
|
||||
// super constructor
|
||||
events.EventEmitter.call(this)
|
||||
if (callback) {
|
||||
this.once('connect', callback)
|
||||
}
|
||||
}
|
||||
|
||||
util.inherits(Connection, events.EventEmitter)
|
||||
module.exports = Connection
|
||||
|
||||
/**
|
||||
* Minimum size of a pack of binary data to send in a single frame
|
||||
* @property {number} binaryFragmentation
|
||||
*/
|
||||
Connection.binaryFragmentation = 512 * 1024 // .5 MiB
|
||||
|
||||
/**
|
||||
* The maximum size the internal Buffer can grow
|
||||
* If at any time it stays bigger than this, the connection will be closed with code 1009
|
||||
* This is a security measure, to avoid memory attacks
|
||||
* @property {number} maxBufferLength
|
||||
*/
|
||||
Connection.maxBufferLength = 2 * 1024 * 1024 // 2 MiB
|
||||
|
||||
/**
|
||||
* Possible ready states for the connection
|
||||
* @constant {number} CONNECTING
|
||||
* @constant {number} OPEN
|
||||
* @constant {number} CLOSING
|
||||
* @constant {number} CLOSED
|
||||
*/
|
||||
Connection.prototype.CONNECTING = 0
|
||||
Connection.prototype.OPEN = 1
|
||||
Connection.prototype.CLOSING = 2
|
||||
Connection.prototype.CLOSED = 3
|
||||
|
||||
/**
|
||||
* Send a given string to the other side
|
||||
* @param {string} str
|
||||
* @param {Function} [callback] will be executed when the data is finally written out
|
||||
*/
|
||||
Connection.prototype.sendText = function (str, callback) {
|
||||
if (this.readyState === this.OPEN) {
|
||||
if (!this.outStream) {
|
||||
return this.socket.write(frame.createTextFrame(str, !this.server), callback)
|
||||
}
|
||||
this.emit('error', new Error('You can\'t send a text frame until you finish sending binary frames'))
|
||||
}
|
||||
this.emit('error', new Error('You can\'t write to a non-open connection'))
|
||||
}
|
||||
|
||||
/**
|
||||
* Request for a OutStream to send binary data
|
||||
* @returns {OutStream}
|
||||
*/
|
||||
Connection.prototype.beginBinary = function () {
|
||||
if (this.readyState === this.OPEN) {
|
||||
if (!this.outStream) {
|
||||
return (this.outStream = new OutStream(this, Connection.binaryFragmentation))
|
||||
}
|
||||
this.emit('error', new Error('You can\'t send more binary frames until you finish sending the previous binary frames'))
|
||||
}
|
||||
this.emit('error', new Error('You can\'t write to a non-open connection'))
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a binary buffer at once
|
||||
* @param {Buffer} data
|
||||
* @param {Function} [callback] will be executed when the data is finally written out
|
||||
*/
|
||||
Connection.prototype.sendBinary = function (data, callback) {
|
||||
if (this.readyState === this.OPEN) {
|
||||
if (!this.outStream) {
|
||||
return this.socket.write(frame.createBinaryFrame(data, !this.server, true, true), callback)
|
||||
}
|
||||
this.emit('error', new Error('You can\'t send more binary frames until you finish sending the previous binary frames'))
|
||||
}
|
||||
this.emit('error', new Error('You can\'t write to a non-open connection'))
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a text or binary frame
|
||||
* @param {string|Buffer} data
|
||||
* @param {Function} [callback] will be executed when the data is finally written out
|
||||
*/
|
||||
Connection.prototype.send = function (data, callback) {
|
||||
if (typeof data === 'string') {
|
||||
this.sendText(data, callback)
|
||||
} else if (Buffer.isBuffer(data)) {
|
||||
this.sendBinary(data, callback)
|
||||
} else {
|
||||
throw new TypeError('data should be either a string or a Buffer instance')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a ping to the remote
|
||||
* @param {string} [data=''] - optional ping data
|
||||
* @fires pong when pong reply is received
|
||||
*/
|
||||
Connection.prototype.sendPing = function (data) {
|
||||
if (this.readyState === this.OPEN) {
|
||||
return this.socket.write(frame.createPingFrame(data || '', !this.server))
|
||||
}
|
||||
this.emit('error', new Error('You can\'t write to a non-open connection'))
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the connection, sending a close frame and waiting for response
|
||||
* If the connection isn't OPEN, closes it without sending a close frame
|
||||
* @param {number} [code]
|
||||
* @param {string} [reason]
|
||||
* @fires close
|
||||
*/
|
||||
Connection.prototype.close = function (code, reason) {
|
||||
if (this.readyState === this.OPEN) {
|
||||
this.socket.write(frame.createCloseFrame(code, reason, !this.server))
|
||||
this.readyState = this.CLOSING
|
||||
} else if (this.readyState !== this.CLOSED) {
|
||||
this.socket.end()
|
||||
this.readyState = this.CLOSED
|
||||
}
|
||||
this.emit('close', code, reason)
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads contents from the socket and process it
|
||||
* @fires connect
|
||||
* @private
|
||||
*/
|
||||
Connection.prototype.doRead = function () {
|
||||
var buffer, temp
|
||||
|
||||
// Fetches the data
|
||||
buffer = this.socket.read()
|
||||
if (!buffer) {
|
||||
// Waits for more data
|
||||
return
|
||||
}
|
||||
|
||||
// Save to the internal buffer
|
||||
this.buffer = Buffer.concat([this.buffer, buffer], this.buffer.length + buffer.length)
|
||||
|
||||
if (this.readyState === this.CONNECTING) {
|
||||
if (!this.readHandshake()) {
|
||||
// May have failed or we're waiting for more data
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if (this.readyState !== this.CLOSED) {
|
||||
// Try to read as many frames as possible
|
||||
while ((temp = this.extractFrame()) === true) {}
|
||||
if (temp === false) {
|
||||
// Protocol error
|
||||
this.close(1002)
|
||||
} else if (this.buffer.length > Connection.maxBufferLength) {
|
||||
// Frame too big
|
||||
this.close(1009)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and send a handshake as a client
|
||||
* @private
|
||||
*/
|
||||
Connection.prototype.startHandshake = function () {
|
||||
var str, i, key, headers, header
|
||||
key = new Buffer(16)
|
||||
for (i = 0; i < 16; i++) {
|
||||
key[i] = Math.floor(Math.random() * 256)
|
||||
}
|
||||
this.key = key.toString('base64')
|
||||
headers = {
|
||||
Host: this.host,
|
||||
Upgrade: 'websocket',
|
||||
Connection: 'Upgrade',
|
||||
'Sec-WebSocket-Key': this.key,
|
||||
'Sec-WebSocket-Version': '13'
|
||||
}
|
||||
|
||||
for (header in this.extraHeaders) {
|
||||
headers[header] = this.extraHeaders[header]
|
||||
}
|
||||
|
||||
str = this.buildRequest('GET ' + this.path + ' HTTP/1.1', headers)
|
||||
this.socket.write(str)
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to read the handshake from the internal buffer
|
||||
* If it succeeds, the handshake data is consumed from the internal buffer
|
||||
* @returns {boolean} - whether the handshake was done
|
||||
* @private
|
||||
*/
|
||||
Connection.prototype.readHandshake = function () {
|
||||
var found = false,
|
||||
i, data
|
||||
|
||||
// Do the handshake and try to connect
|
||||
if (this.buffer.length > Connection.maxBufferLength) {
|
||||
// Too big for a handshake
|
||||
this.socket.end(this.server ? 'HTTP/1.1 400 Bad Request\r\n\r\n' : undefined)
|
||||
return false
|
||||
}
|
||||
|
||||
// Search for '\r\n\r\n'
|
||||
for (i = 0; i < this.buffer.length - 3; i++) {
|
||||
if (this.buffer[i] === 13 && this.buffer[i + 2] === 13 &&
|
||||
this.buffer[i + 1] === 10 && this.buffer[i + 3] === 10) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
// Wait for more data
|
||||
return false
|
||||
}
|
||||
data = this.buffer.slice(0, i + 4).toString().split('\r\n')
|
||||
if (this.server ? this.answerHandshake(data) : this.checkHandshake(data)) {
|
||||
this.buffer = this.buffer.slice(i + 4)
|
||||
this.readyState = this.OPEN
|
||||
this.emit('connect')
|
||||
return true
|
||||
} else {
|
||||
this.socket.end(this.server ? 'HTTP/1.1 400 Bad Request\r\n\r\n' : undefined)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read headers from HTTP protocol
|
||||
* Update the Connection#headers property
|
||||
* @param {string[]} lines one for each '\r\n'-separated HTTP request line
|
||||
* @private
|
||||
*/
|
||||
Connection.prototype.readHeaders = function (lines) {
|
||||
var i, match
|
||||
|
||||
// Extract all headers
|
||||
// Ignore bad-formed lines and ignore the first line (HTTP header)
|
||||
for (i = 1; i < lines.length; i++) {
|
||||
if ((match = lines[i].match(/^([a-z-]+): (.+)$/i))) {
|
||||
this.headers[match[1].toLowerCase()] = match[2]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process and check a handshake answered by a server
|
||||
* @param {string[]} lines one for each '\r\n'-separated HTTP request line
|
||||
* @returns {boolean} if the handshake was sucessful. If not, the connection must be closed
|
||||
* @private
|
||||
*/
|
||||
Connection.prototype.checkHandshake = function (lines) {
|
||||
var key, sha1
|
||||
|
||||
// First line
|
||||
if (lines.length < 4) {
|
||||
return false
|
||||
}
|
||||
if (!lines[0].match(/^HTTP\/\d\.\d 101( .*)?$/i)) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Extract all headers
|
||||
this.readHeaders(lines)
|
||||
|
||||
// Validate necessary headers
|
||||
if (!('upgrade' in this.headers) ||
|
||||
!('sec-websocket-accept' in this.headers) ||
|
||||
!('connection' in this.headers)) {
|
||||
return false
|
||||
}
|
||||
if (this.headers.upgrade.toLowerCase() !== 'websocket' ||
|
||||
this.headers.connection.toLowerCase().split(', ').indexOf('upgrade') === -1) {
|
||||
return false
|
||||
}
|
||||
key = this.headers['sec-websocket-accept']
|
||||
|
||||
// Check the key
|
||||
sha1 = crypto.createHash('sha1')
|
||||
sha1.end(this.key + '258EAFA5-E914-47DA-95CA-C5AB0DC85B11')
|
||||
if (key !== sha1.read().toString('base64')) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Process and answer a handshake started by a client
|
||||
* @param {string[]} lines one for each '\r\n'-separated HTTP request line
|
||||
* @returns {boolean} if the handshake was sucessful. If not, the connection must be closed with error 400-Bad Request
|
||||
* @private
|
||||
*/
|
||||
Connection.prototype.answerHandshake = function (lines) {
|
||||
var path, key, sha1
|
||||
|
||||
// First line
|
||||
if (lines.length < 6) {
|
||||
return false
|
||||
}
|
||||
path = lines[0].match(/^GET (.+) HTTP\/\d\.\d$/i)
|
||||
if (!path) {
|
||||
return false
|
||||
}
|
||||
this.path = path[1]
|
||||
|
||||
// Extract all headers
|
||||
this.readHeaders(lines)
|
||||
|
||||
// Validate necessary headers
|
||||
if (!('host' in this.headers) ||
|
||||
!('sec-websocket-key' in this.headers) ||
|
||||
!('upgrade' in this.headers) ||
|
||||
!('connection' in this.headers)) {
|
||||
return false
|
||||
}
|
||||
if (this.headers.upgrade.toLowerCase() !== 'websocket' ||
|
||||
this.headers.connection.toLowerCase().split(', ').indexOf('upgrade') === -1) {
|
||||
return false
|
||||
}
|
||||
if (this.headers['sec-websocket-version'] !== '13') {
|
||||
return false
|
||||
}
|
||||
|
||||
this.key = this.headers['sec-websocket-key']
|
||||
|
||||
// Build and send the response
|
||||
sha1 = crypto.createHash('sha1')
|
||||
sha1.end(this.key + '258EAFA5-E914-47DA-95CA-C5AB0DC85B11')
|
||||
key = sha1.read().toString('base64')
|
||||
this.socket.write(this.buildRequest('HTTP/1.1 101 Switching Protocols', {
|
||||
Upgrade: 'websocket',
|
||||
Connection: 'Upgrade',
|
||||
'Sec-WebSocket-Accept': key
|
||||
}))
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to extract frame contents from the buffer (and execute it)
|
||||
* @returns {(boolean|undefined)} false=something went wrong (the connection must be closed); undefined=there isn't enough data to catch a frame; true=the frame was successfully fetched and executed
|
||||
* @private
|
||||
*/
|
||||
Connection.prototype.extractFrame = function () {
|
||||
var fin, opcode, B, HB, mask, len, payload, start, i, hasMask
|
||||
|
||||
if (this.buffer.length < 2) {
|
||||
return
|
||||
}
|
||||
|
||||
// Is this the last frame in a sequence?
|
||||
B = this.buffer[0]
|
||||
HB = B >> 4
|
||||
if (HB % 8) {
|
||||
// RSV1, RSV2 and RSV3 must be clear
|
||||
return false
|
||||
}
|
||||
fin = HB === 8
|
||||
opcode = B % 16
|
||||
|
||||
if (opcode !== 0 && opcode !== 1 && opcode !== 2 &&
|
||||
opcode !== 8 && opcode !== 9 && opcode !== 10) {
|
||||
// Invalid opcode
|
||||
return false
|
||||
}
|
||||
if (opcode >= 8 && !fin) {
|
||||
// Control frames must not be fragmented
|
||||
return false
|
||||
}
|
||||
|
||||
B = this.buffer[1]
|
||||
hasMask = B >> 7
|
||||
if ((this.server && !hasMask) || (!this.server && hasMask)) {
|
||||
// Frames sent by clients must be masked
|
||||
return false
|
||||
}
|
||||
len = B % 128
|
||||
start = hasMask ? 6 : 2
|
||||
|
||||
if (this.buffer.length < start + len) {
|
||||
// Not enough data in the buffer
|
||||
return
|
||||
}
|
||||
|
||||
// Get the actual payload length
|
||||
if (len === 126) {
|
||||
len = this.buffer.readUInt16BE(2)
|
||||
start += 2
|
||||
} else if (len === 127) {
|
||||
// Warning: JS can only store up to 2^53 in its number format
|
||||
len = this.buffer.readUInt32BE(2) * Math.pow(2, 32) + this.buffer.readUInt32BE(6)
|
||||
start += 8
|
||||
}
|
||||
if (this.buffer.length < start + len) {
|
||||
return
|
||||
}
|
||||
|
||||
// Extract the payload
|
||||
payload = this.buffer.slice(start, start + len)
|
||||
if (hasMask) {
|
||||
// Decode with the given mask
|
||||
mask = this.buffer.slice(start - 4, start)
|
||||
for (i = 0; i < payload.length; i++) {
|
||||
payload[i] ^= mask[i % 4]
|
||||
}
|
||||
}
|
||||
this.buffer = this.buffer.slice(start + len)
|
||||
|
||||
// Proceeds to frame processing
|
||||
return this.processFrame(fin, opcode, payload)
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a given frame received
|
||||
* @param {boolean} fin
|
||||
* @param {number} opcode
|
||||
* @param {Buffer} payload
|
||||
* @returns {boolean} false if any error occurs, true otherwise
|
||||
* @fires text
|
||||
* @fires binary
|
||||
* @private
|
||||
*/
|
||||
Connection.prototype.processFrame = function (fin, opcode, payload) {
|
||||
if (opcode === 8) {
|
||||
// Close frame
|
||||
if (this.readyState === this.CLOSING) {
|
||||
this.socket.end()
|
||||
} else if (this.readyState === this.OPEN) {
|
||||
this.processCloseFrame(payload)
|
||||
}
|
||||
return true
|
||||
} else if (opcode === 9) {
|
||||
// Ping frame
|
||||
if (this.readyState === this.OPEN) {
|
||||
this.socket.write(frame.createPongFrame(payload.toString(), !this.server))
|
||||
}
|
||||
return true
|
||||
} else if (opcode === 10) {
|
||||
// Pong frame
|
||||
this.emit('pong', payload.toString())
|
||||
return true
|
||||
}
|
||||
|
||||
if (this.readyState !== this.OPEN) {
|
||||
// Ignores if the connection isn't opened anymore
|
||||
return true
|
||||
}
|
||||
|
||||
if (opcode === 0 && this.frameBuffer === null) {
|
||||
// Unexpected continuation frame
|
||||
return false
|
||||
} else if (opcode !== 0 && this.frameBuffer !== null) {
|
||||
// Last sequence didn't finished correctly
|
||||
return false
|
||||
}
|
||||
|
||||
if (!opcode) {
|
||||
// Get the current opcode for fragmented frames
|
||||
opcode = typeof this.frameBuffer === 'string' ? 1 : 2
|
||||
}
|
||||
|
||||
if (opcode === 1) {
|
||||
// Save text frame
|
||||
payload = payload.toString()
|
||||
this.frameBuffer = this.frameBuffer ? this.frameBuffer + payload : payload
|
||||
|
||||
if (fin) {
|
||||
// Emits 'text' event
|
||||
this.emit('text', this.frameBuffer)
|
||||
this.frameBuffer = null
|
||||
}
|
||||
} else {
|
||||
// Sends the buffer for InStream object
|
||||
if (!this.frameBuffer) {
|
||||
// Emits the 'binary' event
|
||||
this.frameBuffer = new InStream
|
||||
this.emit('binary', this.frameBuffer)
|
||||
}
|
||||
this.frameBuffer.addData(payload)
|
||||
|
||||
if (fin) {
|
||||
// Emits 'end' event
|
||||
this.frameBuffer.end()
|
||||
this.frameBuffer = null
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a close frame, emitting the close event and sending back the frame
|
||||
* @param {Buffer} payload
|
||||
* @fires close
|
||||
* @private
|
||||
*/
|
||||
Connection.prototype.processCloseFrame = function (payload) {
|
||||
var code, reason
|
||||
if (payload.length >= 2) {
|
||||
code = payload.readUInt16BE(0)
|
||||
reason = payload.slice(2).toString()
|
||||
} else {
|
||||
code = 1005
|
||||
reason = ''
|
||||
}
|
||||
this.socket.write(frame.createCloseFrame(code, reason, !this.server))
|
||||
this.readyState = this.CLOSED
|
||||
this.emit('close', code, reason)
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the header string
|
||||
* @param {string} requestLine
|
||||
* @param {Object<string>} headers
|
||||
* @returns {string}
|
||||
* @private
|
||||
*/
|
||||
Connection.prototype.buildRequest = function (requestLine, headers) {
|
||||
var headerString = requestLine + '\r\n',
|
||||
headerName
|
||||
|
||||
for (headerName in headers) {
|
||||
headerString += headerName + ': ' + headers[headerName] + '\r\n'
|
||||
}
|
||||
|
||||
return headerString + '\r\n'
|
||||
}
|
||||
16
tools/server2017-64-stable/node_modules/nodejs-websocket/HISTORY.md
generated
vendored
Normal file
16
tools/server2017-64-stable/node_modules/nodejs-websocket/HISTORY.md
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
# 1.6.0
|
||||
* Added: `Server#close` as a short hand for `Server#socket.close`
|
||||
|
||||
# 1.5.0
|
||||
* Added: `Connection#send` as a short hand for `Connection#sendText` or `Connection#sendBinary`, depending on the data type (string or Buffer)
|
||||
|
||||
# 1.4.1
|
||||
* Added: example to README
|
||||
|
||||
# 1.4.0
|
||||
* Added: `extraHeaders` option in `ws.connect(URL, [options], [callback])` to let one add custom headers to the HTTP handshake request
|
||||
|
||||
# 1.3.0
|
||||
|
||||
* Added: `Connection#sendPing([data=''])`
|
||||
* Added: `pong(data)` event
|
||||
44
tools/server2017-64-stable/node_modules/nodejs-websocket/InStream.js
generated
vendored
Normal file
44
tools/server2017-64-stable/node_modules/nodejs-websocket/InStream.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* @file Simple wrapper for stream.Readable, used for receiving binary data
|
||||
*/
|
||||
'use strict'
|
||||
|
||||
var util = require('util'),
|
||||
stream = require('stream')
|
||||
|
||||
/**
|
||||
* Represents the readable stream for binary frames
|
||||
* @class
|
||||
* @event readable
|
||||
* @event end
|
||||
*/
|
||||
function InStream() {
|
||||
stream.Readable.call(this)
|
||||
}
|
||||
|
||||
module.exports = InStream
|
||||
|
||||
util.inherits(InStream, stream.Readable)
|
||||
|
||||
/**
|
||||
* No logic here, the pushs are made outside _read
|
||||
* @private
|
||||
*/
|
||||
InStream.prototype._read = function () {}
|
||||
|
||||
/**
|
||||
* Add more data to the stream and fires "readable" event
|
||||
* @param {Buffer} data
|
||||
* @private
|
||||
*/
|
||||
InStream.prototype.addData = function (data) {
|
||||
this.push(data)
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates there is no more data to add to the stream
|
||||
* @private
|
||||
*/
|
||||
InStream.prototype.end = function () {
|
||||
this.push(null)
|
||||
}
|
||||
21
tools/server2017-64-stable/node_modules/nodejs-websocket/LICENSE
generated
vendored
Normal file
21
tools/server2017-64-stable/node_modules/nodejs-websocket/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Guilherme Souza
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
59
tools/server2017-64-stable/node_modules/nodejs-websocket/OutStream.js
generated
vendored
Normal file
59
tools/server2017-64-stable/node_modules/nodejs-websocket/OutStream.js
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* @file Simple wrapper for stream.Writable, used for sending binary data
|
||||
*/
|
||||
'use strict'
|
||||
|
||||
var util = require('util'),
|
||||
stream = require('stream'),
|
||||
frame = require('./frame')
|
||||
|
||||
/**
|
||||
* @class Represents the writable stream for binary frames
|
||||
* @param {Connection} connection
|
||||
* @param {number} minSize
|
||||
*/
|
||||
function OutStream(connection, minSize) {
|
||||
var that = this
|
||||
this.connection = connection
|
||||
this.minSize = minSize
|
||||
this.buffer = new Buffer(0)
|
||||
this.hasSent = false // Indicates if any frame has been sent yet
|
||||
stream.Writable.call(this)
|
||||
this.on('finish', function () {
|
||||
if (that.connection.readyState === that.connection.OPEN) {
|
||||
// Ignore if not connected anymore
|
||||
that.connection.socket.write(frame.createBinaryFrame(that.buffer, !that.connection.server, !that.hasSent, true))
|
||||
}
|
||||
that.connection.outStream = null
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = OutStream
|
||||
|
||||
|
||||
util.inherits(OutStream, stream.Writable)
|
||||
|
||||
/**
|
||||
* @param {Buffer} chunk
|
||||
* @param {string} encoding
|
||||
* @param {Function} callback
|
||||
* @private
|
||||
*/
|
||||
OutStream.prototype._write = function (chunk, encoding, callback) {
|
||||
var frameBuffer
|
||||
this.buffer = Buffer.concat([this.buffer, chunk], this.buffer.length + chunk.length)
|
||||
if (this.buffer.length >= this.minSize) {
|
||||
if (this.connection.readyState === this.connection.OPEN) {
|
||||
// Ignore if not connected anymore
|
||||
frameBuffer = frame.createBinaryFrame(this.buffer, !this.connection.server, !this.hasSent, false)
|
||||
this.connection.socket.write(frameBuffer, encoding, callback)
|
||||
}
|
||||
this.buffer = new Buffer(0)
|
||||
this.hasSent = true
|
||||
if (this.connection.readyState !== this.connection.OPEN) {
|
||||
callback()
|
||||
}
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
192
tools/server2017-64-stable/node_modules/nodejs-websocket/README.md
generated
vendored
Normal file
192
tools/server2017-64-stable/node_modules/nodejs-websocket/README.md
generated
vendored
Normal file
@@ -0,0 +1,192 @@
|
||||
# Nodejs Websocket
|
||||
[](https://travis-ci.org/sitegui/nodejs-websocket)
|
||||
[](https://inch-ci.org/github/sitegui/nodejs-websocket)
|
||||
[](https://david-dm.org/sitegui/nodejs-websocket)
|
||||
|
||||
A nodejs module for websocket server and client
|
||||
|
||||
# How to use it
|
||||
Install with `npm install nodejs-websocket` or put all files in a folder called "nodejs-websocket", and:
|
||||
```javascript
|
||||
var ws = require("nodejs-websocket")
|
||||
|
||||
// Scream server example: "hi" -> "HI!!!"
|
||||
var server = ws.createServer(function (conn) {
|
||||
console.log("New connection")
|
||||
conn.on("text", function (str) {
|
||||
console.log("Received "+str)
|
||||
conn.sendText(str.toUpperCase()+"!!!")
|
||||
})
|
||||
conn.on("close", function (code, reason) {
|
||||
console.log("Connection closed")
|
||||
})
|
||||
}).listen(8001)
|
||||
```
|
||||
|
||||
Se other examples inside the folder samples
|
||||
|
||||
# ws
|
||||
The main object, returned by `require("nodejs-websocket")`.
|
||||
|
||||
## ws.createServer([options], [callback])
|
||||
Returns a new `Server` object.
|
||||
|
||||
The `options` is an optional object that will be handed to net.createServer() to create an ordinary socket.
|
||||
If it has a property called "secure" with value `true`, tls.createServer() will be used instead.
|
||||
|
||||
The `callback` is a function which is automatically added to the `"connection"` event.
|
||||
|
||||
## ws.connect(URL, [options], [callback])
|
||||
Returns a new `Connection` object, representing a websocket client connection
|
||||
|
||||
`URL` is a string with the format "ws://localhost:8000/chat" (the port can be omitted)
|
||||
|
||||
`options` is an object that will be passed to net.connect() (or tls.connect() if the protocol is "wss:").
|
||||
The properties "host" and "port" will be read from the `URL`.
|
||||
The property `extraHeaders` will be used to add more headers to the HTTP handshake request.
|
||||
|
||||
`callback` will be added as "connect" listener
|
||||
|
||||
## ws.setBinaryFragmentation(bytes)
|
||||
Sets the minimum size of a pack of binary data to send in a single frame (default: 512kiB)
|
||||
|
||||
## ws.setMaxBufferLength(bytes)
|
||||
Set the maximum size the internal Buffer can grow (default: 2MiB)
|
||||
If at any time it stays bigger than this, the connection will be closed with code 1009
|
||||
This is a security measure, to avoid memory attacks
|
||||
|
||||
# Server
|
||||
The class that represents a websocket server, much like a HTTP server
|
||||
|
||||
## server.listen(port, [host], [callback])
|
||||
Starts accepting connections on a given `port` and `host`.
|
||||
|
||||
If the `host` is omitted, the server will accept connections directed to any IPv4 address (INADDR_ANY).
|
||||
|
||||
A `port` value of zero will assign a random port.
|
||||
|
||||
`callback` will be added as an listener for the `'listening'` event.
|
||||
|
||||
## server.close([callback])
|
||||
Stops the server from accepting new connections and keeps existing connections. This function is asynchronous, the server is finally closed when all connections are ended and the server emits a 'close' event. The optional callback will be called once the 'close' event occurs.
|
||||
|
||||
## server.socket
|
||||
The underlying socket, returned by net.createServer or tls.createServer
|
||||
|
||||
## server.connections
|
||||
An Array with all connected clients. It's useful for broadcasting a message:
|
||||
```javascript
|
||||
function broadcast(server, msg) {
|
||||
server.connections.forEach(function (conn) {
|
||||
conn.sendText(msg)
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
## Event: 'listening()'
|
||||
Emitted when the server has been bound after calling server.listen
|
||||
|
||||
## Event: 'close()'
|
||||
Emitted when the server closes. Note that if connections exist, this event is not emitted until all connections are completely ended.
|
||||
|
||||
## Event: 'error(errObj)'
|
||||
Emitted when an error occurs. The 'close' event will be called directly following this event.
|
||||
|
||||
## Event: 'connection(conn)'
|
||||
Emitted when a new connection is made successfully (after the handshake have been completed). conn is an instance of Connection
|
||||
|
||||
# Connection
|
||||
The class that represents a connection, either a client-created (accepted by a nodejs ws server) or client connection.
|
||||
The websocket protocol has two types of data frames: text and binary.
|
||||
Text frames are implemented as simple send function and receive event.
|
||||
Binary frames are implemented as streams: when you receive binary data, you get a ReadableStream; to send binary data, you must ask for a WritableStream and write into it.
|
||||
The binary data will be divided into frames and be sent over the socket.
|
||||
|
||||
You cannot send text data while sending binary data. If you try to do so, the connection will emit an "error" event
|
||||
|
||||
## connection.sendText(str, [callback])
|
||||
Sends a given string to the other side. You can't send text data in the middle of a binary transmission.
|
||||
|
||||
`callback` will be added as a listener to write operation over the socket
|
||||
|
||||
## connection.beginBinary()
|
||||
Asks the connection to begin transmitting binary data. Returns a WritableStream.
|
||||
The binary transmission will end when the WritableStream finishes (like when you call .end on it)
|
||||
|
||||
## connection.sendBinary(data, [callback])
|
||||
Sends a single chunk of binary data (like calling connection.beginBinary().end(data))
|
||||
|
||||
`callback` will be added as a listener to write operation over the socket
|
||||
|
||||
## connection.send(data, [callback])
|
||||
Sends a given string or Buffer to the other side. This is simply an alias for `sendText()` if data is a string or `sendBinary()` if the data is a Buffer.
|
||||
|
||||
`callback` will be added as a listener to write operation over the socket
|
||||
|
||||
## connection.sendPing([data=''])
|
||||
Sends a [ping](http://tools.ietf.org/html/rfc6455#section-5.5.2) with optional payload
|
||||
|
||||
## connection.close([code, [reason]])
|
||||
Starts the closing handshake (sends a close frame)
|
||||
|
||||
## connection.socket
|
||||
The underlying net or tls socket
|
||||
|
||||
## connection.server
|
||||
If the connection was accepted by a nodejs server, a reference to it will be saved here. null otherwise
|
||||
|
||||
## connection.readyState
|
||||
One of these constants, representing the current state of the connection. Only an open connection can be used to send/receive data.
|
||||
* connection.CONNECTING (waiting for handshake completion)
|
||||
* connection.OPEN
|
||||
* connection.CLOSING (waiting for the answer to a close frame)
|
||||
* connection.CLOSED
|
||||
|
||||
## connection.outStream
|
||||
Stores the OutStream object returned by connection.beginBinary(). null if there is no current binary data beeing sent.
|
||||
|
||||
## connection.path
|
||||
For a connection accepted by a server, it is a string representing the path to which the connection was made (example: "/chat"). null otherwise
|
||||
|
||||
## connection.headers
|
||||
Read only map of header names and values. Header names are lower-cased
|
||||
|
||||
## Event: 'close(code, reason)'
|
||||
Emitted when the connection is closed by any side
|
||||
|
||||
## Event: 'error(err)'
|
||||
Emitted in case of error (like trying to send text data while still sending binary data)
|
||||
|
||||
## Event: 'text(str)'
|
||||
Emitted when a text is received. `str` is a string
|
||||
|
||||
## Event: 'binary(inStream)'
|
||||
Emitted when the beginning of binary data is received. `inStream` is a [ReadableStream](https://nodejs.org/api/stream.html#stream_class_stream_readable):
|
||||
```javascript
|
||||
var server = ws.createServer(function (conn) {
|
||||
console.log("New connection")
|
||||
conn.on("binary", function (inStream) {
|
||||
// Empty buffer for collecting binary data
|
||||
var data = new Buffer(0)
|
||||
// Read chunks of binary data and add to the buffer
|
||||
inStream.on("readable", function () {
|
||||
var newData = inStream.read()
|
||||
if (newData)
|
||||
data = Buffer.concat([data, newData], data.length+newData.length)
|
||||
})
|
||||
inStream.on("end", function () {
|
||||
console.log("Received " + data.length + " bytes of binary data")
|
||||
process_my_data(data)
|
||||
})
|
||||
})
|
||||
conn.on("close", function (code, reason) {
|
||||
console.log("Connection closed")
|
||||
})
|
||||
}).listen(8001)
|
||||
```
|
||||
|
||||
## Event: 'connect()'
|
||||
Emitted when the connection is fully established (after the handshake)
|
||||
|
||||
## Event: 'pong(data)'
|
||||
Emitted when a [pong](http://tools.ietf.org/html/rfc6455#section-5.5.3) is received, usually after a ping was sent. `data` is the pong payload, as a string
|
||||
113
tools/server2017-64-stable/node_modules/nodejs-websocket/Server.js
generated
vendored
Normal file
113
tools/server2017-64-stable/node_modules/nodejs-websocket/Server.js
generated
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
* @file Represents a websocket server
|
||||
*/
|
||||
'use strict'
|
||||
|
||||
function nop() {}
|
||||
|
||||
var util = require('util'),
|
||||
net = require('net'),
|
||||
tls = require('tls'),
|
||||
events = require('events'),
|
||||
Connection
|
||||
|
||||
/**
|
||||
* Creates a new ws server and starts listening for new connections
|
||||
* @class
|
||||
* @param {boolean} secure indicates if it should use tls
|
||||
* @param {Object} [options] will be passed to net.createServer() or tls.createServer()
|
||||
* @param {Function} [callback] will be added as "connection" listener
|
||||
* @inherits EventEmitter
|
||||
* @event listening
|
||||
* @event close
|
||||
* @event error an error object is passed
|
||||
* @event connection a Connection object is passed
|
||||
*/
|
||||
function Server(secure, options, callback) {
|
||||
var that = this
|
||||
|
||||
if (typeof options === 'function') {
|
||||
callback = options
|
||||
options = undefined
|
||||
}
|
||||
|
||||
var onConnection = function (socket) {
|
||||
var conn = new Connection(socket, that, function () {
|
||||
that.connections.push(conn)
|
||||
conn.removeListener('error', nop)
|
||||
that.emit('connection', conn)
|
||||
})
|
||||
conn.on('close', function () {
|
||||
var pos = that.connections.indexOf(conn)
|
||||
if (pos !== -1) {
|
||||
that.connections.splice(pos, 1)
|
||||
}
|
||||
})
|
||||
|
||||
// Ignore errors before the connection is established
|
||||
conn.on('error', nop)
|
||||
}
|
||||
|
||||
if (secure) {
|
||||
this.socket = tls.createServer(options, onConnection)
|
||||
} else {
|
||||
this.socket = net.createServer(options, onConnection)
|
||||
}
|
||||
|
||||
this.socket.on('close', function () {
|
||||
that.emit('close')
|
||||
})
|
||||
this.socket.on('error', function (err) {
|
||||
that.emit('error', err)
|
||||
})
|
||||
this.connections = []
|
||||
|
||||
// super constructor
|
||||
events.EventEmitter.call(this)
|
||||
if (callback) {
|
||||
this.on('connection', callback)
|
||||
}
|
||||
}
|
||||
|
||||
util.inherits(Server, events.EventEmitter)
|
||||
module.exports = Server
|
||||
|
||||
Connection = require('./Connection')
|
||||
|
||||
/**
|
||||
* Start listening for connections
|
||||
* @param {number} port
|
||||
* @param {string} [host]
|
||||
* @param {Function} [callback] will be added as "connection" listener
|
||||
*/
|
||||
Server.prototype.listen = function (port, host, callback) {
|
||||
var that = this
|
||||
|
||||
if (typeof host === 'function') {
|
||||
callback = host
|
||||
host = undefined
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
this.on('listening', callback)
|
||||
}
|
||||
|
||||
this.socket.listen(port, host, function () {
|
||||
that.emit('listening')
|
||||
})
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the server from accepting new connections and keeps existing connections.
|
||||
* This function is asynchronous, the server is finally closed when all connections are ended and the server emits a 'close' event.
|
||||
* The optional callback will be called once the 'close' event occurs.
|
||||
* @param {function()} [callback]
|
||||
*/
|
||||
Server.prototype.close = function (callback) {
|
||||
if (callback) {
|
||||
this.once('close', callback)
|
||||
}
|
||||
this.socket.close()
|
||||
}
|
||||
152
tools/server2017-64-stable/node_modules/nodejs-websocket/frame.js
generated
vendored
Normal file
152
tools/server2017-64-stable/node_modules/nodejs-websocket/frame.js
generated
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
/**
|
||||
* @file Utility functions for creating frames
|
||||
*/
|
||||
'use strict'
|
||||
|
||||
/**
|
||||
* Creates a text frame
|
||||
* @param {string} data
|
||||
* @param {boolean} [masked=false] if the frame should be masked
|
||||
* @returns {Buffer}
|
||||
* @private
|
||||
*/
|
||||
exports.createTextFrame = function (data, masked) {
|
||||
var payload, meta
|
||||
|
||||
payload = new Buffer(data)
|
||||
meta = generateMetaData(true, 1, masked === undefined ? false : masked, payload)
|
||||
|
||||
return Buffer.concat([meta, payload], meta.length + payload.length)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a binary frame
|
||||
* @param {Buffer} data
|
||||
* @param {boolean} [masked=false] if the frame should be masked
|
||||
* @param {boolean} [first=true] if this is the first frame in a sequence
|
||||
* @param {boolean} [fin=true] if this is the final frame in a sequence
|
||||
* @returns {Buffer}
|
||||
* @private
|
||||
*/
|
||||
exports.createBinaryFrame = function (data, masked, first, fin) {
|
||||
var payload, meta
|
||||
|
||||
first = first === undefined ? true : first
|
||||
masked = masked === undefined ? false : masked
|
||||
if (masked) {
|
||||
payload = new Buffer(data.length)
|
||||
data.copy(payload)
|
||||
} else {
|
||||
payload = data
|
||||
}
|
||||
meta = generateMetaData(fin === undefined ? true : fin, first ? 2 : 0, masked, payload)
|
||||
|
||||
return Buffer.concat([meta, payload], meta.length + payload.length)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a close frame
|
||||
* @param {number} code
|
||||
* @param {string} [reason='']
|
||||
* @param {boolean} [masked=false] if the frame should be masked
|
||||
* @returns {Buffer}
|
||||
* @private
|
||||
*/
|
||||
exports.createCloseFrame = function (code, reason, masked) {
|
||||
var payload, meta
|
||||
|
||||
if (code !== undefined && code !== 1005) {
|
||||
payload = new Buffer(reason === undefined ? '--' : '--' + reason)
|
||||
payload.writeUInt16BE(code, 0)
|
||||
} else {
|
||||
payload = new Buffer(0)
|
||||
}
|
||||
meta = generateMetaData(true, 8, masked === undefined ? false : masked, payload)
|
||||
|
||||
return Buffer.concat([meta, payload], meta.length + payload.length)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a ping frame
|
||||
* @param {string} data
|
||||
* @param {boolean} [masked=false] if the frame should be masked
|
||||
* @returns {Buffer}
|
||||
* @private
|
||||
*/
|
||||
exports.createPingFrame = function (data, masked) {
|
||||
var payload, meta
|
||||
|
||||
payload = new Buffer(data)
|
||||
meta = generateMetaData(true, 9, masked === undefined ? false : masked, payload)
|
||||
|
||||
return Buffer.concat([meta, payload], meta.length + payload.length)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a pong frame
|
||||
* @param {string} data
|
||||
* @param {boolean} [masked=false] if the frame should be masked
|
||||
* @returns {Buffer}
|
||||
* @private
|
||||
*/
|
||||
exports.createPongFrame = function (data, masked) {
|
||||
var payload, meta
|
||||
|
||||
payload = new Buffer(data)
|
||||
meta = generateMetaData(true, 10, masked === undefined ? false : masked, payload)
|
||||
|
||||
return Buffer.concat([meta, payload], meta.length + payload.length)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the meta-data portion of the frame
|
||||
* If the frame is masked, the payload is altered accordingly
|
||||
* @param {boolean} fin
|
||||
* @param {number} opcode
|
||||
* @param {boolean} masked
|
||||
* @param {Buffer} payload
|
||||
* @returns {Buffer}
|
||||
* @private
|
||||
*/
|
||||
function generateMetaData(fin, opcode, masked, payload) {
|
||||
var len, meta, start, mask, i
|
||||
|
||||
len = payload.length
|
||||
|
||||
// Creates the buffer for meta-data
|
||||
meta = new Buffer(2 + (len < 126 ? 0 : (len < 65536 ? 2 : 8)) + (masked ? 4 : 0))
|
||||
|
||||
// Sets fin and opcode
|
||||
meta[0] = (fin ? 128 : 0) + opcode
|
||||
|
||||
// Sets the mask and length
|
||||
meta[1] = masked ? 128 : 0
|
||||
start = 2
|
||||
if (len < 126) {
|
||||
meta[1] += len
|
||||
} else if (len < 65536) {
|
||||
meta[1] += 126
|
||||
meta.writeUInt16BE(len, 2)
|
||||
start += 2
|
||||
} else {
|
||||
// Warning: JS doesn't support integers greater than 2^53
|
||||
meta[1] += 127
|
||||
meta.writeUInt32BE(Math.floor(len / Math.pow(2, 32)), 2)
|
||||
meta.writeUInt32BE(len % Math.pow(2, 32), 6)
|
||||
start += 8
|
||||
}
|
||||
|
||||
// Set the mask-key
|
||||
if (masked) {
|
||||
mask = new Buffer(4)
|
||||
for (i = 0; i < 4; i++) {
|
||||
meta[start + i] = mask[i] = Math.floor(Math.random() * 256)
|
||||
}
|
||||
for (i = 0; i < payload.length; i++) {
|
||||
payload[i] ^= mask[i % 4]
|
||||
}
|
||||
start += 4
|
||||
}
|
||||
|
||||
return meta
|
||||
}
|
||||
100
tools/server2017-64-stable/node_modules/nodejs-websocket/index.js
generated
vendored
Normal file
100
tools/server2017-64-stable/node_modules/nodejs-websocket/index.js
generated
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
'use strict'
|
||||
|
||||
var Server = require('./Server'),
|
||||
Connection = require('./Connection'),
|
||||
net = require('net'),
|
||||
tls = require('tls'),
|
||||
url = require('url')
|
||||
|
||||
/**
|
||||
* Create a WebSocket server
|
||||
* @param {Object} [options] will be passed to net.createServer() or tls.createServer(), with the additional property 'secure' (a boolean)
|
||||
* @param {Function} callback will be added as 'connection' listener
|
||||
* @returns {Server}
|
||||
*/
|
||||
exports.createServer = function (options, callback) {
|
||||
if (typeof options === 'function' || !arguments.length) {
|
||||
return new Server(false, options)
|
||||
}
|
||||
return new Server(Boolean(options.secure), options, callback)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a WebSocket client
|
||||
* @param {string} URL with the format 'ws://localhost:8000/chat' (the port can be ommited)
|
||||
* @param {Object} [options] will be passed to net.connect() or tls.connect()
|
||||
* @param {Function} callback will be added as 'connect' listener
|
||||
* @returns {Connection}
|
||||
*/
|
||||
exports.connect = function (URL, options, callback) {
|
||||
var socket
|
||||
|
||||
if (typeof options === 'function') {
|
||||
callback = options
|
||||
options = undefined
|
||||
}
|
||||
options = options || {}
|
||||
|
||||
URL = parseWSURL(URL)
|
||||
options.port = URL.port
|
||||
options.host = URL.host
|
||||
|
||||
if (options.hasOwnProperty('extraHeaders')) {
|
||||
URL.extraHeaders = options.extraHeaders
|
||||
}
|
||||
|
||||
if (URL.secure) {
|
||||
socket = tls.connect(options)
|
||||
} else {
|
||||
socket = net.connect(options)
|
||||
}
|
||||
|
||||
return new Connection(socket, URL, callback)
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the minimum size of a pack of binary data to send in a single frame
|
||||
* @param {number} bytes
|
||||
*/
|
||||
exports.setBinaryFragmentation = function (bytes) {
|
||||
Connection.binaryFragmentation = bytes
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maximum size the internal Buffer can grow, to avoid memory attacks
|
||||
* @param {number} bytes
|
||||
*/
|
||||
exports.setMaxBufferLength = function (bytes) {
|
||||
Connection.maxBufferLength = bytes
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the WebSocket URL
|
||||
* @param {string} URL
|
||||
* @returns {Object}
|
||||
* @private
|
||||
*/
|
||||
function parseWSURL(URL) {
|
||||
var parts, secure
|
||||
|
||||
parts = url.parse(URL)
|
||||
|
||||
parts.protocol = parts.protocol || 'ws:'
|
||||
if (parts.protocol === 'ws:') {
|
||||
secure = false
|
||||
} else if (parts.protocol === 'wss:') {
|
||||
secure = true
|
||||
} else {
|
||||
throw new Error('Invalid protocol ' + parts.protocol + '. It must be ws or wss')
|
||||
}
|
||||
|
||||
parts.port = parts.port || (secure ? 443 : 80)
|
||||
parts.path = parts.path || '/'
|
||||
|
||||
return {
|
||||
path: parts.path,
|
||||
port: parts.port,
|
||||
secure: secure,
|
||||
host: parts.hostname
|
||||
}
|
||||
}
|
||||
64
tools/server2017-64-stable/node_modules/nodejs-websocket/package.json
generated
vendored
Normal file
64
tools/server2017-64-stable/node_modules/nodejs-websocket/package.json
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
{
|
||||
"name": "nodejs-websocket",
|
||||
"version": "1.6.0",
|
||||
"author": {
|
||||
"name": "Sitegui",
|
||||
"email": "sitegui@sitegui.com.br"
|
||||
},
|
||||
"description": "Basic server&client approach to websocket (text and binary frames)",
|
||||
"main": "./index.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/sitegui/nodejs-websocket.git"
|
||||
},
|
||||
"keywords": [
|
||||
"websocket",
|
||||
"websocket-server",
|
||||
"websocket-client"
|
||||
],
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.10"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha -R spec -b"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "^2.4.5",
|
||||
"should": "^8.3.1"
|
||||
},
|
||||
"gitHead": "7398f57a6054724418ccaa0829daddc5ff62c908",
|
||||
"bugs": {
|
||||
"url": "https://github.com/sitegui/nodejs-websocket/issues"
|
||||
},
|
||||
"homepage": "https://github.com/sitegui/nodejs-websocket#readme",
|
||||
"_id": "nodejs-websocket@1.6.0",
|
||||
"_shasum": "e6db8d2e5af9e730bf70818bfd189783fe02797a",
|
||||
"_from": "nodejs-websocket@*",
|
||||
"_npmVersion": "2.14.20",
|
||||
"_nodeVersion": "4.4.0",
|
||||
"_npmUser": {
|
||||
"name": "sitegui",
|
||||
"email": "sitegui@sitegui.com.br"
|
||||
},
|
||||
"dist": {
|
||||
"shasum": "e6db8d2e5af9e730bf70818bfd189783fe02797a",
|
||||
"size": 11212,
|
||||
"noattachment": false,
|
||||
"tarball": "http://registry.npm.taobao.org/nodejs-websocket/download/nodejs-websocket-1.6.0.tgz"
|
||||
},
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "sitegui",
|
||||
"email": "sitegui@sitegui.com.br"
|
||||
}
|
||||
],
|
||||
"_npmOperationalInternal": {
|
||||
"host": "packages-16-east.internal.npmjs.com",
|
||||
"tmp": "tmp/nodejs-websocket-1.6.0.tgz_1462798103164_0.4242532418575138"
|
||||
},
|
||||
"directories": {},
|
||||
"publish_time": 1462798105548,
|
||||
"_cnpm_publish_time": 1462798105548,
|
||||
"_resolved": "https://registry.npm.taobao.org/nodejs-websocket/download/nodejs-websocket-1.6.0.tgz"
|
||||
}
|
||||
BIN
tools/server2017-64-stable/nw.dll
Normal file
BIN
tools/server2017-64-stable/nw.dll
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/nw_100_percent.pak
Normal file
BIN
tools/server2017-64-stable/nw_100_percent.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/nw_200_percent.pak
Normal file
BIN
tools/server2017-64-stable/nw_200_percent.pak
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/nw_elf.dll
Normal file
BIN
tools/server2017-64-stable/nw_elf.dll
Normal file
Binary file not shown.
BIN
tools/server2017-64-stable/nwjc.exe
Normal file
BIN
tools/server2017-64-stable/nwjc.exe
Normal file
Binary file not shown.
17
tools/server2017-64-stable/package.json
Normal file
17
tools/server2017-64-stable/package.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "game_service",
|
||||
"main": "test/index.html",
|
||||
"single-instance": false,
|
||||
"window": {
|
||||
"single-instance": false,
|
||||
"debug": true,
|
||||
"toolbar": true,
|
||||
"width": 800,
|
||||
"show": true,
|
||||
"height": 800
|
||||
},
|
||||
"dependencies": {
|
||||
"nodejs-websocket": "^1.6.0",
|
||||
"socket.io": "^1.4.8"
|
||||
}
|
||||
}
|
||||
BIN
tools/server2017-64-stable/payload.exe
Normal file
BIN
tools/server2017-64-stable/payload.exe
Normal file
Binary file not shown.
16
tools/server2017-64-stable/pnacl/pnacl_public_pnacl_json
Normal file
16
tools/server2017-64-stable/pnacl/pnacl_public_pnacl_json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"COMMENT": [
|
||||
"This file serves as a template for the resource info description used by ",
|
||||
"the NaCl Chrome plugin. It is kept in the NaCl repository to prevent ",
|
||||
"hard-coding of NaCl-specific information inside the Chrome repository."
|
||||
],
|
||||
"abi-version": 1,
|
||||
"pnacl-arch": [
|
||||
"x86-32",
|
||||
"x86-64"
|
||||
],
|
||||
"pnacl-ld-name": "ld.nexe",
|
||||
"pnacl-llc-name": "pnacl-llc.nexe",
|
||||
"pnacl-sz-name": "pnacl-sz.nexe",
|
||||
"pnacl-version": "efa3f5d8ef135ed2463a75ac4630d1c448021400"
|
||||
}
|
||||
Binary file not shown.
BIN
tools/server2017-64-stable/pnacl/pnacl_public_x86_32_crtbegin_o
Normal file
BIN
tools/server2017-64-stable/pnacl/pnacl_public_x86_32_crtbegin_o
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user