public void write(UserToken token, int type, int area, int command, object message) { byte[] bs = MessageEncoding.Encode(createSocketModel(type, area, command, message)); bs = LengthEncoding.encode(bs); Console.WriteLine("有消息发出"); token.write(bs); }
internal void Brocast(int type, int area, int command, object msg, UserToken exclude) { MSGModel message = MSGModel.CreateMessage(type, area, command, msg); byte[] tmp = MessageEncoding.Encode(message); byte[] buffer = LengthEncoding.encode(tmp); foreach (RoomPlayer rp in teamOne) { if (rp.Token != exclude) { tmp = new byte[buffer.Length]; Buffer.BlockCopy(buffer, 0, tmp, 0, buffer.Length); rp.Token.Write(tmp); } } foreach (RoomPlayer rp in teamTwo) { if (rp.Token != exclude) { tmp = new byte[buffer.Length]; Buffer.BlockCopy(buffer, 0, tmp, 0, buffer.Length); rp.Token.Write(tmp); } } }
public static void write(UserToken token, SocketModel model) { //Console.WriteLine("有消息发出"); byte[] bs = MessageEncoding.Encode(model); bs = LengthEncoding.encode(bs); token.write(bs); }
public void write(UserToken token, int type, int area, int command, object message) { byte[] bs = MessageEncoding.Encode(createSocketModel(type, area, command, message)); bs = LengthEncoding.encode(bs); LoggerHelper.Info(token.connectSocket.RemoteEndPoint.ToString() + " --返回处理结果"); token.write(bs); }
public void write(UserToken token, byte type, int area, int command, object message) { SocketModel model = CreateModel(type, area, command, message); byte[] value = MessageEncoding.Encode(model); value = LengthEncoding.encode(value); token.write(value); }
public static void OnceSend <T>(UserToken token, byte type, int area, int command, T message) { SocketModel socketModel = new SocketModel(); socketModel.type = type; socketModel.area = area; socketModel.command = command; socketModel.message = CommonTool.Serialize <T>(message); byte[] value = MessageEncoding.Encode(socketModel); value = LengthEncoding.Encode(value); token.write(value); }
public void brocast(int type, int area, int command, object message) { byte[] bs = MessageEncoding.Encode(createSocketModel(type, area, command, message)); bs = LengthEncoding.encode(bs); // Console.WriteLine("有群发"); //遍历当前模块所有用户 进行消息发送 foreach (UserToken item in list) { byte[] truebs = new byte[bs.Length]; Array.Copy(bs, 0, truebs, 0, bs.Length); item.write(truebs); } }
public void write(int id, int type, int area, int command, object message) { UserToken token = userBiz.getToken(id); if (token == null) { return; } Console.WriteLine("有消息发出"); byte[] bs = MessageEncoding.Encode(createSocketModel(type, area, command, message)); bs = LengthEncoding.encode(bs); token.write(bs); }
public void brocast(byte type, int area, int command, object message, UserToken exToken = null) { SocketModel model = CreateModel(type, area, command, message); byte[] value = MessageEncoding.Encode(model); value = LengthEncoding.encode(value); foreach (UserToken item in list) { if (exToken != item) { byte[] bs = new byte[value.Length]; Array.Copy(value, 0, bs, 0, value.Length); item.write(bs); } } }
public void writeToUsers(int[] users, byte type, int area, int command, object message) { byte[] value = MessageEncoding.Encode(CreateSocketModel(type, area, command, message)); value = LengthEncoding.Encode(value); foreach (int item in users) { UserToken token = userBiz.getToken(item); if (token == null) { continue; } byte[] bs = new byte[value.Length]; Array.Copy(value, 0, bs, 0, value.Length); token.Write(bs); } }
public void writeToUsers(int[] users, int type, int area, int command, object message) { byte[] bs = MessageEncoding.Encode(createSocketModel(type, area, command, message)); bs = LengthEncoding.encode(bs); foreach (int item in users) { UserToken token = userBiz.getToken(item); if (token != null) { Console.WriteLine("群发给指定ID"); byte[] truebs = new byte[bs.Length]; Array.Copy(bs, 0, truebs, 0, bs.Length); token.write(truebs); } } }
public void exBrocast(UserToken token, int command, object message) { byte[] bs = MessageEncoding.Encode(createSocketModel(getType(), getArea(), command, message)); bs = LengthEncoding.encode(bs); Console.WriteLine("有排除模式群发"); //遍历当前模块所有用户 进行消息发送 foreach (UserToken item in list) { if (item.Equals(token)) { continue; } byte[] truebs = new byte[bs.Length]; Array.Copy(bs, 0, truebs, 0, bs.Length); item.write(truebs); } }
/// <summary> /// 编码数据成二进制协议 /// </summary> /// <param name="type"></param> /// <param name="area"></param> /// <param name="command"></param> /// <param name="message"></param> public byte[] Encode(byte type, int area, int command, object message) { SocketModel model = new SocketModel() { Type = type, Area = area, Command = command, Message = message }; #region 原本写法,感觉有问题 //ByteArray ba = new ByteArray(); //ba.write(type); //ba.write(area); //ba.write(command); ////判断消息体是否为空 不为空则序列化后写入 //if (message != null) { // ba.write(SerializeUtil.Encode(message)); //} //ByteArray arr1 = new ByteArray(); //arr1.write(ba.Length); //arr1.write(ba.getBuff()); //return arr1.getBuff(); #endregion return(LengthEncoding.Encode(MessageEncoding.Encode(model))); }
/// <summary> /// 发送报文 /// </summary> /// <param name="type"></param> /// <param name="command"></param> /// <param name="message"></param> public void Write(byte type, int command, object message) { //长编码<-报文编码<-socket模型 this.Write(LengthEncoding.Encode(MessageEncoding.Encode((object)new SocketModel(type, command, message)))); }
protected void write(UserToken token, int type, int area, int command, object message) { byte[] buffer = MessageEncoding.Encode(MSGModel.CreateMessage(type, area, command, message)); buffer = LengthEncoding.encode(buffer); token.Write(buffer); }