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 Join(GamePeer peer, ConfirmJoinRequest joinReq, SendParameters sendParameters, PlayerInfo info) { if (CanJoin(peer)) { Player newPlayer = playerManager.AddPlayer(peer, info); BroadcastMessageHandler += peer.OnBroadcastMessage; peer.OnLeaveHandler += OnPeerLeave; OnJoin(peer); } else { var response = new OperationResponse(CommonOperationCode.ConfirmJoin, new Dictionary <byte, object> { { (byte)CommonParameterKey.Success, false } }); peer.SendOperationResponse(response, sendParameters); } }
public void Join(GamePeer peer, ConfirmJoinRequest joinReq, SendParameters sendParameters, PlayerInfo info) { if (CanJoin(peer)) { Player newPlayer = playerManager.AddPlayer(peer, info); BroadcastMessageHandler += peer.OnBroadcastMessage; peer.OnLeaveHandler += OnPeerLeave; OnJoin(peer); } else { var response = new OperationResponse(CommonOperationCode.ConfirmJoin, new Dictionary<byte, object> { { (byte)CommonParameterKey.Success, false } }); peer.SendOperationResponse(response, sendParameters); } }