public bool SendBytesMsgBySessId(UInt64 session_id, UInt32 msg_id, byte[] datas, IAttachParas attach = null) { var session = FindSessionBySessionID(session_id); if (session == null) { return(false); } return(session.AsyncSendMsg(msg_id, datas, attach)); }
public bool SendProtoMsgBySessId(UInt64 session_id, UInt32 msg_id, IMessage msg, IAttachParas attach = null) { var session = FindSessionBySessionID(session_id); if (session == null) { return(false); } return(session.AsyncSendProtoMsg(msg_id, msg, attach)); }
public bool AsyncSendProtoMsg(UInt32 msg_id, IMessage message, IAttachParas attach) { if (message != null) { //需优化ToByteArray性能 //https://www.yht7.com/news/36972 byte[] datas = message.ToByteArray(); AsyncSendMsg(msg_id, datas, attach); } else { AsyncSendMsg(msg_id, null, attach); } return(true); }
public bool AsyncSendMsg(UInt32 msg_id, byte[] datas, IAttachParas attach) { MemoryStream memstream = new MemoryStream(); BinaryWriter writer = new BinaryWriter(memstream); byte[] msg_id_bytes = System.BitConverter.GetBytes(msg_id); Array.Reverse(msg_id_bytes); writer.Write(msg_id_bytes); byte[] attach_datas = null; if (attach != null) { attach_datas = attach.FillNetStream(); } if (attach_datas != null) { byte[] attach_len_bytes = System.BitConverter.GetBytes((UInt16)attach_datas.Length); Array.Reverse(attach_len_bytes); writer.Write(attach_len_bytes); writer.Write(attach_datas); } else { byte[] attach_len_bytes = System.BitConverter.GetBytes((UInt16)0); Array.Reverse(attach_len_bytes); writer.Write(attach_len_bytes); } if (datas != null && datas.Length != 0) { writer.Write(datas); } byte[] out_content; coder.FillNetStream(memstream.ToArray(), out out_content); conn.AsyncSend(out_content); return(true); }
public bool SendProtoMsgByHashIdAndSrvType(UInt32 server_type, UInt64 hash_id, UInt32 msg_id, IMessage msg, IAttachParas attach = null) { var logic_server_list = GetLogicSrvVecBySrvType(server_type); if (logic_server_list.Count == 0) { return(false); } UInt64 index = hash_id % (UInt64)logic_server_list.Count; return(logic_server_list[(int)index].GetSession().AsyncSendProtoMsg(msg_id, msg, attach)); }
public void BroadCastProtoMsgBySrvType(UInt32 server_type, UInt32 msg_id, IMessage msg, IAttachParas attach = null) { foreach (KeyValuePair <UInt64, SSServerSession> kv in session_dict) { if (kv.Value.GetRemoteServerType() == server_type) { kv.Value.AsyncSendProtoMsg(msg_id, msg, attach); } } }
public void BroadCastBytesMsgBySrvType(UInt32 server_type, UInt32 msg_id, byte[] datas, IAttachParas attach = null) { foreach (KeyValuePair <UInt64, SSServerSession> kv in session_dict) { if (kv.Value.GetRemoteServerType() == server_type) { kv.Value.AsyncSendMsg(msg_id, datas, attach); } } }
void SendProtoMsg(UInt32 msgID, IMessage message, IAttachParas attach = null) { AsyncSendProtoMsg(msgID, message, attach); }
void SendBytes(UInt32 msgID, byte[] datas, IAttachParas attach = null) { AsyncSendMsg(msgID, datas, attach); }