/// <summary> /// 发送聊天信息 /// </summary> /// <param name="response"></param> private void HandleRoomSendMsgS2C(BufferEntity response) { RoomSendMsgS2C s2cMSG = ProtobufHelper.FromBytes <RoomSendMsgS2C>(response.proto); ChatText.text += $"{RoomCtrl.Instance.GetNickName(s2cMSG.RolesID)}:{s2cMSG.Text}\n"; ChatVertical.value = 0; }
public static void Send(this Session session, IMessage message) { ushort opcode = Hotfix.Scene.GetComponent <OpcodeTypeComponent>().GetOpcode(message.GetType()); byte[] bytes = ProtobufHelper.ToBytes(message); session.Send(opcode, bytes); }
/// <exception cref="System.IO.IOException"/> public virtual void BlockReceivedAndDeleted(DatanodeRegistration registration, string poolId, StorageReceivedDeletedBlocks[] receivedAndDeletedBlocks) { DatanodeProtocolProtos.BlockReceivedAndDeletedRequestProto.Builder builder = DatanodeProtocolProtos.BlockReceivedAndDeletedRequestProto .NewBuilder().SetRegistration(PBHelper.Convert(registration)).SetBlockPoolId(poolId ); foreach (StorageReceivedDeletedBlocks storageBlock in receivedAndDeletedBlocks) { DatanodeProtocolProtos.StorageReceivedDeletedBlocksProto.Builder repBuilder = DatanodeProtocolProtos.StorageReceivedDeletedBlocksProto .NewBuilder(); repBuilder.SetStorageUuid(storageBlock.GetStorage().GetStorageID()); // Set for wire compatibility. repBuilder.SetStorage(PBHelper.Convert(storageBlock.GetStorage())); foreach (ReceivedDeletedBlockInfo rdBlock in storageBlock.GetBlocks()) { repBuilder.AddBlocks(PBHelper.Convert(rdBlock)); } builder.AddBlocks(((DatanodeProtocolProtos.StorageReceivedDeletedBlocksProto)repBuilder .Build())); } try { rpcProxy.BlockReceivedAndDeleted(NullController, ((DatanodeProtocolProtos.BlockReceivedAndDeletedRequestProto )builder.Build())); } catch (ServiceException se) { throw ProtobufHelper.GetRemoteException(se); } }
/// <exception cref="System.IO.IOException"/> public virtual DatanodeCommand CacheReport(DatanodeRegistration registration, string poolId, IList <long> blockIds) { DatanodeProtocolProtos.CacheReportRequestProto.Builder builder = DatanodeProtocolProtos.CacheReportRequestProto .NewBuilder().SetRegistration(PBHelper.Convert(registration)).SetBlockPoolId(poolId ); foreach (long blockId in blockIds) { builder.AddBlocks(blockId); } DatanodeProtocolProtos.CacheReportResponseProto resp; try { resp = rpcProxy.CacheReport(NullController, ((DatanodeProtocolProtos.CacheReportRequestProto )builder.Build())); } catch (ServiceException se) { throw ProtobufHelper.GetRemoteException(se); } if (resp.HasCmd()) { return(PBHelper.Convert(resp.GetCmd())); } return(null); }
public void Send(byte flag, IMessage message) { ushort opcode = Game.OpcodeTypeComponent.GetOpcode(message.GetType()); byte[] bytes = ProtobufHelper.ToBytes(message); session.Send(flag, opcode, bytes); }
public static MessageBean formatChessDoneMessage(BLOKUSChessDoneInfo chessDoneInfoTemp) { MessageBean message = new MessageBean(); message.operationCode = OperationCode.CHESS_DONE; message.statusCode = StatusCode.SUCCESS; message.data = ProtobufHelper.SerializerToBytes(chessDoneInfoTemp); return message; }
/// <summary> /// <para> /// Drop the range partition from the table with with an identical lower /// bound and upper bound. /// </para> /// /// <para> /// If a range column is missing a value, the logical minimum value for that /// column type will be used as the default. /// </para> /// /// <para> /// Multiple range partitions may be dropped as part of a single alter table /// transaction by calling this method multiple times. /// </para> /// </summary> /// <param name="configure">Delegate to configure the partition row.</param> public AlterTableBuilder DropRangePartition( Action <PartialRowOperation> configure) { var schema = _table.Schema; var lowerBoundRow = new PartialRowOperation( schema, RowOperation.RangeLowerBound); configure(lowerBoundRow); var upperBoundRow = new PartialRowOperation( lowerBoundRow, RowOperation.InclusiveRangeUpperBound); _request.AlterSchemaSteps.Add(new Step { Type = StepType.DropRangePartition, DropRangePartition = new DropRangePartition { RangeBounds = ProtobufHelper.EncodeRowOperations( lowerBoundRow, upperBoundRow) } }); if (_request.Schema is null) { _request.Schema = _table.SchemaPbNoIds.Schema; } return(this); }
/// <summary> /// 注册功能 /// </summary> /// <param name="request"></param> private void HandleUserRegisterC2S(BufferEntity request) { UserRegisterC2S c2sMSG = ProtobufHelper.FromBytes <UserRegisterC2S>(request.proto); UserRegisterS2C s2cMSG = new UserRegisterS2C(); if (DBUserInfo.Instance.Select(MySqlCMD.Where("Account", c2sMSG.UserInfo.Account)) != null) { Debug.Log("帐号已被注册"); s2cMSG.Result = 3; } else { bool result = DBUserInfo.Instance.Insert(c2sMSG.UserInfo); if (result == true) { s2cMSG.Result = 0;//注册成功 } else { s2cMSG.Result = 4;//未知原因导致的失败 } } //返回结果 BufferFactory.CreqateAndSendPackage(request, s2cMSG); }
/// <exception cref="System.IO.IOException"/> public virtual ReplicaRecoveryInfo InitReplicaRecovery(BlockRecoveryCommand.RecoveringBlock rBlock) { InterDatanodeProtocolProtos.InitReplicaRecoveryRequestProto req = ((InterDatanodeProtocolProtos.InitReplicaRecoveryRequestProto )InterDatanodeProtocolProtos.InitReplicaRecoveryRequestProto.NewBuilder().SetBlock (PBHelper.Convert(rBlock)).Build()); InterDatanodeProtocolProtos.InitReplicaRecoveryResponseProto resp; try { resp = rpcProxy.InitReplicaRecovery(NullController, req); } catch (ServiceException e) { throw ProtobufHelper.GetRemoteException(e); } if (!resp.GetReplicaFound()) { // No replica found on the remote node. return(null); } else { if (!resp.HasBlock() || !resp.HasState()) { throw new IOException("Replica was found but missing fields. " + "Req: " + req + "\n" + "Resp: " + resp); } } HdfsProtos.BlockProto b = resp.GetBlock(); return(new ReplicaRecoveryInfo(b.GetBlockId(), b.GetNumBytes(), b.GetGenStamp(), PBHelper.Convert(resp.GetState()))); }
private void judgeAround(int x, int y) { bool judgeSuccess = false; int lastX = x; int lastY = y; if (judgeOverall(x, y)) { judgeSuccess = true; } else { foreach (ChessPoint point in getAroundPoints(x, y)) { if (judgeOverall(point.x, point.y)) { judgeSuccess = true; lastX = point.x; lastY = point.y; break; } } } if (judgeSuccess) { MessageBean message = MessageFormater.formatChessDoneMessage(lastX, lastY, CurrentSquareName, CurrentSquare.rotationFlag, CurrentSquare.symmetryFlag, CurrentSquare.model); BLOKUSChessDoneInfo chessDoneInfo = ProtobufHelper.DederializerFromBytes <BLOKUSChessDoneInfo>(message.data); GameObject.Find("BlokusUIController").GetComponent <BlokusUIController>().tryChess(chessDoneInfo); // chessDone(chessDoneInfo); } }
public void HandleMessage(MemoryStream memoryStream, Session session) { var login = ProtobufHelper.FromStream(typeof(LoginMessage), memoryStream) as LoginMessage; var conn = DBHelper.Instance.GetConnection(); AccountDAO dao = new AccountDAO(); LoginMessage ms = new LoginMessage(); if (login == null) { ms.Message = "N"; } else { Account result = dao.VerifyAccount(conn, login.Email, login.Password, null); if (result == null) { ms.Message = "N"; } else { ms.Message = "Y"; ms.Id = result.Id; ms.Username = result.UserName; ms.Password = result.Password; ms.Email = result.Email; ms.Phone = result.Phone; } } ResponseMessage(ms, session); }
/// <summary> /// 返回了注册结果 /// </summary> /// <param name="obj"></param> private void HandleUserRegisterS2C(BufferEntity p) { UserRegisterS2C s2cMSG = ProtobufHelper.FromBytes <UserRegisterS2C>(p.proto); switch (s2cMSG.Result) { case 0: Debug.Log("注册成功!"); //打开提示窗体 提示 WindowManager.Instance.ShowTips("注册成功!"); break; case 1: break; case 2: break; case 3: Debug.Log("帐号已被注册!"); WindowManager.Instance.ShowTips("帐号已被注册!"); //打开提示窗体 break; default: break; } }
public static void Send(this Session session, IMessage message) { ushort opcode = GetOpcode(message.GetType()); byte[] bytes = ProtobufHelper.ToBytes(message); session.Send(opcode, bytes); }
public static Packet DeserializePacket(IPacketHeader packetHeader, Stream source /*, out object customErrorData*/) { ET_CSPacketHeader header = packetHeader as ET_CSPacketHeader; if (header == null) { Debug.LogError("header为空."); return(null); } Packet packet = null; if (header.IsValid) { Type packetType = GetClientToServerPacketType(header.Id); if (packetType != null && source is MemoryStream) { object instance = Activator.CreateInstance(packetType); packet = (Packet)ProtobufHelper.FromStream(instance, (MemoryStream)source); } else { Debug.LogError("Can not deserialize packet for packet id '{0}'.", header.Id.ToString()); } } else { Debug.LogError("Packet header is invalid."); } header.Clear(); return(packet); }
/// <summary> /// 返回了登录的结果 /// </summary> /// <param name="obj"></param> private void HandleUserLoginS2C(BufferEntity p) { UserLoginS2C s2cMSG = ProtobufHelper.FromBytes <UserLoginS2C>(p.proto); switch (s2cMSG.Result) { case 0: Debug.Log("登录成功!"); //保存数据 if (s2cMSG.RolesInfo != null) { //保存数据 LoginCtrl.Instance.SaveRolesInfo(s2cMSG.RolesInfo); //打开大厅界面 WindowManager.Instance.OpenWindow(WindowType.LobbyWindow); } else { //跳转到角色界面 WindowManager.Instance.OpenWindow(WindowType.RolesWindow); } Close(); //关闭自己 break; case 2: Debug.Log("帐号密码不匹配!"); WindowManager.Instance.ShowTips("帐号密码不匹配!"); //打开提示窗体 break; default: break; } }
/// <summary> /// 加载进度 /// </summary> /// <param name="response"></param> private void HandleRoomLoadProgressS2C(BufferEntity response) { RoomLoadProgressS2C s2cMSG = ProtobufHelper.FromBytes <RoomLoadProgressS2C>(response.proto); //更新界面 if (s2cMSG.IsBattleStart == true) { ct.Cancel(); for (int i = 0; i < s2cMSG.RolesID.Count; i++) { playerLoadDIC[s2cMSG.RolesID[i]].transform.Find("Progress") .GetComponent <Text>().text = "100%"; } async.allowSceneActivation = true; Close(); } else { //如果还不能进入战斗场景 for (int i = 0; i < s2cMSG.RolesID.Count; i++) { playerLoadDIC[s2cMSG.RolesID[i]].transform.Find("Progress") .GetComponent <Text>().text = $"{s2cMSG.LoadProgress[i]}%"; } } }
public override void Send(int opcode, long pid, object message) { MemoryStream stream = this.Stream; stream.Seek(0, SeekOrigin.Begin); stream.SetLength(0); ProtobufHelper.ToStream(message, stream); this.opcodeCache.WriteTo(0, opcode); this.IdCache.WriteTo(0, pid); this.packetSizeCache.WriteTo(0, (int)stream.Length); if (BitConverter.IsLittleEndian) { Array.Reverse(this.opcodeCache, 0, opcodeCache.Length); Array.Reverse(this.IdCache, 0, IdCache.Length); Array.Reverse(this.packetSizeCache, 0, packetSizeCache.Length); } this.sendBuffer.Write(this.opcodeCache, 0, this.opcodeCache.Length); this.sendBuffer.Write(this.IdCache, 0, this.IdCache.Length); this.sendBuffer.Write(this.packetSizeCache, 0, this.packetSizeCache.Length); this.sendBuffer.Write(stream); }
public void HandleMessage(MemoryStream msg, Session session) { var addFriend = ProtobufHelper.FromStream(typeof(AddFriendMessage), msg) as AddFriendMessage; AccountDAO accountDAO = new AccountDAO(); var id = accountDAO.GetAccountIdByEmail(DBHelper.Instance.GetConnection(), addFriend.FriendEmail); FriendDAO friendDAO = new FriendDAO(); ResponseMessage responseMessage = new ResponseMessage(); if (id != -1) { var result = friendDAO.InsertFriend(DBHelper.Instance.GetConnection(), addFriend.OwnerId, id); if (result) { responseMessage.Message = "Y"; } else { responseMessage.Message = "N"; } } else { responseMessage.Message = "N"; } ResponseMessage(responseMessage, session); }
/// <summary> /// 反序列化消息包。 /// </summary> /// <param name="packetHeader">消息包头。</param> /// <param name="source">要反序列化的来源流。</param> /// <param name="customErrorData">用户自定义错误数据。</param> /// <returns>反序列化后的消息包。</returns> public Packet DeserializePacket(IPacketHeader packetHeader, Stream source, out object customErrorData) { customErrorData = null; CTM_SCPacketHeader header = packetHeader as CTM_SCPacketHeader; if (header == null) { Log.Warning("Packet header is invalid."); return(null); } Packet packet = null; if (header.IsValid) { Type packetType = GetServerToClientPacketType(header.Id); if (packetType != null && source is MemoryStream) { packet = (Packet)ProtobufHelper.FromStream(ReferencePool.Acquire(packetType), (MemoryStream)source); } else { Log.Warning("Can not deserialize packet for packet id '{0}'.", header.Id.ToString()); } } else { Log.Warning("Packet header is invalid."); } ReferencePool.Release(header); return(packet); }
/// <summary> /// 选择召唤师技能的协议 /// </summary> /// <param name="response"></param> private void HandleRoomSelectHeroSkillS2C(BufferEntity response) { RoomSelectHeroSkillS2C s2cMSG = ProtobufHelper.FromBytes <RoomSelectHeroSkillS2C>(response.proto); if (s2cMSG.GridID == 0) { rolesDIC[s2cMSG.RolesID].transform.Find("Hero_SkillA").GetComponent <Image>().sprite = ResManager.Instance.LoadGeneralSkill(s2cMSG.SkillID); if (RoomCtrl.Instance.CheckIsSelfRoles(s2cMSG.RolesID)) { SkillA.sprite = ResManager.Instance.LoadGeneralSkill(s2cMSG.SkillID); SkillInfo.gameObject.SetActive(false); } } else { rolesDIC[s2cMSG.RolesID].transform.Find("Hero_SkillB").GetComponent <Image>().sprite = ResManager.Instance.LoadGeneralSkill(s2cMSG.SkillID); if (RoomCtrl.Instance.CheckIsSelfRoles(s2cMSG.RolesID)) { SkillB.sprite = ResManager.Instance.LoadGeneralSkill(s2cMSG.SkillID); //关闭技能选择面板 SkillInfo.gameObject.SetActive(false); } } }
private void RoomList(MessageBean message) { if (message.statusCode == StatusCode.SUCCESS) { BLOKUSRoomList bLOKUSRoomList = ProtobufHelper.DederializerFromBytes <BLOKUSRoomList>(message.data); GameObject.Find("UIController").SendMessage("OnRoomListUpdate", bLOKUSRoomList); } }
private void profile(MessageBean message) { if (message.statusCode == StatusCode.SUCCESS) { BLOKUSProfile bLOKUSProfile = ProtobufHelper.DederializerFromBytes <BLOKUSProfile>(message.data); GameObject.Find("UIController").SendMessage("onShowProfile", bLOKUSProfile); } }
private void chessDone(MessageBean message) { if (message.statusCode == StatusCode.SUCCESS) { BLOKUSChessDoneInfo bLOKUSChessDoneInfo = ProtobufHelper.DederializerFromBytes <BLOKUSChessDoneInfo>(message.data); GameObject.Find("BlokusController").SendMessage("chessDone", bLOKUSChessDoneInfo); } }
private void chatInGame(MessageBean message) { if (message.statusCode == StatusCode.SUCCESS) { BLOKUSChatMessage bLOKUSChatMessage = ProtobufHelper.DederializerFromBytes <BLOKUSChatMessage>(message.data); GameObject.Find("BlokusUIController").SendMessage("chatInGame", bLOKUSChatMessage.chatMessage); } }
private void initPlayerInfoInGame(MessageBean message) { if (message.statusCode == StatusCode.SUCCESS) { BLOKUSRoomPlayerList bLOKUSRoomPlayerList = ProtobufHelper.DederializerFromBytes <BLOKUSRoomPlayerList>(message.data); GameObject.Find("BlokusUIController").SendMessage("InitBlokusRoomUIInfo", bLOKUSRoomPlayerList); } }
private void rankInfo(MessageBean message) { if (message.statusCode == StatusCode.SUCCESS) { BLOKUSRankInfo bLOKUSRankInfo = ProtobufHelper.DederializerFromBytes <BLOKUSRankInfo>(message.data); GameObject.Find("UIController").SendMessage("updateRankInfo", bLOKUSRankInfo); } }
public static void Run(Session session, PacketInfo packetInfo) { ushort opcode = packetInfo.Opcode; Type t = Hotfix.Scene.GetComponent <OpcodeTypeComponent>().GetType(opcode); object message = ProtobufHelper.FromBytes(t, packetInfo.Bytes, packetInfo.Index, packetInfo.Length); Hotfix.Scene.GetComponent <MessageDispatherComponent>().Handle(session, new MessageInfo(packetInfo.RpcId, packetInfo.Opcode, message)); }
public void Run(Session session, PacketInfo packetInfo) { ushort opcode = packetInfo.Opcode; Type t = SessionHelper.GetMessageType(opcode); object aa = ProtobufHelper.FromBytes(t, packetInfo.Bytes, packetInfo.Index, packetInfo.Length); IMessage message = (IMessage)aa; Hotfix.Scene.GetComponent <MessageDispatherComponent>().Handle(session, opcode, message); }
/// <summary> /// 解散房间 /// </summary> /// <param name="response"></param> private void HandleRoomCloseS2C(BufferEntity response) { RoomCloseS2C s2cMSG = ProtobufHelper.FromBytes <RoomCloseS2C>(response.proto); Close(); RoomCtrl.Instance.RemoveRoomInfo(); WindowManager.Instance.OpenWindow(WindowType.LobbyWindow); }
/// <exception cref="System.IO.IOException"/> public virtual HeartbeatResponse SendHeartbeat(DatanodeRegistration registration, StorageReport[] reports, long cacheCapacity, long cacheUsed, int xmitsInProgress , int xceiverCount, int failedVolumes, VolumeFailureSummary volumeFailureSummary ) { DatanodeProtocolProtos.HeartbeatRequestProto.Builder builder = DatanodeProtocolProtos.HeartbeatRequestProto .NewBuilder().SetRegistration(PBHelper.Convert(registration)).SetXmitsInProgress (xmitsInProgress).SetXceiverCount(xceiverCount).SetFailedVolumes(failedVolumes); builder.AddAllReports(PBHelper.ConvertStorageReports(reports)); if (cacheCapacity != 0) { builder.SetCacheCapacity(cacheCapacity); } if (cacheUsed != 0) { builder.SetCacheUsed(cacheUsed); } if (volumeFailureSummary != null) { builder.SetVolumeFailureSummary(PBHelper.ConvertVolumeFailureSummary(volumeFailureSummary )); } DatanodeProtocolProtos.HeartbeatResponseProto resp; try { resp = rpcProxy.SendHeartbeat(NullController, ((DatanodeProtocolProtos.HeartbeatRequestProto )builder.Build())); } catch (ServiceException se) { throw ProtobufHelper.GetRemoteException(se); } DatanodeCommand[] cmds = new DatanodeCommand[resp.GetCmdsList().Count]; int index = 0; foreach (DatanodeProtocolProtos.DatanodeCommandProto p in resp.GetCmdsList()) { cmds[index] = PBHelper.Convert(p); index++; } RollingUpgradeStatus rollingUpdateStatus = null; // Use v2 semantics if available. if (resp.HasRollingUpgradeStatusV2()) { rollingUpdateStatus = PBHelper.Convert(resp.GetRollingUpgradeStatusV2()); } else { if (resp.HasRollingUpgradeStatus()) { rollingUpdateStatus = PBHelper.Convert(resp.GetRollingUpgradeStatus()); } } return(new HeartbeatResponse(cmds, PBHelper.Convert(resp.GetHaStatus()), rollingUpdateStatus )); }