目录结构调整
This commit is contained in:
120
codes/games/server/youle/server_agent/class.tcplist.js
Normal file
120
codes/games/server/youle/server_agent/class.tcplist.js
Normal file
@@ -0,0 +1,120 @@
|
||||
///////////////////////////////////////////////////
|
||||
//////////////cls_youle_agent_tcplist: tcp连接列表类///////////
|
||||
///////////////////////////////////////////////////
|
||||
var cls_youle_agent_tcplist = cls_youle_agent_tcplist || {
|
||||
new: function() {
|
||||
var tcplist = {};
|
||||
tcplist.list = [];
|
||||
|
||||
//方法
|
||||
tcplist.method = {};
|
||||
|
||||
//载入tcp连接
|
||||
tcplist.method.load_tcp = function(str_tcpid, o_player, gameidx){
|
||||
return cls_youle_agent_tcplist.load_tcp(tcplist, str_tcpid, o_player, gameidx);
|
||||
}
|
||||
|
||||
//查找tcp连接
|
||||
tcplist.method.find_tcp = function(str_tcpid){
|
||||
return cls_youle_agent_tcplist.find_tcp(tcplist, str_tcpid);
|
||||
}
|
||||
|
||||
//删除tcp连接
|
||||
tcplist.method.delete_tcp = function(str_tcpid){
|
||||
return cls_youle_agent_tcplist.delete_tcp(tcplist, str_tcpid);
|
||||
}
|
||||
|
||||
return tcplist;
|
||||
},
|
||||
|
||||
//载入tcp连接
|
||||
load_tcp: function(o_tcplsit, str_tcpid, o_player, gameidx){
|
||||
var idx = cls_youle_agent_tcplist.aryidx(str_tcpid);
|
||||
if (idx == -1){
|
||||
return null;
|
||||
}
|
||||
if (o_tcplsit.list.length <= idx){
|
||||
o_tcplsit.list.length = idx + 1;
|
||||
}
|
||||
|
||||
var old_tcp = o_tcplsit.list[idx];
|
||||
if (old_tcp){
|
||||
var _player = old_tcp.o_player;
|
||||
if (_player.playerid != o_player.playerid){
|
||||
var _gameidx = old_tcp.gameidx;
|
||||
if (_player.gameinfo[_gameidx]){
|
||||
if (_player.gameinfo[_gameidx].roomcode){
|
||||
_player.gameinfo[_gameidx].ip = null;
|
||||
_player.gameinfo[_gameidx].conmode = null;
|
||||
_player.gameinfo[_gameidx].fromid = null;
|
||||
} else {
|
||||
//如果不在房间内
|
||||
_player.gameinfo[_gameidx] = null;
|
||||
//判断是否要释放玩家
|
||||
var freeflag = true;
|
||||
for (var m = 0; m < _player.gameinfo.length; m++) {
|
||||
if (_player.gameinfo[m]){
|
||||
freeflag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (freeflag){
|
||||
// _player.o_agent.players[_player.playerid - 100001] = null;
|
||||
_player.method.open_free_timer();
|
||||
}
|
||||
|
||||
//统计在线玩家数
|
||||
var o_game = _player.o_agent.games[_gameidx];
|
||||
if (o_game){
|
||||
o_game.method.online_p_chang(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var new_tcp = {};
|
||||
new_tcp.tcpid = str_tcpid;
|
||||
new_tcp.o_player = o_player;
|
||||
new_tcp.gameidx = gameidx;
|
||||
o_tcplsit.list[idx] = new_tcp;
|
||||
o_player.method.close_free_timer();
|
||||
return new_tcp;
|
||||
},
|
||||
|
||||
//查找tcp连接
|
||||
find_tcp: function(o_tcplsit, str_tcpid){
|
||||
var idx = cls_youle_agent_tcplist.aryidx(str_tcpid);
|
||||
if (idx == -1){
|
||||
return null;
|
||||
}
|
||||
if (o_tcplsit.list.length <= idx){
|
||||
return null;
|
||||
}
|
||||
return o_tcplsit.list[idx];
|
||||
},
|
||||
|
||||
//删除tcp连接
|
||||
delete_tcp: function(o_tcplsit, str_tcpid){
|
||||
var idx = cls_youle_agent_tcplist.aryidx(str_tcpid);
|
||||
if (idx == -1){
|
||||
return;
|
||||
}
|
||||
if (o_tcplsit.list.length <= idx){
|
||||
return;
|
||||
}
|
||||
o_tcplsit.list[idx] = null;
|
||||
},
|
||||
|
||||
//计算tcp连接的数组下标
|
||||
aryidx: function(str_tcpid){
|
||||
var idx = parseInt(str_tcpid.replace("tcp_", ""));
|
||||
if (isNaN(idx)){
|
||||
return -1;
|
||||
}
|
||||
return idx - 10000;
|
||||
}
|
||||
}
|
||||
|
||||
//tcp连接列表
|
||||
youle_agent.tcps = cls_youle_agent_tcplist.new();
|
||||
Reference in New Issue
Block a user