public static void Dispatch(OperationCode type, MyGameServer.ClientPeer peer, OperationRequest operationRequest, SendParameters sendParameters) { Delegate d; if (messageTable.TryGetValue(type, out d)) { Act callback = d as Act; if (callback != null) { callback(peer, operationRequest, sendParameters); } else { MyGameServer.MyGameServer.log.Info(string.Format("no such event type {0}", type)); } } }
/// <summary> /// 组队成功,移除对应的Peer /// </summary> /// <param name="_strRoomid"></param> /// <param name="_peer"></param> public void RemovePeer(string _strRoomid, ClientPeer _peer) { if (string.IsNullOrEmpty(_strRoomid)) { return; } List <ClientPeer> pList; if (m_dicForTeam.TryGetValue(_strRoomid, out pList)) { if (pList.Contains(_peer)) { pList.Remove(_peer); } m_dicForTeam.Remove(_strRoomid); m_dicForTeam.Add(_strRoomid, pList); } }
//关闭 public void Close() { for (int i = 0; i < conns.Length; i++) { ClientPeer conn = conns[i]; if (conn == null) { continue; } if (!conn.isUse) { continue; } lock (conn) { conn.Close(); } } }
//获取链接池索引,返回负数表示获取失败 public int NewIndex() { if (conns == null) { return(-1); } for (int i = 0; i < conns.Length; i++) { if (conns[i] == null) { conns[i] = new ClientPeer(); return(i); } else if (conns[i].isUse == false) { return(i); } } return(-1); }
/// <summary> /// 客户端申请进入副本 /// </summary> /// <param name="_strRoomid"></param> /// <param name="_peer"></param> public void AddTeam(string _strRoomid, ClientPeer _peer) { List <ClientPeer> pList; if (_strRoomid.Equals("")) { Helper.Log("副本ID为空!"); return; } // 已有副本队伍 if (m_dicForTeam.TryGetValue(_strRoomid, out pList)) { if (!pList.Contains(_peer)) { pList.Add(_peer); } } else // 新副本队伍 { pList = new List <ClientPeer>(); pList.Add(_peer); m_dicForTeam.Add(_strRoomid, pList); } }