第一次提交 游戏界面资源数据已更新

This commit is contained in:
2026-02-02 17:47:01 +08:00
commit de17737ca1
8152 changed files with 3079449 additions and 0 deletions

View File

@@ -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>

View File

@@ -0,0 +1 @@
min_loadJsFile("server/app.js", function (){});

View File

@@ -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;
}
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,15 @@
///////////////////////////////////////////////////
//////////////// cls_paiju: 单局牌局 //////////////
///////////////////////////////////////////////////
var cls_paiju = cls_paiju || {
//创建单张牌实例
new: function(){
var paiju = {};
return paiju;
}
}

View File

@@ -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属性值 iddom、或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);

View File

@@ -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;
};

View File

@@ -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);
}
}
}

View File

@@ -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;
}
}
}
}
}
}