public async Task HandleConfirmJoinOperation(GamePeer peer, OperationRequest operationRequest, SendParameters sendParameters) { var joinRequest = new ConfirmJoinRequest(peer.Protocol, operationRequest); if (!peer.ValidateOperation(joinRequest, sendParameters)) { return; } //string playerInfoStr = await WebHelper.RequestPlayerInfo(joinRequest.UserKey); string playerInfoStr = "{ \"username\": \"test\", \"game_money\": 2000 }"; PlayerInfo info = JsonConvert.DeserializeObject<PlayerInfo>(playerInfoStr); PeerManager.Instance.OnPeerJoin(peer, new PeerInfo(peer, joinRequest.RoomID, joinRequest.UserKey)); var room = FindRoom(joinRequest.RoomID); if (room != null) { room.ExecutionFiber.Enqueue(() => room.Join(peer, joinRequest, sendParameters, info)); } else { var response = new OperationResponse(CommonOperationCode.ConfirmJoin, new Dictionary<byte, object> { { (byte)CommonParameterKey.Success, false } }); peer.SendOperationResponse(response, sendParameters); } }
public async Task HandleConfirmJoinOperation(GamePeer peer, OperationRequest operationRequest, SendParameters sendParameters) { var joinRequest = new ConfirmJoinRequest(peer.Protocol, operationRequest); if (!peer.ValidateOperation(joinRequest, sendParameters)) { return; } //string playerInfoStr = await WebHelper.RequestPlayerInfo(joinRequest.UserKey); string playerInfoStr = "{ \"username\": \"test\", \"game_money\": 2000 }"; PlayerInfo info = JsonConvert.DeserializeObject <PlayerInfo>(playerInfoStr); PeerManager.Instance.OnPeerJoin(peer, new PeerInfo(peer, joinRequest.RoomID, joinRequest.UserKey)); var room = FindRoom(joinRequest.RoomID); if (room != null) { room.ExecutionFiber.Enqueue(() => room.Join(peer, joinRequest, sendParameters, info)); } else { var response = new OperationResponse(CommonOperationCode.ConfirmJoin, new Dictionary <byte, object> { { (byte)CommonParameterKey.Success, false } }); peer.SendOperationResponse(response, sendParameters); } }
public void HandleChatOperation(GamePeer peer, OperationRequest operationRequest, SendParameters sendParameters) { var chatRequest = new ChatRequest(peer.Protocol, operationRequest); if (!peer.ValidateOperation(chatRequest, sendParameters)) { return; } var room = FindPeerRoom(peer); if (room != null) { room.Chat(peer, chatRequest, sendParameters); } }
public void HandleExitOperation(GamePeer peer, OperationRequest operationRequest, SendParameters sendParameters) { var exitRequest = new ExitRequest(peer.Protocol, operationRequest); if (!peer.ValidateOperation(exitRequest, sendParameters)) { return; } var room = FindPeerRoom(peer); if (room != null) { room.ExecutionFiber.Enqueue(() => room.Leave(peer)); } peer.Leave(); }
public void HandleJoinOperation(GamePeer peer, OperationRequest operationRequest, SendParameters sendParameters) { var joinRequest = new JoinRequest(peer.Protocol, operationRequest); if (!peer.ValidateOperation(joinRequest, sendParameters)) { return; } var room = FindRoom(joinRequest.RoomID); var response = new OperationResponse(CommonOperationCode.Join, new Dictionary<byte, object> { { (byte)CommonParameterKey.Success, false } }); response.Parameters[(byte)JoinParameterKey.RoomID] = joinRequest.RoomID; if (room != null && room.CanJoin(peer)) { response.Parameters[(byte)CommonParameterKey.Success] = true; } peer.SendOperationResponse(response, sendParameters); }
public void HandleJoinOperation(GamePeer peer, OperationRequest operationRequest, SendParameters sendParameters) { var joinRequest = new JoinRequest(peer.Protocol, operationRequest); if (!peer.ValidateOperation(joinRequest, sendParameters)) { return; } var room = FindRoom(joinRequest.RoomID); var response = new OperationResponse(CommonOperationCode.Join, new Dictionary <byte, object> { { (byte)CommonParameterKey.Success, false } }); response.Parameters[(byte)JoinParameterKey.RoomID] = joinRequest.RoomID; if (room != null && room.CanJoin(peer)) { response.Parameters[(byte)CommonParameterKey.Success] = true; } peer.SendOperationResponse(response, sendParameters); }