目录结构调整
This commit is contained in:
163
codes/games/sales_service/youle/server_room/class.agent.js
Normal file
163
codes/games/sales_service/youle/server_room/class.agent.js
Normal file
@@ -0,0 +1,163 @@
|
||||
///////////////////////////////////////////////////////////////
|
||||
//////////////// cls_youle_room_agent: 运营商 /////////////////
|
||||
///////////////////////////////////////////////////////////////
|
||||
var cls_youle_room_agent = cls_youle_room_agent || {
|
||||
//构造函数
|
||||
new: function(agentid, name, server, tcpport, httpport, freeroom){
|
||||
var agent = {};
|
||||
agent.agentid = agentid; //运营商id
|
||||
agent.agentname = name; //运营商名称
|
||||
agent.server = server; //运营商服务器地址
|
||||
agent.tcpport = tcpport; //运营商服务器tcp端口
|
||||
agent.httpport = httpport; //运营商服务器http端口
|
||||
agent.freeroom = freeroom; //默认同意解散房间的倒计时,秒
|
||||
|
||||
//游戏列表
|
||||
agent.games = [];
|
||||
|
||||
//方法
|
||||
agent.method = {};
|
||||
//载入游戏(没找到则创建)
|
||||
agent.method.load_game = function(gameid, gamename, seatcount, makewar, modename, roomserver, tcpport, httpport, minroomcode, maxroomcode){
|
||||
return cls_youle_room_agent.load_game(agent, gameid, gamename, seatcount, makewar, modename, roomserver, tcpport, httpport, minroomcode, maxroomcode);
|
||||
};
|
||||
//查找游戏
|
||||
agent.method.find_game = function(gameid){
|
||||
return cls_youle_room_agent.find_game(agent, gameid);
|
||||
};
|
||||
|
||||
return agent;
|
||||
},
|
||||
|
||||
//载入游戏(没找到则创建)
|
||||
load_game: function(o_agent, gameid, gamename, seatcount, makewar, modename, roomserver, tcpport, httpport, minroomcode, maxroomcode){
|
||||
var idx = cls_youle_room_agent.aryidx_game(gameid);
|
||||
if (o_agent.games.length <= idx) {
|
||||
o_agent.games.length = idx + 1;
|
||||
}
|
||||
var o_game = o_agent.games[idx];
|
||||
if (!o_game){
|
||||
//不存在则创建
|
||||
o_game = cls_youle_room_game.new(o_agent, gameid, idx, gamename, seatcount, makewar, modename, roomserver, tcpport, httpport, minroomcode, maxroomcode);
|
||||
o_agent.games[idx] = o_game;
|
||||
} else {
|
||||
o_game.idx = idx;
|
||||
o_game.gamename = gamename;
|
||||
o_game.seatcount = seatcount;
|
||||
o_game.makewar = makewar;
|
||||
o_game.modename = modename;
|
||||
o_game.roomserver = roomserver;
|
||||
o_game.tcpport = tcpport;
|
||||
o_game.httpport = httpport;
|
||||
o_game.minroomcode = minroomcode;
|
||||
o_game.maxroomcode = maxroomcode;
|
||||
}
|
||||
return o_game;
|
||||
},
|
||||
|
||||
//查找游戏
|
||||
find_game: function(o_agent, gameid){
|
||||
var idx = cls_youle_room_agent.aryidx_game(gameid);
|
||||
if (idx == -1){
|
||||
return null;
|
||||
}
|
||||
if (o_agent.games.length <= idx){
|
||||
return null;
|
||||
}
|
||||
if (!o_agent.games[idx]){
|
||||
return null;
|
||||
}
|
||||
if (o_agent.games[idx].gameid != gameid){
|
||||
return null;
|
||||
}
|
||||
return o_agent.games[idx];
|
||||
},
|
||||
|
||||
//计算游戏的数组下标
|
||||
aryidx_game: function(gameid){
|
||||
//gameid的5、10、15、20四位组成数组下标
|
||||
var idx = parseInt(gameid.substr(4, 1)
|
||||
+ gameid.substr(9, 1)
|
||||
+ gameid.substr(14, 1)
|
||||
+ gameid.substr(19, 1));
|
||||
if (isNaN(idx)){
|
||||
return -1;
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
/////////// cls_youle_room_agentlist: 运营商列表 //////////
|
||||
///////////////////////////////////////////////////////////////
|
||||
var cls_youle_room_agentlist = cls_youle_room_agentlist || {
|
||||
//构造函数
|
||||
new: function() {
|
||||
var agentlist = {};
|
||||
//代理商列表
|
||||
agentlist.list = [];
|
||||
|
||||
//方法
|
||||
agentlist.method = {};
|
||||
|
||||
//载入代理商(没找到则创建)
|
||||
agentlist.method.load_agent = function(agentid, name, server, tcpport, httpport, freeroom){
|
||||
var idx = agentlist.method.aryidx_agent(agentid);
|
||||
if (idx == -1){
|
||||
return null;
|
||||
}
|
||||
if (agentlist.list.length <= idx) {
|
||||
agentlist.list.length = idx + 1;
|
||||
}
|
||||
var o_agent = agentlist.list[idx];
|
||||
if (!o_agent) {
|
||||
//不存在则创建
|
||||
o_agent = cls_youle_room_agent.new(agentid, name, server, tcpport, httpport, freeroom);
|
||||
agentlist.list[idx] = o_agent;
|
||||
} else {
|
||||
o_agent.agentname = name;
|
||||
o_agent.server = server;
|
||||
o_agent.tcpport = tcpport;
|
||||
o_agent.httpport = httpport;
|
||||
o_agent.freeroom = freeroom;
|
||||
}
|
||||
return o_agent;
|
||||
};
|
||||
|
||||
//查找运营商
|
||||
agentlist.method.find_agent = function(agentid){
|
||||
var idx = agentlist.method.aryidx_agent(agentid);
|
||||
if (idx == -1){
|
||||
return null;
|
||||
}
|
||||
if (agentlist.list.length <= idx){
|
||||
return null;
|
||||
}
|
||||
if (!agentlist.list[idx]){
|
||||
return null;
|
||||
}
|
||||
if (agentlist.list[idx].agentid != agentid){
|
||||
return null;
|
||||
}
|
||||
return agentlist.list[idx];
|
||||
};
|
||||
|
||||
//计算运营商的数组下标
|
||||
agentlist.method.aryidx_agent = function(agentid) {
|
||||
//agentid的5、10、15、20四位组成数组下标
|
||||
var idx = parseInt(agentid.substr(4, 1)
|
||||
+ agentid.substr(9, 1)
|
||||
+ agentid.substr(14, 1)
|
||||
+ agentid.substr(19, 1));
|
||||
if (isNaN(idx)){
|
||||
return -1;
|
||||
}
|
||||
return idx;
|
||||
};
|
||||
|
||||
return agentlist;
|
||||
}
|
||||
}
|
||||
|
||||
//运营商列表
|
||||
youle_room.agents = cls_youle_room_agentlist.new();
|
||||
Reference in New Issue
Block a user