static void doRequestPlayers(BaseProtocolVO baseVO) { var vo = (RequestPlayers)baseVO; var players = new PlayerInfo[3]; for (int i = 1; i <= 3; i++) { players[i - 1] = new PlayerInfo() { uid = i + 20000, name = "qqq" + i, status = i % 2 == 0, type = (PlayerType)i, maxResetTimes = i, fff = i * 100 + i * 0.11111f, createTime = DateTime.Now, items = new[] { 111, 222, 777 }, }; } var response = new ResponsePlayers() { status = true, players = players, }; server.Send(response, baseVO.customData); }
static void doRequestSendString(BaseProtocolVO baseVO) { var vo = (RequestSendString)baseVO; var response = ResponseSendString.CreateInstance(); response.content = vo.content; server.Send(response, baseVO.customData); }
static void globalHandler(BaseProtocolVO baseVO) { Console.WriteLine(String.Format("从[{0}]收到协议:{1}", baseVO.customData, baseVO.MessageType)); //发回所有收到的消息 //server.Send(baseVO, client); }
public void Call(BaseProtocolVO vo) { Console.WriteLine("发送消息:" + vo); var bytes = packager.Encode(vo); send(bytes); }
public byte[] Encode(BaseProtocolVO vo) { var binWriter = new ProtocolBinaryWriter(new MemoryStream()); binWriter.Write(vo.MessageId); vo.encode(binWriter); binWriter.Seek(0, SeekOrigin.Begin); int len = (int)binWriter.BaseStream.Length; var bytes = new byte[len]; binWriter.BaseStream.Read(bytes, 0, len); return bytes; }
static public void DispatchMessage(BaseProtocolVO msg) { globalMessageHandlerGroup.CallHandler(msg); MessageHandlerGroup<BaseProtocolVO> handlerGroup; if (dic_handlerGroup.TryGetValue(msg.MessageType, out handlerGroup)) { handlerGroup.CallHandler(msg); } DispatchProtocolClassMessage(msg); }
private void globalMessageHandler(BaseProtocolVO baseVO) { Console.WriteLine("收到消息:" + baseVO); }
private void ResponseSendString(BaseProtocolVO vo) { var msg = (ResponseSendString)vo; Console.WriteLine("ResponseSendString:" + msg.content); }
public void Send(BaseProtocolVO vo, object client) { Console.WriteLine("发送消息:" + vo + " 给" + client); var bytes = translator.Encode(vo); server.send(bytes, ((ClientObject)client).socket); }